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

Side by Side Diff: build/gyp_chromium

Issue 73623005: Move GYP_DEFINES parsing to Python for GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« 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 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 sys 16 import sys
17 17
18 script_dir = os.path.dirname(os.path.realpath(__file__)) 18 script_dir = os.path.dirname(os.path.realpath(__file__))
19 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) 19 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
20 20
21 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) 21 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
22 import gyp 22 import gyp
23 23
24 # 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
24 # Add paths so that pymod_do_main(...) can import files. 27 # Add paths so that pymod_do_main(...) can import files.
25 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers')) 28 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers'))
26 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit')) 29 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
27 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build')) 30 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
28 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build')) 31 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
29 sys.path.insert(1, os.path.join(chrome_src, 'native_client_sdk', 'src', 32 sys.path.insert(1, os.path.join(chrome_src, 'native_client_sdk', 'src',
30 'build_tools')) 33 'build_tools'))
31 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build')) 34 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build'))
32 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', 35 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit',
33 'Source', 'build', 'scripts')) 36 'Source', 'build', 'scripts'))
(...skipping 10 matching lines...) Expand all
44 # may not be worth it). 47 # may not be worth it).
45 if sys.platform == 'win32': 48 if sys.platform == 'win32':
46 try: 49 try:
47 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) 50 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
48 import psyco 51 import psyco
49 except: 52 except:
50 psyco = None 53 psyco = None
51 else: 54 else:
52 psyco = None 55 psyco = None
53 56
54 def additional_include_files(args=[]): 57
58 def GetSupplementalFiles():
59 """Returns a list of the supplemental files that are included in all GYP
60 sources."""
61 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
62
63
64 def GetVarsStringForGN(supplemental_files):
65 vars_dict = {}
66
67 for supplement in supplemental_files:
68 with open(supplement, 'r') as f:
69 try:
70 file_data = eval(f.read(), {'__builtins__': None}, None)
71 except SyntaxError, e:
72 e.filename = os.path.abspath(supplement)
73 raise
74 variables = file_data.get('variables')
75 for v in variables:
76 vars_dict[v] = '"' + variables[v] + '"'
77
78 env_string = os.environ.get('GYP_DEFINES', [])
79 items = shlex.split(env_string)
80 for item in items:
81 tokens = item.split('=', 1)
82 if len(tokens) == 2:
83 # Escape $ characters which have special meaning to GN.
84 vars_dict[tokens[0]] = '"' + tokens[1].replace("$", "\\$") + '"'
85 else:
86 # No value supplied, treat it as a boolean and set it.
87 vars_dict[tokens[0]] = 'true'
88
89 vars_string = ''
90 for v in vars_dict:
91 vars_string = vars_string + v + '=' + vars_dict[v] + ' '
92 return vars_string.strip() # Remove trailing space.
93
94
95 def additional_include_files(supplemental_files, args=[]):
55 """ 96 """
56 Returns a list of additional (.gypi) files to include, without 97 Returns a list of additional (.gypi) files to include, without duplicating
57 duplicating ones that are already specified on the command line. 98 ones that are already specified on the command line. The list of supplemental
99 include files is passed in as an argument.
58 """ 100 """
59 # Determine the include files specified on the command line. 101 # Determine the include files specified on the command line.
60 # This doesn't cover all the different option formats you can use, 102 # This doesn't cover all the different option formats you can use,
61 # but it's mainly intended to avoid duplicating flags on the automatic 103 # but it's mainly intended to avoid duplicating flags on the automatic
62 # makefile regeneration which only uses this format. 104 # makefile regeneration which only uses this format.
63 specified_includes = set() 105 specified_includes = set()
64 for arg in args: 106 for arg in args:
65 if arg.startswith('-I') and len(arg) > 2: 107 if arg.startswith('-I') and len(arg) > 2:
66 specified_includes.add(os.path.realpath(arg[2:])) 108 specified_includes.add(os.path.realpath(arg[2:]))
67 109
68 result = [] 110 result = []
69 def AddInclude(path): 111 def AddInclude(path):
70 if os.path.realpath(path) not in specified_includes: 112 if os.path.realpath(path) not in specified_includes:
71 result.append(path) 113 result.append(path)
72 114
73 # Always include common.gypi. 115 # Always include common.gypi.
74 AddInclude(os.path.join(script_dir, 'common.gypi')) 116 AddInclude(os.path.join(script_dir, 'common.gypi'))
75 117
76 # Optionally add supplemental .gypi files if present. 118 # Optionally add supplemental .gypi files if present.
77 supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) 119 for supplement in supplemental_files:
78 for supplement in supplements:
79 AddInclude(supplement) 120 AddInclude(supplement)
80 121
81 return result 122 return result
82 123
124
125 def RunGN(supplemental_includes):
126 """Runs GN, returning True if it succeeded, printing an error and returning
127 false if not."""
128
129 # The binaries in platform-specific subdirectories in src/tools/gn/bin.
130 gnpath = SRC_DIR + '/tools/gn/bin/'
131 if sys.platform == 'win32':
132 gnpath += 'win/gn.exe'
133 elif sys.platform.startswith('linux'):
134 # On Linux we have 32-bit and 64-bit versions. Checking /sbin/init avoids
135 # uname's confusion when running a 32-bit userland on a 64-bit kernel.
136 if subprocess.check_output(["file", "/sbin/init"]).find("ELF 64-bit") >= 0:
Nico 2013/12/03 22:45:16 (I think the usual thing to do is `getconf LONG_BI
137 gnpath += 'linux/gn'
138 else:
139 gnpath += 'linux/gn32'
140 elif sys.platform == 'darwin':
141 gnpath += 'mac/gn'
142 else:
143 print 'Unknown platform for GN: ', sys.platform
144 return False
145
146 print 'Generating gyp files from GN...'
147 gyp_vars = GetVarsStringForGN(supplemental_includes)
148
149 # Need to pass both the source root (the bots don't run this command from
150 # within the source tree) as well as set the is_gyp value so the BUILD files
151 # to know they're being run under GYP.
152 args = [gnpath, 'gyp', '-q',
153 '--root=' + chrome_src,
154 '--args=is_gyp=true',
155 '--gyp_vars=' + gyp_vars + '']
156 return subprocess.call(args) == 0
157
158
83 if __name__ == '__main__': 159 if __name__ == '__main__':
84 args = sys.argv[1:] 160 args = sys.argv[1:]
85 161
86 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): 162 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)):
87 print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.' 163 print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.'
88 sys.exit(0) 164 sys.exit(0)
89 165
90 # Use the Psyco JIT if available. 166 # Use the Psyco JIT if available.
91 if psyco: 167 if psyco:
92 psyco.profile() 168 psyco.profile()
(...skipping 26 matching lines...) Expand all
119 # assuming 'all.gyp' from the same directory as the script. 195 # assuming 'all.gyp' from the same directory as the script.
120 if not gyp_file_specified: 196 if not gyp_file_specified:
121 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') 197 gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
122 if gyp_file: 198 if gyp_file:
123 # Note that CHROMIUM_GYP_FILE values can't have backslashes as 199 # Note that CHROMIUM_GYP_FILE values can't have backslashes as
124 # path separators even on Windows due to the use of shlex.split(). 200 # path separators even on Windows due to the use of shlex.split().
125 args.extend(shlex.split(gyp_file)) 201 args.extend(shlex.split(gyp_file))
126 else: 202 else:
127 args.append(os.path.join(script_dir, 'all.gyp')) 203 args.append(os.path.join(script_dir, 'all.gyp'))
128 204
129 args.extend(['-I' + i for i in additional_include_files(args)]) 205 supplemental_includes = GetSupplementalFiles()
206
207 if not RunGN(supplemental_includes):
208 sys.exit(1)
209
210 args.extend(
211 ['-I' + i for i in additional_include_files(supplemental_includes, args)])
130 212
131 # There shouldn't be a circular dependency relationship between .gyp files, 213 # There shouldn't be a circular dependency relationship between .gyp files,
132 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships 214 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
133 # currently exist. The check for circular dependencies is currently 215 # currently exist. The check for circular dependencies is currently
134 # bypassed on other platforms, but is left enabled on the Mac, where a 216 # bypassed on other platforms, but is left enabled on the Mac, where a
135 # violation of the rule causes Xcode to misbehave badly. 217 # violation of the rule causes Xcode to misbehave badly.
136 # TODO(mark): Find and kill remaining circular dependencies, and remove this 218 # TODO(mark): Find and kill remaining circular dependencies, and remove this
137 # option. http://crbug.com/35878. 219 # option. http://crbug.com/35878.
138 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the 220 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
139 # list. 221 # list.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 # to enfore syntax checking. 265 # to enfore syntax checking.
184 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') 266 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
185 if syntax_check and int(syntax_check): 267 if syntax_check and int(syntax_check):
186 args.append('--check') 268 args.append('--check')
187 269
188 print 'Updating projects from gyp files...' 270 print 'Updating projects from gyp files...'
189 sys.stdout.flush() 271 sys.stdout.flush()
190 272
191 # Off we go... 273 # Off we go...
192 sys.exit(gyp.main(args)) 274 sys.exit(gyp.main(args))
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