Skip to content

Commit

Permalink
In AppleBootstrap.java give several rule repos access to apple_common…
Browse files Browse the repository at this point in the history
… that need it, and activate the access restriction independent of INCOMPATIBLE_STOP_EXPORTING_LANGUAGE_MODULES

PiperOrigin-RevId: 696999389
Change-Id: I000911fbef3b48039beb423e5ba1ab48059b8eeb
  • Loading branch information
pzembrod authored and copybara-github committed Nov 15, 2024
1 parent 17057fd commit b406bdc
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.starlarkbuildapi.core.Bootstrap;
import com.google.devtools.build.lib.starlarkbuildapi.core.ContextAndFlagGuardedValue;
import com.google.devtools.build.lib.starlarkbuildapi.core.ContextGuardedValue;
import net.starlark.java.eval.Starlark;

/** {@link Bootstrap} for Starlark objects related to apple rules. */
Expand All @@ -28,17 +27,22 @@ public class AppleBootstrap implements Bootstrap {
private static final ImmutableSet<PackageIdentifier> allowedRepositories =
ImmutableSet.of(
PackageIdentifier.createUnchecked("_builtins", ""),
PackageIdentifier.createUnchecked("apple_support", ""),
PackageIdentifier.createUnchecked("bazel_tools", ""),
PackageIdentifier.createUnchecked("local_config_cc", ""),
PackageIdentifier.createUnchecked("rules_apple", ""),
PackageIdentifier.createUnchecked("", "tools/build_defs/apple"));
PackageIdentifier.createUnchecked("rules_cc", ""),
PackageIdentifier.createUnchecked("rules_go", ""),
PackageIdentifier.createUnchecked("rules_ios", ""),
PackageIdentifier.createUnchecked("rules_swift", ""),
PackageIdentifier.createUnchecked("stardoc", ""),
PackageIdentifier.createUnchecked("tulsi", ""),
PackageIdentifier.createUnchecked("", "test_starlark"),
PackageIdentifier.createUnchecked("", "tools/osx"));

@Override
public void addBindingsToBuilder(ImmutableMap.Builder<String, Object> builder) {
builder.put(
"apple_common",
ContextAndFlagGuardedValue.onlyInAllowedReposOrWhenIncompatibleFlagIsFalse(
BuildLanguageOptions.INCOMPATIBLE_STOP_EXPORTING_LANGUAGE_MODULES,
Starlark.NONE,
allowedRepositories));
"apple_common", ContextGuardedValue.onlyInAllowedRepos(Starlark.NONE, allowedRepositories));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public final class XcodeVersionTest extends BuildViewTestCase {

@Test
public void testXcodeVersionCanBeReadFromStarlark() throws Exception {
scratch.file("examples/rule/BUILD");
scratch.file("test_starlark/rule/BUILD");
scratch.file(
"examples/rule/apple_rules.bzl",
"test_starlark/rule/apple_rules.bzl",
"""
MyInfo = provider()
Expand Down Expand Up @@ -72,7 +72,7 @@ def my_rule_impl(ctx):
scratch.file(
"examples/apple_starlark/BUILD",
"""
load("//examples/rule:apple_rules.bzl", "my_rule")
load("//test_starlark/rule:apple_rules.bzl", "my_rule")
package(default_visibility = ["//visibility:public"])
Expand All @@ -95,7 +95,7 @@ def my_rule_impl(ctx):
(RuleConfiguredTarget) getConfiguredTarget("//examples/apple_starlark:my_target");
Provider.Key key =
new StarlarkProvider.Key(
keyForBuild(Label.parseCanonical("//examples/rule:apple_rules.bzl")), "MyInfo");
keyForBuild(Label.parseCanonical("//test_starlark/rule:apple_rules.bzl")), "MyInfo");
StructImpl myInfo = (StructImpl) starlarkTarget.get(key);
assertThat((String) myInfo.getValue("xcode_version")).isEqualTo("8");
assertThat((String) myInfo.getValue("ios_version")).isEqualTo("9.0");
Expand Down
Loading

0 comments on commit b406bdc

Please sign in to comment.