use of com.facebook.buck.rules.Cell in project buck by facebook.
the class OwnersReport method generateOwnersReport.
@VisibleForTesting
static OwnersReport generateOwnersReport(Cell rootCell, TargetNode<?, ?> targetNode, Iterable<String> filePaths) {
// Process arguments assuming they are all relative file paths.
Set<Path> inputs = Sets.newHashSet();
Set<String> nonExistentInputs = Sets.newHashSet();
Set<String> nonFileInputs = Sets.newHashSet();
for (String filePath : filePaths) {
Path file = rootCell.getFilesystem().getPathForRelativePath(filePath);
if (!Files.exists(file)) {
nonExistentInputs.add(filePath);
} else if (!Files.isRegularFile(file)) {
nonFileInputs.add(filePath);
} else {
inputs.add(rootCell.getFilesystem().getPath(filePath));
}
}
// Try to find owners for each valid and existing file.
Set<Path> inputsWithNoOwners = Sets.newHashSet(inputs);
SetMultimap<TargetNode<?, ?>, Path> owners = TreeMultimap.create();
for (final Path commandInput : inputs) {
Predicate<Path> startsWith = input -> !commandInput.equals(input) && commandInput.startsWith(input);
Set<Path> ruleInputs = targetNode.getInputs();
if (ruleInputs.contains(commandInput) || FluentIterable.from(ruleInputs).anyMatch(startsWith)) {
inputsWithNoOwners.remove(commandInput);
owners.put(targetNode, commandInput);
}
}
return new OwnersReport(owners, inputsWithNoOwners, nonExistentInputs, nonFileInputs);
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class BuckQueryEnvironment method getBuildFiles.
@Override
public ImmutableSet<QueryTarget> getBuildFiles(Set<QueryTarget> targets) throws QueryException {
final ProjectFilesystem cellFilesystem = rootCell.getFilesystem();
final Path rootPath = cellFilesystem.getRootPath();
Preconditions.checkState(rootPath.isAbsolute());
ImmutableSet.Builder<QueryTarget> builder = ImmutableSet.builder();
for (QueryTarget target : targets) {
Preconditions.checkState(target instanceof QueryBuildTarget);
BuildTarget buildTarget = ((QueryBuildTarget) target).getBuildTarget();
Cell cell = rootCell.getCell(buildTarget);
if (!buildFileTrees.containsKey(cell)) {
LOG.info("Creating a new filesystem-backed build file tree for %s", cell.getRoot());
buildFileTrees.put(cell, new FilesystemBackedBuildFileTree(cell.getFilesystem(), cell.getBuildFileName()));
}
BuildFileTree buildFileTree = Preconditions.checkNotNull(buildFileTrees.get(cell));
Optional<Path> path = buildFileTree.getBasePathOfAncestorTarget(buildTarget.getBasePath());
Preconditions.checkState(path.isPresent());
Path buildFilePath = MorePaths.relativize(rootPath, cell.getFilesystem().resolve(path.get()).resolve(cell.getBuildFileName()));
Preconditions.checkState(cellFilesystem.exists(buildFilePath));
builder.add(QueryFileTarget.of(buildFilePath));
}
return builder.build();
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DistBuildFactory method createDistBuildExecutor.
public static DistBuildSlaveExecutor createDistBuildExecutor(BuildJobState jobState, CommandRunnerParams params, WeightedListeningExecutorService executorService, DistBuildService service, DistBuildMode mode, int coordinatorPort, Optional<StampedeId> stampedeId, Optional<Path> globalCacheDir) throws IOException {
DistBuildState state = DistBuildState.load(Optional.of(params.getBuckConfig()), jobState, params.getCell(), params.getKnownBuildRuleTypesFactory());
Preconditions.checkArgument(state.getCells().size() > 0);
// Create a cache factory which uses a combination of the distributed build config,
// overridden with the local buck config (i.e. the build slave).
Cell rootCell = Preconditions.checkNotNull(state.getCells().get(0));
ArtifactCacheFactory distBuildArtifactCacheFactory = params.getArtifactCacheFactory().cloneWith(rootCell.getBuckConfig());
DistBuildSlaveExecutor executor = new DistBuildSlaveExecutor(DistBuildExecutorArgs.builder().setBuckEventBus(params.getBuckEventBus()).setPlatform(params.getPlatform()).setClock(params.getClock()).setArtifactCache(distBuildArtifactCacheFactory.newInstance(true)).setState(state).setObjectMapper(params.getObjectMapper()).setRootCell(params.getCell()).setParser(params.getParser()).setExecutorService(executorService).setActionGraphCache(params.getActionGraphCache()).setCacheKeySeed(params.getBuckConfig().getKeySeed()).setConsole(params.getConsole()).setProvider(new MultiSourceContentsProvider(service, globalCacheDir)).setExecutors(params.getExecutors()).setDistBuildMode(mode).setCoordinatorPort(coordinatorPort).setStampedeId(stampedeId.orElse(new StampedeId().setId("LOCAL_FILE"))).setVersionedTargetGraphCache(params.getVersionedTargetGraphCache()).build());
return executor;
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DistBuildCellIndexer method apply.
@Override
public Integer apply(Path input) {
// Non-cell Paths are just stored in the root cell data marked as absolute paths.
Integer i = rootCell.getKnownRoots().contains(input) ? index.get(input) : ROOT_CELL_INDEX;
if (i == null) {
i = index.size();
index.put(input, i);
Cell cell = rootCell.getCellIgnoringVisibilityCheck(input);
state.put(i, dumpCell(cell));
}
return i;
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DistBuildSlaveExecutor method createStackOfDefaultFileHashCache.
private StackedFileHashCache createStackOfDefaultFileHashCache() throws IOException {
ImmutableList.Builder<ProjectFileHashCache> allCachesBuilder = ImmutableList.builder();
Cell rootCell = args.getState().getRootCell();
// 1. Add all cells (including the root cell).
for (Path cellPath : rootCell.getKnownRoots()) {
Cell cell = rootCell.getCell(cellPath);
allCachesBuilder.add(DefaultFileHashCache.createDefaultFileHashCache(cell.getFilesystem()));
}
// 2. Add the Operating System roots.
allCachesBuilder.addAll(DefaultFileHashCache.createOsRootDirectoriesCaches());
return new StackedFileHashCache(allCachesBuilder.build());
}
Aggregations