use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class AbstractPrebuiltCxxLibraryGroupDescription method getSharedLinkArgs.
/**
* @return the link args formed from the user-provided shared link line after resolving library
* macro references.
*/
private Iterable<Arg> getSharedLinkArgs(BuildTarget target, ImmutableMap<String, SourcePath> libs, ImmutableList<String> args) {
ImmutableList.Builder<Arg> builder = ImmutableList.builder();
for (String arg : args) {
Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO, REL_LIB_MACRO), arg);
if (libRef.isPresent()) {
SourcePath lib = libs.get(libRef.get().getSecond());
if (lib == null) {
throw new HumanReadableException("%s: library \"%s\" (in \"%s\") must refer to keys in the `sharedLibs` parameter", target, libRef.get().getSecond(), arg);
}
Arg libArg;
if (libRef.get().getFirst().equals(LIB_MACRO)) {
libArg = SourcePathArg.of(lib);
} else if (libRef.get().getFirst().equals(REL_LIB_MACRO)) {
if (!(lib instanceof PathSourcePath)) {
throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", target);
}
libArg = new RelativeLinkArg((PathSourcePath) lib);
} else {
throw new IllegalStateException();
}
builder.add(libArg);
} else {
builder.add(StringArg.of(arg));
}
}
return builder.build();
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class Project method addSourceFolders.
private boolean addSourceFolders(SerializableModule module, @Nullable BuildRule buildRule, @Nullable ImmutableList<SourceRoot> sourceRoots, boolean isTestSource) {
if (buildRule == null || sourceRoots == null) {
return false;
}
if (buildRule.getProperties().is(PACKAGING) && sourceRoots.isEmpty()) {
return false;
}
JavaLibrary javaLibrary;
if (buildRule instanceof JavaLibrary) {
javaLibrary = (JavaLibrary) buildRule;
Path basePath = buildRule.getBuildTarget().getBasePath();
for (SourcePath path : javaLibrary.getSources()) {
if (!(path instanceof PathSourcePath)) {
Path pathToTarget = resolver.getRelativePath(path);
Path relativePath = basePath.relativize(Paths.get("")).resolve(pathToTarget).getParent();
String url = "file://$MODULE_DIR$/" + MorePaths.pathWithUnixSeparators(relativePath);
SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource, "");
module.sourceFolders.add(sourceFolder);
}
}
}
if (sourceRoots.isEmpty()) {
// When there is a src_target, but no src_roots were specified, then the current directory is
// treated as the SourceRoot. This is the common case when a project contains one folder of
// Java source code with a build file for each Java package. For example, if the project's
// only source folder were named "java/" and a build file in java/com/example/base/ contained
// the an extremely simple set of build rules:
//
// java_library(
// name = 'base',
// srcs = glob(['*.java']),
// }
//
// project_config(
// src_target = ':base',
// )
//
// then the corresponding .iml file (in the same directory) should contain:
//
// <content url="file://$MODULE_DIR$">
// <sourceFolder url="file://$MODULE_DIR$"
// isTestSource="false"
// packagePrefix="com.example.base" />
// <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
//
// <!-- It will have an <excludeFolder> for every "subpackage" of com.example.base. -->
// <excludeFolder url="file://$MODULE_DIR$/util" />
// </content>
//
// Note to prevent the <excludeFolder> elements from being included, the project_config()
// rule should be:
//
// project_config(
// src_target = ':base',
// src_root_includes_subdirectories = True,
// )
//
// Because developers who organize their code this way will have many build files, the default
// values of project_config() assume this approach to help minimize the tedium in writing all
// of those project_config() rules.
String url = "file://$MODULE_DIR$";
String packagePrefix = javaPackageFinder.findJavaPackage(Preconditions.checkNotNull(module.pathToImlFile));
SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource, packagePrefix);
module.sourceFolders.add(sourceFolder);
} else {
for (SourceRoot sourceRoot : sourceRoots) {
SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder("file://$MODULE_DIR$/" + sourceRoot.getName(), isTestSource);
module.sourceFolders.add(sourceFolder);
}
}
// Include <excludeFolder> elements, as appropriate.
for (Path relativePath : this.buildFileTree.getChildPaths(buildRule.getBuildTarget())) {
String excludeFolderUrl = "file://$MODULE_DIR$/" + relativePath;
SerializableModule.SourceFolder excludeFolder = new SerializableModule.SourceFolder(excludeFolderUrl, /* isTestSource */
false);
module.excludeFolders.add(excludeFolder);
}
return true;
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class AbstractOcamlBuildContext method getLexOutput.
protected FluentIterable<SourcePath> getLexOutput(Iterable<SourcePath> lexInputs) {
return FluentIterable.from(lexInputs).transform(lexInput -> {
Path fileName = getSourcePathResolver().getAbsolutePath(lexInput).getFileName();
Path out = getGeneratedSourceDir().resolve(fileName.toString().replaceFirst(OcamlCompilables.OCAML_MLL_REGEX, OcamlCompilables.OCAML_ML));
return new PathSourcePath(getProjectFilesystem(), out);
});
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class ShTestDescription method createBuildRule.
@Override
public <A extends Arg> ShTest createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver);
final ImmutableList<com.facebook.buck.rules.args.Arg> testArgs = args.args.stream().map(toArg::apply).collect(MoreCollectors.toImmutableList());
final ImmutableMap<String, com.facebook.buck.rules.args.Arg> testEnv = ImmutableMap.copyOf(Maps.transformValues(args.env, toArg));
return new ShTest(params.copyAppendingExtraDeps(() -> FluentIterable.from(testArgs).append(testEnv.values()).transformAndConcat(arg -> arg.getDeps(ruleFinder))), ruleFinder, args.test, testArgs, testEnv, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.runTestSeparately.orElse(false), args.labels, args.contacts);
}
use of com.facebook.buck.rules.PathSourcePath 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);
}
Aggregations