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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 def FormatKeyForGN(key): | 66 def FormatKeyForGN(key): |
67 """Returns the given GYP key reformatted for GN. | 67 """Returns the given GYP key reformatted for GN. |
68 | 68 |
69 GYP dictionary keys can be almost anything, but in GN they are identifiers | 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 | 70 and must follow the same rules. This reformats such keys to be valid GN |
71 identifiers.""" | 71 identifiers.""" |
72 return ''.join([c if c in string.ascii_letters else '_' for c in key]) | 72 return ''.join([c if c in string.ascii_letters else '_' for c in key]) |
73 | 73 |
74 | 74 |
| 75 def EscapeStringForGN(s): |
| 76 """Converts a string to a GN string literal.""" |
| 77 # Escape $ characters which have special meaning to GN. |
| 78 return '"' + s.replace('$', '\\$').replace('"', '\\"') + '"' |
| 79 |
| 80 |
75 def GetVarsStringForGN(supplemental_files): | 81 def GetVarsStringForGN(supplemental_files): |
76 vars_dict = {} | 82 vars_dict = {} |
77 | 83 |
78 for supplement in supplemental_files: | 84 for supplement in supplemental_files: |
79 with open(supplement, 'r') as f: | 85 with open(supplement, 'r') as f: |
80 try: | 86 try: |
81 file_data = eval(f.read(), {'__builtins__': None}, None) | 87 file_data = eval(f.read(), {'__builtins__': None}, None) |
82 except SyntaxError, e: | 88 except SyntaxError, e: |
83 e.filename = os.path.abspath(supplement) | 89 e.filename = os.path.abspath(supplement) |
84 raise | 90 raise |
85 variables = file_data.get('variables', []) | 91 variables = file_data.get('variables', []) |
86 for v in variables: | 92 for v in variables: |
87 vars_dict[FormatKeyForGN(v)] = '"' + \ | 93 vars_dict[FormatKeyForGN(v)] = EscapeStringForGN(str(variables[v])) |
88 str(variables[v]).replace("$", "\\$") + '"' | |
89 | 94 |
90 env_string = os.environ.get('GYP_DEFINES', '') | 95 env_string = os.environ.get('GYP_DEFINES', '') |
91 items = shlex.split(env_string) | 96 items = shlex.split(env_string) |
92 for item in items: | 97 for item in items: |
93 tokens = item.split('=', 1) | 98 tokens = item.split('=', 1) |
94 # Some GYP variables have hyphens, which we don't support. | 99 # Some GYP variables have hyphens, which we don't support. |
95 key = FormatKeyForGN(tokens[0]) | 100 key = FormatKeyForGN(tokens[0]) |
96 if len(tokens) == 2: | 101 if len(tokens) == 2: |
97 # Escape $ characters which have special meaning to GN. | 102 vars_dict[key] = EscapeStringForGN(tokens[1]) |
98 vars_dict[key] = '"' + tokens[1].replace("$", "\\$") + '"' | |
99 else: | 103 else: |
100 # No value supplied, treat it as a boolean and set it. | 104 # No value supplied, treat it as a boolean and set it. |
101 vars_dict[key] = 'true' | 105 vars_dict[key] = 'true' |
102 | 106 |
103 vars_string = '' | 107 vars_string = '' |
104 for v in vars_dict: | 108 for v in vars_dict: |
105 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' | 109 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' |
106 return vars_string.strip() # Remove trailing space. | 110 return vars_string.strip() # Remove trailing space. |
107 | 111 |
108 | 112 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 # to enfore syntax checking. | 282 # to enfore syntax checking. |
279 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') | 283 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') |
280 if syntax_check and int(syntax_check): | 284 if syntax_check and int(syntax_check): |
281 args.append('--check') | 285 args.append('--check') |
282 | 286 |
283 print 'Updating projects from gyp files...' | 287 print 'Updating projects from gyp files...' |
284 sys.stdout.flush() | 288 sys.stdout.flush() |
285 | 289 |
286 # Off we go... | 290 # Off we go... |
287 sys.exit(gyp.main(args)) | 291 sys.exit(gyp.main(args)) |
OLD | NEW |