Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: scripts/slave/recipe_modules/isolate/resources/isolate.py

Issue 2471023002: Make isolate.py fail if Go isolate fails (Closed)
Patch Set: Remove call to os.Access Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Calls either isolate.py or isolate Go executable in the checkout. 6 """Calls the isolate Go executable in the checkout, failing if it cannot run.
7 """ 7 """
8 8
9 # TODO(djd): make the caller invoke the Go binary directly, kill this script.
10
9 import os 11 import os
10 import subprocess 12 import subprocess
11 import sys 13 import sys
12 14
13 15
14 def try_go(path, args): 16 def try_go(path, args):
15 """Tries to run the Go implementation of isolate. 17 """Tries to run the Go implementation of isolate.
16
17 Returns None if it should fall back to the python implementation.
18 """ 18 """
19 luci_go = os.path.join(os.path.dirname(path), 'luci-go') 19 luci_go = os.path.join(os.path.dirname(path), 'luci-go')
20 if sys.platform == 'win32': 20 if sys.platform == 'win32':
21 exe = os.path.join(luci_go, 'win64', 'isolate.exe') 21 exe = os.path.join(luci_go, 'win64', 'isolate.exe')
22 elif sys.platform == 'darwin': 22 elif sys.platform == 'darwin':
23 exe = os.path.join(luci_go, 'mac64', 'isolate') 23 exe = os.path.join(luci_go, 'mac64', 'isolate')
24 else: 24 else:
25 exe = os.path.join(luci_go, 'linux64', 'isolate') 25 exe = os.path.join(luci_go, 'linux64', 'isolate')
26 if not os.access(exe, os.X_OK):
27 return None
28
29 # Try to use Go implementation.
30 try:
31 version = subprocess.check_output([exe, 'version']).strip()
32 version = tuple(map(int, version.split('.')))
33 except (subprocess.CalledProcessError, OSError, ValueError):
34 return None
35
36 expected = (0, 2, 2)
37
38 # Enlarge both tuples so (1, 0) == (1, 0, 0).
39 while len(version) < len(expected):
40 version = tuple(list(version) + [0])
41 while len(expected) < len(version):
42 version = tuple(list(expected) + [0])
43
44 # Key behavior based on version if necessary.
45 if version < expected:
46 print('Expected %s, found %s' % '.'.join(expected), '.'.join(version))
47 return None
48 26
49 return subprocess.call([exe] + args) 27 return subprocess.call([exe] + args)
mithro 2016/11/02 07:13:11 Maybe you want to use subprocess.check_call ?
50 28
51 29
52 def main(): 30 def main():
53 path = sys.argv[1] 31 path = sys.argv[1]
54 args = sys.argv[2:] 32 args = sys.argv[2:]
55 ret = try_go(path, args) 33 return try_go(path, args)
56 if ret is None:
57 return subprocess.call(
58 [sys.executable, os.path.join(path, 'isolate.py')] + args)
59 return ret
60 34
61 35
62 if __name__ == '__main__': 36 if __name__ == '__main__':
63 sys.exit(main()) 37 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698