Search in sources :

Example 1 with JavacOptions

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

the class AndroidLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    if (params.getBuildTarget().getFlavors().contains(JavaLibrary.SRC_JAR)) {
        return new JavaSourceJar(params, args.srcs, args.mavenCoords);
    }
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
    final ImmutableSet.Builder<BuildRule> queriedDepsBuilder = ImmutableSet.builder();
    if (args.depsQuery.isPresent()) {
        queriedDepsBuilder.addAll(QueryUtils.resolveDepQuery(params, args.depsQuery.get(), resolver, targetGraph).collect(Collectors.toList()));
    }
    final ImmutableSet<BuildRule> queriedDeps = queriedDepsBuilder.build();
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(params.getBuildTarget(), params.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(queriedDeps).addAll(resolver.getAllRules(args.exportedDeps)).build())), javacOptions, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
    false, args.resourceUnionPackage, args.finalRName, false);
    boolean hasDummyRDotJavaFlavor = params.getBuildTarget().getFlavors().contains(DUMMY_R_DOT_JAVA_FLAVOR);
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        if (hasDummyRDotJavaFlavor) {
            return graphEnhancer.getBuildableForAndroidResourcesAbi(resolver, ruleFinder);
        }
        BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule libraryRule = resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
    }
    Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(resolver, /* createBuildableIfEmpty */
    hasDummyRDotJavaFlavor);
    if (hasDummyRDotJavaFlavor) {
        return dummyRDotJava.get();
    } else {
        ImmutableSet<Either<SourcePath, Path>> additionalClasspathEntries = ImmutableSet.of();
        if (dummyRDotJava.isPresent()) {
            additionalClasspathEntries = ImmutableSet.of(Either.ofLeft(dummyRDotJava.get().getSourcePathToOutput()));
            ImmutableSortedSet<BuildRule> newDeclaredDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).add(dummyRDotJava.get()).build();
            params = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(newDeclaredDeps), params.getExtraDeps());
        }
        AndroidLibraryCompiler compiler = compilerFactory.getCompiler(args.language.orElse(JvmLanguage.JAVA));
        ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
        ImmutableSortedSet.Builder<BuildRule> declaredDepsBuilder = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(queriedDeps).addAll(compiler.getDeclaredDeps(args, resolver));
        ImmutableSortedSet<BuildRule> declaredDeps = declaredDepsBuilder.build();
        ImmutableSortedSet<BuildRule> extraDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(declaredDeps, exportedDeps, resolver.getAllRules(args.providedDeps)))).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).addAll(compiler.getExtraDeps(args, resolver)).build();
        SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
        BuildRuleParams androidLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(declaredDeps), Suppliers.ofInstance(extraDeps));
        return new AndroidLibrary(androidLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), args.proguardConfig, args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, androidLibraryParams.getDeps()), additionalClasspathEntries, javacOptions, compiler.trackClassUsage(javacOptions), compiler.compileToJar(args, javacOptions, resolver), args.resourcesRoot, args.mavenCoords, args.manifest, args.tests);
    }
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ImmutableSet(com.google.common.collect.ImmutableSet) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) JavaSourceJar(com.facebook.buck.jvm.java.JavaSourceJar)

Example 2 with JavacOptions

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

the class ProjectCommand method writeProjectAndGetRequiredBuildTargets.

private ImmutableSet<BuildTarget> writeProjectAndGetRequiredBuildTargets(CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets) throws IOException {
    ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
    BuckConfig buckConfig = params.getBuckConfig();
    BuildRuleResolver ruleResolver = result.getResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    JavacOptions javacOptions = buckConfig.getView(JavaBuckConfig.class).getDefaultJavacOptions();
    IjProject project = new IjProject(targetGraphAndTargets, getJavaPackageFinder(buckConfig), JavaFileParser.createJavaFileParser(javacOptions), ruleResolver, sourcePathResolver, ruleFinder, params.getCell().getFilesystem(), getIntellijAggregationMode(buckConfig), buckConfig);
    return project.write(runIjCleaner, getRemoveUnusedLibraries(buckConfig), excludeArtifacts || getExcludeArtifactsFromConfig(buckConfig));
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) IjProject(com.facebook.buck.jvm.java.intellij.IjProject) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 3 with JavacOptions

use of com.facebook.buck.jvm.java.JavacOptions 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 JavacOptions

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

the class JavaDepsFinder method createJavaDepsFinder.

public static JavaDepsFinder createJavaDepsFinder(BuckConfig buckConfig, final CellPathResolver cellNames, ObjectMapper objectMapper, BuildEngineBuildContext buildContext, ExecutionContext executionContext, BuildEngine buildEngine) {
    Optional<String> javaPackageMappingOption = buckConfig.getValue(BUCK_CONFIG_SECTION, "java-package-mappings");
    ImmutableSortedMap<String, BuildTarget> javaPackageMapping;
    if (javaPackageMappingOption.isPresent()) {
        Stream<Map.Entry<String, BuildTarget>> entries = Splitter.on(',').omitEmptyStrings().withKeyValueSeparator("=>").split(javaPackageMappingOption.get()).entrySet().stream().map(entry -> {
            String originalKey = entry.getKey().trim();
            boolean appearsToBeJavaPackage = !originalKey.endsWith(".") && CharMatcher.javaUpperCase().matchesNoneOf(originalKey);
            String key = appearsToBeJavaPackage ? originalKey + "." : originalKey;
            BuildTarget buildTarget = BuildTargetParser.INSTANCE.parse(entry.getValue().trim(), BuildTargetPatternParser.fullyQualified(), cellNames);
            return Maps.immutableEntry(key, buildTarget);
        });
        javaPackageMapping = ImmutableSortedMap.copyOf((Iterable<Map.Entry<String, BuildTarget>>) entries::iterator, Comparator.reverseOrder());
    } else {
        javaPackageMapping = ImmutableSortedMap.of();
    }
    JavaBuckConfig javaBuckConfig = buckConfig.getView(JavaBuckConfig.class);
    JavacOptions javacOptions = javaBuckConfig.getDefaultJavacOptions();
    JavaFileParser javaFileParser = JavaFileParser.createJavaFileParser(javacOptions);
    return new JavaDepsFinder(javaPackageMapping, javaFileParser, objectMapper, buildContext, executionContext, buildEngine);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) JavaFileParser(com.facebook.buck.jvm.java.JavaFileParser) BuildTarget(com.facebook.buck.model.BuildTarget) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 5 with JavacOptions

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

the class IjModuleFactory method getSourceLevel.

private Optional<String> getSourceLevel(Iterable<TargetNode<?, ?>> targetNodes) {
    Optional<String> result = Optional.empty();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        if (!(targetNode.getDescription() instanceof JavaLibraryDescription)) {
            continue;
        }
        JavacOptions defaultJavacOptions = projectConfig.getJavaBuckConfig().getDefaultJavacOptions();
        String defaultSourceLevel = defaultJavacOptions.getSourceLevel();
        String defaultTargetLevel = defaultJavacOptions.getTargetLevel();
        JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) targetNode.getConstructorArg();
        if (!defaultSourceLevel.equals(arg.source.orElse(defaultSourceLevel)) || !defaultTargetLevel.equals(arg.target.orElse(defaultTargetLevel))) {
            result = arg.source;
        }
    }
    if (result.isPresent()) {
        result = Optional.of(JavaLanguageLevelHelper.normalizeSourceLevel(result.get()));
    }
    return result;
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg)

Aggregations

JavacOptions (com.facebook.buck.jvm.java.JavacOptions)14 BuildTarget (com.facebook.buck.model.BuildTarget)10 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 BuildRule (com.facebook.buck.rules.BuildRule)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)8 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)5 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 Optional (java.util.Optional)5 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)3 DefaultJavaLibrary (com.facebook.buck.jvm.java.DefaultJavaLibrary)3 JavaLibraryDescription (com.facebook.buck.jvm.java.JavaLibraryDescription)3 Flavor (com.facebook.buck.model.Flavor)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)3 Path (java.nio.file.Path)3 Test (org.junit.Test)3 JavaBuckConfig (com.facebook.buck.jvm.java.JavaBuckConfig)2 JavaOptions (com.facebook.buck.jvm.java.JavaOptions)2 Either (com.facebook.buck.model.Either)2