Skip to content

Commit 39a5caa

Browse files
committed
Refactor scan resources to account for base_paths
1 parent ccab2c5 commit 39a5caa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tools/toolchains/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ def is_ignored(self, file_path):
512512
return True
513513
return False
514514

515+
def add_ignore_patterns(self, root, base_path, patterns):
516+
real_base = relpath(root, base_path)
517+
if real_base == ".":
518+
self.ignore_patterns.extend(patterns)
519+
else:
520+
self.ignore_patterns.extend(join(real_base, pat) for pat in patterns)
521+
515522
# Create a Resources object from the path pointed to by *path* by either traversing a
516523
# a directory structure, when *path* is a directory, or adding *path* to the resources,
517524
# when *path* is a file.
@@ -559,10 +566,11 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
559566
lines = [l for l in lines if l != ""] # Strip empty lines
560567
lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
561568
# Append root path to glob patterns and append patterns to ignore_patterns
562-
self.ignore_patterns.extend([join(root,line.strip()) for line in lines])
569+
self.add_ignore_patterns(root, base_path, lines)
563570

564571
# Skip the whole folder if ignored, e.g. .mbedignore containing '*'
565-
if self.is_ignored(join(root,"")):
572+
if self.is_ignored(join(relpath(root, base_path),"")):
573+
dirs[:] = []
566574
continue
567575

568576
for d in copy(dirs):
@@ -577,7 +585,7 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
577585
# Ignore toolchain that do not match the current TOOLCHAIN
578586
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
579587
# Ignore .mbedignore files
580-
self.is_ignored(join(dir_path,"")) or
588+
self.is_ignored(join(relpath(root, base_path), d,"")) or
581589
# Ignore TESTS dir
582590
(d == 'TESTS')):
583591
dirs.remove(d)
@@ -606,7 +614,7 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
606614
def _add_file(self, file_path, resources, base_path, exclude_paths=None):
607615
resources.file_basepath[file_path] = base_path
608616

609-
if self.is_ignored(file_path):
617+
if self.is_ignored(relpath(file_path, base_path)):
610618
return
611619

612620
_, ext = splitext(file_path)

0 commit comments

Comments
 (0)