def handle_action(args): Core.preprocess_arguments(args) # populate args.architecture with sane values args.architecture = filter_architectures( args.architecture, Core.supported_architectures, TargetPlatform.instance.default_architectures() ) # Now that we have a list of architectures -- verify the target # platform can use that. for arch in args.architecture: if not TargetPlatform.compiler.supports_build_architecture( Language.CPP, arch ): raise Exception( "TargetPlatform does not support architecture: %s!" % arch ) global_params = Attributes() if args.command in ["generate", "build", "clean"]: # required for running command-line utils executor = Executor() # This first step accomplishes the following: # - loops through all product data in buildfile and generates dependencies # - use/generate BuildCache by associated products and dependencies with buildfiles gather_product_data( args, args.architecture, args.configuration, os.path.abspath(args.build_file), args.products if getattr(args, "products", None) else None, global_params, executor, [] ) # Using the buildcache we generated (or loaded) above, # execute the command on products in the correct order. BuildCache.execute_command(executor, args.command, execute_command) # save file manager data FileManager.instance.save() elif args.command in ["distclean"]: FileManager.instance.distclean()
def is_source_file(path): """ Returns true if this is a source file (.c, .cpp, .m, .mm) """ from pegasus.core import Core for pattern in Core.get_source_patterns(): if re.search(pattern, path): return True return False
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()