Search in sources :

Example 1 with SourceToTargetMap

use of com.google.idea.blaze.base.targetmaps.SourceToTargetMap in project intellij by bazelbuild.

the class SyncStatusHelper method isUnsynced.

static boolean isUnsynced(Project project, VirtualFile virtualFile) {
    if (!virtualFile.isInLocalFileSystem()) {
        return false;
    }
    if (ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile) == null) {
        return false;
    }
    OCWorkspace workspace = OCWorkspaceProvider.getWorkspace(project);
    if (!(workspace instanceof BlazeCWorkspace)) {
        // Skip if the project isn't a Blaze project or doesn't have C support enabled anyway.
        return false;
    }
    if (workspace.getConfigurations().isEmpty()) {
        // The workspace configurations may not have been loaded yet.
        return false;
    }
    SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
    return sourceToTargetMap.getRulesForSourceFile(VfsUtilCore.virtualToIoFile(virtualFile)).isEmpty();
}
Also used : SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) OCWorkspace(com.jetbrains.cidr.lang.workspace.OCWorkspace) BlazeCWorkspace(com.google.idea.blaze.cpp.BlazeCWorkspace)

Example 2 with SourceToTargetMap

use of com.google.idea.blaze.base.targetmaps.SourceToTargetMap in project intellij by bazelbuild.

the class BlazeConfigurationResolverResult method getConfigurationForFile.

@Nullable
OCResolveConfiguration getConfigurationForFile(VirtualFile sourceFile) {
    SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
    ImmutableCollection<TargetKey> targetsForSourceFile = sourceToTargetMap.getRulesForSourceFile(VfsUtilCore.virtualToIoFile(sourceFile));
    if (targetsForSourceFile.isEmpty()) {
        return null;
    }
    // If a source file is in two different targets, we can't possibly show how it will be
    // interpreted in both contexts at the same time in the IDE, so just pick the "first" target.
    TargetKey targetKey = targetsForSourceFile.stream().min(TargetKey::compareTo).orElse(null);
    Preconditions.checkNotNull(targetKey);
    return configurationMap.get(targetKey);
}
Also used : SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Nullable(javax.annotation.Nullable)

Example 3 with SourceToTargetMap

use of com.google.idea.blaze.base.targetmaps.SourceToTargetMap in project intellij by bazelbuild.

the class BlazeRenderErrorContributor method reportResourceTargetShouldDependOnClassTarget.

/**
 * Blaze doesn't resolve class dependencies from resources until building the final
 * android_binary, so we could end up with resources that ultimately build correctly, but fail to
 * find their class dependencies during rendering in the layout editor.
 */
private void reportResourceTargetShouldDependOnClassTarget(TargetIdeInfo target, TargetMap targetMap, ArtifactLocationDecoder decoder) {
    Collection<String> missingClasses = logger.getMissingClasses();
    if (missingClasses == null || missingClasses.isEmpty()) {
        return;
    }
    // Sorted entries for deterministic error message.
    SortedSetMultimap<String, TargetKey> missingClassToTargetMap = TreeMultimap.create();
    SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
    ImmutableCollection transitiveDependencies = TransitiveDependencyMap.getInstance(project).getTransitiveDependencies(target.key);
    for (String missingClass : missingClasses) {
        File sourceFile = getSourceFileForClass(missingClass);
        if (sourceFile == null) {
            continue;
        }
        ImmutableCollection<TargetKey> sourceTargets = sourceToTargetMap.getRulesForSourceFile(sourceFile);
        if (sourceTargets.stream().noneMatch(sourceTarget -> sourceTarget.equals(target.key) || transitiveDependencies.contains(sourceTarget))) {
            missingClassToTargetMap.putAll(missingClass, sourceTargets);
        }
    }
    if (missingClassToTargetMap.isEmpty()) {
        return;
    }
    HtmlBuilder builder = new HtmlBuilder();
    addTargetLink(builder, target, decoder).add(" contains resource files that reference these classes:").beginList();
    for (String missingClass : missingClassToTargetMap.keySet()) {
        builder.listItem().addLink(missingClass, getLinkManager().createOpenClassUrl(missingClass)).add(" from ");
        for (TargetKey targetKey : missingClassToTargetMap.get(missingClass)) {
            addTargetLink(builder, targetMap.get(targetKey), decoder).add(" ");
        }
    }
    builder.endList().add("Please fix your dependencies so that ");
    addTargetLink(builder, target, decoder).add(" correctly depends on these classes, ").addLink("then ", "sync the project", " ", getLinkManager().createSyncProjectUrl()).addLink("and ", "refresh the layout", ".", getLinkManager().createRefreshRenderUrl()).newline().newline().addBold("NOTE: blaze can still build with the incorrect dependencies " + "due to the way it handles resources, " + "but the layout editor needs them to be correct.");
    addIssue().setSeverity(HighlightSeverity.ERROR, // Reported above missing classes.
    HIGH_PRIORITY + 1).setSummary("Missing class dependencies").setHtmlContent(builder).build();
}
Also used : SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) ImmutableCollection(com.google.common.collect.ImmutableCollection) HtmlBuilder(com.android.utils.HtmlBuilder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File)

Aggregations

SourceToTargetMap (com.google.idea.blaze.base.targetmaps.SourceToTargetMap)3 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)2 HtmlBuilder (com.android.utils.HtmlBuilder)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 BlazeCWorkspace (com.google.idea.blaze.cpp.BlazeCWorkspace)1 OCWorkspace (com.jetbrains.cidr.lang.workspace.OCWorkspace)1 File (java.io.File)1 Nullable (javax.annotation.Nullable)1