|
19 | 19 | import com.google.common.collect.Collections2;
|
20 | 20 | import com.google.common.collect.ImmutableList;
|
21 | 21 | import com.google.common.collect.ImmutableMap;
|
| 22 | +import com.google.common.collect.ImmutableSet; |
22 | 23 | import com.google.common.collect.Iterables;
|
23 | 24 | import com.google.common.collect.Multimap;
|
24 | 25 | import com.google.devtools.build.lib.analysis.AliasProvider;
|
|
27 | 28 | import com.google.devtools.build.lib.analysis.Dependency;
|
28 | 29 | import com.google.devtools.build.lib.analysis.DependencyKind;
|
29 | 30 | import com.google.devtools.build.lib.analysis.DependencyResolver;
|
| 31 | +import com.google.devtools.build.lib.analysis.PlatformOptions; |
30 | 32 | import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
|
| 33 | +import com.google.devtools.build.lib.analysis.ToolchainCollection; |
| 34 | +import com.google.devtools.build.lib.analysis.ToolchainContext; |
31 | 35 | import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
|
32 | 36 | import com.google.devtools.build.lib.analysis.config.CompilationMode;
|
33 | 37 | import com.google.devtools.build.lib.analysis.config.ConfigurationResolver;
|
| 38 | +import com.google.devtools.build.lib.analysis.platform.PlatformInfo; |
34 | 39 | import com.google.devtools.build.lib.analysis.util.AnalysisMock;
|
35 | 40 | import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
|
| 41 | +import com.google.devtools.build.lib.cmdline.Label; |
36 | 42 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
|
37 | 43 | import com.google.devtools.build.lib.packages.Attribute;
|
38 | 44 | import com.google.devtools.build.lib.packages.RuleClassProvider;
|
|
47 | 53 | import com.google.devtools.build.skyframe.SkyKey;
|
48 | 54 | import com.google.devtools.build.skyframe.SkyValue;
|
49 | 55 | import java.util.List;
|
50 |
| -import org.junit.Ignore; |
| 56 | +import org.junit.Before; |
51 | 57 | import org.junit.Test;
|
52 | 58 | import org.junit.runner.RunWith;
|
53 | 59 | import org.junit.runners.JUnit4;
|
|
75 | 81 | @RunWith(JUnit4.class)
|
76 | 82 | public class ConfigurationsForTargetsTest extends AnalysisTestCase {
|
77 | 83 |
|
| 84 | + public static final Label TARGET_PLATFORM_LABEL = |
| 85 | + Label.parseAbsoluteUnchecked("//platform:target"); |
| 86 | + public static final Label EXEC_PLATFORM_LABEL = Label.parseAbsoluteUnchecked("//platform:exec"); |
| 87 | + |
78 | 88 | /**
|
79 | 89 | * A mock {@link SkyFunction} that just calls {@link ConfiguredTargetFunction#computeDependencies}
|
80 | 90 | * and returns its results.
|
@@ -118,18 +128,35 @@ static final class Value implements SkyValue {
|
118 | 128 | public SkyValue compute(SkyKey skyKey, Environment env)
|
119 | 129 | throws EvalException, InterruptedException {
|
120 | 130 | try {
|
| 131 | + TargetAndConfiguration targetAndConfiguration = (TargetAndConfiguration) skyKey.argument(); |
| 132 | + // Set up the toolchain context so that exec transitions resolve properly. |
| 133 | + ToolchainCollection<ToolchainContext> toolchainContexts = |
| 134 | + ToolchainCollection.builder() |
| 135 | + .addDefaultContext( |
| 136 | + UnloadedToolchainContextImpl.builder( |
| 137 | + ToolchainContextKey.key() |
| 138 | + .toolchainTypes(ImmutableSet.of()) |
| 139 | + .configurationKey( |
| 140 | + targetAndConfiguration.getConfiguration().getKey()) |
| 141 | + .build()) |
| 142 | + .setTargetPlatform( |
| 143 | + PlatformInfo.builder().setLabel(TARGET_PLATFORM_LABEL).build()) |
| 144 | + .setExecutionPlatform( |
| 145 | + PlatformInfo.builder().setLabel(EXEC_PLATFORM_LABEL).build()) |
| 146 | + .build()) |
| 147 | + .build(); |
121 | 148 | OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> depMap =
|
122 | 149 | ConfiguredTargetFunction.computeDependencies(
|
123 | 150 | new ConfiguredTargetFunction.ComputeDependenciesState(),
|
124 | 151 | /*transitivePackagesForPackageRootResolution=*/ null,
|
125 | 152 | /*transitiveRootCauses=*/ NestedSetBuilder.stableOrder(),
|
126 | 153 | env,
|
127 | 154 | new SkyframeDependencyResolver(env),
|
128 |
| - (TargetAndConfiguration) skyKey.argument(), |
| 155 | + targetAndConfiguration, |
129 | 156 | ImmutableList.of(),
|
130 | 157 | ImmutableMap.of(),
|
131 |
| - /*toolchainContexts=*/ null, |
132 |
| - /*useToolchainTransition=*/ false, |
| 158 | + toolchainContexts, |
| 159 | + /*useToolchainTransition=*/ true, |
133 | 160 | stateProvider.lateBoundRuleClassProvider(),
|
134 | 161 | stateProvider.lateBoundHostConfig());
|
135 | 162 | return env.valuesMissing() ? null : new Value(depMap);
|
@@ -243,6 +270,15 @@ protected List<ConfiguredTarget> getConfiguredDeps(ConfiguredTarget target, Stri
|
243 | 270 | String.format("Couldn't find attribute %s for label %s", attrName, targetLabel));
|
244 | 271 | }
|
245 | 272 |
|
| 273 | + @Before |
| 274 | + public void setUp() throws Exception { |
| 275 | + scratch.file( |
| 276 | + "platform/BUILD", |
| 277 | + // Add basic target and exec platforms for testing. |
| 278 | + "platform(name = 'target')", |
| 279 | + "platform(name = 'exec')"); |
| 280 | + } |
| 281 | + |
246 | 282 | @Test
|
247 | 283 | public void nullConfiguredDepsHaveExpectedConfigs() throws Exception {
|
248 | 284 | scratch.file(
|
@@ -275,23 +311,24 @@ public void targetDeps() throws Exception {
|
275 | 311 | * contexts.
|
276 | 312 | */
|
277 | 313 | @Test
|
278 |
| - @Ignore("b/219749974") |
279 |
| - public void hostDeps() throws Exception { |
| 314 | + public void execDeps() throws Exception { |
280 | 315 | scratch.file(
|
281 |
| - "a/host_rule.bzl", |
282 |
| - "host_rule = rule(", |
| 316 | + "a/exec_rule.bzl", |
| 317 | + "exec_rule = rule(", |
283 | 318 | " implementation = lambda ctx: [],",
|
284 |
| - " attrs = {'tools': attr.label_list(cfg = 'host')},", |
| 319 | + " attrs = {'tools': attr.label_list(cfg = 'exec')},", |
285 | 320 | ")");
|
286 | 321 | scratch.file(
|
287 | 322 | "a/BUILD",
|
288 |
| - "load('//a:host_rule.bzl', 'host_rule')", |
289 |
| - "cc_binary(name = 'host_tool', srcs = ['host_tool.cc'])", |
290 |
| - "host_rule(name = 'gen', tools = [':host_tool'])"); |
| 323 | + "load('//a:exec_rule.bzl', 'exec_rule')", |
| 324 | + "sh_binary(name = 'exec_tool', srcs = ['exec_tool.sh'])", |
| 325 | + "exec_rule(name = 'gen', tools = [':exec_tool'])"); |
291 | 326 |
|
292 | 327 | ConfiguredTarget toolDep = Iterables.getOnlyElement(getConfiguredDeps("//a:gen", "tools"));
|
293 |
| - |
294 |
| - assertThat(getConfiguration(toolDep).isHostConfiguration()).isTrue(); |
| 328 | + BuildConfigurationValue toolConfiguration = getConfiguration(toolDep); |
| 329 | + assertThat(toolConfiguration.isToolConfiguration()).isTrue(); |
| 330 | + assertThat(toolConfiguration.getOptions().get(PlatformOptions.class).platforms) |
| 331 | + .containsExactly(EXEC_PLATFORM_LABEL); |
295 | 332 | }
|
296 | 333 |
|
297 | 334 | @Test
|
|
0 commit comments