def test_does_not_search_symlinks_in_proj_dir_twice(
            self, tmp_path, monkeypatch):
        target = {
            "labels": {"A"},
        }
        mbed_lib_files = [
            {
                "path": Path("mbed-os", "TARGET_A", "mbed_lib.json"),
                "json_contents": {
                    "name": "a",
                    "config": {
                        "a": {
                            "value": 4
                        }
                    }
                },
            },
        ]
        project_dir = tmp_path / "project"
        project_dir.mkdir()

        mbed_os_dir = tmp_path / "other" / "mbed-os"
        mbed_os_dir.mkdir(parents=True)
        _ = create_files(mbed_os_dir, mbed_lib_files)

        monkeypatch.chdir(project_dir)
        mbed_symlink = Path("mbed-os")
        mbed_symlink.symlink_to(mbed_os_dir, target_is_directory=True)

        config = assemble_config(target, [project_dir, mbed_symlink], None)

        assert config["config"][0].name == "a"
        assert config["config"][0].value == 4
Esempio n. 2
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
Esempio n. 3
0
    def test_calls_collaborator_with_source_and_file_paths(
        self,
        _assemble_config_from_sources_and_lib_files,
        find_files,
        Source,
    ):
        mbed_target = dict()
        mbed_program_directory = Path("foo")
        app_config_file = mbed_program_directory / "mbed_app.json"

        subject = assemble_config(mbed_target, mbed_program_directory,
                                  app_config_file)

        self.assertEqual(
            subject, _assemble_config_from_sources_and_lib_files.return_value)
        _assemble_config_from_sources_and_lib_files.assert_called_once_with(
            mbed_target, find_files.return_value, app_config_file)
        find_files.assert_called_once_with("mbed_lib.json",
                                           mbed_program_directory)
    def test_calls_collaborator_with_source_and_file_paths(
        self,
        _assemble_config_from_sources_and_lib_files,
        find_files,
        Source,
        MbedProgram,
    ):
        mbed_target = "K64F"
        mbed_program_directory = Path("foo")
        program = mock.Mock()
        MbedProgram.from_existing.return_value = program

        subject = assemble_config(mbed_target, mbed_program_directory)

        self.assertEqual(
            subject, _assemble_config_from_sources_and_lib_files.return_value)
        _assemble_config_from_sources_and_lib_files.assert_called_once_with(
            Source.from_target.return_value, find_files.return_value,
            program.files.app_config_file)
        find_files.assert_called_once_with("mbed_lib.json",
                                           mbed_program_directory)
Esempio n. 5
0
def generate_mbed_config_cmake_file(mbed_target: str,
                                    program_path: pathlib.Path,
                                    toolchain_name: str) -> str:
    """Generate the top-level CMakeLists.txt file containing the correct definitions for a build.

    Args:
        mbed_target: the target the application is being built for
        program_path: the path to the local Mbed program
        toolchain_name: the toolchain to be used to build the application

    Returns:
        A string of rendered contents for the file.
    """
    target_build_attributes = get_target_by_name(mbed_target, program_path)
    config = assemble_config(mbed_target, program_path)
    return _render_mbed_config_cmake_template(
        target_build_attributes,
        config,
        toolchain_name,
        mbed_target,
    )
Esempio n. 6
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
    def test_ignores_duplicate_paths_to_lib_files(self, tmp_path, monkeypatch):
        target = {
            "labels": {"A"},
        }
        mbed_lib_files = [
            {
                "path": Path("mbed-os", "TARGET_A", "mbed_lib.json"),
                "json_contents": {
                    "name": "a",
                    "config": {
                        "a": {
                            "value": 4
                        }
                    }
                },
            },
        ]
        _ = create_files(tmp_path, mbed_lib_files)
        monkeypatch.chdir(tmp_path)

        config = assemble_config(target, [tmp_path, Path("mbed-os")], None)

        assert config["config"][0].name == "a"
        assert config["config"][0].value == 4