# -*- bazel -*-

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

# Glob for all files in this package. We do one big glob (instead of several
# smaller ones) so Bazel's loading is as efficient as possible.
_SRCS = glob(["**/*"])

# All files in this repository are public. Since everything here is excluded
# from Stable API policy, there's no point in trying to set visibility for the
# stable parts vs internal-use-only parts.
exports_files(_SRCS)

# Provide a filegroup with all files.
filegroup(
    name = "drake_models",
    srcs = _SRCS,
)

# Provide one filegroup per subdirectory (so Bazel users can depend on a
# smaller set of runfiles, for efficiency).
[
    filegroup(
        name = top_dir,
        srcs = [
            src
            for src in _SRCS
            if src.startswith(top_dir + "/")
        ],
    )
    for top_dir in depset([
        src.split("/", 1)[0]
        for src in _SRCS
        if "/" in src
    ]).to_list()
]

# Nominally, the `@drake_models` external is fetched via `github_archive()`,
# which creates a json metadata files to explain what it downloaded. Drake's
# install rules use that file to pin the lazy-download version of the models.
#
# However, in case a developer is using a local checkout of `@drake_models`,
# the json file will not exist. In that case, we need to generate a stub file
# to take its place, so that our Bazel install rules can still find it. We'll
# fill it with dummy data. To guard against shipping a Drake release with the
# dummy data, the package_map_remote_test checks the content of the json file.
glob(["drake_repository_metadata.json"], allow_empty = True) or genrule(
    name = "_gen_dummy_metadata",
    outs = ["drake_repository_metadata.json"],
    cmd = "echo '{}' > $@".format(
        json.encode(dict(
            urls = [],
            sha256 = "",
            strip_prefix = "",
        )),
    ),
)
