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

showBuildSettings does not require to call clean #8921

Merged
merged 6 commits into from Apr 21, 2017

Conversation

punty
Copy link
Contributor

@punty punty commented Apr 19, 2017

Checklist

  • [x ] I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • [x ] I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • [x ] I've read the Contribution Guidelines
  • [ x] I've updated the documentation if necessary.

Description

In show building settings, don't call xcodebuild clean, because it's not a necessary workaround anymore.

Motivation and Context

This change will allow the user to do not clean the build (unless specified in the following commands).
Previously for example event setting clean: false, will result in callling clean because of the generated
xcodebuild clean -showBuildSettings

As stated in the comment this was a workaround for an xcodebuild bug. But this bug has being fixed in 8.3 so it's not necessary anymore. https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
As huge benefit, I can keep using fastlane with my CI, and for example, caching pod builds, and reduce my build time significantly.

This pull request also fixes #8099

….3 because Xcode bug has being fixed and this workaround is not required anymore
Copy link
Collaborator

@hjanuschka hjanuschka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 looking promising, left a couple of comments
many thx for your contribution @punty

@@ -299,7 +299,12 @@ def within_a_temp_dir
it "SUPPORTED_PLATFORMS should be iphonesimulator iphoneos" do
options = { project: "./fastlane_core/spec/fixtures/projects/Example.xcodeproj" }
@project = FastlaneCore::Project.new(options, xcodebuild_list_silent: true, xcodebuild_suppress_stderr: true)
expect(FastlaneCore::Project).to receive(:run_command).with("xcodebuild clean -showBuildSettings -project ./fastlane_core/spec/fixtures/projects/Example.xcodeproj 2> /dev/null", { timeout: 10, retries: 3, print: false }).and_return(File.read("./fastlane_core/spec/fixtures/projects/build_settings_with_toolchains"))
if FastlaneCore::Helper.xcode_higher_than_8_3?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should be splitted up into 2 tests. with mocked return of xcode_atleast on time with false and one time with true to be sure that it works on old and new xcodes.

the current variation is depending on the local xcode installation.

@@ -213,6 +213,13 @@ def self.keychain_path(name)
keychain_path
end

# @return true if XCode version is higher than 8.3
def self.xcode_higher_than_8_3?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename this to: self.xcode_atleast?(version) - so we can use this method for variuous version checks of xcode?

def self.xcode_higher_than_8_3?
FastlaneCore::UI.user_error!("Unable to locate Xcode. Please make sure to have Xcode installed on your machine") if xcode_version.nil?
v = xcode_version
Gem::Version.new(v) >= Gem::Version.new('8.3.0')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and use it here: Gem::Version.new(v) >= Gem::Version.new(version)

UI.user_error!("Unable to locate Xcode. Please make sure to have Xcode installed on your machine") if xcode_version.nil?
v = xcode_version
Gem::Version.new(v) >= Gem::Version.new('8.3.0')
FastlaneCore::Helper.xcode_higher_than_8_3?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then use FastlaneCore::Helper.xcode_atleast?("8.3")

@punty
Copy link
Contributor Author

punty commented Apr 20, 2017

@hjanuschka I implemented the changes you requested! Much better!

expect(@project.build_settings(key: "SUPPORTED_PLATFORMS")).to eq("iphonesimulator iphoneos")
end
unless FastlaneCore::Helper.xcode_atleast?('8.3')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get rid of the unless, and mock the result of xcode_atleast to 8.1?
removing the unless and turning the allow to an expect should do it, the allow should also be changed in the above test. so we always no matter which local xcode is installed verify it works on 8.1 and 8.3

or i am i wrong?

thx for your patience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this. According to the official Apple documentation, the XCode bug has being fixed in 8.3, so if we are running this test, by mocking the call to return true, we will end up calling showBuildSettings without the clean command (even for XCode < 8.3). So in this case there is a risk this command will hangs?
According to Apple this happens only if the project contains Core Data. But I still think we should include test for scenarios that are not possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow is used for Mocking, https://www.relishapp.com/rspec/rspec-mocks/v/2-14/docs/method-stubs so when I call that method i return true or false

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the command is not really run in the tests.
expect(FastlaneCore::Project).to receive(:run_command).with(command.to_s, { timeout: 10, retries: 3, print: false }).and_return(File.read("./fastlane_core/spec/fixtures/projects/build_settings_with_toolchains")) mocks it.

the goal should be to test the following two scenarios.

user has xcode < 8.3

  • force xcode_atleast?("8.3") to return false
  • expect the resulting command, to include clean

user has xcode >= 8.3

  • force xcode_atleast?("8.3") to return true
  • expect the resulting command, to NOT include clean

by forcing the result we bypass the local installation interfering the unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the clarification. I will have a look at that!

@hjanuschka
Copy link
Collaborator

@punty awesome, looking solid 👍 thx for your work and patience, one comment left.

@punty
Copy link
Contributor Author

punty commented Apr 20, 2017

@hjanuschka thanks again for your suggestions! I implemented the changes you requested

@@ -213,6 +213,13 @@ def self.keychain_path(name)
keychain_path
end

# @return true if XCode version is higher than 8.3
def self.xcode_atleast?(version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xcode_at_least?

@@ -296,10 +296,21 @@ def within_a_temp_dir
end

describe "build_settings() can handle empty lines" do
it "SUPPORTED_PLATFORMS should be iphonesimulator iphoneos" do
it "SUPPORTED_PLATFORMS should be iphonesimulator iphoneos on XCode >= 8.3" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcode

# The 'clean' portion of this command is a workaround for an xcodebuild bug with Core Data projects.
# See: https://github.com/fastlane/fastlane/pull/5626
command = "xcodebuild clean -showBuildSettings #{xcodebuild_parameters.join(' ')}"
if FastlaneCore::Helper.xcode_atleast?('8.3')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you reference in a command on why this was added, when it was fixed, etc.

@punty
Copy link
Contributor Author

punty commented Apr 20, 2017

@KrauseFx thanks for your feedback. I just implemented the changes you requested.

@hjanuschka hjanuschka merged commit 18322ef into fastlane:master Apr 21, 2017
@hjanuschka
Copy link
Collaborator

@punty 🚀 merged, many thx for your contribution 🎉

@mpirri mpirri mentioned this pull request Apr 21, 2017
@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.28.3 🚀

@punty punty deleted the fix-not-necessary-clean branch April 24, 2017 08:15
@fastlane fastlane locked and limited conversation to collaborators Jul 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean parameter ignored during build settings check
5 participants