Search in sources :

Example 11 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.

the class ProgressEstimatorTest method testUpdatesStorageWithProjectGenerationEstimationsAfterCommandInvocation.

@Test
public void testUpdatesStorageWithProjectGenerationEstimationsAfterCommandInvocation() throws IOException {
    Path storagePath = getStorageForTest();
    Map<String, Object> storageContents = ImmutableSortedMap.<String, Object>naturalOrder().put("project arg1 arg2", ImmutableSortedMap.<String, Number>naturalOrder().put(ProgressEstimator.EXPECTED_NUMBER_OF_GENERATED_PROJECT_FILES, 10).build()).build();
    String contents = MAPPER.writeValueAsString(storageContents);
    Files.write(storagePath, contents.getBytes(StandardCharsets.UTF_8));
    // path is 2 levels up folder
    ProgressEstimator estimator = new ProgressEstimator(storagePath, getBuckEventBus(), MAPPER);
    estimator.setCurrentCommand("project", ImmutableList.of("arg1", "arg2"));
    estimator.didGenerateProjectForTarget();
    estimator.didGenerateProjectForTarget();
    estimator.didGenerateProjectForTarget();
    estimator.didFinishProjectGeneration();
    Map<String, Map<String, Number>> jsonObject = MAPPER.readValue(Files.readAllBytes(storagePath), new TypeReference<HashMap<String, Map<String, Number>>>() {
    });
    Map<String, Number> storedValues = jsonObject.get("project arg1 arg2");
    assertThat(storedValues.get(ProgressEstimator.EXPECTED_NUMBER_OF_GENERATED_PROJECT_FILES).intValue(), Matchers.equalTo(3));
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Test(org.junit.Test)

Example 12 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project bazel by bazelbuild.

the class CcIncLibrary method create.

@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws RuleErrorException, InterruptedException {
    CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":cc_toolchain");
    FeatureConfiguration featureConfiguration = CcCommon.configureFeatures(ruleContext, ccToolchain);
    PathFragment packageFragment = ruleContext.getPackageDirectory();
    // The rule needs a unique location for the include directory, which doesn't conflict with any
    // other rule. For that reason, the include directory is at:
    // configuration/package_name/_/target_name
    // And then the symlink is placed at:
    // configuration/package_name/_/target_name/package_name
    // So that these inclusions can be resolved correctly:
    // #include "package_name/a.h"
    //
    // The target of the symlink is:
    // package_name/targetPrefix/
    // All declared header files must be below that directory.
    String expandedIncSymlinkAttr = ruleContext.attributes().get("prefix", Type.STRING);
    // We use an additional "_" directory here to avoid conflicts between this and previous Blaze
    // versions. Previous Blaze versions created a directory symlink; the new version does not
    // detect that the output directory isn't a directory, and tries to put the symlinks into what
    // is actually a symlink into the source tree.
    PathFragment includeDirectory = new PathFragment("_").getRelative(ruleContext.getTarget().getName());
    Root configIncludeDirectory = ruleContext.getConfiguration().getIncludeDirectory(ruleContext.getRule().getRepository());
    PathFragment includePath = configIncludeDirectory.getExecPath().getRelative(packageFragment).getRelative(includeDirectory);
    Path includeRoot = configIncludeDirectory.getPath().getRelative(packageFragment).getRelative(includeDirectory);
    // For every source artifact, we compute a virtual artifact that is below the include directory.
    // These are used for include checking.
    PathFragment prefixFragment = packageFragment.getRelative(expandedIncSymlinkAttr);
    if (!prefixFragment.isNormalized()) {
        ruleContext.attributeWarning("prefix", "should not contain '.' or '..' elements");
    }
    ImmutableSortedMap.Builder<Artifact, Artifact> virtualArtifactMapBuilder = ImmutableSortedMap.orderedBy(Artifact.EXEC_PATH_COMPARATOR);
    prefixFragment = prefixFragment.normalize();
    ImmutableList<Artifact> hdrs = ruleContext.getPrerequisiteArtifacts("hdrs", Mode.TARGET).list();
    for (Artifact src : hdrs) {
        // All declared header files must start with package/targetPrefix.
        if (!src.getRootRelativePath().startsWith(prefixFragment)) {
            ruleContext.attributeError("hdrs", src + " does not start with '" + prefixFragment.getPathString() + "'");
            return null;
        }
        // Remove the targetPrefix from within the exec path of the source file, and prepend the
        // unique directory prefix, e.g.:
        // third_party/foo/1.2/bar/a.h -> third_party/foo/name/third_party/foo/bar/a.h
        PathFragment suffix = src.getRootRelativePath().relativeTo(prefixFragment);
        PathFragment virtualPath = includeDirectory.getRelative(packageFragment).getRelative(suffix);
        // These virtual artifacts have the symlink action as generating action.
        Artifact virtualArtifact = ruleContext.getPackageRelativeArtifact(virtualPath, configIncludeDirectory);
        virtualArtifactMapBuilder.put(virtualArtifact, src);
    }
    ImmutableSortedMap<Artifact, Artifact> virtualArtifactMap = virtualArtifactMapBuilder.build();
    ruleContext.registerAction(new CreateIncSymlinkAction(ruleContext.getActionOwner(), virtualArtifactMap, includeRoot));
    FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
    CcLibraryHelper.Info info = new CcLibraryHelper(ruleContext, semantics, featureConfiguration, ccToolchain, fdoSupport).addIncludeDirs(Arrays.asList(includePath)).addPublicHeaders(virtualArtifactMap.keySet()).addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET)).build();
    // cc_inc_library doesn't compile any file - no compilation outputs available.
    InstrumentedFilesProvider instrumentedFilesProvider = new CcCommon(ruleContext).getInstrumentedFilesProvider(new ArrayList<Artifact>(), /*withBaselineCoverage=*/
    true);
    return new RuleConfiguredTargetBuilder(ruleContext).addProviders(info.getProviders()).addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME, new CcSkylarkApiProvider()).addOutputGroups(info.getOutputGroups()).add(InstrumentedFilesProvider.class, instrumentedFilesProvider).add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)).build();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Root(com.google.devtools.build.lib.actions.Root) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) RunfilesProvider(com.google.devtools.build.lib.analysis.RunfilesProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)

Example 13 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project gradle by gradle.

the class AbstractNamedFileSnapshotTaskStateChanges method buildSnapshots.

protected static ImmutableSortedMap<String, FileCollectionSnapshot> buildSnapshots(String taskName, FileCollectionSnapshotterRegistry snapshotterRegistry, String title, SortedSet<? extends TaskFilePropertySpec> fileProperties) {
    ImmutableSortedMap.Builder<String, FileCollectionSnapshot> builder = ImmutableSortedMap.naturalOrder();
    for (TaskFilePropertySpec propertySpec : fileProperties) {
        FileCollectionSnapshot result;
        try {
            FileCollectionSnapshotter snapshotter = snapshotterRegistry.getSnapshotter(propertySpec.getSnapshotter());
            result = snapshotter.snapshot(propertySpec.getPropertyFiles(), propertySpec.getCompareStrategy(), propertySpec.getSnapshotNormalizationStrategy());
        } catch (UncheckedIOException e) {
            throw new UncheckedIOException(String.format("Failed to capture snapshot of %s files for task '%s' property '%s' during up-to-date check.", title.toLowerCase(), taskName, propertySpec.getPropertyName()), e);
        }
        builder.put(propertySpec.getPropertyName(), result);
    }
    return builder.build();
}
Also used : FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot) TaskFilePropertySpec(org.gradle.api.internal.tasks.TaskFilePropertySpec) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) UncheckedIOException(org.gradle.api.UncheckedIOException) FileCollectionSnapshotter(org.gradle.api.internal.changedetection.state.FileCollectionSnapshotter)

Example 14 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project gerrit by GerritCodeReview.

the class ChangeNotes method getPatchSets.

public ImmutableSortedMap<PatchSet.Id, PatchSet> getPatchSets() {
    if (patchSets == null) {
        ImmutableSortedMap.Builder<PatchSet.Id, PatchSet> b = ImmutableSortedMap.orderedBy(comparing(PatchSet.Id::get));
        for (Map.Entry<PatchSet.Id, PatchSet> e : state.patchSets()) {
            b.put(e.getKey(), new PatchSet(e.getValue()));
        }
        patchSets = b.build();
    }
    return patchSets;
}
Also used : ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 15 with ImmutableSortedMap

use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.

the class TargetsCommand method getMatchingNodes.

/**
   * @param graph Graph used to resolve dependencies between targets and find all build files.
   * @param referencedFiles If present, the result will be limited to the nodes that transitively
   *                        depend on at least one of those.
   * @param matchingBuildTargets If present, the result will be limited to the specified targets.
   * @param buildRuleTypes If present, the result will be limited to targets with the specified
   *                       types.
   * @param detectTestChanges If true, tests are considered to be dependencies of the targets they
   *                          are testing.
   * @return A map of target names to target nodes.
   */
@VisibleForTesting
ImmutableSortedMap<String, TargetNode<?, ?>> getMatchingNodes(TargetGraph graph, Optional<ImmutableSet<Path>> referencedFiles, final Optional<ImmutableSet<BuildTarget>> matchingBuildTargets, final Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses, boolean detectTestChanges, String buildFileName) {
    ImmutableSet<TargetNode<?, ?>> directOwners;
    if (referencedFiles.isPresent()) {
        BuildFileTree buildFileTree = new InMemoryBuildFileTree(graph.getNodes().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
        directOwners = FluentIterable.from(graph.getNodes()).filter(new DirectOwnerPredicate(buildFileTree, referencedFiles.get(), buildFileName)).toSet();
    } else {
        directOwners = graph.getNodes();
    }
    Iterable<TargetNode<?, ?>> selectedReferrers = FluentIterable.from(getDependentNodes(graph, directOwners, detectTestChanges)).filter(targetNode -> {
        if (matchingBuildTargets.isPresent() && !matchingBuildTargets.get().contains(targetNode.getBuildTarget())) {
            return false;
        }
        if (descriptionClasses.isPresent() && !descriptionClasses.get().contains(targetNode.getDescription().getClass())) {
            return false;
        }
        return true;
    });
    ImmutableSortedMap.Builder<String, TargetNode<?, ?>> matchingNodesBuilder = ImmutableSortedMap.naturalOrder();
    for (TargetNode<?, ?> targetNode : selectedReferrers) {
        matchingNodesBuilder.put(targetNode.getBuildTarget().getFullyQualifiedName(), targetNode);
    }
    return matchingNodesBuilder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) InMemoryBuildFileTree(com.facebook.buck.model.InMemoryBuildFileTree) BuildFileTree(com.facebook.buck.model.BuildFileTree) InMemoryBuildFileTree(com.facebook.buck.model.InMemoryBuildFileTree) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)24 Map (java.util.Map)13 SourcePath (com.facebook.buck.rules.SourcePath)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 Path (java.nio.file.Path)10 PathSourcePath (com.facebook.buck.rules.PathSourcePath)8 BuildTarget (com.facebook.buck.model.BuildTarget)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 HashMap (java.util.HashMap)7 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)6 NSString (com.dd.plist.NSString)5 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 BuildRule (com.facebook.buck.rules.BuildRule)4 TargetNode (com.facebook.buck.rules.TargetNode)4 ImmutableList (com.google.common.collect.ImmutableList)4 HeaderMap (com.facebook.buck.apple.clang.HeaderMap)3 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)3 ImmutableSet (com.google.common.collect.ImmutableSet)3