Skip to content

Commit 6c3ce1e

Browse files
committed
Merge pull request #112 from SeppoTakalo/master
Implement the .mbedignore functionality.
2 parents 20a80cd + 3d3b0a7 commit 6c3ce1e

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

tools/toolchains/__init__.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import re
1919
import sys
20-
from os import stat, walk, getcwd
20+
from os import stat, walk, getcwd, sep
2121
from copy import copy
2222
from time import time, sleep
2323
from types import ListType
@@ -32,6 +32,7 @@
3232
from tools.settings import BUILD_OPTIONS, MBED_ORG_USER
3333
import tools.hooks as hooks
3434
from hashlib import md5
35+
import fnmatch
3536

3637

3738
#Disables multiprocessing if set to higher number than the host machine CPUs
@@ -167,6 +168,7 @@ def __str__(self):
167168

168169
class mbedToolchain:
169170
VERBOSE = True
171+
ignorepatterns = []
170172

171173
CORTEX_SYMBOLS = {
172174
"Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
@@ -345,6 +347,12 @@ def need_update(self, target, dependencies):
345347

346348
return False
347349

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+
348356
def scan_resources(self, path, exclude_paths=None):
349357
labels = self.get_labels()
350358
resources = Resources(path)
@@ -372,10 +380,28 @@ def scan_resources(self, path, exclude_paths=None):
372380
if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
373381
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
374382
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
375-
(d == 'TESTS') or
376-
exists(join(dir_path, '.buildignore'))):
383+
(d == 'TESTS')):
377384
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+
379405
if exclude_paths:
380406
for exclude_path in exclude_paths:
381407
rel_path = relpath(dir_path, exclude_path)
@@ -388,6 +414,10 @@ def scan_resources(self, path, exclude_paths=None):
388414

389415
for file in files:
390416
file_path = join(root, file)
417+
418+
if self.is_ignored(file_path):
419+
continue
420+
391421
_, ext = splitext(file)
392422
ext = ext.lower()
393423

0 commit comments

Comments
 (0)