From cf2aa3f7ee10030f140f8aa5b3743b66e0bf5799 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 21 Jul 2021 17:17:22 +0300 Subject: [PATCH 1/9] localization script refactoring --- xcode/aux_scripts/import_strings.php | 16 ++++++------- xcode/build_phases/localization.sh | 34 ++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php index 7cfdc7d..84b076c 100644 --- a/xcode/aux_scripts/import_strings.php +++ b/xcode/aux_scripts/import_strings.php @@ -1,14 +1,13 @@ $value) { $value_without_linefeed = preg_replace("/\r|\n/", " ", $value); - $ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", comment: "")'."\n".PHP_EOL; + $ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", bundle: '.$BUNDLE.', comment: "'.$value_without_linefeed.'")'."\n".PHP_EOL; } $ios_swift_strings .= '}'.PHP_EOL; - file_put_contents($localization.'String+Localization.swift', $ios_swift_strings); + echo $ios_swift_strings; + file_put_contents($LOCALIZATION_PATH.'String+Localization.swift', $ios_swift_strings); } } ?> diff --git a/xcode/build_phases/localization.sh b/xcode/build_phases/localization.sh index 8c8bf61..dea12e3 100644 --- a/xcode/build_phases/localization.sh +++ b/xcode/build_phases/localization.sh @@ -1,16 +1,36 @@ -LOCALIZATION_PATH="${PRODUCT_NAME}/Resources/Localization" -#first argument set strings folder path +#!/bin/sh + +# Description: +# Generates Localizeable.strings and String+Localization.swift files. +# +# Parameters: +# $1 - path to strings folder containing json files. +# $2 - path to Localization folder (output). +# $3 - Bundle for localization. Default is `.main`. +# +# Required environment variables: +# SCRIPT_DIR - directory of current script. +# +# Optional environment variables: +# PRODUCT_NAME - product name to produce path to localization folder (output). +# +# Examples of usage: +# . localization.sh +# . localization.sh common/strings Resources/Localization/ .main +# + STRINGS_FOLDER=${1:-"common/strings"} +LOCALIZATION_PATH=${2:-"${PRODUCT_NAME}/Resources/Localization/"} +BUNDLE=${3:-".main"} if ! [ -e ${LOCALIZATION_PATH} ]; then - echo "${PROJECT_DIR}/${LOCALIZATION_PATH} path does not exist. Add these folders and try again." + echo "${LOCALIZATION_PATH} path does not exist. Add these folders and try again." exit 1 fi -if ! [ -e "${PROJECT_DIR}/${STRINGS_FOLDER}" ]; then - echo "${PROJECT_DIR}/${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder." +if ! [ -e "${STRINGS_FOLDER}" ]; then + echo "${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder." exit 1 fi -#second argument set strings script path -php ${2:-build-scripts/xcode/aux_scripts/import_strings.php} ${PRODUCT_NAME} ${STRINGS_FOLDER} +php ${SCRIPT_DIR}/../aux_scripts/import_strings.php ${LOCALIZATION_PATH} ${STRINGS_FOLDER} ${BUNDLE} From 82a44c2a1ce1f8f81e6e4826bf2170be0cc0131e Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 21 Jul 2021 17:56:06 +0300 Subject: [PATCH 2/9] disable cyrillic_strings rule for String+Localization.swift --- xcode/aux_scripts/import_strings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php index 84b076c..f2d822f 100644 --- a/xcode/aux_scripts/import_strings.php +++ b/xcode/aux_scripts/import_strings.php @@ -41,6 +41,7 @@ '// swiftlint:disable superfluous_disable_command'.PHP_EOL. '// swiftlint:disable line_length'.PHP_EOL. '// swiftlint:disable file_length'.PHP_EOL. + '// swiftlint:disable cyrillic_strings'.PHP_EOL. '// swiftlint:disable identifier_name'.PHP_EOL.PHP_EOL. 'public extension String {'.PHP_EOL; foreach ($json as $key=>$value) { From 0d555bea19bf9decdb2bbd5113cb94f7cba6f7c2 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 21 Jul 2021 21:06:58 +0300 Subject: [PATCH 3/9] generate xcodeproj before increment build number --- xcode/commonFastfile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index ea9d55c..fa3e6a3 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -86,17 +86,6 @@ private_lane :buildConfiguration do |options| options[:scheme] = options[:scheme] || options[:appName] options[:lane_name] = lane_name - configuration_type = Touchlane::ConfigurationType.from_lane_name(lane_name) - options = fill_up_options_using_configuration_type(options, configuration_type) - - openKeychain(options) - - if !options[:buildNumber].nil? - increment_build_number( - build_number: options[:buildNumber] - ) - end - ipa_name = "#{options[:appName]}.ipa" options[:output_name] = ipa_name @@ -106,8 +95,19 @@ private_lane :buildConfiguration do |options| options[:xcodeproj_path] = options[:xcodeproj_path] || "../#{options[:appName]}.xcodeproj" options[:workspace] = options[:workspace] || "./#{options[:appName]}.xcworkspace" + configuration_type = Touchlane::ConfigurationType.from_lane_name(lane_name) + options = fill_up_options_using_configuration_type(options, configuration_type) + generate_xcodeproj_if_needed(options) + openKeychain(options) + + if !options[:buildNumber].nil? + increment_build_number( + build_number: options[:buildNumber] + ) + end + installDependencies(options) run_code_generation_phase_if_needed(options) From 63ecad8042c73e26c7b95ac15fadcca5d22d331b Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 22 Jul 2021 09:29:22 +0300 Subject: [PATCH 4/9] remove hadcoded CODE_SIGN_STYLE key; remove PROVISIONING_PROFILE_SPECIFIER auto generation --- xcode/config_generator/render_xcconfigs.rb | 17 +++-------------- xcode/config_generator/target_xcconfig.mustache | 4 +--- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index 69aee0b..c96c120 100755 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -64,23 +64,12 @@ def fetch_development_team(development_team_key, distribution_type) return config_option(development_team_key, team_value) end -# Return empty array or generated provisioning profile hash -def generate_provisioning_profile(provisioning_key, bundle_id, distribution_type) - case distribution_type - when "appstore" - app_store_profile = "match AppStore " + bundle_id - config_option(provisioning_key, app_store_profile) - else - config_option(provisioning_key, bundle_id) - end -end - # Generate missing properties if needed def generate_missing_properties(target_name, properties, distribution_type) result = [] development_team_key = "DEVELOPMENT_TEAM" - provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" bundle_id_key = "PRODUCT_BUNDLE_IDENTIFIER" + code_sign_style_key = "CODE_SIGN_STYLE" # Bundle_id_key should be among the properties (required by fastlane) unless properties.key?(bundle_id_key) @@ -91,8 +80,8 @@ def generate_missing_properties(target_name, properties, distribution_type) result.append(fetch_development_team(development_team_key, distribution_type)) end - unless properties.key?(provisioning_key) - result.append(generate_provisioning_profile(provisioning_key, properties[bundle_id_key], distribution_type)) + unless properties.key?(code_sign_style_key) + result.append(config_option(code_sign_style_key, "Manual")) end return result diff --git a/xcode/config_generator/target_xcconfig.mustache b/xcode/config_generator/target_xcconfig.mustache index 7e5477a..570fab1 100644 --- a/xcode/config_generator/target_xcconfig.mustache +++ b/xcode/config_generator/target_xcconfig.mustache @@ -2,6 +2,4 @@ {{#configuration.xcconfig_options}} {{key}} = {{value}} -{{/configuration.xcconfig_options}} - -CODE_SIGN_STYLE = Manual \ No newline at end of file +{{/configuration.xcconfig_options}} \ No newline at end of file From 6a032c324f17fd70c26d33acd7efd67772c19a17 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 27 Jul 2021 15:03:21 +0300 Subject: [PATCH 5/9] replace existing options when generating xcconfigs --- xcode/config_generator/render_xcconfigs.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index c96c120..b19f063 100755 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -102,7 +102,11 @@ targets.each do |target_name, target| # Add properties from settings file properties.each do |key, value| - config["xcconfig_options"].append(config_option(key, value)) + if config["xcconfig_options"].any? { |option| key == option["key"] } + config["xcconfig_options"].map! { |option| key == option["key"] ? config_option(key, value) : option } + else + config["xcconfig_options"].append(config_option(key, value)) + end end # Add missing properties if needed From 8d0449714bf8b3a53bc87561b1ad5b6b01e9249a Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 28 Jul 2021 15:58:18 +0300 Subject: [PATCH 6/9] set xcconfig for framework targets as well --- xcode/commonFastfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index fa3e6a3..d2686a2 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -420,7 +420,8 @@ def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodepro target_to_modify_selector = lambda do |t| supported_product_types = [ Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application], - Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension] + Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension], + Xcodeproj::Constants::PRODUCT_TYPE_UTI[:framework] ] return !t.test_target_type? && supported_product_types.include?(t.product_type) end @@ -428,10 +429,13 @@ def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodepro application_targets = project.native_targets.select(&target_to_modify_selector) application_targets.each do |target| - build_configuration = target.build_configuration_list[configuration] config_name = target.name + lane_name build_configuration_reference = project.files.select { |f| f.path.start_with?(config_name) }.first - build_configuration.base_configuration_reference = build_configuration_reference + + if !build_configuration_reference.nil? # target has custom xcconfig + build_configuration = target.build_configuration_list[configuration] + build_configuration.base_configuration_reference = build_configuration_reference + end end From 6cdd30a872bc018efbc42f1419c407a4a65971c5 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 28 Jul 2021 22:02:43 +0300 Subject: [PATCH 7/9] fix workspace path for code generation --- xcode/commonFastfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index d2686a2..a3147d3 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -93,7 +93,7 @@ private_lane :buildConfiguration do |options| options[:dsym_path] = "./#{options[:appName]}.app.dSYM.zip" options[:xcodeproj_path] = options[:xcodeproj_path] || "../#{options[:appName]}.xcodeproj" - options[:workspace] = options[:workspace] || "./#{options[:appName]}.xcworkspace" + options[:workspace] = options[:workspace] || File.expand_path("../#{options[:appName]}.xcworkspace") configuration_type = Touchlane::ConfigurationType.from_lane_name(lane_name) options = fill_up_options_using_configuration_type(options, configuration_type) @@ -458,6 +458,6 @@ def run_code_generation_phase_if_needed(options) code_generation_script_path = File.expand_path "../.githooks/scripts/CodeGen.sh" if File.exists? code_generation_script_path - sh(code_generation_script_path, options[:workspace_path]) + sh(code_generation_script_path, options[:workspace]) end end From 7c4149778cd5cbe7f9e5b808e4f77c9e1ceed5f2 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 4 Aug 2021 10:45:04 +0300 Subject: [PATCH 8/9] add backslashes before characters that need to be escaped --- xcode/aux_scripts/import_strings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php index f2d822f..e5c0a8d 100644 --- a/xcode/aux_scripts/import_strings.php +++ b/xcode/aux_scripts/import_strings.php @@ -46,7 +46,7 @@ 'public extension String {'.PHP_EOL; foreach ($json as $key=>$value) { $value_without_linefeed = preg_replace("/\r|\n/", " ", $value); - $ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", bundle: '.$BUNDLE.', comment: "'.$value_without_linefeed.'")'."\n".PHP_EOL; + $ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", bundle: '.$BUNDLE.', comment: "'.addslashes($value_without_linefeed).'")'."\n".PHP_EOL; } $ios_swift_strings .= '}'.PHP_EOL; echo $ios_swift_strings; From c2104468bd964f476407c57f2e3f03a94d07885e Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 4 Aug 2021 11:00:50 +0300 Subject: [PATCH 9/9] remove debug output --- xcode/aux_scripts/import_strings.php | 1 - 1 file changed, 1 deletion(-) diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php index e5c0a8d..1cd20ee 100644 --- a/xcode/aux_scripts/import_strings.php +++ b/xcode/aux_scripts/import_strings.php @@ -49,7 +49,6 @@ $ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", bundle: '.$BUNDLE.', comment: "'.addslashes($value_without_linefeed).'")'."\n".PHP_EOL; } $ios_swift_strings .= '}'.PHP_EOL; - echo $ios_swift_strings; file_put_contents($LOCALIZATION_PATH.'String+Localization.swift', $ios_swift_strings); } }