Skip to content

Commit

Permalink
Include BUILD files in generated Xcode projects
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jun 17, 2020
1 parent 6c1dae2 commit ea6c765
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
27 changes: 18 additions & 9 deletions rules/xcodeproj.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def _is_current_project_file(f):
def _is_current_project_path(path):
return not path.startswith("external/")

def _srcs_info_build_files(ctx):
path = ctx.build_file_path
if not _is_current_project_path(path):
return []

return [path]

def _xcodeproj_aspect_impl(target, ctx):
providers = []

Expand Down Expand Up @@ -83,7 +90,7 @@ def _xcodeproj_aspect_impl(target, ctx):
bazel_bin_subdir = bazel_bin_subdir,
srcs = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "srcs")),
asset_srcs = depset([], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "asset_srcs")),
build_files = depset([ctx.build_file_path], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "build_files")),
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,
minimum_os_version = bundle_info.minimum_os_version,
Expand All @@ -96,7 +103,7 @@ def _xcodeproj_aspect_impl(target, ctx):
_SrcsInfo(
srcs = info.srcs,
asset_srcs = info.asset_srcs,
build_files = depset([ctx.build_file_path]),
build_files = depset(_srcs_info_build_files(ctx)),
direct_srcs = [],
),
)
Expand All @@ -120,7 +127,7 @@ def _xcodeproj_aspect_impl(target, ctx):
_SrcsInfo(
srcs = depset(srcs, transitive = _get_attr_values_for_name(deps, _SrcsInfo, "srcs")),
asset_srcs = depset(asset_srcs, transitive = _get_attr_values_for_name(deps, _SrcsInfo, "asset_srcs")),
build_files = depset([ctx.build_file_path], transitive = _get_attr_values_for_name(deps, _SrcsInfo, "build_files")),
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 @@ -215,6 +222,13 @@ def _xcodeproj_impl(ctx):
"optional": True,
"buildPhase": "none",
} for s in target_info.asset_srcs.to_list()]
asset_sources += [{
"path": paths.join(src_dot_dots, p),
"group": paths.dirname(p),
"optional": True,
"buildPhase": "none",
# TODO: add source language type once https://github.com/yonaskolb/XcodeGen/issues/850 is resolved
} for p in target_info.build_files.to_list()]
target_settings = {
"PRODUCT_NAME": target_info.name,
"BAZEL_BIN_SUBDIR": target_info.bazel_bin_subdir,
Expand Down Expand Up @@ -300,15 +314,10 @@ $BAZEL_INSTALLER
settings = proj_settings,
targets = xcodeproj_targets_by_name,
schemes = xcodeproj_schemes_by_name,
fileGroups = [
src_dot_dots + f.short_path
for f in ctx.files.additional_files
if _is_current_project_file(f)
]
fileGroups = project_file_groups,
)

ctx.actions.write(xcodegen_jsonfile, xcodeproj_info.to_json())

ctx.actions.run(
executable = ctx.executable._xcodegen,
arguments = ["--quiet", "--no-env", "--spec", xcodegen_jsonfile.path, "--project", project.dirname],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
78FAC8B505DC9C839473A482 /* iOS-12.0-AppHost.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = "iOS-12.0-AppHost.app"; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
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>"; };
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; };
Expand All @@ -38,6 +40,7 @@
isa = PBXGroup;
children = (
7CCE59C7822E18EBC1CD9D6D /* AssetCatalogFixture.xcassets */,
BA5C2481E04D8592323A7AD9 /* BUILD.bazel */,
908EFE5EAE901D6B372D68F7 /* ios.entitlements */,
EEB1C98DB4C8E24414A69917 /* main.m */,
);
Expand Down Expand Up @@ -99,6 +102,7 @@
F237C982F1E8CD4A105006B4 /* xcodeproj */ = {
isa = PBXGroup;
children = (
A05E016687115D20E64A5C60 /* BUILD.bazel */,
F1162A80978C527830EDADEE /* test.swift */,
);
name = xcodeproj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
0BD63CC255956E60D898C7B7 /* test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = test.swift; path = test.swift; sourceTree = "<group>"; };
2B41830721183AA100B23D64 /* ios.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = ios.entitlements; path = ../../../rules/test_host_app/ios.entitlements; sourceTree = "<group>"; };
2DA260AA799ED8A57078C331 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ../../../rules/test_host_app/main.m; sourceTree = "<group>"; };
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; };
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>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -56,6 +58,7 @@
isa = PBXGroup;
children = (
D46477D0666FC1C236EDC486 /* AssetCatalogFixture.xcassets */,
EAEB79BE70BFB649A6FBC92C /* BUILD.bazel */,
2B41830721183AA100B23D64 /* ios.entitlements */,
2DA260AA799ED8A57078C331 /* main.m */,
);
Expand Down Expand Up @@ -99,6 +102,7 @@
F4FF0CBD8A1F7A37DB68252E /* xcodeproj */ = {
isa = PBXGroup;
children = (
4936F4D0B63B32AD09E63C43 /* BUILD.bazel */,
0BD63CC255956E60D898C7B7 /* test.swift */,
);
name = xcodeproj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
2238C255CB7ED2E848A7FC51 /* common.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = common.pch; path = ../../../rules/library/common.pch; sourceTree = "<group>"; };
2263A980666D293D7413BE92 /* test.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = test.m; path = "../../ios/unit-test/test-imports-app/test.m"; sourceTree = "<group>"; };
246AA4985E50044D3CD8228A /* test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = test.swift; path = "../../ios/unit-test/test-imports-app/test.swift"; sourceTree = "<group>"; };
300321A84FA667D38500A4EE /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = ../../../rules/test_host_app/BUILD.bazel; sourceTree = "<group>"; };
31B65EED0A5FCC9038424593 /* empty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = empty.swift; path = "../../ios/unit-test/empty.swift"; sourceTree = "<group>"; };
36C5066BFCF7F5E1A169E184 /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = "../../ios/unit-test/BUILD.bazel"; sourceTree = "<group>"; };
61CE3CBBAD0BFAFC0953377B /* TestImports-App.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = "TestImports-App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
6725F1A1E5A5BAFC1EE01F00 /* Header2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Header2.h; path = "../../ios/unit-test/test-imports-app/Header2.h"; sourceTree = "<group>"; };
9E7E8177A9991D407C446EF6 /* TestImports-Unit-Tests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = "TestImports-Unit-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
BC8493575E7FDD7052346981 /* BUILD.bazel */ = {isa = PBXFileReference; name = BUILD.bazel; path = "../../ios/unit-test/test-imports-app/BUILD.bazel"; sourceTree = "<group>"; };
BCDD3D2387B5DA5045A0D600 /* Contents.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = Contents.json; path = ../../../rules/test_host_app/AssetCatalogFixture.xcassets/Contents.json; sourceTree = "<group>"; };
CD38E215541F1766D3CAFBEE /* ios.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = ios.entitlements; path = ../../../rules/test_host_app/ios.entitlements; sourceTree = "<group>"; };
F42CC7E6159DCCC28D045A6C /* empty.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = empty.m; path = "../../ios/unit-test/empty.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -77,6 +80,7 @@
47EF8E9B0D250B2E77846871 /* test-imports-app */ = {
isa = PBXGroup;
children = (
BC8493575E7FDD7052346981 /* BUILD.bazel */,
035030AE3B7F41C97A1EE910 /* empty.swift */,
08D20BAAC5B1A41903E13B27 /* Header.h */,
6725F1A1E5A5BAFC1EE01F00 /* Header2.h */,
Expand Down Expand Up @@ -125,6 +129,7 @@
isa = PBXGroup;
children = (
50E12C023D675E3BA9A6FDFA /* AssetCatalogFixture.xcassets */,
300321A84FA667D38500A4EE /* BUILD.bazel */,
CD38E215541F1766D3CAFBEE /* ios.entitlements */,
FE939800D5E84FA4B194548D /* main.m */,
);
Expand All @@ -134,6 +139,7 @@
D09C5AAC3E8F31379C981C8F /* unit-test */ = {
isa = PBXGroup;
children = (
36C5066BFCF7F5E1A169E184 /* BUILD.bazel */,
F42CC7E6159DCCC28D045A6C /* empty.m */,
31B65EED0A5FCC9038424593 /* empty.swift */,
47EF8E9B0D250B2E77846871 /* test-imports-app */,
Expand Down

0 comments on commit ea6c765

Please sign in to comment.