17
17
18
18
import re
19
19
import sys
20
- from os import stat , walk , getcwd
20
+ from os import stat , walk , getcwd , sep
21
21
from copy import copy
22
22
from time import time , sleep
23
23
from types import ListType
32
32
from tools .settings import BUILD_OPTIONS , MBED_ORG_USER
33
33
import tools .hooks as hooks
34
34
from hashlib import md5
35
+ import fnmatch
35
36
36
37
37
38
#Disables multiprocessing if set to higher number than the host machine CPUs
@@ -167,6 +168,7 @@ def __str__(self):
167
168
168
169
class mbedToolchain :
169
170
VERBOSE = True
171
+ ignorepatterns = []
170
172
171
173
CORTEX_SYMBOLS = {
172
174
"Cortex-M0" : ["__CORTEX_M0" , "ARM_MATH_CM0" , "__CMSIS_RTOS" , "__MBED_CMSIS_RTOS_CM" ],
@@ -345,6 +347,12 @@ def need_update(self, target, dependencies):
345
347
346
348
return False
347
349
350
+ def is_ignored (self , file_path ):
351
+ for pattern in self .ignorepatterns :
352
+ if fnmatch .fnmatch (file_path , pattern ):
353
+ return True
354
+ return False
355
+
348
356
def scan_resources (self , path , exclude_paths = None ):
349
357
labels = self .get_labels ()
350
358
resources = Resources (path )
@@ -372,10 +380,28 @@ def scan_resources(self, path, exclude_paths=None):
372
380
if ((d .startswith ('.' ) or d in self .legacy_ignore_dirs ) or
373
381
(d .startswith ('TARGET_' ) and d [7 :] not in labels ['TARGET' ]) or
374
382
(d .startswith ('TOOLCHAIN_' ) and d [10 :] not in labels ['TOOLCHAIN' ]) or
375
- (d == 'TESTS' ) or
376
- exists (join (dir_path , '.buildignore' ))):
383
+ (d == 'TESTS' )):
377
384
dirs .remove (d )
378
-
385
+
386
+ # Check if folder contains .mbedignore
387
+ try :
388
+ with open (join (dir_path ,".mbedignore" ), "r" ) as f :
389
+ lines = f .readlines ()
390
+ lines = [l .strip () for l in lines ] # Strip whitespaces
391
+ lines = [l for l in lines if l != "" ] # Strip empty lines
392
+ lines = [l for l in lines if not re .match ("^#" ,l )] # Strip comment lines
393
+ # Append root path to glob patterns
394
+ # and append patterns to ignorepatterns
395
+ self .ignorepatterns .extend ([join (dir_path ,line .strip ()) for line in lines ])
396
+ except IOError :
397
+ pass
398
+
399
+ # Remove dirs that already match the ignorepatterns
400
+ # to avoid travelling into them and to prevent them
401
+ # on appearing in include path.
402
+ if self .is_ignored (join (dir_path ,"" )):
403
+ dirs .remove (d )
404
+
379
405
if exclude_paths :
380
406
for exclude_path in exclude_paths :
381
407
rel_path = relpath (dir_path , exclude_path )
@@ -388,6 +414,10 @@ def scan_resources(self, path, exclude_paths=None):
388
414
389
415
for file in files :
390
416
file_path = join (root , file )
417
+
418
+ if self .is_ignored (file_path ):
419
+ continue
420
+
391
421
_ , ext = splitext (file )
392
422
ext = ext .lower ()
393
423
0 commit comments