use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class HalideLibraryDescription method createHalideStaticLibrary.
private BuildRule createHalideStaticLibrary(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxPlatform platform, Arg args) throws NoSuchBuildTargetException {
if (!isPlatformSupported(args, platform)) {
return new NoopBuildRule(params);
}
BuildRule halideCompile = ruleResolver.requireRule(params.getBuildTarget().withFlavors(HALIDE_COMPILE_FLAVOR, platform.getFlavor()));
BuildTarget buildTarget = halideCompile.getBuildTarget();
return Archive.from(params.getBuildTarget(), params, ruleFinder, platform, cxxBuckConfig.getArchiveContents(), CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), platform.getFlavor(), CxxSourceRuleFactory.PicType.PIC, platform.getStaticLibraryExtension()), ImmutableList.of(new ExplicitBuildTargetSourcePath(buildTarget, HalideCompile.objectOutputPath(buildTarget, params.getProjectFilesystem(), args.functionName))));
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class CsharpLibrary method resolveReferences.
private ImmutableList<Either<Path, String>> resolveReferences(SourcePathResolver pathResolver, ImmutableList<Either<BuildRule, String>> refs) {
ImmutableList.Builder<Either<Path, String>> resolved = ImmutableList.builder();
for (Either<BuildRule, String> ref : refs) {
if (ref.isLeft()) {
// TODO(shs96c): Do this in the constructor? Or the Description?
BuildRule rule = ref.getLeft();
Preconditions.checkArgument(rule instanceof CsharpLibrary || rule instanceof PrebuiltDotnetLibrary);
SourcePath outputPath = Preconditions.checkNotNull(rule.getSourcePathToOutput());
resolved.add(Either.ofLeft(pathResolver.getAbsolutePath(outputPath)));
} else {
resolved.add(Either.ofRight(ref.getRight()));
}
}
return resolved.build();
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class DefaultSuggestBuildRules method isMissingBuildRule.
/**
* @param transitiveNotDeclaredRule A {@link BuildRule} that is contained in the transitive
* dependency list but is not declared as a dependency.
* @param failedImports A Set of remaining failed imports. This function will mutate this set
* and remove any imports satisfied by {@code transitiveNotDeclaredDep}.
* @return whether or not adding {@code transitiveNotDeclaredDep} as a dependency to this build
* rule would have satisfied one of the {@code failedImports}.
*/
private boolean isMissingBuildRule(BuildRule transitiveNotDeclaredRule, Set<String> failedImports, JarResolver jarResolver) {
if (!(transitiveNotDeclaredRule instanceof JavaLibrary)) {
return false;
}
ImmutableSet<Path> classPaths = ((JavaLibrary) transitiveNotDeclaredRule).getOutputClasspaths().stream().map(c -> pathResolver.getAbsolutePath(c)).collect(MoreCollectors.toImmutableSet());
boolean containsMissingBuildRule = false;
// classpath.
for (Path classPath : classPaths) {
ImmutableSet<String> topLevelSymbols = jarResolver.resolve(classPath);
for (String symbolName : topLevelSymbols) {
if (failedImports.contains(symbolName)) {
failedImports.remove(symbolName);
containsMissingBuildRule = true;
// If we've found all of the missing imports, bail out early.
if (failedImports.isEmpty()) {
return true;
}
}
}
}
return containsMissingBuildRule;
}
use of com.facebook.buck.rules.BuildRule 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 com.facebook.buck.rules.BuildRule in project buck by facebook.
the class AbstractJavacOptions method getInputs.
public ImmutableSortedSet<SourcePath> getInputs(SourcePathRuleFinder ruleFinder) {
ImmutableSortedSet.Builder<SourcePath> builder = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(getAnnotationProcessingParams().getInputs());
Optional<SourcePath> javacJarPath = getJavacJarPath();
if (javacJarPath.isPresent()) {
SourcePath sourcePath = javacJarPath.get();
// Add the original rule regardless of what happens next.
builder.add(sourcePath);
Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath);
if (possibleRule.isPresent()) {
BuildRule rule = possibleRule.get();
// And now include any transitive deps that contribute to the classpath.
if (rule instanceof JavaLibrary) {
builder.addAll(((JavaLibrary) rule).getDepsForTransitiveClasspathEntries().stream().map(BuildRule::getSourcePathToOutput).collect(MoreCollectors.toImmutableList()));
} else {
builder.add(sourcePath);
}
}
}
return builder.build();
}
Aggregations