# -*- python -*-

load(
    "@drake//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")

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

filegroup(
    name = "test_models",
    testonly = 1,
    srcs = glob([
        "test/**/*.config",
        "test/**/*.obj",
        "test/**/*.sdf",
        "test/**/*.urdf",
        "test/**/*.xml",
    ]),
)

drake_cc_package_library(
    name = "parsing",
    deps = [
        ":multibody_plant_sdf_parser",
        ":package_map",
        ":parser_path_utils",
        ":scene_graph_parser_detail",
        ":sdf_parser_common",
    ],
)

drake_cc_library(
    name = "package_map",
    srcs = [
        "package_map.cc",
    ],
    hdrs = [
        "package_map.h",
    ],
    deps = [
        "//common",
        "@spruce",
        "@tinydir",
        "@tinyxml2",
    ],
)

drake_cc_library(
    name = "parser_path_utils",
    srcs = [
        "parser_path_utils.cc",
    ],
    hdrs = [
        "parser_path_utils.h",
    ],
    visibility = [
        "//attic:__subpackages__",
    ],
    deps = [
        ":package_map",
        "//common",
        "@spruce",
    ],
)

drake_cc_library(
    name = "sdf_parser_common",
    srcs = [
        "sdf_parser_common.cc",
    ],
    hdrs = [
        "sdf_parser_common.h",
    ],
    deps = [
        "//common:essential",
        "//multibody/multibody_tree/multibody_plant:coulomb_friction",
        "@sdformat",
    ],
)

drake_cc_library(
    name = "scene_graph_parser_detail",
    srcs = [
        "scene_graph_parser_detail.cc",
    ],
    hdrs = [
        "scene_graph_parser_detail.h",
    ],
    install_hdrs_exclude = [
        # This header includes `sdformat` directly, which we do not want to
        # expose externally.
        "scene_graph_parser_detail.h",
    ],
    visibility = [
        "//visibility:private",
    ],
    deps = [
        ":package_map",
        ":parser_path_utils",
        ":sdf_parser_common",
        "//geometry:scene_graph",
        "//multibody/multibody_tree/multibody_plant:coulomb_friction",
        "@sdformat",
    ],
)

drake_cc_library(
    name = "multibody_plant_sdf_parser",
    srcs = [
        "multibody_plant_sdf_parser.cc",
    ],
    hdrs = [
        "multibody_plant_sdf_parser.h",
    ],
    deps = [
        ":scene_graph_parser_detail",
        ":sdf_parser_common",
        "//multibody/multibody_tree/multibody_plant",
        "@sdformat",
    ],
)

drake_cc_googletest(
    name = "multibody_plant_sdf_parser_test",
    data = [
        ":test_models",
        "//multibody/benchmarks/acrobot:models",
    ],
    deps = [
        ":multibody_plant_sdf_parser",
        "//common:find_resource",
        "//common/test_utilities",
        "//multibody/benchmarks/acrobot",
        "//multibody/benchmarks/acrobot:make_acrobot_plant",
    ],
)

drake_cc_googletest(
    name = "scene_graph_parser_detail_test",
    deps = [
        ":scene_graph_parser_detail",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "package_map_test",
    data = [
        ":test_models",
    ],
    deps = [
        ":package_map",
        "//common:find_resource",
    ],
)

drake_cc_googletest(
    name = "parser_path_utils_test",
    deps = [
        ":parser_path_utils",
    ],
)

add_lint_tests()
