daml/compiler/daml-extension/BUILD.bazel
Andreas Herrmann 89a9f5c7d2
tarball reproducibility (#5258)
* integration-tests reproducibility

* package-app reproducibility

* Make remaining tar czf reproducible

* package-app

CHANGELOG_BEGIN
CHANGELOG_END

* Reproducibility of remaing tar invocation

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2020-03-31 10:09:52 +02:00

113 lines
3.7 KiB
Python

# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
package(default_visibility = ["//visibility:public"])
load("@build_environment//:configuration.bzl", "npm_version")
filegroup(
name = "json-files",
srcs = glob([
"*.json",
"syntaxes/*.json",
]),
)
sh_test(
name = "valid-json",
srcs = ["ci-tests.sh"],
args = [
"$(location @jq_dev_env//:jq)",
"$(locations :json-files)",
],
data = [
":json-files",
"@jq_dev_env//:jq",
],
# This is required to get the test to run on Windows. Otherwise, it looks
# like Bazel decides that because it cannot create symlinks on Windows, it
# may as well just give up and start the test without any of its
# dependencies available at all. But not warn about it, so the script can
# just fail at build time when it doesn't find anything.
deps = ["@bazel_tools//tools/bash/runfiles"],
)
# For some reason,
# 1. Bazel only exposes the node_modules dependency as a list of files, not as
# a folder, and
# 2. Copying these files over is surprisingly slow on my machine.
#
# Because `vsce` needs to run in a folder where all of the node_modules
# dependencies are already populated, this separate step takes all of the
# node_module files, one by one (because that is how Bazel exposes them),
# copies them to their intended place, and then bundles the whole node_modules
# folder as a tarball so the next task, below, can depend on that cached
# tarball and be fast.
# Also for some reason on Windows I get "cannot ceate node_modules: file
# exists", so at this point I'm completely out of trust.
genrule(
name = "node_deps_cache",
srcs = ["@daml_extension_deps//:node_modules"],
outs = ["node_modules.tar.gz"],
cmd = """
if [[ -d node_modules ]]; then
rm -rf node_modules
fi
mkdir node_modules
cd node_modules
for f in $(locations @daml_extension_deps//:node_modules); do
# Because Bazel paths are weird, we need to remove everything
# before node_modules. We also need to extract the path separately
# from the filename because we need to create the path (mkdir -p)
# before we can write the file
file=$$(basename $$f)
dir=$$(dirname $$f | sed 's:^.*/node_modules/::')
mkdir -p $$dir
cp ../$$f $$dir/$$file
done
cd ..
tar c node_modules \
--owner=0 --group=0 --numeric-owner --mtime=2000-01-01\ 00:00Z --sort=name \
| gzip -n > $@
""",
)
genrule(
name = "vsix",
srcs = glob([
"package.json",
"syntaxes/*",
"snippets/*",
"images/*",
"*.json",
"README.md",
"yarn.lock",
"src/*",
]) + [
":node_deps_cache",
],
outs = ["daml-bundled.vsix"],
# rm -rf can fail with "directory not empty" on Windows.
# As a workaround we add `|| return`.
cmd = """
export HOME=/does-not-exist
set -euo pipefail
TMP_DIR=$$(mktemp -d)
cleanup () {{ rm -rf $$TMP_DIR || return; }}
trap cleanup EXIT
DIR=$$PWD
cp -r compiler/daml-extension $$TMP_DIR
cd $$TMP_DIR/daml-extension
tar xzf $$DIR/$(location :node_deps_cache)
sed -i "s/__VERSION__/{npm}/" package.json
sed -i 's/"name": "daml"/"name": "daml-bundled"/' package.json
$$DIR/$(location //:yarn)
$$DIR/$(location //:yarn) compile
$$DIR/$(location @daml_extension_deps//vsce/bin:vsce) package -o $$DIR/$@
""".format(npm = npm_version),
tools = [
"//:yarn",
"@daml_extension_deps//vsce/bin:vsce",
],
)