Merge pull request #139 from TouchInstinct/feature/configurationsGenerator

add configs generator script
This commit is contained in:
Sergey 2019-09-16 16:14:58 +03:00 committed by GitHub
commit 1a96d9ff5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 225 additions and 0 deletions

View File

@ -0,0 +1,25 @@
{
"targets": [
{
"YOUR_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": ""
}
}
}
]
}

View File

@ -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))

View File

@ -0,0 +1,99 @@
require 'json'
require 'mustache'
# Constants
$configs_folder_name = "TargetConfigurations"
$standard_dev_team = "D4HA43V467"
$enterprise_dev_team = "228J5MMU7S"
# 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("custom_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 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(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)]
else
return config_option(provisioning_key, bundle_id)
end
end
# generate missing properties if needed
def generate_missing_properties(properties, account_type)
result = []
development_team_key = "DEVELOPMENT_TEAM"
provisioning_key = "PROVISIONING_PROFILE_SPECIFIER"
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))
end
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($configs_folder_name + "/" + target_name + config["name"] + ".xcconfig", 'w') { |file|
file.puts(Mustache.render(target_xcconfig_tempate, config_data))
}
end
end
# remove config file, it's trash
File.delete("configs_data.json") if File.exist?("configs_data.json")

View File

@ -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