Clone of official tools

Revision:
35:da9c89f8be7d
Parent:
31:8ea194f6145b
Child:
36:96847d42f010
--- a/toolchains/__init__.py	Mon Feb 13 09:29:13 2017 -0600
+++ b/toolchains/__init__.py	Wed Feb 15 13:53:18 2017 -0600
@@ -266,6 +266,9 @@
         # Toolchain flags
         self.flags = deepcopy(build_profile or self.profile_template)
 
+        # System libraries provided by the toolchain
+        self.sys_libs = []
+
         # User-defined macros
         self.macros = macros or []
 
@@ -507,11 +510,26 @@
         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):
+        """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.
@@ -559,10 +577,11 @@
                     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):
@@ -577,7 +596,7 @@
                     # 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
                     # Ignore TESTS dir
                     (d == 'TESTS')):
                         dirs.remove(d)
@@ -606,7 +625,7 @@
     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)