Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 16 | import com.google.common.collect.Iterables; |
janakr | a4634cf | 2017-08-24 09:23:39 +0200 | [diff] [blame] | 17 | import com.google.devtools.build.lib.actions.Artifact; |
| 18 | import com.google.devtools.build.lib.analysis.ConfiguredTarget; |
janakr | 876deaa | 2021-02-17 07:49:48 -0800 | [diff] [blame] | 19 | import com.google.devtools.build.lib.analysis.ConfiguredTargetValue; |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; |
janakr | a4634cf | 2017-08-24 09:23:39 +0200 | [diff] [blame] | 21 | import com.google.devtools.build.lib.analysis.test.TestProvider; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 22 | import com.google.devtools.build.lib.cmdline.Label; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.devtools.build.skyframe.SkyFunction; |
| 24 | import com.google.devtools.build.skyframe.SkyKey; |
| 25 | import com.google.devtools.build.skyframe.SkyValue; |
| 26 | |
| 27 | /** |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 28 | * TestCompletionFunction builds all relevant test artifacts of a {@link |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | * com.google.devtools.build.lib.analysis.ConfiguredTarget}. This includes test shards and repeated |
| 30 | * runs. |
| 31 | */ |
| 32 | public final class TestCompletionFunction implements SkyFunction { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | @Override |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 34 | public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 35 | TestCompletionValue.TestCompletionKey key = |
| 36 | (TestCompletionValue.TestCompletionKey) skyKey.argument(); |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 37 | ConfiguredTargetKey ctKey = key.configuredTargetKey(); |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 38 | TopLevelArtifactContext ctx = key.topLevelArtifactContext(); |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 39 | if (env.getValue(TargetCompletionValue.key(ctKey, ctx, /*willTest=*/ true)) == null) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 40 | return null; |
| 41 | } |
janakr | a4634cf | 2017-08-24 09:23:39 +0200 | [diff] [blame] | 42 | |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 43 | ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ctKey); |
janakr | a4634cf | 2017-08-24 09:23:39 +0200 | [diff] [blame] | 44 | if (ctValue == null) { |
| 45 | return null; |
| 46 | } |
| 47 | |
| 48 | ConfiguredTarget ct = ctValue.getConfiguredTarget(); |
| 49 | if (key.exclusiveTesting()) { |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 50 | // Request test execution iteratively if testing exclusively. |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 51 | for (Artifact.DerivedArtifact testArtifact : TestProvider.getTestStatusArtifacts(ct)) { |
| 52 | env.getValue(testArtifact.getGeneratingActionKey()); |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 53 | if (env.valuesMissing()) { |
janakr | a4634cf | 2017-08-24 09:23:39 +0200 | [diff] [blame] | 54 | return null; |
| 55 | } |
| 56 | } |
| 57 | } else { |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 58 | env.getValues( |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 59 | Iterables.transform( |
| 60 | TestProvider.getTestStatusArtifacts(ct), |
| 61 | Artifact.DerivedArtifact::getGeneratingActionKey)); |
janakr | a4634cf | 2017-08-24 09:23:39 +0200 | [diff] [blame] | 62 | if (env.valuesMissing()) { |
| 63 | return null; |
| 64 | } |
| 65 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 66 | return TestCompletionValue.TEST_COMPLETION_MARKER; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String extractTag(SkyKey skyKey) { |
janakr | ac2cd35 | 2017-12-20 13:37:13 -0800 | [diff] [blame] | 71 | return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 72 | } |
| 73 | } |