Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(builtin): entry point from sources incorrectly used when binary is leveraged as tool, breaking resolution #3605

Merged
merged 1 commit into from Dec 5, 2022

Conversation

devversion
Copy link
Contributor

@devversion devversion commented Dec 2, 2022

Consider a nodejs_binary with a definition like the followed:

js_library(
  name = "lib",
  srcs = ["entrypoint.js", "constants.js"],
)

nodejs_binary(
  name = "bin",
  entry_point = "entrypoint.js",
  data = [":lib"],
)

This seems very standanrd and also works perfectly when the binary is invoked with bazel run. Via Bazel run, the Node Bash launcher resolves the entrypoint via the actual runfiles using rlocation.

If this binary is used as a tool, e.g. in npm_package_bin- then the entry point is resolved from the execroot, landing ultimately on the actual source file. This is wrong and breaks resolution in RBE (where only necessary sources are in the execroot).

This happens because the source entrypoint file. i.e. not the entrypoint.js from bazel-bin is also ending up being included in the runfiles of run_node via NodeRuntimeDepsInfo.

This mismatch breaks resolution, and also results in an incorrect/ unnecessary file being added to the action inputs. The entry point used in NodeRuntimeDepsInfo should be the one derived from the data sources of the rule, ensuring the entry-point can access its other files of the js_library.

i.e. entry-point should come from the data preferred, and if it's not found- then the source, or File can be directly used.

This fixes RBE for angular.io which started unveiling some issues
when we attempted to enable RBE via: angular/angular#48316

Consider a `nodejs_binary` with a definition like the followed:

```bzl
js_library(
  name = "lib",
  srcs = ["entrypoint.js", "constants.js"],
)

nodejs_binary(
  name = "bin",
  entry_point = "entrypoint.js",
  data = [":lib"],
)
```

This seems very standanrd and also works perfectly when the
binary is invoked with `bazel run`. Via Bazel run, the Node
Bash launcher resolves the entrypoint via the actual runfiles
using `rlocation`.

If this binary is used as a tool, e.g. in `npm_package_bin`- then
the entry point is resolved from the execroot, landing ultimately
on the *actual source file*. This is wrong and breaks resolution
in RBE (where only necessary sources are in the execroot).

This happens because the source entrypoint file. i.e. not the
`entrypoint.js` from `bazel-bin` is also ending up being included
in the runfiles of `run_node` via `NodeRuntimeDepsInfo`.

This mismatch breaks resolution, and also results in an incorrect/
unnecessary file being added to the action inputs. The entry point
used in `NodeRuntimeDepsInfo` should be the one derived from the
`data` sources of the rule, ensuring the entry-point can access
its other files of the `js_library`.

i.e. entry-point should come from the `data` preferred, and if it's
not found- then the source, or `File` can be directly used.

This fixes RBE for angular.io which started unveiling some issues
when we attmepted to enable RBE via: angular/angular#48316
@devversion devversion changed the title fix(builtin): entry point from sources used when used as tool fix(builtin): entry point from sources incorrectly used when binary is leveraged as tool, breaking resolution Dec 2, 2022
devversion added a commit to devversion/angular that referenced this pull request Dec 2, 2022
devversion added a commit to devversion/angular that referenced this pull request Dec 2, 2022
@devversion devversion marked this pull request as ready for review December 2, 2022 14:17
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Dec 2, 2022
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Dec 2, 2022
sr5434 pushed a commit to sr5434/angular that referenced this pull request Dec 3, 2022
@gregmagolan gregmagolan merged commit 417711d into bazelbuild:stable Dec 5, 2022
trekladyone pushed a commit to trekladyone/angular that referenced this pull request Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants