bazel-contrib / bazel-lib

Common useful functions for writing BUILD files and Starlark macros/rules
Apache License 2.0
141 stars 91 forks source link

[Bug]: tar generates incorrect mtree for aspect_rules_js runfiles #797

Open Zemnmez opened 8 months ago

Zemnmez commented 8 months ago

What happened?

I tried to make a tar of a js_binary from aspect_rules_js. It failed because the node_modules deps seem to have some incorrectly set filetypes in their mtree.

Instead we get this error:

ERROR: /Users/tshadwell/code/monorepo/ts/pulumi/lib/docker/testing/example/simple/BUILD.bazel:17:10: Tar ts/pulumi/lib/docker/testing/example/simple/simple_tar.tar failed: (Exit 1): tar failed: error executing Tar command (from target //ts/pulumi/lib/docker/testing/example/simple:simple_tar) external/aspect_bazel_lib~~toolchains~bsd_tar_host/tar --create --file bazel-out/darwin_arm64-fastbuild/bin/ts/pulumi/lib/docker/testing/example/simple/simple_tar.tar ... (remaining 1 argument skipped)

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel 7.1.0

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:

    http_archive(
        name = "aspect_rules_js",
        sha256 = "6148188cfa5cb76397b8745b71d57c47a7c1a8e00ff2f1e2e7955206846197f1",
        strip_prefix = "rules_js-1.39.0",
        url = "https://github.com/aspect-build/rules_js/releases/download/v1.39.0/rules_js-v1.39.0.tar.gz",
    )

bazel_dep(name = "aspect_bazel_lib", version = "2.5.3")

Language(s) and/or frameworks involved:

How to reproduce

1. Pull this commit: https://github.com/zemn-me/monorepo/commit/2112ad5adbfc9aed993c2f90dc7406b58a52d124

2. Run `bazelisk build //ts/pulumi/lib/docker/testing/example/simple:simple_tar`

Any other information?

tshadwell@Thomass-Air monorepo % bazel build //ts/pulumi/lib/docker/testing/example/simple:simple_tar 
WARNING: Option 'experimental_remote_build_event_upload' is deprecated: Use --remote_build_event_upload instead
INFO: Invocation ID: 36daec61-8823-4ef8-8c88-23b4f409cecd
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/36daec61-8823-4ef8-8c88-23b4f409cecd
WARNING: Option 'experimental_remote_build_event_upload' is deprecated: Use --remote_build_event_upload instead
INFO: Analyzed target //ts/pulumi/lib/docker/testing/example/simple:simple_tar (0 packages loaded, 0 targets configured).
ERROR: /Users/tshadwell/code/monorepo/ts/pulumi/lib/docker/testing/example/simple/BUILD.bazel:17:10: Tar ts/pulumi/lib/docker/testing/example/simple/simple_tar.tar failed: (Exit 1): tar failed: error executing Tar command (from target //ts/pulumi/lib/docker/testing/example/simple:simple_tar) external/aspect_bazel_lib~~toolchains~bsd_tar_host/tar --create --file bazel-out/darwin_arm64-fastbuild/bin/ts/pulumi/lib/docker/testing/example/simple/simple_tar.tar ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
tar: Error reading archive bazel-out/darwin_arm64-fastbuild/bin/ts/pulumi/lib/docker/testing/example/simple/_simple_tar.mtree.txt: mtree specification has different type for ts/pulumi/lib/docker/testing/example/simple/main_bin.sh.runfiles/_main/node_modules/regenerator-runtime
tar: Error exit delayed from previous errors.
Target //ts/pulumi/lib/docker/testing/example/simple:simple_tar failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.000s, Critical Path: 2.79s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/36daec61-8823-4ef8-8c88-23b4f409cecd
tshadwell@Thomass-Air monorepo % 

Workaround

Make an npm_package and wrap it in js_binary.

Zemnmez commented 8 months ago

It looks like I was able to work around this by making an npm_package, and then creating a js_binary of that.

thesayyn commented 3 weeks ago

Yes, this is why we have js_image_layer because rules_js is really sensitive to symlinks, https://github.com/bazel-contrib/bazel-lib/pull/967 is my incomplete yet daring stab at fixing this, it's not even there yet.