delphimvcframework/dodo.py

280 lines
8.8 KiB
Python
Raw Normal View History

import glob
import os
import subprocess
from shutil import copy2, rmtree
from datetime import datetime
from colorama import *
init() # colorama initialization
# task setup env
DOIT_CONFIG = {'verbosity': 2, 'default_tasks': ['build']}
##########################################################################
############## CONFIGURATION #############################################
##########################################################################
projects = glob.glob("ideexpert\*.dproj")
projects += glob.glob("unittests\**\*.dproj")
2017-05-09 23:13:51 +02:00
projects += glob.glob("samples\**\*.dproj")
failed = []
2017-05-09 23:13:51 +02:00
#projects += glob.glob("*\**\**\*.dproj")
releases_path = "releases"
output = "bin"
2017-05-09 10:49:28 +02:00
output_folder = "" # defined at runtime
##########################################################################
############## END CONFIGURATION #########################################
##########################################################################
# if we are building an actual release, this will be replaced
GlobalBuildVersion = 'DEV'
def header(headers):
elements = None
if type(headers).__name__ == 'str':
elements = [headers]
else:
elements = headers
2017-05-09 23:13:51 +02:00
print(Style.BRIGHT + Back.WHITE + Fore.RED + "*" * 78 + Style.RESET_ALL)
for txt in elements:
2017-05-09 23:13:51 +02:00
s = '{:^78}'.format(txt)
print(Style.BRIGHT + Back.WHITE + Fore.RED + s + Style.RESET_ALL)
2017-05-09 23:13:51 +02:00
print(Style.BRIGHT + Back.WHITE + Fore.RED + "*" * 78 + Style.RESET_ALL)
def buildProject(project, config='DEBUG'):
header(["Building", project, "(config " + config + ")"])
p = project.replace('.dproj', '.cfg')
if os.path.isfile(p):
if os.path.isfile(p + '.unused'):
os.remove(p + '.unused')
os.rename(p, p + '.unused')
rsvars_path = 'C:\\Program Files (x86)\\Embarcadero\\Studio\\19.0\\bin\\rsvars.bat'
if not os.path.isfile(rsvars_path):
rsvars_path = 'D:\\Program Files (x86)\\Embarcadero\\Studio\\19.0\\bin\\rsvars.bat'
if not os.path.isfile(rsvars_path):
return False
cmdline = '"' + rsvars_path + '"' + " & msbuild /t:Build /p:Config=" + config + " /p:Platform=Win32 \"" + project + "\""
print("Running: " + cmdline)
return subprocess.call(cmdline, shell=True) == 0
def buildProjects(config='RELEASE'):
global failed
failed = list()
allres = True
for project in projects:
res = buildProject(project, config)
allres &= res
if not res:
failed.append(project)
if not allres:
print(failed)
return allres
def run_unit_tests():
import os
apppath = os.path.dirname(os.path.realpath(__file__))
res = True
tests = [
"unittests\serializer\jsondataobjects\TestSerializerJsonDataObjects.dproj"
]
testsexe = [
"unittests\serializer\jsondataobjects\Win32\CI\TestSerializerJsonDataObjects.exe"
]
i = 0
for test_project in tests:
res = buildProject(test_project, 'CI') and res
if res:
exename = apppath + "\\" + testsexe[i]
print("Running: " + exename)
retcode = subprocess.call(exename)
print("ExitCode = " + str(retcode))
res = retcode == 0
if not res:
print("UnitTest execution failed!")
return False
i = i + 1
return res
def copy_sources():
2017-05-09 10:49:28 +02:00
global output_folder
os.makedirs(output_folder + "\\sources", exist_ok=True)
os.makedirs(output_folder + "\\ideexpert", exist_ok=True)
# copying main sources
header("Copying DMVCFramework Sources...")
src = glob.glob("sources\\*.pas") + glob.glob("sources\\*.inc")
for file in src:
2017-05-09 10:49:28 +02:00
print("Copying " + file + " to " + output_folder + "\\sources")
copy2(file, output_folder + "\\sources\\")
2017-05-09 23:13:51 +02:00
# copy2("lib\\jsondataobjects\\Source\\JsonDataObjects.pas",
# output_folder + "\\sources\\")
# copying ideexperts
header("Copying DMVCFramework IDEExpert...")
print("Copying ideexpert")
src = glob.glob("ideexpert\\*.pas") + \
2017-05-19 00:47:03 +02:00
glob.glob("ideexpert\\*.dfm") + \
glob.glob("ideexpert\\*.ico") + \
glob.glob("ideexpert\\*.bmp") + \
glob.glob("ideexpert\\*.dpk") + \
glob.glob("ideexpert\\*.dproj")
for file in src:
2017-05-09 10:49:28 +02:00
print("Copying " + file + " to " + output_folder + "\\ideexpert")
copy2(file, output_folder + "\\ideexpert\\")
def copy_libs():
2017-05-09 10:49:28 +02:00
global output_folder
# loggerpro
header("Copying libraries: LoggerPro...")
2017-05-09 10:49:28 +02:00
curr_folder = output_folder + "\\lib\\loggerpro"
os.makedirs(curr_folder, exist_ok=True)
src = glob.glob("lib\\loggerpro\\*.pas")
for file in src:
print("Copying " + file + " to " + curr_folder)
copy2(file, curr_folder)
copy2("lib\\loggerpro\\LICENSE", curr_folder)
copy2("lib\\loggerpro\\VERSION.TXT", curr_folder)
# dmustache
header("Copying libraries: dmustache...")
2017-05-09 10:49:28 +02:00
curr_folder = output_folder + "\\lib\\dmustache"
os.makedirs(curr_folder, exist_ok=True)
src = glob.glob("lib\\dmustache\\*.pas") + \
glob.glob("lib\\dmustache\\*.inc")
for file in src:
print("Copying " + file + " to " + curr_folder)
copy2(file, curr_folder)
copy2("lib\\dmustache\\README.md", curr_folder)
2017-05-09 19:28:06 +02:00
def init_build(version):
2017-05-09 23:13:51 +02:00
'''Required by all tasks'''
global GlobalBuildVersion
2017-05-09 10:49:28 +02:00
global output_folder
global releases_path
GlobalBuildVersion = version
2017-05-09 10:49:28 +02:00
output_folder = releases_path + "\\" + version
print('Output path: ' + output_folder)
header("BUILD VERSION: " + GlobalBuildVersion)
2017-05-09 10:49:28 +02:00
rmtree(output_folder, True)
os.makedirs(output_folder, exist_ok=True)
f = open(output_folder + "\\version.txt", "w")
f.write("VERSION " + GlobalBuildVersion + "\n")
f.write("BUILD DATETIME " + datetime.now().isoformat() + "\n")
f.close()
2017-05-09 10:49:28 +02:00
copy2("README.md", output_folder)
copy2("3_0_0_breaking_changes.md", output_folder)
copy2("roadmap.md", output_folder)
copy2("LICENSE", output_folder)
2017-05-09 19:28:06 +02:00
def zip_samples(version):
2017-05-09 23:13:51 +02:00
global output_folder
2017-05-09 19:28:06 +02:00
cmdline = "7z a " + output_folder + "\\dmvcframeworksamples.zip -r -i@7ziplistfile.txt"
return subprocess.call(cmdline, shell=True) == 0
2017-05-09 10:49:28 +02:00
def create_zip(version):
2017-05-09 23:13:51 +02:00
global output_folder
2017-05-09 10:49:28 +02:00
header("CREATING ZIP")
archivename = "..\\dmvcframework_" + version + ".zip"
#switches = " -o.\\" + releases_path + " -w.\\" + output_folder
switches = ""
#switches = " -oD:\\DEV\\dmvcframework\\releases\\" + " -w " + output_folder
#filenames = output_folder + "\\*"
filenames = "*"
cmdline = "cd " + output_folder + " & 7z.exe a " + \
switches + " " + archivename + " " + filenames
print(cmdline)
return subprocess.call(cmdline, shell=True) == 0
##########################################################################
def task_build():
2017-05-09 19:28:06 +02:00
'''Use: doit build -v <VERSION>.'''
return {
'actions': [
run_unit_tests,
2017-05-09 23:13:51 +02:00
buildProjects,
2017-05-09 19:28:06 +02:00
init_build,
copy_sources,
copy_libs,
2017-05-09 19:28:06 +02:00
zip_samples,
2017-05-09 10:49:28 +02:00
create_zip],
'params': [{'name': 'version',
'short': 'v',
'long': 'version',
'type': str,
'default': 'DEVELOPMENT'},
{'name': 'config',
'short': 'c',
'long': 'config',
'type': str,
'default': 'DEBUG'}
],
'verbosity': 2
}
def task_tests():
'''Use: doit tests'''
return {
'actions': [
run_unit_tests
],
'verbosity': 2
}
2017-05-09 10:49:28 +02:00
def task_zip():
2017-05-09 19:28:06 +02:00
'''Use: doit zip -v <VERSION>.'''
return {
'actions': [
2017-05-09 10:49:28 +02:00
create_zip],
'params': [{'name': 'version',
'short': 'v',
'long': 'version',
'type': str,
'default': 'DEVELOPMENT'},
{'name': 'config',
'short': 'c',
'long': 'config',
'type': str,
'default': 'DEBUG'}
],
'verbosity': 2
}
2017-05-09 10:49:28 +02:00
def task_buildlight():
'''Use: doit buildlight -> Builds all the projects.'''
return {
2017-05-09 10:49:28 +02:00
'actions': [
#'echo off && touch bin\\x.exe && del bin\\*.exe',
2017-05-09 10:49:28 +02:00
buildProjects],
'verbosity': 2
}
2017-05-09 19:28:06 +02:00
def task_samples():
'''creates the samples zip file'''
return {
'actions': [init_build, zip_samples],
'params': [
{
'name': 'version',
'short': 'v',
'long': 'version',
'type': str,
'default': 'DEVELOPMENT'
}
]
}