blob: 7f209d0662c0cb6d51be6af771ef5a0ff37c78a3 [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"
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",
]
args = [
### Args for license_data.sh
rebase_path("//", root_build_dir),
rebase_path(
get_label_info(license_tool, "root_out_dir") + "/check-licenses",
"//"),
### 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, "//")),
"--out_dir",
rebase_path(out_dir, "//"),
"--gn_path",
rebase_path("//prebuilt/third_party/gn/${host_os}-${host_cpu}/gn", "//"),
"--build_dir",
rebase_path(root_out_dir, "//"),
]
if (defined(skip_dirs)) {
args += [ "--skip_dirs" ] + string_join(",", rebase_path(skip_dirs, "//"))
}
if (defined(notice_txt)) {
args +=
[ "--notice_txt" ] + string_join(",", rebase_path(notice_txt, "//"))
}
if (defined(license_allow_list)) {
args += [ "--license_allow_list" ] + "{ " +
string_join(", ", rebase_path(notice_txt, "//")) + " }"
}
}
}