Skip to content

Commit

Permalink
Add xcschemes generator
Browse files Browse the repository at this point in the history
Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones committed Nov 1, 2023
1 parent c3aa4c2 commit c004d74
Show file tree
Hide file tree
Showing 39 changed files with 4,816 additions and 14 deletions.
51 changes: 51 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _TOOLS = {
"pbxproj_prefix": "//tools/generators/pbxproj_prefix",
"pbxtargetdependencies": "//tools/generators/pbxtargetdependencies",
"swiftc_stub": "//tools/swiftc_stub:swiftc",
"xcschemes": "//tools/generators/xcschemes",
}

_TESTS = {
Expand All @@ -24,6 +25,11 @@ _TESTS = {
"//tools/generators/lib/PBXProj:PBXProjTests",
"//tools/generators/pbxtargetdependencies:pbxtargetdependencies_tests",
],
"xcschemes": [
"//tools/generators/lib/PBXProj:PBXProjTests",
"//tools/generators/lib/XCScheme:XCSchemeTests",
"//tools/generators/xcschemes:xcschemes_tests",
],
}

_SCHEME_DIAGNOSTICS = xcode_schemes.diagnostics(
Expand Down Expand Up @@ -191,6 +197,48 @@ _SCHEMES = [
build_configuration = "Release",
),
),
xcode_schemes.scheme(
name = "xcschemes",
launch_action = xcode_schemes.launch_action(
_TOOLS["xcschemes"],
args = [
# outputDirectory
"/tmp/pbxproj_partials/xcschemes",
# schemeManagementOutputPath
"/tmp/pbxproj_partials/xcschememanagement.plist",
# autogenerationMode
"auto",
# defaultXcodeConfiguration
"Debug",
# workspace
"/tmp/workspace",
# installPath
"some/project.xcodeproj",
# extensionPointIdentifiersFile
"bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj_extension_point_identifiers",
# executionActionsFile
"bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj_pbxproj_partials/execution_actions_file",
# targetsArgsEnvFile
"bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj_pbxproj_partials/targets_args_env",
# customSchemesFile
"bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj_pbxproj_partials/custom_schemes_file",
# consolidationMaps
"--consolidation-maps",
"/tmp/pbxproj_partials/consolidation_maps/0",
"/tmp/pbxproj_partials/consolidation_maps/1",
# targetAndExtensionHosts
],
diagnostics = _SCHEME_DIAGNOSTICS,
),
profile_action = xcode_schemes.profile_action(
_TOOLS["xcschemes"],
build_configuration = "Release",
),
test_action = xcode_schemes.test_action(
_TESTS["xcschemes"],
diagnostics = _SCHEME_DIAGNOSTICS,
),
),
]

_XCODE_CONFIGURATIONS = {
Expand Down Expand Up @@ -224,6 +272,9 @@ xcodeproj(
"//tools/generators/pbxtargetdependencies": [
"//tools/generators/pbxtargetdependencies:README.md",
],
"//tools/generators/xcschemes": [
"//tools/generators/xcschemes:README.md",
],
},
extra_files = [
"//tools/generators:README.md",
Expand Down
1 change: 1 addition & 0 deletions tools/generators/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ filegroup(
# "//" + package_name() + "/pbxproj_prefix:release_files",
# "//" + package_name() + "/pbxtargetdependencies:release_files",
# "//" + package_name() + "/selected_model_versions:release_files",
# "//" + package_name() + "/xcschemes:release_files",
],
tags = ["manual"],
visibility = ["//:__subpackages__"],
Expand Down
8 changes: 3 additions & 5 deletions tools/generators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ information.
- `XCBuildConfiguration`
- `XCBuildConfigurationList`
- and various build phases
- Creates automatic `.xcscheme`s
- [`files_and_groups`](files_and_groups/README.md):
- Creates three files:
- A partial containing the `PBXProject.knownRegions` property
Expand All @@ -68,7 +67,6 @@ information.

## Xcode schemes

[Automatic schemes](docs/bazel.md#xcodeproj-scheme_autogeneration_mode) are
generated by one of the `PBXProj` partial generators (`pbxnativetargets`).
[Custom schemes](docs/bazel.md#xcodeproj-schemes) are generated by a separate
generator.
Both [automatic schemes](docs/bazel.md#xcodeproj-scheme_autogeneration_mode) and
[custom schemes](docs/bazel.md#xcodeproj-schemes) are generated by the
[`xcschemes`](xcschemes/README.md) generator.
8 changes: 0 additions & 8 deletions tools/generators/lib/XCScheme/src/CreateBuildAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public struct BuildActionEntry: Equatable {
public static let profiling = Self(rawValue: 1 << 3)
public static let archiving = Self(rawValue: 1 << 4)

public static let all: Self = [
.analyzing,
.testing,
.running,
.profiling,
.archiving,
]

public let rawValue: Int

public init(rawValue: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct CreateSchemeManagement {
self.callable = callable
}

/// Creates the XML for an `.xcscheme` file.
/// Creates the XML for an `xcschememanagement.plist` file.
public func callAsFunction(schemeNames: [String]) -> String {
return callable(/*schemeNames:*/ schemeNames)
}
Expand Down
95 changes: 95 additions & 0 deletions tools/generators/xcschemes/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_universal_binary")
load(
"@build_bazel_rules_apple//apple:macos.bzl",
"macos_command_line_application",
"macos_unit_test",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

exports_files(["README.md"])

# Generator

swift_library(
name = "xcschemes.library",
srcs = glob(["src/**/*.swift"]),
module_name = "xcschemes",
deps = [
"//tools/generators/lib/PBXProj",
"//tools/generators/lib/XCScheme",
"//tools/lib/ToolCommon",
"@com_github_apple_swift_collections//:OrderedCollections",
],
)

# This target exists to keep configurations the same between the generator
# and the tests, which makes the Xcode development experience better. If we used
# `swift_binary` or `apple_universal_binary` in `xcodeproj`, then the
# `macos_unit_test` transition (which is used to be able to set a minimum os
# version on the tests) will create slightly different configurations for our
# `swift_library`s. Maybe https://github.com/bazelbuild/bazel/issues/6526 will
# fix that for us.
macos_command_line_application(
name = "xcschemes",
minimum_os_version = "13.0",
visibility = ["//visibility:public"],
deps = [":xcschemes.library"],
)

swift_binary(
name = "xcschemes_binary",
deps = [":xcschemes.library"],
)

apple_universal_binary(
name = "universal_xcschemes",
binary = ":xcschemes_binary",
forced_cpus = [
"x86_64",
"arm64",
],
minimum_os_version = "13.0",
platform_type = "macos",
visibility = ["//visibility:public"],
)

# Tests

swift_library(
name = "xcschemes_tests.library",
testonly = True,
srcs = glob(["test/**/*.swift"]),
module_name = "xcschemes_tests",
deps = [
":xcschemes.library",
"@com_github_pointfreeco_swift_custom_dump//:CustomDump",
],
)

macos_unit_test(
name = "xcschemes_tests",
minimum_os_version = "13.0",
visibility = [
"//test:__subpackages__",
"@rules_xcodeproj//xcodeproj:generated",
],
deps = [
":xcschemes_tests.library",
],
)

# Release

filegroup(
name = "release_files",
srcs = [
"BUILD.release.bazel",
":universal_xcschemes",
],
tags = ["manual"],
visibility = ["//:__subpackages__"],
)
8 changes: 8 additions & 0 deletions tools/generators/xcschemes/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")

native_binary(
name = "universal_xcschemes",
src = "prebuilt_universal_xcschemes",
out = "universal_xcschemes",
visibility = ["//visibility:public"],
)
Loading

0 comments on commit c004d74

Please sign in to comment.