| # Copyright 2019 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/host.gni") |
| import("//build/rust/rustc_binary.gni") |
| import("//build/rust/rustc_test.gni") |
| import("//build/test/test_package.gni") |
| import("//build/testing/golden_test.gni") |
| import("//zircon/tools/fidl/testdata/info.gni") |
| |
| if (host_toolchain == current_toolchain) { |
| common_sources = [ |
| "src/fidljson.rs", |
| "src/main.rs", |
| "src/simple_logger.rs", |
| "src/templates/html/mod.rs", |
| "src/templates/markdown/mod.rs", |
| "src/templates/mod.rs", |
| ] |
| |
| common_inputs = [ |
| "src/templates/markdown/partials/header.hbs", |
| "src/templates/markdown/partials/types/filename.hbs", |
| "src/templates/html/interface.hbs", |
| "src/templates/markdown/interface.hbs", |
| "src/templates/markdown/partials/header_dir.hbs", |
| "src/templates/markdown/partials/declarations/tables.hbs", |
| "src/templates/markdown/partials/declarations/enums.hbs", |
| "src/templates/markdown/partials/types/vector.hbs", |
| "src/templates/markdown/partials/declarations/constants.hbs", |
| "src/templates/html/main.hbs", |
| "src/templates/markdown/partials/declarations/type_aliases.hbs", |
| "src/templates/markdown/partials/declarations/protocols.hbs", |
| "src/templates/markdown/partials/types/doc.hbs", |
| "src/templates/markdown/partials/footer.hbs", |
| "src/templates/markdown/partials/declarations/bits.hbs", |
| "src/templates/markdown/partials/declarations/unions.hbs", |
| "src/templates/markdown/main.hbs", |
| "src/templates/markdown/toc.hbs", |
| "src/templates/markdown/partials/types/type.hbs", |
| "src/templates/markdown/partials/declarations/structs.hbs", |
| ] |
| |
| rustc_binary("fidldoc_bin") { |
| name = "fidldoc" |
| edition = "2018" |
| deps = [ ":rust_crates" ] |
| |
| sources = common_sources |
| |
| inputs = common_inputs |
| } |
| |
| copy("fidldoc_copy_config") { |
| sources = [ "src/fidldoc.config.json" ] |
| outputs = [ "${host_tools_dir}/fidldoc.config.json" ] |
| } |
| |
| rustc_test("fidldoc_bin_test") { |
| source_root = "src/main.rs" |
| deps = [ |
| ":fidldoc_bin", |
| ":rust_crates", |
| ] |
| |
| sources = common_sources |
| |
| inputs = common_inputs + [ |
| "src/templates/markdown/testdata/README.md", |
| "src/templates/markdown/testdata/_toc.yaml", |
| "src/fidldoc.config.json", |
| ] |
| } |
| |
| group("rust_crates") { |
| deps = [ |
| "//third_party/rust_crates:anyhow", |
| "//third_party/rust_crates:argh", |
| "//third_party/rust_crates:glob", |
| "//third_party/rust_crates:handlebars", |
| "//third_party/rust_crates:lazy_static", |
| "//third_party/rust_crates:log", |
| "//third_party/rust_crates:pulldown-cmark", |
| "//third_party/rust_crates:rayon", |
| "//third_party/rust_crates:regex", |
| "//third_party/rust_crates:serde", |
| "//third_party/rust_crates:serde_json", |
| "//third_party/rust_crates:tempfile", |
| ] |
| } |
| } |
| |
| install_host_tools("fidldoc") { |
| deps = [ |
| ":fidldoc_bin($host_toolchain)", |
| ":fidldoc_copy_config($host_toolchain)", |
| ] |
| |
| outputs = [ "fidldoc" ] |
| } |
| |
| fidl_testdata_info_filtered = [] |
| foreach(info, fidl_testdata_info) { |
| if (info.denylist + [ "fidldoc" ] - [ "fidldoc" ] == info.denylist) { |
| fidl_testdata_info_filtered += [ info ] |
| } |
| } |
| |
| copy("config_for_tests") { |
| sources = [ "src/fidldoc.config.json" ] |
| outputs = [ "$target_gen_dir/fidldoc.config.json" ] |
| } |
| |
| compiled_action("generate_goldens") { |
| testonly = true |
| tool = ":fidldoc_bin" |
| tool_output_name = "fidldoc" |
| deps = [ ":config_for_tests" ] |
| sources = [] |
| args = [ |
| "--silent", |
| "--config", |
| rebase_path(target_gen_dir, root_build_dir) + "/fidldoc.config.json", |
| "--out", |
| rebase_path(target_gen_dir, root_build_dir) + "/goldens", |
| ] |
| outputs = [ |
| "$target_gen_dir/goldens/_toc.yaml", |
| "$target_gen_dir/goldens/README.md", |
| ] |
| foreach(info, fidl_testdata_info_filtered) { |
| deps += [ "${info.target}($fidl_toolchain)" ] |
| json_ir = "${info.fidl_gen_dir}/${info.target_name}.fidl.json" |
| sources += [ json_ir ] |
| args += [ rebase_path(json_ir, root_build_dir) ] |
| outputs += [ "$target_gen_dir/goldens/${info.library}/README.md" ] |
| } |
| } |
| |
| golden_test("fidldoc_golden_tests") { |
| goldens_dir = "goldens" |
| deps = [ ":generate_goldens" ] |
| entries = [ |
| { |
| golden = "_toc.yaml.golden" |
| generated = "$target_gen_dir/goldens/_toc.yaml" |
| }, |
| { |
| golden = "README.md.golden" |
| generated = "$target_gen_dir/goldens/README.md" |
| }, |
| ] |
| foreach(info, fidl_testdata_info_filtered) { |
| entries += [ |
| { |
| golden = "${info.name}.md.golden" |
| generated = "$target_gen_dir/goldens/${info.library}/README.md" |
| }, |
| ] |
| } |
| } |
| |
| group("tests") { |
| testonly = true |
| |
| deps = [ |
| ":fidldoc_bin_test($host_toolchain)", |
| ":fidldoc_golden_tests($host_toolchain)", |
| ] |
| } |