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

Set xcode target build settings, so xcode indexer will work #90

Merged
merged 8 commits into from
Jul 23, 2020
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
37 changes: 34 additions & 3 deletions rules/xcodeproj.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _xcodeproj_aspect_impl(target, ctx):
bazel_build_target_name = "@%s//" % target.label.workspace_name
bazel_build_target_name += "%s:%s" % (target.label.package, target.label.name)
bazel_bin_subdir = "%s/%s" % (target.label.workspace_root, target.label.package)

if AppleBundleInfo in target:
bundle_info = target[AppleBundleInfo]
test_host_appname = None
Expand All @@ -89,7 +90,10 @@ def _xcodeproj_aspect_impl(target, ctx):
bazel_build_target_name = bazel_build_target_name,
bazel_bin_subdir = bazel_bin_subdir,
srcs = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "srcs")),
non_arc_srcs = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "non_arc_srcs")),
asset_srcs = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "asset_srcs")),
framework_includes = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "framework_includes")),
cc_defines = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "cc_defines")),
build_files = depset(_srcs_info_build_files(ctx), transitive = _get_attr_values_for_name(deps, _SrcsInfo, "build_files")),
product_type = bundle_info.product_type[_PRODUCT_SPECIFIER_LENGTH:],
platform_type = bundle_info.platform_type,
Expand All @@ -102,7 +106,10 @@ def _xcodeproj_aspect_impl(target, ctx):
providers.append(
_SrcsInfo(
srcs = info.srcs,
non_arc_srcs = info.non_arc_srcs,
asset_srcs = info.asset_srcs,
framework_includes = info.framework_includes,
cc_defines = info.cc_defines,
build_files = depset(_srcs_info_build_files(ctx)),
direct_srcs = [],
),
Expand All @@ -114,19 +121,30 @@ def _xcodeproj_aspect_impl(target, ctx):
providers.append(target_info)
else:
srcs = []
non_arc_srcs = []
asset_srcs = []
for attr in _dir(ctx.rule.files):
if attr == "srcs":
srcs += getattr(ctx.rule.files, attr, [])
elif attr == "non_arc_srcs":
non_arc_srcs += getattr(ctx.rule.files, attr, [])
else:
asset_srcs += getattr(ctx.rule.files, attr, [])
srcs = [f for f in srcs if _is_current_project_file(f)]
non_arc_srcs = [f for f in non_arc_srcs if _is_current_project_file(f)]
asset_srcs = [f for f in asset_srcs if _is_current_project_file(f)]

framework_includes = _get_attr_values_for_name(deps, _SrcsInfo, "framework_includes")
cc_defines = _get_attr_values_for_name(deps, _SrcsInfo, "cc_defines")
if CcInfo in target:
framework_includes.append(target[CcInfo].compilation_context.framework_includes)
cc_defines.append(target[CcInfo].compilation_context.defines)
providers.append(
_SrcsInfo(
srcs = depset(srcs, transitive = _get_attr_values_for_name(deps, _SrcsInfo, "srcs")),
non_arc_srcs = depset(non_arc_srcs, transitive = _get_attr_values_for_name(deps, _SrcsInfo, "non_arc_srcs")),
asset_srcs = depset(asset_srcs, transitive = _get_attr_values_for_name(deps, _SrcsInfo, "asset_srcs")),
framework_includes = depset([], transitive = framework_includes),
cc_defines = depset([], transitive = cc_defines),
build_files = depset(_srcs_info_build_files(ctx), transitive = _get_attr_values_for_name(deps, _SrcsInfo, "build_files")),
direct_srcs = srcs,
),
Expand Down Expand Up @@ -217,6 +235,12 @@ def _xcodeproj_impl(ctx):
"group": paths.dirname(s.short_path),
"optional": True,
} for s in target_info.srcs.to_list()]
compiled_non_arc_sources = [{
"path": paths.join(src_dot_dots, s.short_path),
"group": paths.dirname(s.short_path),
"optional": True,
"compilerFlags": "-fno-objc-arc",
} for s in target_info.non_arc_srcs.to_list()]
asset_sources = [{
"path": paths.join(src_dot_dots, s.short_path),
"group": paths.dirname(s.short_path),
Expand All @@ -235,8 +259,15 @@ def _xcodeproj_impl(ctx):
"BAZEL_BIN_SUBDIR": target_info.bazel_bin_subdir,
"MACH_O_TYPE": target_macho_type,
"CLANG_ENABLE_MODULES": "YES",
"CLANG_ENABLE_OBJC_ARC": "YES",
}

framework_search_paths = []
for fi in target_info.framework_includes.to_list():
if fi[0] != "/":
fi = "$BAZEL_WORKSPACE_ROOT/%s" % fi
framework_search_paths.append("\"%s\"" % fi)
target_settings["FRAMEWORK_SEARCH_PATHS"] = " ".join(framework_search_paths)
target_settings["GCC_PREPROCESSOR_DEFINITIONS"] = " ".join(["\"%s\"" % d for d in target_info.cc_defines.to_list()])
if target_info.product_type == "application":
target_settings["INFOPLIST_FILE"] = "$BAZEL_STUBS_DIR/Info-stub.plist"
target_settings["PRODUCT_BUNDLE_IDENTIFIER"] = target_info.bundle_id
Expand All @@ -251,7 +282,7 @@ def _xcodeproj_impl(ctx):
target_settings["VALID_ARCHS"] = _ARCH_MAPPING[target_info.platform_type]

xcodeproj_targets_by_name[target_info.name] = {
"sources": compiled_sources + asset_sources,
"sources": compiled_sources + compiled_non_arc_sources + asset_sources,
"type": target_info.product_type,
"platform": _PLATFORM_MAPPING[target_info.platform_type],
"deploymentTarget": target_info.minimum_os_version,
Expand Down
6 changes: 6 additions & 0 deletions tests/macos/xcodeproj/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ ios_unit_test(
name = "Single-Application-UnitTests",
srcs = ["test.swift"],
args = ["-h"],
defines = ["REQUIRED_DEFINED_FLAG"],
env = {
"test_envvar_key1": "test_envvar_value1",
"test_envvar_key2": "test_envvar_value2",
},
minimum_os_version = "11.0",
module_name = "Single_Application_UnitTests",
non_arc_srcs = [
"NonArcObject.h",
"NonArcObject.m",
],
sdk_frameworks = ["XCTest"],
)

Expand All @@ -33,6 +38,7 @@ ios_unit_test(
name = "Single-Application-RunnableTestSuite",
srcs = ["test.swift"],
args = ["-h"],
defines = ["REQUIRED_DEFINED_FLAG"],
env = {
"test_envvar_key1": "test_envvar_value1",
"test_envvar_key2": "test_envvar_value2",
Expand Down
2 changes: 2 additions & 0 deletions tests/macos/xcodeproj/NonArcObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@interface NonArcObject
@end
4 changes: 4 additions & 0 deletions tests/macos/xcodeproj/NonArcObject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "NonArcObject.h"

@implementation NonArcObject
@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0834EB3BB2BE0990DEED46BD /* test.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1162A80978C527830EDADEE /* test.swift */; };
6868785A8F571C49259B50E0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EEB1C98DB4C8E24414A69917 /* main.m */; };
8A8AC7C1D053F87A0D991815 /* NonArcObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E881738E1AAC1FCA61D467D8 /* NonArcObject.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E8D5A100DC66B1E35BB71538 /* test.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1162A80978C527830EDADEE /* test.swift */; };
/* End PBXBuildFile section */

Expand All @@ -19,8 +20,10 @@
7ABD95023B71172929B010EE /* common.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = common.pch; path = ../../../rules/library/common.pch; sourceTree = "<group>"; };
908EFE5EAE901D6B372D68F7 /* ios.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = ios.entitlements; path = ../../../rules/test_host_app/ios.entitlements; sourceTree = "<group>"; };
A05E016687115D20E64A5C60 /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = BUILD.bazel; sourceTree = "<group>"; };
B63432B3F93F02853868034C /* NonArcObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NonArcObject.h; path = NonArcObject.h; sourceTree = "<group>"; };
BA5C2481E04D8592323A7AD9 /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = ../../../rules/test_host_app/BUILD.bazel; sourceTree = "<group>"; };
BFC300E7CF04688067094BFF /* Contents.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = Contents.json; path = ../../../rules/test_host_app/AssetCatalogFixture.xcassets/Contents.json; sourceTree = "<group>"; };
E881738E1AAC1FCA61D467D8 /* NonArcObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = NonArcObject.m; path = NonArcObject.m; sourceTree = "<group>"; };
EEB1C98DB4C8E24414A69917 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ../../../rules/test_host_app/main.m; sourceTree = "<group>"; };
EFADB1CE81C3F97F647C9255 /* Single-Application-UnitTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = "Single-Application-UnitTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
F1162A80978C527830EDADEE /* test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = test.swift; path = test.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,6 +106,8 @@
isa = PBXGroup;
children = (
A05E016687115D20E64A5C60 /* BUILD.bazel */,
B63432B3F93F02853868034C /* NonArcObject.h */,
E881738E1AAC1FCA61D467D8 /* NonArcObject.m */,
F1162A80978C527830EDADEE /* test.swift */,
);
name = xcodeproj;
Expand Down Expand Up @@ -265,6 +270,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8A8AC7C1D053F87A0D991815 /* NonArcObject.m in Sources */,
E8D5A100DC66B1E35BB71538 /* test.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -277,6 +283,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-UnitTests";
Expand All @@ -290,6 +299,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /rules/test_host_app;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "$BAZEL_STUBS_DIR/Info-stub.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACH_O_TYPE = "$(inherited)";
Expand All @@ -304,6 +316,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /rules/test_host_app;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "$BAZEL_STUBS_DIR/Info-stub.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACH_O_TYPE = "$(inherited)";
Expand Down Expand Up @@ -366,6 +381,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-RunnableTestSuite";
Expand All @@ -379,6 +397,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-RunnableTestSuite";
Expand All @@ -392,6 +413,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-UnitTests";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
53E65376450A485B39CE93FE /* test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD63CC255956E60D898C7B7 /* test.swift */; };
706F35140D56EA1BB820A681 /* NonArcObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B1396A59924BC26C630854 /* NonArcObject.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
83D9B2BE42CE395FCC9356FB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DA260AA799ED8A57078C331 /* main.m */; };
B868F40E021F743023B7764F /* test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD63CC255956E60D898C7B7 /* test.swift */; };
/* End PBXBuildFile section */
Expand All @@ -19,11 +20,13 @@
4936F4D0B63B32AD09E63C43 /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = BUILD.bazel; sourceTree = "<group>"; };
58D47D35D8B8E34549EE944E /* Contents.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = Contents.json; path = ../../../rules/test_host_app/AssetCatalogFixture.xcassets/Contents.json; sourceTree = "<group>"; };
712BB7D3F966AAE042C40E4E /* iOS-12.0-AppHost.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = "iOS-12.0-AppHost.app"; sourceTree = BUILT_PRODUCTS_DIR; };
77B1396A59924BC26C630854 /* NonArcObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = NonArcObject.m; path = NonArcObject.m; sourceTree = "<group>"; };
9735D50F44B3B4D188BA18BF /* Single-Application-RunnableTestSuite.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = "Single-Application-RunnableTestSuite.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
CF248CD4BA2D7D91429E9BCB /* common.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = common.pch; path = ../../../rules/library/common.pch; sourceTree = "<group>"; };
E94B0DB5FD5082DE73F52008 /* Single-Application-UnitTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = "Single-Application-UnitTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
EAEB79BE70BFB649A6FBC92C /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = ../../../rules/test_host_app/BUILD.bazel; sourceTree = "<group>"; };
F689E871A09EA979611C589A /* resource_bundle.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = resource_bundle.plist; path = ../../../rules/library/resource_bundle.plist; sourceTree = "<group>"; };
FE2DCE7EA91C1CAF4050351A /* NonArcObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NonArcObject.h; path = NonArcObject.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXGroup section */
Expand Down Expand Up @@ -103,6 +106,8 @@
isa = PBXGroup;
children = (
4936F4D0B63B32AD09E63C43 /* BUILD.bazel */,
FE2DCE7EA91C1CAF4050351A /* NonArcObject.h */,
77B1396A59924BC26C630854 /* NonArcObject.m */,
0BD63CC255956E60D898C7B7 /* test.swift */,
);
name = xcodeproj;
Expand Down Expand Up @@ -249,6 +254,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
706F35140D56EA1BB820A681 /* NonArcObject.m in Sources */,
53E65376450A485B39CE93FE /* test.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -277,6 +283,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-RunnableTestSuite";
Expand All @@ -290,6 +299,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-UnitTests";
Expand Down Expand Up @@ -327,6 +339,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /rules/test_host_app;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "$BAZEL_STUBS_DIR/Info-stub.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACH_O_TYPE = "$(inherited)";
Expand All @@ -341,6 +356,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /rules/test_host_app;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "$BAZEL_STUBS_DIR/Info-stub.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACH_O_TYPE = "$(inherited)";
Expand All @@ -355,6 +373,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-RunnableTestSuite";
Expand Down Expand Up @@ -392,6 +413,9 @@
buildSettings = {
BAZEL_BIN_SUBDIR = /tests/macos/xcodeproj;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_PREPROCESSOR_DEFINITIONS = "\"REQUIRED_DEFINED_FLAG\"";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACH_O_TYPE = "$(inherited)";
PRODUCT_NAME = "Single-Application-UnitTests";
Expand Down
Loading