Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public BlazeConfigurationResolverResult update(
context, blazeProjectData.getTargetMap());

Optional<XcodeCompilerSettings> xcodeSettings =
BlazeConfigurationToolchainResolver.resolveXcodeCompilerSettings(context, project);
BlazeConfigurationToolchainResolver.resolveXcodeCompilerSettings(context, project, blazeProjectData);

ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettings =
BlazeConfigurationToolchainResolver.buildCompilerSettingsMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.idea.blaze.base.ideinfo.TargetIdeInfo;
import com.google.idea.blaze.base.ideinfo.TargetKey;
import com.google.idea.blaze.base.ideinfo.TargetMap;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.ExecutionRootPath;
import com.google.idea.blaze.base.model.primitives.LanguageClass;
import com.google.idea.blaze.base.model.primitives.TargetExpression;
Expand Down Expand Up @@ -424,14 +425,13 @@ private static <T> ListenableFuture<T> submit(Callable<T> callable) {
return BlazeExecutor.getInstance().submit(callable);
}

public static Optional<XcodeCompilerSettings> resolveXcodeCompilerSettings(BlazeContext context,
Project project) {
public static Optional<XcodeCompilerSettings> resolveXcodeCompilerSettings(BlazeContext context, Project project, BlazeProjectData projectData) {
return Scope.push(
context,
childContext -> {
childContext.push(new TimingScope("Resolve Xcode information", EventType.Other));
try {
return XcodeCompilerSettingsProvider.getInstance(project).fromContext(context, project);
return XcodeCompilerSettingsProvider.getInstance(project).fromContext(context, project, projectData);
} catch (XcodeCompilerSettingsException e) {
IssueOutput.warn(
String.format("There was an error fetching the Xcode information from the build: %s\n\nSome C++ functionality may not be available.", e.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.idea.blaze.cpp;

import com.google.common.collect.ImmutableMap;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
Expand All @@ -30,7 +31,7 @@ static XcodeCompilerSettingsProvider getInstance(Project project) {
return ServiceManager.getService(project, XcodeCompilerSettingsProvider.class);
}

Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project)
Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project, BlazeProjectData projectData)
throws XcodeCompilerSettingsException;

default ImmutableMap<String, String> asEnvironmentVariables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.idea.blaze.base.command.BlazeCommand;
import com.google.idea.blaze.base.command.BlazeCommandName;
import com.google.idea.blaze.base.console.BlazeConsoleLineProcessorProvider;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.scope.BlazeContext;
Expand All @@ -45,20 +46,26 @@


public class XcodeCompilerSettingsProviderImpl implements XcodeCompilerSettingsProvider {


// provides only the default xcode version but is available in Bazel 9 as well
private static final String HOST_XCODES_TARGET = "@bazel_tools//tools/cpp:host_xcodes";

// provides the current xcode version but is not available in Bazel 9 anymore
private static final String CURRENT_XCODE_CONFIG_TARGET = "@bazel_tools//tools/osx:current_xcode_config";

private static final String QUERY_STARLARK_FILE = "xcode_query.bzl";

// This only exists because it's impossible to escape a `deps()` query expression correctly in a Java string.
private static final String[] QUERY_XCODE_VERSION_SCRIPT_LINES = new String[]{
"#!/bin/bash",
"__BAZEL_BIN__ cquery \\",
" 'deps(\"@bazel_tools//tools/osx:current_xcode_config\")' \\",
" 'deps(__TARGET__)' \\",
" --output=starlark \\",
" --starlark:file='__QUERY_FILE__'",
};

@Override
public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project)
public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project, BlazeProjectData projectData)
throws XcodeCompilerSettingsException {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
BuildSystem.BuildInvoker invoker =
Expand All @@ -68,7 +75,8 @@ public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project
context,
invoker,
workspaceRoot,
project);
project,
projectData);

if (!xcodeAndSdkVersions.isPresent()) {
return Optional.empty();
Expand Down Expand Up @@ -205,14 +213,22 @@ private static Optional<XcodeAndSdkVersions> queryXcodeAndSdkVersions(
BlazeContext context,
BuildInvoker invoker,
WorkspaceRoot workspaceRoot,
Project project)
Project project,
BlazeProjectData projectData)
throws XcodeCompilerSettingsException {
// this will not work with query sync, since at the moment aspects are only written as part of the async
final var queryFile = AspectStorageService.of(project)
.resolve(QUERY_STARLARK_FILE)
.orElseThrow(() -> new IllegalStateException("could not resolve query file"))
.toFilePath()
.toString();

final String queryTarget;
if (projectData.getBlazeVersionData().bazelIsAtLeastVersion(9, 0, 0)) {
queryTarget = HOST_XCODES_TARGET;
} else {
queryTarget = CURRENT_XCODE_CONFIG_TARGET;
}

File blazeCqueryWrapper = null;
try {
Expand All @@ -226,6 +242,7 @@ private static Optional<XcodeAndSdkVersions> queryXcodeAndSdkVersions(
Arrays.stream(QUERY_XCODE_VERSION_SCRIPT_LINES).forEach(line -> {
line = line.replace("__BAZEL_BIN__", invoker.getBinaryPath());
line = line.replace("__QUERY_FILE__", queryFile);
line = line.replace("__TARGET__", queryTarget);

pw.println(line);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.idea.blaze.cpp;

import com.google.common.collect.ImmutableMap;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.intellij.openapi.project.Project;
import java.util.Optional;
Expand All @@ -13,7 +14,7 @@
public class XcodeCompilerSettingsProviderNoopImpl implements XcodeCompilerSettingsProvider {

@Override
public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project)
public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project, BlazeProjectData projectData)
throws XcodeCompilerSettingsException {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.idea.blaze.cpp;

import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.intellij.openapi.project.Project;
import java.util.Optional;

Expand All @@ -28,7 +29,7 @@ public void setXcodeSettings(XcodeCompilerSettings settings) {
}

@Override
public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project)
public Optional<XcodeCompilerSettings> fromContext(BlazeContext context, Project project, BlazeProjectData projectData)
throws XcodeCompilerSettingsException {
if (this.settings != null) {
return Optional.of(this.settings);
Expand Down