blob: f2357ef3a9dfdd3e094f78b5703a9b6c21ee9112 [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;
emilyguo305fcc32022-03-29 10:10:07 -070023import com.google.devtools.build.skyframe.GraphTraversingHelper;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024import com.google.devtools.build.skyframe.SkyFunction;
25import com.google.devtools.build.skyframe.SkyKey;
26import com.google.devtools.build.skyframe.SkyValue;
27
28/**
Dmitry Lomove2033b12015-08-19 16:57:49 +000029 * TestCompletionFunction builds all relevant test artifacts of a {@link
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010030 * com.google.devtools.build.lib.analysis.ConfiguredTarget}. This includes test shards and repeated
31 * runs.
32 */
33public final class TestCompletionFunction implements SkyFunction {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010034 @Override
Janak Ramakrishnan3c0adb22016-08-15 21:54:55 +000035 public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010036 TestCompletionValue.TestCompletionKey key =
37 (TestCompletionValue.TestCompletionKey) skyKey.argument();
janakr573807d2018-01-11 14:02:35 -080038 ConfiguredTargetKey ctKey = key.configuredTargetKey();
Googlerbfd4e242016-07-15 22:23:37 +000039 TopLevelArtifactContext ctx = key.topLevelArtifactContext();
janakr573807d2018-01-11 14:02:35 -080040 if (env.getValue(TargetCompletionValue.key(ctKey, ctx, /*willTest=*/ true)) == null) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010041 return null;
42 }
janakra4634cf2017-08-24 09:23:39 +020043
janakr573807d2018-01-11 14:02:35 -080044 ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ctKey);
janakra4634cf2017-08-24 09:23:39 +020045 if (ctValue == null) {
46 return null;
47 }
48
49 ConfiguredTarget ct = ctValue.getConfiguredTarget();
50 if (key.exclusiveTesting()) {
janakrb9d8d582018-06-13 21:57:19 -070051 // Request test execution iteratively if testing exclusively.
janakrefb3f152019-06-05 17:42:34 -070052 for (Artifact.DerivedArtifact testArtifact : TestProvider.getTestStatusArtifacts(ct)) {
53 env.getValue(testArtifact.getGeneratingActionKey());
janakrb9d8d582018-06-13 21:57:19 -070054 if (env.valuesMissing()) {
janakra4634cf2017-08-24 09:23:39 +020055 return null;
56 }
57 }
58 } else {
emilyguo305fcc32022-03-29 10:10:07 -070059 if (GraphTraversingHelper.declareDependenciesAndCheckIfValuesMissingMaybeWithExceptions(
60 env,
janakrefb3f152019-06-05 17:42:34 -070061 Iterables.transform(
62 TestProvider.getTestStatusArtifacts(ct),
emilyguo305fcc32022-03-29 10:10:07 -070063 Artifact.DerivedArtifact::getGeneratingActionKey))) {
janakra4634cf2017-08-24 09:23:39 +020064 return null;
65 }
66 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010067 return TestCompletionValue.TEST_COMPLETION_MARKER;
68 }
69
70 @Override
71 public String extractTag(SkyKey skyKey) {
janakrac2cd352017-12-20 13:37:13 -080072 return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel());
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010073 }
74}