use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class CxxPreprocessAndCompile method appendToRuleKey.
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
// the rule key, as changing this changes the generated object file.
if (operation == CxxPreprocessAndCompileStep.Operation.PREPROCESS_AND_COMPILE) {
sink.setReflectively("compilationDirectory", compilerSanitizer.getCompilationDirectory());
}
if (sandboxTree.isPresent()) {
ImmutableMap<Path, SourcePath> links = sandboxTree.get().getLinks();
for (Path path : ImmutableSortedSet.copyOf(links.keySet())) {
SourcePath source = links.get(path);
sink.setReflectively("sandbox(" + path.toString() + ")", source);
}
}
if (precompiledHeaderRule.isPresent()) {
sink.setReflectively("precompiledHeaderRuleInput", precompiledHeaderRule.get().getInput());
}
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class PrebuiltCxxLibraryDescription method createSharedLibraryInterface.
private <A extends Arg> BuildRule createSharedLibraryInterface(BuildTarget baseTarget, BuildRuleParams baseParams, BuildRuleResolver resolver, CxxPlatform cxxPlatform, Optional<String> versionSubdir, A args) throws NoSuchBuildTargetException {
if (!args.supportsSharedLibraryInterface) {
throw new HumanReadableException("%s: rule does not support shared library interfaces", baseTarget, cxxPlatform.getFlavor());
}
Optional<SharedLibraryInterfaceFactory> factory = cxxPlatform.getSharedLibraryInterfaceFactory();
if (!factory.isPresent()) {
throw new HumanReadableException("%s: C/C++ platform %s does not support shared library interfaces", baseTarget, cxxPlatform.getFlavor());
}
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
SourcePath sharedLibrary = requireSharedLibrary(baseTarget, resolver, pathResolver, baseParams.getCellRoots(), baseParams.getProjectFilesystem(), cxxPlatform, versionSubdir, args);
return factory.get().createSharedInterfaceLibrary(baseTarget.withAppendedFlavors(Type.SHARED_INTERFACE.getFlavor(), cxxPlatform.getFlavor()), baseParams, resolver, pathResolver, ruleFinder, sharedLibrary);
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class PrebuiltCxxLibraryDescription method getApplicableSourcePath.
private static SourcePath getApplicableSourcePath(final BuildTarget target, final CellPathResolver cellRoots, final ProjectFilesystem filesystem, final BuildRuleResolver ruleResolver, final CxxPlatform cxxPlatform, Optional<String> versionSubDir, final String basePathString, final Optional<String> addedPathString) {
ImmutableList<BuildRule> deps;
MacroHandler handler = getMacroHandler(Optional.of(cxxPlatform));
try {
deps = handler.extractBuildTimeDeps(target, cellRoots, ruleResolver, basePathString);
} catch (MacroException e) {
deps = ImmutableList.of();
}
Path libDirPath = filesystem.getPath(expandMacros(handler, target, cellRoots, ruleResolver, basePathString));
if (versionSubDir.isPresent()) {
libDirPath = filesystem.getPath(versionSubDir.get()).resolve(libDirPath);
}
// So just expand the macros and return a PathSourcePath
if (deps.isEmpty()) {
Path resultPath = libDirPath;
if (addedPathString.isPresent()) {
resultPath = libDirPath.resolve(expandMacros(handler, target, cellRoots, ruleResolver, addedPathString.get()));
}
resultPath = target.getBasePath().resolve(resultPath);
return new PathSourcePath(filesystem, resultPath);
}
// If we get here then this is referencing the output from a build rule.
// This always return a ExplicitBuildTargetSourcePath
Path p = filesystem.resolve(libDirPath);
if (addedPathString.isPresent()) {
p = p.resolve(addedPathString.get());
}
p = filesystem.relativize(p);
return new ExplicitBuildTargetSourcePath(deps.iterator().next().getBuildTarget(), p);
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class HaskellPrebuiltLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
return new PrebuiltHaskellLibrary(params) {
private final LoadingCache<CxxPreprocessables.CxxPreprocessorInputCacheKey, ImmutableMap<BuildTarget, CxxPreprocessorInput>> transitiveCxxPreprocessorInputCache = CxxPreprocessables.getTransitiveCxxPreprocessorInputCache(this);
@Override
public HaskellCompileInput getCompileInput(CxxPlatform cxxPlatform, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
return HaskellCompileInput.builder().addAllFlags(args.exportedCompilerFlags).addPackages(HaskellPackage.builder().setInfo(HaskellPackageInfo.of(getBuildTarget().getShortName(), args.version, args.id.orElse(String.format("%s-%s", getBuildTarget().getShortName(), args.version)))).setPackageDb(args.db).addAllInterfaces(args.importDirs).addAllLibraries(depType == Linker.LinkableDepType.SHARED ? args.sharedLibs.values() : args.staticLibs).build()).build();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableDeps() {
return ImmutableList.of();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableExportedDeps() {
return FluentIterable.from(getDeclaredDeps()).filter(NativeLinkable.class);
}
@Override
public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) {
NativeLinkableInput.Builder builder = NativeLinkableInput.builder();
builder.addAllArgs(StringArg.from(args.exportedLinkerFlags));
if (type == Linker.LinkableDepType.SHARED) {
builder.addAllArgs(SourcePathArg.from(args.sharedLibs.values()));
} else {
builder.addAllArgs(SourcePathArg.from(args.staticLibs));
}
return builder.build();
}
@Override
public Linkage getPreferredLinkage(CxxPlatform cxxPlatform) {
return Linkage.ANY;
}
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) {
return args.sharedLibs;
}
@Override
public Iterable<? extends CxxPreprocessorDep> getCxxPreprocessorDeps(CxxPlatform cxxPlatform) {
return FluentIterable.from(getDeps()).filter(CxxPreprocessorDep.class);
}
@Override
public Optional<HeaderSymlinkTree> getExportedHeaderSymlinkTree(CxxPlatform cxxPlatform) {
return Optional.empty();
}
@Override
public CxxPreprocessorInput getCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
CxxPreprocessorInput.Builder builder = CxxPreprocessorInput.builder();
for (SourcePath headerDir : args.cxxHeaderDirs) {
builder.addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, headerDir));
}
return builder.build();
}
@Override
public ImmutableMap<BuildTarget, CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
return transitiveCxxPreprocessorInputCache.getUnchecked(ImmutableCxxPreprocessorInputCacheKey.of(cxxPlatform, headerVisibility));
}
};
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class JavaLibraryRules method getAbiInputs.
public static ImmutableSortedSet<SourcePath> getAbiInputs(BuildRuleResolver resolver, Iterable<BuildRule> inputs) throws NoSuchBuildTargetException {
ImmutableSortedSet.Builder<SourcePath> abiRules = ImmutableSortedSet.naturalOrder();
for (BuildRule dep : inputs) {
if (dep instanceof HasJavaAbi) {
Optional<BuildTarget> abiJarTarget = ((HasJavaAbi) dep).getAbiJar();
if (abiJarTarget.isPresent()) {
BuildRule abiJarRule = resolver.requireRule(abiJarTarget.get());
abiRules.add(Preconditions.checkNotNull(abiJarRule.getSourcePathToOutput()));
}
}
}
return abiRules.build();
}
Aggregations