-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUBS.py
More file actions
356 lines (267 loc) · 14.4 KB
/
UBS.py
File metadata and controls
356 lines (267 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
from Utility.HeaderBase import *
from ConfigParser import *
from Utility.UnrealProjectManager import *
from Utility.UnrealConfigIniManager import *
from Command.GitCommand import *
from Command.MacRATrustCommand import *
from Command.ZipCommand import *
from Command.FastLaneCommand import *
from Utility.Downloader import *
from Command.AndroidCommand import *
from Command.UEEditorCMDCommand import *
from APM import *
from SystemBase import *
import argparse
import platform
from UBSHelper import *
from SystemHelper import *
from Utility.ArchiveManager import *
version_info = {}
class PyUnrealBuildSystem(BaseSystem):
__instance = None
__initialized = False
def __new__(cls, *args, **kwargs):
if not cls.__instance:
cls.__instance = super().__new__(cls, *args, **kwargs)
cls.__instance.__initialized = False
return cls.__instance
def __init__(self) -> None:
if not self.__initialized:
super().__init__()
self.__initialized = True
def Get():
return PyUnrealBuildSystem()
def Start(self):
PrintStageLog("Start Build System")
PyUnrealBuildSystem.Get().Init()
args = PyUnrealBuildSystem.Get().ParseCMDArgs()
PyUnrealBuildSystem.Get().CreateTask(args)
def Init(self):
## Init System Info
PrintStageLog("PyUnrealBuildSystem Init")
PyUnrealBuildSystem.Get().InitBuildSystemInfo()
ConfigParser.Get().Init()
def InitBuildSystemInfo(self):
val_version = "1.""0.""0"
version_info['SystemVersion'] = val_version
PrintLog(version_info)
def ParseCMDArgs(self):
ArgParser = argparse.ArgumentParser(description="Parse Package Args")
self.AddArgsToParser(ArgParser)
Args = ArgParser.parse_args()
PrintLog(Args)
return Args
def AddArgsToParser(self,ArgParser, bIncludeConflictArgs = True):
#bIncludeConflictArgs: Some Args used in this file would have conflicts with args which have the same name in the other files
## because [add_argument] cannot add the same arguments twice
default_targetsystem = self.GetHostPlatform()
if default_targetsystem == SystemHelper.Win_HostName():
default_targetsystem = SystemHelper.Win64_TargetName()
ArgParser.add_argument("-enginepath", default="")
ArgParser.add_argument("-enginever", default="4.27")
ArgParser.add_argument("-uprojectpath", default=Path("Users/admin/Documents/AgoraBPExample/AgoraBPExample.uproject"))
ArgParser.add_argument("-upluginpath", default="") ## if "": use the plugin under the plugins file
ArgParser.add_argument("-targetplatform", default=default_targetsystem)
ArgParser.add_argument("-androidpackagename", default="com.YourCompany.[PROJECT]")
#ArgParser.add_argument("-iosbundlename", default="com.YourCompany.AgoraExample")
# ## For Modern Xcode Project
# ArgParser.add_argument("-moderniosbundleidprefix", default="io.agora")
## For now, use [iosbundlename].rsplit('.',1)[0]
## For Legency Xcode Project
ArgParser.add_argument("-iosbundlename", default="io.agora.AgoraExample")
ArgParser.add_argument("-ioscert",default = "C")
## CreateTask handles it to be the base dir under the project dir
## otherwise it would be under the engine dir
ArgParser.add_argument("-archive_dir",default = "")
ArgParser.add_argument("-WithAllIOSCerts", action='store_true')
## Setup Machine For Packaging
ArgParser.add_argument("-SetupHostMachine", action='store_true')
## Config Set
ArgParser.add_argument("-SetUEConfigIni", action='store_true')
ArgParser.add_argument("-IniFile", default="")
ArgParser.add_argument("-IniSection", default="")
ArgParser.add_argument("-IniKey", default="")
ArgParser.add_argument("-IniVal", default="")
## Build Command
ArgParser.add_argument("-BuildCookRun", action='store_true')
ArgParser.add_argument("-BuildPlugin", action='store_true')
ArgParser.add_argument("-BuildPluginEngineList", default="all")
ArgParser.add_argument("-SkipBuildEditor", action='store_true')
ArgParser.add_argument("-BuildGraph", action='store_true')
## IOS Resign
## Use -ioscert specify the certificate
ArgParser.add_argument("-IPAResign", action='store_true')
ArgParser.add_argument("-IPAPath", default="")
## Utility Command
ArgParser.add_argument("-Clean", action='store_true')
ArgParser.add_argument("-GenProject", action='store_true')
ArgParser.add_argument("-GenIOSProject", action='store_true')
ArgParser.add_argument("-InstallAndroidAPI", action='store_true')
ArgParser.add_argument("-UnInstallAndroidAPI", action='store_true')
ArgParser.add_argument("-AndroidSDKManagerList", action='store_true')
ArgParser.add_argument("-AndroidSDKManagerSubCommand",default="")
ArgParser.add_argument("-ValidatePlatforms", action='store_true')
## achive the final product to the target dir
ArgParser.add_argument("-ArchiveProduct", action='store_true')
ArgParser.add_argument("-CleanOldArchives", action='store_true')
ArgParser.add_argument("-ArchiveRootPath", default="")
ArgParser.add_argument("-RUNCMD", action="store_true")
## BuildGraph
ArgParser.add_argument("-buildgraphpath", default="D:\Github\PyUnrealBuildSystem\Config\BuildGraph\PackageAgoraExample.xml")
ArgParser.add_argument("-args", default="")
if bIncludeConflictArgs:
ArgParser.add_argument("-TestPlugin", action='store_true')
ArgParser.add_argument("-agorasdktype", default="RTC")
ArgParser.add_argument("-agorasdk", default="4.2.1")
ArgParser.add_argument("-CopySDKType",default="None")
ArgParser.add_argument("-RedownloadSDK",action='store_true')
def GetName_TestPluginOutputDir(self):
return "TestPluginOutput"
def GetName_TestPluginUnzipDir(self):
return "TestPluginUnzip"
def InitConfig(self):
PrintLog("Init Log")
## Host Machine
def CreateTask(self,Args):
## Init Host Platform
type_hostplatform = SystemHelper.Get().GetHostPlatform()
UBSHelper.Get().Init(Args)
ret_host,host_platform = CreateHostPlatform(type_hostplatform,Args)
if ret_host == False:
PrintErrWithFrame(sys._getframe())
return
if Args.SetupHostMachine:
host_platform.SetupEnvironment()
if Args.RUNCMD == True:
OneUECommand = UEEditorCMDCommand()
OneUECommand.RUNUECMD_Cook()
if Args.Clean == True:
path_project = Path(Args.uprojectpath).parent
## Path \ or not
## [TBD] clean xcproject
UnrealProjectManager.CleanProject(path_project)
if Args.GenProject == True:
path_uproject_file = Path(Args.uprojectpath)
## [TBD] some needs \ and some doesn't need \
UnrealProjectManager.GenerateProject(host_platform,path_uproject_file)
if Args.GenIOSProject == True:
path_uproject_file = Path(Args.uprojectpath)
## [TBD] some needs \ and some doesn't need \
UnrealProjectManager.GenerateIOSProject(host_platform,path_uproject_file)
if Args.BuildPlugin == True:
# [TBD] Modify
arg_targetplatform = Args.targetplatform
# arg_path_uproject_file = Args.uprojectpath
# arg_path_project = arg_path_uproject_file.parent
# plugin_path = arg_path_project / Path("Plugins/AgoraVoicePlugin/AgoraVoicePlugin.uplugin")
# output_path = arg_path_project / Path("Saved/PluginOutput/")
if Args.upluginpath != "":
plugin_path = Path(Args.upluginpath)
output_path = plugin_path.parent.parent / Path("output/")
host_platform.BuildPlugin(plugin_path,arg_targetplatform,output_path)
if Args.BuildCookRun == True:
target_platform_type_list = ParsePlatformArg(Args.targetplatform)
for target_platform_type in target_platform_type_list:
ret_target,target_platform = CreateTargetPlatform(host_platform,target_platform_type,Args)
if ret_target == True:
## target_platform.SetupEnvironment() did it in [Package]
target_platform.Package()
else:
PrintErr("Invalid TargetPlatform Creation")
if Args.BuildGraph == True:
target_platform_type_list = ParsePlatformArg(Args.targetplatform)
for target_platform_type in target_platform_type_list:
ret_target,target_platform = CreateTargetPlatform(host_platform,target_platform_type,Args)
if ret_target == True:
## target_platform.SetupEnvironment() did it in [Package]
target_platform.BuildGraph()
else:
PrintErr("Invalid TargetPlatform Creation")
bTestCommand = False
if bTestCommand:
if self.GetHostPlatform() == SystemHelper.Mac_HostName():
path_uproject_file = Args.uprojectpath
bundlename = Args.iosbundlename
host_platform.IOSSign(path_uproject_file,bundlename)
if Args.IPAResign == True:
OneFastLaneCommand = FastLaneCommand()
path_uproject = Path(Args.uprojectpath)
name_app = path_uproject.stem + ".ipa"
path_ipa = Path(Args.uprojectpath).parent / "ArchivedBuilds"/ "IOS" / name_app
if Args.IPAPath != "":
path_ipa = Path(Args.IPAPath)
tag_name_ios_cert = Args.ioscert
if ConfigParser.Get().IsIOSCertValid(tag_name_ios_cert) :
PrintLog("[IPAResign] Use IOS Certificate %s " %tag_name_ios_cert)
OneIOSCert = ConfigParser.Get().GetOneIOSCertificate(tag_name_ios_cert)
OneFastLaneCommand.IPAResign(
path_ipa,
OneIOSCert.get_signing_identity,
OneIOSCert.get_filepath_mobileprovision
)
if Args.SetUEConfigIni == True:
UnrealConfigIniManager.SetConfig(Args.IniFile,Args.IniSection,Args.IniKey,Args.IniVal,True)
#OneIOSCert = ConfigParser.Get().GetOneIOSCertificate("D")
#UnrealConfigIniManager.SetConfig_IOSCert(Args.uprojectpath,OneIOSCert["signing_identity"],OneIOSCert["provisioning_profile"])
if Args.InstallAndroidAPI or Args.UnInstallAndroidAPI or Args.AndroidSDKManagerList:
OneAndroidCommand = AndroidCommand()
if Args.UnInstallAndroidAPI:
OneAndroidCommand.SDKManager_UnInstall(Args.AndroidSDKManagerSubCommand,False)
elif Args.InstallAndroidAPI:
OneAndroidCommand.SDKManager_Install(Args.AndroidSDKManagerSubCommand,False)
elif Args.AndroidSDKManagerList:
OneAndroidCommand.SDKManager_List()
if Args.ValidatePlatforms:
ubt_path = Path(UBSHelper.Get().GetPath_UEEngine()) / Path(WinPlatformPathUtility.GetUBTPath())
OneUBTCommand = UBTCommand(ubt_path)
OneUBTCommand.ValidPlatforms()
if Args.ArchiveRootPath != "":
ArchiveManager.Get().SetPath_ArchiveRootDir(Args.ArchiveRootPath)
def BuildPlugin(self,Args,path_plugin_zipfile):
path_working_dir = Path(path_plugin_zipfile).parent
path_unzip = path_working_dir / Path(self.GetName_TestPluginUnzipDir())
## Clean First
if path_unzip.exists():
FileUtility.DeleteDir(path_unzip)
## Prepare :
## Unzip the plugin to get uplugin file path
OneZipCommand =ZipCommand()
OneZipCommand.UnZipFile(path_plugin_zipfile,path_unzip)
name_plugin,path_uplugin_file = UBSHelper.Get().GetInfo_PluginNameAndUPluginFilePath(path_unzip)
## Start Testing
self.BuildPluginInner(Args,path_uplugin_file)
### [After Build] Clean Environment
if path_unzip.exists():
FileUtility.DeleteDir(path_unzip)
def BuildPluginInner(self,Args,path_uplugin_file):
## Ex. /Users/admin/Documents/PluginWorkDir/PluginArchive/4.3.1/AgoraPlugin/AgoraPlugin.uplugin
## -> /Users/admin/Documents/PluginWorkDir/PluginArchive/4.3.1/TestPluginOutput
path_output_dir = Path(path_uplugin_file).parent.parent / Path(self.GetName_TestPluginOutputDir())
if path_output_dir.exists():
FileUtility.DeleteDir(path_output_dir)
path_output_dir.mkdir(parents=True,exist_ok=True)
cur_enginever = Args.enginever
arg_targetplatform = Args.targetplatform
all_engine_list = ConfigParser.Get().GetAllAvailableEngineList()
if Args.BuildPluginEngineList == "all" or Args.BuildPluginEngineList == "" :
pass
elif Args.BuildPluginEngineList == "Top3":
sorted_versions = sorted(all_engine_list, key=float, reverse=True)
all_engine_list = sorted_versions[:3]
elif Args.BuildPluginEngineList != "":
param_enginelist = str(Args.BuildPluginEngineList)
all_engine_list = param_enginelist.split("+")
test_complete_log_keyword = "Test Plugin Complete"
for engine_ver in all_engine_list:
PrintStageLog("Test Use Engine Ver [%s]" % engine_ver)
UBSHelper.Get().SetUEEngineWithVer(engine_ver)
ret_host,tmp_host_platform = CreateHostPlatform(self.GetHostPlatform(),Args)
tmp_host_platform.BuildPlugin(path_uplugin_file,arg_targetplatform,path_output_dir)
PrintStageLog(test_complete_log_keyword + " Engine Ver[%s]" %engine_ver)
PrintStageLog("Test Plugin Complete --- Use keyword [%s] to search in your log" %test_complete_log_keyword )
## [After Test] Recover UE Engine
UBSHelper.Get().SetUEEngineWithVer(cur_enginever)
if path_output_dir.exists():
FileUtility.DeleteDir(path_output_dir)
if __name__ == '__main__':
PyUnrealBuildSystem.Get().Start()