blob: b98e2e46d83522b204f4965d5a4017988d17169c [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.skyframe;
15
janakrefb3f152019-06-05 17:42:34 -070016import com.google.common.collect.Iterables;
janakra4634cf2017-08-24 09:23:39 +020017import com.google.devtools.build.lib.actions.Artifact;
18import com.google.devtools.build.lib.analysis.ConfiguredTarget;
janakr876deaa2021-02-17 07:49:48 -080019import com.google.devtools.build.lib.analysis.ConfiguredTargetValue;
Googlerbfd4e242016-07-15 22:23:37 +000020import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
janakra4634cf2017-08-24 09:23:39 +020021import com.google.devtools.build.lib.analysis.test.TestProvider;
Lukacs Berki6e91eb92015-09-21 09:12:37 +000022import com.google.devtools.build.lib.cmdline.Label;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010023import com.google.devtools.build.skyframe.SkyFunction;
24import com.google.devtools.build.skyframe.SkyKey;
25import com.google.devtools.build.skyframe.SkyValue;
26
27/**
Dmitry Lomove2033b12015-08-19 16:57:49 +000028 * TestCompletionFunction builds all relevant test artifacts of a {@link
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010029 * com.google.devtools.build.lib.analysis.ConfiguredTarget}. This includes test shards and repeated
30 * runs.
31 */
32public final class TestCompletionFunction implements SkyFunction {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010033 @Override
Janak Ramakrishnan3c0adb22016-08-15 21:54:55 +000034 public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010035 TestCompletionValue.TestCompletionKey key =
36 (TestCompletionValue.TestCompletionKey) skyKey.argument();
janakr573807d2018-01-11 14:02:35 -080037 ConfiguredTargetKey ctKey = key.configuredTargetKey();
Googlerbfd4e242016-07-15 22:23:37 +000038 TopLevelArtifactContext ctx = key.topLevelArtifactContext();
janakr573807d2018-01-11 14:02:35 -080039 if (env.getValue(TargetCompletionValue.key(ctKey, ctx, /*willTest=*/ true)) == null) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010040 return null;
41 }
janakra4634cf2017-08-24 09:23:39 +020042
janakr573807d2018-01-11 14:02:35 -080043 ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ctKey);
janakra4634cf2017-08-24 09:23:39 +020044 if (ctValue == null) {
45 return null;
46 }
47
48 ConfiguredTarget ct = ctValue.getConfiguredTarget();
49 if (key.exclusiveTesting()) {
janakrb9d8d582018-06-13 21:57:19 -070050 // Request test execution iteratively if testing exclusively.
janakrefb3f152019-06-05 17:42:34 -070051 for (Artifact.DerivedArtifact testArtifact : TestProvider.getTestStatusArtifacts(ct)) {
52 env.getValue(testArtifact.getGeneratingActionKey());
janakrb9d8d582018-06-13 21:57:19 -070053 if (env.valuesMissing()) {
janakra4634cf2017-08-24 09:23:39 +020054 return null;
55 }
56 }
57 } else {
janakrb9d8d582018-06-13 21:57:19 -070058 env.getValues(
janakrefb3f152019-06-05 17:42:34 -070059 Iterables.transform(
60 TestProvider.getTestStatusArtifacts(ct),
61 Artifact.DerivedArtifact::getGeneratingActionKey));
janakra4634cf2017-08-24 09:23:39 +020062 if (env.valuesMissing()) {
63 return null;
64 }
65 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010066 return TestCompletionValue.TEST_COMPLETION_MARKER;
67 }
68
69 @Override
70 public String extractTag(SkyKey skyKey) {
janakrac2cd352017-12-20 13:37:13 -080071 return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel());
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010072 }
73}