blob: 6b6c7d1f5148676d9f0315494c3d90dadbc6b4a5 [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
tomlua155b532017-11-08 20:12:47 +010016import com.google.common.base.Preconditions;
tomlu9e91f202018-06-18 16:16:36 -070017import com.google.common.collect.ImmutableList;
shahan6aff2d42018-03-13 14:29:12 -070018import com.google.common.collect.ImmutableMap;
janakr573807d2018-01-11 14:02:35 -080019import com.google.common.collect.Interner;
shahan6aff2d42018-03-13 14:29:12 -070020import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
janakr0175ce32018-02-26 15:54:57 -080021import com.google.devtools.build.lib.actions.Actions.GeneratingActions;
shahan6aff2d42018-03-13 14:29:12 -070022import com.google.devtools.build.lib.actions.Artifact;
cparsonse2d200f2018-03-06 16:15:11 -080023import com.google.devtools.build.lib.actions.BasicActionLookupValue;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoCollection;
25import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory;
26import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
Lukacs Berki6e91eb92015-09-21 09:12:37 +000027import com.google.devtools.build.lib.cmdline.Label;
janakr573807d2018-01-11 14:02:35 -080028import com.google.devtools.build.lib.concurrent.BlazeInterners;
janakr92a031f2018-02-01 12:28:21 -080029import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010030import com.google.devtools.build.skyframe.SkyFunctionName;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010031import java.util.Objects;
32
33/**
34 * Value that stores {@link BuildInfoCollection}s generated by {@link BuildInfoFactory} instances.
35 * These collections are used during analysis (see {@code CachingAnalysisEnvironment}).
36 */
shahan6aff2d42018-03-13 14:29:12 -070037@AutoCodec
cparsonse2d200f2018-03-06 16:15:11 -080038public class BuildInfoCollectionValue extends BasicActionLookupValue {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010039 private final BuildInfoCollection collection;
40
tomlu9e91f202018-06-18 16:16:36 -070041 BuildInfoCollectionValue(BuildInfoCollection collection, GeneratingActions generatingActions) {
42 super(generatingActions);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010043 this.collection = collection;
44 }
45
shahan6aff2d42018-03-13 14:29:12 -070046 @AutoCodec.Instantiator
47 @AutoCodec.VisibleForSerialization
48 BuildInfoCollectionValue(
tomlu9e91f202018-06-18 16:16:36 -070049 ImmutableList<ActionAnalysisMetadata> actions,
shahan6aff2d42018-03-13 14:29:12 -070050 ImmutableMap<Artifact, Integer> generatingActionIndex,
tomlu9e91f202018-06-18 16:16:36 -070051 BuildInfoCollection collection) {
52 super(actions, generatingActionIndex);
shahan6aff2d42018-03-13 14:29:12 -070053 this.collection = collection;
54 }
55
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010056 public BuildInfoCollection getCollection() {
57 return collection;
58 }
59
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060 @Override
61 public String toString() {
janakr93e3eea2017-03-30 22:09:37 +000062 return getStringHelper().add("collection", collection).toString();
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010063 }
64
janakr573807d2018-01-11 14:02:35 -080065 public static BuildInfoKeyAndConfig key(
66 BuildInfoFactory.BuildInfoKey key, BuildConfiguration config) {
janakr92a031f2018-02-01 12:28:21 -080067 return BuildInfoKeyAndConfig.create(key, ConfiguredTargetKey.keyFromConfiguration(config).key);
janakr573807d2018-01-11 14:02:35 -080068 }
69
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010070 /** Key for BuildInfoCollectionValues. */
janakr92a031f2018-02-01 12:28:21 -080071 @AutoCodec
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010072 public static class BuildInfoKeyAndConfig extends ActionLookupKey {
janakr92a031f2018-02-01 12:28:21 -080073 private static final Interner<BuildInfoKeyAndConfig> keyInterner =
74 BlazeInterners.newWeakInterner();
janakr92a031f2018-02-01 12:28:21 -080075
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010076 private final BuildInfoFactory.BuildInfoKey infoKey;
janakr667e85d2018-01-24 10:42:19 -080077 private final BuildConfigurationValue.Key configKey;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010078
janakr667e85d2018-01-24 10:42:19 -080079 private BuildInfoKeyAndConfig(
80 BuildInfoFactory.BuildInfoKey key, BuildConfigurationValue.Key configKey) {
81 this.infoKey = Preconditions.checkNotNull(key, configKey);
82 this.configKey = Preconditions.checkNotNull(configKey, key);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010083 }
84
janakr92a031f2018-02-01 12:28:21 -080085 @AutoCodec.Instantiator
86 static BuildInfoKeyAndConfig create(
87 BuildInfoFactory.BuildInfoKey infoKey, BuildConfigurationValue.Key configKey) {
88 return keyInterner.intern(new BuildInfoKeyAndConfig(infoKey, configKey));
89 }
90
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010091 @Override
janakr573807d2018-01-11 14:02:35 -080092 public SkyFunctionName functionName() {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010093 return SkyFunctions.BUILD_INFO_COLLECTION;
94 }
95
96 BuildInfoFactory.BuildInfoKey getInfoKey() {
97 return infoKey;
98 }
99
janakr667e85d2018-01-24 10:42:19 -0800100 BuildConfigurationValue.Key getConfigKey() {
101 return configKey;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100102 }
103
104 @Override
105 public Label getLabel() {
106 return null;
107 }
108
109 @Override
110 public int hashCode() {
janakr667e85d2018-01-24 10:42:19 -0800111 return Objects.hash(infoKey, configKey);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100112 }
113
114 @Override
115 public boolean equals(Object other) {
116 if (this == other) {
117 return true;
118 }
119 if (other == null) {
120 return false;
121 }
122 if (this.getClass() != other.getClass()) {
123 return false;
124 }
125 BuildInfoKeyAndConfig that = (BuildInfoKeyAndConfig) other;
janakr667e85d2018-01-24 10:42:19 -0800126 return Objects.equals(this.infoKey, that.infoKey)
127 && Objects.equals(this.configKey, that.configKey);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100128 }
129 }
130}