Make fuchsia_product_image() slightly more hermetic.
The `ffx assembly` plugin invoked by the action generated by the
fuchsia_product_image() rule needs to call the host `cmc` tool
at runtime. To ensure this works when the action is run inside
a Bazel sandbox, expose both the `cmc` host tool, as well as
the `cmc-meta.json` file that is used to point to it.
The latter is required because ffx looks for SDK host tools
by parsing the top-level metadata file, which will point to
`tools/x64/cmc-meta.json`, which will point to `tools/x64/cmc`.
To fix this, the CL does the following:
- Add a `cmc_manifest` entry to the FuchsiaToolchainInfo
provider, and populate it with an label attribute in
the fuchsia_toolchain_info() rule definition. This ensures
that the value is a File object, as required by Bazel.
- Modify repository_template.BUILD to expose the
`cmc-meta.json` file from @fuchsia_sdk through the provider.
- Modify _fuchsia_product_image_impl to use the toolchain
instance to access the host tool and its manifest, and
add them as inputs to the shell action generated by
the function.
To verify this, apply [1] to your local fuchsia.git tree, then
try to build an assembly command with bazel (see examples in
the second bug below). Before this CL, this would fail with
an error message that looks like:
```
Product Assembly Failed
1. Building Image Assembly config
2. Getting host tool from the SDK: cmc
3. Tool 'cmc' not found in SDK dir
```
After the CL, this fails later, because expanded prebuilt
package content are not available in the sandbox, which will
be addressed by future changes.
[1] htps://fuchsia-review.git.corp.google.com/c/fuchsia/+/793965
Bug: 115151
Bug: 120613
Change-Id: I4e83100a0f3fd8c434862c71f2ba43b47b214f69
Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-integration/+/791985
Reviewed-by: Jiaming Li <lijiaming@google.com>
Commit-Queue: David Turner <digit@google.com>
diff --git a/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_image.bzl b/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_image.bzl
index 55b8468..2e7e24f 100644
--- a/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_image.bzl
+++ b/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_image.bzl
@@ -45,7 +45,8 @@
"""
def _fuchsia_product_image_impl(ctx):
- ffx_tool = ctx.toolchains["@rules_fuchsia//fuchsia:toolchain"].ffx
+ fuchsia_toolchain = ctx.toolchains["@rules_fuchsia//fuchsia:toolchain"]
+ ffx_tool = fuchsia_toolchain.ffx
legacy_aib = ctx.attr.legacy_aib[FuchsiaProductAssemblyBundleInfo]
platform_aibs = ctx.attr.platform_aibs[FuchsiaProductAssemblyBundleInfo]
out_dir = ctx.actions.declare_directory(ctx.label.name + "_out")
@@ -60,9 +61,13 @@
board_config_arg = "--board-info $ORIG_DIR/$BOARD_CONFIG_PATH" if board_config_file else "",
)
+ # NOTE: The `cmc` host tool is used by `ffx`, which finds its location
+ # by parsing the _sdk_manifest, then the `cmc_manifest` one.
ffx_inputs = [
ctx.file._sdk_manifest,
ffx_tool,
+ fuchsia_toolchain.cmc,
+ fuchsia_toolchain.cmc_manifest,
product_config_file,
]
if board_config_file:
diff --git a/bazel_rules_fuchsia/fuchsia/workspace/fuchsia_toolchain_info.bzl b/bazel_rules_fuchsia/fuchsia/workspace/fuchsia_toolchain_info.bzl
index 9e56b7c..2c651b9 100644
--- a/bazel_rules_fuchsia/fuchsia/workspace/fuchsia_toolchain_info.bzl
+++ b/bazel_rules_fuchsia/fuchsia/workspace/fuchsia_toolchain_info.bzl
@@ -13,6 +13,7 @@
blobfs = ctx.executable.blobfs,
bindc = ctx.executable.bindc or None,
cmc = ctx.executable.cmc,
+ cmc_manifest = ctx.files.cmc_manifest[0],
cmc_includes = ctx.attr.cmc_includes or None,
far = ctx.executable.far,
ffx = ctx.executable.ffx,
@@ -68,6 +69,12 @@
executable = True,
allow_single_file = True,
),
+ "cmc_manifest": attr.label(
+ doc = "cmc tool executable SDK manifest, required by ffx.",
+ mandatory = True,
+ cfg = "exec",
+ allow_single_file = True,
+ ),
"cmc_includes": attr.label(
doc = "The collection of cml files to include in the cmc invocation",
providers = [[FuchsiaComponentManifestShardCollectionInfo]],
diff --git a/bazel_rules_fuchsia/fuchsia/workspace/sdk_templates/repository_template.BUILD b/bazel_rules_fuchsia/fuchsia/workspace/sdk_templates/repository_template.BUILD
index dd3986f..260a94c 100644
--- a/bazel_rules_fuchsia/fuchsia/workspace/sdk_templates/repository_template.BUILD
+++ b/bazel_rules_fuchsia/fuchsia/workspace/sdk_templates/repository_template.BUILD
@@ -84,6 +84,7 @@
blobfs = "//tools:x64/blobfs_do_not_depend",
bootserver = "//tools:x64/bootserver",
cmc = "//tools:x64/cmc",
+ cmc_manifest = "//tools:x64/cmc-meta.json",
cmc_includes = select({
"@platforms//os:fuchsia": "//:cmc_includes",
"//conditions:default": None,