def test_assembles_config_using_all_relevant_files(self):
        target_source = SourceFactory(config={"target.foo": "foo"}, overrides={"target.labels": ["A"]})
        mbed_lib_files = [
            {
                "path": Path("TARGET_A", "mbed_lib.json"),
                "json_contents": {
                    "name": "a",
                    "config": {"number": 123},
                    "target_overrides": {"*": {"target.features_add": ["RED"]}},
                },
            },
            {
                "path": Path("subdir", "FEATURE_RED", "mbed_lib.json"),
                "json_contents": {
                    "name": "red",
                    "config": {"bool": False},
                    "target_overrides": {
                        "A": {"bool": True, "target.features_add": ["BLUE"], "target.components_add": ["LEG"]}
                    },
                    "macros": ["RED_MACRO"],
                },
            },
            {
                "path": Path("COMPONENT_LEG", "mbed_lib.json"),
                "json_contents": {"name": "leg", "config": {"number-of-fingers": 5}, "macros": ["LEG_MACRO"]},
            },
        ]
        unused_mbed_lib_file = {
            "path": Path("subdir", "FEATURE_BROWN", "mbed_lib.json"),
            "json_contents": {
                "name": "brown",
                "target_overrides": {"*": {"red.bool": "DON'T USE ME"}},
                "macros": ["DONT_USE_THIS_MACRO"],
            },
        }
        mbed_app_file = {
            "path": Path("mbed_app.json"),
            "json_contents": {"target_overrides": {"*": {"target.foo": "bar"}}},
        }

        with TemporaryDirectory() as directory:
            created_mbed_lib_files = create_files(directory, mbed_lib_files)
            created_mbed_app_file = create_files(directory, [mbed_app_file])[0]
            create_files(directory, [unused_mbed_lib_file])

            subject = _assemble_config_from_sources_and_lib_files(
                target_source, find_files("mbed_lib.json", Path(directory)), created_mbed_app_file
            )

            mbed_lib_sources = [Source.from_mbed_lib(Path(directory, file), ["A"]) for file in created_mbed_lib_files]
            mbed_app_source = Source.from_mbed_app(created_mbed_app_file, ["A"])
            expected_config = Config.from_sources([target_source] + mbed_lib_sources + [mbed_app_source])

            self.assertEqual(subject, expected_config)
예제 #2
0
def assemble_config(mbed_target: str, mbed_program_directory: Path) -> Config:
    """Assemble Config for given target and program directory.

    The structure and configuration of MbedOS requires us to do multiple passes over
    configuration files, as each pass might affect which configuration files should be included
    in the final configuration.
    """
    target_source = Source.from_target(mbed_target, mbed_program_directory)
    mbed_lib_files = find_files("mbed_lib.json", mbed_program_directory)
    mbed_program = MbedProgram.from_existing(mbed_program_directory)
    mbed_app_file = mbed_program.files.app_config_file
    return _assemble_config_from_sources_and_lib_files(target_source,
                                                       mbed_lib_files,
                                                       mbed_app_file)
예제 #3
0
    def test_respects_legacy_filters(self):
        matching_paths = [
            Path("file.txt"),
        ]
        excluded_paths = [
            Path("TESTS", "file.txt"),
            Path("bar", "TEST_APPS"
                 "file.txt"),
        ]
        with create_files(matching_paths + excluded_paths) as directory:
            subject = find_files("file.txt", directory)

        self.assertEqual(len(subject), len(matching_paths))
        for path in matching_paths:
            self.assertIn(Path(directory, path), subject)
예제 #4
0
    def test_finds_files_by_name(self):
        matching_paths = [
            Path("file.txt"),
            Path("sub_directory", "file.txt"),
        ]
        excluded_paths = [
            Path("not_interested.txt"),
            Path("sub_directory", "not_interested.txt"),
        ]

        with create_files(matching_paths + excluded_paths) as directory:
            subject = find_files("file.txt", directory)

        self.assertEqual(len(subject), len(matching_paths))
        for path in matching_paths:
            self.assertIn(Path(directory, path), subject)
예제 #5
0
    def test_respects_mbedignore(self):
        matching_paths = [
            Path("file.txt"),
        ]
        excluded_paths = [
            Path("foo", "file.txt"),
            Path("bar", "file.txt"),
        ]
        with create_files(matching_paths + excluded_paths) as directory:
            Path(directory, ".mbedignore").write_text("foo/*")
            Path(directory, "bar", ".mbedignore").write_text("*")

            subject = find_files("file.txt", directory)

        self.assertEqual(len(subject), len(matching_paths))
        for path in matching_paths:
            self.assertIn(Path(directory, path), subject)