2019-12-13 17:46:43 +03:00
|
|
|
import os
|
2019-07-22 10:20:59 +03:00
|
|
|
from buildbot.plugins import util
|
|
|
|
import multiprocessing
|
|
|
|
import glob
|
|
|
|
import shutil
|
2019-12-26 16:18:17 +03:00
|
|
|
from pathlib import Path
|
2021-04-15 21:10:14 +03:00
|
|
|
from BuildBotLib.stepfactory import StepFactory
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-12-26 11:29:22 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
class BaseModule:
|
2019-12-25 19:35:31 +03:00
|
|
|
|
2020-01-31 14:55:49 +03:00
|
|
|
P_Windows = 'Windows'
|
|
|
|
P_Linux = 'Linux'
|
|
|
|
P_Android = 'Android'
|
2020-10-08 15:35:25 +03:00
|
|
|
P_Wasm = 'Wasm'
|
2020-01-31 14:55:49 +03:00
|
|
|
|
|
|
|
def __init__(self, platform):
|
2019-12-30 16:34:10 +03:00
|
|
|
self.home = str(Path.home())
|
2020-01-31 14:55:49 +03:00
|
|
|
self.platform = platform
|
2021-04-15 21:10:14 +03:00
|
|
|
self.pwd = "."
|
|
|
|
|
2021-03-31 20:59:00 +03:00
|
|
|
if self.platform == self.P_Windows:
|
|
|
|
self.MULTIPLE_SH_COMMAND = ["cmd", "/c"]
|
|
|
|
else:
|
|
|
|
self.MULTIPLE_SH_COMMAND = ["/bin/bash", "-c"]
|
2020-06-19 17:37:37 +03:00
|
|
|
|
2019-12-26 16:18:17 +03:00
|
|
|
def isWin(self, step):
|
2020-01-31 14:55:49 +03:00
|
|
|
return self.platform == BaseModule.P_Windows
|
2019-12-26 16:18:17 +03:00
|
|
|
|
|
|
|
def isLinux(self, step):
|
2020-01-31 14:55:49 +03:00
|
|
|
return self.platform == BaseModule.P_Linux
|
2019-12-26 16:18:17 +03:00
|
|
|
|
|
|
|
def isAndroid(self, step):
|
2020-01-31 14:55:49 +03:00
|
|
|
return self.platform == BaseModule.P_Android
|
2019-12-26 16:18:17 +03:00
|
|
|
|
2020-10-08 15:35:25 +03:00
|
|
|
def isWasm(self, step):
|
|
|
|
return self.platform == BaseModule.P_Wasm
|
|
|
|
|
2019-12-26 11:29:22 +03:00
|
|
|
def generateCmd(self, bashString):
|
2019-12-27 15:13:59 +03:00
|
|
|
|
|
|
|
if isinstance(bashString, list):
|
|
|
|
return bashString
|
|
|
|
|
2019-12-26 11:29:22 +03:00
|
|
|
return self.MULTIPLE_SH_COMMAND + [bashString]
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
def getFactory(self):
|
2021-04-15 21:10:14 +03:00
|
|
|
return StepFactory(self.pwd)
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
def getRepo(self):
|
2019-12-26 11:29:22 +03:00
|
|
|
return ""
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-12-27 15:13:59 +03:00
|
|
|
def getWraper(self, object):
|
2019-12-27 13:50:38 +03:00
|
|
|
|
|
|
|
@util.renderer
|
|
|
|
def cmdWraper(step):
|
2019-12-27 15:13:59 +03:00
|
|
|
if not callable(object):
|
|
|
|
return self.generateCmd(object)
|
|
|
|
|
|
|
|
return object(step)
|
2019-12-27 13:50:38 +03:00
|
|
|
|
|
|
|
return cmdWraper
|
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
def getPropertyes(self):
|
2019-12-26 16:18:17 +03:00
|
|
|
return [
|
|
|
|
]
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
def copyRegExp(self, source, dist):
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
res = []
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
for file in glob.glob(source):
|
|
|
|
res.append(file)
|
|
|
|
shutil.copy(file, dist)
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-12-26 11:29:22 +03:00
|
|
|
return res
|
2019-07-22 10:20:59 +03:00
|
|
|
|
2019-12-26 17:08:56 +03:00
|
|
|
def allSubdirsOf(self, b='.'):
|
|
|
|
result = []
|
|
|
|
for d in os.listdir(b):
|
|
|
|
bd = os.path.join(b, d)
|
|
|
|
if os.path.isdir(bd):
|
|
|
|
result.append(bd)
|
|
|
|
|
|
|
|
return result
|
2019-12-26 16:55:32 +03:00
|
|
|
|
2020-02-04 16:40:15 +03:00
|
|
|
def make(self):
|
2020-02-04 16:34:32 +03:00
|
|
|
if self.platform == BaseModule.P_Windows:
|
2020-02-04 16:40:15 +03:00
|
|
|
return 'mingw32-make'
|
|
|
|
|
|
|
|
return 'make'
|
|
|
|
|
|
|
|
def makeTarget(self, target):
|
|
|
|
command = [self.make()]
|
|
|
|
return command + [target]
|
|
|
|
|
|
|
|
def makeCommand(self, props):
|
|
|
|
command = [self.make()]
|
2020-02-04 16:34:32 +03:00
|
|
|
|
2019-10-06 19:15:02 +03:00
|
|
|
cpus = multiprocessing.cpu_count()
|
|
|
|
|
|
|
|
if cpus:
|
|
|
|
command.extend(['-j', str(cpus)])
|
|
|
|
else:
|
|
|
|
command.extend(['-j', '1'])
|
|
|
|
return command
|
2021-01-10 12:12:26 +03:00
|
|
|
|
|
|
|
def defaultLocationOfQIFRepository(self):
|
|
|
|
return "/var/www/repo/"
|