def test_filter_by_all_libraries(self): """ Assert something """ res = Resources(MockNotifier()) res._add_labels('TARGET', ['K64F', 'FRDM']) for name, loc in SRC_PATHS.items(): res.add_directory(loc, into_path=name) res.filter_by_libraries(res.get_file_refs(FileType.JSON)) assert ("main.cpp" in res.get_file_names(FileType.CPP_SRC))
def test_basic_scan(self): """ Verify that the ordering of Target info addition and directory addition does not matter, so long as all the Target info and all directories are added. """ first = Resources(MockNotifier()) first._add_labels('TARGET', ['K64F']) first._add_labels('TARGET', ['FRDM']) for name, loc in SRC_PATHS.items(): print(name, loc) first.add_directory(loc, into_path=name) assert ("main.cpp" in first.get_file_names(FileType.CPP_SRC))
def test_filter_by_all_libraries(self): """ Assert something """ res = Resources(MockNotifier(), collect_ignores=True) res._add_labels('TARGET', ['K64F', 'FRDM']) for name, loc in SRC_PATHS.items(): res.add_directory(loc, into_path=name) res.filter_by_libraries(res.get_file_refs(FileType.JSON)) assert ("main.cpp" in res.get_file_names(FileType.CPP_SRC)) lib_dirs = (dirname(name) or "." for name in res.get_file_names(FileType.JSON)) assert (not any(dir in res.ignored_dirs for dir in lib_dirs))
def test_filter_by_bm_lib(self): res = Resources(MockNotifier()) res._add_labels('TARGET', ['K64F', 'FRDM']) for name, loc in SRC_PATHS.items(): res.add_directory(loc, into_path=name) filter_by = [ ref for ref in res.get_file_refs(FileType.JSON) if join("platform", "bm", "mbed_lib.json") in ref.name ] res.filter_by_libraries(filter_by) assert ("main.cpp" not in res.get_file_names(FileType.CPP_SRC)) assert (join("mbed-os", "platform", "bm", "bm.cpp") in res.get_file_names(FileType.CPP_SRC)) assert (join("mbed-os", "TARGET_FRDM", "not-main.cpp") in res.get_file_names(FileType.CPP_SRC))
def test_detect_duplicates(self): """ Verify that detect_duplicates finds all of the duplicate object files in the scanned tree. """ notifier = MockNotifier() first = Resources(notifier) first._add_labels('TARGET', ['K64F']) for name, loc in SRC_PATHS.items(): first.add_directory(loc, into_path=name) notifier.messages = [] first.detect_duplicates() error_messages = "\n".join(m['message'] for m in notifier.messages if m['type'] == 'tool_error') assert (" eggs.o " in error_messages) first._add_labels('TARGET', ['FRDM']) first.detect_duplicates() error_messages = "\n".join(m['message'] for m in notifier.messages if m['type'] == 'tool_error') assert (" eggs.o " in error_messages) assert (" not-main.o " in error_messages) assert (" main.o " in error_messages)
def test_filter_by_bm_lib(self): res = Resources(MockNotifier(), collect_ignores=True) res._add_labels('TARGET', ['K64F', 'FRDM']) for name, loc in SRC_PATHS.items(): res.add_directory(loc, into_path=name) libs = [ ref for ref in res.get_file_refs(FileType.JSON) if basename(ref.name) == MBED_LIB_FILENAME ] filter_by = [ ref for ref in libs if join("platform", "bm", "mbed_lib.json") in ref.name ] res.filter_by_libraries(filter_by) assert ("main.cpp" not in res.get_file_names(FileType.CPP_SRC)) assert (join("mbed-os", "platform", "bm", "bm.cpp") in res.get_file_names(FileType.CPP_SRC)) assert (join("mbed-os", "TARGET_FRDM", "not-main.cpp") in res.get_file_names(FileType.CPP_SRC)) inc_names = [dirname(name) or "." for name, _ in filter_by] assert (not any(d in res.ignored_dirs for d in inc_names)) excluded_libs = set(libs) - set(filter_by) exc_names = [dirname(name) or "." for name, _ in excluded_libs] assert (all(e in res.ignored_dirs for e in exc_names))
def test_add_target_info(self): """ Verify that the ordering of Target info addition and directory addition does not matter, so long as all the Target info and all directories are added. """ first = Resources(MockNotifier()) middle = Resources(MockNotifier()) last = Resources(MockNotifier()) first._add_labels('TARGET', ['K64F']) first._add_labels('TARGET', ['FRDM']) middle._add_labels('TARGET', ['FRDM']) for name, loc in SRC_PATHS.items(): first.add_directory(loc, into_path=name) middle.add_directory(loc, into_path=name) last.add_directory(loc, into_path=name) middle._add_labels('TARGET', ['K64F']) last._add_labels('TARGET', ['K64F']) last._add_labels('TARGET', ['FRDM']) for ftype in Resources.ALL_FILE_TYPES: assert (set(first.get_file_refs(ftype)) == set( middle.get_file_refs(ftype))) assert (set(last.get_file_refs(ftype)) == set( middle.get_file_refs(ftype)))
build_profile=[profile_data], app_config=app_config_path) # each toolchain must then scan the mbed dir to pick up more configs resources = Resources(notifier).scan_with_toolchain( src_paths=[mbed_os_dir], toolchain=profile_toolchain, exclude=True, mbedignore_path=mbedignore_file) is_custom_target = os.path.dirname( Target.get_json_target_data()[target_name] ["_from_file"]) == custom_target_dir if is_custom_target: # Add the directory of the custom target resources.add_directory( os.path.join(custom_target_dir, "TARGET_" + target_name)) # Filter out duplicate files (if a target overrides e.g. system_clock.c) dupe_objects, dupe_headers = resources._collect_duplicates( dict(), dict()) duplicates = {**dupe_objects, **dupe_headers} for filename, dupe_paths in duplicates.items(): if len(dupe_paths) <= 1: # Not really a duplicate continue print( "DUPLICATE found: File %s is not unique! It could be one of: %s" % (filename, " ".join(dupe_paths))) for dupe_path in dupe_paths: if os.path.commonpath(
build_dir=config_header_dir, target=target_name, toolchain_name=toolchain_name, build_profile=[profile_data], app_config=app_config_path) # each toolchain must then scan the mbed dir to pick up more configs resources = Resources(notifier).scan_with_toolchain( src_paths=[mbed_os_dir], toolchain=profile_toolchain, exclude=True) profile_toolchain.RESPONSE_FILES = False profile_toolchains.append(profile_toolchain) # Add custom targets if is_custom_target: target_dir = "TARGET_" + target_name resources.add_directory(os.path.join(custom_targets_dir, target_dir)) # Profiles seem to only set flags, so for the remaining operations we can use any toolchain toolchain = profile_toolchains[0] print("Generated config header: " + toolchain.get_config_header()) print("Using settings from these JSON files:\n " + "\n ".join(resources.get_file_paths(FileType.JSON))) # Write target header # ------------------------------------------------------------------------- target_header_path = os.path.join(config_header_dir, "mbed_target_config.h") write_target_header(target_header_path, toolchain.get_symbols()) print("Generated target config header: " + target_header_path)