Revert "[assembly] Remove the not needed image rebase" This reverts commit d873da5bc58f1080ab43fc44b46d0b5f7e502e3e. Reason for revert: broke clients > Error: 'FuchsiaProductImageInfo' value has no field or method 'images_json' Original change's description: > [assembly] Remove the not needed image rebase > > Change-Id: Ibc2bde7cc41f897a5d10f7054ce5b5fa6a626063 > Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-integration/+/788442 > Commit-Queue: Jiaming Li <lijiaming@google.com> > Reviewed-by: Chase Latta <chaselatta@google.com> Change-Id: I83109ac979504c641f4045b3bacba98dd3ad49e1 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-integration/+/788542 Commit-Queue: Aidan Wolter <awolter@google.com> Reviewed-by: RubberStamper 🤖 <android-build-ayeaye@system.gserviceaccount.com> Reviewed-by: Jiaming Li <lijiaming@google.com> Fuchsia-Auto-Submit: Aidan Wolter <awolter@google.com>
diff --git a/bazel_rules_fuchsia/MODULE.bazel b/bazel_rules_fuchsia/MODULE.bazel index 89bbd7f..0d60d7b 100644 --- a/bazel_rules_fuchsia/MODULE.bazel +++ b/bazel_rules_fuchsia/MODULE.bazel
@@ -16,17 +16,21 @@ # Setup the cipd_tool repo for downloading content cipd_tool_ext = use_extension("//cipd:defs.bzl", "cipd_tool_ext") + cipd_tool_ext.client(bin = "foo_tool") + use_repo(cipd_tool_ext, "cipd_tool") # Declare the fuchsia sdk fuchsia_sdk_ext = use_extension("//fuchsia:deps.bzl", "fuchsia_sdk_ext") + use_repo(fuchsia_sdk_ext, "fuchsia_sdk") register_toolchains("@fuchsia_sdk//:fuchsia_toolchain_sdk") # Declare clang fuchsia_clang_ext = use_extension("//fuchsia:deps.bzl", "fuchsia_clang_ext") + use_repo(fuchsia_clang_ext, "fuchsia_clang") register_toolchains("@fuchsia_clang//:cc-x86_64")
diff --git a/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_bundle.bzl b/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_bundle.bzl index 06a8263..eb38e2d 100644 --- a/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_bundle.bzl +++ b/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_bundle.bzl
@@ -393,7 +393,7 @@ def _fuchsia_product_bundle_impl(ctx): partitions_configuration = ctx.attr.partitions_config[FuchsiaAssemblyConfigInfo].config - system_a_out = ctx.attr.product_image[FuchsiaProductImageInfo].images_out + system_a_manifest = ctx.attr.product_image[FuchsiaProductImageInfo].images_json ffx_tool = ctx.toolchains["@rules_fuchsia//fuchsia:toolchain"].ffx pb_out_dir = ctx.actions.declare_directory(ctx.label.name + "_out") @@ -413,7 +413,7 @@ "FFX": ffx_tool.path, "OUTDIR": pb_out_dir.path, "PARTITIONS_PATH": partitions_configuration.path, - "SYSTEM_A_MANIFEST": system_a_out.path + "/images.json", + "SYSTEM_A_MANIFEST": system_a_manifest.path, "ARTIFACTS_BASE_PATH": ctx.attr.artifacts_base_path, } @@ -422,9 +422,9 @@ # If recovery is supplied, add it to the product bundle. if ctx.attr.recovery != None: - system_r_out = ctx.attr.recovery[FuchsiaProductImageInfo].images_out + system_r_manifest = ctx.attr.recovery[FuchsiaProductImageInfo].images_json ffx_invocation.append("--system-r $ORIG_DIR/$SYSTEM_R_MANIFEST") - env["SYSTEM_R_MANIFEST"] = system_r_out.path + "/images.json" + env["SYSTEM_R_MANIFEST"] = system_r_manifest.path inputs.extend(ctx.files.recovery) # If update info is supplied, add it to the product bundle.
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 802d6b0..5429373 100644 --- a/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_image.bzl +++ b/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_image.bzl
@@ -57,6 +57,8 @@ product_config_file = ctx.attr.product_config[FuchsiaProductConfigInfo].product_config board_config_file = ctx.attr.board_config[FuchsiaBoardConfigInfo].board_config + images_json = ctx.actions.declare_file(ctx.label.name + "_images_rebased.json") + ffx_inputs = [ ctx.file._sdk_manifest, ffx_tool, @@ -94,14 +96,26 @@ progress_message = "Product Assembly and create-system for %s" % ctx.label.name, ) + ctx.actions.run( + outputs = [images_json], + inputs = [out_dir], + executable = ctx.executable._rebase_image_json, + arguments = [ + "--image-json-path", + out_dir.path + "/images.json", + "--output", + images_json.path, + ], + ) + return [ - DefaultInfo(files = depset(direct = [out_dir] + ctx.files.product_config)), + DefaultInfo(files = depset(direct = [out_dir, images_json] + ctx.files.product_config)), OutputGroupInfo( debug_files = depset([ffx_isolate_dir]), - all_files = depset([out_dir, ffx_isolate_dir] + ctx.files.product_config), + all_files = depset([out_dir, ffx_isolate_dir, images_json] + ctx.files.product_config), ), FuchsiaProductImageInfo( - images_out = out_dir, + images_json = images_json, ), ] @@ -144,5 +158,10 @@ allow_single_file = True, default = "@fuchsia_sdk//:meta/manifest.json", ), + "_rebase_image_json": attr.label( + default = "//fuchsia/tools:rebase_image_json", + executable = True, + cfg = "exec", + ), }, )
diff --git a/bazel_rules_fuchsia/fuchsia/private/assembly/providers.bzl b/bazel_rules_fuchsia/fuchsia/private/assembly/providers.bzl index 0a68c6f..f747f03 100644 --- a/bazel_rules_fuchsia/fuchsia/private/assembly/providers.bzl +++ b/bazel_rules_fuchsia/fuchsia/private/assembly/providers.bzl
@@ -179,7 +179,7 @@ FuchsiaProductImageInfo = provider( doc = "Info needed to pave a Fuchsia image", fields = { - "images_out": "images out directory", + "images_json": "images.json file", }, )
diff --git a/bazel_rules_fuchsia/fuchsia/tools/BUILD.bazel b/bazel_rules_fuchsia/fuchsia/tools/BUILD.bazel index ba73a34..42de923 100644 --- a/bazel_rules_fuchsia/fuchsia/tools/BUILD.bazel +++ b/bazel_rules_fuchsia/fuchsia/tools/BUILD.bazel
@@ -48,6 +48,11 @@ python_version = "PY3", ) +py_binary( + name = "rebase_image_json", + srcs = ["rebase_image_json.py"], +) + py_library( name = "fuchsia_task_lib", srcs = ["fuchsia_task_lib.py"],
diff --git a/bazel_rules_fuchsia/fuchsia/tools/rebase_image_json.py b/bazel_rules_fuchsia/fuchsia/tools/rebase_image_json.py new file mode 100755 index 0000000..530f1e9 --- /dev/null +++ b/bazel_rules_fuchsia/fuchsia/tools/rebase_image_json.py
@@ -0,0 +1,46 @@ +# Copyright 2022 The Fuchsia Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +"""Rebases relative paths in images.json from the assembly working directory + +into absolute paths. +""" + +import argparse +import json +import os + + +def parse_args(): + """Parses command-line arguments.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--image-json-path", + help="Path to image json", + required=True, + ) + parser.add_argument( + "--output", + help="Path to output images.json file", + required=True, + ) + return parser.parse_args() + + +def main(): + args = parse_args() + image_json_path = args.image_json_path + with open(image_json_path, "r") as f: + images = json.load(f) + + images_manifest = [] + for image in images: + newimage = image.copy() + newimage["path"] = os.path.abspath(newimage["path"]) + images_manifest.append(newimage) + with open(args.output, "w") as f: + json.dump(images_manifest, f, indent=2) + + +if __name__ == "__main__": + main()
diff --git a/tests/MODULE.bazel b/tests/MODULE.bazel index a67bcb7..fc2c116 100644 --- a/tests/MODULE.bazel +++ b/tests/MODULE.bazel
@@ -4,16 +4,17 @@ module( name = "sdk-integration", - version = "1.0", # TODO(fxbug.dev/107744) Migrate to register_toolchains toolchains_to_register = [ "@fuchsia_sdk//:fuchsia_toolchain_sdk", "@fuchsia_clang//:cc-x86_64", "@fuchsia_clang//:cc-aarch64", ], + version = "1.0", ) bazel_dep(name = "rules_fuchsia", version = "") + local_path_override( module_name = "rules_fuchsia", path = "bazel_rules_fuchsia", @@ -22,7 +23,9 @@ bazel_dep(name = "bazel_skylib", version = "1.2.0") fuchsia_sdk_ext = use_extension("@rules_fuchsia//fuchsia:deps.bzl", "fuchsia_sdk_ext") + use_repo(fuchsia_sdk_ext, "fuchsia_sdk") fuchsia_clang_ext = use_extension("@rules_fuchsia//fuchsia:deps.bzl", "fuchsia_clang_ext") + use_repo(fuchsia_clang_ext, "fuchsia_clang")
diff --git a/tests/WORKSPACE.bazel b/tests/WORKSPACE.bazel index 7b51c15..0e02e19 100644 --- a/tests/WORKSPACE.bazel +++ b/tests/WORKSPACE.bazel
@@ -58,21 +58,21 @@ fuchsia_sdk_repository( name = "fuchsia_sdk_x64_only", local_paths = [ - "sdk_generation/goldens/simple_idk_x64", + "sdk_generation/goldens/simple_idk_x64", ], ) fuchsia_sdk_repository( name = "fuchsia_sdk_arm64_only", local_paths = [ - "sdk_generation/goldens/simple_idk_arm64", + "sdk_generation/goldens/simple_idk_arm64", ], ) fuchsia_sdk_repository( name = "fuchsia_sdk_both", local_paths = [ - "sdk_generation/goldens/simple_idk_both", + "sdk_generation/goldens/simple_idk_both", ], )