Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xcode: query xcode parameters from provider based on attributes #7193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions aspect/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ filegroup(
"intellij_info_impl.bzl",
"java_classpath.bzl",
"make_variables.bzl",
"xcode_query.bzl",
":BUILD.bazel",
"//aspect/tools:CreateAar",
"//aspect/tools:JarFilter_deploy.jar",
Expand Down Expand Up @@ -51,6 +52,7 @@ filegroup(
"intellij_info_impl_bundled.bzl",
"java_classpath.bzl",
"make_variables.bzl",
"xcode_query.bzl",
":BUILD.bazel",
],
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -117,9 +119,9 @@ genrule(

genrule(
name = "create_workspace_file",
outs = ["WORKSPACE"],
srcs = [],
cmd = r"""echo 'workspace(name = "intellij_aspect")' > $@"""
outs = ["WORKSPACE"],
cmd = r"""echo 'workspace(name = "intellij_aspect")' > $@""",
)

define_flag_hack()
22 changes: 22 additions & 0 deletions aspect/xcode_query.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
provider_attrs = ["xcode_version", "default_macos_sdk_version"]

def all_items_are_true(items):
for item in items:
if item == False:
return False

return True

def hasattrs(obj, attrs):
return all_items_are_true([hasattr(obj, attr) for attr in attrs])

def format(target):
all_providers = providers(target)
for key in all_providers:
provider = all_providers[key]

if hasattrs(provider, provider_attrs):
attrs = [getattr(provider, attr) for attr in provider_attrs]
return "{} {}".format(attrs[0], attrs[1])

return ""
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static Optional<File> getProjectAspectDirectory(Project project) {
return Optional.ofNullable(project.getProjectFilePath()).map((it) -> Paths.get(it).getParent().resolve("aspect").toFile());
}

private static Optional<File> findAspectDirectory() {
static Optional<File> findAspectDirectory() {
return EP_NAME.getExtensionsIfPointIsRegistered().stream()
.map(AspectRepositoryProvider::aspectDirectory)
.filter(Optional::isPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.sync.aspects.strategy.AspectRepositoryProvider;
import com.google.idea.blaze.cpp.XcodeCompilerSettingsProvider.XcodeCompilerSettingsException.IssueKind;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
Expand All @@ -44,17 +45,13 @@


public class XcodeCompilerSettingsProviderImpl implements XcodeCompilerSettingsProvider {

private static final String QUERY_XCODE_VERSION_STARLARK_EXPR = "`{} {}`.format(providers(target)[`XcodeProperties`].xcode_version, providers(target)[`XcodeProperties`].default_macos_sdk_version) if providers(target) and `XcodeProperties` in providers(target) else ``".replace(
'`', '"');

// 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\")' \\",
" --output=starlark \\",
" --starlark:expr='" + QUERY_XCODE_VERSION_STARLARK_EXPR + "'",
" --starlark:file='" + AspectRepositoryProvider.findAspectDirectory().orElseThrow() + "/xcode_query.bzl'",
};

@Override
Expand Down
Loading