@@ -507,11 +507,26 @@ def need_update(self, target, dependencies):
507
507
return False
508
508
509
509
def is_ignored (self , file_path ):
510
+ """Check if file path is ignored by any .mbedignore thus far"""
510
511
for pattern in self .ignore_patterns :
511
512
if fnmatch .fnmatch (file_path , pattern ):
512
513
return True
513
514
return False
514
515
516
+ def add_ignore_patterns (self , root , base_path , patterns ):
517
+ """Add a series of patterns to the ignored paths
518
+
519
+ Positional arguments:
520
+ root - the directory containing the ignore file
521
+ base_path - the location that the scan started from
522
+ patterns - the list of patterns we will ignore in the future
523
+ """
524
+ real_base = relpath (root , base_path )
525
+ if real_base == "." :
526
+ self .ignore_patterns .extend (patterns )
527
+ else :
528
+ self .ignore_patterns .extend (join (real_base , pat ) for pat in patterns )
529
+
515
530
# Create a Resources object from the path pointed to by *path* by either traversing a
516
531
# a directory structure, when *path* is a directory, or adding *path* to the resources,
517
532
# when *path* is a file.
@@ -559,10 +574,11 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
559
574
lines = [l for l in lines if l != "" ] # Strip empty lines
560
575
lines = [l for l in lines if not re .match ("^#" ,l )] # Strip comment lines
561
576
# 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 ] )
577
+ self .add_ignore_patterns ( root , base_path , lines )
563
578
564
579
# Skip the whole folder if ignored, e.g. .mbedignore containing '*'
565
- if self .is_ignored (join (root ,"" )):
580
+ if self .is_ignored (join (relpath (root , base_path ),"" )):
581
+ dirs [:] = []
566
582
continue
567
583
568
584
for d in copy (dirs ):
@@ -577,7 +593,7 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
577
593
# Ignore toolchain that do not match the current TOOLCHAIN
578
594
(d .startswith ('TOOLCHAIN_' ) and d [10 :] not in labels ['TOOLCHAIN' ]) or
579
595
# Ignore .mbedignore files
580
- self .is_ignored (join (dir_path ,"" )) or
596
+ self .is_ignored (join (relpath ( root , base_path ), d ,"" )) or
581
597
# Ignore TESTS dir
582
598
(d == 'TESTS' )):
583
599
dirs .remove (d )
@@ -606,7 +622,7 @@ def _add_dir(self, path, resources, base_path, exclude_paths=None):
606
622
def _add_file (self , file_path , resources , base_path , exclude_paths = None ):
607
623
resources .file_basepath [file_path ] = base_path
608
624
609
- if self .is_ignored (file_path ):
625
+ if self .is_ignored (relpath ( file_path , base_path ) ):
610
626
return
611
627
612
628
_ , ext = splitext (file_path )
0 commit comments