| # 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/compiled_action.gni") |
| import("//build/host.gni") |
| import("//build/rust/rustc_binary.gni") |
| import("//build/rust/rustc_test.gni") |
| import("//build/testing/golden_files.gni") |
| import("//tools/fidl/fidlc/testdata/info.gni") |
| |
| if (is_host) { |
| common_sources = [ |
| "src/fidljson.rs", |
| "src/main.rs", |
| "src/templates/markdown/mod.rs", |
| "src/templates/mod.rs", |
| ] |
| |
| common_source_root = "src/main.rs" |
| |
| common_inputs = [ |
| "src/templates/markdown/partials/header.hbs", |
| "src/templates/markdown/partials/types/filename.hbs", |
| "src/templates/markdown/library.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/markdown/partials/declarations/aliases.hbs", |
| "src/templates/markdown/partials/declarations/protocols.hbs", |
| "src/templates/markdown/partials/types/doc.hbs", |
| "src/templates/markdown/partials/declarations/bits.hbs", |
| "src/templates/markdown/partials/declarations/unions.hbs", |
| "src/templates/markdown/partials/declarations/services.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", |
| "src/templates/markdown/style.css", |
| ] |
| |
| common_deps = [ |
| "//third_party/rust_crates:anyhow", |
| "//third_party/rust_crates:argh", |
| "//third_party/rust_crates:handlebars", |
| "//third_party/rust_crates:heck", |
| "//third_party/rust_crates:lazy_static", |
| "//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:tracing", |
| "//third_party/rust_crates:tracing-subscriber", |
| ] |
| |
| rustc_binary("fidldoc_bin") { |
| name = "fidldoc" |
| edition = "2021" |
| source_root = common_source_root |
| deps = common_deps |
| 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") { |
| edition = "2021" |
| source_root = common_source_root |
| deps = common_deps + [ "//third_party/rust_crates:tempfile" ] |
| sources = common_sources |
| inputs = common_inputs + [ |
| "src/templates/markdown/testdata/README.md", |
| "src/templates/markdown/testdata/_toc.yaml", |
| "src/fidldoc.config.json", |
| ] |
| } |
| |
| fidl_testdata_info_filtered = [] |
| foreach(info, fidl_testdata_info) { |
| if (info.denylist + [ "fidldoc" ] - [ "fidldoc" ] == info.denylist) { |
| fidl_testdata_info_filtered += [ info ] |
| } |
| } |
| |
| compiled_action("generate_goldens") { |
| testonly = true |
| tool = ":fidldoc_bin" |
| tool_output_name = "fidldoc" |
| deps = [ ":fidldoc_copy_config" ] |
| sources = [] |
| inputs = [ "${host_tools_dir}/fidldoc.config.json" ] |
| args = [ |
| "--silent", |
| "--config", |
| rebase_path("${host_tools_dir}/fidldoc.config.json", root_build_dir), |
| "--out", |
| rebase_path("${target_gen_dir}/goldens", root_build_dir), |
| ] |
| outputs = [ |
| "$target_gen_dir/goldens/_toc.yaml", |
| "$target_gen_dir/goldens/README.md", |
| "$target_gen_dir/goldens/style.css", |
| ] |
| 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_files("fidldoc_golden_tests") { |
| testonly = true |
| deps = [ ":generate_goldens" ] |
| comparisons = [ |
| { |
| golden = "goldens/_toc.yaml.golden" |
| candidate = "$target_gen_dir/goldens/_toc.yaml" |
| }, |
| { |
| golden = "goldens/README.md.golden" |
| candidate = "$target_gen_dir/goldens/README.md" |
| }, |
| { |
| golden = "goldens/style.css.golden" |
| candidate = "$target_gen_dir/goldens/style.css" |
| }, |
| ] |
| foreach(info, fidl_testdata_info_filtered) { |
| comparisons += [ |
| { |
| golden = "goldens/${info.name}.md.golden" |
| candidate = "$target_gen_dir/goldens/${info.library}/README.md" |
| }, |
| ] |
| } |
| } |
| } |
| |
| install_host_tools("fidldoc") { |
| deps = [ |
| ":fidldoc_bin($host_toolchain)", |
| ":fidldoc_copy_config($host_toolchain)", |
| ] |
| outputs = [ "fidldoc" ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":fidldoc_bin_test($host_toolchain)", |
| ":fidldoc_golden_tests($host_toolchain)", |
| ] |
| } |