One cannot have "external" top-level directory and more
Unfortunately if one have a directory named "external" it produces some kind of race (creating junction vs creating bazel internal directory with the same name) and often source forest creation fails:
ERROR: Source forest creation failed: Cannot create junction (name=C:\users\chebotarev_v\appdata\local\temp\_bazel_chebotarev_v\w0ulolcy\execroot\__main__\external, target=C:\users\chebotarev_v\perforce\chebotare
v_pdk\bin\bazel\external): ERROR: src/main/native/windows/file-jni.cc(86): nativeCreateJunction(C:\users\chebotarev_v\appdata\local\temp\_bazel_chebotarev_v\w0ulolcy\execroot\__main__\external, C:\users\chebotare
v_v\perforce\chebotarev_pdk\bin\bazel\external): ERROR: src/main/native/windows/file.cc(128): CreateJunction(\\?\C:\users\chebotarev_v\appdata\local\temp\_bazel_chebotarev_v\w0ulolcy\execroot\__main__\external):
Cannot create a file when that file already exists.
After second try it turns out that bazel erases source forest from bazel-bazel but skips directories which start from dot (see also #4060):
ERROR: Source forest creation failed: Cannot create junction (name=C:\users\chebotarev_v\appdata\local\temp\_bazel_chebotarev_v\w0ulolcy\execroot\__main__\.delivery, target=C:\users\chebotarev_v\perforce\chebotar
ev_pdk\bin\bazel\.delivery): ERROR: src/main/native/windows/file-jni.cc(86): nativeCreateJunction(C:\users\chebotarev_v\appdata\local\temp\_bazel_chebotarev_v\w0ulolcy\execroot\__main__\.delivery, C:\users\chebot
arev_v\perforce\chebotarev_pdk\bin\bazel\.delivery): ERROR: src/main/native/windows/file.cc(128): CreateJunction(\\?\C:\users\chebotarev_v\appdata\local\temp\_bazel_chebotarev_v\w0ulolcy\execroot\__main__\.delive
ry): Cannot create a file when that file already exists.
ATTENTION! Please read and follow:
- if this is a question about how to build / test / query / deploy using Bazel, ask it on StackOverflow instead: https://stackoverflow.com/questions/tagged/bazel
- if this is a discussion starter, send it to [email protected]
- if this is a bug or feature request, fill the form below as best as you can.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I believe one can get fairly big project and create "external" and ".something" top level directories with some BUILD files and run bazel build .... I will try tensorflow and post results later in discussion below.
What operating system are you running Bazel on?
Windows 10 x64
What's the output of bazel info release?
release 0.8.0 and release 0.9.0
Have you found anything relevant by searching the web?
No.
I've created reproduction repository of this or very similar bug for your convenience: https://github.com/excitoon/bazel-issues/tree/master/external-top-level-directory
Right now if one run bazel build ... in external directory it produces the following error:
C:\Users\Chebotarev_V\Documents\bazel-issues\external-top-level-directory\external>bazel build ...
Unhandled exception thrown during build; message: Unrecoverable error while evaluating node '...' (requested by nodes '[...] OFFSET=externalcom.google.devtools.build.lib.pkgcache.TestFilter@e17a1')
INFO: Elapsed time: 2.064s
FAILED: Build did NOT complete successfully (0 packages loaded)
java.lang.RuntimeException: Unrecoverable error while evaluating node '...' (requested by nodes '[...] OFFSET=externalcom.google.devtools.build.lib.pkgcache.TestFilter@e17a1')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:414)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:352)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: No such attribute tags in local_repository rule //external:bazel_tools
at com.google.devtools.build.lib.packages.AbstractAttributeMapper.getIndexWithTypeCheck(AbstractAttributeMapper.java:251)
at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:58)
at com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper.get(NonconfigurableAttributeMapper.java:45)
at com.google.devtools.build.lib.packages.TargetUtils.hasConstraint(TargetUtils.java:201)
at com.google.devtools.build.lib.packages.TargetUtils.hasManualTag(TargetUtils.java:81)
at com.google.devtools.build.lib.pkgcache.FilteringPolicies$FilterManual.shouldRetain(FilteringPolicies.java:73)
at com.google.devtools.build.lib.pkgcache.FilteringPolicies$AndFilteringPolicy.shouldRetain(FilteringPolicies.java:105)
Server terminated abruptly (error code: 14, error message: '', log file: 'c:\t\_bazel_chebotarev_v\05uhpulr/server/jvm.out')
I am also having the problem with external directory.
I created a project with external directory in top level, in which I have a library for which I wrote a BUILD.
It looks like this:
projectDir/
WORKSPACE
/external
myHeaderLibrary.hpp
BUILD
I am getting Source forest creation failed (file already exists) error.:
Source forest creation failed: /home/xxx/.cache/bazel/_bazel_xxx/97f33f95df36b9894f71b3e8c2b2d4f6/execroot/__main__/external (File exists)
If I change name of directory from external to vendor, everything is fine.
System: Archlinux. Bazel version: 0.16.1
I guess this is minor thing, but it would be easy to just rename external in Bazel to something more rare like _external. One thing I'd like to ask about is a way to address external directories from bzl macros and build files, like $(EXTDIR).
/cc @lberki
One of the odd side effects of the workaround I use these days (represent /external as an external repository by adding a WORKSPACE file in it) is that running Bazel from within the external directory starts a new server instance (since, well, it's a different WORKSPACE file) and it won't honor rcfiles in the "outer" workspace.
This is causing us problems for certain repos that have an external directory (many in the Vulkan ecosystem do: https://github.com/KhronosGroup/Vulkan-Tools, https://github.com/KhronosGroup/spirv-tools). Is there a path to fixing this?
@jfroy Yes, there is a path. @scentini has been looking at this recently and I'm helping out with it.
You can follow the work here: https://github.com/bazelbuild/bazel/pull/10604
The next Bazel version will come with the --experimental_sibling_repository_layout, which will enable you to build and test targets in the subpackages of //external, so //external/foo:target is fine. The //external virtual package is still reserved for external repositories.
I see that the Vulkan tools have regular files in the external directory, which may require another fix that @lberki has to completely remove the //external package.
It's landed as https://github.com/bazelbuild/bazel/commit/015f586fcb2e127ed13691b573de42cd9dba8508 . The command line flag is --experimental_disable_external_package.
These two are still not perfect: you still can't have your own package called //external and output files under the external directory can still conflict with output files from external repositories, but it's a good start.
The long-term plan is to fix those issues, too, and flip all these flags, but we currently don't have a strong motivation other than beauty.
@jin @lberki What's the state of this?
This should work if the --experimental_sibling_repository_layout flag is flipped thanks to the work of @gyias . I haven't made plans for flipping that flag by default, though. It would be quite an intrusive change so I don't think it's going to happen anytime soon.
@lberki As a data point, I just ran bazel clean --expunge && bazel build --experimental_sibling_repository_layout //src:bazel and it failed in the final step, but it looks like it's probably just a one-line fix in a shell script:
ERROR: /Users/philwo/src/bazel/src/BUILD:329:9: Executing genrule //src:package-zip_jdk_minimal failed (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)
mv: rename external/platforms/* to ./*: No such file or directory
Target //src:bazel failed to build
@philwo Yes, it's a known issue that I didn't bother to fix yet. Adding an if statement to some lines in the code to unzip platforms.zip in package-bazel.sh will probably do it.
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!
This appears to still be an issue.
Yep, let's keep this open: it's embarrassing enough that I don't want it to be lost.
Yes, this was a quite surprising limitation to discover. The fact that this is not in any way configurable (that I've been able to find) makes it even worse. This is essentially a blocker for me.
Could dynamic code with admin permission validate the external directory?Or have a node with a prelink to a external directory be a two way channel communication setup.