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 | |
tomlu | a155b53 | 2017-11-08 20:12:47 +0100 | [diff] [blame] | 16 | import com.google.common.base.Preconditions; |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableList; |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Interner; |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 20 | import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.Actions.GeneratingActions; |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 22 | import com.google.devtools.build.lib.actions.Artifact; |
cparsons | e2d200f | 2018-03-06 16:15:11 -0800 | [diff] [blame] | 23 | import com.google.devtools.build.lib.actions.BasicActionLookupValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoCollection; |
| 25 | import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory; |
| 26 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 27 | import com.google.devtools.build.lib.cmdline.Label; |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 28 | import com.google.devtools.build.lib.concurrent.BlazeInterners; |
janakr | 92a031f | 2018-02-01 12:28:21 -0800 | [diff] [blame] | 29 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | import com.google.devtools.build.skyframe.SkyFunctionName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | import 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 | */ |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 37 | @AutoCodec |
cparsons | e2d200f | 2018-03-06 16:15:11 -0800 | [diff] [blame] | 38 | public class BuildInfoCollectionValue extends BasicActionLookupValue { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | private final BuildInfoCollection collection; |
| 40 | |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 41 | BuildInfoCollectionValue(BuildInfoCollection collection, GeneratingActions generatingActions) { |
| 42 | super(generatingActions); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | this.collection = collection; |
| 44 | } |
| 45 | |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 46 | @AutoCodec.Instantiator |
| 47 | @AutoCodec.VisibleForSerialization |
| 48 | BuildInfoCollectionValue( |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 49 | ImmutableList<ActionAnalysisMetadata> actions, |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 50 | ImmutableMap<Artifact, Integer> generatingActionIndex, |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 51 | BuildInfoCollection collection) { |
| 52 | super(actions, generatingActionIndex); |
shahan | 6aff2d4 | 2018-03-13 14:29:12 -0700 | [diff] [blame] | 53 | this.collection = collection; |
| 54 | } |
| 55 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 56 | public BuildInfoCollection getCollection() { |
| 57 | return collection; |
| 58 | } |
| 59 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 60 | @Override |
| 61 | public String toString() { |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 62 | return getStringHelper().add("collection", collection).toString(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | } |
| 64 | |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 65 | public static BuildInfoKeyAndConfig key( |
| 66 | BuildInfoFactory.BuildInfoKey key, BuildConfiguration config) { |
janakr | 92a031f | 2018-02-01 12:28:21 -0800 | [diff] [blame] | 67 | return BuildInfoKeyAndConfig.create(key, ConfiguredTargetKey.keyFromConfiguration(config).key); |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 70 | /** Key for BuildInfoCollectionValues. */ |
janakr | 92a031f | 2018-02-01 12:28:21 -0800 | [diff] [blame] | 71 | @AutoCodec |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 72 | public static class BuildInfoKeyAndConfig extends ActionLookupKey { |
janakr | 92a031f | 2018-02-01 12:28:21 -0800 | [diff] [blame] | 73 | private static final Interner<BuildInfoKeyAndConfig> keyInterner = |
| 74 | BlazeInterners.newWeakInterner(); |
janakr | 92a031f | 2018-02-01 12:28:21 -0800 | [diff] [blame] | 75 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 76 | private final BuildInfoFactory.BuildInfoKey infoKey; |
janakr | 667e85d | 2018-01-24 10:42:19 -0800 | [diff] [blame] | 77 | private final BuildConfigurationValue.Key configKey; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 78 | |
janakr | 667e85d | 2018-01-24 10:42:19 -0800 | [diff] [blame] | 79 | 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 83 | } |
| 84 | |
janakr | 92a031f | 2018-02-01 12:28:21 -0800 | [diff] [blame] | 85 | @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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 91 | @Override |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 92 | public SkyFunctionName functionName() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 93 | return SkyFunctions.BUILD_INFO_COLLECTION; |
| 94 | } |
| 95 | |
| 96 | BuildInfoFactory.BuildInfoKey getInfoKey() { |
| 97 | return infoKey; |
| 98 | } |
| 99 | |
janakr | 667e85d | 2018-01-24 10:42:19 -0800 | [diff] [blame] | 100 | BuildConfigurationValue.Key getConfigKey() { |
| 101 | return configKey; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Label getLabel() { |
| 106 | return null; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public int hashCode() { |
janakr | 667e85d | 2018-01-24 10:42:19 -0800 | [diff] [blame] | 111 | return Objects.hash(infoKey, configKey); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 112 | } |
| 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; |
janakr | 667e85d | 2018-01-24 10:42:19 -0800 | [diff] [blame] | 126 | return Objects.equals(this.infoKey, that.infoKey) |
| 127 | && Objects.equals(this.configKey, that.configKey); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |