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 | |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 16 | import com.google.auto.value.AutoValue; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 17 | import com.google.common.collect.Interner; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.common.collect.Iterables; |
| 19 | import com.google.devtools.build.lib.analysis.ConfiguredTarget; |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 21 | import com.google.devtools.build.lib.concurrent.BlazeInterners; |
| 22 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
| 23 | import com.google.devtools.build.skyframe.SkyFunctionName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | import com.google.devtools.build.skyframe.SkyKey; |
| 25 | import com.google.devtools.build.skyframe.SkyValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 26 | import java.util.Collection; |
| 27 | |
| 28 | /** |
| 29 | * A test completion value represents the completion of a test target. This includes the execution |
| 30 | * of all test shards and repeated runs, if applicable. |
| 31 | */ |
| 32 | public class TestCompletionValue implements SkyValue { |
| 33 | static final TestCompletionValue TEST_COMPLETION_MARKER = new TestCompletionValue(); |
| 34 | |
| 35 | private TestCompletionValue() { } |
| 36 | |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 37 | public static SkyKey key( |
janakr | ac2cd35 | 2017-12-20 13:37:13 -0800 | [diff] [blame] | 38 | ConfiguredTargetKey lac, |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 39 | final TopLevelArtifactContext topLevelArtifactContext, |
| 40 | final boolean exclusiveTesting) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 41 | return TestCompletionKey.create(lac, topLevelArtifactContext, exclusiveTesting); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | public static Iterable<SkyKey> keys(Collection<ConfiguredTarget> targets, |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 45 | final TopLevelArtifactContext topLevelArtifactContext, |
| 46 | final boolean exclusiveTesting) { |
Janak Ramakrishnan | f745e99 | 2016-03-03 08:08:50 +0000 | [diff] [blame] | 47 | return Iterables.transform( |
| 48 | targets, |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 49 | ct -> |
| 50 | TestCompletionKey.create( |
janakr | 5720363 | 2018-03-27 13:25:21 -0700 | [diff] [blame] | 51 | // Tests are never in host configuration. |
| 52 | ConfiguredTargetKey.of( |
| 53 | ct, ct.getConfigurationKey(), /*isHostConfiguration=*/ false), |
| 54 | topLevelArtifactContext, |
| 55 | exclusiveTesting)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 56 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 57 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 58 | @AutoCodec |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 59 | @AutoValue |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 60 | abstract static class TestCompletionKey implements SkyKey { |
| 61 | private static final Interner<TestCompletionKey> interner = BlazeInterners.newWeakInterner(); |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 62 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 63 | @AutoCodec.VisibleForSerialization |
| 64 | @AutoCodec.Instantiator |
| 65 | static TestCompletionKey create( |
janakr | ac2cd35 | 2017-12-20 13:37:13 -0800 | [diff] [blame] | 66 | ConfiguredTargetKey configuredTargetKey, |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 67 | TopLevelArtifactContext topLevelArtifactContext, |
| 68 | boolean exclusiveTesting) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 69 | return interner.intern( |
| 70 | new AutoValue_TestCompletionValue_TestCompletionKey( |
| 71 | configuredTargetKey, topLevelArtifactContext, exclusiveTesting)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 72 | } |
| 73 | |
janakr | ac2cd35 | 2017-12-20 13:37:13 -0800 | [diff] [blame] | 74 | abstract ConfiguredTargetKey configuredTargetKey(); |
| 75 | |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 76 | public abstract TopLevelArtifactContext topLevelArtifactContext(); |
| 77 | public abstract boolean exclusiveTesting(); |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 78 | |
| 79 | @Override |
| 80 | public SkyFunctionName functionName() { |
| 81 | return SkyFunctions.TEST_COMPLETION; |
| 82 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 83 | } |
| 84 | } |