Skip to content

Commit 8c11405

Browse files
SalmaSamycopybara-github
authored andcommitted
Stop checking .bzl files visibility in RepoRuleFunction
Fixes #18346 At this point we are creating a rule from an extension repospec and that is always public PiperOrigin-RevId: 532558852 Change-Id: I245de0a23f92ba6283be4bf3be6af4863b7a8c68
1 parent 280de20 commit 8c11405

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoRuleFunction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,16 @@ private ImmutableMap<String, Module> loadBzlModules(
240240

241241
// Load the .bzl module.
242242
try {
243-
// TODO(b/22193153, wyv): Determine whether .bzl load visibility should apply at all to this
244-
// type of .bzl load. As it stands, this call checks that bzlFile is visible to package @//.
243+
// No need to check visibility for an extension repospec that is always public
245244
return PackageFunction.loadBzlModules(
246245
env,
247246
PackageIdentifier.EMPTY_PACKAGE_ID,
248247
"Bzlmod system",
249248
programLoads,
250249
keys,
251250
starlarkSemantics,
252-
null);
251+
null,
252+
/* checkVisibility= */ false);
253253
} catch (NoSuchPackageException e) {
254254
throw new BzlmodRepoRuleFunctionException(e, Transience.PERSISTENT);
255255
}

src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ private static FileValue getBuildFileValue(Environment env, RootedPath buildFile
634634
* construction to the caller, so that loadPrelude can become just a call to the factored-out
635635
* code.
636636
*/
637+
// TODO(18422): Cleanup/refactor this method's signature.
637638
@Nullable
638639
static ImmutableMap<String, Module> loadBzlModules(
639640
Environment env,
@@ -642,7 +643,8 @@ static ImmutableMap<String, Module> loadBzlModules(
642643
List<Pair<String, Location>> programLoads,
643644
List<BzlLoadValue.Key> keys,
644645
StarlarkSemantics semantics,
645-
@Nullable BzlLoadFunction bzlLoadFunctionForInlining)
646+
@Nullable BzlLoadFunction bzlLoadFunctionForInlining,
647+
boolean checkVisibility)
646648
throws NoSuchPackageException, InterruptedException {
647649
List<BzlLoadValue> bzlLoads;
648650
try {
@@ -655,14 +657,17 @@ static ImmutableMap<String, Module> loadBzlModules(
655657
}
656658
// Validate that the current BUILD/WORKSPACE file satisfies each loaded dependency's
657659
// load visibility.
658-
BzlLoadFunction.checkLoadVisibilities(
659-
packageId,
660-
requestingFileDescription,
661-
bzlLoads,
662-
keys,
663-
programLoads,
664-
/*demoteErrorsToWarnings=*/ !semantics.getBool(BuildLanguageOptions.CHECK_BZL_VISIBILITY),
665-
env.getListener());
660+
if (checkVisibility) {
661+
BzlLoadFunction.checkLoadVisibilities(
662+
packageId,
663+
requestingFileDescription,
664+
bzlLoads,
665+
keys,
666+
programLoads,
667+
/* demoteErrorsToWarnings= */ !semantics.getBool(
668+
BuildLanguageOptions.CHECK_BZL_VISIBILITY),
669+
env.getListener());
670+
}
666671
} catch (BzlLoadFailedException e) {
667672
Throwable rootCause = Throwables.getRootCause(e);
668673
throw PackageFunctionException.builder()
@@ -1335,7 +1340,8 @@ private LoadedPackage loadPackage(
13351340
programLoads,
13361341
keys.build(),
13371342
starlarkBuiltinsValue.starlarkSemantics,
1338-
bzlLoadFunctionForInlining);
1343+
bzlLoadFunctionForInlining,
1344+
/* checkVisibility= */ true);
13391345
} catch (NoSuchPackageException e) {
13401346
throw new PackageFunctionException(e, Transience.PERSISTENT);
13411347
}

src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
334334
programLoads,
335335
keys.build(),
336336
starlarkSemantics,
337-
bzlLoadFunctionForInlining);
337+
bzlLoadFunctionForInlining,
338+
/* checkVisibility= */ true);
338339
} catch (NoSuchPackageException e) {
339340
throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
340341
}

0 commit comments

Comments
 (0)