blob: d289ae4e752c7bc7ac086bb3185fa7caa88e4437 [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
Googlerbfd4e242016-07-15 22:23:37 +000016import com.google.auto.value.AutoValue;
janakr5fb2a482018-03-02 17:48:57 -080017import com.google.common.collect.Interner;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018import com.google.common.collect.Iterables;
19import com.google.devtools.build.lib.analysis.ConfiguredTarget;
Googlerbfd4e242016-07-15 22:23:37 +000020import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
janakr5fb2a482018-03-02 17:48:57 -080021import com.google.devtools.build.lib.concurrent.BlazeInterners;
22import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
23import com.google.devtools.build.skyframe.SkyFunctionName;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024import com.google.devtools.build.skyframe.SkyKey;
25import com.google.devtools.build.skyframe.SkyValue;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010026import 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 */
32public class TestCompletionValue implements SkyValue {
33 static final TestCompletionValue TEST_COMPLETION_MARKER = new TestCompletionValue();
34
35 private TestCompletionValue() { }
36
Googlerbfd4e242016-07-15 22:23:37 +000037 public static SkyKey key(
janakrac2cd352017-12-20 13:37:13 -080038 ConfiguredTargetKey lac,
Googlerbfd4e242016-07-15 22:23:37 +000039 final TopLevelArtifactContext topLevelArtifactContext,
40 final boolean exclusiveTesting) {
janakr5fb2a482018-03-02 17:48:57 -080041 return TestCompletionKey.create(lac, topLevelArtifactContext, exclusiveTesting);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010042 }
43
44 public static Iterable<SkyKey> keys(Collection<ConfiguredTarget> targets,
Googlerbfd4e242016-07-15 22:23:37 +000045 final TopLevelArtifactContext topLevelArtifactContext,
46 final boolean exclusiveTesting) {
Janak Ramakrishnanf745e992016-03-03 08:08:50 +000047 return Iterables.transform(
48 targets,
janakr5fb2a482018-03-02 17:48:57 -080049 ct ->
50 TestCompletionKey.create(
janakr57203632018-03-27 13:25:21 -070051 // Tests are never in host configuration.
52 ConfiguredTargetKey.of(
53 ct, ct.getConfigurationKey(), /*isHostConfiguration=*/ false),
54 topLevelArtifactContext,
55 exclusiveTesting));
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010056 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010057
janakr5fb2a482018-03-02 17:48:57 -080058 @AutoCodec
Googlerbfd4e242016-07-15 22:23:37 +000059 @AutoValue
janakr5fb2a482018-03-02 17:48:57 -080060 abstract static class TestCompletionKey implements SkyKey {
61 private static final Interner<TestCompletionKey> interner = BlazeInterners.newWeakInterner();
Googlerbfd4e242016-07-15 22:23:37 +000062
janakr5fb2a482018-03-02 17:48:57 -080063 @AutoCodec.VisibleForSerialization
64 @AutoCodec.Instantiator
65 static TestCompletionKey create(
janakrac2cd352017-12-20 13:37:13 -080066 ConfiguredTargetKey configuredTargetKey,
Googlerbfd4e242016-07-15 22:23:37 +000067 TopLevelArtifactContext topLevelArtifactContext,
68 boolean exclusiveTesting) {
janakr5fb2a482018-03-02 17:48:57 -080069 return interner.intern(
70 new AutoValue_TestCompletionValue_TestCompletionKey(
71 configuredTargetKey, topLevelArtifactContext, exclusiveTesting));
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010072 }
73
janakrac2cd352017-12-20 13:37:13 -080074 abstract ConfiguredTargetKey configuredTargetKey();
75
Googlerbfd4e242016-07-15 22:23:37 +000076 public abstract TopLevelArtifactContext topLevelArtifactContext();
77 public abstract boolean exclusiveTesting();
janakr5fb2a482018-03-02 17:48:57 -080078
79 @Override
80 public SkyFunctionName functionName() {
81 return SkyFunctions.TEST_COMPLETION;
82 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010083 }
84}