Ejemplo n.º 1
0
def main():
	Core.startup()


	Environment.instance = Environment()

	FileManager.instance = FileManager()

	# load the file and any options it may contain

	if len(sys.argv) < 2:
		raise Exception("No build file specified.")


	if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
		buildfile = BuildFile(sys.argv[1])
	else:
		raise Exception("Build file: \"%s\" does not exist!" % sys.argv[1])

	p = argparse.ArgumentParser(prog="pegasus")

	p.add_argument(
		"-q",
		dest="quiet",
		help="Log to a file, don't output to stdout",
		action="store_true",
		default=False
	)

	# position arguments
	p.add_argument("build_file", help="Target build file")

	# setup commands
	p_cmd = p.add_subparsers(
		dest="command",
		title="Commands",
		description="Available Commands"
	)

	p_list = p_cmd.add_parser(
		"list",
		help="List all products in the build file"
	)
	p_list.set_defaults(target_platform=None, command_callback=handle_list)

	p_generate = p_cmd.add_parser(
		"generate",
		help="Generate projects for product(s)"
	)
	p_generate.set_defaults(
		command_callback=handle_action,
		use_cache=False,
		action_name="generate"
	)
	add_common_options(buildfile, p_generate)

	p_build = p_cmd.add_parser("build", help="Build the project")
	p_build.set_defaults(
		command_callback=handle_action,
		use_cache=True,
		action_name="build"
	)
	add_common_options(buildfile, p_build)

	p_clean = p_cmd.add_parser("clean", help="Clean the project")
	p_clean.set_defaults(
		command_callback=handle_action,
		use_cache=True,
		action_name="clean"
	)
	add_common_options(buildfile, p_clean)

	p_distclean = p_cmd.add_parser(
		"distclean",
		help="Purge directories of generated files"
	)
	p_distclean.set_defaults(
		command_callback=handle_action,
		use_cache=True,
		action_name="distclean"
	)
	add_common_options(buildfile, p_distclean)

	args = p.parse_args()

	# setup environment
	Environment.get().use_cache = \
		args.use_cache if hasattr(args, "use_cache") else False

	# register classes (HostPlatforms, Drivers)
	Core.register_classes(args)

	logging.info("HostPlatform is %s" % HostPlatform.get())
	logging.info("TargetPlatform is %s" % TargetPlatform.get())
	logging.info("Compiler is %s, version: %s" % (
		TargetPlatform.get_compiler_name(),
		TargetPlatform.compiler.get_version())
	)


	# run command
	args.command_callback(args)

	if not Environment.get().use_cache:
		BuildCache.save_caches()