コード例 #1
0
    def compile_source_files(self,
                             project,
                             printer=NO_COLOR_PRINTER,
                             continue_on_error=False):
        """
        Use compile_source_file_command to compile all source_files
        """
        dependency_graph = project.create_dependency_graph()
        failures = []
        source_files = project.get_files_in_compile_order(
            dependency_graph=dependency_graph)
        source_files_to_skip = set()

        max_library_name = 0
        max_source_file_name = 0
        if source_files:
            max_library_name = max(
                len(source_file.library.name) for source_file in source_files)
            max_source_file_name = max(
                len(simplify_path(source_file.name))
                for source_file in source_files)

        for source_file in source_files:
            printer.write(
                'Compiling into %s %s ' %
                ((source_file.library.name + ":").ljust(max_library_name + 1),
                 simplify_path(source_file.name).ljust(max_source_file_name)))
            sys.stdout.flush()

            if source_file in source_files_to_skip:
                printer.write("skipped", fg="rgi")
                printer.write("\n")
                continue

            if self.__compile_source_file(source_file, printer):
                project.update(source_file)
            else:
                source_files_to_skip.update(
                    dependency_graph.get_dependent([source_file]))
                failures.append(source_file)

                if not continue_on_error:
                    break

        if failures:
            printer.write("Compile failed\n", fg='ri')
            raise CompileError

        if source_files:
            printer.write("Compile passed\n", fg='gi')
        else:
            printer.write("Re-compile not needed\n")
コード例 #2
0
    def compile_source_files(self, project, continue_on_error=False):
        """
        Use compile_source_file_command to compile all source_files
        """
        dependency_graph = project.create_dependency_graph()
        all_ok = True
        failures = []
        source_files = project.get_files_in_compile_order(
            dependency_graph=dependency_graph)
        source_files_to_skip = set()
        for source_file in source_files:
            if source_file in source_files_to_skip:
                print("Skipping %s due to failed dependencies" %
                      simplify_path(source_file.name))
                continue

            print('Compiling %s into %s ...' %
                  (simplify_path(source_file.name), source_file.library.name))
            try:
                command = None
                command = self.compile_source_file_command(source_file)
                success = run_command(command, env=self.get_env())

            except CompileError:
                success = False

            if success:
                project.update(source_file)
            else:
                source_files_to_skip.update(
                    dependency_graph.get_dependent([source_file]))
                failures.append(source_file)

                if command is None:
                    print(
                        "Failed to compile %s. File type not supported by %s simulator"
                        % (simplify_path(source_file.name), self.name))
                else:
                    print("Failed to compile %s with command:\n%s" %
                          (simplify_path(source_file.name), " ".join(command)))

                all_ok = False
                if not continue_on_error:
                    break

        if not all_ok:
            if continue_on_error:
                print("Failed to compile some files")
            raise CompileError
コード例 #3
0
ファイル: ui.py プロジェクト: darwinbeing/vunit
    def get_source_files(self, pattern="*", library_name=None, allow_empty=False):
        """
        Get a list of source files

        :param pattern: A wildcard pattern matching either an absolute or relative path
        :param library_name: The name of a specific library to search if not all libraries
        :param allow_empty: To disable an error if no files matched the pattern
        :returns: A :class:`.SourceFileList` object
        """
        results = []
        for source_file in self._project.get_source_files_in_order():
            if library_name is not None:
                if source_file.library.name != library_name:
                    continue

            if not (fnmatch(abspath(source_file.name), pattern) or
                    fnmatch(ostools.simplify_path(source_file.name), pattern)):
                continue

            results.append(SourceFile(source_file, self._project, self))

        if (not allow_empty) and len(results) == 0:
            raise ValueError(("Pattern %r did not match any file. "
                              "Use allow_empty=True to avoid exception,") % pattern)

        return SourceFileList(results)
コード例 #4
0
    def get_source_files(self, pattern="*", library_name=None, allow_empty=False):
        """
        Get a list of source files

        :param pattern: A wildcard pattern matching either an absolute or relative path
        :param library_name: The name of a specific library to search if not all libraries
        :param allow_empty: To disable an error if no files matched the pattern
        :returns: A :class:`.SourceFileList` object
        """
        results = []
        for source_file in self._project.get_source_files_in_order():
            if library_name is not None:
                if source_file.library.name != library_name:
                    continue

            if not (fnmatch(abspath(source_file.name), pattern) or
                    fnmatch(ostools.simplify_path(source_file.name), pattern)):
                continue

            results.append(SourceFile(source_file, self._project, self))

        if (not allow_empty) and len(results) == 0:
            raise ValueError(("Pattern %r did not match any file. "
                              "Use allow_empty=True to avoid exception,") % pattern)

        return SourceFileList(results)
コード例 #5
0
    def compile_source_files(self, project, continue_on_error=False):
        """
        Use compile_source_file_command to compile all source_files
        """
        dependency_graph = project.create_dependency_graph()
        all_ok = True
        failures = []
        source_files = project.get_files_in_compile_order(dependency_graph=dependency_graph)
        source_files_to_skip = set()
        for source_file in source_files:
            if source_file in source_files_to_skip:
                print("Skipping %s due to failed dependencies" % simplify_path(source_file.name))
                continue

            print("Compiling %s into %s ..." % (simplify_path(source_file.name), source_file.library.name))
            try:
                command = None
                command = self.compile_source_file_command(source_file)
                success = run_command(command)

            except CompileError:
                success = False

            if success:
                project.update(source_file)
            else:
                source_files_to_skip.update(dependency_graph.get_dependent([source_file]))
                failures.append(source_file)

                if command is None:
                    print(
                        "Failed to compile %s. File type not supported by %s simulator"
                        % (simplify_path(source_file.name), self.name)
                    )
                else:
                    print(
                        "Failed to compile %s with command:\n%s" % (simplify_path(source_file.name), " ".join(command))
                    )

                all_ok = False
                if not continue_on_error:
                    break

        if not all_ok:
            if continue_on_error:
                print("Failed to compile some files")
            raise CompileError
コード例 #6
0
ファイル: simulator_interface.py プロジェクト: barri/vunit
    def compile_source_files(self, project, printer=NO_COLOR_PRINTER, continue_on_error=False):
        """
        Use compile_source_file_command to compile all source_files
        """
        dependency_graph = project.create_dependency_graph()
        failures = []
        source_files = project.get_files_in_compile_order(dependency_graph=dependency_graph)
        source_files_to_skip = set()

        max_library_name = 0
        max_source_file_name = 0
        if source_files:
            max_library_name = max(len(source_file.library.name) for source_file in source_files)
            max_source_file_name = max(len(simplify_path(source_file.name)) for source_file in source_files)

        for source_file in source_files:
            printer.write(
                'Compiling into %s %s ' % (
                    (source_file.library.name + ":").ljust(max_library_name + 1),
                    simplify_path(source_file.name).ljust(max_source_file_name)))
            sys.stdout.flush()

            if source_file in source_files_to_skip:
                printer.write("skipped", fg="rgi")
                printer.write("\n")
                continue

            if self.__compile_source_file(source_file, printer):
                project.update(source_file)
            else:
                source_files_to_skip.update(dependency_graph.get_dependent([source_file]))
                failures.append(source_file)

                if not continue_on_error:
                    break

        if failures:
            printer.write("Compile failed\n", fg='ri')
            raise CompileError

        if source_files:
            printer.write("Compile passed\n", fg='gi')
        else:
            printer.write("Re-compile not needed\n")
コード例 #7
0
def describe_location(location, first=True):
    """
    Describe the location as a string
    """
    if location is None:
        return "Unknown location"

    ((file_name, (start, end)), previous) = location

    retval = ""
    if previous is not None:
        retval += describe_location(previous, first=False) + "\n"

    if file_name is None:
        retval += "Unknown Python string"
        return retval

    if not file_exists(file_name):
        retval += "Unknown location in %s" % file_name
        return retval

    contents = read_file(file_name)

    if first:
        prefix = "at"
    else:
        prefix = "from"

    count = 0
    for lineno, line in enumerate(contents.splitlines()):
        lstart = count
        lend = lstart + len(line)
        if lstart <= start <= lend:
            retval += "%s %s line %i:\n" % (
                prefix,
                simplify_path(file_name),
                lineno + 1,
            )
            retval += line + "\n"
            retval += (" " *
                       (start - lstart)) + ("~" *
                                            (min(lend - 1, end) - start + 1))
            return retval

        count = lend + 1
    return retval
コード例 #8
0
def describe_location(location, first=True):
    """
    Describe the location as a string
    """
    if location is None:
        return "Unknown location"

    ((file_name, (start, end)), previous) = location

    retval = ""
    if previous is not None:
        retval += describe_location(previous, first=False) + "\n"

    if file_name is None:
        retval += "Unknown Python string"
        return retval

    if not file_exists(file_name):
        retval += "Unknown location in %s" % file_name
        return retval

    contents = read_file(file_name)

    if first:
        prefix = "at"
    else:
        prefix = "from"

    count = 0
    for lineno, line in enumerate(contents.splitlines()):
        lstart = count
        lend = lstart + len(line)
        if lstart <= start <= lend:
            retval += "%s %s line %i:\n" % (prefix, simplify_path(file_name), lineno + 1)
            retval += line + "\n"
            retval += (" " * (start - lstart)) + ("~" * (min(lend - 1, end) - start + 1))
            return retval

        count = lend + 1
    return retval
コード例 #9
0
ファイル: ui.py プロジェクト: darwinbeing/vunit
 def name(self):
     """
     The name of the SourceFile
     """
     return ostools.simplify_path(self._source_file.name)
コード例 #10
0
    def compile_source_files(
        self,
        project,
        printer=NO_COLOR_PRINTER,
        continue_on_error=False,
        target_files=None,
    ):
        """
        Use compile_source_file_command to compile all source_files
        param: target_files: Given a list of SourceFiles only these and dependent files are compiled
        """
        dependency_graph = project.create_dependency_graph()
        failures = []

        if target_files is None:
            source_files = project.get_files_in_compile_order(
                dependency_graph=dependency_graph)
        else:
            source_files = project.get_minimal_file_set_in_compile_order(
                target_files)

        source_files_to_skip = set()

        max_library_name = 0
        max_source_file_name = 0
        if source_files:
            max_library_name = max(
                len(source_file.library.name) for source_file in source_files)
            max_source_file_name = max(
                len(simplify_path(source_file.name))
                for source_file in source_files)

        for source_file in source_files:
            printer.write("Compiling into %s %s " % (
                (source_file.library.name + ":").ljust(max_library_name + 1),
                simplify_path(source_file.name).ljust(max_source_file_name),
            ))
            sys.stdout.flush()

            if source_file in source_files_to_skip:
                printer.write("skipped", fg="rgi")
                printer.write("\n")
                continue

            if self.__compile_source_file(source_file, printer):
                project.update(source_file)
            else:
                source_files_to_skip.update(
                    dependency_graph.get_dependent([source_file]))
                failures.append(source_file)

                if not continue_on_error:
                    break

        if failures:
            printer.write("Compile failed\n", fg="ri")
            raise CompileError

        if source_files:
            printer.write("Compile passed\n", fg="gi")
        else:
            printer.write("Re-compile not needed\n")
コード例 #11
0
 def name(self):
     """
     The name of the SourceFile
     """
     return ostools.simplify_path(self._source_file.name)