# Copyright (c) 2020 The DAML Authors. All rights reserved. # SPDX-License-Identifier: Apache-2.0 package(default_visibility = ["//visibility:public"]) 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 czf node_modules.tar.gz node_modules cp node_modules.tar.gz $@ """, ) genrule( name = "vsix", srcs = glob([ "package.json", "syntaxes/*", "snippets/*", "images/*", "*.json", "README.md", "yarn.lock", "src/*", ]) + [ ":node_deps_cache", "//:VERSION", ], outs = ["daml-bundled.vsix"], # rm -rf can fail with "directory not empty" on Windows. # As a workaround we add `|| return`. cmd = """ set -euo pipefail TMP_DIR=$$(mktemp -d) cleanup () { rm -rf $$TMP_DIR || return; } trap cleanup EXIT DIR=$$PWD VERSION=$$(cat $(location //:VERSION)) cp -r compiler/daml-extension $$TMP_DIR cd $$TMP_DIR/daml-extension tar xzf $$DIR/$(location :node_deps_cache) sed -i "s/__VERSION__/$$VERSION/" 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/$@ """, tools = [ "//:yarn", "@daml_extension_deps//vsce/bin:vsce", ], )