blob: e9b723a20629221c1e428c43459674ed1e65a575 [file] [log] [blame]
# Copyright 2020 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/dart/dart_library.gni")
import("//build/dart/dart_tool.gni")
import("//build/dart/test.gni")
group("strict_deps_group") {
deps = [ ":strict_deps" ]
}
dart_library_target_name = "dart_strict_deps_proto"
dart_library_package_name = "tools.dart-strict-deps.$dart_library_target_name"
dart_tool("strict_deps") {
package_name = "strict_deps"
main_dart = "bin/main.dart"
source_dir = "bin"
output_name = "strict_deps"
deps = [
":$dart_library_target_name",
"./library:dart_strict_deps_lib",
"//third_party/dart-pkg/pub/args",
]
}
# This is the generated dart package's source root directory (where the
# pubspec.yaml, etc. go).
package_root_dir = "$target_gen_dir/$dart_library_target_name"
# This is where we put the generated files.
package_gen_dir = "$package_root_dir/lib"
proto_input_filepaths = [ "protos/models.proto" ]
# Compute the list of generated files.
proto_output_filepaths = []
foreach(source, proto_input_filepaths) {
# Extract where the generated file will be.
gen_dir = get_path_info(source, "gen_dir")
# extract the non-extension part of the file.
name_part = get_path_info(source, "name")
source_prefix =
"$package_gen_dir/" + rebase_path(gen_dir, target_gen_dir) + "/$name_part"
proto_output_filepaths += [
"${source_prefix}.pb.dart",
"${source_prefix}.pbenum.dart",
"${source_prefix}.pbjson.dart",
"${source_prefix}.pbserver.dart",
]
}
protoc_label = "//third_party/protobuf:protoc($host_toolchain)"
protoc_gen_dart_label = "//tools/protobuf/protoc_gen_dart($host_toolchain)"
protoc_path = get_label_info(protoc_label, "root_out_dir") + "/protoc"
proto_gen_target = dart_library_target_name + "_generate_bindings"
copy_pubspec_target = dart_library_target_name + "_copy_pubspec"
generated_file("protoc_gen_dart_snapshot_info") {
visibility = [ ":*" ]
outputs = [ "$target_gen_dir/${target_name}.snapshot_info" ]
data_keys = [ "rebased_snapshot_path" ]
walk_keys = [ "rebased_snapshot_path_barrier" ]
rebase = root_build_dir
deps = [ protoc_gen_dart_label ]
}
# This target runs the protoc tool to generate dart sources
action(proto_gen_target) {
visibility = [ ":*" ]
plugin_path = get_label_info(protoc_gen_dart_label, "root_out_dir") +
"/dart-tools/protoc_gen_dart"
# dart snapshot dependency information.
depfile = "$target_gen_dir/${target_name}.d"
snapshot_info_target = ":protoc_gen_dart_snapshot_info"
snapshot_info_files = get_target_outputs(snapshot_info_target)
snapshot_info_file = snapshot_info_files[0]
proto_outputs_file = "${target_gen_dir}/${target_name}_proto.outputs"
write_file(proto_outputs_file,
rebase_path(proto_output_filepaths, root_build_dir))
script = "//build/secondary/third_party/protobuf/protoc_wrapper.py"
sources = proto_input_filepaths
inputs = [
protoc_path,
plugin_path,
snapshot_info_file,
proto_outputs_file,
] + proto_input_filepaths
outputs = proto_output_filepaths
args = [
# path to compiler
"--protoc",
rebase_path(protoc_path, root_build_dir),
# the directory the supplied proto paths are in
"--proto-in-dir",
rebase_path(".", root_build_dir),
# extra import dir for .proto files: the root of fuchsia tree
"--import-dir=" + rebase_path("//", root_build_dir),
# the dart bindings generator
"--plugin",
rebase_path(plugin_path, root_build_dir),
# output path of where bindings are generated
"--plugin-out-dir",
rebase_path(package_gen_dir, root_build_dir),
# plugin dependency information
"--plugin-depfile",
rebase_path(depfile, root_build_dir),
"--plugin-depfile-deps",
rebase_path(snapshot_info_file, root_build_dir),
"--plugin-depfile-outputs",
rebase_path(proto_outputs_file, root_build_dir),
]
# the proto files themselves
args += proto_input_filepaths
deps = [
# dart plugin for the protobuf compiler
protoc_gen_dart_label,
# protobuf compiler
protoc_label,
# snapshot information for the dart plugin
snapshot_info_target,
]
}
copy(copy_pubspec_target) {
visibility = [ ":*" ]
sources = [ "//build/dart/empty_pubspec.yaml" ]
outputs = [ "$package_root_dir/pubspec.yaml" ]
}
# Using the dart sources generated from "gen" above, this constructs a dart
# library out of them.
dart_library(dart_library_target_name) {
disable_analysis = true
package_root = package_root_dir
source_dir = "lib"
package_name = dart_library_package_name
sources = rebase_path(proto_output_filepaths, "$package_root/lib")
deps = [
":$copy_pubspec_target",
":$proto_gen_target",
"//third_party/dart-pkg/pub/protobuf",
]
}
dart_test("dart_strict_deps_tests") {
sources = [
"dependency_check_test.dart",
"file_processor_test.dart",
]
deps = [
":dart_strict_deps_proto",
"./library:dart_strict_deps_lib",
"//third_party/dart-pkg/pub/analyzer",
"//third_party/dart-pkg/pub/mockito",
"//third_party/dart-pkg/pub/package_config",
"//third_party/dart-pkg/pub/quiver",
"//third_party/dart-pkg/pub/test",
]
}
group("tests") {
testonly = true
deps = [ ":dart_strict_deps_tests($host_toolchain)" ]
}