diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php index 7cfdc7d..1cd20ee 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: "'.addslashes($value_without_linefeed).'")'."\n".PHP_EOL; } $ios_swift_strings .= '}'.PHP_EOL; - file_put_contents($localization.'String+Localization.swift', $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} diff --git a/xcode/commonFastfile b/xcode/commonFastfile index ea9d55c..a3147d3 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -86,9 +86,20 @@ private_lane :buildConfiguration do |options| options[:scheme] = options[:scheme] || options[:appName] options[:lane_name] = lane_name + ipa_name = "#{options[:appName]}.ipa" + options[:output_name] = ipa_name + + options[:ipa_path] = "./#{ipa_name}" + options[:dsym_path] = "./#{options[:appName]}.app.dSYM.zip" + + options[:xcodeproj_path] = options[:xcodeproj_path] || "../#{options[:appName]}.xcodeproj" + 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) + generate_xcodeproj_if_needed(options) + openKeychain(options) if !options[:buildNumber].nil? @@ -97,17 +108,6 @@ private_lane :buildConfiguration do |options| ) end - ipa_name = "#{options[:appName]}.ipa" - options[:output_name] = ipa_name - - options[:ipa_path] = "./#{ipa_name}" - options[:dsym_path] = "./#{options[:appName]}.app.dSYM.zip" - - options[:xcodeproj_path] = options[:xcodeproj_path] || "../#{options[:appName]}.xcodeproj" - options[:workspace] = options[:workspace] || "./#{options[:appName]}.xcworkspace" - - generate_xcodeproj_if_needed(options) - installDependencies(options) run_code_generation_phase_if_needed(options) @@ -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 @@ -454,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 diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index 69aee0b..b19f063 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 @@ -113,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 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