Skip to content

Commit

Permalink
Use the default "internal API" allowlist for all functionality used i…
Browse files Browse the repository at this point in the history
…n Starlark migration.

PiperOrigin-RevId: 646473580
Change-Id: I7136b1e7398fd5159548c0862eeeada94b9b6388
  • Loading branch information
c-mita authored and copybara-github committed Jun 25, 2024
1 parent 0473f8b commit 37b8626
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public boolean hasSeparateGenfilesDirectory() {
@Override
public boolean hasSeparateGenfilesDirectoryForStarlark(StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return hasSeparateGenfilesDirectory();
}

Expand Down Expand Up @@ -522,7 +522,7 @@ public boolean isSiblingRepositoryLayout() {

@Override
public boolean isSiblingRepositoryLayoutForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return isSiblingRepositoryLayout();
}

Expand Down Expand Up @@ -657,7 +657,7 @@ public boolean stampBinaries() {

@Override
public boolean stampBinariesForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return stampBinaries();
}

Expand Down Expand Up @@ -877,7 +877,7 @@ public boolean runfilesEnabled() {

@Override
public boolean runfilesEnabledForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return runfilesEnabled();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public boolean macosSetInstallName() {
private static void checkInExpandedApiAllowlist(StarlarkThread thread, String feature)
throws EvalException {
try {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
} catch (EvalException e) {
throw Starlark.errorf("%s (feature '%s' in CppConfiguration)", e.getMessage(), feature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public boolean experimentalEnableJspecify() {

@Override
public boolean autoCreateJavaTestDeployJars(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return autoCreateDeployJarForJavaTests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public Artifact archive() {

@StarlarkMethod(name = "archive", documented = false, useStarlarkThread = true)
public Artifact archiveForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return archive();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean removeDeadCode() {

@Override
public boolean getRemoveDeadCodeForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return removeDeadCode;
}

Expand All @@ -148,7 +148,7 @@ public boolean experimentalJ2ObjcHeaderMap() {
@Override
public boolean getExperimentalJ2ObjcHeaderMapForStarlark(StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return experimentalJ2ObjcHeaderMap;
}

Expand All @@ -162,7 +162,7 @@ public boolean experimentalShorterHeaderPath() {
@Override
public boolean experimentalShorterHeaderPathforStarlark(StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return experimentalShorterHeaderPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public boolean alwayslinkByDefault() {
@Override
public boolean targetShouldAlwayslink(StarlarkRuleContext ruleContext, StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);

AttributeMap attributes = ruleContext.getRuleContext().attributes();
if (attributes.isAttributeValueExplicitlySpecified("alwayslink")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public ImmutableList<String> protocOptsForStarlark() throws EvalException {
documented = false)
public boolean experimentalProtoDescriptorSetsIncludeSourceInfoForStarlark(StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return experimentalProtoDescriptorSetsIncludeSourceInfo();
}

Expand Down Expand Up @@ -232,13 +232,13 @@ public Label protoToolchainForCc() {

@StarlarkMethod(name = "strict_proto_deps", useStarlarkThread = true, documented = false)
public String strictProtoDepsForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return options.strictProtoDeps.toString();
}

@StarlarkMethod(name = "strict_public_imports", useStarlarkThread = true, documented = false)
public String strictPublicImportsForStarlark(StarlarkThread thread) throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return options.strictPublicImports.toString();
}

Expand All @@ -248,7 +248,7 @@ public String strictPublicImportsForStarlark(StarlarkThread thread) throws EvalE
documented = false)
public List<String> ccProtoLibraryHeaderSuffixesForStarlark(StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return ccProtoLibraryHeaderSuffixes;
}

Expand All @@ -258,7 +258,7 @@ public List<String> ccProtoLibraryHeaderSuffixesForStarlark(StarlarkThread threa
documented = false)
public List<String> ccProtoLibrarySourceSuffixesForStarlark(StarlarkThread thread)
throws EvalException {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
BuiltinRestriction.failIfCalledOutsideDefaultAllowlist(thread);
return ccProtoLibrarySourceSuffixes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ def _impl(ctx):

AssertionError e =
assertThrows(AssertionError.class, () -> getConfiguredTarget("//example:custom"));
assertThat(e)
.hasMessageThat()
.contains("file '//example:rule.bzl' cannot use private @_builtins API");
assertThat(e).hasMessageThat().contains("file '//example:rule.bzl' cannot use private API");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ private static void assertBlockedFeature(AssertionError e, String feature) {
assertThat(e)
.hasMessageThat()
.contains(
String.format(
"cannot use private @_builtins API (feature '%s' in CppConfiguration)", feature));
String.format("cannot use private API (feature '%s' in CppConfiguration)", feature));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8197,9 +8197,7 @@ def _impl(ctx):
AssertionError e =
assertThrows(AssertionError.class, () -> getConfiguredTarget("//foo:custom"));

assertThat(e)
.hasMessageThat()
.contains("file '//foo:custom_rule.bzl' cannot use private @_builtins API");
assertThat(e).hasMessageThat().contains("file '//foo:custom_rule.bzl' cannot use private API");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ def _impl(ctx):

getConfiguredTarget("//foo:myrule");

assertContainsEvent("file '//foo:rule.bzl' cannot use private @_builtins API");
assertContainsEvent("file '//foo:rule.bzl' cannot use private API");
}

@Test
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def _impl(ctx):

getConfiguredTarget("//foo:myrule");

assertContainsEvent("file '//foo:rule.bzl' cannot use private @_builtins API");
assertContainsEvent("file '//foo:rule.bzl' cannot use private API");
}

@Test
Expand Down Expand Up @@ -1609,7 +1609,7 @@ def _impl(ctx):

getConfiguredTarget("//foo:myrule");

assertContainsEvent("file '//foo:rule.bzl' cannot use private @_builtins API");
assertContainsEvent("file '//foo:rule.bzl' cannot use private API");
}

@Test
Expand Down

0 comments on commit 37b8626

Please sign in to comment.