Clone of official tools
Diff: build_api.py
- Revision:
- 13:ab47a20b66f0
- Parent:
- 9:2d27d77ada5c
- Child:
- 14:ee1b877e6839
diff -r f2e8a005c7d3 -r ab47a20b66f0 build_api.py --- a/build_api.py Tue Jun 14 11:33:06 2016 +0100 +++ b/build_api.py Thu Jul 14 20:21:19 2016 +0100 @@ -88,7 +88,7 @@ config = Config(target, src_paths) # If the 'target' argument is a string, convert it to a target instance - if isinstance(target, str): + if isinstance(target, basestring): try: target = TARGET_MAP[target] except KeyError: @@ -105,8 +105,27 @@ for path in src_paths[1:]: resources.add(toolchain.scan_resources(path)) - config.add_config_files(resources.json_files) - return config.get_config_data() + # Update configuration files until added features creates no changes + prev_features = set() + while True: + # Update the configuration with any .json files found while scanning + config.add_config_files(resources.json_files) + + # Add features while we find new ones + features = config.get_features() + if features == prev_features: + break + + for feature in features: + if feature in resources.features: + resources += resources.features[feature] + + prev_features = features + config.validate_config() + + cfg, macros = config.get_config_data() + features = config.get_features() + return cfg, macros, features def build_project(src_path, build_path, target, toolchain_name, libraries_paths=None, options=None, linker_script=None, @@ -126,14 +145,11 @@ abs_path = abspath(first_src_path) project_name = basename(normpath(abs_path)) - for path in src_paths: - profile = get_build_profile(path) - # If the configuration object was not yet created, create it now config = config or Config(target, src_paths) # If the 'target' argument is a string, convert it to a target instance - if isinstance(target, str): + if isinstance(target, basestring): try: target = TARGET_MAP[target] except KeyError: @@ -141,7 +157,7 @@ # Toolchain instance try: - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose) except KeyError as e: raise KeyError("Toolchain %s not supported" % toolchain_name) @@ -198,16 +214,15 @@ else: resources.inc_dirs.append(inc_dirs) - # Update the configuration with any .json files found while scanning - config.add_config_files(resources.json_files) - # And add the configuration macros to the toolchain - toolchain.add_macros(config.get_config_data_macros()) + # Load resources into the config system which might expand/modify resources based on config data + resources = config.load_resources(resources) + + # Set the toolchain's configuration data + toolchain.set_config_data(config.get_config_data()) # Compile Sources - for path in src_paths: - src = toolchain.scan_resources(path) - objects = toolchain.compile_sources(src, build_path, resources.inc_dirs) - resources.objects.extend(objects) + objects = toolchain.compile_sources(resources, build_path, resources.inc_dirs) + resources.objects.extend(objects) # Link Program res, _ = toolchain.link_program(resources, build_path, name) @@ -240,7 +255,7 @@ add_result_to_report(report, cur_result) # Let Exception propagate - raise e + raise def build_library(src_paths, build_path, target, toolchain_name, dependencies_paths=None, options=None, name=None, clean=False, archive=True, @@ -267,6 +282,16 @@ # We will use default project name based on project folder name name = project_name + # If the configuration object was not yet created, create it now + config = Config(target, src_paths) + + # If the 'target' argument is a string, convert it to a target instance + if isinstance(target, basestring): + try: + target = TARGET_MAP[target] + except KeyError: + raise KeyError("Target '%s' not found" % target) + if report != None: start = time() @@ -292,12 +317,9 @@ raise Exception(error_msg) - for path in src_paths: - profile = get_build_profile(path) - try: # Toolchain instance - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose, profile=profile) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose) toolchain.VERBOSE = verbose toolchain.jobs = jobs toolchain.build_all = clean @@ -309,13 +331,6 @@ for path in src_paths: # Scan resources resource = toolchain.scan_resources(path) - - # Copy headers, objects and static libraries - all files needed for static lib - toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) - toolchain.copy_files(resource.objects, build_path, rel_path=resource.base_path) - toolchain.copy_files(resource.libraries, build_path, rel_path=resource.base_path) - if resource.linker_script: - toolchain.copy_files(resource.linker_script, build_path, rel_path=resource.base_path) # Extend resources collection if not resources: @@ -350,18 +365,25 @@ else: tmp_path = build_path - # Handle configuration - config = Config(target) - # Update the configuration with any .json files found while scanning - config.add_config_files(resources.json_files) - # And add the configuration macros to the toolchain - toolchain.add_macros(config.get_config_data_macros()) + # Load resources into the config system which might expand/modify resources based on config data + resources = config.load_resources(resources) + + # Set the toolchain's configuration data + toolchain.set_config_data(config.get_config_data()) + + # Copy headers, objects and static libraries - all files needed for static lib + toolchain.copy_files(resources.headers, build_path, resources=resources) + toolchain.copy_files(resources.objects, build_path, resources=resources) + toolchain.copy_files(resources.libraries, build_path, resources=resources) + if resources.linker_script: + toolchain.copy_files(resources.linker_script, build_path, resources=resources) + + if resource.hex_files: + toolchain.copy_files(resources.hex_files, build_path, resources=resources) # Compile Sources - for path in src_paths: - src = toolchain.scan_resources(path) - objects = toolchain.compile_sources(src, abspath(tmp_path), resources.inc_dirs) - resources.objects.extend(objects) + objects = toolchain.compile_sources(resources, abspath(tmp_path), resources.inc_dirs) + resources.objects.extend(objects) if archive: toolchain.build_library(objects, build_path, name) @@ -462,7 +484,7 @@ try: # Toolchain instance - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose, profile=profile) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose) toolchain.VERBOSE = verbose toolchain.jobs = jobs toolchain.build_all = clean @@ -499,7 +521,8 @@ # Copy Headers for resource in resources: - toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) + toolchain.copy_files(resource.headers, build_path, resources=resource) + dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs) # Compile Sources @@ -527,8 +550,6 @@ if toolchain_output: cur_result["output"] += toolchain_output - cur_result["output"] += str(e) - add_result_to_report(report, cur_result) # Let Exception propagate @@ -562,9 +583,6 @@ return False - for path in src_paths: - profile = get_build_profile(path) - try: # Toolchain toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose) @@ -602,7 +620,7 @@ # Target specific sources HAL_SRC = join(MBED_TARGETS_PATH, "hal") hal_implementation = toolchain.scan_resources(HAL_SRC) - toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files + hal_implementation.libraries, BUILD_TARGET, HAL_SRC) + toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files + hal_implementation.libraries, BUILD_TARGET, resources=hal_implementation) incdirs = toolchain.scan_resources(BUILD_TARGET).inc_dirs objects = toolchain.compile_sources(hal_implementation, TMP_PATH, [MBED_LIBRARIES] + incdirs) @@ -780,7 +798,7 @@ hal_implementation = toolchain.scan_resources(HAL_SRC) # Copy files before analysis - toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files, BUILD_TARGET, HAL_SRC) + toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files, BUILD_TARGET, resources=hal_implementation) incdirs = toolchain.scan_resources(BUILD_TARGET) target_includes = ["-I%s" % i for i in incdirs.inc_dirs] @@ -884,7 +902,7 @@ # Copy Headers for resource in resources: - toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) + toolchain.copy_files(resource.headers, build_path, resources=resource) includes += ["-I%s" % i for i in resource.inc_dirs] c_sources += " ".join(resource.c_sources) + " " cpp_sources += " ".join(resource.cpp_sources) + " " @@ -1000,152 +1018,3 @@ paths.append(root) return paths - -def get_build_profile(path): - profile = None - builds = get_build_ids(path) - for build in builds: - if MBED_SDK_REV_MAP.has_key(build): - idx = MBED_SDK_REV_MAP[build] - - if idx is None: - profile = 'v5' - elif idx <= 43: - profile = 'v1' - elif idx <= 68: - profile = 'v2' - elif idx <= 76: - profile = 'v3' - elif idx <= 105: - profile = 'v4' - else: - profile = 'v5' - - return profile - -def get_build_ids(path): - builds = [] - - for (root, dirs, files) in walk(path): - for d in copy(dirs): - if d.startswith('.'): - dirs.remove(d) - - for filename in filter(lambda s: s.endswith(".bld"), files): - try: - # TODO check user has permission to link against build - url = open(join(root, filename), 'r').read() - builds.append(re.sub(r'^.+/(.*?)$', r'\1', url)) - except: - pass - - return builds - -MBED_SDK_REV_MAP = { - '8ed44a420e5c': 105, - 'b9ad9a133dc7': 104, - 'bad568076d81': 103, - 'da0ca467f8b5': 102, - '7cff1c4259d7': 101, - 'cbbeb26dbd92': 100, - 'dbbf35b96557': 99, - '8ab26030e058': 98, - '433970e64889': 97, - '487b796308b0': 96, - '7e07b6fb45cf': 95, - '9ad691361fac': 94, - 'e188a91d3eaa': 93, - '4fc01daae5a5': 92, - '031413cf7a89': 91, - 'cb3d968589d8': 90, - '552587b429a1': 89, - '9327015d4013': 88, - '6213f644d804': 87, - '04dd9b1680ae': 86, - '024bf7f99721': 85, - '0b3ab51c8877': 84, - '8a40adfe8776': 83, - '6473597d706e': 82, - '7d30d6019079': 81, - '8e73be2a2ac1': 80, - '0c05e21ae27e': 79, - 'ed8466a608b4': 78, - '869cf507173a': 77, - '824293ae5e43': 76, - 'dc225afb6914': 75, - 'a842253909c9': 74, - '1efda918f0ba': 73, - '4096f863f923': 72, - '8fabd470bb6e': 71, - '673126e12c73': 70, - '4a7918f48478': 69, - 'f37f3b9c9f0b': 68, - 'a9913a65894f': 67, - '9c8f0e3462fb': 66, - '5798e58a58b1': 65, - 'e3affc9e7238': 64, - 'b3110cd2dd17': 63, - '7e6c9f46b3bd': 62, - '5e5da4a5990b': 61, - '3d0ef94e36ec': 60, - '0883845fe643': 59, - '0954ebd79f59': 58, - '0480438fc29c': 57, - '3753e96f3c8b': 56, - 'd722ed6a4237': 55, - '71b101360fb9': 54, - '63cdd78b2dc1': 53, - '09236a68d21b': 52, - 'a076018f59af': 51, - 'b60934f96c0c': 50, - 'eeb8a2a33ec9': 49, - '49c296715c73': 48, - '134def52cfa0': 47, - '890817bdcffb': 46, - '3d775a932e1d': 45, - '24d45a770a51': 44, - 'e2ed12d17f06': 43, - 'cd19af002ccc': 42, - '10b9abbe79a6': 41, - '976df7c37ad5': 40, - '737756e0b479': 39, - '4c0c40fd0593': 38, - '14f4805c468c': 37, - 'b4b9f287a47e': 36, - '5284544d04b6': 35, - '7495d544864f': 34, - '5364839841bd': 33, - '3b05dd009342': 32, - 'a7ef757f598c': 31, - '3991a86798e3': 30, - '078e4b97a13e': 29, - '667d61c9177b': 28, - '7110ebee3484': 27, - '63bcd7ba4912': 26, - '9a9732ce53a1': 25, - 'e2ac27c8e93e': 24, - '74b8d43b5817': 23, - '9114680c05da': 22, - '3944f1e2fa4f': 21, - '029aa53d7323': 20, - 'e6be4cd80aad': 19, - 'b3c9f16cbb96': 18, - '49a220cc26e0': 17, - '32af5db564d4': 16, - 'd1a9de3f4fe0': 15, - '20a79241b4a0': 14, - 'a0336ede94ce': 13, - 'f63353af7be8': 12, - '1c1ebd0324fa': 11, - 'fcb9359f0959': 10, - 'cf0d45ce28a6': 9, - '00a04e5cd407': 8, - '15d74db76485': 7, - '3fd6a337c7cc': 6, - '62573be585e9': 5, - '5d1359a283bc': 4, - 'aefd12a1f1c5': 3, - '969fc1867111': 2, - '6b7f447ca868': 1, - '82220227f4fa': 0, -} \ No newline at end of file