Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize map-like settings in CoreOptions #18306

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,20 @@ public LinkedHashMap<String, String> getNormalizedCommandLineBuildVariables() {
return flagValueByName;
}

// Normalizes list of map entries by keeping only the last entry for each key.
private static List<Map.Entry<String, String>> normalizeEntries(
List<Map.Entry<String, String>> entries) {
LinkedHashMap<String, String> normalizedEntries = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : entries) {
normalizedEntries.put(entry.getKey(), entry.getValue());
}
if (normalizedEntries.size() == entries.size()) {
return entries;
}
return normalizedEntries.entrySet().stream().map(SimpleEntry::new)
.collect(toImmutableList());
}

/// Normalizes --features flags by sorting the values and having disables win over enables.
private static List<String> getNormalizedFeatures(List<String> features) {
// Parse out the features into a Map<String, boolean>, where the boolean represents whether
Expand Down Expand Up @@ -1104,6 +1118,11 @@ public CoreOptions getNormalized() {
// Normalize features.
result.defaultFeatures = getNormalizedFeatures(defaultFeatures);

result.actionEnvironment = normalizeEntries(actionEnvironment);
result.hostActionEnvironment = normalizeEntries(hostActionEnvironment);
result.testEnvironment = normalizeEntries(testEnvironment);
result.commandLineFlagAliases = normalizeEntries(commandLineFlagAliases);

return result;
}
}