Начал реализацию dsl к билд коммандам

This commit is contained in:
Rustam Zaitov 2013-10-03 21:41:52 +04:00
parent 6e61455c90
commit b0abdcccdb
10 changed files with 126 additions and 16 deletions

View File

@ -0,0 +1 @@
__author__ = 'rzaitov'

View File

@ -0,0 +1,26 @@
import commands.patch_infoplist_command as plist
import os
config = {
'version': '0.1.2',
# patch_info_plist
'plist-CoolApp_rel_path': 'BuildSample/Info.plist',
'plist-CoolApp_CFBundleVersion': '@version', # set CFBundleVersion
'plist-CoolApp_CFBundleDisplayName': '@app_name', # set CFBundleDisplayName
}
base_dir = '/Users/rzaitov/Documents/Apps/BuildScript',
class PathProvider:
def __init__(self, base_dir):
self._base_dir = base_dir
def ResolveAbsPath(self, rel_path):
abs_path = os.path.join(self._base_dir, rel_path)
return abs_path
provider = PathProvider(base_dir)
patcher = plist.PatchInfoPlist(config, provider)
patcher.Execute()

View File

@ -6,10 +6,10 @@ class BuildCommand:
self._cmd_prefix_len = len(self._command_prefix)
self._prefix_name= 'prefix'
self._group_name= 'group'
self._app_name= 'app'
self._key_name = 'key'
def __init__(self, config, cmd_prefix, separator='-'):
def __init__(self, config, cmd_prefix, separator=' '):
self._separator = separator
self._config = config
self.SetCommandPrefix(cmd_prefix)
@ -35,7 +35,7 @@ class BuildCommand:
result = {
self._prefix_name: identifiers[0],
self._group_name: identifiers[1],
self._app_name: identifiers[1],
self._key_name: identifiers[2]
}

View File

@ -16,7 +16,7 @@ class PatchCsproj(bcmd.BuildCommand):
for key_token in key_tokens:
key_info = self.ParseKeyToken(key_token)
project_name = key_info[self._group_name]
project_name = key_info[self._app_name]
key = key_info[self._key_name]
value = self.ParseValueFromToken(self._config[key_token])

View File

@ -4,9 +4,10 @@ import utils.infoplist.patcher as plist
class PatchInfoPlist(bcmd.BuildCommand):
def __init__(self, config):
bcmd.BuildCommand.__init__(self, config, 'plist-')
def __init__(self, config, path_provider):
bcmd.BuildCommand.__init__(self, config, 'plist')
self._info_plist_rel_path = None
self._path_provider = path_provider
self._plist_dict = {}
self.ParseConfig()
@ -44,10 +45,7 @@ class PatchInfoPlist(bcmd.BuildCommand):
return config_key[PatchInfoPlist._cmd_prefix_len:]
def Execute(self):
sln_path = self._config['sln_path']
pConverter = pc.PathConverter(sln_path)
info_plist_abs_path = pConverter.Convert(self._info_plist_rel_path)
info_plist_abs_path = self._path_provider.ResolveAbsPath(self._info_plist_rel_path)
patcher = plist.Patcher(info_plist_abs_path)
patcher.AddOrReplace(self._plist_dict)

View File

@ -0,0 +1,8 @@
import parser.StringValueParser as parser
class AttributeNameParser(parser.StringValueParser):
def __init__(self, attribute_name, model):
parser.StringValueParser.__init__(self, attribute_name, model)
def ProcessToken(self, token):
self._model.rel_path = ''

View File

@ -0,0 +1,10 @@
class StringValueParser:
def __init__(self, valid_string, model):
self._valid_string = valid_string
self._model = model
def IsTokenValid(self, token):
return token == self._valid_string
def ProcessToken(self, token):
pass

View File

@ -0,0 +1 @@
__author__ = 'rzaitov'

View File

@ -0,0 +1,66 @@
from parser.StringValueParser import *
from parser.AttributeNameParser import *
class CsprojParser:
def __init__(self, string_to_parse, value_token, config):
self._config = config
self._token_buffer = string_to_parse.split(' ')
self._token_buffer.append(value_token)
self._token_index = 0;
self._project = None
def Parse(self):
while self._token_index < len(self._token_buffer):
self.ProcessToken()
def ProcessToken(self):
token = self.getCurrentToken()
if self.isCsprojStatement(token):
self._token_index += 1
elif self.isAppToken(token):
self.processAppToken(token)
self._token_index += 1
elif self.isAttributeToken(token):
attribute_name = self.processAttributeNameToken(token)
self._token_index += 1
token = self.getCurrentToken()
attribute_value = self.processAttributeValueToken(token)
setattr(self.project, attribute_name, attribute_value)
def isCsprojStatement(self, token):
return token == 'csproj'
def isAppToken(self, token):
return token.startswith('app:')
def isAttributeToken(self, token):
return ':' not in token
def processAppToken(self, appToken):
appName = appToken[len('app:')]
self.project = Csproj(appName)
self._settings[appName] = self.project
def processAttributeNameToken(self, token):
attribute_name = token
return attribute_name
def processAttributeValueToken(self, token):
value = token
if token.startswith('@'):
key = token[1:]
value = self._config[key]
return value
def getCurrentToken(self):
token = self._token_buffer[self._token_index]
return token
class Csproj:
def __init__(self, appName):
self.appName = appName

View File

@ -30,17 +30,17 @@ ios_development_root = {
'projects_to_exclude': ['NotCompileApp'],
# patch_info_plist
'plist-CoolApp_rel_path': 'BuildSample/Info.plist',
'plist-CoolApp_CFBundleVersion': '@version', # set CFBundleVersion
'plist-CoolApp_CFBundleDisplayName': '@app_name', # set CFBundleDisplayName
'plist app:CoolApp rel_path': 'BuildSample/Info.plist',
'plist app:CoolApp key:CFBundleVersion': '@version', # set CFBundleVersion
'plist app:CoolApp key:CFBundleDisplayName': '@app_name', # set CFBundleDisplayName
# test flight command section
'tf_CoolApp_output': 'ipa',
# patch_csproj
'csproj-CoolApp-rel_path': 'BuildSample/CoolApp.csproj',
'csproj-CoolApp-CodesignProvision': '@codesign_provision',
'csproj-CoolApp-CodesignKey': '@codesign_key',
'csproj group:CoolApp key:rel_path': 'BuildSample/CoolApp.csproj',
'csproj group:CoolApp key:CodesignProvision': '@codesign_provision',
'csproj group:CoolApp key:CodesignKey': '@codesign_key',
'build_steps':[
# before build