Skip to content

Commit

Permalink
[Fastlane.Swift] Swift fastlane does not run on Apple Silicon fastlan…
Browse files Browse the repository at this point in the history
…e#18502

* [Swift] Integrate the required steps to only upgrade the Xcode project build phase and flags needed.
  • Loading branch information
kikeenrique committed Dec 6, 2021
1 parent 66371bc commit 88cc7c4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions fastlane/lib/fastlane/swift_runner_upgrader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def initialize
end

def upgrade_if_needed!(dry_run: false)
upgraded = add_missing_flags!(dry_run: dry_run)
upgraded = add_missing_copy_phase!(dry_run: dry_run)
upgraded = add_missing_groups_and_files!(dry_run: dry_run)
upgraded = upgrade_files!(dry_run: dry_run) || upgraded
upgraded = add_new_files_to_groups! || upgraded
Expand Down Expand Up @@ -208,5 +210,57 @@ def add_missing_groups_and_files!(dry_run: false)

return true # yup, we definitely updated groups
end

# adds build_settings flags to fastlane_runner_target
def add_missing_flags!(dry_run: false)
# Check if upgrade is needed
# If fastlane build settings exists already, we don't need any more changes to the Xcode project
self.fastlane_runner_target.build_configurations.each { |config|
return false if dry_run && config.build_settings["CODE_SIGN_IDENTITY"].nil?
return false if dry_run && config.build_settings["MACOSX_DEPLOYMENT_TARGET"].nil?
}
return true if dry_run

# Proceed to upgrade
self.fastlane_runner_target.build_configurations.each { |config|
config.build_settings["CODE_SIGN_IDENTITY"] = "-"
config.build_settings["MACOSX_DEPLOYMENT_TARGET"] = "10.12"
}
target_project.save()
end

# adds new copy files build phase to fastlane_runner_target
def add_missing_copy_phase!(dry_run: false)
# Check if upgrade is needed
# If fastlane copy files build phase exists already, we don't need any more changes to the Xcode project
phase_copy_sign = self.fastlane_runner_target.copy_files_build_phases.select { |phase_copy| phase_copy.name == "FastlaneRunnerCopySigned" }.first

old_phase_copy_sign = self.fastlane_runner_target.shell_script_build_phases.select { |phase_copy| phase_copy.shell_script == "cd \"${SRCROOT}\"\ncd ../..\ncp \"${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}\" .\n" }.first
unless phase_copy_sign
return false if dry_run
end

return true if dry_run

# Proceed to upgrade
old_phase_copy_sign.remove_from_project() unless old_phase_copy_sign.nil?

unless phase_copy_sign
# Create a copy files build phase
phase_copy_sign = self.fastlane_runner_target.new_copy_files_build_phase("FastlaneRunnerCopySigned")
phase_copy_sign.dst_path = "$SRCROOT/../.."
phase_copy_sign.dst_subfolder_spec = "0"
phase_copy_sign.run_only_for_deployment_postprocessing = "0"
targetBinaryReference = self.fastlane_runner_target.product_reference
phase_copy_sign.add_file_reference(targetBinaryReference)

# Set "Code sign on copy" flag on Xcode for fastlane_runner_target
targetBinaryReference.build_files.each { |targetBinaryBuildFileReference|
targetBinaryBuildFileReference.settings = {"ATTRIBUTES": ["CodeSignOnCopy"]}
}
end

target_project.save()
end
end
end

0 comments on commit 88cc7c4

Please sign in to comment.