blob: 9ce43dcbdbea5660a8097d7248e7003410d06a2d [file]
# 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("//build/bazel/bazel_tool_action.gni")
import("//build/compiled_action.gni")
# Validate a JSON file against a JSON schema.
#
# data (required)
# [file] JSON file to validate.
# If this file is not valid JSON, or does not meet the schema, then this
# target will fail to build.
#
# schema (required)
# [file] Schema to use for validation.
#
# sources (optional)
# [list of files] Additional schema files referenced by schema.
# Additional schema files used by the original schema file must be listed
# here for validation to be re-run when they change.
#
# allow_comments (optional; default is false)
# [bool] If true, the |data| file may contain C-style comments
# (`/* block */` and `// inline`) that will be ignored.
#
# applicable_licenses (optional)
# deps (optional)
# public_deps (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
#
# Example of usage:
#
# validate_json("validate_my_json") {
# data = "my_file.json"
# schema = "my_schema.json"
# }
template("validate_json") {
assert(defined(invoker.data), "data is required")
assert(defined(invoker.schema), "schema is required")
allow_comments = defined(invoker.allow_comments) && invoker.allow_comments
_action_args = {
forward_variables_from(invoker,
[
"applicable_licenses",
"assert_no_deps",
"deps",
"sources",
"public_deps",
"testonly",
"visibility",
])
stamp_file = "$target_gen_dir/$target_name.json_validated"
inputs = [
invoker.data,
invoker.schema,
]
outputs = [ stamp_file ]
args = []
if (allow_comments) {
args += [ "--json5" ]
}
args += [
rebase_path(invoker.schema, root_build_dir),
rebase_path(invoker.data, root_build_dir),
rebase_path(stamp_file, root_build_dir),
]
}
bazel_tool_action(target_name) {
forward_variables_from(_action_args, "*")
tool_label = "//build/tools/json_validator:json_validator_valico"
}
}
# Validate a JSON5 file against a JSON schema.
#
# data (required)
# [file] JSON5 file to validate.
# If this file is not valid JSON5, or does not meet the schema, then this
# target will fail to build.
#
# schema (required)
# [file] Schema to use for validation.
#
# sources (optional)
# [list of files] Additional schema files referenced by schema.
# Additional schema files used by the original schema file must be listed
# here for validation to be re-run when they change.
#
# applicable_licenses (optional)
# deps (optional)
# public_deps (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
#
# Example of usage:
#
# validate_json5("validate_my_json") {
# data = "my_file.json5"
# schema = "my_schema.json"
# }
template("validate_json5") {
assert(defined(invoker.data), "data is required")
assert(defined(invoker.schema), "schema is required")
bazel_tool_action(target_name) {
forward_variables_from(invoker,
[
"applicable_licenses",
"deps",
"sources",
"public_deps",
"testonly",
"visibility",
])
tool_label = "//build/tools/json_validator:json_validator_valico"
stamp_file = "$target_gen_dir/$target_name.json5_validated"
inputs = [
invoker.data,
invoker.schema,
]
outputs = [ stamp_file ]
args = [
"--json5",
rebase_path(invoker.schema, root_build_dir),
rebase_path(invoker.data, root_build_dir),
rebase_path(stamp_file, root_build_dir),
]
}
}