[environment] Use updated toolchain override mechanism
https://fxrev.dev/892038 updated the mechanism by which fuchsia
toolchain builders override the toolchain with a custom version, update
Pigweed recipes accordingly.
Note that this is not a stable interface and should ideally not be
depended on outside the fuchsia recipes repo, Pigweed should not be
depending on properties that are intended to only be read by a single
fuchsia recipe module. Long-term I'd suggest updating the fuchsia recipe
to set additional non-fuchsia-specific properties that can be read by
Pigweed, something like a top-level "toolchain_overrides" property.
Change-Id: Idd4e8daf56d28d222f7169a5f74f5a4c69de04dc
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/173110
Reviewed-by: Rob Mohr <mohrr@google.com>
Pigweed-Auto-Submit: Oliver Newman <olivernewman@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
diff --git a/recipe_modules/environment/api.py b/recipe_modules/environment/api.py
index 89080c9..b970d2c 100644
--- a/recipe_modules/environment/api.py
+++ b/recipe_modules/environment/api.py
@@ -26,7 +26,6 @@
from PB.recipe_modules.pigweed.environment.options import Options
-import attr
from recipe_engine import config_types, recipe_api
@@ -223,9 +222,9 @@
def _toolchain_override(self, env):
"""Checks for a toolchain override and applies it."""
- # Using '$fuchsia/build' properties to simplify interface with the
+ # Using '$fuchsia/checkout' properties to simplify interface with the
# Fuchsia Toolchain team.
- fuchsia_build_props = self.m.properties.thaw().get('$fuchsia/build', {})
+ fuchsia_build_props = self.m.properties.thaw().get('$fuchsia/checkout', {})
toolchain_props = fuchsia_build_props.get('clang_toolchain', {})
if not toolchain_props:
return
@@ -234,28 +233,27 @@
with self.m.context(infra_steps=True):
toolchain_dir = env.dir / 'override' / 'clang_toolchain'
- if toolchain_props['source'] == 'cipd':
+ if cipd_version := toolchain_props.get('cipd_version'):
pkgs = self.m.cipd.EnsureFile()
pkgs.add_package(
'fuchsia/third_party/clang/${platform}',
- toolchain_props['version'],
+ cipd_version,
)
self.m.cipd.ensure(toolchain_dir, pkgs)
- elif toolchain_props['source'] in 'isolated':
+ elif cas_digest := toolchain_props.get('cas_digest'):
with self.m.cas.with_instance(
'projects/chromium-swarm/instances/default_instance'
):
self.m.cas.download(
'download',
- digest=toolchain_props['version'],
+ digest=cas_digest,
output_dir=toolchain_dir,
)
else: # pragma: no cover
raise KeyError(
- f'clang toolchain source {toolchain_props["source"]} '
- 'not recognized'
+ f'invalid clang toolchain properties: {toolchain_props!r}'
)
env.prefixes.setdefault('PATH', [])
diff --git a/recipe_modules/environment/test_api.py b/recipe_modules/environment/test_api.py
index aa3fd78..efaa9f2 100644
--- a/recipe_modules/environment/test_api.py
+++ b/recipe_modules/environment/test_api.py
@@ -42,11 +42,18 @@
return self.m.properties(**{name: opts})
- def override_clang(self, source, version):
+ def override_clang(self, cas_digest=None, cipd_version=None):
+ assert bool(cas_digest) != bool(
+ cipd_version
+ ), 'exactly one of cas_digest or cipd_version is required'
+ tc = {}
+ if cas_digest:
+ tc['cas_digest'] = cas_digest
+ if cipd_version:
+ tc['cipd_version'] = cipd_version
+
props = {
- '$fuchsia/build': {
- 'clang_toolchain': {'source': source, 'version': version,},
- },
+ '$fuchsia/checkout': {'clang_toolchain': tc},
}
return self.m.properties(**props)
diff --git a/recipe_modules/environment/tests/full.py b/recipe_modules/environment/tests/full.py
index 37a2421..fd813be 100644
--- a/recipe_modules/environment/tests/full.py
+++ b/recipe_modules/environment/tests/full.py
@@ -90,13 +90,13 @@
yield (
api.test('override-cipd')
+ api.environment.properties(skip_submodule_check=True)
- + api.environment.override_clang(source='cipd', version='latest')
+ + api.environment.override_clang(cipd_version='latest')
)
yield (
api.test('override-cas')
+ api.environment.properties(skip_submodule_check=True)
- + api.environment.override_clang(source='isolated', version='123456')
+ + api.environment.override_clang(cas_digest='123456')
)
yield api.test('empty')