Example #1
0
def generate_config(target_name: str, toolchain: str, program: MbedProgram) -> Tuple[Config, pathlib.Path]:
    """Generate an Mbed config file after parsing the Mbed config system.

    Args:
        target_name: Name of the target to configure for.
        toolchain: Name of the toolchain to use.
        program: The MbedProgram to configure.

    Returns:
        Config object (UserDict).
        Path to the generated config file.
    """
    targets_data = _load_raw_targets_data(program)
    target_build_attributes = get_target_by_name(target_name, targets_data)
    config = assemble_config(
        target_build_attributes, [program.root, program.mbed_os.root], program.files.app_config_file
    )
    cmake_file_contents = render_mbed_config_cmake_template(
        target_name=target_name, config=config, toolchain_name=toolchain,
    )
    cmake_config_file_path = program.files.cmake_build_dir / CMAKE_CONFIG_FILE
    write_file(cmake_config_file_path, cmake_file_contents)
    mbedignore_path = program.files.cmake_build_dir / MBEDIGNORE_FILE
    write_file(mbedignore_path, "*")
    return config, cmake_config_file_path
Example #2
0
    def test_writes_content_to_file(self):
        with tempfile.TemporaryDirectory() as directory:
            content = "Some rendered content"
            export_path = pathlib.Path(directory, "output", "some_file.txt")

            write_file(export_path, content)

            created_file = pathlib.Path(export_path)
            self.assertEqual(created_file.read_text(), content)
Example #3
0
def generate_config(target_name: str, toolchain: str,
                    program: MbedProgram) -> pathlib.Path:
    """Generate an Mbed config file at the program root by parsing the mbed config system.

    Args:
        target_name: Name of the target to configure for.
        toolchain: Name of the toolchain to use.
        program: The MbedProgram to configure.

    Returns:
        Path to the generated config file.
    """
    target_build_attributes = get_target_by_name(
        target_name, program.mbed_os.targets_json_file)
    config = assemble_config(target_build_attributes, program.root,
                             program.files.app_config_file)
    cmake_file_contents = generate_mbed_config_cmake_file(
        target_name, target_build_attributes, config, toolchain)
    cmake_config_file_path = program.files.cmake_config_file
    write_file(cmake_config_file_path.parent, cmake_config_file_path.name,
               cmake_file_contents)
    return cmake_config_file_path
Example #4
0
def configure(output_directory: Any, toolchain: str, mbed_target: str,
              program_path: str) -> None:
    """Exports a mbed_config.cmake file to a .mbedbuild directory in the output path.

    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 output path if it doesn't
    exist.

    Args:
        output_directory: the path where .mbedbuild/mbed_config.cmake will be written
        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
    """
    cmake_file_contents = generate_mbed_config_cmake_file(
        mbed_target.upper(), pathlib.Path(program_path), toolchain)
    output_directory = pathlib.Path(output_directory, ".mbedbuild")
    write_file(output_directory, "mbed_config.cmake", cmake_file_contents)
    click.echo(
        f"mbed_config.cmake has been generated and written to '{str(output_directory.resolve())}'"
    )
Example #5
0
 def test_output_dir_is_file(self):
     with tempfile.TemporaryDirectory() as directory:
         bad_export_dir = pathlib.Path(directory, "some_file.txt", ".txt")
         bad_export_dir.parent.touch()
         with self.assertRaises(InvalidExportOutputDirectory):
             write_file(bad_export_dir, "some contents")