use of com.facebook.buck.config.CellConfig 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();
}
use of com.facebook.buck.config.CellConfig in project buck by facebook.
the class CellProvider method createForLocalBuild.
/**
* Create a cell provider at a given root.
*/
public static CellProvider createForLocalBuild(ProjectFilesystem rootFilesystem, Watchman watchman, BuckConfig rootConfig, CellConfig rootCellConfigOverrides, KnownBuildRuleTypesFactory knownBuildRuleTypesFactory) throws IOException {
DefaultCellPathResolver rootCellCellPathResolver = new DefaultCellPathResolver(rootFilesystem.getRootPath(), rootConfig.getConfig());
ImmutableMap<RelativeCellName, Path> transitiveCellPathMapping = rootCellCellPathResolver.getTransitivePathMapping();
ImmutableMap<Path, RawConfig> pathToConfigOverrides;
try {
pathToConfigOverrides = rootCellConfigOverrides.getOverridesByPath(transitiveCellPathMapping);
} catch (CellConfig.MalformedOverridesException e) {
throw new HumanReadableException(e.getMessage());
}
ImmutableSet<Path> allRoots = ImmutableSet.copyOf(transitiveCellPathMapping.values());
return new CellProvider(cellProvider -> new CacheLoader<Path, Cell>() {
@Override
public Cell load(Path cellPath) throws IOException, InterruptedException {
Path normalizedCellPath = cellPath.toRealPath().normalize();
Preconditions.checkState(allRoots.contains(normalizedCellPath), "Cell %s outside of transitive closure of root cell (%s).", normalizedCellPath, allRoots);
RawConfig configOverrides = Optional.ofNullable(pathToConfigOverrides.get(normalizedCellPath)).orElse(RawConfig.of(ImmutableMap.of()));
Config config = Configs.createDefaultConfig(normalizedCellPath, configOverrides);
DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(normalizedCellPath, config);
cellPathResolver.getCellPaths().forEach((name, path) -> {
Path pathInRootResolver = rootCellCellPathResolver.getCellPaths().get(name);
if (pathInRootResolver == null) {
throw new HumanReadableException("In the config of %s: %s.%s must exist in the root cell's cell mappings.", cellPath.toString(), DefaultCellPathResolver.REPOSITORIES_SECTION, name);
} else if (!pathInRootResolver.equals(path)) {
throw new HumanReadableException("In the config of %s: %s.%s must point to the same directory as the root " + "cell's cell mapping: (root) %s != (current) %s", cellPath.toString(), DefaultCellPathResolver.REPOSITORIES_SECTION, name, pathInRootResolver, path);
}
});
ProjectFilesystem cellFilesystem = new ProjectFilesystem(normalizedCellPath, config);
BuckConfig buckConfig = new BuckConfig(config, cellFilesystem, rootConfig.getArchitecture(), rootConfig.getPlatform(), rootConfig.getEnvironment(), cellPathResolver);
return new Cell(cellPathResolver.getKnownRoots(), cellFilesystem, watchman, buckConfig, knownBuildRuleTypesFactory, cellProvider);
}
}, cellProvider -> {
try {
return new Cell(rootCellCellPathResolver.getKnownRoots(), rootFilesystem, watchman, rootConfig, knownBuildRuleTypesFactory, cellProvider);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while loading root cell", e);
} catch (IOException e) {
throw new HumanReadableException("Failed to load root cell", e);
}
});
}
use of com.facebook.buck.config.CellConfig in project buck by facebook.
the class TestCellBuilder method build.
public Cell build() throws IOException, InterruptedException {
ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
BuckConfig config = buckConfig == null ? FakeBuckConfig.builder().setFilesystem(filesystem).build() : buckConfig;
KnownBuildRuleTypesFactory typesFactory = new KnownBuildRuleTypesFactory(executor, androidDirectoryResolver);
if (parserFactory == null) {
return CellProvider.createForLocalBuild(filesystem, watchman, config, cellConfig, typesFactory).getCellByPath(filesystem.getRootPath());
}
// The constructor for `Cell` is private, and it's in such a central location I don't really
// want to make it public. Brace yourselves.
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Cell.class);
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
if ("createBuildFileParserFactory".equals(method.getName())) {
return parserFactory;
}
return proxy.invokeSuper(obj, args);
});
return (Cell) enhancer.create();
}
Aggregations