blob: cc9486e9896a5dcf3092b2bbc364c55fdb8fb869 [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
#
# configs (optional)
# [list] Paths to config files.
# Default: "//tools/check-licenses/config/config.json"
#
# skip_dirs (optional)
# [list] Directories to skip checking.
#
# notice_txt (optional)
# [list] Paths to NOTICE.txt files to parse.
#
# license_allow_list (optional)
# [list] Map of license pattern file (.lic) to list of directories
# where the license can be used.
#
# out_dir (optional)
# [string] Directory where generated NOTICE files will be placed. Defaults
# to target_out_dir.
#
# testonly, visibility
template("license_data") {
action(target_name) {
forward_variables_from(invoker,
[
"configs",
"license_allow_list",
"notice_txt",
"out_dir",
"skip_dirs",
"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 ]
if (!defined(configs)) {
configs = [ "//tools/check-licenses/config/config.json" ]
}
sources = configs
if (!defined(out_dir)) {
out_dir = target_out_dir
}
outputs = [
"$out_dir/NOTICE.html.gz",
"$out_dir/NOTICE.txt.gz",
"$out_dir/NOTICE.summary.csv",
]
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.
"--exit_on_unlicensed_files=false",
"--config_file",
string_join(",", rebase_path(configs, 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 (defined(skip_dirs)) {
args += [ "--skip_dirs" ] +
string_join(",", rebase_path(skip_dirs, root_build_dir))
}
if (defined(notice_txt)) {
args += [ "--notice_txt" ] +
string_join(",", rebase_path(notice_txt, root_build_dir))
}
if (defined(license_allow_list)) {
args += [ "--license_allow_list" ] + "{ " +
string_join(", ", rebase_path(notice_txt, root_build_dir)) + " }"
}
}
}