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.skyframe; |
| 15 | |
Mark Schaller | aff46bc | 2015-10-07 21:25:19 +0000 | [diff] [blame] | 16 | import static com.google.common.truth.Truth.assertThat; |
| 17 | |
tomlu | a155b53 | 2017-11-08 20:12:47 +0100 | [diff] [blame] | 18 | import com.google.common.base.Preconditions; |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Mark Schaller | 908f4c9 | 2015-10-21 18:33:25 +0000 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableMap; |
| 21 | import com.google.common.collect.ImmutableSet; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 22 | import com.google.common.collect.Interner; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.common.collect.Iterables; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 24 | import com.google.devtools.build.lib.concurrent.BlazeInterners; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 25 | import com.google.devtools.build.lib.events.Event; |
ulfjack | 52b4f68 | 2017-07-18 10:12:09 +0200 | [diff] [blame] | 26 | import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 27 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.devtools.build.lib.util.Pair; |
Mark Schaller | aff46bc | 2015-10-07 21:25:19 +0000 | [diff] [blame] | 29 | import com.google.devtools.build.skyframe.SkyFunction.Environment; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | import com.google.devtools.build.skyframe.SkyFunctionException.Transience; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | import java.util.HashMap; |
| 32 | import java.util.LinkedHashMap; |
| 33 | import java.util.LinkedHashSet; |
| 34 | import java.util.Map; |
| 35 | import java.util.Set; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 36 | import javax.annotation.Nullable; |
| 37 | |
| 38 | /** |
| 39 | * A helper class to create graphs and run skyframe tests over these graphs. |
| 40 | * |
| 41 | * <p>There are two types of values, computing values, which may not be set to a constant value, |
| 42 | * and leaf values, which must be set to a constant value and may not have any dependencies. |
| 43 | * |
| 44 | * <p>Note that the value builder looks into the test values created here to determine how to |
| 45 | * behave. However, skyframe will only re-evaluate the value and call the value builder if any of |
| 46 | * its dependencies has changed. That means in order to change the set of dependencies of a value, |
| 47 | * you need to also change one of its previous dependencies to force re-evaluation. Changing a |
| 48 | * computing value does not mark it as modified. |
| 49 | */ |
| 50 | public class GraphTester { |
| 51 | |
Michajlo Matijkiw | 6630426 | 2015-10-15 20:54:33 +0000 | [diff] [blame] | 52 | public static final SkyFunctionName NODE_TYPE = SkyFunctionName.FOR_TESTING; |
janakr | bdba40f | 2018-06-04 06:50:17 -0700 | [diff] [blame] | 53 | private final Map<SkyFunctionName, SkyFunction> functionMap = new HashMap<>(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | |
| 55 | private final Map<SkyKey, TestFunction> values = new HashMap<>(); |
| 56 | private final Set<SkyKey> modifiedValues = new LinkedHashSet<>(); |
| 57 | |
janakr | bdba40f | 2018-06-04 06:50:17 -0700 | [diff] [blame] | 58 | public GraphTester() { |
| 59 | functionMap.put(NODE_TYPE, new DelegatingFunction()); |
janakr | e54491e | 2018-07-11 16:29:13 -0700 | [diff] [blame] | 60 | functionMap.put(FOR_TESTING_NONHERMETIC, new DelegatingFunction()); |
janakr | bdba40f | 2018-06-04 06:50:17 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | public TestFunction getOrCreate(String name) { |
| 64 | return getOrCreate(skyKey(name)); |
| 65 | } |
| 66 | |
| 67 | public TestFunction getOrCreate(SkyKey key) { |
| 68 | return getOrCreate(key, false); |
| 69 | } |
| 70 | |
| 71 | public TestFunction getOrCreate(SkyKey key, boolean markAsModified) { |
| 72 | TestFunction result = values.get(key); |
| 73 | if (result == null) { |
| 74 | result = new TestFunction(); |
| 75 | values.put(key, result); |
| 76 | } else if (markAsModified) { |
| 77 | modifiedValues.add(key); |
| 78 | } |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | public TestFunction set(String key, SkyValue value) { |
| 83 | return set(skyKey(key), value); |
| 84 | } |
| 85 | |
| 86 | public TestFunction set(SkyKey key, SkyValue value) { |
| 87 | return getOrCreate(key, true).setConstantValue(value); |
| 88 | } |
| 89 | |
Mark Schaller | 908f4c9 | 2015-10-21 18:33:25 +0000 | [diff] [blame] | 90 | public ImmutableSet<SkyKey> getModifiedValues() { |
| 91 | return ImmutableSet.copyOf(modifiedValues); |
| 92 | } |
| 93 | |
| 94 | public void clearModifiedValues() { |
| 95 | modifiedValues.clear(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | public SkyFunction getFunction() { |
| 99 | return new SkyFunction() { |
| 100 | @Override |
| 101 | public SkyValue compute(SkyKey key, Environment env) |
| 102 | throws SkyFunctionException, InterruptedException { |
| 103 | TestFunction builder = values.get(key); |
| 104 | Preconditions.checkState(builder != null, "No TestFunction for " + key); |
| 105 | if (builder.builder != null) { |
| 106 | return builder.builder.compute(key, env); |
| 107 | } |
| 108 | if (builder.warning != null) { |
| 109 | env.getListener().handle(Event.warn(builder.warning)); |
| 110 | } |
| 111 | if (builder.progress != null) { |
| 112 | env.getListener().handle(Event.progress(builder.progress)); |
| 113 | } |
ulfjack | 52b4f68 | 2017-07-18 10:12:09 +0200 | [diff] [blame] | 114 | if (builder.postable != null) { |
| 115 | env.getListener().post(builder.postable); |
| 116 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 117 | Map<SkyKey, SkyValue> deps = new LinkedHashMap<>(); |
| 118 | boolean oneMissing = false; |
| 119 | for (Pair<SkyKey, SkyValue> dep : builder.deps) { |
| 120 | SkyValue value; |
| 121 | if (dep.second == null) { |
| 122 | value = env.getValue(dep.first); |
| 123 | } else { |
| 124 | try { |
| 125 | value = env.getValueOrThrow(dep.first, SomeErrorException.class); |
| 126 | } catch (SomeErrorException e) { |
| 127 | value = dep.second; |
| 128 | } |
| 129 | } |
| 130 | if (value == null) { |
| 131 | oneMissing = true; |
| 132 | } else { |
| 133 | deps.put(dep.first, value); |
| 134 | } |
Janak Ramakrishnan | b2b7b35 | 2016-03-04 20:54:29 +0000 | [diff] [blame] | 135 | Preconditions.checkState( |
| 136 | oneMissing == env.valuesMissing(), "%s %s %s", dep, value, env.valuesMissing()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 137 | } |
| 138 | if (env.valuesMissing()) { |
| 139 | return null; |
| 140 | } |
| 141 | |
| 142 | if (builder.hasTransientError) { |
| 143 | throw new GenericFunctionException(new SomeErrorException(key.toString()), |
| 144 | Transience.TRANSIENT); |
| 145 | } |
| 146 | if (builder.hasError) { |
| 147 | throw new GenericFunctionException(new SomeErrorException(key.toString()), |
| 148 | Transience.PERSISTENT); |
| 149 | } |
| 150 | |
| 151 | if (builder.value != null) { |
| 152 | return builder.value; |
| 153 | } |
| 154 | |
| 155 | if (Thread.currentThread().isInterrupted()) { |
| 156 | throw new InterruptedException(key.toString()); |
| 157 | } |
| 158 | |
| 159 | return builder.computer.compute(deps, env); |
| 160 | } |
| 161 | |
| 162 | @Nullable |
| 163 | @Override |
| 164 | public String extractTag(SkyKey skyKey) { |
| 165 | return values.get(skyKey).tag; |
| 166 | } |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | public static SkyKey skyKey(String key) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 171 | return Key.create(key); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 172 | } |
| 173 | |
janakr | e54491e | 2018-07-11 16:29:13 -0700 | [diff] [blame] | 174 | public static NonHermeticKey nonHermeticKey(String key) { |
| 175 | return NonHermeticKey.create(key); |
| 176 | } |
| 177 | |
mschaller | cfe25a6 | 2017-08-05 01:40:57 +0200 | [diff] [blame] | 178 | /** A value in the testing graph that is constructed in the tester. */ |
| 179 | public static class TestFunction { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 180 | // TODO(bazel-team): We could use a multiset here to simulate multi-pass dependency discovery. |
| 181 | private final Set<Pair<SkyKey, SkyValue>> deps = new LinkedHashSet<>(); |
| 182 | private SkyValue value; |
| 183 | private ValueComputer computer; |
| 184 | private SkyFunction builder = null; |
| 185 | |
| 186 | private boolean hasTransientError; |
| 187 | private boolean hasError; |
| 188 | |
| 189 | private String warning; |
| 190 | private String progress; |
ulfjack | 52b4f68 | 2017-07-18 10:12:09 +0200 | [diff] [blame] | 191 | private Postable postable; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 192 | |
| 193 | private String tag; |
| 194 | |
| 195 | public TestFunction addDependency(String name) { |
| 196 | return addDependency(skyKey(name)); |
| 197 | } |
| 198 | |
| 199 | public TestFunction addDependency(SkyKey key) { |
| 200 | deps.add(Pair.<SkyKey, SkyValue>of(key, null)); |
| 201 | return this; |
| 202 | } |
| 203 | |
| 204 | public TestFunction removeDependency(String name) { |
| 205 | return removeDependency(skyKey(name)); |
| 206 | } |
| 207 | |
| 208 | public TestFunction removeDependency(SkyKey key) { |
| 209 | deps.remove(Pair.<SkyKey, SkyValue>of(key, null)); |
| 210 | return this; |
| 211 | } |
| 212 | |
| 213 | public TestFunction addErrorDependency(String name, SkyValue altValue) { |
| 214 | return addErrorDependency(skyKey(name), altValue); |
| 215 | } |
| 216 | |
| 217 | public TestFunction addErrorDependency(SkyKey key, SkyValue altValue) { |
| 218 | deps.add(Pair.of(key, altValue)); |
| 219 | return this; |
| 220 | } |
| 221 | |
| 222 | public TestFunction setConstantValue(SkyValue value) { |
| 223 | Preconditions.checkState(this.computer == null); |
| 224 | this.value = value; |
| 225 | return this; |
| 226 | } |
| 227 | |
mschaller | cfe25a6 | 2017-08-05 01:40:57 +0200 | [diff] [blame] | 228 | public TestFunction unsetConstantValue() { |
| 229 | this.value = null; |
| 230 | return this; |
| 231 | } |
| 232 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 233 | public TestFunction setComputedValue(ValueComputer computer) { |
| 234 | Preconditions.checkState(this.value == null); |
| 235 | this.computer = computer; |
| 236 | return this; |
| 237 | } |
| 238 | |
Mark Schaller | 342b0b8 | 2016-03-07 17:36:37 +0000 | [diff] [blame] | 239 | public TestFunction unsetComputedValue() { |
| 240 | this.computer = null; |
| 241 | return this; |
| 242 | } |
| 243 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 244 | public TestFunction setBuilder(SkyFunction builder) { |
| 245 | Preconditions.checkState(this.value == null); |
| 246 | Preconditions.checkState(this.computer == null); |
| 247 | Preconditions.checkState(deps.isEmpty()); |
| 248 | Preconditions.checkState(!hasTransientError); |
| 249 | Preconditions.checkState(!hasError); |
| 250 | Preconditions.checkState(warning == null); |
| 251 | Preconditions.checkState(progress == null); |
| 252 | this.builder = builder; |
| 253 | return this; |
| 254 | } |
| 255 | |
shreyax | a3c95c5 | 2018-03-19 09:22:24 -0700 | [diff] [blame] | 256 | public TestFunction setBuilderUnconditionally(SkyFunction builder) { |
| 257 | this.builder = builder; |
| 258 | return this; |
| 259 | } |
| 260 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 261 | public TestFunction setHasTransientError(boolean hasError) { |
| 262 | this.hasTransientError = hasError; |
| 263 | return this; |
| 264 | } |
| 265 | |
| 266 | public TestFunction setHasError(boolean hasError) { |
| 267 | // TODO(bazel-team): switch to an enum for hasError. |
| 268 | this.hasError = hasError; |
| 269 | return this; |
| 270 | } |
| 271 | |
| 272 | public TestFunction setWarning(String warning) { |
| 273 | this.warning = warning; |
| 274 | return this; |
| 275 | } |
| 276 | |
| 277 | public TestFunction setProgress(String info) { |
| 278 | this.progress = info; |
| 279 | return this; |
| 280 | } |
| 281 | |
| 282 | public TestFunction setTag(String tag) { |
| 283 | this.tag = tag; |
| 284 | return this; |
| 285 | } |
| 286 | |
ulfjack | 52b4f68 | 2017-07-18 10:12:09 +0200 | [diff] [blame] | 287 | public TestFunction setPostable(Postable postable) { |
| 288 | this.postable = postable; |
| 289 | return this; |
| 290 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 291 | } |
| 292 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 293 | public static ImmutableList<SkyKey> toSkyKeys(String... names) { |
| 294 | ImmutableList.Builder<SkyKey> result = ImmutableList.builder(); |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 295 | for (String element : names) { |
| 296 | result.add(Key.create(element)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 297 | } |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 298 | return result.build(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | public static SkyKey toSkyKey(String name) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 302 | return toSkyKeys(name).get(0); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | private class DelegatingFunction implements SkyFunction { |
| 306 | @Override |
| 307 | public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, |
| 308 | InterruptedException { |
| 309 | return getFunction().compute(skyKey, env); |
| 310 | } |
| 311 | |
| 312 | @Nullable |
| 313 | @Override |
| 314 | public String extractTag(SkyKey skyKey) { |
| 315 | return getFunction().extractTag(skyKey); |
| 316 | } |
| 317 | } |
| 318 | |
Mark Schaller | 908f4c9 | 2015-10-21 18:33:25 +0000 | [diff] [blame] | 319 | public ImmutableMap<SkyFunctionName, ? extends SkyFunction> getSkyFunctionMap() { |
janakr | bdba40f | 2018-06-04 06:50:17 -0700 | [diff] [blame] | 320 | return ImmutableMap.copyOf(functionMap); |
| 321 | } |
| 322 | |
| 323 | public void putSkyFunction(SkyFunctionName functionName, SkyFunction function) { |
| 324 | functionMap.put(functionName, function); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Simple value class that stores strings. |
| 329 | */ |
| 330 | public static class StringValue implements SkyValue { |
Eric Fellheimer | 26b3d85 | 2015-11-19 02:16:24 +0000 | [diff] [blame] | 331 | protected final String value; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 332 | |
| 333 | public StringValue(String value) { |
| 334 | this.value = value; |
| 335 | } |
| 336 | |
| 337 | public String getValue() { |
| 338 | return value; |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public boolean equals(Object o) { |
| 343 | if (!(o instanceof StringValue)) { |
| 344 | return false; |
| 345 | } |
| 346 | return value.equals(((StringValue) o).value); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public int hashCode() { |
| 351 | return value.hashCode(); |
| 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public String toString() { |
| 356 | return "StringValue: " + getValue(); |
| 357 | } |
Mark Schaller | aff46bc | 2015-10-07 21:25:19 +0000 | [diff] [blame] | 358 | |
| 359 | public static StringValue of(String string) { |
| 360 | return new StringValue(string); |
| 361 | } |
| 362 | |
| 363 | public static StringValue from(SkyValue skyValue) { |
| 364 | assertThat(skyValue).isInstanceOf(StringValue.class); |
| 365 | return (StringValue) skyValue; |
| 366 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Eric Fellheimer | 26b3d85 | 2015-11-19 02:16:24 +0000 | [diff] [blame] | 369 | /** A StringValue that is also a NotComparableSkyValue. */ |
| 370 | public static class NotComparableStringValue extends StringValue |
| 371 | implements NotComparableSkyValue { |
| 372 | public NotComparableStringValue(String value) { |
| 373 | super(value); |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public boolean equals(Object o) { |
| 378 | throw new UnsupportedOperationException(value + " is incomparable - what are you doing?"); |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public int hashCode() { |
| 383 | throw new UnsupportedOperationException(value + " is incomparable - what are you doing?"); |
| 384 | } |
| 385 | } |
| 386 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 387 | /** |
| 388 | * A callback interface to provide the value computation. |
| 389 | */ |
| 390 | public interface ValueComputer { |
| 391 | /** This is called when all the declared dependencies exist. It may request new dependencies. */ |
| 392 | SkyValue compute(Map<SkyKey, SkyValue> deps, SkyFunction.Environment env) |
| 393 | throws InterruptedException; |
| 394 | } |
| 395 | |
| 396 | public static final ValueComputer COPY = new ValueComputer() { |
| 397 | @Override |
| 398 | public SkyValue compute(Map<SkyKey, SkyValue> deps, SkyFunction.Environment env) { |
| 399 | return Iterables.getOnlyElement(deps.values()); |
| 400 | } |
| 401 | }; |
| 402 | |
| 403 | public static final ValueComputer CONCATENATE = new ValueComputer() { |
| 404 | @Override |
| 405 | public SkyValue compute(Map<SkyKey, SkyValue> deps, SkyFunction.Environment env) { |
| 406 | StringBuilder result = new StringBuilder(); |
| 407 | for (SkyValue value : deps.values()) { |
| 408 | result.append(((StringValue) value).value); |
| 409 | } |
| 410 | return new StringValue(result.toString()); |
| 411 | } |
| 412 | }; |
Mark Schaller | aff46bc | 2015-10-07 21:25:19 +0000 | [diff] [blame] | 413 | |
| 414 | public static ValueComputer formatter(final SkyKey key, final String format) { |
| 415 | return new ValueComputer() { |
| 416 | @Override |
| 417 | public SkyValue compute(Map<SkyKey, SkyValue> deps, Environment env) |
| 418 | throws InterruptedException { |
| 419 | return StringValue.of(String.format(format, StringValue.from(deps.get(key)).getValue())); |
| 420 | } |
| 421 | }; |
| 422 | } |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 423 | |
| 424 | @AutoCodec.VisibleForSerialization |
| 425 | @AutoCodec |
| 426 | static class Key extends AbstractSkyKey<String> { |
| 427 | private static final Interner<Key> interner = BlazeInterners.newWeakInterner(); |
| 428 | |
janakr | e54491e | 2018-07-11 16:29:13 -0700 | [diff] [blame] | 429 | private Key(String arg) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 430 | super(arg); |
| 431 | } |
| 432 | |
janakr | e54491e | 2018-07-11 16:29:13 -0700 | [diff] [blame] | 433 | @AutoCodec.VisibleForSerialization |
| 434 | @AutoCodec.Instantiator |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 435 | static Key create(String arg) { |
| 436 | return interner.intern(new Key(arg)); |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public SkyFunctionName functionName() { |
| 441 | return SkyFunctionName.FOR_TESTING; |
| 442 | } |
| 443 | } |
janakr | e54491e | 2018-07-11 16:29:13 -0700 | [diff] [blame] | 444 | |
| 445 | @AutoCodec.VisibleForSerialization |
| 446 | @AutoCodec |
| 447 | static class NonHermeticKey extends AbstractSkyKey<String> { |
| 448 | private static final Interner<NonHermeticKey> interner = BlazeInterners.newWeakInterner(); |
| 449 | |
| 450 | private NonHermeticKey(String arg) { |
| 451 | super(arg); |
| 452 | } |
| 453 | |
| 454 | @AutoCodec.VisibleForSerialization |
| 455 | @AutoCodec.Instantiator |
| 456 | static NonHermeticKey create(String arg) { |
| 457 | return interner.intern(new NonHermeticKey(arg)); |
| 458 | } |
| 459 | |
| 460 | @Override |
| 461 | public SkyFunctionName functionName() { |
| 462 | return FOR_TESTING_NONHERMETIC; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | private static final SkyFunctionName FOR_TESTING_NONHERMETIC = |
| 467 | SkyFunctionName.createNonHermetic("FOR_TESTING_NONHERMETIC"); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 468 | } |