diff --git a/sdk/compiler/daml-extension/BUILD.bazel b/sdk/compiler/daml-extension/BUILD.bazel index 9d5532111f47..99123a9ee1d9 100644 --- a/sdk/compiler/daml-extension/BUILD.bazel +++ b/sdk/compiler/daml-extension/BUILD.bazel @@ -4,6 +4,7 @@ package(default_visibility = ["//visibility:public"]) load("@build_environment//:configuration.bzl", "npm_version") +load("@os_info//:os_info.bzl", "is_windows") filegroup( name = "json-files", @@ -45,37 +46,33 @@ sh_test( # 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", - "//compiler/daml-extension:yarn.lock", - ], - 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 - # exclude scoped (@-prefixed) directories that will be copied below - if [[ $$f != *"@"* ]]; then - cp -r ../$$f ./ - fi - done - # copy all scoped (@-prefixed) package directories - for scope_dir in ../$(BINDIR)/external/daml_extension_deps/node_modules/@*/; do - cp -r "$$scope_dir" ./ - done - cd .. - # Check for poison! - # Avoid file path too long errors on Windows of the form - # .../tar_dev_env/usr/bin/tar: node_modules/.cache/terser-webpack-plugin/...: file name is too long (cannot be split); not dumped - $(execpath //bazel_tools/sh:mktgz) $@ node_modules --dereference - """, - tools = ["//bazel_tools/sh:mktgz"], -) +#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 .. +# # Avoid file path too long errors on Windows of the form +# # .../tar_dev_env/usr/bin/tar: node_modules/.cache/terser-webpack-plugin/...: file name is too long (cannot be split); not dumped +# $(execpath //bazel_tools/sh:mktgz) $@ --exclude="node_modules/.cache/*" node_modules +# """, +# tools = ["//bazel_tools/sh:mktgz"], +#) genrule( name = "webview-stylesheet", @@ -102,9 +99,9 @@ genrule( "yarn.lock", ".vscodeignore", "src/*", - ]) + [ - ":node_deps_cache", - ], + "windows_node_modules.zip", + "unix_node_modules.zip", + ]), outs = ["daml-bundled.vsix"], # rm -rf can fail with "directory not empty" on Windows. # As a workaround we add `|| return`. @@ -119,7 +116,8 @@ genrule( # we store the target cpu value to ensure the archive is platform specific echo $(TARGET_CPU) > $$TMP_DIR/target_cpu cd $$TMP_DIR/daml-extension - tar xzf $$DIR/$(location :node_deps_cache) + tar xzf {node_modules_zip} + rm windows_node_modules.zip unix_node_modules.zip sed -i "s/__VERSION__/{npm}/" package.json sed -i 's/"name": "daml"/"name": "daml-bundled"/' package.json $$DIR/$(location //:yarn) compile @@ -129,7 +127,10 @@ genrule( # So for now, we explicitly depend on concat-map in `package.json` to avoid this # Check for poison! PATH=$$(dirname $$DIR/$(location @nodejs//:node_bin)):$$(dirname $$DIR/$(location //:yarn)):$$PATH $$DIR/$(location @nodejs//:node_bin) node_modules/@vscode/vsce/vsce package --yarn -o $$DIR/$@ - """.format(npm = npm_version), + """.format( + node_modules_zip = "windows_node_modules.zip" if is_windows else "unix_node_modules.zip", + npm = npm_version, + ), tools = [ "//:yarn", "@nodejs//:node_bin", diff --git a/sdk/compiler/daml-extension/unix_node_modules.zip b/sdk/compiler/daml-extension/unix_node_modules.zip new file mode 100644 index 000000000000..1aa3a0c2cf09 Binary files /dev/null and b/sdk/compiler/daml-extension/unix_node_modules.zip differ diff --git a/sdk/compiler/daml-extension/windows_node_modules.zip b/sdk/compiler/daml-extension/windows_node_modules.zip new file mode 100644 index 000000000000..6ddb8c568302 Binary files /dev/null and b/sdk/compiler/daml-extension/windows_node_modules.zip differ