load(
    "//doc:defs.bzl",
    "DEFAULT_TEST_TAGS",
    "enumerate_filegroup",
)
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_py.bzl",
    "drake_py_binary",
    "drake_py_library",
    "drake_py_unittest",
)

package(default_visibility = ["//visibility:private"])

# This library is the loadable module used by our pydrake documentation tools
# to render system diagrams.  Our Doxygen build uses the same Python file, but
# not via this library target.
drake_py_library(
    name = "system_doxygen",
    srcs = ["system_doxygen.py"],
    visibility = [
        "//doc/pydrake:__pkg__",
        "//tools/workspace/pybind11:__pkg__",
    ],
)

drake_py_unittest(
    name = "system_doxygen_test",
    deps = [":system_doxygen"],
)

filegroup(
    name = "doxygen_input",
    srcs = [
        "Doxyfile_CXX.in",
        "DoxygenLayout.xml",
        "doxygen.h",
        "doxygen_extra.css",
        "header.html.patch",
        "footer.html",
        # We call this program directly as a shebang executable, without using
        # the py_library target above.  This is easier than trying to get the
        # PYTHONPATH configuration correct for use as a library.
        "system_doxygen.py",
    ],
    tags = [
        # Don't re-lint system_doxygen.py.  The py_library rule already has it.
        "nolint",
    ],
)

enumerate_filegroup(
    name = "doxygen_input.txt",
    data = [":doxygen_input"],
)

drake_py_binary(
    name = "build",
    srcs = ["build.py"],
    add_test_rule = 1,
    data = [
        ":doxygen_input",
        ":doxygen_input.txt",
        "//:.bazelproject",
        "//tools/workspace:cmake_configure_file",
        "@doxygen",
        "@rules_python//python/runfiles",
    ],
    test_rule_args = [
        "--out_dir=<test>",
        # Only generate some modules, so that the test provides quick feedback.
        "--quick",
        "drake/math",
    ],
    test_rule_tags = DEFAULT_TEST_TAGS,
    visibility = ["//doc:__pkg__"],
    deps = [
        "//doc:defs",
    ],
)

add_lint_tests()
