Search in sources :

Example 1 with CellConfig

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();
}
Also used : RelativeCellName(com.facebook.buck.rules.RelativeCellName) HumanReadableException(com.facebook.buck.util.HumanReadableException) CellConfig(com.facebook.buck.config.CellConfig) Map(java.util.Map)

Example 2 with CellConfig

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);
        }
    });
}
Also used : Path(java.nio.file.Path) LoadingCache(com.google.common.cache.LoadingCache) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Config(com.facebook.buck.config.Config) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) Configs(com.facebook.buck.config.Configs) HumanReadableException(com.facebook.buck.util.HumanReadableException) Watchman(com.facebook.buck.io.Watchman) Function(java.util.function.Function) RawConfig(com.facebook.buck.config.RawConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) CacheBuilder(com.google.common.cache.CacheBuilder) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) Config(com.facebook.buck.config.Config) RawConfig(com.facebook.buck.config.RawConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) IOException(java.io.IOException) RawConfig(com.facebook.buck.config.RawConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) HumanReadableException(com.facebook.buck.util.HumanReadableException) CellConfig(com.facebook.buck.config.CellConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 3 with CellConfig

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();
}
Also used : MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) IOException(java.io.IOException) ProjectBuildFileParserFactory(com.facebook.buck.json.ProjectBuildFileParserFactory) Watchman(com.facebook.buck.io.Watchman) NULL_WATCHMAN(com.facebook.buck.io.Watchman.NULL_WATCHMAN) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) TestConsole(com.facebook.buck.testutil.TestConsole) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) Enhancer(net.sf.cglib.proxy.Enhancer) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Nullable(javax.annotation.Nullable) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Enhancer(net.sf.cglib.proxy.Enhancer) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole)

Aggregations

CellConfig (com.facebook.buck.config.CellConfig)3 BuckConfig (com.facebook.buck.cli.BuckConfig)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 Watchman (com.facebook.buck.io.Watchman)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 IOException (java.io.IOException)2 Nullable (javax.annotation.Nullable)2 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 Config (com.facebook.buck.config.Config)1 Configs (com.facebook.buck.config.Configs)1 RawConfig (com.facebook.buck.config.RawConfig)1 NULL_WATCHMAN (com.facebook.buck.io.Watchman.NULL_WATCHMAN)1 ProjectBuildFileParserFactory (com.facebook.buck.json.ProjectBuildFileParserFactory)1 RelativeCellName (com.facebook.buck.rules.RelativeCellName)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 TestConsole (com.facebook.buck.testutil.TestConsole)1 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)1 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)1