Отладил патчинг csproj файла
This commit is contained in:
parent
970be15c16
commit
9dea142c7a
|
|
@ -1,26 +1,18 @@
|
|||
import commands.patch_infoplist_command as plist
|
||||
import os
|
||||
import path_provider
|
||||
|
||||
config = {
|
||||
'version': '0.1.2',
|
||||
'app_name': 'TestAppName',
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
base_dir = '/Users/rzaitov/Documents/Apps/BuildScript',
|
||||
provider = path_provider.PathProvider(base_dir)
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ class BuildCommand:
|
|||
all_keys = []
|
||||
|
||||
for k in self._config:
|
||||
k.startswith(self._command_prefix)
|
||||
all_keys.append(k)
|
||||
if k.startswith(self._command_prefix):
|
||||
all_keys.append(k)
|
||||
|
||||
print all_keys
|
||||
return all_keys
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ class PatchCsproj(bcmd.BuildCommand):
|
|||
self._path_provider = path_provider
|
||||
self._parser = None
|
||||
|
||||
self.ParseConfig()
|
||||
|
||||
def ParseConfig(self):
|
||||
csproj_keys = self.FetchAllKeysFromConfig()
|
||||
self.FillPatchSettings(csproj_keys)
|
||||
|
|
@ -21,13 +23,13 @@ class PatchCsproj(bcmd.BuildCommand):
|
|||
|
||||
|
||||
def Execute(self):
|
||||
projects_list = self._parser.projects
|
||||
projects_list = self._parser.getProjects()
|
||||
|
||||
for project in projects_list:
|
||||
self.PatchProject(project)
|
||||
|
||||
def PatchProject(self, project):
|
||||
csproj_abs_path = self._path_provider.fetchAbsPath(project.rel_path)
|
||||
csproj_abs_path = self._path_provider.resolveAbsPath(project.rel_path)
|
||||
|
||||
patcher = csproj.Patcher(csproj_abs_path)
|
||||
patcher.AddOrReplace(project.settings, self._config['sln_config'])
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class PatchInfoPlist(bcmd.BuildCommand):
|
|||
return config_key[PatchInfoPlist._cmd_prefix_len:]
|
||||
|
||||
def Execute(self):
|
||||
info_plist_abs_path = self._path_provider.ResolveAbsPath(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)
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
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
|
||||
|
|
@ -0,0 +1 @@
|
|||
import ManualTests.csproj_test
|
||||
|
|
@ -8,17 +8,23 @@ class Patcher:
|
|||
def FetchPropertyGroup(self, sln_config_name):
|
||||
tree = eT.parse(self._csproj_abs_path)
|
||||
project_element = tree.getroot()
|
||||
property_group = self.GetPropertyGroupBy(project_element, sln_config_name)
|
||||
|
||||
property_group = self.GetPropertyGroupBy(project_element, sln_config_name)
|
||||
return property_group
|
||||
|
||||
|
||||
def GetPropertyGroupBy(self, project_element, config_name):
|
||||
property_groups = project_element.findall('PropertyGroup')
|
||||
namespaces = {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'}
|
||||
property_groups = project_element.findall('xmlns:PropertyGroup', namespaces)
|
||||
|
||||
prop_group = None
|
||||
|
||||
for pg_elem in property_groups:
|
||||
atr_value = pg_elem.get('Condition')
|
||||
|
||||
if atr_value is None:
|
||||
continue
|
||||
|
||||
is_fit = self.IsValueFitFor(config_name, atr_value)
|
||||
|
||||
if is_fit:
|
||||
|
|
|
|||
Loading…
Reference in New Issue