use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class WorkspaceHelper method resolveWorkspace.
@Nullable
private static Workspace resolveWorkspace(Project project, File absoluteFile) {
WorkspacePathResolver pathResolver = WorkspacePathResolverProvider.getInstance(project).getPathResolver();
if (pathResolver == null) {
return null;
}
// try project workspace first
WorkspaceRoot root = pathResolver.findWorkspaceRoot(absoluteFile);
if (root != null) {
return new Workspace(root, null);
}
Map<String, WorkspaceRoot> externalWorkspaces = getExternalWorkspaceRoots(project);
if (externalWorkspaces == null) {
return null;
}
for (Entry<String, WorkspaceRoot> entry : externalWorkspaces.entrySet()) {
root = entry.getValue();
WorkspacePath workspacePath = root.workspacePathForSafe(absoluteFile);
if (workspacePath != null) {
return new Workspace(root, entry.getKey());
}
}
return null;
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot 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;
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class BlazeApkBuildStepNormalBuild method build.
@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.BUILD);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, buildFlags);
BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
command.addTargets(getTargetToBuild()).addBlazeFlags("--output_groups=+android_deploy_info").addBlazeFlags(buildFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
FileCaches.refresh(project);
if (retVal != 0) {
context.setHasError();
return null;
}
deployInfo = deployInfoHelper.readDeployInfo(context);
if (deployInfo == null) {
IssueOutput.error("Could not read apk deploy info from build").submit(context);
}
return null;
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
try {
Futures.get(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
}
return context.shouldContinue();
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class ExternalWorkspaceReferenceFragment method resolveProjectWorkspaceFile.
@Nullable
private static BuildFile resolveProjectWorkspaceFile(Project project) {
WorkspaceRoot projectRoot = WorkspaceRoot.fromProjectSafe(project);
if (projectRoot == null) {
return null;
}
PsiFileSystemItem workspaceFile = BuildReferenceManager.getInstance(project).resolveFile(projectRoot.fileForPath(new WorkspacePath("WORKSPACE")));
return ObjectUtils.tryCast(workspaceFile, BuildFile.class);
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class DeprecatedLoadQuickFix method fixLoadString.
private static void fixLoadString(Project project, StringLiteral importString) {
String contents = importString.getStringContents();
if (!contents.startsWith("/") || LabelUtils.isAbsolute(contents)) {
return;
}
WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(project);
if (root == null) {
return;
}
WorkspacePath workspacePath = WorkspacePath.createIfValid(contents.substring(1));
if (workspacePath == null) {
return;
}
File file = root.fileForPath(workspacePath);
File parentPackageFile = findContainingPackage(project, file);
if (parentPackageFile == null) {
return;
}
WorkspacePath packagePath = root.workspacePathForSafe(parentPackageFile);
if (packagePath == null) {
return;
}
String relativePath = Paths.relativeIfUnder(workspacePath.relativePath(), packagePath.relativePath());
if (relativePath == null) {
return;
}
String newString = "//" + packagePath + ":" + relativePath + ".bzl";
ASTNode node = importString.getNode();
node.replaceChild(node.getFirstChildNode(), PsiUtils.createNewLabel(importString.getProject(), newString));
}
Aggregations