blob: 4b71f8121ab39c7aa0c73a187b18b4bb587d3a5a [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2015 The Bazel Authors. All rights reserved.
Ulf Adams89179252015-04-23 18:48:39 +00002//
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.analysis;
15
Dmitry Lomove851fe22017-02-14 23:11:23 +000016import com.google.common.collect.ImmutableList;
Ulf Adams89179252015-04-23 18:48:39 +000017import com.google.common.testing.EqualsTester;
janakr93e3eea2017-03-30 22:09:37 +000018import com.google.devtools.build.lib.actions.ActionLookupValue;
Ulf Adams89179252015-04-23 18:48:39 +000019import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
Florian Weikertcca703a2015-12-07 09:56:38 +000020import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
Luis Fernando Pino Duquee82713d2016-04-26 16:22:38 +000021import com.google.devtools.build.lib.analysis.util.TestAspects;
Dmitry Lomov8ff06452015-10-21 19:16:30 +000022import com.google.devtools.build.lib.analysis.util.TestAspects.AttributeAspect;
23import com.google.devtools.build.lib.analysis.util.TestAspects.ExtraAttributeAspect;
Lukacs Berki6e91eb92015-09-21 09:12:37 +000024import com.google.devtools.build.lib.cmdline.Label;
Dmitry Lomov15756522016-12-16 16:52:37 +000025import com.google.devtools.build.lib.packages.AspectDescriptor;
Marian Lobur702cad72015-09-02 09:53:58 +000026import com.google.devtools.build.lib.packages.AspectParameters;
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000027import com.google.devtools.build.lib.packages.NativeAspectClass;
Ulf Adams89179252015-04-23 18:48:39 +000028import com.google.devtools.build.lib.skyframe.AspectValue;
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000029import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey;
30import com.google.devtools.build.skyframe.SkyKey;
Ulf Adams89179252015-04-23 18:48:39 +000031import org.junit.Test;
32import org.junit.runner.RunWith;
33import org.junit.runners.JUnit4;
34
35/**
36 * Tests for {@link com.google.devtools.build.lib.skyframe.AspectValue}.
37 */
38@RunWith(JUnit4.class)
Florian Weikertcca703a2015-12-07 09:56:38 +000039public class AspectValueTest extends AnalysisTestCase {
Ulf Adams89179252015-04-23 18:48:39 +000040
41 @Test
Michael Staib04f6f242016-03-01 15:40:29 +000042 public void keyEquality() throws Exception {
Ulf Adams89179252015-04-23 18:48:39 +000043 update();
44 BuildConfiguration c1 = getTargetConfiguration();
45 BuildConfiguration c2 = getHostConfiguration();
46 Label l1 = Label.parseAbsolute("//a:l1");
47 Label l1b = Label.parseAbsolute("//a:l1");
48 Label l2 = Label.parseAbsolute("//a:l2");
Marian Lobur702cad72015-09-02 09:53:58 +000049 AspectParameters i1 = new AspectParameters.Builder()
50 .addAttribute("foo", "bar")
51 .build();
Michael Staib04f6f242016-03-01 15:40:29 +000052 AspectParameters i1b = new AspectParameters.Builder()
53 .addAttribute("foo", "bar")
54 .build();
Marian Lobur702cad72015-09-02 09:53:58 +000055 AspectParameters i2 = new AspectParameters.Builder()
56 .addAttribute("foo", "baz")
57 .build();
Luis Fernando Pino Duquee82713d2016-04-26 16:22:38 +000058 AttributeAspect a1 = TestAspects.ATTRIBUTE_ASPECT;
59 AttributeAspect a1b = TestAspects.ATTRIBUTE_ASPECT;
60 ExtraAttributeAspect a2 = TestAspects.EXTRA_ATTRIBUTE_ASPECT;
Michael Staib04f6f242016-03-01 15:40:29 +000061
62 // label: //a:l1 or //a:l2
63 // aspectConfiguration: target or host
64 // baseConfiguration: target or host
65 // aspect: Attribute or ExtraAttribute
66 // parameters: bar or baz
Ulf Adams89179252015-04-23 18:48:39 +000067
68 new EqualsTester()
Michael Staib04f6f242016-03-01 15:40:29 +000069 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000070 createKey(l1, c1, a1, i1, c1),
71 createKey(l1, c1, a1, i1b, c1),
72 createKey(l1, c1, a1b, i1, c1),
73 createKey(l1, c1, a1b, i1b, c1),
74 createKey(l1b, c1, a1, i1, c1),
75 createKey(l1b, c1, a1, i1b, c1),
76 createKey(l1b, c1, a1b, i1, c1),
77 createKey(l1b, c1, a1b, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +000078 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000079 createKey(l1, c1, a1, i2, c1),
80 createKey(l1, c1, a1b, i2, c1),
81 createKey(l1b, c1, a1, i2, c1),
82 createKey(l1b, c1, a1b, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +000083 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000084 createKey(l1, c1, a2, i1, c1),
85 createKey(l1, c1, a2, i1b, c1),
86 createKey(l1b, c1, a2, i1, c1),
87 createKey(l1b, c1, a2, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +000088 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000089 createKey(l1, c1, a2, i2, c1),
90 createKey(l1b, c1, a2, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +000091 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +000092 createKey(l1, c2, a1, i1, c1),
93 createKey(l1, c2, a1, i1b, c1),
94 createKey(l1, c2, a1b, i1, c1),
95 createKey(l1, c2, a1b, i1b, c1),
96 createKey(l1b, c2, a1, i1, c1),
97 createKey(l1b, c2, a1, i1b, c1),
98 createKey(l1b, c2, a1b, i1, c1),
99 createKey(l1b, c2, a1b, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000100 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000101 createKey(l1, c2, a1, i2, c1),
102 createKey(l1, c2, a1b, i2, c1),
103 createKey(l1b, c2, a1, i2, c1),
104 createKey(l1b, c2, a1b, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000105 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000106 createKey(l1, c2, a2, i1, c1),
107 createKey(l1, c2, a2, i1b, c1),
108 createKey(l1b, c2, a2, i1, c1),
109 createKey(l1b, c2, a2, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000110 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000111 createKey(l1, c2, a2, i2, c1),
112 createKey(l1b, c2, a2, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000113 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000114 createKey(l1, c1, a1, i1, c2),
115 createKey(l1, c1, a1, i1b, c2),
116 createKey(l1, c1, a1b, i1, c2),
117 createKey(l1, c1, a1b, i1b, c2),
118 createKey(l1b, c1, a1, i1, c2),
119 createKey(l1b, c1, a1, i1b, c2),
120 createKey(l1b, c1, a1b, i1, c2),
121 createKey(l1b, c1, a1b, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000122 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000123 createKey(l1, c1, a1, i2, c2),
124 createKey(l1, c1, a1b, i2, c2),
125 createKey(l1b, c1, a1, i2, c2),
126 createKey(l1b, c1, a1b, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000127 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000128 createKey(l1, c1, a2, i1, c2),
129 createKey(l1, c1, a2, i1b, c2),
130 createKey(l1b, c1, a2, i1, c2),
131 createKey(l1b, c1, a2, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000132 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000133 createKey(l1, c1, a2, i2, c2),
134 createKey(l1b, c1, a2, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000135 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000136 createKey(l1, c2, a1, i1, c2),
137 createKey(l1, c2, a1, i1b, c2),
138 createKey(l1, c2, a1b, i1, c2),
139 createKey(l1, c2, a1b, i1b, c2),
140 createKey(l1b, c2, a1, i1, c2),
141 createKey(l1b, c2, a1, i1b, c2),
142 createKey(l1b, c2, a1b, i1, c2),
143 createKey(l1b, c2, a1b, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000144 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000145 createKey(l1, c2, a1, i2, c2),
146 createKey(l1, c2, a1b, i2, c2),
147 createKey(l1b, c2, a1, i2, c2),
148 createKey(l1b, c2, a1b, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000149 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000150 createKey(l1, c2, a2, i1, c2),
151 createKey(l1, c2, a2, i1b, c2),
152 createKey(l1b, c2, a2, i1, c2),
153 createKey(l1b, c2, a2, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000154 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000155 createKey(l1, c2, a2, i2, c2),
156 createKey(l1b, c2, a2, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000157 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000158 createKey(l2, c1, a1, i1, c1),
159 createKey(l2, c1, a1, i1b, c1),
160 createKey(l2, c1, a1b, i1, c1),
161 createKey(l2, c1, a1b, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000162 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000163 createKey(l2, c1, a1, i2, c1),
164 createKey(l2, c1, a1b, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000165 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000166 createKey(l2, c1, a2, i1, c1),
167 createKey(l2, c1, a2, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000168 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000169 createKey(l2, c1, a2, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000170 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000171 createKey(l2, c2, a1, i1, c1),
172 createKey(l2, c2, a1, i1b, c1),
173 createKey(l2, c2, a1b, i1, c1),
174 createKey(l2, c2, a1b, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000175 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000176 createKey(l2, c2, a1, i2, c1),
177 createKey(l2, c2, a1b, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000178 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000179 createKey(l2, c2, a2, i1, c1),
180 createKey(l2, c2, a2, i1b, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000181 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000182 createKey(l2, c2, a2, i2, c1))
Michael Staib04f6f242016-03-01 15:40:29 +0000183 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000184 createKey(l2, c1, a1, i1, c2),
185 createKey(l2, c1, a1, i1b, c2),
186 createKey(l2, c1, a1b, i1, c2),
187 createKey(l2, c1, a1b, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000188 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000189 createKey(l2, c1, a1, i2, c2),
190 createKey(l2, c1, a1b, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000191 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000192 createKey(l2, c1, a2, i1, c2),
193 createKey(l2, c1, a2, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000194 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000195 createKey(l2, c1, a2, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000196 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000197 createKey(l2, c2, a1, i1, c2),
198 createKey(l2, c2, a1, i1b, c2),
199 createKey(l2, c2, a1b, i1, c2),
200 createKey(l2, c2, a1b, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000201 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000202 createKey(l2, c2, a1, i2, c2),
203 createKey(l2, c2, a1b, i2, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000204 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000205 createKey(l2, c2, a2, i1, c2),
206 createKey(l2, c2, a2, i1b, c2))
Michael Staib04f6f242016-03-01 15:40:29 +0000207 .addEqualityGroup(
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000208 createKey(l2, c2, a2, i2, c2))
209 .addEqualityGroup(
210 createDerivedKey(l1, c1, a1, i1, c1, a2, i2, c2),
211 createDerivedKey(l1, c1, a1, i1b, c1, a2, i2, c2)
212 )
213 .addEqualityGroup(
214 createDerivedKey(l1, c1, a2, i1, c1, a1, i2, c2),
215 createDerivedKey(l1, c1, a2, i1b, c1, a1, i2, c2)
216 )
Ulf Adams89179252015-04-23 18:48:39 +0000217 .testEquals();
218 }
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000219
220 private static SkyKey createKey(
221 Label label, BuildConfiguration baseConfiguration, NativeAspectClass aspectClass,
222 AspectParameters parameters, BuildConfiguration aspectConfiguration) {
223 return ActionLookupValue.key(AspectValue.createAspectKey(
224 label, baseConfiguration, new AspectDescriptor(aspectClass, parameters),
225 aspectConfiguration
226 ));
227 }
228
229 private static SkyKey createDerivedKey(
230 Label label, BuildConfiguration baseConfiguration,
231 NativeAspectClass aspectClass1, AspectParameters parameters1,
232 BuildConfiguration aspectConfiguration1,
233 NativeAspectClass aspectClass2, AspectParameters parameters2,
234 BuildConfiguration aspectConfiguration2) {
235 AspectKey baseKey = AspectValue.createAspectKey(label, baseConfiguration,
236 new AspectDescriptor(aspectClass1, parameters1), aspectConfiguration1);
237 return ActionLookupValue.key(AspectValue.createAspectKey(
Dmitry Lomove851fe22017-02-14 23:11:23 +0000238 label, baseConfiguration,
239 ImmutableList.of(baseKey), new AspectDescriptor(aspectClass2, parameters2),
Dmitry Lomovca9bfa42016-11-15 13:22:36 +0000240 aspectConfiguration2
241 ));
242 }
243
Ulf Adams89179252015-04-23 18:48:39 +0000244}