Skip to content

Commit

Permalink
Don't allow vendoring with --nofetch
Browse files Browse the repository at this point in the history
Related #19563

Vendoring is not possible in offline mode; Verifing this flag before initiating any vendor-related tasks.

PiperOrigin-RevId: 601479912
Change-Id: I67ab3067cbd8c0726abd6006f4f00fe82bf31576
  • Loading branch information
SalmaSamy authored and copybara-github committed Jan 25, 2024
1 parent 7923669 commit e13e0a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
PackageOptions pkgOptions = options.getOptions(PackageOptions.class);
if (!pkgOptions.fetch) {
return createFailedBlazeCommandResult(
env.getReporter(), Code.OPTIONS_INVALID, "You cannot run fetch with --fetch=false");
env.getReporter(), Code.OPTIONS_INVALID, "You cannot run fetch with --nofetch");
}
FetchOptions fetchOptions = options.getOptions(FetchOptions.class);
int optionsCount =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
Code.OPTIONS_INVALID,
"You cannot run vendor without specifying --vendor_dir");
}
PackageOptions pkgOptions = options.getOptions(PackageOptions.class);
if (!pkgOptions.fetch) {
return createFailedBlazeCommandResult(
env.getReporter(), Code.OPTIONS_INVALID, "You cannot run vendor with --nofetch");
}

LoadingPhaseThreadsOption threadsOption = options.getOptions(LoadingPhaseThreadsOption.class);
SkyframeExecutor skyframeExecutor = env.getSkyframeExecutor();
Expand Down
8 changes: 8 additions & 0 deletions src/test/py/bazel/bzlmod/bazel_vendor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def testBasicVendoring(self):
self.assertIn('@bbb~1.0.marker', repos_vendored)
self.assertIn('.vendorignore', repos_vendored)

def testVendorFailsWithNofetch(self):
self.ScratchFile('MODULE.bazel')
self.ScratchFile('BUILD')
_, _, stderr = self.RunBazel(
['vendor', '--vendor_dir=vendor', '--nofetch'], allow_failure=True
)
self.assertIn('ERROR: You cannot run vendor with --nofetch', stderr)

def testVendoringMultipleTimes(self):
self.main_registry.createCcModule('aaa', '1.0')
self.ScratchFile(
Expand Down

0 comments on commit e13e0a2

Please sign in to comment.