From 21f159b4f812d83e0e5ffb9482d401423f9f62da Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 26 Jul 2019 16:34:21 +0300 Subject: [PATCH 01/22] build Release configuration with specific xcconfig --- xcode/commonFastfile | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 73e596c..fb4884c 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -122,6 +122,8 @@ private_lane :buildArchive do |options| exportOptions = icloudEnvironment.to_s.empty? ? {} : {iCloudContainerEnvironment: icloudEnvironment} exportOptions[:compileBitcode] = options[:compileBitcode] || false + set_xcconfig_for_configuration_of_project(options[:configuration], "Release", options[:xcodeproj_path]) + gym( clean: true, workspace: options[:workspace], @@ -129,7 +131,7 @@ private_lane :buildArchive do |options| archive_path: "./", output_directory: "./", output_name: options[:output_name], - configuration: options[:configuration], + configuration: "Release", export_method: options[:method], export_options: exportOptions, skip_package_ipa: options[:skip_package_ipa], @@ -307,3 +309,19 @@ end def fabric_keys_from_shell_script(shell_script_contents) shell_script_contents.gsub("\\n", "").partition('Fabric/run\" ').last.partition('";').first.split(" ") end + +def set_xcconfig_for_configuration_of_project(xcconfig_name, configuration_name, xcodeproj_path) + require 'xcodeproj' + + project = Xcodeproj::Project.open(xcodeproj_path) + + is_app_target = lambda { |t| !t.test_target_type? && t.product_type == Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application] } + application_target = project.native_targets.select(&is_app_target).first + build_configuration = application_target.build_configuration_list[configuration_name] + + build_configuration_reference = project.files.select { |f| f.path.start_with?(xcconfig_name) }.first + + build_configuration.base_configuration_reference = build_configuration_reference + + project.save() +end From cb59454a47ec605565a14a7de47c59677a3f80d8 Mon Sep 17 00:00:00 2001 From: DashaGitHub Date: Fri, 9 Aug 2019 18:51:04 +0300 Subject: [PATCH 02/22] Turn on repo update command --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index fb4884c..64dee17 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -20,7 +20,7 @@ private_lane :installDependencies do |options| end cocoapods( - repo_update: false + repo_update: true ) end From 1250921a31689374c0d56becc8e76e6d90aab103 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 23 Aug 2019 12:59:10 +0300 Subject: [PATCH 03/22] use AppStore config for AppStoreRelease lane --- xcode/commonFastfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 1d69481..d04431b 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -122,7 +122,11 @@ private_lane :buildArchive do |options| exportOptions = icloudEnvironment.to_s.empty? ? {} : {iCloudContainerEnvironment: icloudEnvironment} exportOptions[:compileBitcode] = options[:compileBitcode] || false - set_xcconfig_for_configuration_of_project(options[:configuration], "Release", options[:xcodeproj_path]) + xcconfig_name = options[:configuration] + configuration_name = options[:configuration_name] + xcodeproj_path = options[:xcodeproj_path] + + set_xcconfig_for_configuration_of_project(xcconfig_name, configuration_name, xcodeproj_path) gym( clean: true, @@ -131,7 +135,7 @@ private_lane :buildArchive do |options| archive_path: "./", output_directory: "./", output_name: options[:output_name], - configuration: "Release", + configuration: configuration_name, export_method: options[:method], export_options: exportOptions, skip_package_ipa: options[:skip_package_ipa], @@ -304,6 +308,7 @@ def make_options_for_lane_name(lane_name) method = configuration_type_from_lane_name(lane_name) return { :configuration => lane_name, + :configuration_name => lane_name.start_with?("AppStore") ? "AppStore" : "Release", :method => method, :type => profile_type_from_configuration_type(method) } From 2cd0b029d5085dade3ab9f931a00e8482811b945 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 23 Aug 2019 13:57:38 +0300 Subject: [PATCH 04/22] select AppStore xcconfig for AppStoreRelease lane --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index d04431b..06cb474 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -307,7 +307,7 @@ end def make_options_for_lane_name(lane_name) method = configuration_type_from_lane_name(lane_name) return { - :configuration => lane_name, + :configuration => lane_name.start_with?("AppStore") ? "AppStore" : lane_name, :configuration_name => lane_name.start_with?("AppStore") ? "AppStore" : "Release", :method => method, :type => profile_type_from_configuration_type(method) From 94a72409e9b7c018666e27fd1020ec89e76a288b Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 29 Aug 2019 12:54:49 +0300 Subject: [PATCH 05/22] add bundle install call --- xcode/commonFastfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 06cb474..ec19eae 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -9,6 +9,8 @@ private_lane :installDependencies do |options| sh("rm -rf #{podsReposPath}") end + bundle_install() + if File.exists? "../Cartfile" begin carthage(command: "bootstrap", platform: "iOS") @@ -214,7 +216,7 @@ lane :ManuallyUpdateCodeSigning do |options| shallow_clone = false branch = 'fastlane_certificates' - storage_conf = lambda do + storage_conf = lambda do new_storage = Match::Storage.for_mode('git', { git_url: git_url, shallow_clone: shallow_clone, git_branch: branch, clone_branch_directly: false}) new_storage.download return new_storage @@ -257,7 +259,7 @@ lane :ManuallyUpdateCodeSigning do |options| storage = storage_conf.call encryption = encryption_conf_for_storage.call(storage) - files_to_delete = files_diff.map do |file| + files_to_delete = files_diff.map do |file| old_file = file old_file.slice! old_directory new_file = File.join(storage.working_directory, old_file) From 6a125006eb5bee74e83997fa135d288311b408c3 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 29 Aug 2019 14:00:43 +0300 Subject: [PATCH 06/22] change path of gem home for bundler --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index ec19eae..0cea863 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -9,7 +9,7 @@ private_lane :installDependencies do |options| sh("rm -rf #{podsReposPath}") end - bundle_install() + bundle_install(path: "../.gem") if File.exists? "../Cartfile" begin From 3bffb17ee61ccfa2a919dd39d52898cd845f299d Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Fri, 30 Aug 2019 20:50:08 +0300 Subject: [PATCH 07/22] fix config lane for work wih multiple configs --- xcode/commonFastfile | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 0cea863..aa0bbca 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -364,13 +364,23 @@ def set_xcconfig_for_configuration_of_project(xcconfig_name, configuration_name, project = Xcodeproj::Project.open(xcodeproj_path) - is_app_target = lambda { |t| !t.test_target_type? && t.product_type == Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application] } - application_target = project.native_targets.select(&is_app_target).first - build_configuration = application_target.build_configuration_list[configuration_name] + is_app_target = lambda do |t| + application_const = Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application] + extension_const = Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension] + + is_valid_id = [application_const, extension_const].include?(t.product_type) + return !t.test_target_type? && is_valid_id + end - build_configuration_reference = project.files.select { |f| f.path.start_with?(xcconfig_name) }.first + application_targets = project.native_targets.select(&is_app_target) + + application_targets.each do |target| + build_configuration = target.build_configuration_list[configuration_name] + config_name = target.name + xcconfig_name + build_configuration_reference = project.files.select { |f| f.path.start_with?(config_name) }.first + build_configuration.base_configuration_reference = build_configuration_reference + end - build_configuration.base_configuration_reference = build_configuration_reference project.save() end From 6d01fefb6f43108049d2abc80048a14371d6c787 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Mon, 2 Sep 2019 14:02:25 +0300 Subject: [PATCH 08/22] refactor --- xcode/commonFastfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index aa0bbca..2ad35d9 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -364,15 +364,15 @@ def set_xcconfig_for_configuration_of_project(xcconfig_name, configuration_name, project = Xcodeproj::Project.open(xcodeproj_path) - is_app_target = lambda do |t| - application_const = Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application] - extension_const = Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension] - - is_valid_id = [application_const, extension_const].include?(t.product_type) - return !t.test_target_type? && is_valid_id - end + target_to_modify_selector = lambda do |t| + supported_product_types = [ + Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application] + Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension] + ] + return !t.test_target_type? && supported_product_types.include?(t.product_type) +end - application_targets = project.native_targets.select(&is_app_target) + application_targets = project.native_targets.select(&target_to_modify_selector) application_targets.each do |target| build_configuration = target.build_configuration_list[configuration_name] From b0f9fbc69a4c088c077bb87ce1c560b3ede31ebc Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Tue, 3 Sep 2019 18:56:23 +0300 Subject: [PATCH 09/22] fix missing comma --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 2ad35d9..ce68e58 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -366,7 +366,7 @@ def set_xcconfig_for_configuration_of_project(xcconfig_name, configuration_name, target_to_modify_selector = lambda do |t| supported_product_types = [ - Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application] + Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application], Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension] ] return !t.test_target_type? && supported_product_types.include?(t.product_type) From b6ef418a07aa88abddfac2e32eea08f83964e604 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Thu, 12 Sep 2019 22:35:27 +0300 Subject: [PATCH 10/22] add configs generator script --- xcode/config_generator/Readme.md | 3 + xcode/config_generator/gen_configurations.py | 94 ++++++++++++++++++ xcode/config_generator/render_xcconfigs.rb | 98 +++++++++++++++++++ xcode/config_generator/settings.json | 25 +++++ .../config_generator/target_xcconfig.mustache | 7 ++ 5 files changed, 227 insertions(+) create mode 100644 xcode/config_generator/Readme.md create mode 100644 xcode/config_generator/gen_configurations.py create mode 100644 xcode/config_generator/render_xcconfigs.rb create mode 100644 xcode/config_generator/settings.json create mode 100644 xcode/config_generator/target_xcconfig.mustache diff --git a/xcode/config_generator/Readme.md b/xcode/config_generator/Readme.md new file mode 100644 index 0000000..77fe832 --- /dev/null +++ b/xcode/config_generator/Readme.md @@ -0,0 +1,3 @@ +# Генератор конфигурационных файлов в формате `.xcconfig` + + здесь должна быть инструкция или ссылка на нее \ No newline at end of file diff --git a/xcode/config_generator/gen_configurations.py b/xcode/config_generator/gen_configurations.py new file mode 100644 index 0000000..22845ed --- /dev/null +++ b/xcode/config_generator/gen_configurations.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals # python 2/3 support + +from itertools import chain +import json + +distribution_options = ["Enterprise", "Standard"] +server_type_options = ["Mock", "Touchin", "Customer"] +server_environment_options = ["Dev", "Test", "Stage", "Prod"] +ssl_pinning_options = ["WithSSLPinning", "WithoutSSLPinning"] +build_type_options = ["Debug", "Release"] + +all_options = [ + distribution_options, + server_type_options, + server_environment_options, + ssl_pinning_options, + build_type_options +] + +def combine_string_with_options(all_options, string="", applied_options=[]): + if len(all_options) == 0: + yield string, applied_options + return + + for current_option in chain.from_iterable(all_options[:1]): + for result_tuple in combine_string_with_options(all_options[1:], string + current_option, applied_options + [current_option]): + yield result_tuple + + yield ("AppStoreRelease", ['AppStore', 'Customer', 'Prod', 'WithSSLPinning', 'Release']) + +def make_config_dict(args): + config_name, applied_options = args + + if "Enterprise" in applied_options: + account_type = "Enterprise" + elif "Standard" in applied_options: + account_type = "Standard" + else: + account_type = "AppStore" + + if "Debug" in applied_options: + build_type = "debug" + elif "AppStore" in applied_options: + build_type = "appstore" + else: + build_type = "release" + + return { + "name": config_name, + "build_type": build_type, + "account_type": account_type, + "xcconfig_options": [ + { + "key": "SWIFT_ACTIVE_COMPILATION_CONDITIONS", + "value": " ".join(map(lambda option: option.upper(), applied_options)) + }, + { + "key": "DEBUG_INFORMATION_FORMAT", + "value": "dwarf" if "Debug" in applied_options else "dwarf-with-dsym" + }, + { + "key": "VALIDATE_PRODUCT", + "value": "NO" if "Debug" in applied_options else "YES" + }, + { + "key": "ENABLE_TESTABILITY", + "value": "YES" if "Debug" in applied_options else "NO" + }, + { + "key": "CODE_SIGN_IDENTITY", + "value": "iPhone Developer" if account_type == "Standard" else "iPhone Distribution" + }, + { + "key": "GCC_OPTIMIZATION_LEVEL", + "value": "0" if "Debug" in applied_options else "s" + }, + { + "key": "SWIFT_OPTIMIZATION_LEVEL", + "value": "-Onone" if "Debug" in applied_options else "-O" + }, + { + "key": "SWIFT_COMPILATION_MODE", + "value": "singlefile" if "Debug" in applied_options else "wholemodule" + } + ] + } + + +config_dicts = map(make_config_dict, combine_string_with_options(all_options)) + +print(json.dumps({"configurations": config_dicts}, indent=4)) diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb new file mode 100644 index 0000000..750a2e7 --- /dev/null +++ b/xcode/config_generator/render_xcconfigs.rb @@ -0,0 +1,98 @@ +require 'json' +require 'mustache' + + +# create config files if needed +system("touch configs_data.json") unless File.exist?("configs_data") +system("mkdir TargetConfigurations") unless Dir.exist?("TargetConfigurations") + +# call python script and generate configs to config file +system("python gen_configurations.py > configs_data.json") + + +# open settings + template file +settings = JSON.load(File.open("settings.json")) +target_xcconfig_tempate = File.read("target_xcconfig.mustache") + + +# set global property +targets = settings["targets"] + +# make tuple of key and value become mustache template element +def config_option(key, value) + return { "key" => key, "value" => value } +end + +# return empty array or generated dev team hash +def development_team_if_needed(properties, account_type) + development_team_key = "DEVELOPMENT_TEAM" + if properties.key?(development_team_key) + return [] + end + + team_value = account_type == "Standard" ? "D4HA43V467" : "228J5MMU7S" + return [config_option(development_team_key, team_value)] +end + +# return empty array or generated provisioning profile hash +def provisioning_profile_if_needed(properties, account_type) + provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" + if properties.key?(provisioning_key) + return [] + end + + bundle_id = properties["PRODUCT_BUNDLE_IDENTIFIER"] + if account_type == "AppStore" + app_store_profiile = "match AppStore " + bundle_id + return [config_option(provisioning_key, app_store_profiile)] + else + return [config_option(provisioning_key, bundle_id)] + end +end + +# generate missing properties if needed +def generate_missing_properties(properties, account_type) + result = [] + result.concat(development_team_if_needed(properties, account_type)) + result.concat(provisioning_profile_if_needed(properties, account_type)) + return result +end + +# run through all target in project +targets.each do |target| + + # need open everytime, because script make some changes only for this target + configs = JSON.load(File.open("configs_data.json"))["configurations"] + + # run through all configs + configs.each do |config| + + # take default values + account_type = config["account_type"] + target_name = target.keys.first + properties = target[target_name][account_type] + + # add properties from settings file + properties.each do |key, value| + config["xcconfig_options"].append(config_option(key, value)) + end + + # add missing properties if needed + config["xcconfig_options"].concat(generate_missing_properties(properties, account_type)) + + # create settings pack + config_data = { + "target_name": target_name, + "configuration": config + } + + # create file for every setting in loop + File.open("TargetConfigurations/" + target_name + config["name"] + ".xcconfig", 'w') { |file| + file.puts(Mustache.render(target_xcconfig_tempate, config_data)) + } + end + +end + +# remove config file, it's trash +system("rm configs_data.json") if File.exist?("configs_data.json") diff --git a/xcode/config_generator/settings.json b/xcode/config_generator/settings.json new file mode 100644 index 0000000..d70867d --- /dev/null +++ b/xcode/config_generator/settings.json @@ -0,0 +1,25 @@ +{ + "targets": [ + { + "target_name": { + "Standard": { + "PROVISIONING_PROFILE_SPECIFIER": "", + "PRODUCT_BUNDLE_IDENTIFIER": "", + "CODE_SIGN_ENTITLEMENTS": "" + }, + + "Enterprise": { + "PROVISIONING_PROFILE_SPECIFIER": "", + "PRODUCT_BUNDLE_IDENTIFIER": "", + "CODE_SIGN_ENTITLEMENTS": "" + }, + + "AppStore": { + "DEVELOPMENT_TEAM": "", + "PRODUCT_BUNDLE_IDENTIFIER": "", + "CODE_SIGN_ENTITLEMENTS": "" + } + } + } + ] +} diff --git a/xcode/config_generator/target_xcconfig.mustache b/xcode/config_generator/target_xcconfig.mustache new file mode 100644 index 0000000..7e5477a --- /dev/null +++ b/xcode/config_generator/target_xcconfig.mustache @@ -0,0 +1,7 @@ +#include "Pods/Target Support Files/Pods-{{target_name}}/Pods-{{target_name}}.{{configuration.build_type}}.xcconfig" + +{{#configuration.xcconfig_options}} +{{key}} = {{value}} +{{/configuration.xcconfig_options}} + +CODE_SIGN_STYLE = Manual \ No newline at end of file From 20d4e506983a61a483c81035236513cd541c7104 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Fri, 13 Sep 2019 14:15:48 +0300 Subject: [PATCH 11/22] refactor --- xcode/config_generator/Readme.md | 3 --- xcode/config_generator/render_xcconfigs.rb | 14 +++++++++----- xcode/config_generator/settings.json | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 xcode/config_generator/Readme.md diff --git a/xcode/config_generator/Readme.md b/xcode/config_generator/Readme.md deleted file mode 100644 index 77fe832..0000000 --- a/xcode/config_generator/Readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Генератор конфигурационных файлов в формате `.xcconfig` - - здесь должна быть инструкция или ссылка на нее \ No newline at end of file diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index 750a2e7..a3eecb5 100644 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -1,10 +1,14 @@ require 'json' require 'mustache' +# Constants +configs_folder_name = "TargetConfigurations" +standard_dev_team = "D4HA43V467" +enterprise_dev_team = "228J5MMU7S" # create config files if needed -system("touch configs_data.json") unless File.exist?("configs_data") -system("mkdir TargetConfigurations") unless Dir.exist?("TargetConfigurations") +File.new("configs_data.json", 'a') +Dir.mkdir(configs_folder_name) unless Dir.exist?(configs_folder_name) # call python script and generate configs to config file system("python gen_configurations.py > configs_data.json") @@ -30,7 +34,7 @@ def development_team_if_needed(properties, account_type) return [] end - team_value = account_type == "Standard" ? "D4HA43V467" : "228J5MMU7S" + team_value = account_type == "Standard" ? standard_dev_team : enterprise_dev_team return [config_option(development_team_key, team_value)] end @@ -87,7 +91,7 @@ targets.each do |target| } # create file for every setting in loop - File.open("TargetConfigurations/" + target_name + config["name"] + ".xcconfig", 'w') { |file| + File.open(configs_folder_name + "/" + target_name + config["name"] + ".xcconfig", 'w') { |file| file.puts(Mustache.render(target_xcconfig_tempate, config_data)) } end @@ -95,4 +99,4 @@ targets.each do |target| end # remove config file, it's trash -system("rm configs_data.json") if File.exist?("configs_data.json") +File.delete("configs_data.json") if File.exist?("configs_data.json") diff --git a/xcode/config_generator/settings.json b/xcode/config_generator/settings.json index d70867d..a190324 100644 --- a/xcode/config_generator/settings.json +++ b/xcode/config_generator/settings.json @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": { + "YOUR_TARGET_NAME": { "Standard": { "PROVISIONING_PROFILE_SPECIFIER": "", "PRODUCT_BUNDLE_IDENTIFIER": "", From dea34e68e7bae8fb96eef44a4fc2541e74f5c093 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Fri, 13 Sep 2019 14:29:05 +0300 Subject: [PATCH 12/22] refactor generators functions --- xcode/config_generator/render_xcconfigs.rb | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index a3eecb5..081051d 100644 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -28,37 +28,35 @@ def config_option(key, value) end # return empty array or generated dev team hash -def development_team_if_needed(properties, account_type) - development_team_key = "DEVELOPMENT_TEAM" - if properties.key?(development_team_key) - return [] - end - +def generate_development_team(account_type) team_value = account_type == "Standard" ? standard_dev_team : enterprise_dev_team - return [config_option(development_team_key, team_value)] + return config_option(development_team_key, team_value) end # return empty array or generated provisioning profile hash -def provisioning_profile_if_needed(properties, account_type) - provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" - if properties.key?(provisioning_key) - return [] - end - - bundle_id = properties["PRODUCT_BUNDLE_IDENTIFIER"] +def generate_provisioning_profile(bundle_id, account_type) if account_type == "AppStore" app_store_profiile = "match AppStore " + bundle_id return [config_option(provisioning_key, app_store_profiile)] else - return [config_option(provisioning_key, bundle_id)] + return config_option(provisioning_key, bundle_id) end end # generate missing properties if needed def generate_missing_properties(properties, account_type) result = [] - result.concat(development_team_if_needed(properties, account_type)) - result.concat(provisioning_profile_if_needed(properties, account_type)) + development_team_key = "DEVELOPMENT_TEAM" + provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" + + unless properties.key?(development_team_key) + result.append(generate_development_team(account_type)) + end + + unless properties.key?(provisioning_key) + result.append(generate_provisioning_profile(properties["PRODUCT_BUNDLE_IDENTIFIER"], account_type)) + end + return result end From 1a381bad79d39664c8182560ed97ef2576510816 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Mon, 16 Sep 2019 13:59:09 +0300 Subject: [PATCH 13/22] refactor --- .../{settings.json => custom_settings.json} | 0 xcode/config_generator/render_xcconfigs.rb | 25 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) rename xcode/config_generator/{settings.json => custom_settings.json} (100%) diff --git a/xcode/config_generator/settings.json b/xcode/config_generator/custom_settings.json similarity index 100% rename from xcode/config_generator/settings.json rename to xcode/config_generator/custom_settings.json diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index 081051d..b4ad9b7 100644 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -2,20 +2,19 @@ require 'json' require 'mustache' # Constants -configs_folder_name = "TargetConfigurations" -standard_dev_team = "D4HA43V467" -enterprise_dev_team = "228J5MMU7S" +$configs_folder_name = "TargetConfigurations" +$standard_dev_team = "D4HA43V467" +$enterprise_dev_team = "228J5MMU7S" -# create config files if needed -File.new("configs_data.json", 'a') -Dir.mkdir(configs_folder_name) unless Dir.exist?(configs_folder_name) +# create config directory if needed +Dir.mkdir($configs_folder_name) unless Dir.exist?($configs_folder_name) # call python script and generate configs to config file system("python gen_configurations.py > configs_data.json") # open settings + template file -settings = JSON.load(File.open("settings.json")) +settings = JSON.load(File.open("custom_settings.json")) target_xcconfig_tempate = File.read("target_xcconfig.mustache") @@ -28,13 +27,13 @@ def config_option(key, value) end # return empty array or generated dev team hash -def generate_development_team(account_type) - team_value = account_type == "Standard" ? standard_dev_team : enterprise_dev_team +def generate_development_team(development_team_key, account_type) + team_value = account_type == "Standard" ? $standard_dev_team : $enterprise_dev_team return config_option(development_team_key, team_value) end # return empty array or generated provisioning profile hash -def generate_provisioning_profile(bundle_id, account_type) +def generate_provisioning_profile(provisioning_key, bundle_id, account_type) if account_type == "AppStore" app_store_profiile = "match AppStore " + bundle_id return [config_option(provisioning_key, app_store_profiile)] @@ -50,11 +49,11 @@ def generate_missing_properties(properties, account_type) provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" unless properties.key?(development_team_key) - result.append(generate_development_team(account_type)) + result.append(generate_development_team(development_team_key, account_type)) end unless properties.key?(provisioning_key) - result.append(generate_provisioning_profile(properties["PRODUCT_BUNDLE_IDENTIFIER"], account_type)) + result.append(generate_provisioning_profile(provisioning_key, properties["PRODUCT_BUNDLE_IDENTIFIER"], account_type)) end return result @@ -89,7 +88,7 @@ targets.each do |target| } # create file for every setting in loop - File.open(configs_folder_name + "/" + target_name + config["name"] + ".xcconfig", 'w') { |file| + File.open($configs_folder_name + "/" + target_name + config["name"] + ".xcconfig", 'w') { |file| file.puts(Mustache.render(target_xcconfig_tempate, config_data)) } end From d73b9f8500be0215514abb17946e336f6165aa98 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Mon, 16 Sep 2019 20:06:03 +0300 Subject: [PATCH 14/22] add missing bundle id generator --- xcode/config_generator/render_xcconfigs.rb | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index b4ad9b7..dbe8d84 100644 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -5,6 +5,9 @@ require 'mustache' $configs_folder_name = "TargetConfigurations" $standard_dev_team = "D4HA43V467" $enterprise_dev_team = "228J5MMU7S" +$standard_bundle_prefix = "ru.touchin." +$enterprise_bundle_prefix = "com.touchin." +$bundle_id_key = "PRODUCT_BUNDLE_IDENTIFIER" # create config directory if needed Dir.mkdir($configs_folder_name) unless Dir.exist?($configs_folder_name) @@ -36,24 +39,38 @@ end def generate_provisioning_profile(provisioning_key, bundle_id, account_type) if account_type == "AppStore" app_store_profiile = "match AppStore " + bundle_id - return [config_option(provisioning_key, app_store_profiile)] + return config_option(provisioning_key, app_store_profiile) else return config_option(provisioning_key, bundle_id) end end +def generate_bundle_id(target_name, account_type) + bundle_id_prefix = account_type == "Standard" ? $standard_bundle_prefix : $enterprise_bundle_prefix + bundle_id = bundle_id_prefix + target_name + return config_option($bundle_id_key, bundle_id) +end + # generate missing properties if needed -def generate_missing_properties(properties, account_type) +def generate_missing_properties(target_name, properties, account_type) result = [] development_team_key = "DEVELOPMENT_TEAM" provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" + unless properties.key?($bundle_id_key) + bundle_id_config = generate_bundle_id(target_name, account_type) + bundle_id = bundle_id_config["value"] + result.append(bundle_id_config) + else + bundle_id = properties[$bundle_id_key] + end + unless properties.key?(development_team_key) result.append(generate_development_team(development_team_key, account_type)) end unless properties.key?(provisioning_key) - result.append(generate_provisioning_profile(provisioning_key, properties["PRODUCT_BUNDLE_IDENTIFIER"], account_type)) + result.append(generate_provisioning_profile(provisioning_key, bundle_id, account_type)) end return result @@ -79,7 +96,7 @@ targets.each do |target| end # add missing properties if needed - config["xcconfig_options"].concat(generate_missing_properties(properties, account_type)) + config["xcconfig_options"].concat(generate_missing_properties(target_name, properties, account_type)) # create settings pack config_data = { From f1cbf0431887d617a8aa4e7dea33a19492895131 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Mon, 16 Sep 2019 22:27:51 +0300 Subject: [PATCH 15/22] add lanes generator --- .../generate_lanes_template.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 xcode/config_generator/generate_lanes_template.rb diff --git a/xcode/config_generator/generate_lanes_template.rb b/xcode/config_generator/generate_lanes_template.rb new file mode 100644 index 0000000..313689c --- /dev/null +++ b/xcode/config_generator/generate_lanes_template.rb @@ -0,0 +1,30 @@ +require 'json' + +# call python script and generate configs to config file +system("python gen_configurations.py > configs_data.json") + +# generate fastlane lane block +def generate_lane(lane_name) + first_line = "lane :" + lane_name + " do |options|\n" + second_line = "\tbuildConfiguration(options)\n" + third_line = "end\n" + separator = "\n" + return first_line + second_line + third_line + separator +end + +# open configs for rendering +configs = JSON.load(File.open("configs_data.json"))["configurations"] + +# map configs to lanes +lanes = configs.map { |config| generate_lane(config["name"]) } + +# make all lanes uniq +lanes.uniq! + +# write lanes to file +File.open("lanes_template", 'w') { |file| + file.puts(lanes) +} + +# remove config file, it's trash +File.delete("configs_data.json") if File.exist?("configs_data.json") From e628d3703970e3042110e9dac79de25c37cd7235 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Tue, 17 Sep 2019 11:21:30 +0300 Subject: [PATCH 16/22] Revert "add lanes generator" This reverts commit f1cbf0431887d617a8aa4e7dea33a19492895131. --- .../generate_lanes_template.rb | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 xcode/config_generator/generate_lanes_template.rb diff --git a/xcode/config_generator/generate_lanes_template.rb b/xcode/config_generator/generate_lanes_template.rb deleted file mode 100644 index 313689c..0000000 --- a/xcode/config_generator/generate_lanes_template.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'json' - -# call python script and generate configs to config file -system("python gen_configurations.py > configs_data.json") - -# generate fastlane lane block -def generate_lane(lane_name) - first_line = "lane :" + lane_name + " do |options|\n" - second_line = "\tbuildConfiguration(options)\n" - third_line = "end\n" - separator = "\n" - return first_line + second_line + third_line + separator -end - -# open configs for rendering -configs = JSON.load(File.open("configs_data.json"))["configurations"] - -# map configs to lanes -lanes = configs.map { |config| generate_lane(config["name"]) } - -# make all lanes uniq -lanes.uniq! - -# write lanes to file -File.open("lanes_template", 'w') { |file| - file.puts(lanes) -} - -# remove config file, it's trash -File.delete("configs_data.json") if File.exist?("configs_data.json") From f86e9b653a0ace1c7885025c8fba47a20b0d7a4b Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 13 Jan 2020 12:30:44 +0300 Subject: [PATCH 17/22] add cache_builds option to carthage --- xcode/commonFastfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index a011a27..edea840 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -19,7 +19,7 @@ private_lane :installDependencies do |options| rescue # workaround for https://github.com/Carthage/Carthage/issues/2298 sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") - carthage(command: "update", platform: "iOS") + carthage(command: "update", platform: "iOS", cache_builds: true) end end @@ -366,7 +366,7 @@ def set_xcconfig_for_configuration_of_project(xcconfig_name, configuration_name, project = Xcodeproj::Project.open(xcodeproj_path) - target_to_modify_selector = lambda do |t| + target_to_modify_selector = lambda do |t| supported_product_types = [ Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application], Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension] From 16eeea5b550685c42eba93b10862247ce8e6d189 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 17 Jan 2020 11:19:48 +0300 Subject: [PATCH 18/22] add Rome support --- xcode/commonFastfile | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index edea840..396b8f8 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -13,19 +13,39 @@ private_lane :installDependencies do |options| bundle_install(path: "../.gem") end - if File.exists? "../Cartfile" - begin - carthage(command: "bootstrap", platform: "iOS") - rescue - # workaround for https://github.com/Carthage/Carthage/issues/2298 - sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") - carthage(command: "update", platform: "iOS", cache_builds: true) - end - end - cocoapods( repo_update: true ) + + if File.exists? "../Cartfile" + use_rome = File.exists? "../Romefile" + + swift_version = sh("xcrun swift --version | head -1 | sed 's/.*\\(\(.*\)\\).*/\\1/' | tr -d \"()\" | tr \" \" \"-\"").chop + rome_path = "Pods/Rome/rome" + rome_options = "--platform iOS --cache-prefix #{swift_version} --romefile ../Romefile" + + carthage_install = lambda do + if use_rome + sh("#{rome_path} download #{rome_options}") + end + + carthage(command: "bootstrap", platform: "iOS", cache_builds: true) + + if use_rome + sh("#{rome_path} list --missing #{rome_options} | awk '{print $1}' | xargs #{rome_path} upload #{rome_options}") + end + end + + carthage_install.call + + # begin + + # rescue + # # workaround for https://github.com/Carthage/Carthage/issues/2298 + # sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") + # carthage_install() + # end + end end private_lane :uploadToFabric do |options| From 1a1381dd19c2120c5ed51cee5ff798e2e6d54c40 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 17 Jan 2020 11:47:53 +0300 Subject: [PATCH 19/22] =?UTF-8?q?change=20Rom=D1=83=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 396b8f8..58708c4 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -21,7 +21,7 @@ private_lane :installDependencies do |options| use_rome = File.exists? "../Romefile" swift_version = sh("xcrun swift --version | head -1 | sed 's/.*\\(\(.*\)\\).*/\\1/' | tr -d \"()\" | tr \" \" \"-\"").chop - rome_path = "Pods/Rome/rome" + rome_path = "../Pods/Rome/rome" rome_options = "--platform iOS --cache-prefix #{swift_version} --romefile ../Romefile" carthage_install = lambda do From b2a07d79c3aaf4a46709adc621edd1288c3ed265 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 22 Jan 2020 18:17:11 +0300 Subject: [PATCH 20/22] run rome from project folder --- xcode/commonFastfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 58708c4..892396b 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -21,18 +21,18 @@ private_lane :installDependencies do |options| use_rome = File.exists? "../Romefile" swift_version = sh("xcrun swift --version | head -1 | sed 's/.*\\(\(.*\)\\).*/\\1/' | tr -d \"()\" | tr \" \" \"-\"").chop - rome_path = "../Pods/Rome/rome" - rome_options = "--platform iOS --cache-prefix #{swift_version} --romefile ../Romefile" + rome_path = "Pods/Rome/rome" + rome_options = "--platform iOS --cache-prefix #{swift_version} --romefile Romefile" carthage_install = lambda do if use_rome - sh("#{rome_path} download #{rome_options}") + sh("cd .. && #{rome_path} download #{rome_options}") end carthage(command: "bootstrap", platform: "iOS", cache_builds: true) if use_rome - sh("#{rome_path} list --missing #{rome_options} | awk '{print $1}' | xargs #{rome_path} upload #{rome_options}") + sh("cd .. && #{rome_path} list --missing #{rome_options} | awk '{print $1}' | xargs -I framework_name #{rome_path} upload framework_name #{rome_options}") end end From 555c0f2e58dcdf06b7e00af90ea1793c1340cae5 Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 22 Jan 2020 22:18:40 +0300 Subject: [PATCH 21/22] Update swiftlint.yml --- xcode/.swiftlint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml index 3e81483..b731824 100644 --- a/xcode/.swiftlint.yml +++ b/xcode/.swiftlint.yml @@ -60,6 +60,7 @@ excluded: - Carthage - Pods - Generated + - Localization line_length: 128 From d9d0a6034f20c4997234296b1f3e489af2abd5f8 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 23 Jan 2020 12:55:44 +0300 Subject: [PATCH 22/22] fix carthage retry --- xcode/commonFastfile | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 892396b..0258809 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -36,15 +36,13 @@ private_lane :installDependencies do |options| end end - carthage_install.call - - # begin - - # rescue - # # workaround for https://github.com/Carthage/Carthage/issues/2298 - # sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") - # carthage_install() - # end + begin + carthage_install.call + rescue + # workaround for https://github.com/Carthage/Carthage/issues/2298 + sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") + carthage_install.call + end end end