Esempio n. 1
0
    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="+")
Esempio n. 2
0
    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)
Esempio n. 3
0
    def test_action_append_const(self):
        parser = ArgumentParserEx()
        parser.add_argument("-a", action="append_const", const="v")

        ns, remaining = parser.parse_known_args(["-a", "1", "-a2", "-a"])
        self.assertListEqual(["1", "-a2"], remaining)
        self.assertEqual(["v", "v"], ns.a)
Esempio n. 4
0
    def __init__(self, context, ignore_compile_flags=None):
        CompilerParser.__init__(
            self, context, ignore_compile_flags=ignore_compile_flags
        )

        # Visual Studio rc.exe arguments
        # https://docs.microsoft.com/en-us/windows/desktop/menurc/using-rc-the-rc-command-line-
        self.parser = ArgumentParserEx(prefix_chars="-/")
        self.parser.set_defaults(compile_flags=[], link_flags=[], include_dirs=[])
        # TODO: publish all meaningful flags
        self.parser.set(ignore_case=True, dest=None, raw_dest="compile_flags")
        self.parser.add_argument("/d", raw_format=ReplacePrefixArg("-D"))
        self.parser.add_argument("/u", raw_format=ReplacePrefixArg("-U"))
        self.parser.add_argument("/ln", raw_format=ReplacePrefixArg("/ln"))
        self.parser.add_argument("/l", raw_format=ReplacePrefixArg("/l"))
        self.parser.add_argument("/gn", raw_format=ReplacePrefixArg("/gn"))
        self.parser.add_argument("/g", raw_format=ReplacePrefixArg("/g"))
        self.parser.add_argument(
            "/i", action="append", dest="include_dirs", raw_dest=None
        )
        self.parser.add_argument("/nologo", action="store_true")
        self.parser.add_argument(
            "/w", action="store_true", raw_format=ReplacePrefixArg("/w")
        )
        self.parser.add_argument("/fo", prefix=True, dest="output", raw_dest=None)
        self.parser.add_argument("infiles", dest="infiles", nargs="*", raw_dest=None)
Esempio n. 5
0
    def test_deepcopy_1(self):
        parser = ArgumentParserEx()
        parser.add_argument("-a")

        parser = deepcopy(parser)

        ns = parser.parse_args(["-a", "1"])
        self.assertEqual("1", ns.a)
Esempio n. 6
0
 def test_concatenate_flags(self):
     self.skipTest("not implemented yet")
     parser = ArgumentParserEx()
     parser.add_argument("-a", action="store_true")
     parser.add_argument("-b", action="store_true")
     ns = parser.parse_args(["-ab"])
     self.assertTrue(ns.a)
     self.assertTrue(ns.b)
Esempio n. 7
0
    def test_force_suffix_value(self):
        parser = ArgumentParserEx()
        parser.add_argument(prefixes=["-Xclang"])
        ns = parser.parse_args(["-Xclangvalue"])
        self.assertEqual("value", ns.Xclang)

        parser = ArgumentParserEx()
        parser.add_argument("-Xclang", prefix=True)
        ns = parser.parse_args(["-Xclangvalue"])
        self.assertEqual("value", ns.Xclang)
Esempio n. 8
0
    def __init__(self, context, ignore_compile_flags=None):
        CompilerParser.__init__(self,
                                context,
                                ignore_compile_flags=ignore_compile_flags)

        # NASM arguments
        # https://www.nasm.us/doc/nasmdoc2.html#section-2.1
        self.parser = ArgumentParserEx()
        self.parser.set_defaults(compile_flags=[], include_dirs=[])
        # TODO: publish all meaningful flags
        self.parser.set(dest=None, raw_dest="compile_flags")
        # Define a Macro
        self.parser.add_argument("-D",
                                 raw_format=format_flag_gnu,
                                 ignore_case=True)
        # Select Debug Information Format
        self.parser.add_argument(
            "-F",
            raw_format=format_flag_gnu,
        )
        # Output File Format
        self.parser.add_argument("-f",
                                 required=True,
                                 raw_format=format_flag_gnu)
        # Enabling Debug Information
        self.parser.add_argument("-g", action="store_true")
        # Include File Search Directories
        self.parser.add_argument("-I",
                                 action="append",
                                 dest="include_dirs",
                                 ignore_case=True,
                                 raw_dest=None)
        # Assemble and Generate Dependencies
        self.parser.add_argument("-MD", raw_dest=None)
        # Multipass Optimization
        self.parser.add_argument("-O")
        # Output File Name
        self.parser.add_argument("-o", dest="output", raw_dest=None)
        # Pre-Include a File
        self.parser.add_argument(
            "-P",
            "--include",
            action="append",
            default=[],
            dest="preincludes",
            raw_dest=None,
        )
        # Undefine a Macro
        self.parser.add_argument("-U",
                                 raw_format=format_flag_gnu,
                                 ignore_case=True)
        # Warnings
        self.parser.add_argument("-W", "-w")
        self.parser.add_argument("infile", dest="infile", raw_dest=None)
Esempio n. 9
0
class MsvcMc(ParserBase):
    priority = 7

    @staticmethod
    def add_arguments(arg_parser):
        pass

    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 parse(self, target):
        tokens = target.get("tokens") or []
        if not tokens:
            return target

        if not self.program_re.match(tokens[0]):
            return target

        tokens.pop(0)
        namespace = self.parser.parse_args(tokens)

        if namespace.header_dir is None:
            namespace.header_dir = target["working_dir"]
        header_dir = self.context.get_dir_arg(
            self.context.normalize_path(namespace.header_dir))

        if namespace.resource_dir is None:
            namespace.resource_dir = target["working_dir"]
        resource_dir = self.context.get_dir_arg(
            self.context.normalize_path(namespace.resource_dir))

        filename_no_ext = os.path.basename(namespace.manifest_file)
        filename_no_ext = os.path.splitext(filename_no_ext)[0]

        output = [
            header_dir + "/" + filename_no_ext + ".h",
            resource_dir + "/" + filename_no_ext + ".rc",
        ]

        return get_command_target(None, "mc", namespace.args, output,
                                  namespace.dependencies)
Esempio n. 10
0
class CMake(Parser):
    priority = 7

    @staticmethod
    def add_arguments(arg_parser):
        pass

    @staticmethod
    def is_applicable(project=None, log_type=None):
        return True

    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 parse(self, target):
        tokens = target.get("tokens")
        if not tokens:
            return target

        if not self.program_re.match(tokens[0]):
            return target

        namespace = self.parser.parse_args(tokens[1:])

        if not namespace.command:
            return target

        command = namespace.command[0]
        args = namespace.command[1:]

        dependencies = []
        targets = []
        if command == "cmake_symlink_library":
            # on Mac
            source = self.context.get_file_arg(
                self.context.platform.normalize_path(args[0]), dependencies)
            destinations = args[1:]
            for dest in destinations:
                target_dependencies = copy(dependencies)
                output = self.context.get_output(dest, target_dependencies)
                targets.append(
                    get_copy_target(None, source, output, target_dependencies))
        else:
            logger.warning("Unsupported CMake command: {}".format(command))

        return targets
Esempio n. 11
0
 def test_compatiblity_arguments(self):
     # test ArgumentParser interface compatibility
     # these arguments are simply ignored
     parser = ArgumentParserEx(
         prog="test",
         usage="usage",
         description="description",
         epilog="epilog",
         parents=[],
         formatter_class=object,
         fromfile_prefix_chars="fromfile_prefix_chars",
         argument_default=None,
         conflict_handler="error",
         add_help=True,
     )
     parser.add_argument("-a", help="help", metavar="metavar")
     ns = parser.parse_args(["-a1"])
     self.assertEqual("1", ns.a)
Esempio n. 12
0
    def test_optional_positional_argument(self):
        parser = ArgumentParserEx()
        parser.add_argument("infile")
        parser.add_argument("outfile", nargs="?")

        ns = parser.parse_args(["inout.txt"])
        self.assertEqual("inout.txt", ns.infile)

        ns = parser.parse_args(["in.txt", "out.txt"])
        self.assertEqual("in.txt", ns.infile)
        self.assertEqual(["out.txt"], ns.outfile)
Esempio n. 13
0
 def test_disable_concatenation(self):
     self.skipTest("not implemented yet")
     parser = ArgumentParserEx()
     parser.enable_flag_concatenation(False)
     parser.add_argument("-a", action="store_true")
     parser.add_argument("-b", action="store_true")
     ns, remaining = parser.parse_args(["-ab"])
     self.assertListEqual(["-ab"], remaining)
Esempio n. 14
0
 def test_intermixed_args(self):
     parser = ArgumentParserEx()
     parser.add_argument("files", action="append")
     parser.add_argument("-D", action="append", dest="definitions")
     ns = parser.parse_args(["-DA=1", "a.cpp", "-DB=2", "b.cpp"])
     # standard ArgumentParser won't append 'b.cpp' here
     self.assertListEqual(["a.cpp", "b.cpp"], ns.files)
     self.assertListEqual(["A=1", "B=2"], ns.definitions)
Esempio n. 15
0
    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")
Esempio n. 16
0
    def test_action_default(self):
        parser = ArgumentParserEx()
        parser.add_argument("attr1")
        parser.add_argument("--attr2")

        ns, remaining = parser.parse_known_args(["--attr2", "val1", "val2"])
        self.assertListEqual([], remaining)
        self.assertEqual("val2", ns.attr1)
        self.assertEqual("val1", ns.attr2)
Esempio n. 17
0
 def test_shortening(self):
     parser = ArgumentParserEx()
     parser.add_argument("--abc")
     parser.add_argument("--a")
     # standard ArgumentParser will parse --ab as --abc
     ns, remaining = parser.parse_known_args(
         ["--abc", "1", "--ab", "2", "--a", "3"])
     self.assertListEqual(["--ab", "2"], remaining)
     self.assertEqual("1", ns.abc)
     self.assertEqual("3", ns.a)
Esempio n. 18
0
    def test_msvc_flag_with_value_with_append(self):
        parser = ArgumentParserEx(prefix_chars="/-")
        parser.set(ignore_case=True)
        parser.add_argument("/flag",
                            action="msvc_flag_with_value",
                            dest="flags",
                            append=True)

        ns = parser.parse_args(["/flag:a", "/flag:b"])
        self.assertListEqual(["a", "b"], ns.flags)
Esempio n. 19
0
    def __init__(self, context, project_version=None):
        self.context = context
        self.project_version = project_version

        # Visual Studio lib.exe arguments
        # https://docs.microsoft.com/en-us/cpp/build/reference/running-lib?view=vs-2019
        self.parser = ArgumentParserEx(prefix_chars="-/")
        self.parser.set_defaults(compile_flags=[],
                                 link_flags=[],
                                 include_dirs=[],
                                 infiles=[])
        # TODO: publish all meaningful flags
        self.parser.set(ignore_case=True, dest=None, raw_dest="link_flags")
        self.parser.add_argument("/ignore", action="msvc_flag_with_value")
        self.parser.add_argument("/libpath",
                                 action="msvc_flag_with_value",
                                 append=True,
                                 raw_dest=None)
        self.parser.add_argument("/ltcg", action="store_true")
        self.parser.add_argument("/machine", action="msvc_flag_with_value")
        self.parser.add_argument("/out",
                                 action="msvc_flag_with_value",
                                 dest="output",
                                 raw_dest=None)
        self.parser.add_argument("/nologo", action="store_true")
        self.parser.add_argument("/wx",
                                 action="msvc_flag",
                                 msvc_false_suffix=":no")
        self.parser.add_argument("infiles",
                                 dest="infiles",
                                 nargs="*",
                                 raw_dest=None)

        # lld-link.exe arguments (/lib mode)
        # Cannot find documentation online
        self.lld_link_parser = deepcopy(self.parser)
        self.lld_link_parser.add_argument("/llvmlibthin", action="store_true")
        self.lld_link_parser.set(prefix_chars="-")
        self.lld_link_parser.add_argument("--color-diagnostics",
                                          action="store_true")
Esempio n. 20
0
 def test_case_insensitive_windows_style(self):
     parser = ArgumentParserEx(prefix_chars="/")
     parser.add_argument("/nologo", action="store_true", ignore_case=True)
     ns = parser.parse_args(["/NOLOGO"])
     self.assertTrue(ns.nologo)
     ns = parser.parse_args(["/nologo"])
     self.assertTrue(ns.nologo)
Esempio n. 21
0
    def test_action_append(self):
        parser = ArgumentParserEx()
        parser.add_argument("-a", action="append")

        ns, remaining = parser.parse_known_args(["-a1", "-a2"])
        self.assertListEqual([], remaining)
        self.assertEqual(["1", "2"], ns.a)

        ns, remaining = parser.parse_known_args(["-a", "2", "-a", "1"])
        self.assertListEqual([], remaining)
        self.assertEqual(["2", "1"], ns.a)

        parser.add_argument("b", action="append")

        ns, remaining = parser.parse_known_args(["-a", "1", "2", "-a", "3"])
        self.assertListEqual([], remaining)
        self.assertEqual(["1", "3"], ns.a)
        self.assertEqual(["2"], ns.b)
Esempio n. 22
0
    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,
        )
Esempio n. 23
0
    def test_choices(self):
        parser = ArgumentParserEx()
        parser.add_argument("--a1", choices=["abc", "ab", "a"])
        parser.add_argument("a2", choices=["def", "ef"])

        ns, remaining = parser.parse_known_args(["--a1=abc", "de"])
        self.assertListEqual(["de"], remaining)
        self.assertEqual("abc", ns.a1)
        self.assertIsNone(vars(ns).get("a2"))

        ns, remaining = parser.parse_known_args(["--a1", "abc", "de"])
        self.assertListEqual(["de"], remaining)
        self.assertEqual("abc", ns.a1)
        self.assertIsNone(vars(ns).get("a2"))

        ns, remaining = parser.parse_known_args(["--a1", "b", "def"])
        self.assertListEqual(["--a1", "b"], remaining)
        self.assertIsNone(vars(ns).get("a1"))
        self.assertEqual("def", ns.a2)
Esempio n. 24
0
    def test_dest_is_none(self):
        parser = ArgumentParserEx()
        parser.add_argument("-opt", dest=None, required=True)
        parser.add_argument("pos", dest=None)

        ns = parser.parse_args(["-opt", "1", "2"])
        self.assertIsNone(vars(ns).get("opt"))
        self.assertIsNone(vars(ns).get("pos"))

        ns, remaining = parser.parse_known_args(["-opt"])
        self.assertListEqual(["-opt"], remaining)

        ns, remaining = parser.parse_known_args(["1"])
        self.assertListEqual([], remaining)
        self.assertIsNone(vars(ns).get("opt"))
        self.assertIsNone(vars(ns).get("pos"))

        self.assertRaisesRegexp(ValueError, "Required attribute not found",
                                parser.parse_args, ["1"])
Esempio n. 25
0
    def test_conditional_arguments(self):
        self.skipTest("not implemented yet")
        parser = ArgumentParserEx()
        arg = parser.add_argument("-a")
        parser.add_argument("-b", after=[arg])

        ns = parser.parse_args(["-a", "1", "-b", "2"])
        self.assertEqual("1", ns.a)
        self.assertEqual("2", ns.b)

        ns = parser.parse_args(["-a", "1"])
        self.assertEqual("1", ns.a)

        ns, remaining = parser.parse_known_args(["-b", "1"])
        self.assertListEqual(["-b", "1"], remaining)
        self.assertIsNone(vars(ns).get("b"))
Esempio n. 26
0
    def test_single_hyphen_multichar_flag(self):
        parser = ArgumentParserEx()
        parser.add_argument("-flag")

        ns = parser.parse_args(["-flag", "value"])
        self.assertEqual("value", ns.flag)

        ns = parser.parse_args(["-flag=value"])
        self.assertEqual("value", ns.flag)
Esempio n. 27
0
    def test_action_store_override(self):
        parser = ArgumentParserEx()
        parser.add_argument("attr1", action="store")
        parser.add_argument("--attr2", action="store")

        ns, remaining = parser.parse_known_args(["val1", "--attr2", "val2"])
        self.assertListEqual([], remaining)
        self.assertEqual("val1", ns.attr1)
        self.assertEqual("val2", ns.attr2)

        ns, remaining = parser.parse_known_args(["--attr2", "val2", "val1"])
        self.assertListEqual([], remaining)
        self.assertEqual("val1", ns.attr1)
        self.assertEqual("val2", ns.attr2)

        ns, remaining = parser.parse_known_args(
            ["--attr2", "val1", "val2", "--attr2", "val3"])
        self.assertListEqual([], remaining)
        self.assertEqual("val2", ns.attr1)
        self.assertEqual("val3", ns.attr2)
Esempio n. 28
0
    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)
Esempio n. 29
0
 def test_no_prefix_chars(self):
     parser = ArgumentParserEx()
     parser.add_argument("-D", action="append", dest="definitions")
     parser.add_argument(
         flags=["cmd"],
         action="append",
         nargs="+",
         dest="commands",
         args_regexp=re.compile(r"^(?!cmd)"),
     )
     ns = parser.parse_args(
         ["-DA=1", "cmd", "cl.exe", "cmd", "gcc", "/c", "a.cpp"])
     self.assertListEqual(["A=1"], ns.definitions)
     self.assertListEqual([["cl.exe"], ["gcc", "/c", "a.cpp"]], ns.commands)
Esempio n. 30
0
    def test_action_store_positional(self):
        parser = ArgumentParserEx()
        parser.add_argument("attr", action="store")

        ns, remaining = parser.parse_known_args(["-val"])
        self.assertListEqual(["-val"], remaining)
        self.assertIsNone(vars(ns).get("attr"))

        ns, remaining = parser.parse_known_args(["val"])
        self.assertListEqual([], remaining)
        self.assertEqual("val", ns.attr)