blob: 581b6bade9a8f49aadefaa8407ba17b6b9896d0f [file] [log] [blame]
# Copyright 2024 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/go/go_binary.gni")
import("//build/go/go_library.gni")
import("//build/go/go_test.gni")
import("//build/go/golden_go_proto.gni")
import("//build/testing/golden_files.gni")
if (is_host) {
golden_go_proto("stardoc_output") {
sources = [ "third_party/stardoc/stardoc_output.proto" ]
}
go_library("proto_lib") {
source_dir = "third_party/stardoc"
sources = [ "stardoc_output.pb.go" ]
deps = [ "//third_party/golibs:google.golang.org/protobuf" ]
non_go_deps = [ ":stardoc_output" ]
}
go_library("bazel_docgen_lib") {
sources = [
"doc_generator.go",
"file_provider.go",
"markdown_renderer.go",
"markdown_renderer_test.go",
"renderer.go",
"templates.go",
]
deps = [
":proto_lib",
"//third_party/golibs:golang.org/x/exp",
"//third_party/golibs:gopkg.in/yaml.v2",
]
}
go_test("bazel_docgen_lib_tests") {
library = ":bazel_docgen_lib"
}
go_library("main") {
source_dir = "cmd"
sources = [ "main.go" ]
deps = [
":bazel_docgen_lib",
":proto_lib",
"//third_party/golibs:google.golang.org/protobuf",
]
}
go_binary("bin") {
output_name = "bazel-docgen"
library = ":main"
}
compiled_action("generate_goldens") {
testonly = true
tool = ":bin"
tool_output_name = "bazel-docgen"
sources = [ "testdata/test_lib.textproto" ]
args = [
"--proto",
rebase_path("testdata/test_lib.textproto", root_build_dir),
"--out_dir",
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/rule_example_rule.md",
"$target_gen_dir/goldens/func_some_function.md",
"$target_gen_dir/goldens/func_empty_function.md",
"$target_gen_dir/goldens/provider_FooInfo.md",
"$target_gen_dir/goldens/repo_rule_empty_repo.md",
]
}
golden_files("bazeldoc_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/rule_example_rule.md.golden"
candidate = "$target_gen_dir/goldens/rule_example_rule.md"
},
{
golden = "goldens/func_some_function.md.golden"
candidate = "$target_gen_dir/goldens/func_some_function.md"
},
{
golden = "goldens/func_empty_function.md.golden"
candidate = "$target_gen_dir/goldens/func_empty_function.md"
},
{
golden = "goldens/provider_FooInfo.md.golden"
candidate = "$target_gen_dir/goldens/provider_FooInfo.md"
},
{
golden = "goldens/repo_rule_empty_repo.md.golden"
candidate = "$target_gen_dir/goldens/repo_rule_empty_repo.md"
},
]
}
}
group("tests") {
testonly = true
deps = [
":bazel_docgen_lib_tests($host_toolchain)",
":bazeldoc_golden_tests($host_toolchain)",
]
}
install_host_tools("bazel-docgen") {
deps = [ ":bin($host_toolchain)" ]
outputs = [ "bazel-docgen" ]
}