| # Copyright 2023 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. |
| |
| """Defines the fuchsia_cipd_releases rule.""" |
| |
| load(":fuchsia_artifact_cipd_release.bzl", "fuchsia_artifact_cipd_release") |
| load(":fuchsia_debug_symbol_cipd_release.bzl", "fuchsia_debug_symbol_cipd_release") |
| load("//infra/private:providers.bzl", "FuchsiaCIPDManifestInfo", "FuchsiaCIPDReleaseInfo") |
| |
| def fuchsia_cipd_releases( |
| *, |
| name, |
| pkg, |
| cipd_prefix = None, |
| cipd_pkg_name_base = None, # Deprecated |
| extra_content = {}, |
| include_asan_variant = False, |
| tags = ["manual"], |
| **kwargs): |
| """Creates a CIPD upload manifest for a single package. |
| |
| Creates a CIPD upload manifest for a single package, and optionally for its |
| asan variant. |
| |
| Example usage: |
| ``` |
| load("@fuchsia_infra//:infra.bzl", "fuchsia_cipd_releases") |
| |
| fuchsia_cipd_releases( |
| name = "hello_driver_cipd", |
| pkg = "//src/hello_driver:pkg", |
| cipd_pkg_name_base = "fuchsia/drivers/hello_driver", |
| extra_content = { |
| "//src/hello_driver:hello_driver_licenses.spdx.json": "licenses.spdx.json", |
| "//src/hello_driver:README.fuchsia": "README.fuchsia", |
| }, |
| ) |
| ``` |
| |
| Args: |
| name: The label's name. |
| pkg: The package to upload. |
| cipd_prefix: The CIPD upload destination prefix. |
| The following CIPD buckets will be written to: |
| - ${cipd_prefix}/${cpu} |
| - ${cipd_prefix}/debug-symbols-${cpu} |
| - ${cipd_prefix}/${cpu}-asan |
| - ${cipd_prefix}/debug-symbols-${cpu}-asan |
| cipd_pkg_name_base: Deprecated. Please use `cipd_prefix`. |
| extra_content: A mapping of label to dest directory/file paths. |
| Dest paths are included in the ${cipd_prefix}/${cpu}[-asan] uploads. |
| include_asan_variant: Whether to also upload an asan variant of `pkg`. |
| tags: Typical meaning in Bazel. Defaults to ["manual"]. |
| **kwargs: extra attributes to pass along to the build rule. |
| """ |
| cipd_prefix = (cipd_prefix or cipd_pkg_name_base).strip("/") |
| deps = [] |
| |
| deps.append(name + "_artifact") |
| fuchsia_artifact_cipd_release( |
| name = name + "_artifact", |
| pkg_name = "%s/{cpu}" % cipd_prefix, |
| deps = [pkg], |
| extra_content = extra_content, |
| tags = tags + ["manual"], |
| **kwargs |
| ) |
| |
| deps.append(name + "_debug_symbol") |
| fuchsia_debug_symbol_cipd_release( |
| name = name + "_debug_symbol", |
| pkg_name = "%s/debug-symbols-{cpu}" % cipd_prefix, |
| deps = [pkg], |
| tags = tags + ["manual"], |
| **kwargs |
| ) |
| |
| if include_asan_variant: |
| deps.append(name + "_asan_artifact") |
| fuchsia_artifact_cipd_release( |
| name = name + "_asan_artifact", |
| pkg_name = "%s/{cpu}-asan" % cipd_prefix, |
| deps = [pkg], |
| extra_content = extra_content, |
| asan_enabled = True, |
| tags = tags + ["manual"], |
| **kwargs |
| ) |
| |
| deps.append(name + "_asan_debug_symbol") |
| fuchsia_debug_symbol_cipd_release( |
| name = name + "_asan_debug_symbol", |
| pkg_name = "%s/debug-symbols-{cpu}-asan" % cipd_prefix, |
| deps = [pkg], |
| asan_enabled = True, |
| tags = tags + ["manual"], |
| **kwargs |
| ) |
| |
| _fuchsia_cipd_releases( |
| name = name, |
| deps = deps, |
| tags = tags, |
| **kwargs |
| ) |
| |
| def _fuchsia_cipd_releases_impl(ctx): |
| cipd_manifests = [c[FuchsiaCIPDManifestInfo].manifest.path for c in ctx.attr.deps] |
| return [ |
| DefaultInfo( |
| files = depset(ctx.files.deps), |
| ), |
| FuchsiaCIPDReleaseInfo(manifests = cipd_manifests), |
| ] |
| |
| _fuchsia_cipd_releases = rule( |
| implementation = _fuchsia_cipd_releases_impl, |
| provides = [FuchsiaCIPDReleaseInfo], |
| attrs = { |
| "deps": attr.label_list( |
| providers = [FuchsiaCIPDManifestInfo], |
| ), |
| }, |
| ) |