-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `strip_prefix` arg go bzlmod's `git_override` and pass it down to `git_repository`. This allows users to work with git repositories that have other Bazel modules in subdirectories. A prime example of such is the `rules_python`](https://github.com/bazelbuild/rules_python) repo: ``` ./rules_python ├── MODULE.bazel # available on BCR as "rules_python" └── gazelle └── MODULE.bazel # available on BCR as "rules_python_gazelle_plugin" ``` Fixes #22076. RELNOTES: bzlmod `git_repository` now accepts the `strip_prefix` arg and passes it to the underlying `git_repository` call. Closes #22077. PiperOrigin-RevId: 628059135 Change-Id: I8b9df3a5d41924302475fd9495aff6cd21ce6db2 Commit 8edddb3 Co-authored-by: Douglas Thor <[email protected]>
- Loading branch information
1 parent
ddc37e5
commit 6c883e4
Showing
3 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
# pylint: disable=g-long-ternary | ||
|
||
import os | ||
import shutil | ||
import tempfile | ||
from absl.testing import absltest | ||
from src.test.py.bazel import test_base | ||
|
@@ -36,6 +37,8 @@ def setUp(self): | |
'bbb', '1.1', {'aaa': '1.1'} | ||
).createCcModule( | ||
'ccc', '1.1', {'aaa': '1.1', 'bbb': '1.1'} | ||
).createCcModule( | ||
'ddd', '1.0' | ||
) | ||
self.ScratchFile( | ||
'.bazelrc', | ||
|
@@ -272,6 +275,104 @@ def testGitOverride(self): | |
self.assertIn('main function => [email protected]', stdout) | ||
self.assertIn('[email protected] => [email protected] (locally patched)', stdout) | ||
|
||
def testGitOverrideStripPrefix(self): | ||
self.writeMainProjectFiles() | ||
|
||
# Update BUILD and main.cc to also call `ddd`. | ||
self.ScratchFile( | ||
'BUILD', | ||
[ | ||
'cc_binary(', | ||
' name = "main",', | ||
' srcs = ["main.cc"],', | ||
' deps = [', | ||
' "@aaa//:lib_aaa",', | ||
' "@bbb//:lib_bbb",', | ||
' "@ddd//:lib_ddd",', | ||
' ],', | ||
')', | ||
], | ||
) | ||
self.ScratchFile( | ||
'main.cc', | ||
[ | ||
'#include "aaa.h"', | ||
'#include "bbb.h"', | ||
'#include "ddd.h"', | ||
'int main() {', | ||
' hello_aaa("main function");', | ||
' hello_bbb("main function");', | ||
' hello_ddd("main function");', | ||
'}', | ||
], | ||
) | ||
src_aaa_1_0 = self.main_registry.projects.joinpath('aaa', '1.0') | ||
src_ddd_1_0 = self.main_registry.projects.joinpath('ddd', '1.0') | ||
self.RunProgram(['git', 'init'], cwd=src_aaa_1_0) | ||
self.RunProgram( | ||
['git', 'config', 'user.name', 'tester'], | ||
cwd=src_aaa_1_0, | ||
) | ||
self.RunProgram( | ||
['git', 'config', 'user.email', '[email protected]'], | ||
cwd=src_aaa_1_0, | ||
) | ||
|
||
# Make a subdirectory that itself is the published module 'ddd'. | ||
subdir_name = 'subdir_containing_ddd' | ||
shutil.copytree(src=src_ddd_1_0, dst=src_aaa_1_0 / subdir_name) | ||
|
||
# Edit the code in 'subdir_containing_ddd/ddd.cc' so that we can assert | ||
# that we're using it. | ||
src_aaa_relpath = src_aaa_1_0.relative_to(self._test_cwd) | ||
self.ScratchFile( | ||
str(src_aaa_relpath / subdir_name / 'ddd.cc'), | ||
[ | ||
'#include <stdio.h>', | ||
'#include "ddd.h"', | ||
'void hello_ddd(const std::string& caller) {', | ||
' std::string lib_name = "[email protected]";', | ||
( | ||
' printf("%s => %s from subdir\\n", caller.c_str(),' | ||
' lib_name.c_str());' | ||
), | ||
'}', | ||
], | ||
) | ||
|
||
self.RunProgram(['git', 'add', './'], cwd=src_aaa_1_0) | ||
self.RunProgram( | ||
['git', 'commit', '-m', 'Initial commit.'], | ||
cwd=src_aaa_1_0, | ||
) | ||
|
||
_, stdout, _ = self.RunProgram( | ||
['git', 'rev-parse', 'HEAD'], cwd=src_aaa_1_0 | ||
) | ||
|
||
commit = stdout[0].strip() | ||
|
||
self.ScratchFile( | ||
'MODULE.bazel', | ||
[ | ||
'bazel_dep(name = "aaa", version = "1.1")', | ||
'bazel_dep(name = "bbb", version = "1.1")', | ||
'bazel_dep(name = "ddd", version = "1.0")', | ||
'git_override(', | ||
' module_name = "ddd",', | ||
' remote = "%s",' % src_aaa_1_0.as_uri(), | ||
' commit = "%s",' % commit, | ||
' strip_prefix = "%s",' % subdir_name, | ||
')', | ||
], | ||
) | ||
|
||
_, stdout, _ = self.RunBazel(['run', '//:main']) | ||
self.assertIn('main function => [email protected]', stdout) | ||
self.assertIn('main function => [email protected]', stdout) | ||
self.assertIn('[email protected] => [email protected]', stdout) | ||
self.assertIn('main function => [email protected] from subdir', stdout) | ||
|
||
def testLocalPathOverride(self): | ||
src_aaa_1_0 = self.main_registry.projects.joinpath('aaa', '1.0') | ||
self.writeMainProjectFiles() | ||
|