Skip to content

Refactor scan resources to account for base_paths #3560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,26 @@ def need_update(self, target, dependencies):
return False

def is_ignored(self, file_path):
"""Check if file path is ignored by any .mbedignore thus far"""
for pattern in self.ignore_patterns:
if fnmatch.fnmatch(file_path, pattern):
return True
return False

def add_ignore_patterns(self, root, base_path, patterns):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a doc string to this? root and base_path are a bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

"""Add a series of patterns to the ignored paths

Positional arguments:
root - the directory containing the ignore file
base_path - the location that the scan started from
patterns - the list of patterns we will ignore in the future
"""
real_base = relpath(root, base_path)
if real_base == ".":
self.ignore_patterns.extend(patterns)
else:
self.ignore_patterns.extend(join(real_base, pat) for pat in patterns)

# Create a Resources object from the path pointed to by *path* by either traversing a
# a directory structure, when *path* is a directory, or adding *path* to the resources,
# when *path* is a file.
Expand Down Expand Up @@ -559,10 +574,11 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
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])
self.add_ignore_patterns(root, base_path, lines)

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

for d in copy(dirs):
Expand All @@ -577,7 +593,7 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
# 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
self.is_ignored(join(relpath(root, base_path), d,"")) or
Copy link
Contributor

@bridadan bridadan Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this was here before, but do you know why the path is being joined with ""?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get that extra "/" on the end.

# Ignore TESTS dir
(d == 'TESTS')):
dirs.remove(d)
Expand Down Expand Up @@ -606,7 +622,7 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
def _add_file(self, file_path, resources, base_path, exclude_paths=None):
resources.file_basepath[file_path] = base_path

if self.is_ignored(file_path):
if self.is_ignored(relpath(file_path, base_path)):
return

_, ext = splitext(file_path)
Expand Down