def test_modify_existing_target(): """Set default targets file, then override base Target definition""" initial_target_json = """ { "Target": { "core": null, "default_toolchain": "ARM", "supported_toolchains": null, "extra_labels": [], "is_disk_virtual": false, "macros": [], "device_has": [], "features": [], "detect_code": [], "public": false, "default_lib": "std", "bootloader_supported": false }, "Test_Target": { "inherits": ["Target"], "core": "Cortex-M4", "supported_toolchains": ["ARM"] } }""" test_target_json = """ { "Target": { "core": "Cortex-M0", "default_toolchain": "GCC_ARM", "supported_toolchains": null, "extra_labels": [], "is_disk_virtual": false, "macros": [], "device_has": [], "features": [], "detect_code": [], "public": false, "default_lib": "std", "bootloader_supported": true } } """ with temp_target_file(initial_target_json, json_filename="targets.json") as targets_dir: Target.set_targets_json_location(os.path.join(targets_dir, "targets.json")) update_target_data() assert TARGET_MAP["Test_Target"].core == "Cortex-M4" assert TARGET_MAP["Test_Target"].default_toolchain == 'ARM' assert TARGET_MAP["Test_Target"].bootloader_supported == False with temp_target_file(test_target_json) as source_dir: Target.add_extra_targets(source_dir=source_dir) update_target_data() assert TARGET_MAP["Test_Target"].core == "Cortex-M4" # The existing target should not be modified by custom targets assert TARGET_MAP["Test_Target"].default_toolchain != 'GCC_ARM' assert TARGET_MAP["Test_Target"].bootloader_supported != True
def extract_mcus(parser, options): try: if options.source_dir: for source_dir in options.source_dir: Target.add_extra_targets(source_dir) update_target_data() except KeyError: pass targetnames = TARGET_NAMES targetnames.sort() try: return argparse_many(argparse_force_uppercase_type(targetnames, "MCU"))(options.mcu) except ArgumentTypeError as exc: args_error(parser, "argument -m/--mcu: {}".format(str(exc)))
def test_add_extra_targets(self): """Search for extra targets json in a source folder""" test_target_json = """ { "Test_Target": { "inherits": ["Target"] } } """ with self.temp_target_file(test_target_json) as source_dir: Target.add_extra_targets(source_dir=source_dir) update_target_data() assert 'Test_Target' in TARGET_MAP assert TARGET_MAP['Test_Target'].core is None, \ "attributes should be inherited from Target"
def test_add_extra_targets(): """Search for extra targets json in a source folder""" test_target_json = """ { "Test_Target": { "inherits": ["Target"] } } """ with temp_target_file(test_target_json) as source_dir: Target.add_extra_targets(source_dir=source_dir) update_target_data() assert 'Test_Target' in TARGET_MAP assert TARGET_MAP['Test_Target'].core is None, \ "attributes should be inherited from Target"
def extract_project_info(self, generate_config=False): """Extract comprehensive information in order to build a PlatformIO project src_paths - a list of paths that contain needed files to build project build_path - a path where mbed_config.h will be created target - suitable mbed target name framework_path = path to the root folder of the mbed framework package app_config - path to mbed_app.json ignore_dirs - doesn't work with GCC at the moment? """ # Default values for mbed build api functions if self.custom_target_path and isfile( join(self.custom_target_path, "custom_targets.json")): print ("Detected custom target file") Target.add_extra_targets(source_dir=self.custom_target_path) update_target_data() target = self.get_target_config() build_profile = self.get_build_profile() jobs = 1 # how many compilers we can run at once name = None # the name of the project dependencies_paths = None # libraries location to include when linking macros = None # additional macros inc_dirs = None # additional dirs where include files may be found ignore = self.ignore_dirs # list of paths to add to mbedignore clean = False # Rebuild everything if True # For cases when project and framework are on different # logic drives (Windows only) backup_cwd = os.getcwd() os.chdir(self.framework_path) # Convert src_path to a list if needed if not isinstance(self.src_paths, list): self.src_paths = [self.src_paths] self.src_paths = [relpath(s) for s in self.src_paths] # Pass all params to the unified prepare_toolchain() self.toolchain = prepare_toolchain( self.src_paths, self.build_path, target, self.toolchain_name, macros=macros, clean=clean, jobs=jobs, notify=self.notify, app_config=self.app_config, build_profile=build_profile, ignore=ignore) # The first path will give the name to the library if name is None: name = basename(normpath(abspath(self.src_paths[0]))) # Disabled for legacy libraries # for src_path in self.src_paths: # if not exists(src_path): # error_msg = "The library src folder doesn't exist:%s", src_path # raise Exception(error_msg) self.resources = MbedResourcesFixedPath(self.framework_path, self.notify).scan_with_toolchain( self.src_paths, self.toolchain, dependencies_paths, inc_dirs=inc_dirs) src_files = ( self.resources.s_sources + self.resources.c_sources + self.resources.cpp_sources ) if generate_config: self.generate_mbed_config_file() # Revert back project cwd os.chdir(backup_cwd) result = { "src_files": src_files, "inc_dirs": self.resources.inc_dirs, "ldscript": [self.resources.linker_script], "objs": self.resources.objects, "build_flags": {k: sorted(v) for k, v in self.toolchain.flags.items()}, "libs": [basename(l) for l in self.resources.libraries], "lib_paths": self.resources.lib_dirs, "syslibs": self.toolchain.sys_libs, "build_symbols": self.process_symbols( self.toolchain.get_symbols()), "hex": self.resources.hex_files, "bin": self.resources.bin_files } return result
generated_path = os.path.join(project_root_dir, generated_rpath) custom_target_dir = args.custom_target_dir app_config_path = args.app_config mbedignore_file = args.mbedignore pathlib.Path(generated_path).mkdir(parents=True, exist_ok=True) with open(os.path.join(generated_path, "do-not-modify.txt"), 'w') as do_not_modify: do_not_modify.write( "Files in this folder were generated by configure_for_target.py") # Perform the scan of the Mbed OS dirs # ------------------------------------------------------------------------- if custom_target_dir is not None: Target.add_extra_targets(custom_target_dir) # profile constants # list of all profile JSONs profile_jsons = [ os.path.join(mbed_os_dir, "tools/profiles/develop.json"), os.path.join(mbed_os_dir, "tools/profiles/debug.json"), os.path.join(mbed_os_dir, "tools/profiles/release.json") ] # CMake build type matching each Mbed profile profile_cmake_names = ["RELWITHDEBINFO", "DEBUG", "RELEASE"] for target_name in target_names: print(">> Configuring build system for target: " + target_name) # Can NOT be the current directory, or it screws up some internal regexes inside mbed tools.