| # Copyright 2024 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. |
| # |
| # Convert a FuchsiaPackageInfo provider to JSON. Mostly used for |
| # manual debugging. All paths are relative to the Bazel execroot. |
| # |
| # Example use: |
| # bazel cquery <config-options> |
| # --output=starlark --starlark:file=/path/to/this/file \ |
| # //path/to/fuchsia:package |
| # |
| def resources_to_json(resources): |
| return [{"dest": r.dest, "src": r.src.path} for r in resources] |
| |
| def fuchsia_component_info_to_json(info): |
| return { |
| "name": info.name, |
| "is_driver": info.is_driver, |
| "is_test": info.is_test, |
| "run_tag": info.run_tag, |
| "manifest": info.manifest.path, |
| "resources": resources_to_json(info.resources), |
| } |
| |
| def fuchsia_packaged_component_info_to_json(info): |
| return { |
| "dest": info.dest, |
| "component_info": fuchsia_component_info_to_json(info.component_info), |
| } |
| |
| def format(target): |
| info = providers(target)["@@fuchsia_rules_common+//packages:providers.bzl%FuchsiaPackageInfo"] |
| result = { |
| "fuchsia_cpu": info.fuchsia_cpu, |
| "package_name": info.package_name, |
| "package_manifest": info.package_manifest.path, |
| "far_file": info.far_file.path, |
| "meta_far": info.meta_far.path, |
| "files": [f.path for f in info.files], |
| "packaged_components": [fuchsia_packaged_component_info_to_json(c) for c in info.packaged_components], |
| "package_resources": resources_to_json(info.package_resources), |
| } |
| return json.encode_indent(result, indent = " ") |