OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Automates running BuildPackageLists, BuildSysroot, and | |
7 UploadSysroot for each supported arch of each sysroot creator. | |
8 """ | |
9 | |
10 import glob | |
11 import hashlib | |
12 import json | |
13 import multiprocessing | |
14 import os | |
15 import re | |
16 import string | |
17 import subprocess | |
18 import sys | |
19 | |
20 def run_script(args): | |
21 fnull = open(os.devnull, 'w') | |
22 subprocess.check_call(args, stdout=fnull, stderr=fnull) | |
23 | |
24 def sha1sumfile(filename): | |
25 sha1 = hashlib.sha1() | |
26 with open(filename, 'rb') as f: | |
27 while True: | |
28 data = f.read(65536) | |
29 if not data: | |
30 break | |
31 sha1.update(data) | |
32 return sha1.hexdigest() | |
33 | |
34 def get_proc_output(args): | |
35 return subprocess.check_output(args).strip() | |
36 | |
37 def build_and_upload(script_path, distro, release, arch, lock): | |
38 # TODO(thomasanderson): Find out which revision 'git-cl upload' uses to | |
39 # calculate the diff against and use that instead of HEAD. | |
40 script_dir = os.path.dirname(os.path.realpath(__file__)) | |
41 revision = get_proc_output(['git', '-C', script_dir, 'rev-parse', 'HEAD']) | |
42 | |
43 run_script([script_path, 'UpdatePackageLists%s' % arch]) | |
44 run_script([script_path, 'BuildSysroot%s' % arch]) | |
45 run_script([script_path, 'UploadSysroot%s' % arch, revision]) | |
46 | |
47 tarball = '%s_%s_%s_sysroot.tgz' % (distro, release, arch.lower()) | |
48 tgz_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), | |
49 "..", "..", "..", "out", "sysroot-build", | |
50 release, tarball) | |
51 sha1sum = sha1sumfile(tgz_path) | |
52 sysroot_dir = '%s_%s_%s-sysroot' % (distro, release, arch.lower()) | |
53 | |
54 sysroot_metadata = { | |
55 'Revision': revision, | |
56 'Tarball': tarball, | |
57 'Sha1Sum': sha1sum, | |
58 'SysrootDir': sysroot_dir | |
59 } | |
60 with lock: | |
61 with open('sysroots.json', 'rw+') as f: | |
62 sysroots = json.load(f) | |
63 sysroots["%s_%s" % (release, arch.lower())] = sysroot_metadata | |
64 f.seek(0) | |
65 f.truncate() | |
66 f.write(json.dumps(sysroots, sort_keys=True, indent=4, | |
67 separators=(',', ': '))) | |
68 f.write('\n') | |
69 | |
70 def build_and_upload_all(): | |
71 script_dir = os.path.dirname(os.path.realpath(__file__)) | |
72 procs = [] | |
73 lock = multiprocessing.Lock() | |
74 for filename in glob.glob(os.path.join(script_dir, 'sysroot-creator-*.sh')): | |
75 script_path = os.path.join(script_dir, filename) | |
76 distro = get_proc_output([script_path, 'PrintDistro']) | |
77 release = get_proc_output([script_path, 'PrintRelease']) | |
78 architectures = get_proc_output([script_path, 'PrintArchitectures']) | |
79 for arch in architectures.split('\n'): | |
80 proc = multiprocessing.Process(target=build_and_upload, | |
81 args=(script_path, distro, release, arch, | |
82 lock)) | |
83 procs.append(("%s %s (%s)" % (distro, release, arch), proc)) | |
84 proc.start() | |
85 for _, proc in procs: | |
86 proc.join() | |
87 | |
88 print "SYSROOT CREATION SUMMARY" | |
89 for name, proc in procs: | |
90 status = "FAILURE" if proc.exitcode else "SUCCESS" | |
91 print "%s sysroot creation\t%s" % (name, status) | |
Sam Clegg
2016/12/13 00:30:37
Shouldn't function return 1 if any proc.exitcode i
Tom (Use chromium acct)
2016/12/13 02:33:09
Done.
| |
92 | |
93 def main(): | |
94 build_and_upload_all() | |
95 # If there were no exceptions, all went well. | |
96 return 0 | |
97 | |
98 if __name__ == '__main__': | |
99 sys.exit(main()) | |
OLD | NEW |