use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class SourceToTargetMapImpl method computeSourceToTargetMap.
@SuppressWarnings("unused")
private static ImmutableMultimap<File, TargetKey> computeSourceToTargetMap(Project project, BlazeProjectData blazeProjectData) {
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
ImmutableMultimap.Builder<File, TargetKey> sourceToTargetMap = ImmutableMultimap.builder();
for (TargetIdeInfo target : blazeProjectData.targetMap.targets()) {
TargetKey key = target.key;
for (ArtifactLocation sourceArtifact : target.sources) {
sourceToTargetMap.put(artifactLocationDecoder.decode(sourceArtifact), key);
}
}
return sourceToTargetMap.build();
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeGoBinaryConfigurationProducer method getTargetLabel.
@Nullable
private static TargetInfo getTargetLabel(PsiFile psiFile) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(psiFile.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
VirtualFile vf = psiFile.getVirtualFile();
if (vf == null) {
return null;
}
File file = new File(vf.getPath());
return SourceToTargetMap.getInstance(psiFile.getProject()).getRulesForSourceFile(file).stream().map(projectData.targetMap::get).filter(Objects::nonNull).filter(t -> t.kind.languageClass.equals(LanguageClass.GO)).filter(t -> t.kind.ruleType.equals(RuleType.BINARY)).map(TargetIdeInfo::toTargetInfo).findFirst().orElse(null);
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeGoTestLocator method getGoTestTarget.
@Nullable
private static TargetIdeInfo getGoTestTarget(Project project, String path) {
WorkspacePath targetPackage = WorkspacePath.createIfValid(PathUtil.getParentPath(path));
if (targetPackage == null) {
return null;
}
TargetName targetName = TargetName.createIfValid(PathUtil.getFileName(path));
if (targetName == null) {
return null;
}
Label label = Label.create(targetPackage, targetName);
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
return null;
}
TargetIdeInfo target = projectData.targetMap.get(TargetKey.forPlainTarget(label));
if (target != null && target.kind.languageClass.equals(LanguageClass.GO) && target.kind.ruleType.equals(RuleType.TEST)) {
return target;
}
return null;
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeGoTestLocator method findTestFunction.
/**
* @param path for function "TestFoo" in target "//foo/bar:baz" would be "foo/bar/baz::TestFoo".
* See {@link BlazeGoTestEventsHandler#testLocationUrl}.
*/
@SuppressWarnings("rawtypes")
private static List<Location> findTestFunction(Project project, String path) {
String[] parts = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER);
if (parts.length != 2) {
return ImmutableList.of();
}
String functionName = parts[1];
TargetIdeInfo target = getGoTestTarget(project, parts[0]);
List<VirtualFile> goFiles = getGoFiles(project, target);
if (goFiles.isEmpty()) {
return ImmutableList.of();
}
GlobalSearchScope scope = FilesScope.filesScope(project, goFiles);
Collection<GoFunctionDeclaration> functions = StubIndex.getElements(GoFunctionIndex.KEY, functionName, project, scope, GoFunctionDeclaration.class);
return functions.stream().map(PsiLocation::new).collect(Collectors.toList());
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class FastBuildServiceImpl method buildDeployJar.
private ListenableFuture<FastBuildState.BuildOutput> buildDeployJar(Label label, FastBuildParameters buildParameters) {
Label deployJarLabel = createDeployJarLabel(label);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
// TODO(plumpy): this assumes we're running this build as part of a run action. I try not to
// make that assumption anywhere else, so this should be supplied by the caller.
BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
AspectStrategy aspectStrategy = AspectStrategyProvider.findAspectStrategy(projectDataManager.getBlazeProjectData().blazeVersionData);
BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file));
ListenableFuture<BuildResult> buildResultFuture = ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {
@Override
protected BuildResult execute(BlazeContext context) {
context.push(new IssuesScope(project, /* focusProblemsViewOnIssue */
true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.blazeFlags()).addBlazeFlags(buildResultHelper.getBuildFlags());
List<String> outputGroups = new ArrayList<>();
// needed to retrieve the deploy jar
outputGroups.add("default");
outputGroups.addAll(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
aspectStrategy.addAspectAndOutputGroups(command, outputGroups);
int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
return BuildResult.fromExitCode(exitCode);
}
});
ListenableFuture<BuildOutput> buildOutputFuture = transform(buildResultFuture, result -> {
if (result.status != Status.SUCCESS) {
throw new RuntimeException("Blaze failure building deploy jar");
}
ImmutableList<File> deployJarArtifacts = buildResultHelper.getBuildArtifactsForTarget(deployJarLabel);
checkState(deployJarArtifacts.size() == 1);
File deployJar = deployJarArtifacts.get(0);
ImmutableList<File> ideInfoFiles = buildResultHelper.getArtifactsForOutputGroups(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
ImmutableMap<TargetKey, TargetIdeInfo> targetMap = ideInfoFiles.stream().map(file -> readTargetIdeInfo(aspectStrategy, file)).filter(Objects::nonNull).collect(toImmutableMap(ideInfo -> ideInfo.key, i -> i));
return BuildOutput.create(deployJar, new TargetMap(targetMap));
}, ConcurrencyUtil.getAppExecutorService());
buildOutputFuture.addListener(buildResultHelper::close, ConcurrencyUtil.getAppExecutorService());
return buildOutputFuture;
}
Aggregations