OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # This script is wrapper for Chromium that adds some support for how GYP | 7 # This script is wrapper for Chromium that adds some support for how GYP |
8 # is invoked by Chromium beyond what can be done in the gclient hooks. | 8 # is invoked by Chromium beyond what can be done in the gclient hooks. |
9 | 9 |
10 import glob | 10 import glob |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 else: | 55 else: |
56 psyco = None | 56 psyco = None |
57 | 57 |
58 | 58 |
59 def GetSupplementalFiles(): | 59 def GetSupplementalFiles(): |
60 """Returns a list of the supplemental files that are included in all GYP | 60 """Returns a list of the supplemental files that are included in all GYP |
61 sources.""" | 61 sources.""" |
62 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) | 62 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) |
63 | 63 |
64 | 64 |
65 def FormatKeyForGN(key): | |
66 """Returns the given GYP key reformatted for GN. | |
67 | |
68 GYP dictionary keys can be almost anything, but in GN they are identifiers | |
69 and must follow the same rules. This reformats such keys to be valid GN | |
70 identifiers.""" | |
71 ret = '' | |
72 for c in key: | |
73 if (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z'): | |
Nico
2013/12/04 18:15:20
if c in string.ascii_letters, and add `import stri
| |
74 ret = ret + c | |
Nico
2013/12/04 18:15:20
ret += c
| |
75 else: | |
76 ret = ret + '_' | |
Nico
2013/12/04 18:15:20
ret += '_'
| |
77 return ret | |
Nico
2013/12/04 18:15:20
I think the "more pythonic" way of writing this is
| |
78 | |
79 | |
65 def GetVarsStringForGN(supplemental_files): | 80 def GetVarsStringForGN(supplemental_files): |
66 vars_dict = {} | 81 vars_dict = {} |
67 | 82 |
68 for supplement in supplemental_files: | 83 for supplement in supplemental_files: |
69 with open(supplement, 'r') as f: | 84 with open(supplement, 'r') as f: |
70 try: | 85 try: |
71 file_data = eval(f.read(), {'__builtins__': None}, None) | 86 file_data = eval(f.read(), {'__builtins__': None}, None) |
72 except SyntaxError, e: | 87 except SyntaxError, e: |
73 e.filename = os.path.abspath(supplement) | 88 e.filename = os.path.abspath(supplement) |
74 raise | 89 raise |
75 variables = file_data.get('variables') | 90 variables = file_data.get('variables') |
76 for v in variables: | 91 for v in variables: |
77 vars_dict[v] = '"' + str(variables[v]) + '"' | 92 vars_dict[v] = '"' + str(variables[v]) + '"' |
78 | 93 |
79 env_string = os.environ.get('GYP_DEFINES', '') | 94 env_string = os.environ.get('GYP_DEFINES', '') |
80 items = shlex.split(env_string) | 95 items = shlex.split(env_string) |
81 for item in items: | 96 for item in items: |
82 tokens = item.split('=', 1) | 97 tokens = item.split('=', 1) |
83 # Some GYP variables have hyphens, which we don't support. | 98 # Some GYP variables have hyphens, which we don't support. |
84 key = tokens[0].replace("-", "_") | 99 key = FormatKeyForGN(tokens[0]) |
85 if len(tokens) == 2: | 100 if len(tokens) == 2: |
86 # Escape $ characters which have special meaning to GN. | 101 # Escape $ characters which have special meaning to GN. |
87 vars_dict[key] = '"' + tokens[1].replace("$", "\\$") + '"' | 102 vars_dict[key] = '"' + tokens[1].replace("$", "\\$") + '"' |
88 else: | 103 else: |
89 # No value supplied, treat it as a boolean and set it. | 104 # No value supplied, treat it as a boolean and set it. |
90 vars_dict[key] = 'true' | 105 vars_dict[key] = 'true' |
91 | 106 |
92 vars_string = '' | 107 vars_string = '' |
93 for v in vars_dict: | 108 for v in vars_dict: |
94 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' | 109 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') | 214 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') |
200 if gyp_file: | 215 if gyp_file: |
201 # Note that CHROMIUM_GYP_FILE values can't have backslashes as | 216 # Note that CHROMIUM_GYP_FILE values can't have backslashes as |
202 # path separators even on Windows due to the use of shlex.split(). | 217 # path separators even on Windows due to the use of shlex.split(). |
203 args.extend(shlex.split(gyp_file)) | 218 args.extend(shlex.split(gyp_file)) |
204 else: | 219 else: |
205 args.append(os.path.join(script_dir, 'all.gyp')) | 220 args.append(os.path.join(script_dir, 'all.gyp')) |
206 | 221 |
207 supplemental_includes = GetSupplementalFiles() | 222 supplemental_includes = GetSupplementalFiles() |
208 | 223 |
209 # Temporarily disabled until it is debugged. | 224 if not RunGN(supplemental_includes): |
210 # TODO(brettw) re-enable this code. | 225 sys.exit(1) |
211 #if not RunGN(supplemental_includes): | |
212 # sys.exit(1) | |
213 | 226 |
214 args.extend( | 227 args.extend( |
215 ['-I' + i for i in additional_include_files(supplemental_includes, args)]) | 228 ['-I' + i for i in additional_include_files(supplemental_includes, args)]) |
216 | 229 |
217 # There shouldn't be a circular dependency relationship between .gyp files, | 230 # There shouldn't be a circular dependency relationship between .gyp files, |
218 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships | 231 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships |
219 # currently exist. The check for circular dependencies is currently | 232 # currently exist. The check for circular dependencies is currently |
220 # bypassed on other platforms, but is left enabled on the Mac, where a | 233 # bypassed on other platforms, but is left enabled on the Mac, where a |
221 # violation of the rule causes Xcode to misbehave badly. | 234 # violation of the rule causes Xcode to misbehave badly. |
222 # TODO(mark): Find and kill remaining circular dependencies, and remove this | 235 # TODO(mark): Find and kill remaining circular dependencies, and remove this |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 # to enfore syntax checking. | 282 # to enfore syntax checking. |
270 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') | 283 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') |
271 if syntax_check and int(syntax_check): | 284 if syntax_check and int(syntax_check): |
272 args.append('--check') | 285 args.append('--check') |
273 | 286 |
274 print 'Updating projects from gyp files...' | 287 print 'Updating projects from gyp files...' |
275 sys.stdout.flush() | 288 sys.stdout.flush() |
276 | 289 |
277 # Off we go... | 290 # Off we go... |
278 sys.exit(gyp.main(args)) | 291 sys.exit(gyp.main(args)) |
OLD | NEW |