blob: cd1155c7cc64f6dc376c44ddcd32b34075c58cff [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.
import("//build/packages/prebuilt_package_with_flavors.gni")
import("//src/chromium/build_args.gni")
# Generates a `prebuilt_package_with_flavors` target, which allows choosing a
# specific flavor of the target to use in the build.
#
# Parameters
#
# available_flavors (required)
# Must be set if and only if `default_flavor` is set.
# A `"custom"` flavor corresponding to `custom_package_path` is appended.
# See `flavors` in the `prebuilt_package_with_flavors()` documentation.
#
# default_flavor (required; string)
# The name of the default flavor in available_flavors to use if not overridden.
# Must be set if and only if `flavors` is set.
# See `default` in the `prebuilt_package_with_flavors()` documentation.
#
# custom_package_path (required)
# [path]: The path to the package inside a custom chromium build output directory.
#
# repository (required; string)
# The repository host name part of the package URL.
# See https://fuchsia.dev/fuchsia-src/concepts/packages/package_url#repository
# for more details.
#
# selections (optional; list)
# Flavor choice. This allows flavor to be changed based on other build args. See
# //build/packages/prebuilt_package_with_flavors.gni
#
# deps (optional)
# testonly (optional)
# visibility (optional)
# Usual GN meanings.
#
template("generate_package_flavors") {
assert(defined(invoker.available_flavors),
"The available flavors must be specified")
assert(defined(invoker.default_flavor),
"The default flavor must be specified")
assert(defined(invoker.custom_package_path),
"A custom package path must be specified")
assert(defined(invoker.repository), "The Repository must be specified")
assert(!defined(invoker.package_name),
"Custom package names are not supported")
_base_target_name = target_name
prebuilt_package_with_flavors("${target_name}_pkg") {
forward_variables_from(invoker,
[
"deps",
"repository",
"selections",
"testonly",
"visibility",
])
if (!defined(visibility)) {
visibility = []
}
visibility += [ ":${invoker.target_name}" ]
# Override the default behavior, which would include "_pkg".
package_name = _base_target_name
default = invoker.default_flavor
flavors = invoker.available_flavors
flavors += [
{
name = "custom"
archive = "${invoker.chromium_build_dir}${invoker.custom_package_path}"
# Custom builds are never production-safe.
production_safe = false
},
]
}
}
# Generates a prebuilt_package_with_flavors target for packages related to the
# fuchsia.web` FIDL Protocol.
#
# Parameters
#
# prebuilt_archive_base_path (required)
# [path]: Base path for the prebuilt archive.
#
# See the `generate_package_flavors` template for documentation of other
# parameters.
template("generate_fuchsia_web_package_flavors") {
assert(defined(invoker.prebuilt_archive_base_path),
"A prebuilt archive base path must be specified")
generate_package_flavors("${target_name}") {
forward_variables_from(invoker,
[
"custom_package_path",
"deps",
"repository",
"testonly",
"visibility",
])
default_flavor = "canary"
available_flavors = [
{
name = "canary"
archive = "${invoker.prebuilt_archive_base_path}/arch/$target_cpu/${target_name}.far"
# TODO(https://fxbug.dev/42149832): Add support for overriding this.
production_safe = false
},
]
# Always use the custom build when the GN arg is specified.
if (chromium_build_dir != "") {
print("Using ${target_name} prebuilts from ", chromium_build_dir)
selections = [
{
name = target_name
flavor = "custom"
},
]
}
}
}