blob: 64e0a1aa6092fb0f83be242fc1e8bb5fc7c39449 [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.
# Invokes the check-licenses tool.
#
# Parameters
#
# fuchsia_dir (optional)
# [string] Path to the fuchsia root directory. Defaults to "//".
#
# out_dir (optional)
# [string] Directory where generated NOTICE files will be placed. Defaults
# to target_out_dir.
#
# testonly, visibility
template("license_data") {
# TODO(jcecil): Remove this "configs" flag from all targets
# that use this template.
not_needed(invoker, [ "configs" ])
filter = ""
if (defined(invoker.filter)) {
filter = invoker.filter
}
out_dir = "$target_out_dir/check-licenses"
if (defined(invoker.out_dir)) {
out_dir = invoker.out_dir
}
temp_out_dir = "$out_dir/temp"
check_licenses_target = "${target_name}_check-licenses"
copy_txt_notices_target = "${target_name}_txt_copy"
copy_html_notices_target = "${target_name}_html_copy"
txt_notices_output = "license_texts_grouped_by_license_pattern_deduped.txt.gz"
html_notices_output =
"license_texts_grouped_by_license_pattern_deduped.html.gz"
action(check_licenses_target) {
forward_variables_from(invoker,
[
"fuchsia_dir",
"testonly",
"visibility",
])
# check-licenses assumes that it runs from //,
# but actions run from root_build_dir.
# This shell script sets the CWD and then calls check-licenses.
script = "//tools/check-licenses/license_data.sh"
# The license tool scans the whole source tree, so it cannot be hermetic.
# TODO(fxb/84924): Improve the way notice files are generated.
hermetic_deps = false
license_tool = "//tools/check-licenses($host_toolchain)"
deps = [ license_tool ]
sources = [ "//tools/check-licenses/_config.json" ]
out_dir = temp_out_dir
outputs = [
"$temp_out_dir/out/$txt_notices_output",
"$temp_out_dir/out/$html_notices_output",
]
args = [
### Args for license_data.sh
rebase_path("//", root_build_dir),
rebase_path(
get_label_info(license_tool, "root_out_dir") + "/check-licenses",
root_build_dir),
### Args for check-licenses
# TODO: Remove once all files are attributed in the file generated by
# check-licenses.
"--log_level",
"0",
"--fuchsia_dir",
rebase_path("//", root_build_dir),
"--out_dir",
rebase_path(out_dir, root_build_dir),
"--gn_path",
rebase_path("//prebuilt/third_party/gn/${host_os}-${host_cpu}/gn",
root_build_dir),
"--build_dir",
rebase_path(root_out_dir, root_build_dir),
]
if (filter != "") {
args += [
"--filter",
filter,
]
}
}
copy(copy_txt_notices_target) {
forward_variables_from(invoker,
[
"fuchsia_dir",
"testonly",
"visibility",
])
sources = [ "$temp_out_dir/out/$txt_notices_output" ]
outputs = [ "$out_dir/NOTICE.txt.gz" ]
deps = [ ":$check_licenses_target" ]
}
copy(copy_html_notices_target) {
forward_variables_from(invoker,
[
"fuchsia_dir",
"testonly",
"visibility",
])
sources = [ "$temp_out_dir/out/$html_notices_output" ]
outputs = [ "$out_dir/NOTICE.html.gz" ]
deps = [ ":$check_licenses_target" ]
}
group(target_name) {
forward_variables_from(invoker,
[
"fuchsia_dir",
"testonly",
"visibility",
])
deps = [
":$check_licenses_target",
":$copy_html_notices_target",
":$copy_txt_notices_target",
]
}
}