Skip to content

Commit

Permalink
Stop checking .bzl files visibility in RepoRuleFunction
Browse files Browse the repository at this point in the history
Fixes bazelbuild#18346

At this point we are creating a rule from an extension repospec and that is always public

PiperOrigin-RevId: 532558852
Change-Id: I245de0a23f92ba6283be4bf3be6af4863b7a8c68
  • Loading branch information
SalmaSamy authored and iancha1992 committed May 18, 2023
1 parent 969c102 commit c630a7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ private ImmutableMap<String, Module> loadBzlModules(

// Load the .bzl module.
try {
// TODO(b/22193153, wyv): Determine whether .bzl load visibility should apply at all to this
// type of .bzl load. As it stands, this call checks that bzlFile is visible to package @//.
// No need to check visibility for an extension repospec that is always public
return PackageFunction.loadBzlModules(
env,
PackageIdentifier.EMPTY_PACKAGE_ID,
"Bzlmod system",
programLoads,
keys,
starlarkSemantics,
null);
null,
/* checkVisibility= */ false);
} catch (NoSuchPackageException e) {
throw new BzlmodRepoRuleFunctionException(e, Transience.PERSISTENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ private static FileValue getBuildFileValue(Environment env, RootedPath buildFile
* construction to the caller, so that loadPrelude can become just a call to the factored-out
* code.
*/
// TODO(18422): Cleanup/refactor this method's signature.
@Nullable
static ImmutableMap<String, Module> loadBzlModules(
Environment env,
Expand All @@ -644,7 +645,8 @@ static ImmutableMap<String, Module> loadBzlModules(
List<Pair<String, Location>> programLoads,
List<BzlLoadValue.Key> keys,
StarlarkSemantics semantics,
@Nullable BzlLoadFunction bzlLoadFunctionForInlining)
@Nullable BzlLoadFunction bzlLoadFunctionForInlining,
boolean checkVisibility)
throws NoSuchPackageException, InterruptedException {
List<BzlLoadValue> bzlLoads;
try {
Expand All @@ -657,14 +659,17 @@ static ImmutableMap<String, Module> loadBzlModules(
}
// Validate that the current BUILD/WORKSPACE file satisfies each loaded dependency's
// load visibility.
BzlLoadFunction.checkLoadVisibilities(
packageId,
requestingFileDescription,
bzlLoads,
keys,
programLoads,
/*demoteErrorsToWarnings=*/ !semantics.getBool(BuildLanguageOptions.CHECK_BZL_VISIBILITY),
env.getListener());
if (checkVisibility) {
BzlLoadFunction.checkLoadVisibilities(
packageId,
requestingFileDescription,
bzlLoads,
keys,
programLoads,
/* demoteErrorsToWarnings= */ !semantics.getBool(
BuildLanguageOptions.CHECK_BZL_VISIBILITY),
env.getListener());
}
} catch (BzlLoadFailedException e) {
Throwable rootCause = Throwables.getRootCause(e);
throw PackageFunctionException.builder()
Expand Down Expand Up @@ -1325,7 +1330,8 @@ private LoadedPackage loadPackage(
programLoads,
keys.build(),
starlarkBuiltinsValue.starlarkSemantics,
bzlLoadFunctionForInlining);
bzlLoadFunctionForInlining,
/* checkVisibility= */ true);
} catch (NoSuchPackageException e) {
throw new PackageFunctionException(e, Transience.PERSISTENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
programLoads,
keys.build(),
starlarkSemantics,
bzlLoadFunctionForInlining);
bzlLoadFunctionForInlining,
/* checkVisibility= */ true);
} catch (NoSuchPackageException e) {
throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
}
Expand Down

0 comments on commit c630a7c

Please sign in to comment.