use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.
the class ScalaTestDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams rawParams, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (CalculateAbi.isAbiTarget(rawParams.getBuildTarget())) {
BuildTarget testTarget = CalculateAbi.getLibraryTarget(rawParams.getBuildTarget());
BuildRule testRule = resolver.requireRule(testTarget);
return CalculateAbi.of(rawParams.getBuildTarget(), ruleFinder, rawParams, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final BuildRule scalaLibrary = resolver.getRule(config.getScalaLibraryTarget());
BuildRuleParams params = rawParams.copyReplacingDeclaredAndExtraDeps(() -> ImmutableSortedSet.<BuildRule>naturalOrder().addAll(rawParams.getDeclaredDeps().get()).add(scalaLibrary).build(), rawParams.getExtraDeps());
JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, ruleFinder, cxxPlatform);
params = cxxLibraryEnhancement.updatedParams;
Tool scalac = config.getScalac(resolver);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), scalac.getDeps(ruleFinder))).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), /* generatedSourceFolderName */
Optional.empty(), /* proguardConfig */
Optional.empty(), /* postprocessClassesCommands */
ImmutableList.of(), /* exportDeps */
ImmutableSortedSet.of(), /* providedDeps */
ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), /* trackClassUsage */
false, /* additionalClasspathEntries */
ImmutableSet.of(), new ScalacToJarStepFactory(scalac, config.getCompilerFlags(), args.extraArguments, ImmutableSet.of()), args.resourcesRoot, args.manifestFile, args.mavenCoords, /* tests */
ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of()));
return new JavaTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, /* additionalClasspathEntries */
ImmutableSet.of(), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.runTestSeparately.orElse(false), args.forkMode.orElse(ForkMode.NONE), args.stdOutLogLevel, args.stdErrLogLevel);
}
use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.
the class LuaStandaloneBinary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
buildableContext.recordArtifact(output);
// Make sure the parent directory exists.
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
// Delete any other pex that was there (when switching between pex styles).
steps.add(new RmStep(getProjectFilesystem(), output, RmStep.Mode.RECURSIVE));
SourcePathResolver resolver = context.getSourcePathResolver();
steps.add(new ShellStep(getProjectFilesystem().getRootPath()) {
@Override
protected Optional<String> getStdin(ExecutionContext context) {
try {
return Optional.of(context.getObjectMapper().writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, resolver::getAbsolutePath)))));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
ImmutableList.Builder<String> command = ImmutableList.builder();
command.addAll(builder.getCommandPrefix(resolver));
command.addAll(builderArgs);
command.add("--entry-point", mainModule);
command.add("--interpreter");
if (starter.isPresent()) {
command.add(resolver.getAbsolutePath(starter.get()).toString());
} else {
command.add(lua.getCommandPrefix(resolver).get(0));
}
command.add(getProjectFilesystem().resolve(output).toString());
return command.build();
}
@Override
public String getShortName() {
return "lua_package";
}
});
return steps.build();
}
use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.
the class ExportFile method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
SourcePathResolver resolver = context.getSourcePathResolver();
// This file is copied rather than symlinked so that when it is included in an archive zip and
// unpacked on another machine, it is an ordinary file in both scenarios.
ImmutableList.Builder<Step> builder = ImmutableList.builder();
if (mode == ExportFileDescription.Mode.COPY) {
Path out = getCopiedPath();
builder.add(new MkdirStep(getProjectFilesystem(), out.getParent()));
builder.add(new RmStep(getProjectFilesystem(), out, RmStep.Mode.RECURSIVE));
if (resolver.getFilesystem(src).isDirectory(resolver.getRelativePath(src))) {
builder.add(CopyStep.forDirectory(getProjectFilesystem(), resolver.getAbsolutePath(src), out, CopyStep.DirectoryMode.CONTENTS_ONLY));
} else {
builder.add(CopyStep.forFile(getProjectFilesystem(), resolver.getAbsolutePath(src), out));
}
buildableContext.recordArtifact(out);
}
return builder.build();
}
use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.
the class ExportFileDescription method createBuildRule.
@Override
public <A extends Arg> ExportFile createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
BuildTarget target = params.getBuildTarget();
Mode mode = args.mode.orElse(Mode.COPY);
String name;
if (args.out.isPresent()) {
if (mode == ExportFileDescription.Mode.REFERENCE) {
throw new HumanReadableException("%s: must not set `out` for `export_file` when using `REFERENCE` mode", params.getBuildTarget());
}
name = args.out.get();
} else {
name = target.getShortNameAndFlavorPostfix();
}
SourcePath src;
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
if (args.src.isPresent()) {
if (mode == ExportFileDescription.Mode.REFERENCE && !pathResolver.getFilesystem(args.src.get()).equals(params.getProjectFilesystem())) {
throw new HumanReadableException("%s: must use `COPY` mode for `export_file` when source (%s) uses a different cell", target, args.src.get());
}
src = args.src.get();
} else {
src = new PathSourcePath(params.getProjectFilesystem(), target.getBasePath().resolve(target.getShortNameAndFlavorPostfix()));
}
return new ExportFile(params, ruleFinder, pathResolver, name, mode, src);
}
use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.
the class RustCompileRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) {
Path output = getOutput();
buildableContext.recordArtifact(output);
SourcePathResolver resolver = buildContext.getSourcePathResolver();
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), srcs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), scratchDir), new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputDir(getBuildTarget(), getProjectFilesystem())), new ShellStep(getProjectFilesystem().getRootPath()) {
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
ImmutableList<String> linkerCmd = linker.getCommandPrefix(resolver);
ImmutableList.Builder<String> cmd = ImmutableList.builder();
Path src = scratchDir.resolve(resolver.getRelativePath(rootModule));
cmd.addAll(compiler.getCommandPrefix(resolver)).addAll(executionContext.getAnsi().isAnsiTerminal() ? ImmutableList.of("--color=always") : ImmutableList.of()).add(String.format("-Clinker=%s", linkerCmd.get(0))).addAll(processLinkerArgs(linkerCmd.subList(1, linkerCmd.size()))).addAll(processLinkerArgs(Arg.stringify(linkerArgs, buildContext.getSourcePathResolver()))).addAll(Arg.stringify(args, buildContext.getSourcePathResolver())).add("-o", output.toString()).add(src.toString());
return cmd.build();
}
/*
* Make sure all stderr output from rustc is emitted, since its either a warning or an
* error. In general Rust code should have zero warnings, or all warnings as errors.
* Regardless, respect requests for silence.
*/
@Override
protected boolean shouldPrintStderr(Verbosity verbosity) {
return !verbosity.isSilent();
}
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
return compiler.getEnvironment(buildContext.getSourcePathResolver());
}
@Override
public String getShortName() {
return "rust-build";
}
});
}
Aggregations