forked from daos-stack/daos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
434 lines (368 loc) · 16.1 KB
/
SConstruct
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
"""Build DAOS"""
import os
import sys
import platform
import subprocess
import time
import errno
import SCons.Warnings
from SCons.Script import BUILD_TARGETS
if sys.version_info.major < 3:
print(""""Python 2.7 is no longer supported in the DAOS build.
Install python3 version of SCons. On some platforms this package does not
install the scons binary so your command may need to use scons-3 instead of
scons or you will need to create an alias or script by the same name to
wrap scons-3.""")
Exit(1)
SCons.Warnings.warningAsException()
try:
input = raw_input # pylint: disable=redefined-builtin
except NameError:
pass
import daos_build
import compiler_setup
from prereq_tools import PreReqComponent
import stack_analyzer
def get_version(env):
""" Read version from VERSION file """
with open("VERSION", "r") as version_file:
version = version_file.read().rstrip()
(major, minor, fix) = version.split('.')
env.Append(DAOS_VERSION_MAJOR=major)
env.Append(DAOS_VERSION_MINOR=minor)
env.Append(DAOS_VERSION_FIX=fix)
return version
API_VERSION_MAJOR = "2"
API_VERSION_MINOR = "1"
API_VERSION_FIX = "0"
API_VERSION = "{}.{}.{}".format(API_VERSION_MAJOR, API_VERSION_MINOR,
API_VERSION_FIX)
def update_rpm_version(version, tag):
""" Update the version (and release) in the RPM specfile """
spec = open("utils/rpms/daos.spec", "r").readlines()
current_version = 0
release = 0
for line_num, line in enumerate(spec):
if line.startswith("Version:"):
current_version = line[line.rfind(' ')+1:].rstrip()
if version < current_version:
print("You cannot create a new version ({}) lower than the RPM "
"spec file has currently ({})".format(version,
current_version))
return False
if version > current_version:
spec[line_num] = "Version: {}\n".format(version)
if line.startswith("Release:"):
if version == current_version:
current_release = int(line[line.rfind(' ')+1:line.find('%')])
release = current_release + 1
else:
release = 1
spec[line_num] = "Release: {}%{{?relval}}%{{?dist}}\n".\
format(release)
if line == "%changelog\n":
cmd = 'rpmdev-packager'
try:
pkg_st = subprocess.Popen(cmd, stdout=subprocess.PIPE) # nosec
packager = pkg_st.communicate()[0].strip().decode('UTF-8')
except OSError:
print("You need to have the rpmdev-packager tool (from the "
"rpmdevtools RPM on EL7) in order to make releases.\n\n"
"Additionally, you should define %packager in "
"~/.rpmmacros as such:\n"
"%packager John A. Doe <[email protected]>"
"so that package changelog entries are well defined")
return False
date_str = time.strftime('%a %b %d %Y', time.gmtime())
spec.insert(line_num + 1, "\n")
spec.insert(line_num + 1,
"- Version bump up to {}\n".format(tag))
spec.insert(line_num + 1,
u'* {} {} - {}-{}\n'.format(date_str,
packager,
version,
release))
break
open("utils/rpms/daos.spec", "w").writelines(spec)
return True
def is_platform_arm():
"""Detect if platform is ARM"""
processor = platform.machine()
arm_list = ["arm", "aarch64", "arm64"]
if processor.lower() in arm_list:
return True
return False
def set_defaults(env, daos_version):
"""set compiler defaults"""
AddOption('--preprocess',
dest='preprocess',
action='store_true',
default=False,
help='Preprocess selected files for profiling')
AddOption('--no-rpath',
dest='no_rpath',
action='store_true',
default=False,
help='Disable rpath')
AddOption('--analyze-stack',
dest='analyze_stack',
metavar='ARGSTRING',
default=None,
help='Gather stack usage statistics after build')
env.Append(API_VERSION_MAJOR=API_VERSION_MAJOR)
env.Append(API_VERSION_MINOR=API_VERSION_MINOR)
env.Append(API_VERSION_FIX=API_VERSION_FIX)
env.Append(CCFLAGS=['-DDAOS_VERSION=\\"' + daos_version + '\\"'])
env.Append(CCFLAGS=['-DAPI_VERSION=\\"' + API_VERSION + '\\"'])
def build_misc():
"""Build miscellaneous items"""
# install the configuration files
SConscript('utils/config/SConscript')
# install certificate generation files
SConscript('utils/certs/SConscript')
# install man pages
try:
SConscript('doc/man/SConscript', must_exist=0)
except SCons.Warnings.MissingSConscriptWarning as _warn:
print("Missing doc/man/SConscript...")
def scons(): # pylint: disable=too-many-locals
"""Execute build"""
if COMMAND_LINE_TARGETS == ['release']:
try:
# pylint: disable=import-outside-toplevel
import pygit2
import github
import yaml
# pylint: enable=import-outside-toplevel
except ImportError:
print("You need yaml, pygit2 and pygithub python modules to "
"create releases")
Exit(1)
variables = Variables()
variables.Add('RELEASE', 'Set to the release version to make', None)
variables.Add('RELEASE_BASE', 'Set to the release version to make',
'master')
variables.Add('ORG_NAME', 'The GitHub project to do the release on.',
'daos-stack')
variables.Add('REMOTE_NAME', 'The remoten name release on.', 'origin')
env = Environment(variables=variables)
org_name = env['ORG_NAME']
remote_name = env['REMOTE_NAME']
base_branch = env['RELEASE_BASE']
try:
tag = env['RELEASE']
except KeyError:
print("Usage: scons RELEASE=x.y.z release")
Exit(1)
dash = tag.find('-') # pylint: disable=no-member
if dash > 0:
version = tag[0:dash]
else:
print("** Final releases should be made on GitHub directly "
"using a previous pre-release such as a release candidate.\n")
question = "Are you sure you want to continue? (y/N): "
answer = None
while answer not in ["y", "n", ""]:
answer = input(question).lower().strip()
if answer != 'y':
Exit(1)
version = tag
try:
token = yaml.safe_load(open(os.path.join(os.path.expanduser("~"),
".config", "hub"), 'r')
)['github.com'][0]['oauth_token']
except IOError as excpn:
if excpn.errno == errno.ENOENT:
print("You need to install hub (from the hub RPM on EL7) to "
"and run it at least once to create an authorization "
"token in order to create releases")
Exit(1)
raise
# create a branch for the PR
branch = 'create-release-{}'.format(tag)
print("Creating a branch for the PR...")
repo = pygit2.Repository('.git')
try:
base_ref = repo.lookup_reference(
'refs/remotes/{}/{}'.format(remote_name, base_branch))
except KeyError:
print("Branch {}/{} is not a valid branch\n"
"See https://github.com/{}/daos/branches".format(
remote_name, base_branch, org_name))
Exit(1)
# older pygit2 didn't have AlreadyExistsError
try:
already_exists_error_exception = pygit2.AlreadyExistsError
except AttributeError:
already_exists_error_exception = ValueError
try:
repo.branches.create(branch, repo[base_ref.target])
except already_exists_error_exception:
print("Branch {} exists locally already.\n"
"You need to delete it or rename it to try again.".format(
branch))
Exit(1)
# and check it out
print("Checking out branch for the PR...")
repo.checkout(repo.lookup_branch(branch))
print("Updating the RPM specfile...")
if not update_rpm_version(version, tag):
print("Branch has been left in the created state. You will have "
"to clean it up manually.")
Exit(1)
print("Updating the VERSION and TAG files...")
with open("VERSION", "w") as version_file:
version_file.write(version + '\n')
with open("TAG", "w") as version_file:
version_file.write(tag + '\n')
print("Committing the changes...")
# now create the commit
index = repo.index
index.read()
author = repo.default_signature
committer = repo.default_signature
summary = "Update version to v{}".format(tag)
# pylint: disable=no-member
message = "{}\n\n" \
"Signed-off-by: {} <{}>".format(summary,
repo.default_signature.name,
repo.default_signature.email)
# pylint: enable=no-member
index.add("utils/rpms/daos.spec")
index.add("VERSION")
index.add("TAG")
index.write()
tree = index.write_tree()
# pylint: disable=no-member
repo.create_commit('HEAD', author, committer, message, tree,
[repo.head.target])
# pylint: enable=no-member
# set up authentication callback
class MyCallbacks(pygit2.RemoteCallbacks): # pylint: disable=too-few-public-methods
""" Callbacks for pygit2 """
@staticmethod
def credentials(_url, username_from_url, allowed_types): # pylint: disable=method-hidden
"""setup credentials"""
if allowed_types & pygit2.credentials.GIT_CREDTYPE_SSH_KEY:
if "SSH_AUTH_SOCK" in os.environ:
# Use ssh agent for authentication
return pygit2.KeypairFromAgent(username_from_url)
#else:
# need to determine if key is passphrase protected and ask
# for the passphrase in order to use this method
# ssh_key = os.path.join(os.path.expanduser("~"),
# ".ssh", "id_rsa")
# return pygit2.Keypair("git", ssh_key + ".pub",
# ssh_key, "")
#elif allowed_types & pygit2.credentials.GIT_CREDTYPE_USERNAME:
# this is not really useful in the GitHub context
# return pygit2.Username("git")
else:
raise Exception("No supported credential types allowed "
"by remote end. SSH_AUTH_SOCK not found "
"in your environment. Are you running an "
"ssh-agent?")
return None
# and push it
print("Pushing the changes to GitHub...")
remote = repo.remotes[remote_name]
# pylint: disable=no-member
try:
remote.push(['refs/heads/{}'.format(branch)],
callbacks=MyCallbacks())
except pygit2.GitError as excpt:
print("Error pushing branch: {}".format(excpt))
Exit(1)
# pylint: enable=no-member
print("Creating the PR...")
# now create a PR for it
gh_context = github.Github(token)
try:
org = gh_context.get_organization(org_name)
repo = org.get_repo('daos')
except github.UnknownObjectException:
# maybe not an organization
repo = gh_context.get_repo('{}/daos'.format(org_name))
new_pr = repo.create_pull(title=summary, body="", base=base_branch,
head="{}:{}".format(org_name, branch))
print("Successfully created PR#{0} for this version "
"update:\n"
"https://github.com/{1}/daos/pull/{0}/".format(new_pr.number,
org_name))
print("Self-assigning the PR...")
# self-assign the PR
new_pr.as_issue().add_to_assignees(
gh_context.get_user(gh_context.get_user().login))
print("Done.")
Exit(0)
env = Environment(TOOLS=['extra', 'default', 'textfile'])
opts_file = os.path.join(Dir('#').abspath, 'daos.conf')
opts = Variables(opts_file)
commits_file = os.path.join(Dir('#').abspath, 'utils/build.config')
if not os.path.exists(commits_file):
commits_file = None
platform_arm = is_platform_arm()
prereqs = PreReqComponent(env, opts, commits_file)
if not GetOption('help') and not GetOption('clean'):
daos_build.load_mpi_path(env)
build_prefix = prereqs.get_src_build_dir()
prereqs.init_build_targets(build_prefix)
prereqs.load_defaults(platform_arm)
if prereqs.check_component('valgrind_devel'):
env.AppendUnique(CPPDEFINES=["D_HAS_VALGRIND"])
AddOption('--deps-only',
dest='deps_only',
action='store_true',
default=False,
help='Download and build dependencies only, do not build daos')
prereqs.add_opts(('GO_BIN', 'Full path to go binary', None))
opts.Save(opts_file, env)
res = GetOption('deps_only')
if res:
print('Exiting because deps-only was set')
Exit(0)
conf_dir = ARGUMENTS.get('CONF_DIR', '$PREFIX/etc')
env.Alias('install', '$PREFIX')
daos_version = get_version(env)
set_defaults(env, daos_version)
base_env = env.Clone()
compiler_setup.base_setup(env, prereqs=prereqs)
args = GetOption('analyze_stack')
if args is not None:
analyzer = stack_analyzer.analyzer(env, build_prefix, args)
analyzer.analyze_on_exit()
# Export() is handled specially by pylint so do not merge these two lines.
Export('daos_version', 'API_VERSION', 'env', 'base_env', 'prereqs')
Export('platform_arm', 'conf_dir')
# generate targets in specific build dir to avoid polluting the source code
VariantDir(build_prefix, '.', duplicate=0)
SConscript('{}/src/SConscript'.format(build_prefix))
buildinfo = prereqs.get_build_info()
buildinfo.gen_script('.build_vars.sh')
buildinfo.save('.build_vars.json')
# also install to $PREFIX/lib to work with existing avocado test code
if prereqs.test_requested():
daos_build.install(env, "lib/daos/",
['.build_vars.sh', '.build_vars.json'])
env.Install('$PREFIX/lib/daos/TESTING/ftest/util',
['site_scons/env_modules.py'])
env.Install('$PREFIX/lib/daos/TESTING/ftest/',
['ftest.sh'])
env.Install("$PREFIX/lib64/daos", "VERSION")
if prereqs.client_requested():
api_version = env.Command("%s/API_VERSION" % build_prefix,
"%s/SConstruct" % build_prefix,
"echo %s > $TARGET" % (API_VERSION))
env.Install("$PREFIX/lib64/daos", api_version)
env.Install(conf_dir + '/bash_completion.d', ['utils/completion/daos.bash'])
build_misc()
Default(build_prefix)
# an "rpms" target
env.Command('rpms', '', 'make -C utils/rpms rpms')
try:
#if using SCons 2.4+, provide a more complete help
Help(opts.GenerateHelpText(env), append=True)
except TypeError:
Help(opts.GenerateHelpText(env))
if __name__ == "SCons.Script":
scons()