daml/templates/BUILD.bazel
Andreas Herrmann cf24597e70
Factor out reproducibility flags for tar and gzip (#6884)
* Factor out tar/gzip reproducibility flags

* use mktgz in package-app

* Bazel managed tar/gzip

* Remove quiet = True

As stated in the comment this is no longer required with Bazel >= 3.0.

* Build package-app as a sh_binary

This way Bazel will manage the runtime dependencies tar, gzip, mktgz,
and patchelf.

package-app.sh changes directory so it needs to make sure that all paths
are absolute and that the runfiles tree/manifest location is forwarded
to programs called by package-app.sh.

* Avoid file path too long errors

* Fix readlink -f on MacOS

* Document abspath

changelog_begin
changelog_end

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2020-08-05 14:27:14 +00:00

110 lines
3.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("@os_info//:os_info.bzl", "is_windows")
exports_files(glob(["create-daml-app-test-resources/*"]))
# Split out into a separate rule so we can cheaply include this in the
# live-preview.
genrule(
name = "create-daml-app-docs",
srcs = glob(
["create-daml-app/**"],
exclude = ["**/NO_AUTO_COPYRIGHT"],
) + [
"//templates:create-daml-app-test-resources/messaging.patch",
],
outs = ["create-daml-app-docs.tar.gz"],
cmd = """
set -eou pipefail
SRC=templates
OUT=create-daml-app
mkdir -p $$OUT
cp -rL $$SRC/create-daml-app/* $$OUT
# Undo project name templating since we dont want that to show up
# in the docs.
find $$OUT/ -name '*.template' -type f -exec sh -c 'mv "$$0" "$${0%.template}" && sed -i "s/__PROJECT_NAME__/create-daml-app/g" "$${0%.template}"' {} ';'
# Apply patch for messaging feature (we only need the "after" state)
PATCH_TOOL=$$PWD/$(location @patch_dev_env//:patch)
MESSAGING_PATCH=$$PWD/$(location //templates:create-daml-app-test-resources/messaging.patch)
$$PATCH_TOOL -s -p1 < $$MESSAGING_PATCH
$(execpath //bazel_tools/sh:mktgz) $@ create-daml-app
""",
tools = [
"//bazel_tools/sh:mktgz",
"@patch_dev_env//:patch",
],
visibility = ["//visibility:public"],
) if not is_windows else None
genrule(
name = "templates-tarball",
srcs = glob(
[
"default-gitignore",
"default-dlint-yaml",
"skeleton/**",
"empty-skeleton/**",
"create-daml-app/**",
"quickstart-java/**",
"quickstart-scala/**",
],
exclude = ["**/NO_AUTO_COPYRIGHT"],
) + [
"//docs:quickstart-java.tar.gz",
"//docs:daml-intro-templates",
"//docs:daml-patterns",
"//docs:copy-trigger-template",
"//docs:script-example-template",
"//language-support/scala/examples:quickstart-scala-dir",
],
outs = ["templates-tarball.tar.gz"],
cmd = """
SRC=templates
OUT=templates-tarball
# templates in templates dir
for d in skeleton empty-skeleton create-daml-app quickstart-scala quickstart-java; do
mkdir -p $$OUT/$$d
cp -rL $$SRC/$$d/* $$OUT/$$d/
# use default .gitignore and .dlint.yaml if they don't exist in the template
cp -n $$SRC/default-gitignore $$OUT/$$d/.gitignore
cp -n $$SRC/default-dlint-yaml $$OUT/$$d/.dlint.yaml
# We avoid introducing infix syntax in the GSG so we disable
# the lint there.
if [ "$$d" = "create-daml-app" ]; then
cat >> $$OUT/$$d/.dlint.yaml <<EOF
# This rule is enabled by default but we avoid
# infix syntax here to keep things simple.
- ignore: {name: Use infix }
EOF
fi
done
## special cases we should work to remove
# quickstart-java template
tar xf $(location //docs:quickstart-java.tar.gz) --strip-components=1 -C $$OUT/quickstart-java
# quickstart-scala template
cp -r $(location //language-support/scala/examples:quickstart-scala-dir)/* $$OUT/quickstart-scala/
# daml intro templates
tar xf $(location //docs:daml-intro-templates) -C $$OUT
mkdir -p $$OUT/copy-trigger
tar xf $(location //docs:copy-trigger-template) -C $$OUT/copy-trigger
mkdir -p $$OUT/script-example
tar xf $(location //docs:script-example-template) -C $$OUT/script-example
mkdir -p $$OUT/daml-patterns
tar xf $(location //docs:daml-patterns) --strip-components=1 -C $$OUT/daml-patterns
$(execpath //bazel_tools/sh:mktgz) $@ templates-tarball
""",
tools = ["//bazel_tools/sh:mktgz"],
visibility = ["//visibility:public"],
)