use of com.facebook.buck.rules.RelativeCellName in project buck by facebook.
the class AbstractCellConfig method getOverridesByPath.
/**
* Translates the 'cell name'->override map into a 'Path'->override map.
* @param pathMapping a map containing paths to all of the cells we want to query.
* @return 'Path'->override map
*/
public ImmutableMap<Path, RawConfig> getOverridesByPath(ImmutableMap<RelativeCellName, Path> pathMapping) throws MalformedOverridesException {
ImmutableSet<RelativeCellName> relativeNamesOfCellsWithOverrides = FluentIterable.from(getValues().keySet()).filter(Predicates.not(ALL_CELLS_OVERRIDE::equals)).toSet();
ImmutableSet.Builder<Path> pathsWithOverrides = ImmutableSet.builder();
for (RelativeCellName cellWithOverride : relativeNamesOfCellsWithOverrides) {
if (!pathMapping.containsKey(cellWithOverride)) {
throw new MalformedOverridesException(String.format("Trying to override settings for unknown cell %s", cellWithOverride));
}
pathsWithOverrides.add(pathMapping.get(cellWithOverride));
}
ImmutableMultimap<Path, RelativeCellName> pathToRelativeName = Multimaps.index(pathMapping.keySet(), Functions.forMap(pathMapping));
for (Path pathWithOverrides : pathsWithOverrides.build()) {
ImmutableCollection<RelativeCellName> namesForPath = pathToRelativeName.get(pathWithOverrides);
if (namesForPath.size() > 1) {
throw new MalformedOverridesException(String.format("Configuration override is ambiguous: cell rooted at %s is reachable " + "as [%s]. Please override the config by placing a .buckconfig.local file in the " + "cell's root folder.", pathWithOverrides, Joiner.on(',').join(namesForPath)));
}
}
Map<Path, RawConfig> overridesByPath = new HashMap<>();
for (Map.Entry<RelativeCellName, Path> entry : pathMapping.entrySet()) {
RelativeCellName cellRelativeName = entry.getKey();
Path cellPath = entry.getValue();
RawConfig configFromOtherRelativeName = overridesByPath.get(cellPath);
RawConfig config = getForCell(cellRelativeName);
if (configFromOtherRelativeName != null) {
Preconditions.checkState(configFromOtherRelativeName.equals(config), "Attempting to create cell %s at %s with conflicting overrides [%s] vs [%s].", cellRelativeName, cellPath, configFromOtherRelativeName, config);
} else {
overridesByPath.put(cellPath, config);
}
}
return ImmutableMap.copyOf(overridesByPath);
}
use of com.facebook.buck.rules.RelativeCellName in project buck by facebook.
the class AbstractCommand method getConfigOverrides.
@Override
public CellConfig getConfigOverrides() {
CellConfig.Builder builder = CellConfig.builder();
// Parse command-line config overrides.
for (Map.Entry<String, String> entry : configOverrides.entrySet()) {
List<String> key = Splitter.on("//").limit(2).splitToList(entry.getKey());
RelativeCellName cellName = CellConfig.ALL_CELLS_OVERRIDE;
String configKey = key.get(0);
if (key.size() == 2) {
// path overrides for cells.
if (key.get(0).length() == 0) {
cellName = RelativeCellName.ROOT_CELL_NAME;
} else {
cellName = RelativeCellName.of(ImmutableSet.of(key.get(0)));
}
configKey = key.get(1);
}
int separatorIndex = configKey.lastIndexOf('.');
if (separatorIndex < 0 || separatorIndex == configKey.length() - 1) {
throw new HumanReadableException("Invalid config override \"%s=%s\" Expected <section>.<field>=<value>.", configKey, entry.getValue());
}
String value = entry.getValue();
// If the value is empty, un-set the config
if (value == null) {
value = "";
}
// Overrides for locations of transitive children of cells are weird as the order of overrides
// can affect the result (for example `-c a/b/c.k=v -c a/b//repositories.c=foo` causes an
// interesting problem as the a/b/c cell gets created as a side-effect of the first override,
// but the second override wants to change its identity).
// It's generally a better idea to use the .buckconfig.local mechanism when overriding
// repositories anyway, so here we simply disallow them.
String section = configKey.substring(0, separatorIndex);
if (section.equals("repositories")) {
throw new HumanReadableException("Overriding repository locations from the command line " + "is not supported. Please place a .buckconfig.local in the appropriate location and " + "use that instead.");
}
String field = configKey.substring(separatorIndex + 1);
builder.put(cellName, section, field, value);
}
if (numThreads != null) {
builder.put(CellConfig.ALL_CELLS_OVERRIDE, "build", "threads", String.valueOf(numThreads));
}
if (noCache) {
builder.put(CellConfig.ALL_CELLS_OVERRIDE, "cache", "mode", "");
}
return builder.build();
}
Aggregations