def test_config_param_from_target_processed_with_default_name_mangling( program): generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() assert "MBED_CONF_TARGET_XIP_ENABLE=0" in config_text
def test_requires_config_option(program): create_mbed_app_json(program.root, requires=["bare-metal"]) create_mbed_lib_json(program.mbed_os.root / "bare-metal" / "mbed_lib.json", "bare-metal", requires=["platform"]) create_mbed_lib_json( program.mbed_os.root / "platform" / "mbed_lib.json", "platform", config={"stdio-baud-rate": { "value": 9600 }}, ) create_mbed_lib_json( program.mbed_os.root / "storage" / "mbed_lib.json", "filesystem", config={ "read_size": { "macro_name": "MBED_LFS_READ_SIZE", "value": 64 } }, ) generate_config("K64F", "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert "MBED_CONF_PLATFORM_STDIO_BAUD_RATE=9600" in config_text assert "MBED_LFS_READ_SIZE=64" not in config_text
def test_settings_from_multiple_libs_included(matching_target_and_filter, program): target, target_filter = matching_target_and_filter create_mbed_lib_json( program.mbed_os.root / "mbed_lib.json", "platform", config={"stdio-baud-rate": { "value": 9600 }}, ) create_mbed_lib_json( program.mbed_os.root / "storage" / "mbed_lib.json", "filesystem", config={ "read_size": { "macro_name": "MBED_LFS_READ_SIZE", "value": 64 } }, ) generate_config(target, "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert "MBED_CONF_PLATFORM_STDIO_BAUD_RATE=9600" in config_text assert "MBED_LFS_READ_SIZE=64" in config_text
def test_macros_from_target_collected(program): generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() for macro in TARGET_DATA["macros"]: assert macro in config_text
def test_config_parsed_when_mbed_os_outside_project_root( program_in_mbed_os_subdir, matching_target_and_filter): program = program_in_mbed_os_subdir target, target_filter = matching_target_and_filter create_mbed_lib_json( program.mbed_os.root / "mbed_lib.json", "platform", config={"stdio-baud-rate": { "value": 9600 }}, ) create_mbed_lib_json( program.mbed_os.root / "storage" / "mbed_lib.json", "filesystem", config={ "read_size": { "macro_name": "MBED_LFS_READ_SIZE", "value": 64 } }, ) generate_config("K64F", "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert "MBED_CONF_PLATFORM_STDIO_BAUD_RATE=9600" in config_text assert "MBED_LFS_READ_SIZE=64" in config_text
def test_macros_from_target_collected(program): generate_config("K64F", "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() for macro in TARGET_DATA["macros"]: assert macro in config_text
def test_raises_error_when_attempting_to_customize_existing_target(program): program.files.custom_targets_json.write_text( json.dumps({TARGETS[0]: TARGET_DATA})) target = TARGETS[0] toolchain = "GCC_ARM" with pytest.raises(ToolsError): generate_config(target, toolchain, program)
def test_macros_from_app_collected(macros, program): create_mbed_app_json(program.root, macros=macros) generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() for macro in macros: assert macro in config_text
def test_mbedignore_generated(program): target = "K64F" toolchain = "GCC_ARM" generate_config(target, toolchain, program) mbedignore_file = (program.files.cmake_build_dir / MBEDIGNORE_FILE) assert os.path.isfile(mbedignore_file)
def test_target_and_toolchain_collected(program): target = "K64F" toolchain = "GCC_ARM" generate_config(target, toolchain, program) config_text = program.files.cmake_config_file.read_text() assert target in config_text assert toolchain in config_text
def test_target_and_toolchain_collected(program): target = "K64F" toolchain = "GCC_ARM" generate_config(target, toolchain, program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert target in config_text assert toolchain in config_text
def test_custom_targets_data_found(program): program.files.custom_targets_json.write_text( json.dumps({"IMAGINARYBOARD": TARGET_DATA})) target = "IMAGINARYBOARD" toolchain = "GCC_ARM" generate_config(target, toolchain, program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert target in config_text
def test_raises_when_attempting_to_override_nonexistent_param( matching_target_and_filter, program): target, target_filter = matching_target_and_filter create_mbed_app_json(program.root, target_overrides={ target_filter: { "target.some-nonexistent-config-param": 999999 } }) with pytest.raises(ValueError): generate_config(target, "GCC_ARM", program)
def test_macros_from_lib_collected(macros, program): create_mbed_lib_json(program.mbed_os.root / "connectivity" / "mbed_lib.json", "nanostack", macros=macros) generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() for macro in macros: assert macro in config_text
def test_warns_when_attempting_to_override_nonexistent_param( matching_target_and_filter, program, caplog): target, target_filter = matching_target_and_filter override_name = "target.some-nonexistent-config-param" create_mbed_app_json( program.root, target_overrides={target_filter: { override_name: 999999 }}) generate_config(target, "GCC_ARM", program) assert override_name in caplog.text
def test_output_ext_hex(program): target = "IMAGINARYBOARD" toolchain = "GCC_ARM" target_data = TARGET_DATA.copy() target_data["OUTPUT_EXT"] = "hex" program.files.custom_targets_json.write_text( json.dumps({target: target_data})) generate_config(target, toolchain, program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert 'MBED_OUTPUT_EXT "hex"' in config_text
def test_forced_reset_timeout_set(program): target = "IMAGINARYBOARD" toolchain = "GCC_ARM" target_data = TARGET_DATA.copy() target_data["forced_reset_timeout"] = 20 program.files.custom_targets_json.write_text( json.dumps({target: target_data})) generate_config(target, toolchain, program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert 'MBED_GREENTEA_TEST_RESET_TIMEOUT "20"' in config_text
def test_overrides_target_config_param_from_app(matching_target_and_filter, program): target, target_filter = matching_target_and_filter create_mbed_app_json( program.root, target_overrides={target_filter: { "target.xip-enable": True }}) generate_config(target, "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() assert "MBED_CONF_TARGET_XIP_ENABLE=1" in config_text
def test_overrides_target_non_config_params_from_app( matching_target_and_filter, config_param, config_param_value, expected_output, program): target, target_filter = matching_target_and_filter create_mbed_app_json( program.root, target_overrides={target_filter: { config_param: config_param_value }}) generate_config(target, "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() assert expected_output in config_text
def configure(toolchain: str, mbed_target: str, program_path: str, mbed_os_path: str) -> None: """Exports a mbed_config.cmake file to build directory in the program root. The parameters set in the CMake file will be dependent on the combination of toolchain and Mbed target provided and these can then control which parts of Mbed OS are included in the build. This command will create the .mbedbuild directory at the program root if it doesn't exist. Args: toolchain: the toolchain you are using (eg. GCC_ARM, ARM) mbed_target: the target you are building for (eg. K64F) program_path: the path to the local Mbed program mbed_os_path: the path to the local Mbed OS directory """ cmake_build_subdir = pathlib.Path(mbed_target.upper(), "develop", toolchain.upper()) if mbed_os_path is None: program = MbedProgram.from_existing(pathlib.Path(program_path), cmake_build_subdir) else: program = MbedProgram.from_existing(pathlib.Path(program_path), cmake_build_subdir, pathlib.Path(mbed_os_path)) mbed_target = mbed_target.upper() output_path = generate_config(mbed_target, toolchain, program) click.echo( f"mbed_config.cmake has been generated and written to '{str(output_path.resolve())}'" )
def test_target_list_params_can_be_added_to(matching_target_and_filter, config_param, config_param_value, expected_output, program): target, target_filter = matching_target_and_filter create_mbed_app_json( program.root, target_overrides={target_filter: { config_param: config_param_value }}, ) generate_config(target, "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() for expected in expected_output: assert expected in config_text
def test_target_list_params_can_be_removed(matching_target_and_filter, config_param, config_param_value, expected_output, program): target, target_filter = matching_target_and_filter create_mbed_app_json( program.root, target_overrides={target_filter: { config_param: config_param_value }}, ) generate_config(target, "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert expected_output not in config_text
def test_config_param_from_app_processed_with_default_name_mangling(program): create_mbed_app_json( program.root, config={ "stdio-convert-newlines": { "help": "Enable conversion to standard newlines on stdin/stdout/stderr", "value": True, } }, ) generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() assert "MBED_CONF_APP_STDIO_CONVERT_NEWLINES" in config_text
def test_overrides_target_config_param_from_lib(matching_target_and_filter, program): target, target_filter = matching_target_and_filter create_mbed_lib_json( program.root / "platform" / "mbed_lib.json", "platform", target_overrides={target_filter: { "target.xip-enable": True }}, ) generate_config(target, "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert "MBED_CONF_TARGET_XIP_ENABLE=1" in config_text
def test_config_param_from_lib_processed_with_user_set_name(program): create_mbed_lib_json( program.mbed_os.root / "platform" / "mbed_lib.json", "platform", config={ "stdio-convert-newlines": { "help": "Enable conversion to standard newlines on stdin/stdout/stderr", "value": True, "macro_name": "ENABLE_NEWLINES", } }, ) generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() assert "ENABLE_NEWLINES" in config_text
def test_target_labels_collected_as_defines(program): generate_config("K64F", "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() for label in TARGET_DATA["labels"] + TARGET_DATA["extra_labels"]: assert f"TARGET_{label}" in config_text for feature in TARGET_DATA["features"]: assert f"FEATURE_{feature}=1" in config_text for component in TARGET_DATA["components"]: assert f"COMPONENT_{component}=1" in config_text for device in TARGET_DATA["device_has"]: assert f"DEVICE_{device}=1" in config_text for form_factor in TARGET_DATA["supported_form_factors"]: assert f"TARGET_FF_{form_factor}" in config_text
def test_overrides_lib_config_param_from_same_lib(matching_target_and_filter, program): target, target_filter = matching_target_and_filter create_mbed_lib_json( program.mbed_os.root / "mbed_lib.json", "platform", config={"stdio-baud-rate": { "value": 9600 }}, target_overrides={target_filter: { "stdio-baud-rate": 115200 }}, ) generate_config(target, "GCC_ARM", program) config_text = program.files.cmake_config_file.read_text() assert "MBED_CONF_PLATFORM_STDIO_BAUD_RATE=115200" in config_text
def test_config_param_from_lib_processed_with_default_name_mangling(program): create_mbed_lib_json( program.mbed_os.root / "platform" / "mbed_lib.json", "platform", config={ "stdio-convert-newlines": { "help": "Enable conversion to standard newlines on stdin/stdout/stderr", "value": True, } }, ) generate_config("K64F", "GCC_ARM", program) config_text = (program.files.cmake_build_dir / CMAKE_CONFIG_FILE).read_text() assert "MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES" in config_text
def test_raises_when_attempting_to_override_lib_config_param_from_other_lib( matching_target_and_filter, program): target, target_filter = matching_target_and_filter create_mbed_lib_json( program.mbed_os.root / "platform" / "mbed_lib.json", "platform", config={"stdio-baud-rate": { "value": 9600 }}, ) create_mbed_lib_json( program.mbed_os.root / "filesystem" / "mbed_lib.json", "filesystem", target_overrides={target_filter: { "platform.stdio-baud-rate": 115200 }}, ) with pytest.raises(ToolsError): generate_config(target, "GCC_ARM", program)
def build(program_path: str, build_type: str, toolchain: str = "", mbed_target: str = "", clean: bool = False) -> None: """Configure and build an Mbed project using CMake and Ninja. If the project has already been configured and contains '.mbedbuild/mbed_config.cmake', this command will skip the Mbed configuration step and invoke CMake. If the CMake configuration step has already been run previously (i.e a CMake build tree exists), then just try to build the project immediately using Ninja. Args: program_path: Path to the Mbed project. build_type: The Mbed build profile (debug, develop or release). toolchain: The toolchain to use for the build. mbed_target: The name of the Mbed target to build for. clean: Force regeneration of config and build system before building. """ program = MbedProgram.from_existing(pathlib.Path(program_path)) mbed_config_file = program.files.cmake_config_file if not mbed_config_file.exists() or clean: click.echo("Generating Mbed config...") if not toolchain: raise click.UsageError( "--toolchain argument is required when generating Mbed config!" ) if not mbed_target: raise click.UsageError( "--mbed-target argument is required when generating Mbed config!" ) generate_config(mbed_target.upper(), toolchain, program) build_tree = program.files.cmake_build_dir if not build_tree.exists() or clean: generate_build_system(program.root, build_tree, build_type) build_project(build_tree)