|
14 | 14 |
|
15 | 15 | package com.google.devtools.build.lib.runtime.commands;
|
16 | 16 |
|
| 17 | +import static com.google.common.collect.ImmutableList.toImmutableList; |
17 | 18 | import static com.google.common.truth.Truth.assertThat;
|
| 19 | +import static com.google.common.truth.Truth.assertWithMessage; |
18 | 20 |
|
| 21 | +import com.google.common.base.Predicates; |
19 | 22 | import com.google.common.collect.ImmutableList;
|
20 | 23 | import com.google.common.collect.ImmutableSet;
|
21 | 24 | import com.google.common.collect.Iterables;
|
@@ -195,23 +198,54 @@ public void showConfigIds() throws Exception {
|
195 | 198 | assertThat(fullJson.get("configuration-IDs").getAsJsonArray().size()).isEqualTo(3);
|
196 | 199 | }
|
197 | 200 |
|
| 201 | + private boolean skipNoConfig(JsonElement configHash) { |
| 202 | + try { |
| 203 | + return !new Gson() |
| 204 | + .fromJson( |
| 205 | + callConfigCommand(configHash.getAsString()).outAsLatin1(), |
| 206 | + ConfigurationForOutput.class) |
| 207 | + .mnemonic |
| 208 | + .contains("-noconfig"); |
| 209 | + } catch (Exception e) { |
| 210 | + assertWithMessage("Failed to retrieve %s: %s", configHash.getAsString(), e.getMessage()) |
| 211 | + .fail(); |
| 212 | + return false; |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Calls the config command to return all config hashes currently available. |
| 218 | + * |
| 219 | + * @param includeNoConfig if true, include the "noconfig" configuration (see {@link |
| 220 | + * com.google.devtools.build.lib.analysis.config.transitions.NoConfigTransition}. Else filter |
| 221 | + * it out. |
| 222 | + */ |
| 223 | + private ImmutableList<String> getConfigHashes(boolean includeNoConfig) throws Exception { |
| 224 | + return JsonParser.parseString(callConfigCommand().outAsLatin1()) |
| 225 | + .getAsJsonObject() |
| 226 | + .get("configuration-IDs") |
| 227 | + .getAsJsonArray() |
| 228 | + .asList() |
| 229 | + .stream() |
| 230 | + .filter(includeNoConfig ? Predicates.alwaysTrue() : this::skipNoConfig) |
| 231 | + .map(c -> c.getAsString()) |
| 232 | + .collect(toImmutableList()); |
| 233 | + } |
| 234 | + |
198 | 235 | @Test
|
199 | 236 | public void showSingleConfig() throws Exception {
|
200 | 237 | analyzeTarget();
|
201 |
| - String configHash1 = |
202 |
| - JsonParser.parseString(callConfigCommand().outAsLatin1()) |
203 |
| - .getAsJsonObject() |
204 |
| - .get("configuration-IDs") |
205 |
| - .getAsJsonArray() |
206 |
| - .get(0) |
207 |
| - .getAsString(); |
| 238 | + // Find the first non-noconfig configuration (see NoConfigTransition). noconfig is a special |
| 239 | + // configuration that strips away most of its structure, so not a good candidate for this test. |
| 240 | + String configHash = getConfigHashes(/* includeNoConfig= */ false).get(0); |
208 | 241 | ConfigurationForOutput config =
|
209 | 242 | new Gson()
|
210 |
| - .fromJson(callConfigCommand(configHash1).outAsLatin1(), ConfigurationForOutput.class); |
| 243 | + .fromJson(callConfigCommand(configHash).outAsLatin1(), ConfigurationForOutput.class); |
| 244 | + |
211 | 245 | assertThat(config).isNotNull();
|
212 | 246 | // Verify config metadata:
|
213 |
| - assertThat(config.configHash).isEqualTo(configHash1); |
214 |
| - assertThat(config.skyKey).isEqualTo(String.format("BuildConfigurationKey[%s]", configHash1)); |
| 247 | + assertThat(config.configHash).isEqualTo(configHash); |
| 248 | + assertThat(config.skyKey).isEqualTo(String.format("BuildConfigurationKey[%s]", configHash)); |
215 | 249 | // Verify the existence of a couple of expected fragments:
|
216 | 250 | assertThat(
|
217 | 251 | config.fragments.stream()
|
|
0 commit comments