Skip to content

Commit

Permalink
Rename _bazel-external to bazel-external
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorcloudy committed Jun 17, 2024
1 parent b263af6 commit 8edd507
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions site/en/external/vendor.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ To achieve offline build, Bazel also vendors all registry files fetched from net
External repositories may contain symlinks pointing to other files or directories.
To make sure symlinks work correctly, Bazel uses the following strategy to rewrite symlinks in the vendored source:

- Create a symlink `<vendor_dir>/_bazel-external` that points to `$(bazel info output_base)/external`. It is refreshed by every Bazel command automatically.
- For the vendored source, rewrite all symlinks that originally point to a path under `$(bazel info output_base)/external` to a relative path under `<vendor_dir>/_bazel-external`.
- Create a symlink `<vendor_dir>/bazel-external` that points to `$(bazel info output_base)/external`. It is refreshed by every Bazel command automatically.
- For the vendored source, rewrite all symlinks that originally point to a path under `$(bazel info output_base)/external` to a relative path under `<vendor_dir>/bazel-external`.

For example, if the original symlink is

Expand All @@ -184,16 +184,16 @@ For example, if the original symlink is
It will be rewritten to

```
<vendor_dir>/repo_foo~/link => ../../_bazel-external/repo_bar~/file
<vendor_dir>/repo_foo~/link => ../../bazel-external/repo_bar~/file
```

where

```
<vendor_dir>/_bazel-external => $(bazel info output_base)/external # This might be new if output base is changed
<vendor_dir>/bazel-external => $(bazel info output_base)/external # This might be new if output base is changed
```

Since `<vendor_dir>/_bazel-external` is generated by Bazel automatically, it's recommended to add it to `.gitignore` or equivalent to avoid checking it in.
Since `<vendor_dir>/bazel-external` is generated by Bazel automatically, it's recommended to add it to `.gitignore` or equivalent to avoid checking it in.

With this strategy, symlinks in the vendored source should work correctly even after the vendored source is moved to another location or the bazel output base is changed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,10 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
// On Windows, symlinks are resolved differently.
// Given <external>/repo_foo/link,
// where <external>/repo_foo points to <vendor dir>/repo_foo in vendor mode
// and repo_foo/link points to a relative path ../_bazel-external/repo_bar/data.
// and repo_foo/link points to a relative path ../bazel-external/repo_bar/data.
// Windows won't resolve `repo_foo` before resolving `link`, which causes
// <external>/repo_foo/link to be resolved to <external>/_bazel-external/repo_bar/data
// To work around this, we create a symlink <external>/_bazel-external -> <external>.
// <external>/repo_foo/link to be resolved to <external>/bazel-external/repo_bar/data
// To work around this, we create a symlink <external>/bazel-external -> <external>.
FileSystemUtils.ensureSymbolicLink(
externalRoot.getChild(VendorManager.EXTERNAL_ROOT_SYMLINK_NAME),
externalRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class VendorManager {

private static final String REGISTRIES_DIR = "_registries";

public static final String EXTERNAL_ROOT_SYMLINK_NAME = "_bazel-external";
public static final String EXTERNAL_ROOT_SYMLINK_NAME = "bazel-external";

private final Path vendorDirectory;

Expand Down
2 changes: 1 addition & 1 deletion src/test/py/bazel/bzlmod/bazel_vendor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def testVendorRepoWithSymlinks(self):
])
self.RunBazel(['vendor', '--vendor_dir=vendor', '--repo=@foo'])
self.RunBazel(['clean', '--expunge'])
self.AssertPathIsSymlink(self._test_cwd + '/vendor/_bazel-external')
self.AssertPathIsSymlink(self._test_cwd + '/vendor/bazel-external')

# Move the vendor directory to a new location and use a new output base, it should still work
os.rename(self._test_cwd + '/vendor', self._test_cwd + '/vendor_new')
Expand Down

0 comments on commit 8edd507

Please sign in to comment.