OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2015 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 | |
7 """Download recipe prerequisites and run a single recipe.""" | |
8 | |
9 | |
10 import base64 | |
11 import json | |
12 import os | |
13 import subprocess | |
14 import sys | |
15 import tarfile | |
16 import tempfile | |
estaab
2015/09/15 23:05:14
You're not using this and probably should :) Can
Ryan Tseng
2015/09/17 23:39:23
Actually swarming does it all for me if I leave al
| |
17 import urllib2 | |
18 import zlib | |
19 | |
20 | |
21 def download(source, dest): | |
22 u = urllib2.urlopen(source) # TODO: Verify certificate? | |
23 with open(dest, 'wb') as f: | |
24 while True: | |
25 buf = u.read(8192) | |
26 if not buf: | |
27 break | |
28 f.write(buf) | |
29 | |
30 | |
31 def unzip(source, dest): | |
32 with tarfile.open(source, 'r') as z: | |
33 z.extractall(dest) | |
34 | |
35 | |
36 def get_infra(dt_dir, root_dir): | |
37 fetch = os.path.join(dt_dir, 'fetch.py') | |
38 subprocess.check_call([sys.executable, fetch, 'infra'], cwd=root_dir) | |
39 | |
40 | |
41 def seed_properties(args): | |
42 # Assumes args[0] is factory properties and args[1] is build properties. | |
43 fact_prop_str = args[0][len('--factory-properties-gz='):] | |
44 build_prop_str = args[1][len('--build-properties-gz='):] | |
45 fact_prop = json.loads(zlib.decompress(base64.b64decode(fact_prop_str))) | |
46 build_prop = json.loads(zlib.decompress(base64.b64decode(build_prop_str))) | |
47 for k, v in fact_prop.iteritems(): | |
48 print '@@@SET_BUILD_PROPERTY@%s@%s@@@' % (k, v) | |
49 for k, v in build_prop.iteritems(): | |
50 print '@@@SET_BUILD_PROPERTY@%s@%s@@@' % (k, v) | |
51 | |
52 | |
53 def main(args): | |
54 cwd = os.getcwd() | |
55 | |
56 # Bootstrap depot tools (required for fetching build/infra) | |
57 dt_url = 'https://storage.googleapis.com/dumbtest/depot_tools.tar.gz' | |
58 dt_dir = os.path.join(cwd, 'staging') | |
59 os.makedirs(dt_dir) | |
60 dt_zip = os.path.join(dt_dir, 'depot_tools.tar.gz') | |
61 download(dt_url, os.path.join(dt_zip)) | |
estaab
2015/09/15 23:05:14
Can you handle errors for the parts we'll likely k
Ryan Tseng
2015/09/17 23:39:23
What do you mean? Like add retry logic?
This'll r
| |
62 unzip(dt_zip, dt_dir) | |
63 dt_path = os.path.join(dt_dir, 'depot_tools') | |
64 gclient = os.path.join(dt_path, 'gclient.py') | |
65 os.environ['PATH'] = '%s:%s' % (dt_path, os.environ['PATH']) | |
66 | |
67 # Fetch infra (which comes with build, which comes with recipes) | |
68 root_dir = os.path.join(cwd, 'b') | |
69 os.makedirs(root_dir) | |
70 get_infra(dt_path, root_dir) | |
71 work_dir = os.path.join(root_dir, 'build', 'slave', 'bot', 'build') | |
72 os.makedirs(work_dir) | |
73 | |
74 # Emit annotations that encapsulates build properties. | |
75 seed_properties(args) | |
76 | |
77 # JUST DO IT. | |
78 cmd = [sys.executable, '-u', '../../../scripts/slave/annotated_run.py'] | |
79 cmd.extend(args) | |
80 subprocess.check_call(cmd, cwd=work_dir) | |
81 | |
82 if __name__ == '__main__': | |
83 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |