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

Add thread checkers to xcscheme.diagnostics #3096

5 changes: 4 additions & 1 deletion docs/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ An opaque value for the [`scheme_autogeneration_config`](xcodeproj-scheme_autoge
## xcschemes.diagnostics

<pre>
xcschemes.diagnostics(<a href="#xcschemes.diagnostics-address_sanitizer">address_sanitizer</a>, <a href="#xcschemes.diagnostics-thread_sanitizer">thread_sanitizer</a>, <a href="#xcschemes.diagnostics-undefined_behavior_sanitizer">undefined_behavior_sanitizer</a>)
xcschemes.diagnostics(<a href="#xcschemes.diagnostics-address_sanitizer">address_sanitizer</a>, <a href="#xcschemes.diagnostics-thread_sanitizer">thread_sanitizer</a>, <a href="#xcschemes.diagnostics-undefined_behavior_sanitizer">undefined_behavior_sanitizer</a>,
<a href="#xcschemes.diagnostics-main_thread_checker">main_thread_checker</a>, <a href="#xcschemes.diagnostics-thread_performance_checker">thread_performance_checker</a>)
</pre>

Defines the diagnostics to enable.
Expand All @@ -280,6 +281,8 @@ Defines the diagnostics to enable.
| <a id="xcschemes.diagnostics-address_sanitizer"></a>address_sanitizer | Whether to enable Address Sanitizer.<br><br>If `True`, [`thread_sanitizer`](#xcschemes.diagnostics-thread_sanitizer) must be `False`. | `False` |
| <a id="xcschemes.diagnostics-thread_sanitizer"></a>thread_sanitizer | Whether to enable Thread Sanitizer.<br><br>If `True`, [`address_sanitizer`](#xcschemes.diagnostics-address_sanitizer) must be `False`. | `False` |
| <a id="xcschemes.diagnostics-undefined_behavior_sanitizer"></a>undefined_behavior_sanitizer | Whether to enable Undefined Behavior Sanitizer. | `False` |
| <a id="xcschemes.diagnostics-main_thread_checker"></a>main_thread_checker | Whether to enable Main Thread Checker | `True` |
| <a id="xcschemes.diagnostics-thread_performance_checker"></a>thread_performance_checker | Whether to enable Thread Performance Checker | `True` |


<a id="xcschemes.env_value"></a>
Expand Down
6 changes: 6 additions & 0 deletions test/internal/xcschemes/info_constructors_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def info_constructors_test_suite(name):
address_sanitizer = "0",
thread_sanitizer = "0",
undefined_behavior_sanitizer = "0",
main_thread_checker = "1",
thread_performance_checker = "1",
),
)

Expand All @@ -243,13 +245,17 @@ def info_constructors_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),

# Expected
expected_info = struct(
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
)

Expand Down
12 changes: 12 additions & 0 deletions test/internal/xcschemes/infos_from_json_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ def infos_from_json_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = full_env,
env_include_defaults = "0",
Expand Down Expand Up @@ -800,6 +802,8 @@ def infos_from_json_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = expected_full_env,
env_include_defaults = "0",
Expand All @@ -826,6 +830,8 @@ def infos_from_json_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = full_env,
env_include_defaults = "0",
Expand All @@ -852,6 +858,8 @@ def infos_from_json_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = expected_full_env,
env_include_defaults = "0",
Expand Down Expand Up @@ -939,6 +947,8 @@ def infos_from_json_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = full_env,
env_include_defaults = "1",
Expand Down Expand Up @@ -1025,6 +1035,8 @@ def infos_from_json_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = expected_full_env,
env_include_defaults = "1",
Expand Down
2 changes: 2 additions & 0 deletions test/internal/xcschemes/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def _dict_to_diagnostics_info(d):
address_sanitizer = d["address_sanitizer"],
thread_sanitizer = d["thread_sanitizer"],
undefined_behavior_sanitizer = d["undefined_behavior_sanitizer"],
main_thread_checker = d["main_thread_checker"],
thread_performance_checker = d["thread_performance_checker"],
)

def _dict_to_launch_target_info(d):
Expand Down
28 changes: 28 additions & 0 deletions test/internal/xcschemes/write_schemes_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ def write_schemes_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = {
"A": xcscheme_infos_testable.make_env(
Expand Down Expand Up @@ -599,6 +601,8 @@ def write_schemes_test_suite(name):
address_sanitizer = "1",
thread_sanitizer = "1",
undefined_behavior_sanitizer = "1",
main_thread_checker = "1",
thread_performance_checker = "1",
),
env = {
"VAR\nWITH\nNEWLINES": xcscheme_infos_testable.make_env(
Expand Down Expand Up @@ -712,6 +716,10 @@ def write_schemes_test_suite(name):
"0",
# - test - enableUBSanitizer
"0",
# - test - enableMainThreadChecker
"1",
# - test - enableThreadPerformanceChecker
"1",
# - test - xcodeConfiguration
"",
# - run - buildTargets
Expand All @@ -728,6 +736,10 @@ def write_schemes_test_suite(name):
"0",
# - run - enableUBSanitizer
"0",
# - test - enableMainThreadChecker
"1",
# - test - enableThreadPerformanceChecker
"1",
# - run - xcodeConfiguration
"",
# - run - launchTarget - isPath
Expand Down Expand Up @@ -801,6 +813,10 @@ def write_schemes_test_suite(name):
"1",
# - test - enableUBSanitizer
"1",
# - test - enableMainThreadChecker
"1",
# - test - enableThreadPerformanceChecker
"1",
# - test - xcodeConfiguration
"Test",
# - run - buildTargets
Expand Down Expand Up @@ -842,6 +858,10 @@ def write_schemes_test_suite(name):
"1",
# - run - enableUBSanitizer
"1",
# - test - enableMainThreadChecker
"1",
# - test - enableThreadPerformanceChecker
"1",
# - run - xcodeConfiguration
"Run",
# - run - launchTarget - isPath
Expand Down Expand Up @@ -918,6 +938,10 @@ def write_schemes_test_suite(name):
"0",
# - test - enableUBSanitizer
"0",
# - test - enableMainThreadChecker
"1",
# - test - enableThreadPerformanceChecker
"1",
# - test - xcodeConfiguration
"",
# - run - buildTargets
Expand All @@ -934,6 +958,10 @@ def write_schemes_test_suite(name):
"0",
# - run - enableUBSanitizer
"0",
# - test - enableMainThreadChecker
"1",
# - test - enableThreadPerformanceChecker
"1",
# - run - xcodeConfiguration
"",
# - run - launchTarget - isPath
Expand Down
15 changes: 15 additions & 0 deletions tools/generators/lib/XCScheme/src/CreateLaunchAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public struct CreateLaunchAction {
enableAddressSanitizer: Bool,
enableThreadSanitizer: Bool,
enableUBSanitizer: Bool,
enableMainThreadChecker: Bool,
enableThreadPerformanceChecker: Bool,
environmentVariables: [EnvironmentVariable],
postActions: [ExecutionAction],
preActions: [ExecutionAction],
Expand All @@ -28,6 +30,8 @@ public struct CreateLaunchAction {
/*enableAddressSanitizer:*/ enableAddressSanitizer,
/*enableThreadSanitizer:*/ enableThreadSanitizer,
/*enableUBSanitizer:*/ enableUBSanitizer,
/*enableMainThreadChecker:*/ enableMainThreadChecker,
/*enableThreadPerformanceChecker:*/ enableThreadPerformanceChecker,
/*environmentVariables:*/ environmentVariables,
/*postActions:*/ postActions,
/*preActions:*/ preActions,
Expand All @@ -46,6 +50,8 @@ extension CreateLaunchAction {
_ enableAddressSanitizer: Bool,
_ enableThreadSanitizer: Bool,
_ enableUBSanitizer: Bool,
_ enableMainThreadChecker: Bool,
_ enableThreadPerformanceChecker: Bool,
_ environmentVariables: [EnvironmentVariable],
_ postActions: [ExecutionAction],
_ preActions: [ExecutionAction],
Expand All @@ -59,6 +65,8 @@ extension CreateLaunchAction {
enableAddressSanitizer: Bool,
enableThreadSanitizer: Bool,
enableUBSanitizer: Bool,
enableMainThreadChecker: Bool,
enableThreadPerformanceChecker: Bool,
environmentVariables: [EnvironmentVariable],
postActions: [ExecutionAction],
preActions: [ExecutionAction],
Expand Down Expand Up @@ -98,6 +106,13 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
components.append(#"enableUBSanitizer = "YES""#)
}

if !enableMainThreadChecker {
components.append(#"disableMainThreadChecker = "YES""#)
}
if !enableThreadPerformanceChecker {
components.append(#"disablePerformanceAntipatternChecker = "YES""#)
}

components.append(#"launchStyle = "0""#)

if isHosted {
Expand Down
15 changes: 15 additions & 0 deletions tools/generators/lib/XCScheme/src/CreateTestAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public struct CreateTestAction {
enableAddressSanitizer: Bool,
enableThreadSanitizer: Bool,
enableUBSanitizer: Bool,
enableMainThreadChecker: Bool,
enableThreadPerformanceChecker: Bool,
environmentVariables: [EnvironmentVariable],
expandVariablesBasedOn: BuildableReference?,
postActions: [ExecutionAction],
Expand All @@ -28,6 +30,8 @@ public struct CreateTestAction {
/*enableAddressSanitizer:*/ enableAddressSanitizer,
/*enableThreadSanitizer:*/ enableThreadSanitizer,
/*enableUBSanitizer:*/ enableUBSanitizer,
/*enableMainThreadChecker:*/ enableMainThreadChecker,
/*enableThreadPerformanceChecker:*/ enableThreadPerformanceChecker,
/*environmentVariables:*/ environmentVariables,
/*expandVariablesBasedOn:*/ expandVariablesBasedOn,
/*postActions:*/ postActions,
Expand All @@ -47,6 +51,8 @@ extension CreateTestAction {
_ enableAddressSanitizer: Bool,
_ enableThreadSanitizer: Bool,
_ enableUBSanitizer: Bool,
_ enableMainThreadChecker: Bool,
_ enableThreadPerformanceChecker: Bool,
_ environmentVariables: [EnvironmentVariable],
_ expandVariablesBasedOn: BuildableReference?,
_ postActions: [ExecutionAction],
Expand All @@ -61,6 +67,8 @@ extension CreateTestAction {
enableAddressSanitizer: Bool,
enableThreadSanitizer: Bool,
enableUBSanitizer: Bool,
enableMainThreadChecker: Bool,
enableThreadPerformanceChecker: Bool,
environmentVariables: [EnvironmentVariable],
expandVariablesBasedOn macroReference: BuildableReference?,
postActions: [ExecutionAction],
Expand Down Expand Up @@ -89,6 +97,13 @@ buildConfiguration = "\#(buildConfiguration)"
components.append(#"enableUBSanitizer = "YES""#)
}

if !enableMainThreadChecker {
components.append(#"disableMainThreadChecker = "YES""#)
}
if !enableThreadPerformanceChecker {
components.append(#"disablePerformanceAntipatternChecker = "YES""#)
}

let macroExpansion: String
if let macroReference {
macroExpansion = #"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,72 @@ final class CreateLaunchActionTests: XCTestCase {
XCTAssertNoDifference(action, expectedAction)
}

func test_disableMainThreadChecker() {
// Arrange

let buildConfiguration = "Profile"
let enableMainThreadChecker = false

let expectedAction = #"""
<LaunchAction
buildConfiguration = "Profile"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
disableMainThreadChecker = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
"""#

// Act

let action = createLaunchActionWithDefaults(
buildConfiguration: buildConfiguration,
enableMainThreadChecker: enableMainThreadChecker
)

// Assert

XCTAssertNoDifference(action, expectedAction)
}

func test_disableThreadPerformanceChecker() {
// Arrange

let buildConfiguration = "Profile"
let enableThreadPerformanceChecker = false

let expectedAction = #"""
<LaunchAction
buildConfiguration = "Profile"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
disablePerformanceAntipatternChecker = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
"""#

// Act

let action = createLaunchActionWithDefaults(
buildConfiguration: buildConfiguration,
enableThreadPerformanceChecker: enableThreadPerformanceChecker
)

// Assert

XCTAssertNoDifference(action, expectedAction)
}

func test_enableAddressSanitizer() {
// Arrange

Expand Down Expand Up @@ -523,6 +589,8 @@ private func createLaunchActionWithDefaults(
enableAddressSanitizer: Bool = false,
enableThreadSanitizer: Bool = false,
enableUBSanitizer: Bool = false,
enableMainThreadChecker: Bool = true,
enableThreadPerformanceChecker: Bool = true,
environmentVariables: [EnvironmentVariable] = [],
postActions: [ExecutionAction] = [],
preActions: [ExecutionAction] = [],
Expand All @@ -535,6 +603,8 @@ private func createLaunchActionWithDefaults(
enableAddressSanitizer: enableAddressSanitizer,
enableThreadSanitizer: enableThreadSanitizer,
enableUBSanitizer: enableUBSanitizer,
enableMainThreadChecker: enableMainThreadChecker,
enableThreadPerformanceChecker: enableThreadPerformanceChecker,
environmentVariables: environmentVariables,
postActions: postActions,
preActions: preActions,
Expand Down
Loading
Loading