Skip to content

Commit 8254e41

Browse files
committed
Allow installation of platform dependencies from repositories
Benefits: - Allows testing against non-release versions of platforms. - Allows the installation of platforms which don't have Board Manager installation support.
1 parent 2127988 commit 8254e41

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ Keys:
4747
- `source-path` - path to install as a platform. Relative paths are assumed to be relative to the root of the repository.
4848
- `name` - platform name in the form of `VENDOR:ARCHITECTURE`.
4949

50+
##### Repository
51+
52+
Keys:
53+
- `source-url` - URL to clone the repository from. It must start with `git://` or end with `.git`.
54+
- `version` - [Git ref](https://git-scm.com/book/en/v2/Git-Internals-Git-References) of the repository to checkout. The special version name `latest` will cause the latest tag to be used. By default, the repository will be checked out to the tip of the default branch.
55+
- `source-path` - path to install as a library. Paths are relative to the root of the repository. The default is to install from the root of the repository.
56+
- `name` - platform name in the form of `VENDOR:ARCHITECTURE`.
57+
5058
### `libraries`
5159

5260
YAML-format list of library dependencies to install.

compilesketches/compilesketches.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ def install_platforms(self):
234234
if len(platform_list.path) > 0:
235235
self.install_platforms_from_path(platform_list=platform_list.path)
236236

237+
if len(platform_list.repository) > 0:
238+
self.install_platforms_from_repository(platform_list=platform_list.repository)
239+
237240
def get_fqbn_platform_dependency(self):
238241
"""Return the platform dependency definition automatically generated from the FQBN."""
239242
# Extract the platform name from the FQBN (e.g., arduino:avr:uno => arduino:avr)
@@ -466,6 +469,30 @@ def __init__(self):
466469

467470
return platform_installation_path
468471

472+
def install_platforms_from_repository(self, platform_list):
473+
"""Install libraries by cloning Git repositories
474+
475+
Keyword arguments:
476+
platform_list -- list of dictionaries defining the dependencies
477+
"""
478+
for platform in platform_list:
479+
self.verbose_print("Installing platform from repository:", platform[self.dependency_source_url_key])
480+
481+
git_ref = self.get_repository_dependency_ref(dependency=platform)
482+
483+
if self.dependency_source_path_key in platform:
484+
source_path = platform[self.dependency_source_path_key]
485+
else:
486+
source_path = "."
487+
488+
destination_path = self.get_platform_installation_path(platform=platform)
489+
490+
self.install_from_repository(url=platform[self.dependency_source_url_key],
491+
git_ref=git_ref,
492+
source_path=source_path,
493+
destination_parent_path=destination_path.base,
494+
destination_name=destination_path.platform)
495+
469496
def get_repository_dependency_ref(self, dependency):
470497
"""Return the appropriate git ref value for a repository dependency
471498

compilesketches/tests/test_compilesketches.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,59 @@ def __init__(self, stdout):
704704
shutil.rmtree.assert_not_called()
705705

706706

707+
def test_install_platforms_from_repository(mocker):
708+
platform_list = [
709+
{compilesketches.CompileSketches.dependency_source_url_key: unittest.mock.sentinel.source_url,
710+
compilesketches.CompileSketches.dependency_source_path_key: unittest.mock.sentinel.source_path,
711+
compilesketches.CompileSketches.dependency_destination_name_key: unittest.mock.sentinel.destination_name},
712+
{compilesketches.CompileSketches.dependency_source_url_key: unittest.mock.sentinel.source_url2}
713+
]
714+
715+
git_ref = unittest.mock.sentinel.git_ref
716+
717+
class PlatformInstallationPath:
718+
def __init__(self):
719+
self.base = pathlib.PurePath()
720+
self.platform = pathlib.PurePath()
721+
722+
platform_installation_path = PlatformInstallationPath()
723+
platform_installation_path.base = pathlib.Path("/foo/PlatformInstallationPathParent")
724+
platform_installation_path.platform = pathlib.Path("PlatformInstallationPathName")
725+
726+
expected_source_path_list = [unittest.mock.sentinel.source_path, "."]
727+
expected_destination_name_list = [unittest.mock.sentinel.destination_name, None]
728+
729+
compile_sketches = get_compilesketches_object()
730+
731+
mocker.patch("compilesketches.CompileSketches.get_repository_dependency_ref", autospec=True, return_value=git_ref)
732+
mocker.patch("compilesketches.CompileSketches.get_platform_installation_path",
733+
autospec=True,
734+
return_value=platform_installation_path)
735+
mocker.patch("compilesketches.CompileSketches.install_from_repository", autospec=True, return_value=git_ref)
736+
737+
compile_sketches.install_platforms_from_repository(platform_list=platform_list)
738+
739+
get_repository_dependency_ref_calls = []
740+
get_platform_installation_path_calls = []
741+
install_from_repository_calls = []
742+
for platform, expected_source_path, expected_destination_name in zip(platform_list,
743+
expected_source_path_list,
744+
expected_destination_name_list):
745+
get_repository_dependency_ref_calls.append(unittest.mock.call(compile_sketches, dependency=platform))
746+
get_platform_installation_path_calls.append(unittest.mock.call(compile_sketches, platform=platform))
747+
install_from_repository_calls.append(
748+
unittest.mock.call(compile_sketches,
749+
url=platform[compilesketches.CompileSketches.dependency_source_url_key],
750+
git_ref=git_ref,
751+
source_path=expected_source_path,
752+
destination_parent_path=platform_installation_path.base,
753+
destination_name=platform_installation_path.platform)
754+
)
755+
756+
compile_sketches.get_repository_dependency_ref.assert_has_calls(calls=get_repository_dependency_ref_calls)
757+
compile_sketches.install_from_repository.assert_has_calls(calls=install_from_repository_calls)
758+
759+
707760
@pytest.mark.parametrize(
708761
"dependency, expected_ref",
709762
[({compilesketches.CompileSketches.dependency_version_key: "1.2.3"}, "1.2.3"),

0 commit comments

Comments
 (0)