Skip to content

Commit

Permalink
Enable Bzlmod in AnalysisTestCase.java
Browse files Browse the repository at this point in the history
Working towards: #19824

Related: #23023

Part of: #23253

PiperOrigin-RevId: 664876902
Change-Id: I8386b13fd12f5d4fb0599c0142df668b0c4a7f74
  • Loading branch information
meteorcloudy authored and copybara-github committed Aug 19, 2024
1 parent c299b39 commit f848b06
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testIncrementalGlobIOException() throws Exception {
@Test
public void testWorkspaceError() throws IOException {
scratch.file("a/BUILD");
crashMessage = path -> path.toString().contains("WORKSPACE") ? "bork" : null;
crashMessage = path -> path.toString().contains("MODULE.bazel") ? "bork" : null;
reporter.removeHandler(failFastHandler);
assertThrows(
TargetParsingException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public void aspectCreationWorksThroughBind() throws Exception {
.add("bind(name='b', actual='//a:b')")
.build());

useConfiguration("--enable_workspace");
update();

skyframeExecutor.invalidateFilesUnderPathForTesting(
reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory));

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

update("//foo:a");
assertContainsEvent("DEBUG /workspace/foo/rule.bzl:3:8: f owner is @//foo:a");
assertContainsEvent("DEBUG /workspace/foo/rule.bzl:3:8: f owner is @@//foo:a");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public enum Flag {
CPU_K8,
// Flags from TestConstants.PRODUCT_SPECIFIC_FLAGS.
PRODUCT_SPECIFIC_FLAGS,
// The --enable_bzlmod flags.
ENABLE_BZLMOD,
// The --nolegacy_external_runfiles flag.
NO_LEGACY_EXTERNAL_RUNFILES
}
Expand Down Expand Up @@ -245,6 +243,11 @@ protected void useRuleClassProvider(ConfiguredRuleClassProvider ruleClassProvide
RepositoryDelegatorFunction.DISABLE_NATIVE_REPO_RULES, false),
PrecomputedValue.injected(
ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
RepositoryDelegatorFunction.FORCE_FETCH,
RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(
BazelModuleResolutionFunction.CHECK_DIRECT_DEPENDENCIES,
CheckDirectDepsMode.WARNING),
Expand Down Expand Up @@ -272,7 +275,6 @@ private void reinitializeSkyframeExecutor() {
packageOptions.showLoadingProgress = true;
packageOptions.globbingThreads = 3;
BuildLanguageOptions buildLanguageOptions = Options.getDefaults(BuildLanguageOptions.class);
buildLanguageOptions.enableBzlmod = true;
skyframeExecutor.preparePackageLoading(
pkgLocator,
packageOptions,
Expand Down Expand Up @@ -352,11 +354,6 @@ public void useConfiguration(String... args) throws Exception {
if (defaultFlags().contains(Flag.PRODUCT_SPECIFIC_FLAGS)) {
optionsParser.parse(TestConstants.PRODUCT_SPECIFIC_FLAGS);
}
if (defaultFlags().contains(Flag.ENABLE_BZLMOD)) {
optionsParser.parse("--enable_bzlmod");
} else {
optionsParser.parse("--noenable_bzlmod");
}
if (defaultFlags().contains(Flag.NO_LEGACY_EXTERNAL_RUNFILES)) {
optionsParser.parse("--nolegacy_external_runfiles");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,6 @@ protected AnalysisResult update(String... labels) throws Exception {
return super.update(labels);
}

@Override
protected FlagBuilder defaultFlags() {
return super.defaultFlags().with(Flag.ENABLE_BZLMOD);
}

protected SkyframeExecutor getSkyframeExecutor() {
return skyframeExecutor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public ToolchainCollection<UnloadedToolchainContext> getToolchainCollection(Stri

@Before
public void createToolchains() throws Exception {
scratch.appendFile("WORKSPACE", "register_toolchains('//toolchains:all')");
scratch.appendFile("MODULE.bazel", "register_toolchains('//toolchains:all')");

scratch.file(
"toolchain/toolchain_def.bzl",
Expand Down Expand Up @@ -783,7 +783,7 @@ public void targetCompatibleWith_matchesExecCompatibleWith() throws Exception {
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder()
.withToolchainTargetConstraints("@//platforms:local_value_a")
.withToolchainTargetConstraints("@@//platforms:local_value_a")
.withToolchainExecConstraints()
.withCpu("fake"));
scratch.file(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,8 @@ def _rule_impl(ctx):
var value = ((StarlarkInfo) configuredAspect.get(providerKey)).getValue("value");
assertThat((Iterable<?>) value)
.containsExactly(
"toolchain_aspect has param = xxx on @//test:t1",
"toolchain_aspect has param = xxx on @//toolchain:foo with tool in ToolchainInfo ="
"toolchain_aspect has param = xxx on @@//test:t1",
"toolchain_aspect has param = xxx on @@//toolchain:foo with tool in ToolchainInfo ="
+ " <generated file toolchain/atool>");
}

Expand Down Expand Up @@ -1172,8 +1172,8 @@ def _rule_impl(ctx):
var value = ((StarlarkInfo) configuredAspect.get(providerKey)).getValue("value");
assertThat((Iterable<?>) value)
.containsExactly(
"toolchain_aspect has param = xxx on @//test:t1",
"toolchain_aspect has param = xxx on @//toolchain:foo with tool in"
"toolchain_aspect has param = xxx on @@//test:t1",
"toolchain_aspect has param = xxx on @@//toolchain:foo with tool in"
+ " ToolchainInfo = <generated file toolchain/atool>");
}

Expand Down Expand Up @@ -1243,8 +1243,8 @@ def _rule_impl(ctx):
var value = ((StarlarkInfo) configuredAspect.get(providerKey)).getValue("value");
assertThat((Iterable<?>) value)
.containsExactly(
"toolchain_aspect has param = xxx on @//test:t1",
"toolchain_aspect has param = xxx on @//toolchain:foo with tool in ToolchainInfo ="
"toolchain_aspect has param = xxx on @@//test:t1",
"toolchain_aspect has param = xxx on @@//toolchain:foo with tool in ToolchainInfo ="
+ " <generated file toolchain/atool>");
}

Expand Down Expand Up @@ -1395,10 +1395,10 @@ def _rule_impl(ctx):
var value = ((StarlarkInfo) configuredAspect.get(providerKey)).getValue("value");
assertThat((Iterable<?>) value)
.containsExactly(
"toolchain_aspect on @//test:t1 can see required_aspect (required_aspect on"
+ " @//test:t1)",
"toolchain_aspect on @//toolchain:foo can see required_aspect (required_aspect on"
+ " @//toolchain:foo with tool in ToolchainInfo = <generated file"
"toolchain_aspect on @@//test:t1 can see required_aspect (required_aspect on"
+ " @@//test:t1)",
"toolchain_aspect on @@//toolchain:foo can see required_aspect (required_aspect on"
+ " @@//toolchain:foo with tool in ToolchainInfo = <generated file"
+ " toolchain/atool>)");
}

Expand Down Expand Up @@ -1467,9 +1467,9 @@ def _rule_2_impl(ctx):
var value = ((StarlarkInfo) configuredTarget.get(providerKey)).getValue("value");
assertThat((Iterable<?>) value)
.containsExactly(
"toolchain_aspect on @//test:t2",
"toolchain_aspect on @//toolchain:foo_with_dep",
"toolchain_aspect on @//toolchain:toolchain_dep");
"toolchain_aspect on @@//test:t2",
"toolchain_aspect on @@//toolchain:foo_with_dep",
"toolchain_aspect on @@//toolchain:toolchain_dep");
}

private ImmutableList<AspectKey> getAspectKeys(String targetLabel, String aspectLabel) {
Expand Down
Loading

0 comments on commit f848b06

Please sign in to comment.