def __init__(self, context, platform=platform.system().lower()): ParserBase.__init__(self, context) self.platform = get_platform(platform) self.program_re = self.platform.get_program_path_re("icupkg") # https://helpmanual.io/help/icupkg/ self.parser = ArgumentParserEx() self.parser.set(dest=None, raw_dest="args") self.parser.add_argument("--type", "-t", choices=["l", "b", "e"]) self.parser.add_argument("--copyright", "-c") self.parser.add_argument("--comment", "-C") self.parser.add_argument("--add", "-a") self.parser.add_argument("--remove", "-r") self.parser.add_argument("--extract", "-x") self.parser.add_argument("--writepkg", "-w", action="store_true") self.parser.add_argument("--matchmode", "-m") self.parser.add_argument("--auto_toc_prefix", action="store_true") self.parser.add_argument("--auto_toc_prefix_with_type", action="store_true") self.parser.add_argument("--sourcedir", "-s", raw_handler=self.input_dir) self.parser.add_argument("--destdir", "-d", raw_handler=self.input_dir) self.parser.add_argument("--list", "-l", action="store_true") self.parser.add_argument("--outlist", "-o", raw_handler=self.output_file) self.parser.add_argument("infilename", raw_handler=self.input_file) self.parser.add_argument("outfilename", nargs="?", raw_handler=self.output_file)
def __init__(self, context, platform=None): self.context = context self.platform = get_platform(platform) self.program_re = self.platform.get_program_path_re("cmake") self.parser = ArgumentParserEx(prog="cmake") self.parser.add_argument("-E", dest="command", nargs="+")
def __init__(self, context, platform=None): self.platform = get_platform(platform) self.program_re = self.platform.get_program_path_re("ar") self.context = context # see https://linux.die.net/man/1/ar self.parser = ArgumentParserNoExit(prog="ar") self.parser.add_argument("-q", action="store_true", dest="insert") self.parser.add_argument("-r", action="store_true", dest="replace") self.parser.add_argument("-c", action="store_true", dest="create") self.parser.add_argument("-s", action="store_true", dest="index") self.parser.add_argument("-v", action="store_true", dest="verbose") self.parser.add_argument("-N", action="store_true", dest="multiple") self.parser.add_argument("-u", action="store_true", dest="update") self.parser.add_argument("-x", action="store_true", dest="extract") self.parser.add_argument("-t", action="store_true", dest="table") parser_mode = self.parser.add_mutually_exclusive_group() parser_mode.set_defaults(mode=self.Modes.default) parser_mode.add_argument("-a", action="store_const", const=self.Modes.after, dest="mode") parser_mode.add_argument("-b", "-i", action="store_const", const=self.Modes.before, dest="mode")
def __init__(self, context, project_version=None, platform=None): self.context = context self.platform = get_platform(platform) self.project_version = project_version self.program_re = self.platform.get_program_path_re("libtool") # see https://www.gnu.org/software/libtool/manual/libtool.html self.parser = ArgumentParserNoExit(prog="libtool") self.parser.add_argument("-static", action="store_true") self.parser.add_argument("objects", nargs="+") self.parser.add_argument("-o", dest="output")
def __init__(self, context, platform=None): ParserBase.__init__(self, context) self.platform = get_platform(platform) self.program_re = self.platform.get_program_path_re("mc") # https://docs.microsoft.com/en-us/windows/windows/wes/message-compiler--mc-exe- # Currently, only small subset of flags is supported self.parser = ArgumentParserEx() self.parser.set(raw_dest="args") self.parser.add_argument("-h", raw_handler=self.input_dir, dest="header_dir") self.parser.add_argument("-r", raw_handler=self.input_dir, dest="resource_dir") self.parser.add_argument("manifest_file", raw_handler=self.input_file, dest="manifest_file")
def __init__(self, context, platform=None): ParserBase.__init__(self, context) self.platform = get_platform(platform) self.program_re = self.platform.get_program_path_re("objcopy") # https://sourceware.org/binutils/docs/binutils/objcopy.html self.parser = ArgumentParserEx() self.parser.set(dest=None, raw_dest="args") self.parser.add_argument("--redefine-syms", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--keep-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--strip-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--strip-unneeded-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--keep-global-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--keep-global-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--localize-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--globalize-symbols", raw_handler=self.input_file_after_equals_sign) self.parser.add_argument("--weaken-symbols", raw_handler=self.input_file_after_equals_sign) obj_re = re.compile(r"^[^-=+:]+$") self.parser.add_argument("infile", dest="infile", raw_handler=self.input_file, args_regexp=obj_re) self.parser.add_argument( "outfile", dest="outfile", nargs="?", raw_handler=self.output_file, args_regexp=obj_re, )
def __init__(self, context, platform=None): ParserBase.__init__(self, context) self.platform = get_platform(platform) self.program_re = self.platform.get_program_path_re("pkgdata") # https://helpmanual.io/help/icupkg/ self.parser = ArgumentParserEx() self.parser.set(raw_dest="args") self.parser.add_argument("--name", "-p") self.parser.add_argument("--bldopt", "-O", raw_handler=self.input_file) self.parser.add_argument( "--mode", "-m", choices=["files", "dll", "library", "common", "archive", "static"], ) self.parser.add_argument("--verbose", "-v", action="store_true") self.parser.add_argument("--copyright", "-c", action="store_true") self.parser.add_argument("--comment", "-C", action="store_true") self.parser.add_argument("--destdir", "-d", raw_handler=self.input_dir) self.parser.add_argument("--rebuild", "-F", action="store_true") self.parser.add_argument("--tempdir", "-T", raw_handler=self.input_dir) self.parser.add_argument("--install", "-I") self.parser.add_argument("--sourcedir", "-s", raw_handler=self.input_dir) self.parser.add_argument("--entrypoint", "-e") self.parser.add_argument("--revision", "-r") self.parser.add_argument("--force-prefix", "-f") self.parser.add_argument("--libname", "-L") self.parser.add_argument("--quiet", "-q", action="store_true") self.parser.add_argument("--without-assembly", "-w", action="store_true") self.parser.add_argument("--zos-pds-build", "-z", action="store_true") self.parser.add_argument("packageFile", raw_handler=self.input_file)
def parse_and_generate(self, test_platform, presets=None, path_aliases=None, log_type=None, cmakelists_name="CMakeLists.txt", max_relpath_level=1, project=None, extra_targets=None, build_dirs=None, source_dir=None, commands=None, load=None, save=None, logs=None, source_subdir=None, flag_optimizer_ver=None, **kwargs): if path_aliases is None: path_aliases = [] if source_subdir is None: source_subdir = "." if flag_optimizer_ver is None: flag_optimizer_ver = "1" platform = get_platform(test_platform) if presets is None: presets = copy.copy(self.default_presets.get(test_platform)) if source_dir is None: source_dir = os.path.join(self.test_method_dir, "source") if build_dirs is None: build_dir = os.path.join(self.test_method_dir, "build") multiple_build_dirs = [ os.path.join(self.test_method_dir, "build1"), os.path.join(self.test_method_dir, "build2"), ] if os.path.exists(multiple_build_dirs[0]): build_dirs = multiple_build_dirs else: build_dirs = [build_dir] generator_out_dir = os.path.join(self.test_method_out_dir, "out") self.makedirs(generator_out_dir) expected_cmake_template = os.path.join(self.test_method_dir, cmakelists_name + ".in") if os.path.exists(expected_cmake_template): expected_cmake = self._format_template(expected_cmake_template, platform) else: expected_cmake = os.path.join(self.test_method_dir, cmakelists_name) if logs is None: build_log_template = os.path.join(self.test_method_dir, "build.log.in") multiple_build_logs_first = os.path.join(self.test_method_dir, "build1.log") multiple_build_logs_first_template = os.path.join( self.test_method_dir, "build1.log.in") if os.path.exists(build_log_template): logs = [build_log_template] elif os.path.exists(multiple_build_logs_first): logs = [multiple_build_logs_first] idx = 2 while True: path = os.path.join(self.test_method_dir, "build%d.log" % idx) idx += 1 if os.path.exists(path): logs.append(path) else: break elif os.path.exists(multiple_build_logs_first_template): logs = [] idx = 1 while True: template = os.path.join(self.test_method_dir, "build%d.log.in" % idx) if not os.path.exists(template): break idx += 1 logs.append(template) else: logs = [os.path.join(self.test_method_dir, "build.log")] logs = [self._format_template(path, platform) for path in logs] if log_type: log_type += ":" else: log_type = "" kwargs.update({ "platform": test_platform, "path_aliases": path_aliases, "max_relpath_level": max_relpath_level, "logs": [log_type + log for log in logs], "build_dirs": build_dirs, "source_dir": source_dir, "project": project, "out_dir": generator_out_dir, "save": None, "load": None, "source_subdir": source_subdir, "flag_optimizer_ver": flag_optimizer_ver, }) modules = None settings = {} if presets is not None: loader = SettingsLoader() settings = loader.load(presets) settings = loader.merge(settings, kwargs) else: settings = kwargs if settings is not None: modules = ModuleLoader( settings.get("module_dirs")).load(**get_subdict( settings, ModuleGroups.BUILDERS, ModuleGroups.PARSERS, ModuleGroups.OPTIMIZERS, ModuleGroups.GENERATORS, )) migrator = BuildMigrator(modules) targets = [] if load: targets = migrator.load_build_object_model(load) if extra_targets: targets.extend(extra_targets) if commands is None or "parse" in commands: targets = migrator.parse(targets, **settings) if "targets" in settings: del settings["targets"] if commands is None or "optimize" in commands: targets = migrator.optimize(targets, **settings) if save: migrator.save_build_object_model(save, targets) if commands is None or "generate" in commands: migrator.generate(targets, **settings) result_cmake = os.path.join(generator_out_dir, "CMakeLists.txt") self.assertTrue(os.path.exists(result_cmake)) self.assertFilesEqual(expected_cmake, result_cmake)
def __init__( self, build_migrator, logs, source_dir, build_dirs, project=None, platform=platform.system().lower(), working_dir=None, path_aliases=None, max_relpath_level=0, targets=None, force_target_name=None, capture_sources=None, log_type=None, dont_capture_sources=None, ): if not logs: raise ValueError("Specify at least one log (--logs argument)") if capture_sources and dont_capture_sources: raise ValueError( "capture_sources cannot be specified if dont_capture_sources is True" ) self.current_target = None self.platform = os_ext.get_platform(platform) self.logs = self._parse_logs(logs, log_type) self.project = project self.build_dirs = [ self.platform.normalize_path(os.path.abspath(os.path.join(os.curdir, bd))) for bd in build_dirs ] self.source_dir = self.platform.normalize_path( os.path.abspath(os.path.join(os.curdir, source_dir)) ) if working_dir: self._working_dir = self.platform.normalize_path( os.path.abspath(working_dir) ) else: self._working_dir = self.build_dirs[0] self.max_relpath_level = max_relpath_level self.path_aliases = None self.target_index = None # target_output => target self.targets = None self._arg_path_aliases = path_aliases self._arg_dont_capture_sources = dont_capture_sources self._arg_capture_sources = capture_sources self.dir_mapping = {self.source_dir: self.source_dir_placeholder} for build_dir in self.build_dirs: self.dir_mapping[build_dir] = self.build_dir_placeholder if source_dir == build_dir: raise ValueError("Source dir cannot be the same as build directory") self.required_targets = None if targets: self.required_targets = [] for tgt in targets: file_found = False for bd in self.build_dirs: paths = self._list_files(bd, tgt) if paths: file_found = True for path in paths: # search target by output path = self._construct_path_arg(path).relocatable if path not in self.required_targets: self.required_targets.append(path) if not file_found: # search target after parsing provided log if tgt not in self.required_targets: self.required_targets.append(tgt) self.force_target_name = {} for output, name in force_target_name or []: self.force_target_name[output] = name
def __init__( self, context, project_version=None, platform=platform.system().lower(), ignore_link_flags=None, ignore_compile_flags=None, ): CompilerParser.__init__(self, context, ignore_compile_flags=ignore_compile_flags) LinkerParser.__init__(self, context, ignore_link_flags=ignore_link_flags) self.platform_name = platform self.platform = get_platform(platform) self.project_version = project_version self.program_re = self.platform.get_program_path_re( "cc", "c++", "clang", "clang++", "gcc", "g++") # Clang/GCC arguments # See https://linux.die.net/man/1/gcc # https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html # https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html # https://clang.llvm.org/docs/ClangCommandLineReference.html self.parser = ArgumentParserEx(prog="gcc") self.parser.set_defaults( mode=self.Mode.link, lib_dirs=[], libs=[], include_dirs=[], link_flags=[], compile_flags=[], ) # control flags self.parser.set(dest=None) self.parser.add_argument("-E", action="store_const", const=self.Mode.preprocess, dest="mode") self.parser.add_argument("-MD", action="store_true") self.parser.add_argument("-MF") self.parser.add_argument("-MMD", action="store_true") self.parser.add_argument("-MP", action="store_true") self.parser.add_argument("-MT") self.parser.add_argument("-S", action="store_const", const=self.Mode.compile, dest="mode") self.parser.add_argument("-c", action="store_const", const=self.Mode.assemble, dest="mode") self.parser.add_argument("-o", dest="output") self.parser.add_argument("-pipe", action="store_true") # linker flags self.parser.set(raw_dest="link_flags") self.parser.add_argument("-L", action="append", dest="lib_dirs", raw_dest=None) self.parser.add_argument("-Q", dest="driver_arguments") self.parser.add_argument(prefixes=["-Wl,"]) self.parser.add_argument("-all_load", action="store_true") self.parser.add_argument("-compatibility_version") self.parser.add_argument("-current_version") self.parser.add_argument("-version-info") self.parser.add_argument( "-dynamiclib", "-dynamic", action="store_true", raw_dest=None, dest="is_shared", ) self.parser.add_argument("-exported_symbols_list") self.parser.add_argument("-framework") self.parser.add_argument("-rpath") self.parser.add_argument("-headerpad_max_install_names", action="store_true") self.parser.add_argument("-no-undefined", action="store_true") self.parser.add_argument("-install_name") self.parser.add_argument(prefixes=["-l:", "-l"]) self.parser.add_argument("-nolibc", action="store_true") self.parser.add_argument("-nostdlib++", action="store_true") self.parser.add_argument("-no-canonical-prefixes", action="store_true") self.parser.add_argument("-nostdlib", action="store_true") self.parser.add_argument("-single_module", action="store_true") self.parser.add_argument("-pie", action="store_true") self.parser.add_argument("-rdynamic", action="store_true") self.parser.add_argument("-shared", action="store_true", raw_dest=None, dest="is_shared") self.parser.add_argument("-static", action="store_true") self.parser.add_argument("-static-libgcc", action="store_true") self.parser.add_argument("-static-libstdc++", action="store_true") self.parser.add_argument("-stdlib") self.parser.add_argument(flags=["-z"]) self.parser.add_argument("static_libs", nargs="*", args_regexp=re.compile(r"^(?!-Wl).+\.a$")) if platform == "linux": self.parser.add_argument( "shared_libs", nargs="*", args_regexp=re.compile(r"^(?!-Wl).+\.so$")) if platform == "darwin": self.parser.add_argument( "shared_libs", nargs="*", args_regexp=re.compile(r"^(?!-Wl).+\.dylib(?:\.\d+)*$"), ) # compiler flags self.parser.set(raw_dest="compile_flags") self.parser.add_argument("-D", raw_format=format_flag_gnu) self.parser.add_argument(prefixes=["-B"]) # Aurora stuff self.parser.add_argument("--target", "-target") self.parser.add_argument("--gcc-toolchain", "-gcc-toolchain") self.parser.add_argument("--sysroot") self.parser.add_argument("-I", action="append", dest="include_dirs", raw_dest=None) self.parser.add_argument(prefixes=["-O"]) self.parser.add_argument("-Q") self.parser.add_argument("-U", raw_format=format_flag_gnu) self.parser.add_argument(prefixes=["-W"], args_regexp=re.compile("^(?!l,)")) self.parser.add_argument(prefixes=["-Wa,"]) self.parser.add_argument("-arch") self.parser.add_argument("-w", action="store_true") self.parser.add_argument(prefixes=["-f"]) self.parser.add_argument(prefixes=["-W"]) self.parser.add_argument("-W", action="store_true") self.parser.add_argument("-pedantic", action="store_true") self.parser.add_argument(prefixes=["-std=", "--std="]) self.parser.add_argument("-x", dest="language_mode") self.parser.add_argument("-isystem", action="append") # compiler + linker flags # TODO: HACK: list support in raw_dest is temporary until a better solution comes up self.parser.set(raw_dest=["compile_flags", "link_flags"]) self.parser.add_argument("-g", nargs="?") self.parser.add_argument("-isysroot") self.parser.add_argument(prefixes=["-m"]) self.parser.add_argument("-pthread", action="store_true") self.parser.add_argument("infiles", nargs="*", dest="infiles", raw_dest=None)