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 |
11 import gyp_helper | 11 import gyp_helper |
12 import os | 12 import os |
13 import pipes | 13 import pipes |
14 import shlex | 14 import shlex |
15 import subprocess | 15 import subprocess |
| 16 import string |
16 import sys | 17 import sys |
17 | 18 |
18 script_dir = os.path.dirname(os.path.realpath(__file__)) | 19 script_dir = os.path.dirname(os.path.realpath(__file__)) |
19 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 20 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
20 | 21 |
21 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 22 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
22 import gyp | 23 import gyp |
23 | 24 |
24 # Assume this file is in a one-level-deep subdirectory of the source root. | 25 # Assume this file is in a one-level-deep subdirectory of the source root. |
25 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 26 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
(...skipping 29 matching lines...) Expand all Loading... |
55 else: | 56 else: |
56 psyco = None | 57 psyco = None |
57 | 58 |
58 | 59 |
59 def GetSupplementalFiles(): | 60 def GetSupplementalFiles(): |
60 """Returns a list of the supplemental files that are included in all GYP | 61 """Returns a list of the supplemental files that are included in all GYP |
61 sources.""" | 62 sources.""" |
62 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) | 63 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) |
63 | 64 |
64 | 65 |
| 66 def FormatKeyForGN(key): |
| 67 """Returns the given GYP key reformatted for GN. |
| 68 |
| 69 GYP dictionary keys can be almost anything, but in GN they are identifiers |
| 70 and must follow the same rules. This reformats such keys to be valid GN |
| 71 identifiers.""" |
| 72 return ''.join([c if c in string.ascii_letters else '_' for c in key]) |
| 73 |
| 74 |
65 def GetVarsStringForGN(supplemental_files): | 75 def GetVarsStringForGN(supplemental_files): |
66 vars_dict = {} | 76 vars_dict = {} |
67 | 77 |
68 for supplement in supplemental_files: | 78 for supplement in supplemental_files: |
69 with open(supplement, 'r') as f: | 79 with open(supplement, 'r') as f: |
70 try: | 80 try: |
71 file_data = eval(f.read(), {'__builtins__': None}, None) | 81 file_data = eval(f.read(), {'__builtins__': None}, None) |
72 except SyntaxError, e: | 82 except SyntaxError, e: |
73 e.filename = os.path.abspath(supplement) | 83 e.filename = os.path.abspath(supplement) |
74 raise | 84 raise |
75 variables = file_data.get('variables') | 85 variables = file_data.get('variables') |
76 for v in variables: | 86 for v in variables: |
77 vars_dict[v] = '"' + str(variables[v]) + '"' | 87 vars_dict[v] = '"' + str(variables[v]) + '"' |
78 | 88 |
79 env_string = os.environ.get('GYP_DEFINES', '') | 89 env_string = os.environ.get('GYP_DEFINES', '') |
80 items = shlex.split(env_string) | 90 items = shlex.split(env_string) |
81 for item in items: | 91 for item in items: |
82 tokens = item.split('=', 1) | 92 tokens = item.split('=', 1) |
83 # Some GYP variables have hyphens, which we don't support. | 93 # Some GYP variables have hyphens, which we don't support. |
84 key = tokens[0].replace("-", "_") | 94 key = FormatKeyForGN(tokens[0]) |
85 if len(tokens) == 2: | 95 if len(tokens) == 2: |
86 # Escape $ characters which have special meaning to GN. | 96 # Escape $ characters which have special meaning to GN. |
87 vars_dict[key] = '"' + tokens[1].replace("$", "\\$") + '"' | 97 vars_dict[key] = '"' + tokens[1].replace("$", "\\$") + '"' |
88 else: | 98 else: |
89 # No value supplied, treat it as a boolean and set it. | 99 # No value supplied, treat it as a boolean and set it. |
90 vars_dict[key] = 'true' | 100 vars_dict[key] = 'true' |
91 | 101 |
92 vars_string = '' | 102 vars_string = '' |
93 for v in vars_dict: | 103 for v in vars_dict: |
94 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' | 104 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') | 209 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') |
200 if gyp_file: | 210 if gyp_file: |
201 # Note that CHROMIUM_GYP_FILE values can't have backslashes as | 211 # Note that CHROMIUM_GYP_FILE values can't have backslashes as |
202 # path separators even on Windows due to the use of shlex.split(). | 212 # path separators even on Windows due to the use of shlex.split(). |
203 args.extend(shlex.split(gyp_file)) | 213 args.extend(shlex.split(gyp_file)) |
204 else: | 214 else: |
205 args.append(os.path.join(script_dir, 'all.gyp')) | 215 args.append(os.path.join(script_dir, 'all.gyp')) |
206 | 216 |
207 supplemental_includes = GetSupplementalFiles() | 217 supplemental_includes = GetSupplementalFiles() |
208 | 218 |
209 # Temporarily disabled until it is debugged. | 219 if not RunGN(supplemental_includes): |
210 # TODO(brettw) re-enable this code. | 220 sys.exit(1) |
211 #if not RunGN(supplemental_includes): | |
212 # sys.exit(1) | |
213 | 221 |
214 args.extend( | 222 args.extend( |
215 ['-I' + i for i in additional_include_files(supplemental_includes, args)]) | 223 ['-I' + i for i in additional_include_files(supplemental_includes, args)]) |
216 | 224 |
217 # There shouldn't be a circular dependency relationship between .gyp files, | 225 # There shouldn't be a circular dependency relationship between .gyp files, |
218 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships | 226 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships |
219 # currently exist. The check for circular dependencies is currently | 227 # currently exist. The check for circular dependencies is currently |
220 # bypassed on other platforms, but is left enabled on the Mac, where a | 228 # bypassed on other platforms, but is left enabled on the Mac, where a |
221 # violation of the rule causes Xcode to misbehave badly. | 229 # violation of the rule causes Xcode to misbehave badly. |
222 # TODO(mark): Find and kill remaining circular dependencies, and remove this | 230 # 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. | 277 # to enfore syntax checking. |
270 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') | 278 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') |
271 if syntax_check and int(syntax_check): | 279 if syntax_check and int(syntax_check): |
272 args.append('--check') | 280 args.append('--check') |
273 | 281 |
274 print 'Updating projects from gyp files...' | 282 print 'Updating projects from gyp files...' |
275 sys.stdout.flush() | 283 sys.stdout.flush() |
276 | 284 |
277 # Off we go... | 285 # Off we go... |
278 sys.exit(gyp.main(args)) | 286 sys.exit(gyp.main(args)) |
OLD | NEW |