blob: db96b08352d081e5d078d5d53eaa4884be88a50f [file] [log] [blame]
# Copyright 2018 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("//src/modular/build/fuchsia_module_facet.gni")
import("//src/sys/cmc/build/cmc.gni")
# Validates a cmx file
#
# The cmx_validate template will ensure that a given cmx file is conformant to
# the cmx schema, as defined by //src/sys/cmc/schema.json. A stamp file is
# generated to mark that a given cmx file has passed.
#
# Parameters
#
# manifest (required)
# [file] The path to the cmx file that is to be validated
#
# deps (optional)
# testonly (optional)
# visibility (optional)
template("cmx_validate") {
cmc(target_name) {
forward_variables_from(invoker,
[
"deps",
"sources",
"testonly",
"visibility",
])
stamp_file = "$target_gen_dir/$target_name.verified"
inputs = [ invoker.manifest ]
outputs = [ stamp_file ]
args = [
"--stamp",
rebase_path(stamp_file, root_build_dir),
"validate",
rebase_path(invoker.manifest, root_build_dir),
]
}
validate_module_cmx_facet("module_" + target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
cmx = invoker.manifest
}
}
# Merges together cmx files
#
# The cmx_merge template will combine the given cmx files into a single cmx
# file.
#
# Parameters
#
# sources (required)
# [list of files] A list of cmx files that are to be merged.
#
# output_name (optional)
# [path] Name for the output.
# If not specified, the target name is used.
#
# deps (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("cmx_merge") {
cmc(target_name) {
forward_variables_from(invoker,
[
"deps",
"output_name",
"sources",
"testonly",
"visibility",
])
if (!defined(output_name)) {
output_name = target_name
}
merged_output = "${target_out_dir}/${output_name}"
inputs = invoker.sources
outputs = [ merged_output ]
args = [
"merge",
"--output",
rebase_path(merged_output, root_build_dir),
]
foreach(source, sources) {
args += [ rebase_path(source, root_build_dir) ]
}
}
}
# Formats a cmx file
#
# The cmx_format template will minify the given cmx file if is_debug is set to
# false, and will pretty-print the given cmx file if is_debug is set to true.
#
# Parameters
#
# manifest (required)
# [file] The path to the cmx file that is to be formatted
#
# output_name (optional)
# [path] Name for the output.
# If not specified, the target name is used.
#
# deps (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("cmx_format") {
cmc(target_name) {
forward_variables_from(invoker,
[
"deps",
"output_name",
"testonly",
"visibility",
])
if (!defined(output_name)) {
output_name = target_name
}
formatted_output = "${target_out_dir}/${output_name}"
inputs = [ invoker.manifest ]
outputs = [ formatted_output ]
args = [
"format",
"--output",
rebase_path(formatted_output, root_build_dir),
rebase_path(invoker.manifest, root_build_dir),
]
if (is_debug) {
args += [ "--pretty" ]
}
}
}
# Prepares a cmx file for packaging
#
# Parameters
#
# manifest (required)
# [file] The cmx file
#
# output_name (optional)
# [path] Name for the output.
# If not specified, the target name is used.
template("cmx") {
cmx_validate("${target_name}_validate") {
forward_variables_from(invoker,
[
"manifest",
"deps",
"testonly",
])
visibility = [ ":*" ]
}
invoker.deps += [ ":${target_name}_validate" ]
patches_name = "${target_name}_patches"
cmx_patches = "${target_out_dir}/${target_name}_cmx_patches"
generated_file(patches_name) {
data_keys = [ "cmx_patches_data" ]
walk_keys = [ "cmx_patches_walk" ]
outputs = [ cmx_patches ]
output_conversion = "json"
visibility = [ ":*" ]
forward_variables_from(invoker,
[
"deps",
"testonly",
])
}
needs_debugdata =
select_variant + [ "profile" ] - [ "profile" ] != select_variant
cmx_merge("${target_name}_merge") {
sources = [
cmx_patches,
invoker.manifest,
]
if (needs_debugdata) {
sources += [ "//build/config/sanitizers/debugdata.cmx" ]
}
forward_variables_from(invoker,
[
"deps",
"testonly",
])
deps += [ ":${patches_name}" ]
visibility = [ ":*" ]
}
invoker.deps += [ ":${target_name}_merge" ]
merged = get_target_outputs(":${target_name}_merge")
merged = merged[0]
cmx_format(target_name) {
manifest = merged
forward_variables_from(invoker,
[
"deps",
"output_name",
"testonly",
"visibility",
])
}
}