Skip to content

Commit 3a01862

Browse files
authored
Merge pull request #1967 from screamerbg/fix-double-ignores
Fixed double-ignored files that cause python exception
2 parents 76c8be6 + e835c48 commit 3a01862

File tree

1 file changed

+57
-43
lines changed

1 file changed

+57
-43
lines changed

tools/toolchains/__init__.py

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ def __str__(self):
210210

211211
class mbedToolchain:
212212
VERBOSE = True
213-
ignorepatterns = []
214213

215214
CORTEX_SYMBOLS = {
216215
"Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
@@ -230,48 +229,70 @@ class mbedToolchain:
230229
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
231230
self.target = target
232231
self.name = self.__class__.__name__
232+
233+
# compile/assemble/link/binary hooks
233234
self.hook = hooks.Hook(target, self)
234-
self.silent = silent
235-
self.output = ""
236-
237-
self.legacy_ignore_dirs = LEGACY_IGNORE_DIRS - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]])
238-
239-
if notify:
240-
self.notify_fun = notify
241-
elif extra_verbose:
242-
self.notify_fun = self.print_notify_verbose
243-
else:
244-
self.notify_fun = self.print_notify
245235

236+
# Build options passed by -o flag
246237
self.options = options if options is not None else []
247-
248-
self.macros = macros or []
249238
self.options.extend(BUILD_OPTIONS)
250239
if self.options:
251240
self.info("Build Options: %s" % (', '.join(self.options)))
252241

253-
self.obj_path = join("TARGET_"+target.name, "TOOLCHAIN_"+self.name)
254-
242+
# Toolchain flags
243+
self.flags = deepcopy(self.DEFAULT_FLAGS)
244+
245+
# User-defined macros
246+
self.macros = macros or []
247+
248+
# Macros generated from toolchain and target rules/features
255249
self.symbols = None
250+
251+
# Labels generated from toolchain and target rules/features (used for selective build)
256252
self.labels = None
253+
257254
self.has_config = False
255+
# config_header_content will hold the content of the config header (if used)
256+
self.config_header_content = None
258257

258+
# Non-incremental compile
259259
self.build_all = False
260+
261+
# Build output dir
260262
self.build_dir = None
261263
self.timestamp = time()
262-
self.jobs = 1
263264

264-
self.CHROOT = None
265+
# Output build naming based on target+toolchain combo (mbed 2.0 builds)
266+
self.obj_path = join("TARGET_"+target.name, "TOOLCHAIN_"+self.name)
267+
268+
# Number of concurrent build jobs. 0 means auto (based on host system cores)
269+
self.jobs = 0
265270

266-
self.mp_pool = None
271+
self.CHROOT = None
267272

273+
# Ignore patterns from .mbedignore files
274+
self.ignore_patterns = []
275+
276+
# Pre-mbed 2.0 ignore dirs
277+
self.legacy_ignore_dirs = LEGACY_IGNORE_DIRS - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]])
278+
279+
# Output notify function
280+
if notify:
281+
self.notify_fun = notify
282+
elif extra_verbose:
283+
self.notify_fun = self.print_notify_verbose
284+
else:
285+
self.notify_fun = self.print_notify
286+
287+
# Silent builds (no output)
288+
self.silent = silent
289+
290+
# Print output buffer
291+
self.output = ""
292+
293+
# uVisor spepcific rules
268294
if 'UVISOR' in self.target.features and 'UVISOR_SUPPORTED' in self.target.extra_labels:
269295
self.target.core = re.sub(r"F$", '', self.target.core)
270-
271-
self.flags = deepcopy(self.DEFAULT_FLAGS)
272-
273-
# config_header_content will hold the content of the config header (if used)
274-
self.config_header_content = None
275296

276297
def get_output(self):
277298
return self.output
@@ -325,10 +346,6 @@ def notify(self, event):
325346
"""
326347
return self.notify_fun(event, self.silent)
327348

328-
def __exit__(self):
329-
if self.mp_pool is not None:
330-
self.mp_pool.terminate()
331-
332349
def goanna_parse_line(self, line):
333350
if "analyze" in self.options:
334351
return self.GOANNA_DIAGNOSTIC_PATTERN.match(line)
@@ -407,7 +424,7 @@ def need_update(self, target, dependencies):
407424
return False
408425

409426
def is_ignored(self, file_path):
410-
for pattern in self.ignorepatterns:
427+
for pattern in self.ignore_patterns:
411428
if fnmatch.fnmatch(file_path, pattern):
412429
return True
413430
return False
@@ -441,33 +458,30 @@ def scan_resources(self, path, exclude_paths=None, base_path=None):
441458
lines = [l.strip() for l in lines] # Strip whitespaces
442459
lines = [l for l in lines if l != ""] # Strip empty lines
443460
lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
444-
# Append root path to glob patterns
445-
# and append patterns to ignorepatterns
446-
self.ignorepatterns.extend([join(root,line.strip()) for line in lines])
461+
# Append root path to glob patterns and append patterns to ignore_patterns
462+
self.ignore_patterns.extend([join(root,line.strip()) for line in lines])
447463

448464
for d in copy(dirs):
449465
dir_path = join(root, d)
450466
if d == '.hg':
451467
resources.repo_dirs.append(dir_path)
452468
resources.repo_files.extend(self.scan_repository(dir_path))
453-
469+
454470
if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
471+
# Ignore targets that do not match the TARGET in extra_labels list
455472
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
473+
# Ignore toolchain that do not match the current TOOLCHAIN
456474
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
475+
# Ignore .mbedignore files
476+
self.is_ignored(join(dir_path,"")) or
477+
# Ignore TESTS dir
457478
(d == 'TESTS')):
458479
dirs.remove(d)
459-
460-
if (d.startswith('FEATURE_')):
480+
elif d.startswith('FEATURE_'):
481+
# Recursively scan features but ignore them in the current scan. These are dynamically added by the config system if the conditions are matched
461482
resources.features[d[8:]] = self.scan_resources(dir_path, base_path=base_path)
462483
dirs.remove(d)
463-
464-
# Remove dirs that already match the ignorepatterns
465-
# to avoid travelling into them and to prevent them
466-
# on appearing in include path.
467-
if self.is_ignored(join(dir_path,"")):
468-
dirs.remove(d)
469-
470-
if exclude_paths:
484+
elif exclude_paths:
471485
for exclude_path in exclude_paths:
472486
rel_path = relpath(dir_path, exclude_path)
473487
if not (rel_path.startswith('..')):

0 commit comments

Comments
 (0)