Skip to content

Commit

Permalink
Add build_mode attribute to xcodeproj
Browse files Browse the repository at this point in the history
This only supports `xcode` as a value for now, but by introducing the attribute and adjusting the fixtures, it makes the changes from new values easier to review.
  • Loading branch information
brentleyjones committed Apr 18, 2022
1 parent 71afa10 commit d04aabb
Show file tree
Hide file tree
Showing 64 changed files with 3,857 additions and 3,801 deletions.
4 changes: 2 additions & 2 deletions examples/ios_app/test/fixtures/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ update_fixtures(
name = "update",
tags = ["manual"],
targets = [
":fixture",
":fixture_bwx",
],
)

xcodeproj_test_suite(
name = "xcodeproj",
fixture_tests = [
xcodeproj_tests.from_fixture("//test/fixtures:fixture"),
xcodeproj_tests.from_fixture("//test/fixtures:fixture_bwx"),
],
)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
}
],
"invalid_target_merges": [],
"label": "//test/fixtures:fixture",
"name": "project",
"label": "//test/fixtures:fixture_bwx",
"name": "bwx",
"target_merges": [
"//Example:Example.library ios-x86_64-min15.0-applebin_ios-ios_x86_64-fastbuild-ST-d3e756bfe7fd",
[
Expand Down
1 change: 1 addition & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test_suite(
"//test/internal/opts",
"//test/internal/platform",
"//test/internal/target",
"//test/internal/xcodeproj_tests",
],
)

Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/fixtures/cc/spec.json → test/fixtures/cc/bwx_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"examples/cc/tool/BUILD"
],
"invalid_target_merges": [],
"label": "//test/fixtures/cc:xcodeproj",
"name": "project",
"label": "//test/fixtures/cc:xcodeproj_bwx",
"name": "bwx",
"target_merges": [],
"targets": [
"//examples/cc/lib2:lib_impl darwin_x86_64-fastbuild-ST-d53d69b6b8c1",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
}
],
"invalid_target_merges": [],
"label": "//test/fixtures/command_line:xcodeproj",
"name": "project",
"label": "//test/fixtures/command_line:xcodeproj_bwx",
"name": "bwx",
"target_merges": [
"//examples/command_line/Tests:LibSwiftTestsLib macos-x86_64-min11.0-applebin_macos-darwin_x86_64-fastbuild-ST-8946c8252059",
[
Expand Down
12 changes: 9 additions & 3 deletions test/fixtures/fixtures.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""Constants for fixture declarations."""

FIXTURE_BASENAMES = [
_FIXTURE_BASENAMES = [
"cc",
"command_line",
"generator",
"tvos_app",
]

_FIXTURE_PACKAGES = ["//test/fixtures/{}".format(b) for b in FIXTURE_BASENAMES]
_FIXTURE_SUFFIXES = ["bwx"]

FIXTURE_TARGETS = ["{}:xcodeproj".format(p) for p in _FIXTURE_PACKAGES]
_FIXTURE_PACKAGES = ["//test/fixtures/{}".format(b) for b in _FIXTURE_BASENAMES]

FIXTURE_TARGETS = [
"{}:xcodeproj_{}".format(package, suffix)
for package in _FIXTURE_PACKAGES
for suffix in _FIXTURE_SUFFIXES
]
2,112 changes: 2,112 additions & 0 deletions test/fixtures/generator/bwx.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"//tools/generator:generator darwin_x86_64-fastbuild-ST-d53d69b6b8c1"
]
],
"label": "//test/fixtures/generator:xcodeproj",
"name": "project",
"label": "//test/fixtures/generator:xcodeproj_bwx",
"name": "bwx",
"target_merges": [
"//tools/generator/test:tests.library darwin_x86_64-fastbuild-ST-d53d69b6b8c1",
[
Expand Down
2,112 changes: 0 additions & 2,112 deletions test/fixtures/generator/project.xcodeproj/project.pbxproj

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
}
],
"invalid_target_merges": [],
"label": "//test/fixtures/tvos_app:xcodeproj",
"name": "project",
"label": "//test/fixtures/tvos_app:xcodeproj_bwx",
"name": "bwx",
"target_merges": [
"//examples/tvos_app/Example:Example.library tvos-x86_64-min15.0-applebin_tvos-tvos_x86_64-fastbuild-ST-4e14a11cd4e6",
[
Expand Down
2 changes: 1 addition & 1 deletion test/internal/xcodeproj_tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
load(":xcodeproj_tests_tests.bzl", "xcodeproj_tests_test_suite")

xcodeproj_tests_test_suite(name = "xcodeproj_tests_tests")
xcodeproj_tests_test_suite(name = "xcodeproj_tests")
6 changes: 3 additions & 3 deletions test/internal/xcodeproj_tests/xcodeproj_tests_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _from_fixture_test(ctx):
expected = struct(
basename = "pkg",
target_under_test = "//path/to/pkg:custom_xcodeproj",
expected_spec = "@//path/to/pkg:spec.json",
expected_spec = "@//path/to/pkg:custom_xcodeproj_spec",
expected_xcodeproj = "@//path/to/pkg:custom_xcodeproj_output",
)
asserts.equals(env, expected, actual, "Specifying fixture target")
Expand All @@ -20,13 +20,13 @@ def _from_fixture_test(ctx):
actual = xcodeproj_tests.from_fixture(
"//path/to/pkg:custom_xcodeproj",
basename = "custom_basename",
expected_spec = "//path/to/pkg:custom_spec.json",
expected_spec = "//path/to/pkg:custom_spec",
expected_xcodeproj = "//path/to/pkg:custom_xcodeproj_output",
)
expected = struct(
basename = "custom_basename",
target_under_test = "//path/to/pkg:custom_xcodeproj",
expected_spec = "//path/to/pkg:custom_spec.json",
expected_spec = "//path/to/pkg:custom_spec",
expected_xcodeproj = "//path/to/pkg:custom_xcodeproj_output",
)
asserts.equals(env, expected, actual, "Specifying everything")
Expand Down
84 changes: 57 additions & 27 deletions xcodeproj/internal/fixtures.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def _update_fixtures_impl(ctx):
target[XcodeProjOutputInfo].xcodeproj
for target in ctx.attr.targets
]
project_names = [
target[XcodeProjOutputInfo].project_name
for target in ctx.attr.targets
]

updater = ctx.actions.declare_file(
"{}-updater.sh".format(ctx.label.name),
Expand All @@ -54,6 +58,7 @@ def _update_fixtures_impl(ctx):
"%installers%": " \n".join(
[installer.short_path for installer in installers],
),
"%project_names%": " \n".join(project_names),
"%specs%": " \n".join([spec.short_path for spec in specs]),
},
)
Expand Down Expand Up @@ -98,35 +103,60 @@ _fixture_xcodeproj = make_xcodeproj_rule(
def fixture_output_name(fixture_name):
return "{}_output".format(fixture_name)

def fixture_spec_name(fixture_name):
return "{}_spec".format(fixture_name)

def xcodeproj_fixture(
*,
name = "xcodeproj",
project_name = "project",
workspace_name = "rules_xcodeproj",
modes_and_suffixes = [("xcode", "bwx")],
targets):
native.exports_files([
"spec.json",
])

xcodeproj(
name = name,
external_dir_override = "bazel-{}/external".format(workspace_name),
generated_dir_override = "bazel-out",
project_name = project_name,
targets = targets,
xcodeproj_rule = _fixture_xcodeproj,
visibility = ["//test:__subpackages__"],
)

native.filegroup(
name = fixture_output_name(name),
srcs = native.glob(
["{}.xcodeproj/**/*".format(project_name)],
exclude = [
"{}.xcodeproj/xcshareddata/**/*".format(project_name),
"{}.xcodeproj/**/xcuserdata/**/*".format(project_name),
"{}.xcodeproj/*.xcuserdatad/**/*".format(project_name),
],
),
visibility = ["//test:__subpackages__"],
)
"""Creates the fixture for an existing `xcodeproj` target.
This will create an `xcodeproj` target for each `build_mode` option.
Args:
name: The name of the fixture. This will be the prefix of the .xcodeproj
and spec files.
workspace_name: The name of the workspace.
modes_and_suffixes: A `list` of `tuple`s of `build_mode` and `suffix`.
The `build_mode` will be pass to `xcodeproj.build_mode` and the
`suffix` will be used as the suffix of the project and spec files.
targets: Maps to `xcodeproj.targets`.
"""
for mode, suffix in modes_and_suffixes:
fixture_name = "{}_{}".format(name, suffix)
spec_name = "{}_spec.json".format(suffix)

native.exports_files([spec_name])

native.alias(
name = fixture_spec_name(fixture_name),
actual = spec_name,
visibility = ["//test:__subpackages__"],
)

xcodeproj(
name = fixture_name,
build_mode = mode,
external_dir_override = "bazel-{}/external".format(workspace_name),
generated_dir_override = "bazel-out",
project_name = suffix,
targets = targets,
xcodeproj_rule = _fixture_xcodeproj,
visibility = ["//test:__subpackages__"],
)

native.filegroup(
name = fixture_output_name(fixture_name),
srcs = native.glob(
["{}.xcodeproj/**/*".format(suffix)],
exclude = [
"{}.xcodeproj/xcshareddata/**/*".format(suffix),
"{}.xcodeproj/**/xcuserdata/**/*".format(suffix),
"{}.xcodeproj/*.xcuserdatad/**/*".format(suffix),
],
),
visibility = ["//test:__subpackages__"],
)
1 change: 1 addition & 0 deletions xcodeproj/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ XcodeProjOutputInfo = provider(
"Provides information about the outputs of the `xcodeproj` rule.",
fields = {
"installer": "The xcodeproj installer",
"project_name": "The installed project name",
"root_dirs": "The root directories file",
"spec": "The json spec",
"xcodeproj": "The xcodeproj file",
Expand Down
13 changes: 9 additions & 4 deletions xcodeproj/internal/updater.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

set -euo pipefail

readonly project_names=(
%project_names%
)
readonly specs=(
%specs%
)
readonly installers=(
%installers%
)

for spec in "${specs[@]}"; do
# "fixtures/app/xcodeproj_spec.json" -> "//test/fixtures/app/spec.json"
dir="${BUILD_WORKSPACE_DIRECTORY}/${spec%/*}"
dest="$dir/spec.json"
for i in "${!specs[@]}"; do
# "fixtures/app/xcodeproj_spec.json" -> "//test/fixtures/app/name_spec.json"
spec="${specs[i]}"
name="${project_names[i]}"
dir="$BUILD_WORKSPACE_DIRECTORY/${spec%/*}"
dest="$dir/${name}_spec.json"

mkdir -p "$dir"
python3 -m json.tool "$spec" > "$dest"
Expand Down
5 changes: 5 additions & 0 deletions xcodeproj/internal/xcodeproj.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def _xcodeproj_impl(ctx):
),
XcodeProjOutputInfo(
installer = installer,
project_name = project_name,
root_dirs = root_dirs_file,
spec = spec_file,
xcodeproj = xcodeproj,
Expand All @@ -246,6 +247,10 @@ def make_xcodeproj_rule(*, transition = None):
"bazel_path": attr.string(
default = "bazel",
),
"build_mode": attr.string(
default = "xcode",
values = ["xcode"],
),
"external_dir_override": attr.string(
default = "",
),
Expand Down
14 changes: 11 additions & 3 deletions xcodeproj/internal/xcodeproj_tests.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Tests for the `xcodeproj` rule."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load(":fixtures.bzl", "fixture_output_name", "fixtures_transition")
load(
":fixtures.bzl",
"fixture_output_name",
"fixture_spec_name",
"fixtures_transition",
)
load(":providers.bzl", "XcodeProjOutputInfo")

# xcodeproj_tests API
Expand Down Expand Up @@ -37,7 +42,10 @@ def _from_fixture(
if basename == None:
basename = paths.basename(pkg)
if expected_spec == None:
expected_spec = "{pkg}:spec.json".format(pkg = pkg)
expected_spec = "{pkg}:{name}".format(
pkg = pkg,
name = fixture_spec_name(target_under_test_label.name),
)
if expected_xcodeproj == None:
expected_xcodeproj = "{pkg}:{name}".format(
pkg = pkg,
Expand Down Expand Up @@ -127,7 +135,7 @@ def xcodeproj_test_suite(name, fixture_tests):
name: The base name to be used in things created by this macro. Also the
name of the test suite.
fixture_tests: A `list` of structs as returned by
`xcodeproj_tests.from_fixture()`.
`xcodeproj_tests.from_fixture()`.
"""
test_names = []

Expand Down

0 comments on commit d04aabb

Please sign in to comment.