forked from edwardstock/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.py
184 lines (151 loc) · 4.9 KB
/
deploy.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
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
#!/usr/bin/env python3
import argparse
import os
import platform
import subprocess
###### DEFINE PROJECT CONFIG HERE ######
CONAN_PROJECT_NAME = "toolbox"
CONAN_REPO = "edwardstock"
CONAN_REPO_TAG = "latest"
# only boolean options supported
BUILD_OPTIONS = ["shared"]
###### END PROJECT CONFIG ##############
def get_version():
if os.path.isfile("version.info"):
version = open("version.info").read().strip()
elif os.path.isfile("../version.info"):
version = open("../version.info").read().strip()
else:
version = ""
return version
def combine_options(build_options, build_values):
build_options_tmp = []
result = []
opts_cnt = len(build_options)
values_cnt = len(build_values)
tmp_cnt = values_cnt * opts_cnt
# Populate build_options_tmp
for value_idx in range(values_cnt):
for opt_idx in range(opts_cnt):
option = f"{build_options[opt_idx]}={build_values[value_idx]}"
build_options_tmp.append(option)
# Combine options
for i in range(tmp_cnt):
option = ""
for n in range(opts_cnt):
next_index = (i + n) % tmp_cnt
option += " " + build_options_tmp[next_index]
result.append(option)
return result
def upload(version):
cmd_upload = [
"conan",
"upload",
"{}/{}@{}/{}".format(CONAN_PROJECT_NAME, version, CONAN_REPO, CONAN_REPO_TAG),
"-r={}".format(CONAN_REPO),
]
subprocess.run(cmd_upload, check=True)
def build():
sysname = os.name
std_lib_names = []
values = ["True", "False"]
if sysname == "posix":
if platform.system() == "Darwin":
std_lib_names = ["libc++"]
else:
std_lib_names = ["libstdc++", "libstdc++11"]
else:
std_lib_names = []
version = get_version()
target_options = combine_options(BUILD_OPTIONS, values)
if len(std_lib_names) == 0:
# iterate over available c++ stdlib
for option in target_options:
cmd_debug = [
"conan",
"create",
".", # current dir, call this script from project root
"-s",
"build_type=Debug",
"--build=missing",
"-o",
option,
"--user={}".format(CONAN_REPO),
"--channel={}".format(CONAN_REPO_TAG),
]
cmd_release = cmd_debug.copy()
cmd_release[4] = "build_type=Release"
subprocess.run(cmd_debug, check=True)
subprocess.run(cmd_release, check=True)
else:
for std_lib in std_lib_names:
for option in target_options:
cmd_debug = [
"conan",
"create",
".", # current dir, call this script from project root
"-s",
"build_type=Debug",
"-s",
"compiler.libcxx={}".format(std_lib),
"--build=missing",
"-o",
option,
"--user={}".format(CONAN_REPO),
"--channel={}".format(CONAN_REPO_TAG),
]
cmd_release = cmd_debug.copy()
cmd_release[4] = "build_type=Release"
subprocess.run(cmd_debug, check=True)
subprocess.run(cmd_release, check=True)
def clear_cache():
cmd_remove_all = [
"conan",
"remove",
"{}/*".format(CONAN_PROJECT_NAME),
"-c"
]
cmd_remove_specific = [
"conan",
"remove",
"{}/*@{}/{}".format(CONAN_PROJECT_NAME, CONAN_REPO, CONAN_REPO_TAG),
"-c"
]
cmd_cache_clean_all = [
"conan",
"cache",
"clean",
"{}/*".format(CONAN_PROJECT_NAME),
"--source",
"--build",
"--download"
]
cmd_cache_clean_specific = [
"conan",
"cache",
"clean",
"{}/*@{}/{}".format(CONAN_PROJECT_NAME, CONAN_REPO, CONAN_REPO_TAG),
"--source",
"--build",
"--download"
]
subprocess.run(cmd_remove_all, check=True)
subprocess.run(cmd_remove_specific, check=True)
subprocess.run(cmd_cache_clean_all, check=True)
subprocess.run(cmd_cache_clean_specific, check=True)
def main():
parser = argparse.ArgumentParser(description='Conan Build and Upload script.')
parser.add_argument('command', choices=['build', 'upload', 'clear-cache'], help='The command to execute.')
parser.add_argument('--force', action='store_true', help='If set, clear cache before build.')
args = parser.parse_args()
version = get_version()
if args.command == 'build':
if args.force:
clear_cache()
build()
elif args.command == 'upload':
upload(version)
elif args.command == 'clear-cache':
clear_cache()
if __name__ == "__main__":
main()