Skip to content

Commit

Permalink
Merge pull request #619 from jmkk/add_disableMainThreadChecker
Browse files Browse the repository at this point in the history
Add support for setting/getting main thread checker related flags for launch and test actions.
  • Loading branch information
dnkoutso authored Oct 28, 2018
2 parents acfb037 + fe507e7 commit f23193b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

##### Enhancements

* None.
* Add support for disableMainThreadChecker and stopOnEveryMainThreadCheckerIssue flags
[Jacek Suliga](https://github.com/jmkk)
[#619](https://github.com/CocoaPods/Xcodeproj/pull/619)

##### Bug Fixes

Expand Down
34 changes: 34 additions & 0 deletions lib/xcodeproj/scheme/launch_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ def allow_location_simulation=(flag)
@xml_element.attributes['allowLocationSimulation'] = bool_to_string(flag)
end

# @return [Bool]
# Whether this Build Action should disable detection of UI API misuse
# from background threads
#
def disable_main_thread_checker?
string_to_bool(@xml_element.attributes['disableMainThreadChecker'])
end

# @param [Bool] flag
# Set whether this Build Action should disable detection of UI API misuse
# from background threads
#
def disable_main_thread_checker=(flag)
@xml_element.attributes['disableMainThreadChecker'] = bool_to_string(flag)
end

# @return [Bool]
# Whether UI API misuse from background threads detection should pause execution.
# This flag is ignored when the thread checker disabled
# ([disable_main_thread_checker] flag).
#
def stop_on_every_main_thread_checker_issue?
string_to_bool(@xml_element.attributes['stopOnEveryMainThreadCheckerIssue'])
end

# @param [Bool] flag
# Set whether UI API misuse from background threads detection should pause execution.
# This flag is ignored when the thread checker disabled
# ([disable_main_thread_checker] flag).
#
def stop_on_every_main_thread_checker_issue=(flag)
@xml_element.attributes['stopOnEveryMainThreadCheckerIssue'] = bool_to_string(flag)
end

# @return [String]
# The launch automatically substyle
#
Expand Down
16 changes: 16 additions & 0 deletions lib/xcodeproj/scheme/test_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def should_use_launch_scheme_args_env=(flag)
@xml_element.attributes['shouldUseLaunchSchemeArgsEnv'] = bool_to_string(flag)
end

# @return [Bool]
# Whether this Test Action should disable detection of UI API misuse
# from background threads
#
def disable_main_thread_checker?
string_to_bool(@xml_element.attributes['disableMainThreadChecker'])
end

# @param [Bool] flag
# Set whether this Test Action should disable detection of UI API misuse
# from background threads
#
def disable_main_thread_checker=(flag)
@xml_element.attributes['disableMainThreadChecker'] = bool_to_string(flag)
end

# @return [Bool]
# Whether Clang Code Coverage is enabled ('Gather coverage data' turned ON)
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
disableMainThreadChecker = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
Expand Down Expand Up @@ -56,6 +57,8 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
disableMainThreadChecker = "YES"
stopOnEveryMainThreadCheckerIssue = "YES"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
Expand Down
2 changes: 2 additions & 0 deletions spec/scheme/launch_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Xcodeproj

action.xml_element.attributes['buildConfiguration'].should == 'Debug'
action.xml_element.attributes['allowLocationSimulation'].should == 'YES'
action.xml_element.attributes['disableMainThreadChecker'].nil?
action.xml_element.attributes['stopOnEveryMainThreadCheckerIssue'].nil?
end

it 'raises if created with an invalid XML node' do
Expand Down
2 changes: 2 additions & 0 deletions spec/scheme/test_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Xcodeproj
test_action.xml_element.attributes['selectedLauncherIdentifier'].should == 'Xcode.DebuggerFoundation.Launcher.LLDB'
test_action.xml_element.attributes['shouldUseLaunchSchemeArgsEnv'].should == 'YES'
test_action.xml_element.attributes['buildConfiguration'].should == 'Debug'
test_action.xml_element.attributes['disableMainThreadChecker'].nil?
end

it 'raises if created with an invalid XML node' do
Expand All @@ -28,6 +29,7 @@ module Xcodeproj
extend SpecHelper::XCScheme
specs_for_bool_attr(:should_use_launch_scheme_args_env => 'shouldUseLaunchSchemeArgsEnv')
specs_for_bool_attr(:code_coverage_enabled => 'codeCoverageEnabled')
specs_for_bool_attr(:disable_main_thread_checker => 'disableMainThreadChecker')

it '#testables' do
project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj')
Expand Down
3 changes: 3 additions & 0 deletions spec/scheme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module ProjectSpecs
it 'Properly map the scheme\'s TestAction' do
@scheme.test_action.should_use_launch_scheme_args_env?.should == true
@scheme.test_action.build_configuration.should == 'Debug'
@scheme.test_action.disable_main_thread_checker?.should == true

@scheme.test_action.testables.count.should == 0
@scheme.test_action.macro_expansions.count.should == 1
Expand All @@ -65,6 +66,8 @@ module ProjectSpecs
it 'Properly map the scheme\'s LaunchAction' do
@scheme.launch_action.allow_location_simulation?.should == true
@scheme.launch_action.build_configuration.should == 'Debug'
@scheme.launch_action.disable_main_thread_checker?.should == true
@scheme.launch_action.stop_on_every_main_thread_checker_issue?.should == true

bpr = @scheme.launch_action.buildable_product_runnable
bpr.class.should == Xcodeproj::XCScheme::BuildableProductRunnable
Expand Down

0 comments on commit f23193b

Please sign in to comment.