-
Notifications
You must be signed in to change notification settings - Fork 522
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
[Bug]: npm_install
modifying the source tree during the build is an antipattern
#3693
Comments
Writing to the source tree during the build (even from repository modules) is definitely an antipattern. However, that does not answer the question as to what else to do; my understanding is that the Historically, the answer to this was @joeleba , how does this exactly cause trouble? Disregarding the inherent ugliness of this, this would only be a problem if the build touched the @alexeagle , can you offer some guidance here? My ideas (I'm not sure what is my order of preference):
|
In
Since you mentioned the possibility of adding stuff to MODULE.bazel: cc @meteorcloudy |
I think I mentioned |
But if we want to add a |
FWIW, "you" here meant @lberki. |
From reading the doc, we don't seem to have this problem with @alexeagle could you please confirm? |
cc @gregmagolan |
…ase. Some rules in Bazel (`npm_install` is a particular example) modify the source tree after the target pattern parsing phase. This would make the syscall cache stale. This CL mitigate that issue by clearing the syscall cache after the target pattern parsing phase. This would have very little impact on the overall performance, since there's relatively quite a small number of entries in the cache at this point. See bazel-contrib/rules_nodejs#3693 PiperOrigin-RevId: 565007842 Change-Id: Ibc4f62aeb2f5347e0ecf2a186652944ea6fcdbe5
This issue has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs in 30 days. Note as of rules_nodejs v6 the rules_nodejs repository contains only the core nodejs toolchain and |
Hey sorry we never replied @joeleba - that's correct that rules_js writes only to the output tree. rules_nodejs 6.0.0 fixed this, in the sense that this package manager code no longer exists, the scope is now only to provide a nodejs toolchain. |
I found this issue from https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java;l=414-415;drc=9bf989f6c4f8fb4b463bee07cce7b6f04df8d6e0. @joeleba @alexeagle any idea if it's still needed or can we remove the syscall cache clearing code? |
What happened?
tl,dr: I think modifying the source dir during the build is an antipattern.
Background
I ran into an issue while trying to build bazelbuild/buildtools with
--experimental_merged_skyframe_analysis_and_execution
(context: Project Skymeld bazelbuild/bazel#14057). Some actions were reporting missing inputs from thenode_modules
directory.Without going into too much details, I managed to figure out the issue: compared to the regular version of blaze, Skymeld clears the syscall cache at a different point in time.
Take the following example:
where
WORKSPACE
contains an instance ofnpm_install
.Assume that there are actions that refer to
node_modules
. When doingbazel build //foo/...
with bazel at HEAD, this is what happens (chronological order):npm_install
in theWORKSPACE
file is evaluated andnode_modules
is generated{ foo -> [a.in, b.in]}
{ foo -> [a.in, b.in, node_modules] }
The syscall cache is extra-Skyframe and generally assumes that the source doesn't change during the build (code). This
node_modules
directory is generated in the source dir and hence isn't considered "external" either.So what happens if we don't clear the syscall cache after the analysis phase? One would expect a memory regression, but in this case, it's worse: we'll start seeing missing input errors:
npm_install
in theWORKSPACE
file is evaluated andnode_modules
is generated{ foo -> [a.in, b.in]}
node_modules
directory{ foo -> [a.in, b.in] }
Disabling the cache clearance: bazelbuild/bazel@54b4c39
Proposal
The syscall cache was there only for performance reason, but it accidentally tolerated this behavior. This will not be the case when we switch over to Skymeld mode, because then the syscall cache clearance happens at a different time.
IMO we have 2 options to move forward:
I believe that (1) is just once more sweeping this problem under the rug and isn't a desirable option, not to mention the potential regression from clearing the syscall cache before the analysis work.
WDYT?
Version
Development (host) and target OS/architectures: Linux
Output of
bazel --version
: development versionVersion of rules_nodejs, or other relevant rules from your
WORKSPACE
orMODULE.bazel
file: 4.0.0Language(s) and/or frameworks involved:
How to reproduce
Clone
bazelbuild/buildtools
and build...
:The text was updated successfully, but these errors were encountered: