|
| 1 | +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +import os |
| 4 | +import textwrap |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import yaml |
| 8 | + |
| 9 | +from idf_component_manager.core import ComponentManager |
| 10 | +from idf_component_manager.prepare_components.prepare import _component_list_file |
| 11 | + |
| 12 | + |
| 13 | +def _generate_lock_file(project_dir: Path, yaml_str: str, build_dir: str = 'build'): |
| 14 | + managed_components_list_file = project_dir / build_dir / 'managed_components_list.temp.cmake' |
| 15 | + local_components_list_file = project_dir / build_dir / 'local_components_list.temp.yml' |
| 16 | + |
| 17 | + os.makedirs(project_dir / 'main') |
| 18 | + (project_dir / 'main' / 'CMakeLists.txt').touch() |
| 19 | + |
| 20 | + (project_dir / 'main' / 'idf_component.yml').write_text(textwrap.dedent(yaml_str)) |
| 21 | + |
| 22 | + os.makedirs(project_dir / build_dir) |
| 23 | + |
| 24 | + ComponentManager( |
| 25 | + path=str(project_dir), |
| 26 | + interface_version=2, |
| 27 | + ).prepare_dep_dirs( |
| 28 | + managed_components_list_file=str(managed_components_list_file), |
| 29 | + component_list_file=_component_list_file('build'), |
| 30 | + local_components_list_file=str(local_components_list_file), |
| 31 | + ) |
| 32 | + |
| 33 | + |
| 34 | +def test_dependencies_with_registry_url(tmp_path, monkeypatch): |
| 35 | + monkeypatch.setenv('CI_TESTING_IDF_VERSION', '5.4.0') |
| 36 | + monkeypatch.setenv('IDF_TARGET', 'esp32') |
| 37 | + monkeypatch.setenv('IDF_PATH', '/tmp') |
| 38 | + |
| 39 | + _generate_lock_file( |
| 40 | + tmp_path, |
| 41 | + """ |
| 42 | + dependencies: |
| 43 | + example/cmp: |
| 44 | + version: "*" |
| 45 | + registry_url: "https://components-staging.espressif.com" |
| 46 | + """, |
| 47 | + ) |
| 48 | + |
| 49 | + assert (tmp_path / 'dependencies.lock').exists() |
| 50 | + with open(tmp_path / 'dependencies.lock') as f: |
| 51 | + lock_data = yaml.safe_load(f) |
| 52 | + |
| 53 | + assert lock_data['dependencies']['example/cmp'] |
| 54 | + assert ( |
| 55 | + lock_data['dependencies']['example/cmp']['source']['registry_url'] |
| 56 | + == 'https://components-staging.espressif.com' |
| 57 | + ) |
| 58 | + assert lock_data['dependencies']['example/cmp']['source']['type'] == 'service' |
0 commit comments