Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-sdk-tools by
Diff: toolchains/__init__.py
- Revision:
- 21:4fdf0dd04f6f
- Parent:
- 20:835f6355470d
- Child:
- 22:9e85236d8716
diff -r 835f6355470d -r 4fdf0dd04f6f toolchains/__init__.py --- a/toolchains/__init__.py Fri Jul 15 15:28:09 2016 +0100 +++ b/toolchains/__init__.py Fri Jul 15 22:58:15 2016 +0100 @@ -28,7 +28,7 @@ from tools.config import Config from multiprocessing import Pool, cpu_count -from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path +from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path, compile_worker from tools.settings import BUILD_OPTIONS, MBED_ORG_USER import tools.hooks as hooks from tools.memap import MemapParser @@ -38,28 +38,7 @@ #Disables multiprocessing if set to higher number than the host machine CPUs CPU_COUNT_MIN = 1 - -def compile_worker(job): - results = [] - for command in job['commands']: - try: - _, _stderr, _rc = run_cmd(command, work_dir=job['work_dir'], chroot=job['chroot']) - except KeyboardInterrupt as e: - raise ToolException - - results.append({ - 'code': _rc, - 'output': _stderr, - 'command': command - }) - - return { - 'source': job['source'], - 'object': job['object'], - 'commands': job['commands'], - 'results': results - } - +CPU_COEF = 1 class Resources: def __init__(self, base_path=None): @@ -210,6 +189,8 @@ class mbedToolchain: VERBOSE = True + COMPILE_C_AS_CPP = False + RESPONSE_FILES = True CORTEX_SYMBOLS = { "Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], @@ -223,10 +204,6 @@ "Cortex-M7FD" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], "Cortex-A9" : ["__CORTEX_A9", "ARM_MATH_CA9", "__FPU_PRESENT", "__CMSIS_RTOS", "__EVAL", "__MBED_CMSIS_RTOS_CA9"], } - - - GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%" - GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?P<severity>warning) \[(?P<file>[^:]+):(?P<line>\d+)\] \- (?P<message>.*)"') MBED_CONFIG_FILE_NAME="mbed_config.h" @@ -271,7 +248,7 @@ self.ignore_patterns = [] # Pre-mbed 2.0 ignore dirs - self.legacy_ignore_dirs = LEGACY_IGNORE_DIRS - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]]) + self.legacy_ignore_dirs = (LEGACY_IGNORE_DIRS | TOOLCHAINS) - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]]) # Output notify function if notify: @@ -325,7 +302,7 @@ elif event['type'] == 'cc': event['severity'] = event['severity'].title() event['file'] = basename(event['file']) - msg = '[%(severity)s] %(file)s@%(line)s: %(message)s' % event + msg = '[%(severity)s] %(file)s@%(line)s,%(col)s: %(message)s' % event elif event['type'] == 'progress': if not silent: @@ -360,12 +337,6 @@ """ return self.notify_fun(event, self.silent) - def goanna_parse_line(self, line): - if "analyze" in self.options: - return self.GOANNA_DIAGNOSTIC_PATTERN.match(line) - else: - return None - def get_symbols(self): if self.symbols is None: # Target and Toolchain symbols @@ -451,6 +422,8 @@ # object and the parameter *exclude_paths* is used by the directory traversal to # exclude certain paths from the traversal. def scan_resources(self, path, exclude_paths=None, base_path=None): + self.progress("scan", path) + resources = Resources(path) if not base_path: if isfile(path): @@ -498,9 +471,8 @@ for d in copy(dirs): dir_path = join(root, d) # Add internal repo folders/files. This is needed for exporters - if d == '.hg': + if d == '.hg' or d == '.git': resources.repo_dirs.append(dir_path) - resources.repo_files.extend(self.scan_repository(dir_path)) if ((d.startswith('.') or d in self.legacy_ignore_dirs) or # Ignore targets that do not match the TARGET in extra_labels list @@ -632,20 +604,6 @@ mkdir(obj_dir) return join(obj_dir, name + '.o') - def get_link_file(self, cmd): - link_file = join(self.build_dir, ".link_files.txt") - with open(link_file, "wb") as f: - cmd_list = [] - for c in cmd: - if c: - c = c.replace("\\", "/") - if self.CHROOT: - c = c.replace(self.CHROOT, '') - cmd_list.append(('"%s"' % c) if not c.startswith('-') else c) - string = " ".join(cmd_list) - f.write(string) - return link_file - def get_inc_file(self, includes): include_file = join(self.build_dir, ".includes_%s.txt" % self.inc_md5) if not exists(include_file): @@ -661,12 +619,38 @@ f.write(string) return include_file + def get_link_file(self, cmd): + link_file = join(self.build_dir, ".link_files.txt") + with open(link_file, "wb") as f: + cmd_list = [] + for c in cmd: + if c: + c = c.replace("\\", "/") + if self.CHROOT: + c = c.replace(self.CHROOT, '') + cmd_list.append(('"%s"' % c) if not c.startswith('-') else c) + string = " ".join(cmd_list) + f.write(string) + return link_file + + def get_arch_file(self, objects): + archive_file = join(self.build_dir, ".archive_files.txt") + with open(archive_file, "wb") as f: + o_list = [] + for o in objects: + o_list.append('"%s"' % o) + string = " ".join(o_list).replace("\\", "/") + f.write(string) + return archive_file + def compile_sources(self, resources, build_path, inc_dirs=None): # Web IDE progress bar for project build files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources self.to_be_compiled = len(files_to_compile) self.compiled = 0 + self.cc_verbose("Macros: "+' '.join(['-D%s' % s for s in self.get_symbols()])) + inc_paths = resources.inc_dirs if inc_dirs is not None: inc_paths.extend(inc_dirs) @@ -716,7 +700,7 @@ self.compiled += 1 self.progress("compile", item['source'], build_update=True) for res in result['results']: - self.debug("Command: %s" % ' '.join(res['command'])) + self.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source']) self.compile_output([ res['code'], res['output'], @@ -726,7 +710,7 @@ return objects def compile_queue(self, queue, objects): - jobs_count = int(self.jobs if self.jobs else cpu_count()) + jobs_count = int(self.jobs if self.jobs else cpu_count() * CPU_COEF) p = Pool(processes=jobs_count) results = [] @@ -753,7 +737,7 @@ self.compiled += 1 self.progress("compile", result['source'], build_update=True) for res in result['results']: - self.debug("Command: %s" % ' '.join(res['command'])) + self.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source']) self.compile_output([ res['code'], res['output'], @@ -784,10 +768,10 @@ dep_path = base + '.d' deps = self.parse_dependencies(dep_path) if (exists(dep_path)) else [] if len(deps) == 0 or self.need_update(object, deps): - if ext == '.c': + if ext == '.cpp' or self.COMPILE_C_AS_CPP: + return self.compile_cpp(source, object, includes) + else: return self.compile_c(source, object, includes) - else: - return self.compile_cpp(source, object, includes) elif ext == '.s': deps = [source] if self.need_update(object, deps): @@ -811,12 +795,8 @@ for error_line in _stderr.splitlines(): self.debug("Output: %s"% error_line) - # Check return code if _rc != 0: - for line in _stderr.splitlines(): - self.tool_error(line) - if self.is_not_supported_error(_stderr): raise NotSupportedException(_stderr) else: @@ -863,7 +843,6 @@ if self.need_update(bin, [elf]): needed_update = True self.progress("elf2bin", name) - self.binary(r, elf, bin) self.mem_stats(map) @@ -874,9 +853,7 @@ return bin, needed_update def default_cmd(self, command): - self.debug("Command: %s"% ' '.join(command)) _stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT) - self.debug("Return: %s"% _rc) for output_line in _stdout.splitlines(): @@ -900,14 +877,13 @@ message = "[DEBUG] " + message self.notify({'type': 'debug', 'message': message}) - def cc_info(self, severity, file, line, message, target_name=None, toolchain_name=None): - self.notify({'type': 'cc', - 'severity': severity, - 'file': file, - 'line': line, - 'message': message, - 'target_name': target_name, - 'toolchain_name': toolchain_name}) + def cc_info(self, info=None): + if info is not None: + info['type'] = 'cc' + self.notify(info) + + def cc_verbose(self, message, file=""): + self.debug(message) def progress(self, action, file, build_update=False): msg = {'type': 'progress', 'action': action, 'file': file}