Skip to content

Commit 4581263

Browse files
committed
Allow installation of platform dependencies from archive downloads
Benefits: - Allows installing platforms that are not available from a Git repository. - Installing from an archive download is often faster than cloning a repository.
1 parent 8254e41 commit 4581263

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ Keys:
5555
- `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.
5656
- `name` - platform name in the form of `VENDOR:ARCHITECTURE`.
5757

58+
##### Archive download
59+
60+
Keys:
61+
- `source-url` - download URL for the archive (e.g., `https://github.com/arduino/ArduinoCore-avr/archive/master.zip`).
62+
- `source-path` - path to install as a library. Paths are relative to the root folder of the archive, or the root of the archive if it has no root folder. The default is to install from the root folder of the archive.
63+
- `name` - platform name in the form of `VENDOR:ARCHITECTURE`.
64+
5865
### `libraries`
5966

6067
YAML-format list of library dependencies to install.

compilesketches/compilesketches.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ def install_platforms(self):
237237
if len(platform_list.repository) > 0:
238238
self.install_platforms_from_repository(platform_list=platform_list.repository)
239239

240+
if len(platform_list.download) > 0:
241+
self.install_platforms_from_download(platform_list=platform_list.download)
242+
240243
def get_fqbn_platform_dependency(self):
241244
"""Return the platform dependency definition automatically generated from the FQBN."""
242245
# Extract the platform name from the FQBN (e.g., arduino:avr:uno => arduino:avr)
@@ -564,6 +567,26 @@ def clone_repository(self, url, git_ref, destination_path):
564567
# checkout ref
565568
cloned_repository.git.checkout(git_ref)
566569

570+
def install_platforms_from_download(self, platform_list):
571+
"""Install libraries by downloading them
572+
573+
Keyword arguments:
574+
platform_list -- list of dictionaries defining the dependencies
575+
"""
576+
for platform in platform_list:
577+
self.verbose_print("Installing platform from download URL:", platform[self.dependency_source_url_key])
578+
if self.dependency_source_path_key in platform:
579+
source_path = platform[self.dependency_source_path_key]
580+
else:
581+
source_path = "."
582+
583+
destination_path = self.get_platform_installation_path(platform=platform)
584+
585+
install_from_download(url=platform[self.dependency_source_url_key],
586+
source_path=source_path,
587+
destination_parent_path=destination_path.base,
588+
destination_name=destination_path.platform)
589+
567590
def install_libraries(self):
568591
"""Install Arduino libraries."""
569592
libraries = yaml.load(stream="", Loader=yaml.SafeLoader)

compilesketches/tests/test_compilesketches.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,47 @@ def test_get_repository_dependency_ref(dependency, expected_ref):
767767
assert compile_sketches.get_repository_dependency_ref(dependency=dependency) == expected_ref
768768

769769

770+
def test_install_platforms_from_download(mocker):
771+
platform_list = [
772+
{compilesketches.CompileSketches.dependency_source_url_key: unittest.mock.sentinel.source_url1,
773+
compilesketches.CompileSketches.dependency_source_path_key: unittest.mock.sentinel.source_path,
774+
compilesketches.CompileSketches.dependency_destination_name_key: unittest.mock.sentinel.destination_name},
775+
{compilesketches.CompileSketches.dependency_source_url_key: unittest.mock.sentinel.source_url2}
776+
]
777+
778+
class PlatformInstallationPath:
779+
def __init__(self):
780+
self.base = pathlib.PurePath()
781+
self.platform = pathlib.PurePath()
782+
783+
platform_installation_path = PlatformInstallationPath()
784+
platform_installation_path.parent = pathlib.Path("/foo/PlatformInstallationPathParent")
785+
platform_installation_path.name = pathlib.Path("PlatformInstallationPathName")
786+
787+
expected_source_path_list = [unittest.mock.sentinel.source_path, "."]
788+
789+
compile_sketches = get_compilesketches_object()
790+
791+
mocker.patch("compilesketches.CompileSketches.get_platform_installation_path",
792+
autospec=True,
793+
return_value=platform_installation_path)
794+
mocker.patch("compilesketches.install_from_download", autospec=True)
795+
796+
compile_sketches.install_platforms_from_download(platform_list=platform_list)
797+
798+
get_platform_installation_path_calls = []
799+
install_platforms_from_download_calls = []
800+
for platform, expected_source_path, in zip(platform_list, expected_source_path_list):
801+
get_platform_installation_path_calls.append(unittest.mock.call(compile_sketches, platform=platform))
802+
install_platforms_from_download_calls.append(
803+
unittest.mock.call(url=platform[compilesketches.CompileSketches.dependency_source_url_key],
804+
source_path=expected_source_path,
805+
destination_parent_path=platform_installation_path.base,
806+
destination_name=platform_installation_path.platform)
807+
)
808+
compilesketches.install_from_download.assert_has_calls(calls=install_platforms_from_download_calls)
809+
810+
770811
@pytest.mark.parametrize(
771812
"libraries, expected_manager, expected_path, expected_repository, expected_download",
772813
[("", [], [{compilesketches.CompileSketches.dependency_source_path_key: pathlib.PurePath("/foo/GitHubWorkspace")}],

0 commit comments

Comments
 (0)