daml/bazel_tools/docs.bzl

32 lines
1.1 KiB
Python
Raw Normal View History

# Copyright (c) 2020 The DAML Authors. All rights reserved.
2019-04-04 11:33:38 +03:00
# SPDX-License-Identifier: Apache-2.0
# Build rule for a DA Documentation Package.
def da_doc_package(**args):
src_name = args["name"] + "-srcs"
native.filegroup(
name = src_name,
srcs = native.glob(["source/**"]),
)
2019-04-04 11:33:38 +03:00
prepare = args.get("prepare", "")
extra_srcs = args.get("extra_srcs", [])
native.genrule(
name = args["name"],
outs = ["sources.tar.gz"],
srcs = [src_name, "@tar_dev_env//:tar", "@gzip_dev_env//:gzip"] + extra_srcs,
cmd = """
2019-04-04 11:33:38 +03:00
export PATH=$$(dirname $(location {gzip})):$$PATH
# Bazel makes it fairly hard to get the directory in a robust way so
# we take the first file and strip everything after source.
SRCS=($(locations {srcs}))
BASEDIR=$${{SRCS[0]%%source*}}
{prepare}
$(location {tar}) czhf $(location sources.tar.gz) -C $$BASEDIR source
""".format(
srcs = ":" + src_name,
prepare = prepare,
tar = "@tar_dev_env//:tar",
gzip = "@gzip_dev_env//:gzip",
),
)