Skip to content

wip: Support StoreKit Configuration setting in xcscheme Run action #3182

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

Closed
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
5 changes: 3 additions & 2 deletions docs/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ Defines the Profile action.
## xcschemes.run

<pre>
xcschemes.run(<a href="#xcschemes.run-args">args</a>, <a href="#xcschemes.run-build_targets">build_targets</a>, <a href="#xcschemes.run-diagnostics">diagnostics</a>, <a href="#xcschemes.run-env">env</a>, <a href="#xcschemes.run-env_include_defaults">env_include_defaults</a>, <a href="#xcschemes.run-launch_target">launch_target</a>,
<a href="#xcschemes.run-xcode_configuration">xcode_configuration</a>)
xcschemes.run(<a href="#xcschemes.run-args">args</a>, <a href="#xcschemes.run-build_targets">build_targets</a>, <a href="#xcschemes.run-diagnostics">diagnostics</a>, <a href="#xcschemes.run-env">env</a>, <a href="#xcschemes.run-env_include_defaults">env_include_defaults</a>, <a href="#xcschemes.run-storekit_configuration">storekit_configuration</a>,
<a href="#xcschemes.run-launch_target">launch_target</a>, <a href="#xcschemes.run-xcode_configuration">xcode_configuration</a>)
</pre>

Defines the Run action.
Expand All @@ -494,6 +494,7 @@ Defines the Run action.
| <a id="xcschemes.run-diagnostics"></a>diagnostics | The diagnostics to enable when running the launch target.<br><br>Can be `None` or a value returned by [`xcschemes.diagnostics`](#xcschemes.diagnostics). If `None`, `xcschemes.diagnostics()` will be used, which means no diagnostics will be enabled. | `None` |
| <a id="xcschemes.run-env"></a>env | Environment variables to use when running the launch target.<br><br>If set to `"inherit"`, then the environment variables will be supplied by the launch target (e.g. [`cc_binary.env`](https://bazel.build/reference/be/common-definitions#binary.env)). Otherwise, the `dict` of environment variables will be set as provided, and `None` or `{}` will result in no environment variables.<br><br>Each value of the `dict` can either be a string or a value returned by [`xcschemes.env_value`](#xcschemes.env_value). If a value is a string, it will be transformed into `xcschemes.env_value(value)`. For example, <pre><code>xcschemes.run(&#10; env = {&#10; "VAR1": "value 1",&#10; "VAR 2": xcschemes.env_value("value2", enabled = False),&#10; },&#10;)</code></pre> will be transformed into: <pre><code>xcschemes.run(&#10; env = {&#10; "VAR1": xcschemes.env_value("value 1"),&#10; "VAR 2": xcschemes.env_value("value2", enabled = False),&#10; },&#10;)</code></pre> | `"inherit"` |
| <a id="xcschemes.run-env_include_defaults"></a>env_include_defaults | Whether to include the rules_xcodeproj provided default Bazel environment variables (e.g. `BUILD_WORKING_DIRECTORY` and `BUILD_WORKSPACE_DIRECTORY`), in addition to any set by [`env`](#xcschemes.run-env). This does not apply to [`xcschemes.launch_path`](#xcschemes.launch_path)s. | `True` |
| <a id="xcschemes.run-storekit_configuration"></a>storekit_configuration | A StoreKit configuration file for use with [StoreKit Testing in Xcode](https://developer.apple.com/documentation/xcode/setting-up-storekit-testing-in-xcode).<br><br>Can be `None`, or a label string. | `None` |
| <a id="xcschemes.run-launch_target"></a>launch_target | The target to launch when running.<br><br>Can be `None`, a label string, a value returned by [`xcschemes.launch_target`](#xcschemes.launch_target), or a value returned by [`xcschemes.launch_path`](#xcschemes.launch_path). If a label string, `xcschemes.launch_target(label_str)` will be used. If `None`, `xcschemes.launch_target()` will be used, which means no launch target will be set (i.e. the `Executable` dropdown will be set to `None`). | `None` |
| <a id="xcschemes.run-xcode_configuration"></a>xcode_configuration | The name of the Xcode configuration to use to build the targets referenced in the Run action (i.e in the [`build_targets`](#xcschemes.run-build_targets) and [`launch_target`](#xcschemes.run-launch_target) attributes).<br><br>If not set, the value of [`xcodeproj.default_xcode_configuration`](#xcodeproj-default_xcode_configuration) is used. | `None` |

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"appPolicies" : {
"eula" : "",
"policies" : [
{
"locale" : "en_US",
"policyText" : "",
"policyURL" : ""
}
]
},
"identifier" : "",
"nonRenewingSubscriptions" : [

],
"products" : [

],
"settings" : {
"_failTransactionsEnabled" : false
},
"subscriptionGroups" : [

],
"version" : {
"major" : 4,
"minor" : 0
}
}
1 change: 1 addition & 0 deletions examples/integration/xcodeproj_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ XCSCHEMES = [
],
),
],
storekit_configuration = "//examples/integration/iOSApp/Resources/ExampleResources:Confiugration.storekit",
),
),
]
3 changes: 3 additions & 0 deletions test/internal/xcschemes/info_constructors_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def info_constructors_test_suite(name):
diagnostics = xcscheme_infos_testable.make_diagnostics(),
env = None,
env_include_defaults = "1",
storekit_configuration = "",
launch_target = xcscheme_infos_testable.make_launch_target(),
xcode_configuration = "",
),
Expand Down Expand Up @@ -619,6 +620,7 @@ def info_constructors_test_suite(name):
"VAR\n0": xcscheme_infos_testable.make_env("value 0"),
"VAR 1": xcscheme_infos_testable.make_env("value\n1"),
},
storekit_configuration = "/Configuration.storekit",
env_include_defaults = "0",
launch_target = xcscheme_infos_testable.make_launch_target("L"),
xcode_configuration = "Run",
Expand Down Expand Up @@ -648,6 +650,7 @@ def info_constructors_test_suite(name):
"VAR 1": xcscheme_infos_testable.make_env("value\n1"),
},
env_include_defaults = "0",
storekit_configuration = "/Configuration.storekit",
launch_target = xcscheme_infos_testable.make_launch_target(
id = "L",
),
Expand Down
1 change: 1 addition & 0 deletions test/internal/xcschemes/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _dict_to_run_info(d):
diagnostics = _dict_to_diagnostics_info(d["diagnostics"]),
env = _dict_of_dicts_to_env_infos(d["env"]),
env_include_defaults = d["env_include_defaults"],
storekit_configuration = d["storekit_configuration"],
launch_target = _dict_to_launch_target_info(d["launch_target"]),
xcode_configuration = d["xcode_configuration"],
)
Expand Down
8 changes: 8 additions & 0 deletions test/internal/xcschemes/write_schemes_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def write_schemes_test_suite(name):
),
},
env_include_defaults = "0",
storekit_configuration = "run storekit config",
launch_target = xcscheme_infos_testable.make_launch_target(
extension_host = "run extension host id",
id = "run launch id",
Expand Down Expand Up @@ -660,6 +661,7 @@ def write_schemes_test_suite(name):
xcscheme_infos_testable.make_scheme(
name = "Scheme 3",
run = xcscheme_infos_testable.make_run(
storekit_configuration = "/Configuration.storekit",
launch_target = xcscheme_infos_testable.make_launch_target(
path = "/Foo/Bar.app",
),
Expand Down Expand Up @@ -1100,6 +1102,8 @@ def write_schemes_test_suite(name):
"-1",
# - run - environmentVariablesIncludeDefaults
"1",
# - run - storeKitConfigurationPath
"",
# - run - enableAddressSanitizer
"0",
# - run - enableThreadSanitizer
Expand Down Expand Up @@ -1226,6 +1230,8 @@ def write_schemes_test_suite(name):
"1",
# - run - environmentVariablesIncludeDefaults
"0",
# - run - storeKitConfigurationPath
"run storekit config",
# - run - enableAddressSanitizer
"1",
# - run - enableThreadSanitizer
Expand Down Expand Up @@ -1330,6 +1336,8 @@ def write_schemes_test_suite(name):
"-1",
# - run - environmentVariablesIncludeDefaults
"1",
# - run - storeKitConfigurationPath
"/Configuration.storekit",
# - run - enableAddressSanitizer
"0",
# - run - enableThreadSanitizer
Expand Down
17 changes: 17 additions & 0 deletions tools/generators/lib/XCScheme/src/CreateLaunchAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public struct CreateLaunchAction {
enableMainThreadChecker: Bool,
enableThreadPerformanceChecker: Bool,
environmentVariables: [EnvironmentVariable],
storeKitConfigurationPath: String?,
postActions: [ExecutionAction],
preActions: [ExecutionAction],
runnable: Runnable?
Expand All @@ -33,6 +34,7 @@ public struct CreateLaunchAction {
/*enableMainThreadChecker:*/ enableMainThreadChecker,
/*enableThreadPerformanceChecker:*/ enableThreadPerformanceChecker,
/*environmentVariables:*/ environmentVariables,
/*storeKitConfigurationPath:*/ storeKitConfigurationPath,
/*postActions:*/ postActions,
/*preActions:*/ preActions,
/*runnable:*/ runnable
Expand All @@ -53,6 +55,7 @@ extension CreateLaunchAction {
_ enableMainThreadChecker: Bool,
_ enableThreadPerformanceChecker: Bool,
_ environmentVariables: [EnvironmentVariable],
_ storeKitConfigurationPath: String?,
_ postActions: [ExecutionAction],
_ preActions: [ExecutionAction],
_ runnable: Runnable?
Expand All @@ -68,6 +71,7 @@ extension CreateLaunchAction {
enableMainThreadChecker: Bool,
enableThreadPerformanceChecker: Bool,
environmentVariables: [EnvironmentVariable],
storeKitConfigurationPath: String?,
postActions: [ExecutionAction],
preActions: [ExecutionAction],
runnable: Runnable?
Expand Down Expand Up @@ -202,6 +206,18 @@ ignoresPersistentStateOnLaunch = "NO"
runnableString = ""
}

let storeKitConfigurationFileReferenceString: String
if let storeKitConfigurationPath {
storeKitConfigurationFileReferenceString = #"""
<StoreKitConfigurationFileReference
identifier = "\#(storeKitConfigurationPath)">
</StoreKitConfigurationFileReference>

"""#
} else {
storeKitConfigurationFileReferenceString = ""
}

return #"""
<LaunchAction
\#(components.joined(separator: "\n "))>
Expand All @@ -210,6 +226,7 @@ ignoresPersistentStateOnLaunch = "NO"
\#(runnableString)\#
\#(commandLineArguments.commandLineArgumentsString)\#
\#(environmentVariables.environmentVariablesString)\#
\#(storeKitConfigurationFileReferenceString)\#
</LaunchAction>
"""#
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,45 @@ final class CreateLaunchActionTests: XCTestCase {

XCTAssertNoDifference(action, expectedAction)
}

func test_storekit_configuration() {
// Arrange
let buildConfiguration = "Debug"
let runnable = Runnable.path(path: "/Foo/Bar.app")

let expectedAction = #"""
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<PathRunnable
runnableDebuggingMode = "0"
FilePath = "/Foo/Bar.app">
</PathRunnable>
<StoreKitConfigurationFileReference
identifier = "/Configuration.storekit">
</StoreKitConfigurationFileReference>
</LaunchAction>
"""#

// Act

let action = createLaunchActionWithDefaults(
buildConfiguration: buildConfiguration,
storeKitConfigurationPath: "/Configuration.storekit",
runnable: runnable
)

// Assert

XCTAssertNoDifference(action, expectedAction)
}
}

private func createLaunchActionWithDefaults(
Expand All @@ -592,6 +631,7 @@ private func createLaunchActionWithDefaults(
enableMainThreadChecker: Bool = true,
enableThreadPerformanceChecker: Bool = true,
environmentVariables: [EnvironmentVariable] = [],
storeKitConfigurationPath: String? = nil,
postActions: [ExecutionAction] = [],
preActions: [ExecutionAction] = [],
runnable: Runnable? = nil
Expand All @@ -606,6 +646,7 @@ private func createLaunchActionWithDefaults(
enableMainThreadChecker: enableMainThreadChecker,
enableThreadPerformanceChecker: enableThreadPerformanceChecker,
environmentVariables: environmentVariables,
storeKitConfigurationPath: storeKitConfigurationPath,
postActions: postActions,
preActions: preActions,
runnable: runnable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ extension Generator.CreateAutomaticSchemeInfo {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: runEnvironmentVariables,
storeKitConfigurationPath: nil,
launchTarget: launchTarget,
xcodeConfiguration: nil
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ set
as: String?.self,
in: url
)
let storeKitConfigurationPath = try consumeArg(
"run-storekit-configuration-path",
as: String?.self,
in: url
)

if let launchTarget,
launchTarget.canExpandMacros && environmentVariablesIncludeDefaults
Expand All @@ -544,6 +549,7 @@ set
enableMainThreadChecker: enableMainThreadChecker,
enableThreadPerformanceChecker: enableThreadPerformanceChecker,
environmentVariables: environmentVariables,
storeKitConfigurationPath: storeKitConfigurationPath,
launchTarget: launchTarget,
xcodeConfiguration: xcodeConfiguration
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ extension Generator.CreateScheme {
enableThreadPerformanceChecker: schemeInfo.run.enableThreadPerformanceChecker,
environmentVariables: launchRunnable == nil ?
[] : schemeInfo.run.environmentVariables,
storeKitConfigurationPath: schemeInfo.run.storeKitConfigurationPath,
postActions: launchPostActions
.sorted(by: compareExecutionActions)
.map(\.action),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct SchemeInfo: Equatable {
let enableMainThreadChecker: Bool
let enableThreadPerformanceChecker: Bool
let environmentVariables: [EnvironmentVariable]
let storeKitConfigurationPath: String?
let launchTarget: LaunchTarget?
let xcodeConfiguration: String?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: baseEnvironmentVariables,
storeKitConfigurationPath: nil,
launchTarget: .target(
primary: launchable,
extensionHost: nil
Expand Down Expand Up @@ -233,6 +234,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: baseEnvironmentVariables,
storeKitConfigurationPath: nil,
launchTarget: .target(
primary: launchable,
extensionHost: extensionHost
Expand Down Expand Up @@ -311,6 +313,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: baseEnvironmentVariables,
storeKitConfigurationPath: nil,
launchTarget: .target(
primary: launchable,
extensionHost: nil
Expand Down Expand Up @@ -389,6 +392,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableThreadPerformanceChecker: false,
environmentVariables:
baseEnvironmentVariables + environmentVariables,
storeKitConfigurationPath: nil,
launchTarget: .target(
primary: launchable,
extensionHost: nil
Expand Down Expand Up @@ -464,6 +468,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: baseEnvironmentVariables,
storeKitConfigurationPath: nil,
launchTarget: nil,
xcodeConfiguration: nil
),
Expand Down Expand Up @@ -532,6 +537,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: [],
storeKitConfigurationPath: nil,
launchTarget: nil,
xcodeConfiguration: nil
),
Expand Down Expand Up @@ -603,6 +609,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: [],
storeKitConfigurationPath: nil,
launchTarget: nil,
xcodeConfiguration: nil
),
Expand Down Expand Up @@ -675,6 +682,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: [],
storeKitConfigurationPath: nil,
launchTarget: nil,
xcodeConfiguration: nil
),
Expand Down Expand Up @@ -742,6 +750,7 @@ final class CreateAutomaticSchemeInfoTests: XCTestCase {
enableMainThreadChecker: false,
enableThreadPerformanceChecker: false,
environmentVariables: [],
storeKitConfigurationPath: nil,
launchTarget: nil,
xcodeConfiguration: nil
),
Expand Down
2 changes: 2 additions & 0 deletions tools/generators/xcschemes/test/SchemeInfo+Testing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extension SchemeInfo.Run {
enableThreadSanitizer: Bool = false,
enableUBSanitizer: Bool = false,
environmentVariables: [EnvironmentVariable] = [],
storeKitConfigurationPath: String? = nil,
launchTarget: SchemeInfo.LaunchTarget? = nil,
xcodeConfiguration: String? = nil
) -> Self {
Expand All @@ -66,6 +67,7 @@ extension SchemeInfo.Run {
enableMainThreadChecker: enableMainThreadChecker,
enableThreadPerformanceChecker: enableThreadPerformanceChecker,
environmentVariables: environmentVariables,
storeKitConfigurationPath: storeKitConfigurationPath,
launchTarget: launchTarget,
xcodeConfiguration: xcodeConfiguration
)
Expand Down
Loading
Loading