use of com.facebook.buck.rules.SourcePathRuleFinder 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.SourcePathRuleFinder 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.SourcePathRuleFinder 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.SourcePathRuleFinder in project buck by facebook.
the class NdkLibraryDescription method generateMakefile.
/**
* @return a {@link BuildRule} which generates a Android.mk which pulls in the local Android.mk
* file and also appends relevant preprocessor and linker flags to use C/C++ library deps.
*/
private Pair<String, Iterable<BuildRule>> generateMakefile(BuildRuleParams params, BuildRuleResolver resolver) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableList.Builder<String> outputLinesBuilder = ImmutableList.builder();
ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
for (Map.Entry<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> entry : cxxPlatforms.entrySet()) {
CxxPlatform cxxPlatform = entry.getValue().getCxxPlatform();
// Collect the preprocessor input for all C/C++ library deps. We search *through* other
// NDK library rules.
CxxPreprocessorInput cxxPreprocessorInput = CxxPreprocessorInput.concat(CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, params.getDeps(), NdkLibrary.class::isInstance));
// We add any dependencies from the C/C++ preprocessor input to this rule, even though
// it technically should be added to the top-level rule.
deps.addAll(cxxPreprocessorInput.getDeps(resolver, ruleFinder));
// Add in the transitive preprocessor flags contributed by C/C++ library rules into the
// NDK build.
ImmutableList.Builder<String> ppFlags = ImmutableList.builder();
ppFlags.addAll(cxxPreprocessorInput.getPreprocessorFlags().get(CxxSource.Type.C));
Preprocessor preprocessor = CxxSourceTypes.getPreprocessor(cxxPlatform, CxxSource.Type.C).resolve(resolver);
ppFlags.addAll(CxxHeaders.getArgs(cxxPreprocessorInput.getIncludes(), pathResolver, Optional.empty(), preprocessor));
String localCflags = Joiner.on(' ').join(escapeForMakefile(params.getProjectFilesystem(), ppFlags.build()));
// Collect the native linkable input for all C/C++ library deps. We search *through* other
// NDK library rules.
NativeLinkableInput nativeLinkableInput = NativeLinkables.getTransitiveNativeLinkableInput(cxxPlatform, params.getDeps(), Linker.LinkableDepType.SHARED, NdkLibrary.class::isInstance);
// We add any dependencies from the native linkable input to this rule, even though
// it technically should be added to the top-level rule.
deps.addAll(nativeLinkableInput.getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator());
// Add in the transitive native linkable flags contributed by C/C++ library rules into the
// NDK build.
String localLdflags = Joiner.on(' ').join(escapeForMakefile(params.getProjectFilesystem(), com.facebook.buck.rules.args.Arg.stringify(nativeLinkableInput.getArgs(), pathResolver)));
// Write the relevant lines to the generated makefile.
if (!localCflags.isEmpty() || !localLdflags.isEmpty()) {
NdkCxxPlatforms.TargetCpuType targetCpuType = entry.getKey();
String targetArchAbi = getTargetArchAbi(targetCpuType);
outputLinesBuilder.add(String.format("ifeq ($(TARGET_ARCH_ABI),%s)", targetArchAbi));
if (!localCflags.isEmpty()) {
outputLinesBuilder.add("BUCK_DEP_CFLAGS=" + localCflags);
}
if (!localLdflags.isEmpty()) {
outputLinesBuilder.add("BUCK_DEP_LDFLAGS=" + localLdflags);
}
outputLinesBuilder.add("endif");
outputLinesBuilder.add("");
}
}
// GCC-only magic that rewrites non-deterministic parts of builds
String ndksubst = NdkCxxPlatforms.ANDROID_NDK_ROOT;
outputLinesBuilder.addAll(ImmutableList.copyOf(new String[] { // We're evaluated once per architecture, but want to add the cflags only once.
"ifeq ($(BUCK_ALREADY_HOOKED_CFLAGS),)", "BUCK_ALREADY_HOOKED_CFLAGS := 1", // Only GCC supports -fdebug-prefix-map
"ifeq ($(filter clang%,$(NDK_TOOLCHAIN_VERSION)),)", // Replace absolute paths with machine-relative ones.
"NDK_APP_CFLAGS += -fdebug-prefix-map=$(NDK_ROOT)/=" + ndksubst + "/", "NDK_APP_CFLAGS += -fdebug-prefix-map=$(abspath $(BUCK_PROJECT_DIR))/=./", // repository root.
"NDK_APP_CFLAGS += -fdebug-prefix-map=$(BUCK_PROJECT_DIR)/=./", "NDK_APP_CFLAGS += -fdebug-prefix-map=./=" + ".$(subst $(abspath $(BUCK_PROJECT_DIR)),,$(abspath $(CURDIR)))/", "NDK_APP_CFLAGS += -fno-record-gcc-switches", "ifeq ($(filter 4.6,$(TOOLCHAIN_VERSION)),)", // headers either.
"NDK_APP_CPPFLAGS += -fno-canonical-system-headers", // detailed command line argument information anyway.
"NDK_APP_CFLAGS += -gno-record-gcc-switches", // !GCC 4.6
"endif", // !clang
"endif", // absolute path, but only for modules under the project root.
"BUCK_SAVED_IMPORTS := $(__ndk_import_dirs)", "__ndk_import_dirs :=", "$(foreach __dir,$(BUCK_SAVED_IMPORTS),\\", "$(call import-add-path-optional,\\", "$(if $(filter $(abspath $(BUCK_PROJECT_DIR))%,$(__dir)),\\", "$(BUCK_PROJECT_DIR)$(patsubst $(abspath $(BUCK_PROJECT_DIR))%,%,$(__dir)),\\", "$(__dir))))", // !already hooked
"endif", // generic paths.
"NDK_APP_CFLAGS += -fdebug-prefix-map=$(TOOLCHAIN_PREBUILT_ROOT)/=" + "@ANDROID_NDK_ROOT@/toolchains/$(TOOLCHAIN_NAME)/prebuilt/@BUILD_HOST@/" }));
outputLinesBuilder.add("include Android.mk");
String contents = Joiner.on(System.lineSeparator()).join(outputLinesBuilder.build());
return new Pair<String, Iterable<BuildRule>>(contents, deps.build());
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class AppleDescriptions method createAppleBundle.
static AppleBundle createAppleBundle(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, CodeSignIdentityStore codeSignIdentityStore, ProvisioningProfileStore provisioningProfileStore, BuildTarget binary, Either<AppleBundleExtension, String> extension, Optional<String> productName, final SourcePath infoPlist, ImmutableMap<String, String> infoPlistSubstitutions, ImmutableSortedSet<BuildTarget> deps, ImmutableSortedSet<BuildTarget> tests, AppleDebugFormat debugFormat, boolean dryRunCodeSigning, boolean cacheable) throws NoSuchBuildTargetException {
AppleCxxPlatform appleCxxPlatform = ApplePlatforms.getAppleCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms, params.getBuildTarget(), MultiarchFileInfos.create(appleCxxPlatforms, params.getBuildTarget()));
AppleBundleDestinations destinations;
if (extension.isLeft() && extension.getLeft().equals(AppleBundleExtension.FRAMEWORK)) {
destinations = AppleBundleDestinations.platformFrameworkDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
} else {
destinations = AppleBundleDestinations.platformDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
}
AppleBundleResources collectedResources = AppleResources.collectResourceDirsAndFiles(targetGraph, Optional.empty(), targetGraph.get(params.getBuildTarget()));
ImmutableSet.Builder<SourcePath> frameworksBuilder = ImmutableSet.builder();
if (INCLUDE_FRAMEWORKS.getRequiredValue(params.getBuildTarget())) {
for (BuildTarget dep : deps) {
Optional<FrameworkDependencies> frameworkDependencies = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(FRAMEWORK_FLAVOR).addFlavors(NO_INCLUDE_FRAMEWORKS_FLAVOR).addFlavors(appleCxxPlatform.getCxxPlatform().getFlavor()).build(), FrameworkDependencies.class);
if (frameworkDependencies.isPresent()) {
frameworksBuilder.addAll(frameworkDependencies.get().getSourcePaths());
}
}
}
ImmutableSet<SourcePath> frameworks = frameworksBuilder.build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
BuildRuleParams paramsWithoutBundleSpecificFlavors = stripBundleSpecificFlavors(params);
Optional<AppleAssetCatalog> assetCatalog = createBuildRuleForTransitiveAssetCatalogDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, sourcePathResolver, appleCxxPlatform.getAppleSdk().getApplePlatform(), appleCxxPlatform.getActool());
addToIndex(resolver, assetCatalog);
Optional<CoreDataModel> coreDataModel = createBuildRulesForCoreDataDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, AppleBundle.getBinaryName(params.getBuildTarget(), productName), appleCxxPlatform);
addToIndex(resolver, coreDataModel);
Optional<SceneKitAssets> sceneKitAssets = createBuildRulesForSceneKitAssetsDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, appleCxxPlatform);
addToIndex(resolver, sceneKitAssets);
// TODO(bhamiltoncx): Sort through the changes needed to make project generation work with
// binary being optional.
BuildRule flavoredBinaryRule = getFlavoredBinaryRule(cxxPlatformFlavorDomain, defaultCxxPlatform, targetGraph, paramsWithoutBundleSpecificFlavors.getBuildTarget().getFlavors(), resolver, binary);
if (!AppleDebuggableBinary.isBuildRuleDebuggable(flavoredBinaryRule)) {
debugFormat = AppleDebugFormat.NONE;
}
BuildTarget unstrippedTarget = flavoredBinaryRule.getBuildTarget().withoutFlavors(CxxStrip.RULE_FLAVOR, AppleDebuggableBinary.RULE_FLAVOR, AppleBinaryDescription.APP_FLAVOR).withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebuggableBinary.RULE_FLAVOR).withoutFlavors(ImmutableSet.of(AppleBinaryDescription.APP_FLAVOR));
Optional<LinkerMapMode> linkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
if (linkerMapMode.isPresent()) {
unstrippedTarget = unstrippedTarget.withAppendedFlavors(linkerMapMode.get().getFlavor());
}
BuildRule unstrippedBinaryRule = resolver.requireRule(unstrippedTarget);
BuildRule targetDebuggableBinaryRule;
Optional<AppleDsym> appleDsym;
if (unstrippedBinaryRule instanceof ProvidesLinkedBinaryDeps) {
BuildTarget binaryBuildTarget = getBinaryFromBuildRuleWithBinary(flavoredBinaryRule).getBuildTarget().withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
BuildRuleParams binaryParams = params.withBuildTarget(binaryBuildTarget);
targetDebuggableBinaryRule = createAppleDebuggableBinary(binaryParams, resolver, getBinaryFromBuildRuleWithBinary(flavoredBinaryRule), (ProvidesLinkedBinaryDeps) unstrippedBinaryRule, debugFormat, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
appleDsym = createAppleDsymForDebugFormat(debugFormat, binaryParams, resolver, (ProvidesLinkedBinaryDeps) unstrippedBinaryRule, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
} else {
targetDebuggableBinaryRule = unstrippedBinaryRule;
appleDsym = Optional.empty();
}
BuildRuleParams bundleParamsWithFlavoredBinaryDep = getBundleParamsWithUpdatedDeps(params, binary, ImmutableSet.<BuildRule>builder().add(targetDebuggableBinaryRule).addAll(OptionalCompat.asSet(assetCatalog)).addAll(OptionalCompat.asSet(coreDataModel)).addAll(OptionalCompat.asSet(sceneKitAssets)).addAll(BuildRules.toBuildRulesFor(params.getBuildTarget(), resolver, RichStream.from(collectedResources.getAll()).concat(frameworks.stream()).filter(BuildTargetSourcePath.class).map(BuildTargetSourcePath::getTarget).collect(MoreCollectors.toImmutableSet()))).addAll(OptionalCompat.asSet(appleDsym)).build());
ImmutableMap<SourcePath, String> extensionBundlePaths = collectFirstLevelAppleDependencyBundles(params.getDeps(), destinations);
return new AppleBundle(bundleParamsWithFlavoredBinaryDep, resolver, extension, productName, infoPlist, infoPlistSubstitutions, Optional.of(getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)), appleDsym, destinations, collectedResources, extensionBundlePaths, frameworks, appleCxxPlatform, assetCatalog, coreDataModel, sceneKitAssets, tests, codeSignIdentityStore, provisioningProfileStore, dryRunCodeSigning, cacheable);
}
Aggregations