use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class GoCompile method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(output);
ImmutableList.Builder<Path> compileSrcListBuilder = ImmutableList.builder();
ImmutableList.Builder<Path> headerSrcListBuilder = ImmutableList.builder();
ImmutableList.Builder<Path> asmSrcListBuilder = ImmutableList.builder();
for (SourcePath path : srcs) {
Path srcPath = context.getSourcePathResolver().getAbsolutePath(path);
String extension = MorePaths.getFileExtension(srcPath).toLowerCase();
if (extension.equals("s")) {
asmSrcListBuilder.add(srcPath);
} else if (extension.equals("go")) {
compileSrcListBuilder.add(srcPath);
} else {
headerSrcListBuilder.add(srcPath);
}
}
ImmutableList<Path> compileSrcs = compileSrcListBuilder.build();
ImmutableList<Path> headerSrcs = headerSrcListBuilder.build();
ImmutableList<Path> asmSrcs = asmSrcListBuilder.build();
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
Optional<Path> asmHeaderPath;
if (!asmSrcs.isEmpty()) {
asmHeaderPath = Optional.of(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_hdr").resolve("go_asm.h"));
steps.add(new MkdirStep(getProjectFilesystem(), asmHeaderPath.get().getParent()));
} else {
asmHeaderPath = Optional.empty();
}
boolean allowExternalReferences = !asmSrcs.isEmpty();
if (compileSrcs.isEmpty()) {
steps.add(new TouchStep(getProjectFilesystem(), output));
} else {
steps.add(new GoCompileStep(getProjectFilesystem().getRootPath(), compiler.getEnvironment(context.getSourcePathResolver()), compiler.getCommandPrefix(context.getSourcePathResolver()), compilerFlags, packageName, compileSrcs, importPathMap, ImmutableList.of(symlinkTree.getRoot()), asmHeaderPath, allowExternalReferences, platform, output));
}
if (!asmSrcs.isEmpty()) {
Path asmIncludeDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_includes");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), asmIncludeDir));
if (!headerSrcs.isEmpty()) {
// TODO(mikekap): Allow header-map style input.
for (Path header : FluentIterable.from(headerSrcs).append(asmSrcs)) {
steps.add(new SymlinkFileStep(getProjectFilesystem(), header, asmIncludeDir.resolve(header.getFileName()), /* useAbsolutePaths */
true));
}
}
Path asmOutputDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_compile");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), asmOutputDir));
ImmutableList.Builder<Path> asmOutputs = ImmutableList.builder();
for (Path asmSrc : asmSrcs) {
Path outputPath = asmOutputDir.resolve(asmSrc.getFileName().toString().replaceAll("\\.[sS]$", ".o"));
steps.add(new GoAssembleStep(getProjectFilesystem().getRootPath(), assembler.getEnvironment(context.getSourcePathResolver()), assembler.getCommandPrefix(context.getSourcePathResolver()), assemblerFlags, asmSrc, ImmutableList.<Path>builder().addAll(assemblerIncludeDirs).add(asmHeaderPath.get().getParent()).add(asmIncludeDir).build(), platform, outputPath));
asmOutputs.add(outputPath);
}
steps.add(new GoPackStep(getProjectFilesystem().getRootPath(), packer.getEnvironment(context.getSourcePathResolver()), packer.getCommandPrefix(context.getSourcePathResolver()), GoPackStep.Operation.APPEND, asmOutputs.build(), output));
}
return steps.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class RecordingProjectFileHashCache method extractBuckConfigFileHashes.
private synchronized void extractBuckConfigFileHashes(DistBuildConfig distBuildConfig) {
// We want to materialize files during pre-loading for .buckconfig entries
materializeCurrentFileDuringPreloading = true;
// TODO(alisdair04,shivanker): KnownBuildRuleTypes always loads java compilers if they are
// defined in a .buckconfig, regardless of what type of build is taking place. Unless peforming
// a Java build, they are not added to the build graph, and as such Stampede needs to be told
// about them directly via the whitelist.
// TODO(alisdair04,ruibm): capture all .buckconfig dependencies automatically.
Optional<ImmutableList<Path>> whitelist = distBuildConfig.getOptionalPathWhitelist();
if (!whitelist.isPresent()) {
return;
}
LOG.info("Stampede always_materialize_whitelist=[%s] cell=[%s].", whitelist.isPresent() ? Joiner.on(", ").join(whitelist.get()) : "", delegate.getFilesystem().getRootPath().toString());
try {
for (Path absPath : whitelist.get()) {
Optional<Path> relPathOpt = projectFilesystem.getPathRelativeToProjectRoot(absPath);
if (!relPathOpt.isPresent() || !willGet(relPathOpt.get()) || !projectFilesystem.exists(relPathOpt.get())) {
continue;
}
// Record this path immediately.
get(relPathOpt.get());
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
materializeCurrentFileDuringPreloading = false;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class CopyResourcesStep method buildSteps.
@VisibleForTesting
ImmutableList<Step> buildSteps() {
ImmutableList.Builder<Step> allSteps = ImmutableList.builder();
if (resources.isEmpty()) {
return allSteps.build();
}
String targetPackageDir = javaPackageFinder.findJavaPackage(target);
for (SourcePath rawResource : resources) {
// If the path to the file defining this rule were:
// "first-party/orca/lib-http/tests/com/facebook/orca/BUCK"
//
// And the value of resource were:
// "first-party/orca/lib-http/tests/com/facebook/orca/protocol/base/batch_exception1.txt"
//
// Assuming that `src_roots = tests` were in the [java] section of the .buckconfig file,
// then javaPackageAsPath would be:
// "com/facebook/orca/protocol/base/"
//
// And the path that we would want to copy to the classes directory would be:
// "com/facebook/orca/protocol/base/batch_exception1.txt"
//
// Therefore, some path-wrangling is required to produce the correct string.
Optional<BuildRule> underlyingRule = ruleFinder.getRule(rawResource);
Path relativePathToResource = resolver.getRelativePath(rawResource);
String resource;
if (underlyingRule.isPresent()) {
BuildTarget underlyingTarget = underlyingRule.get().getBuildTarget();
if (underlyingRule.get() instanceof HasOutputName) {
resource = MorePaths.pathWithUnixSeparators(underlyingTarget.getBasePath().resolve(((HasOutputName) underlyingRule.get()).getOutputName()));
} else {
Path genOutputParent = BuildTargets.getGenPath(filesystem, underlyingTarget, "%s").getParent();
Path scratchOutputParent = BuildTargets.getScratchPath(filesystem, underlyingTarget, "%s").getParent();
Optional<Path> outputPath = MorePaths.stripPrefix(relativePathToResource, genOutputParent).map(Optional::of).orElse(MorePaths.stripPrefix(relativePathToResource, scratchOutputParent));
Preconditions.checkState(outputPath.isPresent(), "%s is used as a resource but does not output to a default output directory", underlyingTarget.getFullyQualifiedName());
resource = MorePaths.pathWithUnixSeparators(underlyingTarget.getBasePath().resolve(outputPath.get()));
}
} else {
resource = MorePaths.pathWithUnixSeparators(relativePathToResource);
}
Path javaPackageAsPath = javaPackageFinder.findJavaPackageFolder(outputDirectory.getFileSystem().getPath(resource));
Path relativeSymlinkPath;
if ("".equals(javaPackageAsPath.toString())) {
// In this case, the project root is acting as the default package, so the resource path
// works fine.
relativeSymlinkPath = relativePathToResource.getFileName();
} else {
int lastIndex = resource.lastIndexOf(MorePaths.pathWithUnixSeparatorsAndTrailingSlash(javaPackageAsPath));
if (lastIndex < 0) {
Preconditions.checkState(rawResource instanceof BuildTargetSourcePath, "If resource path %s does not contain %s, then it must be a BuildTargetSourcePath.", relativePathToResource, javaPackageAsPath);
// Handle the case where we depend on the output of another BuildRule. In that case, just
// grab the output and put in the same package as this target would be in.
relativeSymlinkPath = outputDirectory.getFileSystem().getPath(String.format("%s%s%s", targetPackageDir, targetPackageDir.isEmpty() ? "" : "/", resolver.getRelativePath(rawResource).getFileName()));
} else {
relativeSymlinkPath = outputDirectory.getFileSystem().getPath(resource.substring(lastIndex));
}
}
Path target = outputDirectory.resolve(relativeSymlinkPath);
MkdirAndSymlinkFileStep link = new MkdirAndSymlinkFileStep(filesystem, resolver.getAbsolutePath(rawResource), target);
allSteps.add(link);
}
return allSteps.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class DefaultJavaLibrary method getBuildSteps.
/**
* Building a java_library() rule entails compiling the .java files specified in the srcs
* attribute. They are compiled into a directory under {@link BuckPaths#getScratchDir()}.
*/
@Override
public final ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
FluentIterable<JavaLibrary> declaredClasspathDeps = JavaLibraryClasspathProvider.getJavaLibraryDeps(getDepsForTransitiveClasspathEntries());
// Always create the output directory, even if there are no .java files to compile because there
// might be resources that need to be copied there.
BuildTarget target = getBuildTarget();
Path outputDirectory = getClassesDir(target, getProjectFilesystem());
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory));
SuggestBuildRules suggestBuildRule = DefaultSuggestBuildRules.createSuggestBuildFunction(JAR_RESOLVER, context.getSourcePathResolver(), declaredClasspathDeps.toSet(), ImmutableSet.<JavaLibrary>builder().addAll(getTransitiveClasspathDeps()).add(this).build(), context.getActionGraph().getNodes());
// We don't want to add these to the declared or transitive deps, since they're only used at
// compile time.
Collection<Path> provided = JavaLibraryClasspathProvider.getJavaLibraryDeps(providedDeps).transformAndConcat(JavaLibrary::getOutputClasspaths).filter(Objects::nonNull).transform(context.getSourcePathResolver()::getAbsolutePath).toSet();
Iterable<Path> declaredClasspaths = declaredClasspathDeps.transformAndConcat(JavaLibrary::getOutputClasspaths).transform(context.getSourcePathResolver()::getAbsolutePath);
// Only override the bootclasspath if this rule is supposed to compile Android code.
ImmutableSortedSet<Path> declared = ImmutableSortedSet.<Path>naturalOrder().addAll(declaredClasspaths).addAll(additionalClasspathEntries.stream().map(e -> e.isLeft() ? context.getSourcePathResolver().getAbsolutePath(e.getLeft()) : checkIsAbsolute(e.getRight())).collect(MoreCollectors.toImmutableSet())).addAll(provided).build();
// Make sure that this directory exists because ABI information will be written here.
Step mkdir = new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToAbiOutputDir());
steps.add(mkdir);
// If there are resources, then link them to the appropriate place in the classes directory.
JavaPackageFinder finder = context.getJavaPackageFinder();
if (resourcesRoot.isPresent()) {
finder = new ResourcesRootPackageFinder(resourcesRoot.get(), finder);
}
steps.add(new CopyResourcesStep(getProjectFilesystem(), context.getSourcePathResolver(), ruleFinder, target, resources, outputDirectory, finder));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputJarDirPath(target, getProjectFilesystem())));
// into the built jar.
if (!getJavaSrcs().isEmpty()) {
ClassUsageFileWriter usedClassesFileWriter;
if (trackClassUsage) {
final Path usedClassesFilePath = getUsedClassesFilePath(getBuildTarget(), getProjectFilesystem());
depFileOutputPath = getProjectFilesystem().getPathForRelativePath(usedClassesFilePath);
usedClassesFileWriter = new DefaultClassUsageFileWriter(usedClassesFilePath);
buildableContext.recordArtifact(usedClassesFilePath);
} else {
usedClassesFileWriter = NoOpClassUsageFileWriter.instance();
}
// This adds the javac command, along with any supporting commands.
Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
Path scratchDir = BuildTargets.getGenPath(getProjectFilesystem(), target, "lib__%s____working_directory");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
Optional<Path> workingDirectory = Optional.of(scratchDir);
ImmutableSortedSet<Path> javaSrcs = getJavaSrcs().stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableSortedSet());
compileStepFactory.createCompileToJarStep(context, javaSrcs, target, context.getSourcePathResolver(), ruleFinder, getProjectFilesystem(), declared, outputDirectory, workingDirectory, pathToSrcsList, Optional.of(suggestBuildRule), postprocessClassesCommands, ImmutableSortedSet.of(outputDirectory), /* mainClass */
Optional.empty(), manifestFile.map(context.getSourcePathResolver()::getAbsolutePath), outputJar.get(), usedClassesFileWriter, /* output params */
steps, buildableContext, classesToRemoveFromJar);
}
if (outputJar.isPresent()) {
Path output = outputJar.get();
// No source files, only resources
if (getJavaSrcs().isEmpty()) {
steps.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(outputDirectory), /* mainClass */
null, manifestFile.map(context.getSourcePathResolver()::getAbsolutePath).orElse(null), true, classesToRemoveFromJar));
}
buildableContext.recordArtifact(output);
}
JavaLibraryRules.addAccumulateClassNamesStep(this, buildableContext, context.getSourcePathResolver(), steps);
return steps.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class ReactNativeBundle method getInputsAfterBuildingLocally.
@Override
public ImmutableList<SourcePath> getInputsAfterBuildingLocally(BuildContext context) throws IOException {
ImmutableList.Builder<SourcePath> inputs = ImmutableList.builder();
// Use the generated depfile to determinate which sources ended up being used.
ImmutableMap<Path, SourcePath> pathToSourceMap = Maps.uniqueIndex(srcs, context.getSourcePathResolver()::getAbsolutePath);
Path depFile = getPathToDepFile(getBuildTarget(), getProjectFilesystem());
for (String line : getProjectFilesystem().readLines(depFile)) {
Path path = getProjectFilesystem().getPath(line);
SourcePath sourcePath = pathToSourceMap.get(path);
if (sourcePath == null) {
throw new IOException(String.format("%s: entry path '%s' transitively uses source file not preset in `srcs`: %s", getBuildTarget(), entryPath, path));
}
inputs.add(sourcePath);
}
return inputs.build();
}
Aggregations