use of com.google.common.collect.ImmutableList in project buck by facebook.
the class HeaderSymlinkTreeWithHeaderMap method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
LOG.debug("Generating post-build steps to write header map to %s", headerMapPath);
Path buckOut = getProjectFilesystem().resolve(getProjectFilesystem().getBuckPaths().getBuckOut());
ImmutableMap.Builder<Path, Path> headerMapEntries = ImmutableMap.builder();
for (Path key : getLinks().keySet()) {
// The key is the path that will be referred to in headers. It can be anything. However, the
// value given in the headerMapEntries is the path of that entry in the generated symlink
// tree. Because "reasons", we don't want to cache that value, so we need to relativize the
// path to the output directory of this current rule. We then rely on magic and the stars
// aligning in order to get this to work. May we find peace in another life.
headerMapEntries.put(key, buckOut.relativize(getRoot().resolve(key)));
}
ImmutableList.Builder<Step> builder = ImmutableList.<Step>builder().addAll(super.getBuildSteps(context, buildableContext)).add(new HeaderMapStep(getProjectFilesystem(), headerMapPath, headerMapEntries.build()));
if (shouldCreateModule) {
Optional<String> umbrellaHeader = getUmbrellaHeader(getBuildTarget().getShortName());
String moduleName = normalizeModuleName(getBuildTarget().getShortName());
builder.add(new MkdirStep(getProjectFilesystem(), getRoot().resolve(moduleName)));
builder.add(createCreateModuleStep(moduleName, umbrellaHeader));
}
return builder.build();
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class DCompileBuildRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
Path output = context.getSourcePathResolver().getRelativePath(Preconditions.checkNotNull(getSourcePathToOutput()));
buildableContext.recordArtifact(output);
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
ImmutableList.Builder<String> flagsBuilder = ImmutableList.builder();
flagsBuilder.addAll(compilerFlags);
for (DIncludes include : includes) {
flagsBuilder.add("-I" + context.getSourcePathResolver().getAbsolutePath(include.getLinkTree()));
}
ImmutableList<String> flags = flagsBuilder.build();
steps.add(new DCompileStep(getProjectFilesystem().getRootPath(), compiler.getEnvironment(context.getSourcePathResolver()), compiler.getCommandPrefix(context.getSourcePathResolver()), flags, context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()), context.getSourcePathResolver().getAllAbsolutePaths(sources)));
return steps.build();
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class JavaSymbolFinder method possibleBuckFilesForSourceFile.
/**
* Look at all the directories above a given source file, up to the project root, and return the
* paths to any BUCK files that exist at those locations. These files are the only ones that could
* define a rule that includes the given source file.
*/
private ImmutableList<Path> possibleBuckFilesForSourceFile(Path sourceFilePath) {
ImmutableList.Builder<Path> possibleBuckFiles = ImmutableList.builder();
Path dir = sourceFilePath.getParent();
ParserConfig parserConfig = config.getView(ParserConfig.class);
// For a source file like foo/bar/example.java, add paths like foo/bar/BUCK and foo/BUCK.
while (dir != null) {
Path buckFile = dir.resolve(parserConfig.getBuildFileName());
if (projectFilesystem.isFile(buckFile)) {
possibleBuckFiles.add(buckFile);
}
dir = dir.getParent();
}
// Finally, add ./BUCK in the root directory.
Path rootBuckFile = Paths.get(parserConfig.getBuildFileName());
if (projectFilesystem.exists(rootBuckFile)) {
possibleBuckFiles.add(rootBuckFile);
}
return possibleBuckFiles.build();
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class JavaTest method runTests.
/**
* Runs the tests specified by the "srcs" of this class. If this rule transitively depends on
* other {@code java_test()} rules, then they will be run separately.
*/
@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
// If no classes were generated, then this is probably a java_test() that declares a number of
// other java_test() rules as deps, functioning as a test suite. In this case, simply return an
// empty list of commands.
Set<String> testClassNames = getClassNamesForSources(pathResolver);
LOG.debug("Testing these classes: %s", testClassNames.toString());
if (testClassNames.isEmpty()) {
return ImmutableList.of();
}
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path pathToTestOutput = getPathToTestOutputDirectory();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
if (forkMode() == ForkMode.PER_TEST) {
ImmutableList.Builder<JUnitStep> junitsBuilder = ImmutableList.builder();
for (String testClass : testClassNames) {
junitsBuilder.add(getJUnitStep(executionContext, pathResolver, options, Optional.of(pathToTestOutput), Optional.of(pathToTestLogs), Collections.singleton(testClass)));
}
junits = junitsBuilder.build();
} else {
junits = ImmutableList.of(getJUnitStep(executionContext, pathResolver, options, Optional.of(pathToTestOutput), Optional.of(pathToTestLogs), testClassNames));
}
steps.addAll(junits);
return steps.build();
}
use of com.google.common.collect.ImmutableList in project buck by facebook.
the class PythonPackagedBinary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path binPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
// Make sure the parent directory exists.
steps.add(new MkdirStep(getProjectFilesystem(), binPath.getParent()));
// Delete any other pex that was there (when switching between pex styles).
steps.add(new RmStep(getProjectFilesystem(), binPath, RmStep.Mode.RECURSIVE));
Path workingDirectory = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__working_directory");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), workingDirectory));
SourcePathResolver resolver = context.getSourcePathResolver();
// Generate and return the PEX build step.
steps.add(new PexStep(getProjectFilesystem(), builder.getEnvironment(resolver), ImmutableList.<String>builder().addAll(builder.getCommandPrefix(resolver)).addAll(buildArgs).build(), pythonEnvironment.getPythonPath(), pythonEnvironment.getPythonVersion(), workingDirectory, binPath, mainModule, resolver.getMappedPaths(getComponents().getModules()), resolver.getMappedPaths(getComponents().getResources()), resolver.getMappedPaths(getComponents().getNativeLibraries()), ImmutableSet.copyOf(resolver.getAllAbsolutePaths(getComponents().getPrebuiltLibraries())), preloadLibraries, getComponents().isZipSafe().orElse(true)));
// Record the executable package for caching.
buildableContext.recordArtifact(binPath);
return steps.build();
}
Aggregations