Skip to content

Commit

Permalink
Stop using --fat_apk_cpu in tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 687111838
Change-Id: Ifb804d115aa0adec833287e67f44c519080c299b
  • Loading branch information
katre authored and copybara-github committed Oct 18, 2024
1 parent 408ab2d commit 2ce9e35
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ java_test(
deps = [
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/core_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/configuration_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

package com.google.devtools.build.lib.analysis.starlark;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Multimaps.toMultimap;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
Expand All @@ -29,6 +31,8 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.RequiredConfigFragmentsProvider;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.CoreOptions;
import com.google.devtools.build.lib.analysis.config.OutputPathMnemonicComputer;
import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
Expand All @@ -49,7 +53,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import net.starlark.java.eval.Dict;
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkInt;
Expand Down Expand Up @@ -637,16 +640,29 @@ private void writeReadSettingsTestFiles() throws Exception {
"""
load("//myinfo:myinfo.bzl", "MyInfo")
def _flag_impl(ctx):
pass
string_flag = rule(
implementation = _flag_impl,
build_setting = config.string(flag = True),
)
string_list_flag = rule(
implementation = _flag_impl,
build_setting = config.string_list(flag = True),
)
def transition_func(settings, attr):
transitions = []
for cpu in settings["//command_line_option:fat_apk_cpu"]:
transitions.append({"//command_line_option:cpu": cpu})
for val in settings["//test/starlark:source"]:
transitions.append({"//test/starlark:dest": val})
return transitions
my_transition = transition(
implementation = transition_func,
inputs = ["//command_line_option:fat_apk_cpu"],
outputs = ["//command_line_option:cpu"],
inputs = ["//test/starlark:source"],
outputs = ["//test/starlark:dest"],
)
def impl(ctx):
Expand All @@ -663,7 +679,17 @@ def impl(ctx):
scratch.file(
"test/starlark/BUILD",
"""
load("//test/starlark:my_rule.bzl", "my_rule")
load("//test/starlark:my_rule.bzl", "my_rule", "string_list_flag", "string_flag")
string_list_flag(
name = "source",
build_setting_default = [],
)
string_flag(
name = "dest",
build_setting_default = "",
)
my_rule(
name = "test",
Expand All @@ -682,18 +708,25 @@ public void testReadSettingsSplitDepAttrDep() throws Exception {
getAnalysisMock().ccSupport().setupCcToolchainConfigForCpu(mockToolsConfig, "armeabi-v7a");
writeReadSettingsTestFiles();

useConfiguration("--fat_apk_cpu=k8,armeabi-v7a");
useConfiguration("--//test/starlark:source=first,second");
ConfiguredTarget target = getConfiguredTarget("//test/starlark:test");

@SuppressWarnings("unchecked")
Dict<String, ConfiguredTarget> splitDep =
(Dict<String, ConfiguredTarget>) getMyInfoFromTarget(target).getValue("attr_dep");
assertThat(splitDep.size()).isEqualTo(2);
List<String> cpus =
ImmutableSet<String> values =
splitDep.values().stream()
.map(ct -> getConfiguration(ct).getCpu())
.collect(Collectors.toList());
assertThat(cpus).containsExactly("k8", "armeabi-v7a");
.map(this::getConfiguration)
.map(BuildConfigurationValue::getOptions)
.map(
options ->
(String)
options
.getStarlarkOptions()
.get(Label.parseCanonicalUnchecked("//test/starlark:dest")))
.collect(toImmutableSet());
assertThat(values).containsExactly("first", "second");
}

private void writeOptionConversionTestFiles() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ public void testStartEndLib() throws Exception {
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_START_END_LIB));
useConfiguration(
// Prevent Android from trying to setup ARM crosstool by forcing it on system cpu.
"--fat_apk_cpu=k8", "--start_end_lib");
useConfiguration("--start_end_lib");
scratch.file(
"test/BUILD",
"""
Expand Down

0 comments on commit 2ce9e35

Please sign in to comment.