use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class JavacStepTest method missingBootclasspathDirFailsWithError.
@Test
public void missingBootclasspathDirFailsWithError() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/no-such-dir").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
assertThat(result, equalTo(StepExecutionResult.ERROR));
assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("Invalid Java compiler options: Bootstrap classpath /no-such-dir " + "contains no valid entries")));
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class NdkLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// .so files are written to the libs/ subdirectory of the output directory.
// All of them should be recorded via the BuildableContext.
Path binDirectory = buildArtifactsDirectory.resolve("libs");
steps.add(new RmStep(getProjectFilesystem(), makefile));
steps.add(new MkdirStep(getProjectFilesystem(), makefile.getParent()));
steps.add(new WriteFileStep(getProjectFilesystem(), makefileContents, makefile, false));
steps.add(new NdkBuildStep(getProjectFilesystem(), root, makefile, buildArtifactsDirectory, binDirectory, flags, macroExpander));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), genDirectory));
steps.add(CopyStep.forDirectory(getProjectFilesystem(), binDirectory, genDirectory, CopyStep.DirectoryMode.CONTENTS_ONLY));
buildableContext.recordArtifact(genDirectory);
// Some tools need to inspect .so files whose symbols haven't been stripped, so cache these too.
// However, the intermediate object files are huge and we have no interest in them, so filter
// them out.
steps.add(new AbstractExecutionStep("cache_unstripped_so") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
try {
Set<Path> unstrippedSharedObjs = getProjectFilesystem().getFilesUnderPath(buildArtifactsDirectory, input -> input.toString().endsWith(".so"));
for (Path path : unstrippedSharedObjs) {
buildableContext.recordArtifact(path);
}
} catch (IOException e) {
context.logError(e, "Failed to cache intermediate artifacts of %s.", getBuildTarget());
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
return steps.build();
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class RelinkerRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
final ImmutableList.Builder<Step> relinkerSteps = ImmutableList.builder();
if (linker != null) {
ImmutableList<Arg> args = ImmutableList.<Arg>builder().addAll(linkerArgs).add(StringArg.of("-Wl,--version-script=" + getRelativeVersionFilePath().toString())).build();
relinkerSteps.addAll(new CxxLink(buildRuleParams.withAppendedFlavor(InternalFlavor.of("cxx-link")).withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor()), linker, getLibFilePath(), args, cxxBuckConfig.getLinkScheduleInfo(), cxxBuckConfig.shouldCacheLinks()).getBuildSteps(context, buildableContext));
buildableContext.recordArtifact(getRelativeVersionFilePath());
}
buildableContext.recordArtifact(getSymbolsNeededOutPath());
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getScratchDirPath()), new AbstractExecutionStep("xdso-dce relinker") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
ImmutableSet<String> symbolsNeeded = readSymbolsNeeded();
if (linker == null) {
getProjectFilesystem().copyFile(getBaseLibPath(), getLibFilePath());
buildableContext.recordArtifact(getLibFilePath());
} else {
writeVersionScript(context.getProcessExecutor(), symbolsNeeded);
for (Step s : relinkerSteps.build()) {
StepExecutionResult executionResult = s.execute(context);
if (!executionResult.isSuccess()) {
return StepExecutionResult.ERROR;
}
}
}
writeSymbols(getSymbolsNeededOutPath(), Sets.union(symbolsNeeded, getSymbols(context.getProcessExecutor(), getLibFilePath()).undefined));
return StepExecutionResult.SUCCESS;
}
});
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class CopyNativeLibraries method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getBinPath()));
final Path pathToNativeLibs = getPathToNativeLibsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibs));
final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibsAssets));
for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) {
copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(nativeLibDir), pathToNativeLibs, cpuFilters, steps);
}
addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibRules, pathToNativeLibs, steps);
addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibAssetRules, pathToNativeLibsAssets, steps);
final Path pathToMetadataTxt = getPathToMetadataTxt();
steps.add(new AbstractExecutionStep("hash_native_libs") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
ProjectFilesystem filesystem = getProjectFilesystem();
ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
try {
for (Path nativeLib : filesystem.getFilesUnderPath(getPathToAllLibsDir())) {
Sha1HashCode filesha1 = filesystem.computeSha1(nativeLib);
Path relativePath = getPathToAllLibsDir().relativize(nativeLib);
metadataLines.add(String.format("%s %s", relativePath, filesha1));
}
filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt);
} catch (IOException e) {
context.logError(e, "There was an error hashing native libraries.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
buildableContext.recordArtifact(pathToNativeLibs);
buildableContext.recordArtifact(pathToNativeLibsAssets);
buildableContext.recordArtifact(pathToMetadataTxt);
return steps.build();
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class OcamlBuildStep method generateSources.
private StepExecutionResult generateSources(ExecutionContext context, Path workingDirectory) throws IOException, InterruptedException {
MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getGeneratedSourceDir());
StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
if (!mkDirExecutionResult.isSuccess()) {
return mkDirExecutionResult;
}
for (SourcePath yaccSource : ocamlContext.getYaccInput()) {
SourcePath output = ocamlContext.getYaccOutput(ImmutableSet.of(yaccSource)).get(0);
OcamlYaccStep yaccStep = new OcamlYaccStep(workingDirectory, resolver, new OcamlYaccStep.Args(ocamlContext.getYaccCompiler().get(), resolver.getAbsolutePath(output), resolver.getAbsolutePath(yaccSource)));
StepExecutionResult yaccExecutionResult = yaccStep.execute(context);
if (!yaccExecutionResult.isSuccess()) {
return yaccExecutionResult;
}
}
for (SourcePath lexSource : ocamlContext.getLexInput()) {
SourcePath output = ocamlContext.getLexOutput(ImmutableSet.of(lexSource)).get(0);
OcamlLexStep lexStep = new OcamlLexStep(workingDirectory, resolver, new OcamlLexStep.Args(ocamlContext.getLexCompiler().get(), resolver.getAbsolutePath(output), resolver.getAbsolutePath(lexSource)));
StepExecutionResult lexExecutionResult = lexStep.execute(context);
if (!lexExecutionResult.isSuccess()) {
return lexExecutionResult;
}
}
return StepExecutionResult.SUCCESS;
}
Aggregations