Search in sources :

Example 1 with DefaultJavaLibrary

use of com.facebook.buck.jvm.java.DefaultJavaLibrary in project buck by facebook.

the class AndroidBinaryGraphEnhancer method createAdditionalBuildables.

AndroidGraphEnhancementResult createAdditionalBuildables() throws NoSuchBuildTargetException {
    ImmutableSortedSet.Builder<BuildRule> enhancedDeps = ImmutableSortedSet.naturalOrder();
    enhancedDeps.addAll(originalDeps);
    ImmutableList.Builder<BuildRule> additionalJavaLibrariesBuilder = ImmutableList.builder();
    AndroidPackageableCollector collector = new AndroidPackageableCollector(originalBuildTarget, buildTargetsToExcludeFromDex, resourcesToExclude, apkModuleGraph);
    collector.addPackageables(AndroidPackageableCollector.getPackageableRules(originalDeps));
    AndroidPackageableCollection packageableCollection = collector.build();
    AndroidPackageableCollection.ResourceDetails resourceDetails = packageableCollection.getResourceDetails();
    AndroidNativeLibsGraphEnhancementResult nativeLibsEnhancementResult = nativeLibsEnhancer.enhance(packageableCollection);
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibraries = nativeLibsEnhancementResult.getCopyNativeLibraries();
    if (copyNativeLibraries.isPresent()) {
        ruleResolver.addAllToIndex(copyNativeLibraries.get().values());
        enhancedDeps.addAll(copyNativeLibraries.get().values());
    }
    Optional<ImmutableSortedMap<String, String>> sonameMergeMap = nativeLibsEnhancementResult.getSonameMergeMap();
    if (sonameMergeMap.isPresent() && nativeLibraryMergeCodeGenerator.isPresent()) {
        BuildRule generatorRule = ruleResolver.getRule(nativeLibraryMergeCodeGenerator.get());
        GenerateCodeForMergedLibraryMap generateCodeForMergedLibraryMap = new GenerateCodeForMergedLibraryMap(buildRuleParams.withAppendedFlavor(GENERATE_NATIVE_LIB_MERGE_MAP_GENERATED_CODE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(generatorRule)), Suppliers.ofInstance(ImmutableSortedSet.of())), sonameMergeMap.get(), generatorRule);
        ruleResolver.addToIndex(generateCodeForMergedLibraryMap);
        BuildRuleParams paramsForCompileGenCode = buildRuleParams.withAppendedFlavor(COMPILE_NATIVE_LIB_MERGE_MAP_GENERATED_CODE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(generateCodeForMergedLibraryMap)), Suppliers.ofInstance(ImmutableSortedSet.of()));
        DefaultJavaLibrary compileMergedNativeLibMapGenCode = new DefaultJavaLibrary(paramsForCompileGenCode, pathResolver, ruleFinder, ImmutableSet.of(generateCodeForMergedLibraryMap.getSourcePathToOutput()), /* resources */
        ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
        Optional.empty(), /* postprocessClassesCommands */
        ImmutableList.of(), /* exportedDeps */
        ImmutableSortedSet.of(), /* providedDeps */
        ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(ruleResolver, paramsForCompileGenCode.getDeps()), /* trackClassUsage */
        false, /* additionalClasspathEntries */
        ImmutableSet.of(), new JavacToJarStepFactory(// to 6 in their .buckconfig.
        javacOptions.withSourceLevel("7").withTargetLevel("7"), JavacOptionsAmender.IDENTITY), /* resourcesRoot */
        Optional.empty(), /* manifest file */
        Optional.empty(), /* mavenCoords */
        Optional.empty(), ImmutableSortedSet.of(), /* classesToRemoveFromJar */
        ImmutableSet.of());
        ruleResolver.addToIndex(compileMergedNativeLibMapGenCode);
        additionalJavaLibrariesBuilder.add(compileMergedNativeLibMapGenCode);
        enhancedDeps.add(compileMergedNativeLibMapGenCode);
    }
    ImmutableSortedSet<BuildRule> resourceRules = getTargetsAsRules(resourceDetails.getResourcesWithNonEmptyResDir());
    ImmutableCollection<BuildRule> rulesWithResourceDirectories = ruleFinder.filterBuildRuleInputs(resourceDetails.getResourceDirectories());
    FilteredResourcesProvider filteredResourcesProvider;
    boolean needsResourceFiltering = resourceFilter.isEnabled() || resourceCompressionMode.isStoreStringsAsAssets() || !locales.isEmpty();
    if (needsResourceFiltering) {
        BuildRuleParams paramsForResourcesFilter = buildRuleParams.withAppendedFlavor(RESOURCES_FILTER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(resourceRules).addAll(rulesWithResourceDirectories).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
        ResourcesFilter resourcesFilter = new ResourcesFilter(paramsForResourcesFilter, resourceDetails.getResourceDirectories(), ImmutableSet.copyOf(resourceDetails.getWhitelistedStringDirectories()), locales, resourceCompressionMode, resourceFilter);
        ruleResolver.addToIndex(resourcesFilter);
        filteredResourcesProvider = resourcesFilter;
        enhancedDeps.add(resourcesFilter);
        resourceRules = ImmutableSortedSet.of(resourcesFilter);
    } else {
        filteredResourcesProvider = new IdentityResourcesProvider(resourceDetails.getResourceDirectories().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableList()));
    }
    // Create the AaptPackageResourcesBuildable.
    BuildRuleParams paramsForAaptPackageResources = buildRuleParams.withAppendedFlavor(AAPT_PACKAGE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    AaptPackageResources aaptPackageResources = new AaptPackageResources(paramsForAaptPackageResources, ruleFinder, ruleResolver, manifest, filteredResourcesProvider, getTargetsAsResourceDeps(resourceDetails.getResourcesWithNonEmptyResDir()), getTargetsAsRules(resourceDetails.getResourcesWithEmptyResButNonEmptyAssetsDir()), packageableCollection.getAssetsDirectories(), resourceUnionPackage, shouldBuildStringSourceMap, skipCrunchPngs, includesVectorDrawables, bannedDuplicateResourceTypes, manifestEntries);
    ruleResolver.addToIndex(aaptPackageResources);
    enhancedDeps.add(aaptPackageResources);
    Optional<PackageStringAssets> packageStringAssets = Optional.empty();
    if (resourceCompressionMode.isStoreStringsAsAssets()) {
        BuildRuleParams paramsForPackageStringAssets = buildRuleParams.withAppendedFlavor(PACKAGE_STRING_ASSETS_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(aaptPackageResources).addAll(resourceRules).addAll(rulesWithResourceDirectories).addAll(Iterables.filter(ImmutableList.of(filteredResourcesProvider), BuildRule.class)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
        packageStringAssets = Optional.of(new PackageStringAssets(paramsForPackageStringAssets, locales, filteredResourcesProvider, aaptPackageResources));
        ruleResolver.addToIndex(packageStringAssets.get());
        enhancedDeps.add(packageStringAssets.get());
    }
    // already been added to the APK under test.
    if (packageType != PackageType.INSTRUMENTED) {
        ImmutableSortedSet<JavaLibrary> buildConfigDepsRules = addBuildConfigDeps(buildRuleParams, packageType, exopackageModes, buildConfigValues, buildConfigValuesFile, ruleResolver, javacOptions, packageableCollection);
        enhancedDeps.addAll(buildConfigDepsRules);
        additionalJavaLibrariesBuilder.addAll(buildConfigDepsRules);
    }
    ImmutableList<BuildRule> additionalJavaLibraries = additionalJavaLibrariesBuilder.build();
    ImmutableMultimap<APKModule, DexProducedFromJavaLibrary> preDexedLibraries = ImmutableMultimap.of();
    if (shouldPreDex) {
        preDexedLibraries = createPreDexRulesForLibraries(// TODO(dreiss): Put R.java here.
        additionalJavaLibraries, packageableCollection);
    }
    // Create rule to trim uber R.java sources.
    Collection<DexProducedFromJavaLibrary> preDexedLibrariesForResourceIdFiltering = trimResourceIds ? preDexedLibraries.values() : ImmutableList.of();
    BuildRuleParams paramsForTrimUberRDotJava = buildRuleParams.withAppendedFlavor(TRIM_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(aaptPackageResources).addAll(preDexedLibrariesForResourceIdFiltering).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    TrimUberRDotJava trimUberRDotJava = new TrimUberRDotJava(paramsForTrimUberRDotJava, aaptPackageResources, preDexedLibrariesForResourceIdFiltering, keepResourcePattern);
    ruleResolver.addToIndex(trimUberRDotJava);
    // Create rule to compile uber R.java sources.
    BuildRuleParams paramsForCompileUberRDotJava = buildRuleParams.withAppendedFlavor(COMPILE_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(trimUberRDotJava)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    JavaLibrary compileUberRDotJava = new DefaultJavaLibrary(paramsForCompileUberRDotJava, pathResolver, ruleFinder, ImmutableSet.of(trimUberRDotJava.getSourcePathToOutput()), /* resources */
    ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
    Optional.empty(), /* postprocessClassesCommands */
    ImmutableList.of(), /* exportedDeps */
    ImmutableSortedSet.of(), /* providedDeps */
    ImmutableSortedSet.of(), // we can just use its output as the ABI.
    JavaLibraryRules.getAbiInputs(ruleResolver, paramsForCompileUberRDotJava.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), new JavacToJarStepFactory(javacOptions.withSourceLevel("7").withTargetLevel("7"), JavacOptionsAmender.IDENTITY), /* resourcesRoot */
    Optional.empty(), /* manifest file */
    Optional.empty(), /* mavenCoords */
    Optional.empty(), ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of());
    ruleResolver.addToIndex(compileUberRDotJava);
    // Create rule to dex uber R.java sources.
    BuildRuleParams paramsForDexUberRDotJava = buildRuleParams.withAppendedFlavor(DEX_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(compileUberRDotJava)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    DexProducedFromJavaLibrary dexUberRDotJava = new DexProducedFromJavaLibrary(paramsForDexUberRDotJava, compileUberRDotJava);
    ruleResolver.addToIndex(dexUberRDotJava);
    Optional<PreDexMerge> preDexMerge = Optional.empty();
    if (shouldPreDex) {
        preDexMerge = Optional.of(createPreDexMergeRule(preDexedLibraries, dexUberRDotJava));
        enhancedDeps.add(preDexMerge.get());
    } else {
        enhancedDeps.addAll(getTargetsAsRules(packageableCollection.getJavaLibrariesToDex()));
        // If not pre-dexing, AndroidBinary needs to ProGuard and/or dex the compiled R.java.
        enhancedDeps.add(compileUberRDotJava);
    }
    // Add dependencies on all the build rules generating third-party JARs.  This is mainly to
    // correctly capture deps when a prebuilt_jar forwards the output from another build rule.
    enhancedDeps.addAll(ruleFinder.filterBuildRuleInputs(packageableCollection.getPathsToThirdPartyJars()));
    Optional<ComputeExopackageDepsAbi> computeExopackageDepsAbi = Optional.empty();
    if (!exopackageModes.isEmpty()) {
        BuildRuleParams paramsForComputeExopackageAbi = buildRuleParams.withAppendedFlavor(CALCULATE_ABI_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(enhancedDeps.build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
        computeExopackageDepsAbi = Optional.of(new ComputeExopackageDepsAbi(paramsForComputeExopackageAbi, exopackageModes, packageableCollection, copyNativeLibraries, preDexMerge));
        ruleResolver.addToIndex(computeExopackageDepsAbi.get());
        enhancedDeps.add(computeExopackageDepsAbi.get());
    }
    return AndroidGraphEnhancementResult.builder().setPackageableCollection(packageableCollection).setAaptPackageResources(aaptPackageResources).setCompiledUberRDotJava(compileUberRDotJava).setCopyNativeLibraries(copyNativeLibraries).setPackageStringAssets(packageStringAssets).setPreDexMerge(preDexMerge).setComputeExopackageDepsAbi(computeExopackageDepsAbi).setClasspathEntriesToDex(ImmutableSet.<SourcePath>builder().addAll(packageableCollection.getClasspathEntriesToDex()).addAll(additionalJavaLibraries.stream().map(BuildRule::getSourcePathToOutput).collect(MoreCollectors.toImmutableList())).build()).setFinalDeps(enhancedDeps.build()).setAPKModuleGraph(apkModuleGraph).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) JavacToJarStepFactory(com.facebook.buck.jvm.java.JavacToJarStepFactory) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary)

Example 2 with DefaultJavaLibrary

use of com.facebook.buck.jvm.java.DefaultJavaLibrary 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);
}
Also used : Optional(java.util.Optional) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTestDescription(com.facebook.buck.jvm.java.JavaTestDescription) JavaTest(com.facebook.buck.jvm.java.JavaTest) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool)

Example 3 with DefaultJavaLibrary

use of com.facebook.buck.jvm.java.DefaultJavaLibrary in project buck by facebook.

the class RobolectricTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    JavacOptions javacOptions = JavacOptionsFactory.create(templateOptions, params, resolver, ruleFinder, args);
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(params.getBuildTarget(), params.copyReplacingExtraDeps(Suppliers.ofInstance(resolver.getAllRules(args.exportedDeps))), javacOptions, DependencyMode.TRANSITIVE, /* forceFinalResourceIds */
    true, /* resourceUnionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), args.useOldStyleableFormat);
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        if (params.getBuildTarget().getFlavors().contains(AndroidLibraryGraphEnhancer.DUMMY_R_DOT_JAVA_FLAVOR)) {
            return graphEnhancer.getBuildableForAndroidResourcesAbi(resolver, ruleFinder);
        }
        BuildTarget testTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule testRule = resolver.requireRule(testTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
    }
    ImmutableList<String> vmArgs = args.vmArgs;
    Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(resolver, /* createBuildableIfEmpty */
    true);
    ImmutableSet<Either<SourcePath, Path>> additionalClasspathEntries = ImmutableSet.of();
    if (dummyRDotJava.isPresent()) {
        additionalClasspathEntries = ImmutableSet.of(Either.ofLeft(dummyRDotJava.get().getSourcePathToOutput()));
        ImmutableSortedSet<BuildRule> newExtraDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).add(dummyRDotJava.get()).build();
        params = params.copyReplacingExtraDeps(Suppliers.ofInstance(newExtraDeps));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, ruleFinder, cxxPlatform);
    params = cxxLibraryEnhancement.updatedParams;
    // Rewrite dependencies on tests to actually depend on the code which backs the test.
    BuildRuleParams testsLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps)))).build()), Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).build())).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
    JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig, /* postprocessClassesCommands */
    ImmutableList.of(), /* exportDeps */
    ImmutableSortedSet.of(), /* providedDeps */
    resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), javacOptions.trackClassUsage(), additionalClasspathEntries, new JavacToJarStepFactory(javacOptions, new BootClasspathAppender()), args.resourcesRoot, args.manifestFile, args.mavenCoords, /* tests */
    ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of()));
    return new RobolectricTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), ruleFinder, testsLibrary, additionalClasspathEntries, args.labels, args.contacts, TestType.JUNIT, javaOptions, vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment, dummyRDotJava, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel, args.stdErrLogLevel, args.robolectricRuntimeDependency, args.robolectricManifest);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavacToJarStepFactory(com.facebook.buck.jvm.java.JavacToJarStepFactory) Optional(java.util.Optional) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) Either(com.facebook.buck.model.Either) JavaTestDescription(com.facebook.buck.jvm.java.JavaTestDescription) BuildRule(com.facebook.buck.rules.BuildRule)

Example 4 with DefaultJavaLibrary

use of com.facebook.buck.jvm.java.DefaultJavaLibrary in project buck by facebook.

the class KnownBuildRuleTypesTest method whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey.

@Test
public void whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey() throws Exception {
    final Path javac;
    if (Platform.detect() == Platform.WINDOWS) {
        javac = Paths.get("C:/Windows/system32/rundll32.exe");
    } else {
        javac = temporaryFolder.newExecutableFile();
    }
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("tools", ImmutableMap.of("javac", javac.toString()));
    BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(sections).build();
    KnownBuildRuleTypes buildRuleTypes = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(filesystem, environment);
    DefaultJavaLibrary libraryRule = createJavaLibrary(buildRuleTypes);
    ProcessExecutor processExecutor = createExecutor(javac.toString(), "fakeVersion 0.1");
    KnownBuildRuleTypes configuredBuildRuleTypes = KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, processExecutor, new FakeAndroidDirectoryResolver()).build();
    DefaultJavaLibrary configuredRule = createJavaLibrary(configuredBuildRuleTypes);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(javac, MorePaths.asByteSource(javac).hash(Hashing.sha1())));
    RuleKey configuredKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(configuredRule);
    RuleKey libraryKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(libraryRule);
    assertNotEquals(libraryKey, configuredKey);
}
Also used : Path(java.nio.file.Path) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 5 with DefaultJavaLibrary

use of com.facebook.buck.jvm.java.DefaultJavaLibrary in project buck by facebook.

the class KnownBuildRuleTypesTest method createJavaLibrary.

private DefaultJavaLibrary createJavaLibrary(KnownBuildRuleTypes buildRuleTypes) throws NoSuchBuildTargetException {
    JavaLibraryDescription description = (JavaLibraryDescription) buildRuleTypes.getDescription(Description.getBuildRuleType(JavaLibraryDescription.class));
    JavaLibraryDescription.Arg arg = new JavaLibraryDescription.Arg();
    populateJavaArg(arg);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    return (DefaultJavaLibrary) description.createBuildRule(TargetGraph.EMPTY, buildRuleParams, resolver, arg);
}
Also used : JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary)

Aggregations

DefaultJavaLibrary (com.facebook.buck.jvm.java.DefaultJavaLibrary)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)8 BuildTarget (com.facebook.buck.model.BuildTarget)7 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)6 BuildRule (com.facebook.buck.rules.BuildRule)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 JavacOptions (com.facebook.buck.jvm.java.JavacOptions)3 Optional (java.util.Optional)3 Test (org.junit.Test)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 FakeJavaLibrary (com.facebook.buck.jvm.java.FakeJavaLibrary)2 JavaTest (com.facebook.buck.jvm.java.JavaTest)2 JavaTestDescription (com.facebook.buck.jvm.java.JavaTestDescription)2 JavacToJarStepFactory (com.facebook.buck.jvm.java.JavacToJarStepFactory)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)2 Tool (com.facebook.buck.rules.Tool)2 ImmutableMap (com.google.common.collect.ImmutableMap)2