예제 #1
0
def Build(output_stream=sys.stdout, ):
    """Builds clang-formatProxy"""

    with StreamDecorator(output_stream).DoneManager(
            line_prefix="",
            prefix="\nResults: ",
            suffix="\n",
    ) as dm:
        command_line = '"{script}" Compile "/input={input}" "/output_dir={output_dir}" /no_bundle {exclude_modules}'.format(
            script=CurrentShell.CreateScriptName("CxFreezeCompiler"),
            input=os.path.join(_script_dir, "clang-formatProxy.py"),
            output_dir=os.path.join(
                _script_dir,
                "..",
                "..",
                "Tools",
                "clang-formatProxy",
                "v1.0",
                CurrentShell.CategoryName,
            ),
            exclude_modules=" ".join([
                '"/exclude_module={}"'.format(module)
                for module in EXCLUDE_MODULES
            ], ),
        )

        dm.result = Process.Execute(command_line, dm.stream)
        if dm.result != 0:
            return dm.result

        return dm.result
    def StopCoverage(self, output_stream):
        if not self._dirs:
            return 0

        # Move coverage data to this dir
        output_dir = os.path.dirname(self._coverage_filename)

        for filename in FileSystem.WalkFiles(
                output_dir,
                include_file_extensions=[".gcda"],
        ):
            dest_filename = os.path.join(output_dir,
                                         os.path.basename(filename))
            if dest_filename == filename:
                continue

            if not os.path.isfile(dest_filename):
                shutil.copyfile(filename, dest_filename)

        return Process.Execute(
            '{script} Lcov {dirs} "/output_dir={output}"'.format(
                script=CurrentShell.CreateScriptName("ExtractCoverageInfo"),
                dirs=" ".join(
                    ['"/bin_dir={}"'.format(dir) for dir in self._dirs]),
                output=output_dir,
            ),
            output_stream,
        )
예제 #3
0
def Build(
    force=False,
    output_stream=sys.stdout,
    verbose=False,
):
    return Process.Execute(
        '"{script}" Generate PythonJson CppToJson "{output_dir}" "/input={input}" /plugin_arg=no_serialization:true{force}{verbose}'
        .format(
            script=CurrentShell.CreateScriptName("SimpleSchemaGenerator"),
            output_dir=os.path.join(_script_dir, "..", "GeneratedCode"),
            input=os.path.join(_script_dir, "..", "CppToJson.SimpleSchema"),
            force=" /force" if force else "",
            verbose=" /verbose" if verbose else "",
        ),
        output_stream,
    )
예제 #4
0
def Build(
    output_dir,
    output_stream=sys.stdout,
):
    paths = []
    includes = []
    excludes = []

    command_line = '"{script}" Compile "/input={input}" "/output_dir={output_dir}" /no_bundle /no_optimize {paths}{includes}{excludes}' \
                        .format( script=CurrentShell.CreateScriptName("CxFreezeCompiler"),
                                 input=os.path.join(_script_dir, "Backup.py"),
                                 output_dir=output_dir,
                                 paths='' if not paths else " {}".format(' '.join([ '"/path={}"'.format(path) for path in paths ])),
                                 includes='' if not includes else " {}".format(' '.join([ '"/include={}"'.format(include) for include in includes ])),
                                 excludes='' if not excludes else " {}".format(' '.join([ '"/exclude={}"'.format(exclude) for exclude in excludes ])),
                               )

    return Process.Execute(command_line, output_stream)
def EntryPoint(
    arg,
    output_stream=sys.stdout,
):
    args = arg
    del arg

    # One of the args will be the filename
    input_filename = None

    for arg in args:
        if arg.startswith("-assume-filename="):
            input_filename = arg[len("-assume-filename=") :]
            break

    if input_filename is None:
        raise Exception("Unable to extract the filename from '{}'".format(args))

    # Write the contents from stdin to a temp file
    input_content = sys.stdin.read()
    assert input_content

    temp_filename = CurrentShell.CreateTempFilename(os.path.splitext(input_filename)[1])

    with open(temp_filename, "w") as f:
        f.write(input_content)

    with CallOnExit(lambda: FileSystem.RemoveFile(temp_filename)):
        # Invoke the script
        script_name = "Formatter"
        if CurrentShell.CategoryName != "Linux":
            script_name = CurrentShell.CreateScriptName(script_name)

        command_line = '"{script}" Format "{filename}" /quiet "/plugin_arg=hint_filename:{original_filename}"'.format(
            script=script_name,
            filename=temp_filename,
            original_filename=input_filename.replace(":", "\\:"),
        )

        result, formatted_output = Process.Execute(command_line)

    output_stream.write(formatted_output)
    return result
예제 #6
0
def Build(output_stream=sys.stdout, ):
    with StreamDecorator(output_stream).DoneManager(
            line_prefix="",
            prefix="\nResults: ",
            suffix="\n",
    ) as dm:
        input_file = os.path.join(_script_dir, "..", "SimpleSchema.g4")
        assert os.path.isfile(input_file), input_file

        output_dir = os.path.join(_script_dir, "..", "GeneratedCode")

        command_line = '{script} Compile Python3 -o "{output_dir}" -no-listener -visitor "{input_file}"'.format(
            script=CurrentShell.CreateScriptName("ANTLR"),
            output_dir=output_dir,
            input_file=input_file,
        )

        dm.result = Process.Execute(command_line, dm.stream)
        return dm.result
예제 #7
0
def Build(
    force=False,
    output_stream=sys.stdout,
    verbose=False,
):
    with StreamDecorator(output_stream).DoneManager(
            line_prefix="",
            prefix="\nResults: ",
            suffix="\n",
    ) as dm:
        dm.result = Process.Execute(
            '"{script}" Generate PythonYaml CodeCoverageFilter "{output_dir}" "/input={input_file}" /plugin_arg=no_serialization:True{force}{verbose}'
            .format(
                script=CurrentShell.CreateScriptName("SimpleSchemaGenerator"),
                output_dir=os.path.join(_script_dir, "..", "GeneratedCode"),
                input_file=os.path.join(_script_dir, "..",
                                        "CodeCoverageFilter.SimpleSchema"),
                force=" /force" if force else "",
                verbose=" /verbose" if verbose else "",
            ),
            dm.stream,
        )

        return dm.result
    def ExtractCoverageInfo(
        self,
        coverage_filename,
        binary_filename,
        includes,
        excludes,
        output_stream,
    ):

        # This is a hack. The names extracted from the coverage files are mangled
        # while the names provided in includes and excludes are in the glob format.
        # Split the glob and then determine matches by checking to see if each component
        # is in the mangled name. There is a lot that could go wrong with this, but
        # hopefully it is good enough.

        # ----------------------------------------------------------------------
        def ProcessFilter(value):
            return [part for part in value.split("::") if part != "*"]

        # ----------------------------------------------------------------------
        def Matches(value, parts):
            for part in parts:
                if part not in value:
                    return False

            return True

        # ----------------------------------------------------------------------

        if excludes:
            excludes = [ProcessFilter(exclude) for exclude in excludes]
            excludes_func = lambda method_name: any(
                Matches(method_name, exclude) for exclude in excludes)
        else:
            excludes_func = lambda method_name: False

        if includes:
            includes = [ProcessFilter(include) for include in includes]
            includes_func = lambda method_name: any(
                Matches(method_name, include) for include in includes)
        else:
            includes_func = lambda method_name: True

        # ----------------------------------------------------------------------
        def ShouldInclude(method_name):
            return not excludes_func(method_name) and includes_func(
                method_name)

        # ----------------------------------------------------------------------

        # grcov will parse every file in the directory which isn't what we want here. Move the coverage
        # files for this binary to a temp dir, parse that dir, and then remove it.
        temp_directory = CurrentShell.CreateTempDirectory()

        with CallOnExit(lambda: FileSystem.RemoveTree(temp_directory)):
            # ----------------------------------------------------------------------
            def GetCoverageFilename(ext):
                dirname, basename = os.path.split(binary_filename)
                basename = os.path.splitext(basename)[0]

                for item in os.listdir(dirname):
                    fullpath = os.path.join(dirname, item)
                    if not os.path.isfile(fullpath):
                        continue

                    this_basename, this_ext = os.path.splitext(item)
                    if this_ext == ext and this_basename.startswith(basename):
                        return fullpath

                return None

            # ----------------------------------------------------------------------

            gcno_filename = GetCoverageFilename(".gcno")
            assert gcno_filename and os.path.isfile(gcno_filename), (
                binary_filename, gcno_filename)

            shutil.copyfile(
                gcno_filename,
                os.path.join(temp_directory, os.path.basename(gcno_filename)),
            )

            gcda_filename = GetCoverageFilename(".gcda")
            assert gcda_filename and os.path.isfile(gcda_filename), (
                binary_filename, gcda_filename)

            shutil.copyfile(
                gcda_filename,
                os.path.join(temp_directory, os.path.basename(gcda_filename)),
            )

            # Convert the content
            result = Process.Execute(
                '{} Lcov "/bin_dir={}" /type=ade'.format(
                    CurrentShell.CreateScriptName("ExtractCoverageInfo"),
                    temp_directory,
                ),
                output_stream,
            )

            if result != 0:
                return result

            # Note that the coverage files for all output was generated when coverage was stopped.
            # These coverage files are used to extract coverage percentages for display purposes.
            # Don't let the output name of the file fool you - these files are different from the
            # globally generated coverage file.
            coverage_filename = os.path.join(temp_directory, "lcov.info")
            assert os.path.isfile(coverage_filename), coverage_filename

            # Parse the file
            covered = 0
            not_covered = 0

            with open(coverage_filename) as f:
                for line in f.readlines():
                    content = json.loads(line)

                    if "method" not in content:
                        continue

                    content = content["method"]

                    if ("name" not in content or "total_covered" not in content
                            or "total_uncovered" not in content):
                        continue

                    if not ShouldInclude(content["name"]):
                        continue

                    covered += content["total_covered"]
                    not_covered += content["total_uncovered"]

            return covered, not_covered
예제 #9
0
def Build(
    force=False,
    output_stream=sys.stdout,
    verbose=False,
):
    """Builds components used for Integration tests"""

    with StreamDecorator(output_stream).DoneManager(
            line_prefix="",
            prefix="\nResults: ",
            suffix="\n",
    ) as dm:
        command_line_template = '{script} Generate {{plugin}} {{schema}} "{{output_dir}}" /input="{{input_filename}}" /output_data_filename_prefix={{plugin}} /filter_unsupported_attributes{force}{verbose}'.format(
            script=CurrentShell.CreateScriptName("SimpleSchemaGenerator"),
            force=" /force" if force else "",
            verbose=" /verbose" if verbose else "",
        )

        schema_names = [
            ("AllTypes.SimpleSchema", [], " /include=types"),
            ("DefaultValues.SimpleSchema", [], None),
            ("DictionaryTest.SimpleSchema", ["PythonJson",
                                             "PythonYaml"], None),
            ("FileSystemTest.SimpleSchema", [], None),
            ("ProcessAdditionalData.SimpleSchema", [], None),
            ("Test.SimpleSchema", [], None),
        ]

        all_plugin_names = [
            "PythonJson",
            "PythonXml",
            "PythonYaml",
            "JsonSchema",
            "XsdSchema",
        ]

        for schema_name_index, (schema_name, plugin_names,
                                schema_flags) in enumerate(schema_names):
            plugin_names = plugin_names or all_plugin_names
            schema_flags = schema_flags or ""

            dm.stream.write("Processing '{}' ({} of {})...".format(
                schema_name, schema_name_index + 1, len(schema_names)))
            with dm.stream.DoneManager(suffix="\n", ) as schema_dm:
                schema_basename = os.path.splitext(schema_name)[0]

                output_dir = os.path.join(_script_dir, "Generated",
                                          schema_basename)

                schema_name = os.path.join(_script_dir, "..", "Impl",
                                           schema_name)
                assert os.path.isfile(schema_name), schema_name

                for plugin_index, plugin_name in enumerate(plugin_names):
                    schema_dm.stream.write("Plugin '{}' ({} of {})...".format(
                        plugin_name, plugin_index + 1, len(plugin_names)))
                    with schema_dm.stream.DoneManager(
                            suffix="\n" if verbose else None, ) as plugin_dm:
                        command_line = command_line_template.format(
                            plugin=plugin_name,
                            schema=schema_basename,
                            output_dir=output_dir,
                            input_filename=schema_name,
                        )

                        if plugin_name.endswith("Schema"):
                            command_line += schema_flags

                        plugin_dm.result, output = Process.Execute(
                            command_line)
                        if plugin_dm.result != 0 or verbose:
                            plugin_dm.stream.write(output)

        return dm.result