-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.py
96 lines (75 loc) · 3.14 KB
/
build.py
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
import os
import datetime
import subprocess
import sys
build_list = [
{
"qmake": r"/Users/runner/Qt/6.7.2/clang_64/bin/qmake",
"qmake_params": r'"CONFIG+=qtquickcompiler"',
"make": r"make",
"project": r"/Users/runner/code/Qt-App/Qt-App.pro",
"build_directory": r"/Users/runner/code/Qt-App/build/Desktop_Qt_6_7_0_clang_64bit-Release",
}
]
class Builder:
def __init__(self, project, qmake, qmake_params, make, build_directory):
self.project = project
self.qmake = qmake
self.qmake_params = qmake_params
self.make = make
self.build_directory = build_directory
(self.qmake_path, self.qmake_name) = os.path.split(qmake)
(self.jom_path, self.jom_name) = os.path.split(make)
(self.project_path, self.project_name) = os.path.split(project)
self.qt_version = self.qmake_path.split("/")[-3]
self.compiler_version = self.qmake_path.split("/")[-2]
def execute_qmake_cmd_line(self):
create_qmake_cmd_line = (
self.qmake + " " + self.project + " -spec macx-clang " + self.qmake_params
)
return True if execute(create_qmake_cmd_line) else False
def execute_make_cmd_line(self):
cmd_line = "{0} -j $(sysctl -n hw.ncpu)".format(self.make)
return True if execute(cmd_line) else False
def execute_make_clean_cmd_line(self):
if os.path.exists("Makefile") | os.path.exists("makefile"):
return True if execute("{0} clean".format(self.make)) else False
return True
def build(self):
os.chdir(self.build_directory)
print("Starting build [{0}]".format(os.path.splitext(self.project_name)[0]))
isOk = True
status = self.execute_make_clean_cmd_line()
isOk = isOk and status
print("Make clean: ", "Success" if status else "Failed")
status = self.execute_qmake_cmd_line()
isOk = isOk and status
print("QMake: ", "Success" if status else "Failed")
status = self.execute_make_cmd_line()
isOk = isOk and status
print("Make: ", "Success" if status else "Failed")
print("End build ", "Success" if isOk else "Failed")
return isOk
def execute(cmd):
print(cmd)
result = subprocess.run(cmd, stdout=sys.stdout, stderr=sys.stderr, shell=True)
if result.returncode != 0:
print(result.stderr)
return True if result.returncode == 0 else False
def build(build_list):
for each in build_list:
qmake = each.get("qmake")
qmake_params = (
"" if each.get("qmake_params") == None else each.get("qmake_params")
)
make = each.get("make")
project = each.get("project")
build_directory = each.get("build_directory")
builder = Builder(project, qmake, qmake_params, make, build_directory)
if builder.build() == False:
print("[{0}] Deploy failed!!!".format(datetime.datetime.now()))
exit(-1)
if __name__ == "__main__":
print("[{0}] Start deploy...".format(datetime.datetime.now()))
build(build_list)
print("[{0}] Deploy success!!!".format(datetime.datetime.now()))