|
15 | 15 | package com.google.devtools.build.lib.rules.repository;
|
16 | 16 |
|
17 | 17 | import static com.google.common.base.Preconditions.checkState;
|
| 18 | +import static com.google.common.collect.ImmutableSet.toImmutableSet; |
18 | 19 |
|
19 | 20 | import com.google.common.annotations.VisibleForTesting;
|
20 | 21 | import com.google.common.base.Preconditions;
|
|
40 | 41 | import com.google.devtools.build.lib.skyframe.PackageLookupFunction;
|
41 | 42 | import com.google.devtools.build.lib.skyframe.PackageLookupValue;
|
42 | 43 | import com.google.devtools.build.lib.skyframe.PrecomputedValue;
|
| 44 | +import com.google.devtools.build.lib.skyframe.RepositoryMappingValue; |
43 | 45 | import com.google.devtools.build.lib.vfs.FileSystemUtils;
|
44 | 46 | import com.google.devtools.build.lib.vfs.Path;
|
45 | 47 | import com.google.devtools.build.lib.vfs.PathFragment;
|
|
50 | 52 | import com.google.devtools.build.skyframe.SkyFunctionException;
|
51 | 53 | import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
|
52 | 54 | import com.google.devtools.build.skyframe.SkyKey;
|
| 55 | +import com.google.devtools.build.skyframe.SkyframeLookupResult; |
53 | 56 | import java.io.IOException;
|
54 | 57 | import java.util.Collection;
|
55 | 58 | import java.util.LinkedHashMap;
|
@@ -205,15 +208,49 @@ private static ImmutableSet<String> getEnviron(Rule rule) {
|
205 | 208 | public boolean verifyMarkerData(Rule rule, Map<String, String> markerData, Environment env)
|
206 | 209 | throws InterruptedException {
|
207 | 210 | return verifyEnvironMarkerData(markerData, env, getEnviron(rule))
|
208 |
| - && verifyMarkerDataForFiles(rule, markerData, env) |
209 |
| - && verifySemanticsMarkerData(markerData, env); |
| 211 | + && verifySemanticsMarkerData(markerData, env) |
| 212 | + && verifyRepoMappingMarkerData(markerData, env) |
| 213 | + && verifyMarkerDataForFiles(rule, markerData, env); |
210 | 214 | }
|
211 | 215 |
|
212 | 216 | protected boolean verifySemanticsMarkerData(Map<String, String> markerData, Environment env)
|
213 | 217 | throws InterruptedException {
|
214 | 218 | return true;
|
215 | 219 | }
|
216 | 220 |
|
| 221 | + private static boolean verifyRepoMappingMarkerData( |
| 222 | + Map<String, String> markerData, Environment env) throws InterruptedException { |
| 223 | + ImmutableSet<SkyKey> skyKeys = |
| 224 | + markerData.keySet().stream() |
| 225 | + .filter(k -> k.startsWith("REPO_MAPPING:")) |
| 226 | + // grab the part after the 'REPO_MAPPING:' and before the comma |
| 227 | + .map(k -> k.substring("REPO_MAPPING:".length(), k.indexOf(','))) |
| 228 | + .map(k -> RepositoryMappingValue.key(RepositoryName.createUnvalidated(k))) |
| 229 | + .collect(toImmutableSet()); |
| 230 | + SkyframeLookupResult result = env.getValuesAndExceptions(skyKeys); |
| 231 | + if (env.valuesMissing()) { |
| 232 | + return false; |
| 233 | + } |
| 234 | + for (Map.Entry<String, String> entry : markerData.entrySet()) { |
| 235 | + if (!entry.getKey().startsWith("REPO_MAPPING:")) { |
| 236 | + continue; |
| 237 | + } |
| 238 | + int commaIndex = entry.getKey().indexOf(','); |
| 239 | + RepositoryName fromRepo = |
| 240 | + RepositoryName.createUnvalidated( |
| 241 | + entry.getKey().substring("REPO_MAPPING:".length(), commaIndex)); |
| 242 | + String apparentRepoName = entry.getKey().substring(commaIndex + 1); |
| 243 | + RepositoryMappingValue repoMappingValue = |
| 244 | + (RepositoryMappingValue) result.get(RepositoryMappingValue.key(fromRepo)); |
| 245 | + if (repoMappingValue == RepositoryMappingValue.NOT_FOUND_VALUE |
| 246 | + || !RepositoryName.createUnvalidated(entry.getValue()) |
| 247 | + .equals(repoMappingValue.getRepositoryMapping().get(apparentRepoName))) { |
| 248 | + return false; |
| 249 | + } |
| 250 | + } |
| 251 | + return true; |
| 252 | + } |
| 253 | + |
217 | 254 | private static boolean verifyLabelMarkerData(Rule rule, String key, String value, Environment env)
|
218 | 255 | throws InterruptedException {
|
219 | 256 | Preconditions.checkArgument(key.startsWith("FILE:"));
|
|
0 commit comments