blob: 8f51f11a0c1dcadae2c21a0065cf2198e1eca524 [file] [log] [blame]
# Copyright 2021 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.
load(":providers.bzl", "FuchsiaPackageResourcesInfo")
load(":utils.bzl", "make_resource_struct")
def _package_resources_providers(ctx, resources):
return [
FuchsiaPackageResourcesInfo(resources = resources),
# Note: We create a package_resource for our cc_binary distributions
# in the SDK and we need to export the default info as a root symlink
# to access them. This needs to exist until fuchsia_cc.bzl does not
# need to access the root_symlinks.
DefaultInfo(
runfiles = ctx.runfiles(
root_symlinks = {r.dest: r.src for r in resources},
),
),
]
def _fuchsia_package_resource_impl(ctx):
if len(ctx.attr.dest) == 0:
fail("dest must not be an empty string")
return _package_resources_providers(ctx, [make_resource_struct(
src = ctx.files.src[0],
dest = ctx.attr.dest,
)])
fuchsia_package_resource = rule(
doc = """Declares a resource to be included in a Fuchsia package.
`src` can be a static file or something generated by another rule.
`dest` must be a path relative to /.
This rule can be added as a dependency of a fuchsia_package and it
will be added to the final package contents.
""",
implementation = _fuchsia_package_resource_impl,
attrs = {
"src": attr.label(
doc = "The resource to include in the package.",
mandatory = True,
allow_single_file = True,
),
"dest": attr.string(
doc = "The path where this will be installed in the package.",
mandatory = True,
),
},
)
def _fuchsia_package_resource_group_impl(ctx):
resources = []
dest = ctx.attr.dest.removesuffix("/")
for src in ctx.files.srcs:
name = src.short_path.removeprefix(ctx.label.package + "/").removeprefix(ctx.attr.strip_prefix).removeprefix("/")
resources.append(
make_resource_struct(src = src, dest = dest + "/" + name),
)
return _package_resources_providers(ctx, resources)
fuchsia_package_resource_group = rule(
doc = """Declares a group of resources to be included in a Fuchsia package.
""",
implementation = _fuchsia_package_resource_group_impl,
attrs = {
"srcs": attr.label_list(
doc = "The resource to include in the package.",
mandatory = True,
allow_files = True,
),
"dest": attr.string(
doc = "The path where this will be installed in the package.",
mandatory = True,
),
"strip_prefix": attr.string(
doc = "A path to remove from the srcs",
default = "",
),
},
)