use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class BuildCommand method executeDistributedBuild.
private int executeDistributedBuild(final CommandRunnerParams params, ActionAndTargetGraphs graphs, final WeightedListeningExecutorService executorService) throws IOException, InterruptedException {
// Distributed builds serialize and send the unversioned target graph,
// and then deserialize and version remotely.
TargetGraphAndBuildTargets targetGraphAndBuildTargets = graphs.unversionedTargetGraph;
ProjectFilesystem filesystem = params.getCell().getFilesystem();
FileHashCache fileHashCache = params.getFileHashCache();
DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(params.getObjectMapper());
ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
DistBuildTargetGraphCodec targetGraphCodec = new DistBuildTargetGraphCodec(params.getObjectMapper(), parserTargetNodeFactory, new Function<TargetNode<?, ?>, Map<String, Object>>() {
@Nullable
@Override
public Map<String, Object> apply(TargetNode<?, ?> input) {
try {
return params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell().getCell(input.getBuildTarget()), false, /* enableProfiling */
executorService, input);
} catch (BuildFileParseException e) {
throw new RuntimeException(e);
}
}
}, targetGraphAndBuildTargets.getBuildTargets().stream().map(t -> t.getFullyQualifiedName()).collect(Collectors.toSet()));
BuildJobState jobState = computeDistributedBuildJobState(targetGraphCodec, params, targetGraphAndBuildTargets, graphs.actionGraph, executorService);
if (distributedBuildStateFile != null) {
Path stateDumpPath = Paths.get(distributedBuildStateFile);
BuildJobStateSerializer.serialize(jobState, filesystem.newFileOutputStream(stateDumpPath));
return 0;
} else {
BuckVersion buckVersion = getBuckVersion();
Preconditions.checkArgument(params.getInvocationInfo().isPresent());
try (DistBuildService service = DistBuildFactory.newDistBuildService(params);
DistBuildLogStateTracker distBuildLogStateTracker = DistBuildFactory.newDistBuildLogStateTracker(params.getInvocationInfo().get().getLogDirectoryPath(), filesystem)) {
DistBuildClientExecutor build = new DistBuildClientExecutor(jobState, service, distBuildLogStateTracker, 1000, /* millisBetweenStatusPoll */
buckVersion);
int exitCode = build.executeAndPrintFailuresToEventBus(executorService, filesystem, fileHashCache, params.getBuckEventBus());
// TODO(shivanker): Add a flag to disable building, and only fetch from the cache.
if (exitCode == 0) {
exitCode = executeLocalBuild(params, graphs.actionGraph, executorService);
}
return exitCode;
}
}
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CleanCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException {
// Ideally, we would like the implementation of this method to be as simple as:
//
// getProjectFilesystem().deleteRecursivelyIfExists(BuckConstant.BUCK_OUTPUT_DIRECTORY);
//
// However, we want to avoid blowing away directories that IntelliJ indexes, because that tends
// to make it angry. Currently, those directories are:
//
// Project.ANDROID_GEN_DIR
// BuckConstant.ANNOTATION_DIR
//
// However, Buck itself also uses BuckConstant.ANNOTATION_DIR. We need to fix things so that
// IntelliJ does its default thing to generate code from annotations, and manages/indexes those
// directories itself so we can blow away BuckConstant.ANNOTATION_DIR as part of `buck clean`.
// This will also reduce how long `buck project` takes.
//
ProjectFilesystem projectFilesystem = params.getCell().getFilesystem();
if (isCleanBuckProjectFiles()) {
// Delete directories that were created for the purpose of `buck project`.
// TODO(bolinfest): Unify these two directories under a single buck-ide directory,
// which is distinct from the buck-out directory.
projectFilesystem.deleteRecursivelyIfExists(Project.getAndroidGenPath(projectFilesystem));
projectFilesystem.deleteRecursivelyIfExists(projectFilesystem.getBuckPaths().getAnnotationDir());
} else {
// On Windows, you have to close all files that will be deleted.
// Because buck clean will delete build.log, you must close it first.
JavaUtilsLoggingBuildListener.closeLogFile();
projectFilesystem.deleteRecursivelyIfExists(projectFilesystem.getBuckPaths().getScratchDir());
projectFilesystem.deleteRecursivelyIfExists(projectFilesystem.getBuckPaths().getGenDir());
projectFilesystem.deleteRecursivelyIfExists(projectFilesystem.getBuckPaths().getTrashDir());
}
return 0;
}
use of com.facebook.buck.io.ProjectFilesystem 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.io.ProjectFilesystem in project buck by facebook.
the class SwiftCompile method makeCompileStep.
private SwiftCompileStep makeCompileStep(SourcePathResolver resolver) {
ImmutableList.Builder<String> compilerCommand = ImmutableList.builder();
compilerCommand.addAll(swiftCompiler.getCommandPrefix(resolver));
if (bridgingHeader.isPresent()) {
compilerCommand.add("-import-objc-header", resolver.getRelativePath(bridgingHeader.get()).toString());
}
final Function<FrameworkPath, Path> frameworkPathToSearchPath = CxxDescriptionEnhancer.frameworkPathToSearchPath(cxxPlatform, resolver);
compilerCommand.addAll(frameworks.stream().map(frameworkPathToSearchPath::apply).flatMap(searchPath -> ImmutableSet.of("-F", searchPath.toString()).stream()).iterator());
compilerCommand.addAll(MoreIterables.zipAndConcat(Iterables.cycle("-Xcc"), getSwiftIncludeArgs(resolver)));
compilerCommand.addAll(MoreIterables.zipAndConcat(Iterables.cycle(INCLUDE_FLAG), getDeps().stream().filter(SwiftCompile.class::isInstance).map(BuildRule::getSourcePathToOutput).map(input -> resolver.getAbsolutePath(input).toString()).collect(MoreCollectors.toImmutableSet())));
Optional<Iterable<String>> configFlags = swiftBuckConfig.getFlags();
if (configFlags.isPresent()) {
compilerCommand.addAll(configFlags.get());
}
boolean hasMainEntry = srcs.stream().map(input -> resolver.getAbsolutePath(input).getFileName().toString()).anyMatch(SwiftDescriptions.SWIFT_MAIN_FILENAME::equalsIgnoreCase);
compilerCommand.add("-c", enableObjcInterop ? "-enable-objc-interop" : "", hasMainEntry ? "" : "-parse-as-library", "-module-name", moduleName, "-emit-module", "-emit-module-path", modulePath.toString(), "-o", objectPath.toString(), "-emit-objc-header-path", headerPath.toString());
compilerCommand.addAll(compilerFlags);
for (SourcePath sourcePath : srcs) {
compilerCommand.add(resolver.getRelativePath(sourcePath).toString());
}
ProjectFilesystem projectFilesystem = getProjectFilesystem();
return new SwiftCompileStep(projectFilesystem.getRootPath(), ImmutableMap.of(), compilerCommand.build());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class DefaultFileHashCache method createOsRootDirectoriesCaches.
public static ImmutableList<? extends ProjectFileHashCache> createOsRootDirectoriesCaches() {
ImmutableList.Builder<ProjectFileHashCache> allCaches = ImmutableList.builder();
for (Path root : FileSystems.getDefault().getRootDirectories()) {
if (!root.toFile().exists()) {
// as a cacheable location.
continue;
}
ProjectFilesystem projectFilesystem = ProjectFilesystem.createNewOrThrowHumanReadableException(root);
// A cache which caches hashes of absolute paths which my be accessed by certain
// rules (e.g. /usr/bin/gcc), and only serves to prevent rehashing the same file
// multiple times in a single run.
allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem));
}
return allCaches.build();
}
Aggregations