OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 the V8 project authors. All rights reserved. | |
2 # Copyright 2013 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 import functools | |
8 import logging | |
9 import os | |
10 import shlex | |
11 import sys | |
12 | |
13 | |
14 def memoize(default=None): | |
15 """This decorator caches the return value of a parameterless pure function""" | |
16 def memoizer(func): | |
17 val = [] | |
18 @functools.wraps(func) | |
19 def inner(): | |
20 if not val: | |
21 ret = func() | |
22 val.append(ret if ret is not None else default) | |
23 if logging.getLogger().isEnabledFor(logging.INFO): | |
24 print '%s -> %r' % (func.__name__, val[0]) | |
25 return val[0] | |
26 return inner | |
27 return memoizer | |
28 | |
29 | |
30 @memoize() | |
31 def IsWindows(): | |
32 return sys.platform in ['win32', 'cygwin'] | |
33 | |
34 | |
35 @memoize() | |
36 def IsLinux(): | |
37 return sys.platform.startswith(('linux', 'freebsd')) | |
38 | |
39 | |
40 @memoize() | |
41 def IsMac(): | |
42 return sys.platform == 'darwin' | |
43 | |
44 | |
45 @memoize() | |
46 def gyp_defines(): | |
47 """Parses and returns GYP_DEFINES env var as a dictionary.""" | |
48 return dict(arg.split('=', 1) | |
49 for arg in shlex.split(os.environ.get('GYP_DEFINES', ''))) | |
50 | |
51 @memoize() | |
52 def gyp_msvs_version(): | |
53 return os.environ.get('GYP_MSVS_VERSION', '') | |
54 | |
55 @memoize() | |
56 def distributor(): | |
57 """ | |
58 Returns a string which is the distributed build engine in use (if any). | |
59 Possible values: 'goma', 'ib', '' | |
60 """ | |
61 if 'goma' in gyp_defines(): | |
62 return 'goma' | |
63 elif IsWindows(): | |
64 if 'CHROME_HEADLESS' in os.environ: | |
65 return 'ib' # use (win and !goma and headless) as approximation of ib | |
66 | |
67 | |
68 @memoize() | |
69 def platform(): | |
70 """ | |
71 Returns a string representing the platform this build is targetted for. | |
72 Possible values: 'win', 'mac', 'linux', 'ios', 'android' | |
73 """ | |
74 if 'OS' in gyp_defines(): | |
75 if 'android' in gyp_defines()['OS']: | |
76 return 'android' | |
77 else: | |
78 return gyp_defines()['OS'] | |
79 elif IsWindows(): | |
80 return 'win' | |
81 elif IsLinux(): | |
82 return 'linux' | |
83 else: | |
84 return 'mac' | |
85 | |
86 | |
87 @memoize() | |
88 def builder(): | |
89 """ | |
90 Returns a string representing the build engine (not compiler) to use. | |
91 Possible values: 'make', 'ninja', 'xcode', 'msvs', 'scons' | |
92 """ | |
93 if 'GYP_GENERATORS' in os.environ: | |
94 # for simplicity, only support the first explicit generator | |
95 generator = os.environ['GYP_GENERATORS'].split(',')[0] | |
96 if generator.endswith('-android'): | |
97 return generator.split('-')[0] | |
98 elif generator.endswith('-ninja'): | |
99 return 'ninja' | |
100 else: | |
101 return generator | |
102 else: | |
103 if platform() == 'android': | |
104 # Good enough for now? Do any android bots use make? | |
105 return 'ninja' | |
jochen (gone - plz use gerrit)
2014/07/22 14:52:05
we use make, no?
Michael Achenbach
2014/07/22 15:03:59
Right. I relied on GYP_GENERATORS - but it is actu
| |
106 elif platform() == 'ios': | |
107 return 'xcode' | |
108 elif IsWindows(): | |
109 return 'ninja' | |
jochen (gone - plz use gerrit)
2014/07/22 14:52:05
and msvs
| |
110 elif IsLinux(): | |
111 return 'ninja' | |
jochen (gone - plz use gerrit)
2014/07/22 14:52:05
and make here
| |
112 elif IsMac(): | |
113 return 'ninja' | |
jochen (gone - plz use gerrit)
2014/07/22 14:52:05
and xcode there
| |
114 else: | |
115 assert False, 'Don\'t know what builder we\'re using!' | |
OLD | NEW |