Example usage for com.google.common.collect ImmutableSortedSet of

List of usage examples for com.google.common.collect ImmutableSortedSet of

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet of.

Prototype

@SuppressWarnings("unchecked")
    public static <E> ImmutableSortedSet<E> of() 

Source Link

Usage

From source file:com.facebook.buck.apple.AppleDescriptions.java

public static Optional<SceneKitAssets> createBuildRulesForSceneKitAssetsDependencies(TargetGraph targetGraph,
        BuildRuleParams params, AppleCxxPlatform appleCxxPlatform) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());

    ImmutableSet<AppleWrapperResourceArg> sceneKitAssetsArgs = AppleBuildRules.collectTransitiveBuildRules(
            targetGraph, Optional.empty(), AppleBuildRules.SCENEKIT_ASSETS_DESCRIPTION_CLASSES,
            ImmutableList.of(targetNode));

    BuildRuleParams sceneKitAssetsParams = params.copyWithChanges(
            params.getBuildTarget().withAppendedFlavors(SceneKitAssets.FLAVOR),
            Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));

    if (sceneKitAssetsArgs.isEmpty()) {
        return Optional.empty();
    } else {/*from   ww w .  j  a v  a2  s .c  o m*/
        return Optional.of(new SceneKitAssets(sceneKitAssetsParams, appleCxxPlatform,
                sceneKitAssetsArgs.stream()
                        .map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path))
                        .collect(MoreCollectors.toImmutableSet())));
    }
}

From source file:com.facebook.buck.cxx.CxxLibraryDescription.java

/**
 * Create all build rules needed to generate the static library.
 *
 * @return build rule that builds the static library version of this C/C++ library.
 *//*from  ww w .j  av a 2s  . co  m*/
private static BuildRule createStaticLibraryBuildRule(BuildRuleParams params, BuildRuleResolver resolver,
        CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, Arg args, CxxSourceRuleFactory.PicType pic)
        throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);

    // Create rules for compiling the object files.
    ImmutableMap<CxxPreprocessAndCompile, SourcePath> objects = CxxDescriptionEnhancer.requireObjects(params,
            resolver, sourcePathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, pic, args);

    // Write a build rule to create the archive for this C/C++ library.
    BuildTarget staticTarget = CxxDescriptionEnhancer.createStaticLibraryBuildTarget(params.getBuildTarget(),
            cxxPlatform.getFlavor(), pic);

    if (objects.isEmpty()) {
        return new NoopBuildRule(new BuildRuleParams(staticTarget,
                Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()),
                params.getProjectFilesystem(), params.getCellRoots()), sourcePathResolver);
    }

    Path staticLibraryPath = CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(),
            params.getBuildTarget(), cxxPlatform.getFlavor(), pic, cxxPlatform.getStaticLibraryExtension());
    return Archive.from(staticTarget, params, sourcePathResolver, ruleFinder, cxxPlatform,
            cxxBuckConfig.getArchiveContents(), staticLibraryPath, ImmutableList.copyOf(objects.values()));
}

From source file:com.facebook.buck.cxx.AbstractCxxSourceRuleFactory.java

private CxxInferCapture createInferCaptureBuildRule(BuildTarget target, String name, CxxSource source,
        InferBuckConfig inferConfig) {//from  w  ww . j a v  a 2  s  . com
    Preconditions.checkArgument(CxxSourceTypes.isPreprocessableType(source.getType()));

    LOG.verbose("Creating preprocessed InferCapture build rule %s for %s", target, source);

    DepsBuilder depsBuilder = new DepsBuilder(getRuleFinder());
    depsBuilder.add(requireAggregatedPreprocessDepsRule());

    PreprocessorDelegateCacheValue preprocessorDelegateValue = preprocessorDelegates
            .getUnchecked(PreprocessorDelegateCacheKey.of(source.getType(), source.getFlags()));
    depsBuilder.add(preprocessorDelegateValue.getPreprocessorDelegate());

    CxxToolFlags ppFlags = CxxToolFlags.copyOf(
            CxxSourceTypes.getPlatformPreprocessFlags(getCxxPlatform(), source.getType()),
            preprocessorFlags.getUnchecked(source.getType()));

    CxxToolFlags cFlags = computeCompilerFlags(source.getType(), source.getFlags());

    depsBuilder.add(source);

    CxxInferCapture result = new CxxInferCapture(
            getParams().copyWithChanges(target, Suppliers.ofInstance(depsBuilder.build()),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            getPathResolver(), ppFlags, cFlags, source.getPath(), source.getType(),
            getCompileOutputPath(target, name), preprocessorDelegateValue.getPreprocessorDelegate(),
            inferConfig, getCxxPlatform().getCompilerDebugPathSanitizer());
    getResolver().addToIndex(result);
    return result;
}

From source file:com.facebook.buck.jvm.java.autodeps.JavaDepsFinder.java

private Symbols getJavaFileFeatures(TargetNode<?, ?> node, boolean shouldRecordRequiredSymbols) {
    // Build a JavaLibrarySymbolsFinder to create the JavaFileFeatures. By making use of Buck's
    // build cache, we can often avoid running a Java parser.
    BuildTarget buildTarget = node.getBuildTarget();
    Object argForNode = node.getConstructorArg();
    JavaSymbolsRule.SymbolsFinder symbolsFinder;
    ImmutableSortedSet<String> generatedSymbols;
    if (argForNode instanceof JavaLibraryDescription.Arg) {
        JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) argForNode;
        // The build target should be recorded as a provider for every symbol in its
        // generated_symbols set (if it exists). It is common to use this for symbols that are
        // generated via annotation processors.
        generatedSymbols = arg.generatedSymbols;
        symbolsFinder = new JavaLibrarySymbolsFinder(arg.srcs, javaFileParser, shouldRecordRequiredSymbols);
    } else {/*w  w  w . j a va 2s .  c  om*/
        PrebuiltJarDescription.Arg arg = (PrebuiltJarDescription.Arg) argForNode;
        generatedSymbols = ImmutableSortedSet.of();
        symbolsFinder = new PrebuiltJarSymbolsFinder(arg.binaryJar);
    }

    // Build the rule, leveraging Buck's build cache.
    JavaSymbolsRule buildRule = new JavaSymbolsRule(buildTarget, symbolsFinder, generatedSymbols, objectMapper,
            node.getFilesystem());
    ListenableFuture<BuildResult> future = buildEngine.build(buildContext, executionContext, buildRule);
    BuildResult result = Futures.getUnchecked(future);

    Symbols features;
    if (result.getSuccess() != null) {
        features = buildRule.getFeatures();
    } else {
        Throwable failure = result.getFailure();
        Preconditions.checkNotNull(failure);
        throw new RuntimeException("Failed to extract Java symbols for " + buildTarget, failure);
    }
    return features;
}

From source file:com.facebook.buck.parser.PythonDslProjectBuildFileParser.java

@VisibleForTesting
protected BuildFileManifest getAllRulesInternal(Path buildFile) throws IOException, BuildFileParseException {
    ensureNotClosed();/* w ww  .j a  va 2 s.  c o m*/
    initIfNeeded();

    // Check isInitialized implications (to avoid Eradicate warnings).
    Objects.requireNonNull(buckPyProcess);
    Objects.requireNonNull(buckPyProcessInput);
    long alreadyReadBytes = buckPyProcessInput.getCount();

    ParseBuckFileEvent.Started parseBuckFileStarted = ParseBuckFileEvent.started(buildFile, this.getClass());
    buckEventBus.post(parseBuckFileStarted);

    ImmutableList<Map<String, Object>> values = ImmutableList.of();
    Optional<String> profile = Optional.empty();
    try (AssertScopeExclusiveAccess.Scope scope = assertSingleThreadedParsing.scope()) {
        Path cellPath = options.getProjectRoot().toAbsolutePath();
        String watchRoot = cellPath.toString();
        String projectPrefix = "";
        if (options.getWatchman().getProjectWatches().containsKey(cellPath)) {
            ProjectWatch projectWatch = options.getWatchman().getProjectWatches().get(cellPath);
            watchRoot = projectWatch.getWatchRoot();
            if (projectWatch.getProjectPrefix().isPresent()) {
                projectPrefix = projectWatch.getProjectPrefix().get();
            }
        }
        currentBuildFile.set(buildFile);
        BuildFilePythonResult resultObject = performJsonRequest(
                ImmutableMap.of("buildFile", buildFile.toString(), "watchRoot", watchRoot, "projectPrefix",
                        projectPrefix, "packageImplicitLoad",
                        packageImplicitIncludeFinder.findIncludeForBuildFile(getBasePath(buildFile))));
        Path buckPyPath = getPathToBuckPy(options.getDescriptions());
        handleDiagnostics(buildFile, buckPyPath.getParent(), resultObject.getDiagnostics(), buckEventBus);
        values = resultObject.getValues();

        LOG.verbose("Got rules: %s", values);
        LOG.verbose("Parsed %d rules from %s", values.size(), buildFile);
        profile = resultObject.getProfile();
        if (profile.isPresent()) {
            LOG.debug("Profile result:\n%s", profile.get());
        }
        if (values.isEmpty()) {
            // in case Python process cannot send values due to serialization issues, it will send an
            // empty list
            return BuildFileManifest.of(ImmutableMap.of(), ImmutableSortedSet.of(), ImmutableMap.of(),
                    Optional.empty(), ImmutableList.of());
        }
        return toBuildFileManifest(values);
    } finally {
        long parsedBytes = buckPyProcessInput.getCount() - alreadyReadBytes;
        processedBytes.ifPresent(processedBytes -> processedBytes.addAndGet(parsedBytes));
        buckEventBus
                .post(ParseBuckFileEvent.finished(parseBuckFileStarted, values.size(), parsedBytes, profile));
    }
}

From source file:com.facebook.buck.apple.AppleDescriptions.java

static AppleDebuggableBinary createAppleDebuggableBinary(BuildRuleParams params, BuildRuleResolver resolver,
        BuildRule strippedBinaryRule, ProvidesLinkedBinaryDeps unstrippedBinaryRule,
        AppleDebugFormat debugFormat, FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,
        CxxPlatform defaultCxxPlatform, FlavorDomain<AppleCxxPlatform> appleCxxPlatforms) {
    Optional<AppleDsym> appleDsym = createAppleDsymForDebugFormat(debugFormat, params, resolver,
            unstrippedBinaryRule, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
    BuildRule buildRuleForDebugFormat;/*from   w w w .  j  a va2 s.  c  o m*/
    if (debugFormat == AppleDebugFormat.DWARF) {
        buildRuleForDebugFormat = unstrippedBinaryRule;
    } else {
        buildRuleForDebugFormat = strippedBinaryRule;
    }
    AppleDebuggableBinary rule = new AppleDebuggableBinary(
            params.copyWithChanges(
                    strippedBinaryRule.getBuildTarget().withAppendedFlavors(AppleDebuggableBinary.RULE_FLAVOR,
                            debugFormat.getFlavor()),
                    Suppliers.ofInstance(AppleDebuggableBinary.getRequiredRuntimeDeps(debugFormat,
                            strippedBinaryRule, unstrippedBinaryRule, appleDsym)),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            new SourcePathResolver(new SourcePathRuleFinder(resolver)), buildRuleForDebugFormat);
    return rule;
}

From source file:com.google.template.soy.jssrc.internal.GenJsCodeVisitor.java

/**
 * Helper for visitSoyFileNode(SoyFileNode) to add code to require general dependencies.
 * @param soyFile The node we're visiting.
 *//*from   ww w . j  ava 2s.  c om*/
private void addCodeToRequireGeneralDeps(SoyFileNode soyFile) {

    jsCodeBuilder.appendLine("goog.require('soy');");
    jsCodeBuilder.appendLine("goog.require('soydata');");

    SortedSet<String> requiredObjectTypes = ImmutableSortedSet.of();
    if (hasStrictParams(soyFile)) {
        requiredObjectTypes = getRequiredObjectTypes(soyFile);
        jsCodeBuilder.appendLine("/** @suppress {extraRequire} */");
        jsCodeBuilder.appendLine("goog.require('goog.asserts');");
    }

    if (jsSrcOptions.getUseGoogIsRtlForBidiGlobalDir()) {
        jsCodeBuilder.appendLine("/** @suppress {extraRequire} */");
        jsCodeBuilder.appendLine("goog.require('", GOOG_IS_RTL_NAMESPACE, "');");
    }

    if (hasNodeTypes(soyFile, MsgPluralNode.class, MsgSelectNode.class)) {
        jsCodeBuilder.appendLine("goog.require('", GOOG_MESSAGE_FORMAT_NAMESPACE, "');");
    }

    if (hasNodeTypes(soyFile, XidNode.class)) {
        jsCodeBuilder.appendLine("goog.require('xid');");
    }

    SortedSet<String> pluginRequiredJsLibNames = Sets.newTreeSet();
    pluginRequiredJsLibNames.addAll(genDirectivePluginRequiresVisitor.exec(soyFile));
    pluginRequiredJsLibNames.addAll(genFunctionPluginRequiresVisitor.exec(soyFile));
    for (String namespace : pluginRequiredJsLibNames) {
        jsCodeBuilder.appendLine("goog.require('" + namespace + "');");
    }

    if (!requiredObjectTypes.isEmpty()) {
        jsCodeBuilder.appendLine();
        for (String requiredType : requiredObjectTypes) {
            jsCodeBuilder.appendLine("goog.require('" + requiredType + "');");
        }
    }
}

From source file:com.facebook.buck.apple.AppleDescriptions.java

static AppleDsym createAppleDsym(BuildRuleParams params, BuildRuleResolver resolver,
        ProvidesLinkedBinaryDeps unstrippedBinaryBuildRule, FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,
        CxxPlatform defaultCxxPlatform, FlavorDomain<AppleCxxPlatform> appleCxxPlatforms) {

    AppleCxxPlatform appleCxxPlatform = ApplePlatforms.getAppleCxxPlatformForBuildTarget(
            cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms,
            unstrippedBinaryBuildRule.getBuildTarget(),
            MultiarchFileInfos.create(appleCxxPlatforms, unstrippedBinaryBuildRule.getBuildTarget()));

    AppleDsym appleDsym = new AppleDsym(
            params.copyWithDeps(//from w  w  w  . ja va  2  s.c o  m
                    Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder()
                            .add(unstrippedBinaryBuildRule).addAll(unstrippedBinaryBuildRule.getCompileDeps())
                            .addAll(unstrippedBinaryBuildRule.getStaticLibraryDeps()).build()),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            new SourcePathResolver(new SourcePathRuleFinder(resolver)), appleCxxPlatform.getDsymutil(),
            appleCxxPlatform.getLldb(), new BuildTargetSourcePath(unstrippedBinaryBuildRule.getBuildTarget()),
            AppleDsym.getDsymOutputPath(params.getBuildTarget(), params.getProjectFilesystem()));
    resolver.addToIndex(appleDsym);
    return appleDsym;
}

From source file:com.facebook.buck.lua.LuaBinaryDescription.java

private SymlinkTree createSymlinkTree(BuildTarget linkTreeTarget, BuildRuleParams params,
        BuildRuleResolver resolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, Path root,
        ImmutableMap<String, SourcePath> components) {
    return resolver.addToIndex(SymlinkTree.from(params.copyWithChanges(linkTreeTarget,
            Suppliers.ofInstance(//from www . j a  v a 2  s  .  co m
                    ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(components.values()))),
            Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, root, components));
}

From source file:com.facebook.buck.cxx.AbstractCxxSourceRuleFactory.java

/**
 * @return a {@link CxxPreprocessAndCompile} rule that preprocesses, compiles, and assembles the
 * given {@link CxxSource}./*from   w  ww .ja  v  a 2  s  .  c  om*/
 */
@VisibleForTesting
public CxxPreprocessAndCompile createPreprocessAndCompileBuildRule(String name, CxxSource source) {

    BuildTarget target = createCompileBuildTarget(name);
    LOG.verbose("Creating preprocess and compile %s for %s", target, source);
    Preconditions.checkArgument(CxxSourceTypes.isPreprocessableType(source.getType()));

    DepsBuilder depsBuilder = new DepsBuilder(getRuleFinder());
    depsBuilder.add(requireAggregatedPreprocessDepsRule());

    CompilerDelegate compilerDelegate = new CompilerDelegate(getPathResolver(),
            getCxxPlatform().getCompilerDebugPathSanitizer(),
            CxxSourceTypes
                    .getCompiler(getCxxPlatform(), CxxSourceTypes.getPreprocessorOutputType(source.getType()))
                    .resolve(getResolver()),
            computeCompilerFlags(source.getType(), source.getFlags()));
    depsBuilder.add(compilerDelegate);

    PreprocessorDelegateCacheValue preprocessorDelegateValue = preprocessorDelegates
            .getUnchecked(PreprocessorDelegateCacheKey.of(source.getType(), source.getFlags()));
    PreprocessorDelegate preprocessorDelegate = preprocessorDelegateValue.getPreprocessorDelegate();
    depsBuilder.add(preprocessorDelegate);

    depsBuilder.add(source);

    Preprocessor preprocessor = preprocessorDelegate.getPreprocessor();

    if (getPrecompiledHeader().isPresent() && !canUsePrecompiledHeaders(getCxxBuckConfig(), preprocessor)) {
        throw new HumanReadableException(
                "Precompiled header was requested for this rule, but PCH's are not possible under "
                        + "the current environment (preprocessor/compiler, and/or 'cxx.pch_enabled' option).");
    }

    Optional<PrecompiledHeaderReference> precompiledHeaderReference = Optional.empty();
    if (canUsePrecompiledHeaders(getCxxBuckConfig(), preprocessor)
            && (getPrefixHeader().isPresent() || getPrecompiledHeader().isPresent())) {
        CxxPrecompiledHeader precompiledHeader = requirePrecompiledHeaderBuildRule(preprocessorDelegateValue,
                source);
        depsBuilder.add(precompiledHeader);
        precompiledHeaderReference = Optional.of(PrecompiledHeaderReference.of(precompiledHeader));
        if (getPrecompiledHeader().isPresent()) {
            // For a precompiled header (and not a prefix header), we may need extra include paths.
            // The PCH build might have involved some deps that this rule does not have, so we
            // would need to pull in its include paths to ensure any includes that happen during this
            // build play out the same way as they did for the PCH.
            try {
                preprocessorDelegate = preprocessorDelegate
                        .withLeadingIncludePaths(precompiledHeader.getCxxIncludePaths());
            } catch (PreprocessorDelegate.ConflictingHeadersException e) {
                throw e.getHumanReadableExceptionForBuildTarget(getParams().getBuildTarget());
            }
        }
    }

    // Build the CxxCompile rule and add it to our sorted set of build rules.
    CxxPreprocessAndCompile result = CxxPreprocessAndCompile.preprocessAndCompile(
            getParams().copyWithChanges(target, Suppliers.ofInstance(depsBuilder.build()),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            getPathResolver(), preprocessorDelegate, compilerDelegate, getCompileOutputPath(target, name),
            source.getPath(), source.getType(), precompiledHeaderReference,
            getCxxPlatform().getCompilerDebugPathSanitizer(), getCxxPlatform().getAssemblerDebugPathSanitizer(),
            getSandboxTree());
    getResolver().addToIndex(result);
    return result;
}