Beispiel #1
0
    def scan_resources(self, path, exclude_paths=None, base_path=None):
        labels = self.get_labels()

        resources = Resources(path)
        if not base_path:
            base_path = path
        resources.base_path = base_path

        """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
        When topdown is True, the caller can modify the dirnames list in-place
        (perhaps using del or slice assignment), and walk() will only recurse into
        the subdirectories whose names remain in dirnames; this can be used to prune
        the search, impose a specific order of visiting, or even to inform walk()
        about directories the caller creates or renames before it resumes walk()
        again. Modifying dirnames when topdown is False is ineffective, because in
        bottom-up mode the directories in dirnames are generated before dirpath
        itself is generated.
        """
        for root, dirs, files in walk(path, followlinks=True):
            # Check if folder contains .mbedignore
            if ".mbedignore" in files:
                with open(join(root, ".mbedignore"), "r") as f:
                    lines = f.readlines()
                    lines = [l.strip() for l in lines]  # Strip whitespaces
                    lines = [l for l in lines if l != ""]  # Strip empty lines
                    lines = [l for l in lines if not re.match("^#", l)]  # Strip comment lines
                    # Append root path to glob patterns and append patterns to ignore_patterns
                    self.ignore_patterns.extend([join(root, line.strip()) for line in lines])

            # Skip the whole folder if ignored, e.g. .mbedignore containing '*'
            if self.is_ignored(join(root, "")):
                continue

            for d in copy(dirs):
                dir_path = join(root, d)
                # Add internal repo folders/files. This is needed for exporters
                if d == ".hg":
                    resources.repo_dirs.append(dir_path)
                    resources.repo_files.extend(self.scan_repository(dir_path))

                if (
                    (d.startswith(".") or d in self.legacy_ignore_dirs)
                    or
                    # Ignore targets that do not match the TARGET in extra_labels list
                    (d.startswith("TARGET_") and d[7:] not in labels["TARGET"])
                    or
                    # Ignore toolchain that do not match the current TOOLCHAIN
                    (d.startswith("TOOLCHAIN_") and d[10:] not in labels["TOOLCHAIN"])
                    or
                    # Ignore .mbedignore files
                    self.is_ignored(join(dir_path, ""))
                    or
                    # Ignore TESTS dir
                    (d == "TESTS")
                ):
                    dirs.remove(d)
                elif d.startswith("FEATURE_"):
                    # Recursively scan features but ignore them in the current scan.
                    # These are dynamically added by the config system if the conditions are matched
                    resources.features[d[8:]] = self.scan_resources(dir_path, base_path=base_path)
                    dirs.remove(d)
                elif exclude_paths:
                    for exclude_path in exclude_paths:
                        rel_path = relpath(dir_path, exclude_path)
                        if not (rel_path.startswith("..")):
                            dirs.remove(d)
                            break

            # Add root to include paths
            resources.inc_dirs.append(root)

            for file in files:
                file_path = join(root, file)

                resources.file_basepath[file_path] = base_path

                if self.is_ignored(file_path):
                    continue

                _, ext = splitext(file)
                ext = ext.lower()

                if ext == ".s":
                    resources.s_sources.append(file_path)

                elif ext == ".c":
                    resources.c_sources.append(file_path)

                elif ext == ".cpp":
                    resources.cpp_sources.append(file_path)

                elif ext == ".h" or ext == ".hpp":
                    resources.headers.append(file_path)

                elif ext == ".o":
                    resources.objects.append(file_path)

                elif ext == self.LIBRARY_EXT:
                    resources.libraries.append(file_path)
                    resources.lib_dirs.add(root)

                elif ext == self.LINKER_EXT:
                    if resources.linker_script is not None:
                        self.info(
                            "Warning: Multiple linker scripts detected: %s -> %s" % (resources.linker_script, file_path)
                        )
                    resources.linker_script = file_path

                elif ext == ".lib":
                    resources.lib_refs.append(file_path)

                elif ext == ".bld":
                    resources.lib_builds.append(file_path)

                elif file == ".hgignore":
                    resources.repo_files.append(file_path)

                elif ext == ".hex":
                    resources.hex_files.append(file_path)

                elif ext == ".bin":
                    resources.bin_files.append(file_path)

                elif ext == ".json":
                    resources.json_files.append(file_path)

        return resources
Beispiel #2
0
    def scan_resources(self, path, exclude_paths=None):
        labels = self.get_labels()
        resources = Resources(path)
        self.has_config = False

        """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
        When topdown is True, the caller can modify the dirnames list in-place
        (perhaps using del or slice assignment), and walk() will only recurse into
        the subdirectories whose names remain in dirnames; this can be used to prune
        the search, impose a specific order of visiting, or even to inform walk()
        about directories the caller creates or renames before it resumes walk()
        again. Modifying dirnames when topdown is False is ineffective, because in
        bottom-up mode the directories in dirnames are generated before dirpath
        itself is generated.
        """
        for root, dirs, files in walk(path, followlinks=True):
            # Remove ignored directories
            # Check if folder contains .mbedignore
            if ".mbedignore" in files :
                with open (join(root,".mbedignore"), "r") as f:
                    lines=f.readlines()
                    lines = [l.strip() for l in lines] # Strip whitespaces
                    lines = [l for l in lines if l != ""] # Strip empty lines
                    lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
                    # Append root path to glob patterns
                    # and append patterns to ignorepatterns
                    self.ignorepatterns.extend([join(root,line.strip()) for line in lines])

            for d in copy(dirs):
                dir_path = join(root, d)
                if d == '.hg':
                    resources.repo_dirs.append(dir_path)
                    resources.repo_files.extend(self.scan_repository(dir_path))

                if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
                    (d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
                    (d.startswith('FEATURE_') and d[8:] not in labels['FEATURE']) or
                    (d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
                    (d == 'TESTS')):
                    dirs.remove(d)


                # Remove dirs that already match the ignorepatterns
                # to avoid travelling into them and to prevent them
                # on appearing in include path.
                if self.is_ignored(join(dir_path,"")):
                    dirs.remove(d)

                if exclude_paths:
                    for exclude_path in exclude_paths:
                        rel_path = relpath(dir_path, exclude_path)
                        if not (rel_path.startswith('..')):
                            dirs.remove(d)
                            break

            # Add root to include paths
            resources.inc_dirs.append(root)

            for file in files:
                file_path = join(root, file)

                if self.is_ignored(file_path):
                    continue

                _, ext = splitext(file)
                ext = ext.lower()

                if   ext == '.s':
                    resources.s_sources.append(file_path)

                elif ext == '.c':
                    resources.c_sources.append(file_path)

                elif ext == '.cpp':
                    resources.cpp_sources.append(file_path)

                elif ext == '.h' or ext == '.hpp':
                    if basename(file_path) == "mbed_config.h":
                        self.has_config = True
                    resources.headers.append(file_path)

                elif ext == '.o':
                    resources.objects.append(file_path)

                elif ext == self.LIBRARY_EXT:
                    resources.libraries.append(file_path)
                    resources.lib_dirs.add(root)

                elif ext == self.LINKER_EXT:
                    if resources.linker_script is not None:
                        self.info("Warning: Multiple linker scripts detected: %s -> %s" % (resources.linker_script, file_path))
                    resources.linker_script = file_path

                elif ext == '.lib':
                    resources.lib_refs.append(file_path)

                elif ext == '.bld':
                    resources.lib_builds.append(file_path)

                elif file == '.hgignore':
                    resources.repo_files.append(file_path)

                elif ext == '.hex':
                    resources.hex_files.append(file_path)

                elif ext == '.bin':
                    resources.bin_files.append(file_path)

                elif ext == '.json':
                    resources.json_files.append(file_path)

        return resources
Beispiel #3
0
    def _add_dir(self, path, resources, base_path, exclude_paths=None):
        """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
        When topdown is True, the caller can modify the dirnames list in-place
        (perhaps using del or slice assignment), and walk() will only recurse into
        the subdirectories whose names remain in dirnames; this can be used to prune
        the search, impose a specific order of visiting, or even to inform walk()
        about directories the caller creates or renames before it resumes walk()
        again. Modifying dirnames when topdown is False is ineffective, because in
        bottom-up mode the directories in dirnames are generated before dirpath
        itself is generated.
        """
        labels = self.get_labels()
        for root, dirs, files in walk(path, followlinks=True):
            # Check if folder contains .mbedignore
            if ".mbedignore" in files:
                with open (join(root,".mbedignore"), "r") as f:
                    lines=f.readlines()
                    lines = [l.strip() for l in lines] # Strip whitespaces
                    lines = [l for l in lines if l != ""] # Strip empty lines
                    lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
                    # Append root path to glob patterns and append patterns to ignore_patterns
                    self.ignore_patterns.extend([join(root,line.strip()) for line in lines])

            # Skip the whole folder if ignored, e.g. .mbedignore containing '*'
            if self.is_ignored(join(root,"")):
                continue

            for d in copy(dirs):
                dir_path = join(root, d)
                # Add internal repo folders/files. This is needed for exporters
                if d == '.hg' or d == '.git':
                    resources.repo_dirs.append(dir_path)

                if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
                    # Ignore targets that do not match the TARGET in extra_labels list
                    (d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
                    # Ignore toolchain that do not match the current TOOLCHAIN
                    (d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
                    # Ignore .mbedignore files
                    self.is_ignored(join(dir_path,"")) or
                    # Ignore TESTS dir
                    (d == 'TESTS')):
                        dirs.remove(d)
                elif d.startswith('FEATURE_'):
                    # Recursively scan features but ignore them in the current scan.
                    # These are dynamically added by the config system if the conditions are matched
                    resources.features[d[8:]] = self.scan_resources(dir_path, base_path=base_path)
                    dirs.remove(d)
                elif exclude_paths:
                    for exclude_path in exclude_paths:
                        rel_path = relpath(dir_path, exclude_path)
                        if not (rel_path.startswith('..')):
                            dirs.remove(d)
                            break

            # Add root to include paths
            resources.inc_dirs.append(root)

            for file in files:
                file_path = join(root, file)
                self._add_file(file_path, resources, base_path)
Beispiel #4
0
    def _add_dir(self, path, resources, base_path, exclude_paths=None):
        """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
        When topdown is True, the caller can modify the dirnames list in-place
        (perhaps using del or slice assignment), and walk() will only recurse into
        the subdirectories whose names remain in dirnames; this can be used to prune
        the search, impose a specific order of visiting, or even to inform walk()
        about directories the caller creates or renames before it resumes walk()
        again. Modifying dirnames when topdown is False is ineffective, because in
        bottom-up mode the directories in dirnames are generated before dirpath
        itself is generated.
        """
        labels = self.get_labels()
        for root, dirs, files in walk(path, followlinks=True):
            # Check if folder contains .mbedignore
            if ".mbedignore" in files:
                with open (join(root,".mbedignore"), "r") as f:
                    lines=f.readlines()
                    lines = [l.strip() for l in lines] # Strip whitespaces
                    lines = [l for l in lines if l != ""] # Strip empty lines
                    lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
                    # Append root path to glob patterns and append patterns to ignore_patterns
                    self.ignore_patterns.extend([join(root,line.strip()) for line in lines])

            # Skip the whole folder if ignored, e.g. .mbedignore containing '*'
            if self.is_ignored(join(root,"")):
                continue

            for d in copy(dirs):
                dir_path = join(root, d)
                # Add internal repo folders/files. This is needed for exporters
                if d == '.hg' or d == '.git':
                    resources.repo_dirs.append(dir_path)

                if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
                    # Ignore targets that do not match the TARGET in extra_labels list
                    (d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
                    # Ignore toolchain that do not match the current TOOLCHAIN
                    (d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
                    # Ignore .mbedignore files
                    self.is_ignored(join(dir_path,"")) or
                    # Ignore TESTS dir
                    (d == 'TESTS')):
                        dirs.remove(d)
                elif d.startswith('FEATURE_'):
                    # Recursively scan features but ignore them in the current scan.
                    # These are dynamically added by the config system if the conditions are matched
                    resources.features[d[8:]] = self.scan_resources(dir_path, base_path=base_path)
                    dirs.remove(d)
                elif exclude_paths:
                    for exclude_path in exclude_paths:
                        rel_path = relpath(dir_path, exclude_path)
                        if not (rel_path.startswith('..')):
                            dirs.remove(d)
                            break

            # Add root to include paths
            resources.inc_dirs.append(root)

            for file in files:
                file_path = join(root, file)
                self._add_file(file_path, resources, base_path)
Beispiel #5
0
    def scan_resources(self, path, exclude_paths=None):
        labels = self.get_labels()
        resources = Resources(path)
        self.has_config = False
        """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
        When topdown is True, the caller can modify the dirnames list in-place
        (perhaps using del or slice assignment), and walk() will only recurse into
        the subdirectories whose names remain in dirnames; this can be used to prune
        the search, impose a specific order of visiting, or even to inform walk()
        about directories the caller creates or renames before it resumes walk()
        again. Modifying dirnames when topdown is False is ineffective, because in
        bottom-up mode the directories in dirnames are generated before dirpath
        itself is generated.
        """
        for root, dirs, files in walk(path, followlinks=True):
            # Remove ignored directories
            # Check if folder contains .mbedignore
            if ".mbedignore" in files:
                with open(join(root, ".mbedignore"), "r") as f:
                    lines = f.readlines()
                    lines = [l.strip() for l in lines]  # Strip whitespaces
                    lines = [l for l in lines if l != ""]  # Strip empty lines
                    lines = [l for l in lines
                             if not re.match("^#", l)]  # Strip comment lines
                    # Append root path to glob patterns
                    # and append patterns to ignorepatterns
                    self.ignorepatterns.extend(
                        [join(root, line.strip()) for line in lines])

            for d in copy(dirs):
                dir_path = join(root, d)
                if d == '.hg':
                    resources.repo_dirs.append(dir_path)
                    resources.repo_files.extend(self.scan_repository(dir_path))

                if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
                    (d.startswith('TARGET_') and d[7:] not in labels['TARGET'])
                        or (d.startswith('FEATURE_')
                            and d[8:] not in labels['FEATURE'])
                        or (d.startswith('TOOLCHAIN_')
                            and d[10:] not in labels['TOOLCHAIN'])
                        or (d == 'TESTS')):
                    dirs.remove(d)

                # Remove dirs that already match the ignorepatterns
                # to avoid travelling into them and to prevent them
                # on appearing in include path.
                if self.is_ignored(join(dir_path, "")):
                    dirs.remove(d)

                if exclude_paths:
                    for exclude_path in exclude_paths:
                        rel_path = relpath(dir_path, exclude_path)
                        if not (rel_path.startswith('..')):
                            dirs.remove(d)
                            break

            # Add root to include paths
            resources.inc_dirs.append(root)

            for file in files:
                file_path = join(root, file)

                if self.is_ignored(file_path):
                    continue

                _, ext = splitext(file)
                ext = ext.lower()

                if ext == '.s':
                    resources.s_sources.append(file_path)

                elif ext == '.c':
                    resources.c_sources.append(file_path)

                elif ext == '.cpp':
                    resources.cpp_sources.append(file_path)

                elif ext == '.h' or ext == '.hpp':
                    if basename(file_path) == "mbed_config.h":
                        self.has_config = True
                    resources.headers.append(file_path)

                elif ext == '.o':
                    resources.objects.append(file_path)

                elif ext == self.LIBRARY_EXT:
                    resources.libraries.append(file_path)
                    resources.lib_dirs.add(root)

                elif ext == self.LINKER_EXT:
                    if resources.linker_script is not None:
                        self.info(
                            "Warning: Multiple linker scripts detected: %s -> %s"
                            % (resources.linker_script, file_path))
                    resources.linker_script = file_path

                elif ext == '.lib':
                    resources.lib_refs.append(file_path)

                elif ext == '.bld':
                    resources.lib_builds.append(file_path)

                elif file == '.hgignore':
                    resources.repo_files.append(file_path)

                elif ext == '.hex':
                    resources.hex_files.append(file_path)

                elif ext == '.bin':
                    resources.bin_files.append(file_path)

                elif ext == '.json':
                    resources.json_files.append(file_path)

        return resources
Beispiel #6
0
    def scan_resources(self, path, exclude_paths=None, base_path=None):
        labels = self.get_labels()

        resources = Resources(path)
        if not base_path:
            base_path = path
        resources.base_path = base_path
        """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
        When topdown is True, the caller can modify the dirnames list in-place
        (perhaps using del or slice assignment), and walk() will only recurse into
        the subdirectories whose names remain in dirnames; this can be used to prune
        the search, impose a specific order of visiting, or even to inform walk()
        about directories the caller creates or renames before it resumes walk()
        again. Modifying dirnames when topdown is False is ineffective, because in
        bottom-up mode the directories in dirnames are generated before dirpath
        itself is generated.
        """
        for root, dirs, files in walk(path, followlinks=True):
            # Check if folder contains .mbedignore
            if ".mbedignore" in files:
                with open(join(root, ".mbedignore"), "r") as f:
                    lines = f.readlines()
                    lines = [l.strip() for l in lines]  # Strip whitespaces
                    lines = [l for l in lines if l != ""]  # Strip empty lines
                    lines = [l for l in lines
                             if not re.match("^#", l)]  # Strip comment lines
                    # Append root path to glob patterns and append patterns to ignore_patterns
                    self.ignore_patterns.extend(
                        [join(root, line.strip()) for line in lines])

            # Skip the whole folder if ignored, e.g. .mbedignore containing '*'
            if self.is_ignored(join(root, "")):
                continue

            for d in copy(dirs):
                dir_path = join(root, d)
                # Add internal repo folders/files. This is needed for exporters
                if d == '.hg':
                    resources.repo_dirs.append(dir_path)
                    resources.repo_files.extend(self.scan_repository(dir_path))

                if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
                        # Ignore targets that do not match the TARGET in extra_labels list
                    (d.startswith('TARGET_') and d[7:] not in labels['TARGET'])
                        or
                        # Ignore toolchain that do not match the current TOOLCHAIN
                    (d.startswith('TOOLCHAIN_')
                     and d[10:] not in labels['TOOLCHAIN']) or
                        # Ignore .mbedignore files
                        self.is_ignored(join(dir_path, "")) or
                        # Ignore TESTS dir
                    (d == 'TESTS')):
                    dirs.remove(d)
                elif d.startswith('FEATURE_'):
                    # Recursively scan features but ignore them in the current scan.
                    # These are dynamically added by the config system if the conditions are matched
                    resources.features[d[8:]] = self.scan_resources(
                        dir_path, base_path=base_path)
                    dirs.remove(d)
                elif exclude_paths:
                    for exclude_path in exclude_paths:
                        rel_path = relpath(dir_path, exclude_path)
                        if not (rel_path.startswith('..')):
                            dirs.remove(d)
                            break

            # Add root to include paths
            resources.inc_dirs.append(root)

            for file in files:
                file_path = join(root, file)

                resources.file_basepath[file_path] = base_path

                if self.is_ignored(file_path):
                    continue

                _, ext = splitext(file)
                ext = ext.lower()

                if ext == '.s':
                    resources.s_sources.append(file_path)

                elif ext == '.c':
                    resources.c_sources.append(file_path)

                elif ext == '.cpp':
                    resources.cpp_sources.append(file_path)

                elif ext == '.h' or ext == '.hpp':
                    resources.headers.append(file_path)

                elif ext == '.o':
                    resources.objects.append(file_path)

                elif ext == self.LIBRARY_EXT:
                    resources.libraries.append(file_path)
                    resources.lib_dirs.add(root)

                elif ext == self.LINKER_EXT:
                    if resources.linker_script is not None:
                        self.info(
                            "Warning: Multiple linker scripts detected: %s -> %s"
                            % (resources.linker_script, file_path))
                    resources.linker_script = file_path

                elif ext == '.lib':
                    resources.lib_refs.append(file_path)

                elif ext == '.bld':
                    resources.lib_builds.append(file_path)

                elif file == '.hgignore':
                    resources.repo_files.append(file_path)

                elif ext == '.hex':
                    resources.hex_files.append(file_path)

                elif ext == '.bin':
                    resources.bin_files.append(file_path)

                elif ext == '.json':
                    resources.json_files.append(file_path)

        return resources