def register_classes(args): logging.info("--------Registering Host Platforms--------") Core.host_classes = Factory.register_subclasses(HostPlatform, os.path.join(Core.install_path, HOST_PLATFORMS_CLASSPATH)) logging.info("-> Registered %i platform(s)---------" % len(Core.host_classes)) # pick the hostplatform that matches this machine HostPlatform.create_platform(Core.host_classes) logging.info("--------Registering Target Platforms--------") Core.target_classes = Factory.register_subclasses(TargetPlatform, os.path.join(Core.install_path, TARGET_PLATFORMS_CLASSPATH)) logging.info("-> Registered %i platform(s)---------" % len(Core.target_classes)) logging.info("--------Registering Compilers--------") Core.compiler_classes = Factory.register_subclasses(Compiler, os.path.join(Core.install_path, COMPILERS_CLASSPATH)) logging.info("-> Registered %i driver(s)---------" % len(Core.compiler_classes)) # instance the target platform TargetPlatform.create(args, Core.target_classes, Core.compiler_classes, HostPlatform.instance) logging.info("--------Registering Drivers--------") Core.driver_classes = Factory.register_subclasses(Driver, os.path.join(Core.install_path, DRIVERS_CLASSPATH)) logging.info("-> Registered %i driver(s)---------" % len(Core.driver_classes)) # pick which driver to use Driver.create_driver_for_platform(args, TargetPlatform.instance, Core.driver_classes) # after classes have been registered and the TargetPlatform, Driver are instanced # load the Attributes config Attributes.load_schema(Core.config, TargetPlatform.instance) if Core.config.has_key("driver_data"): Driver.instance.post_load_driver_schema(Core.config["driver_data"]) logging.info("--------Registering Serializable classes--------") for subclass in Serializable.__subclasses__(): Serializable.register_class(subclass) Core.supported_architectures = [] for architecture in Architecture.enum_keys: if TargetPlatform.compiler.supports_build_architecture(Language.CPP, architecture): Core.supported_architectures.append(architecture) else: logging.info('Does not support arch: {}'.format(architecture))
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()
def handle_list(args): logging.info( "System info for %s, %s" % (pegasus.__name__, pegasus.__version__) ) logging.info("") logging.info("-- (%i) Architectures --" % (len(Architecture.enum_keys))) for key in Architecture.enum_keys: logging.info("\t%s" % key) logging.info("") logging.info("-- (%i) Languages --" % (len(Language.enum_keys))) for key in Language.enum_keys: logging.info("\t%s" % key) logging.info("") logging.info( "-- (%i) Host Platforms --" % (len(HostPlatform.__subclasses__())) ) for d in HostPlatform.__subclasses__(): logging.info("\t%s" % d.__name__) logging.info("") logging.info( "-- (%i) Target Platforms --" % (len(TargetPlatform.__subclasses__())) ) for d in TargetPlatform.__subclasses__(): logging.info("\t%s" % d.__name__) logging.info("") logging.info("-- (%i) Compilers --" % (len(Compiler.__subclasses__()))) for d in Compiler.__subclasses__(): logging.info("\t%s" % d.__name__) logging.info("") logging.info("-- (%i) Drivers --" % (len(Core.driver_classes))) for d in Core.driver_classes: logging.info("\t%s" % d.__name__) logging.info("") buildfile = BuildFile(args.build_file) # need to mockup a parser here: parser = argparse.ArgumentParser() buildfile.execute("arguments", parser) args = parser.parse_args("") global_params = Attributes() products = buildfile.get_products( args=args, host_platform=HostPlatform, target_platform=TargetPlatform.instance, global_params=global_params ) if not products or type(products[0]) is not Product: raise Exception( "BuildFile returned an invalid value for products()!" ) logging.info( "Listing products for build file '%s' and platform '%s'" % \ (buildfile.abs_buildfile_path, HostPlatform.get()) ) logging.info("") logging.info("-- (%i) Products --" % len(products)) for p in products: logging.info("\t\"%s\": %s" % (p.name, p.output))