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

Side by Side Diff: build/gyp_chromium

Issue 123463005: GN Command line -D parsing, goma on Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't use optparse Created 6 years, 11 months 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 | build/toolchain/win/BUILD.gn » ('j') | 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
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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): 75 def EscapeStringForGN(s):
76 """Converts a string to a GN string literal.""" 76 """Converts a string to a GN string literal."""
77 # Escape $ characters which have special meaning to GN. 77 # Escape $ characters which have special meaning to GN.
78 return '"' + s.replace('$', '\\$').replace('"', '\\"') + '"' 78 return '"' + s.replace('$', '\\$').replace('"', '\\"') + '"'
79 79
80 80
81 def ProcessGypDefinesItems(items):
82 """Converts a list of strings to a list of key-value pairs."""
83 result = []
84 for item in items:
85 tokens = item.split('=', 1)
86 # Some GYP variables have hyphens, which we don't support.
87 key = FormatKeyForGN(tokens[0])
88 if len(tokens) == 2:
89 result += [(key, tokens[1])]
90 else:
91 # No value supplied, treat it as a boolean and set it. Note that we
92 # use the string '1' here so we have a consistent definition whether
93 # you do 'foo=1' or 'foo'.
94 result += [(key, '1')]
95 return result
96
81 def GetGypVarsForGN(supplemental_files): 97 def GetGypVarsForGN(supplemental_files):
82 """Returns a dictionary of all GYP vars that we will be passing to GN.""" 98 """Returns a dictionary of all GYP vars that we will be passing to GN."""
83 vars_dict = {}
84 99
100 # GYP defines from the supplemental.gypi files.
101 supp_items = []
85 for supplement in supplemental_files: 102 for supplement in supplemental_files:
86 with open(supplement, 'r') as f: 103 with open(supplement, 'r') as f:
87 try: 104 try:
88 file_data = eval(f.read(), {'__builtins__': None}, None) 105 file_data = eval(f.read(), {'__builtins__': None}, None)
89 except SyntaxError, e: 106 except SyntaxError, e:
90 e.filename = os.path.abspath(supplement) 107 e.filename = os.path.abspath(supplement)
91 raise 108 raise
92 variables = file_data.get('variables', []) 109 variables = file_data.get('variables', [])
93 for v in variables: 110 for v in variables:
94 vars_dict[FormatKeyForGN(v)] = EscapeStringForGN(str(variables[v])) 111 supp_items += [(FormatKeyForGN(v), str(variables[v]))]
95 112
96 env_string = os.environ.get('GYP_DEFINES', '') 113 # GYP defines from the environment.
97 items = shlex.split(env_string) 114 env_items = ProcessGypDefinesItems(
98 for item in items: 115 shlex.split(os.environ.get('GYP_DEFINES', '')))
99 tokens = item.split('=', 1)
100 # Some GYP variables have hyphens, which we don't support.
101 key = FormatKeyForGN(tokens[0])
102 if len(tokens) == 2:
103 vars_dict[key] = tokens[1]
104 else:
105 # No value supplied, treat it as a boolean and set it.
106 vars_dict[key] = 'true'
107 116
108 return vars_dict 117 # GYP defines from the command line. We can't use optparse since we want
118 # to ignore all arguments other than "-D".
119 cmdline_input_items = []
120 for i in range(len(sys.argv))[1:]:
121 if sys.argv[i] == '-D' and i + 1 < len(sys.argv):
122 cmdline_input_items += [sys.argv[i + 1]]
123 cmdline_items = ProcessGypDefinesItems(cmdline_input_items)
124
125 return dict(supp_items + env_items + cmdline_items)
109 126
110 127
111 def GetArgsStringForGN(supplemental_files): 128 def GetArgsStringForGN(supplemental_files):
112 """Returns the args to pass to GN. 129 """Returns the args to pass to GN.
113 Based on a subset of the GYP variables that have been rewritten a bit.""" 130 Based on a subset of the GYP variables that have been rewritten a bit."""
114 131
115 vars_dict = GetGypVarsForGN(supplemental_files) 132 vars_dict = GetGypVarsForGN(supplemental_files)
133 print vars_dict
116 gn_args = '' 134 gn_args = ''
117 135
118 # Note: These are the additional flags passed to various builds by builders 136 # Note: These are the additional flags passed to various builds by builders
119 # on the main waterfall. We'll probably need to add these at some point: 137 # on the main waterfall. We'll probably need to add these at some point:
120 # mac_strip_release=1 http://crbug.com/330301 138 # mac_strip_release=1 http://crbug.com/330301
121 # linux_dump_symbols=0 http://crbug.com/330300 139 # linux_dump_symbols=0 http://crbug.com/330300
122 # host_os=linux Probably can skip, GN knows the host OS. 140 # host_os=linux Probably can skip, GN knows the host OS.
123 # gcc_version=46 Hopefully we can skip this and fix whatever uses it. 141 # gcc_version=46 Hopefully we can skip this and fix whatever uses it.
124 # order_text_section=<path> http://crbug.com/330299 142 # order_text_section=<path> http://crbug.com/330299
125 # chromium_win_pch=0 http://crbug.com/297678 143 # chromium_win_pch=0 http://crbug.com/297678
126 # clang_use_chrome_plugins=1 http://crbug.com/330298 144 # clang_use_chrome_plugins=1 http://crbug.com/330298
127 # chromium_ios_signing=0 http://crbug.com/330302 145 # chromium_ios_signing=0 http://crbug.com/330302
128 # linux_use_tcmalloc=0 http://crbug.com/330303 146 # linux_use_tcmalloc=0 http://crbug.com/330303
129 # release_extra_flags=... http://crbug.com/330305 147 # release_extra_flags=... http://crbug.com/330305
130 148
131 # These tuples of (key, value, gn_arg_string) use the gn_arg_string for 149 # These tuples of (key, value, gn_arg_string) use the gn_arg_string for
132 # gn when the key is set to the given value in the GYP arguments. 150 # gn when the key is set to the given value in the GYP arguments.
133 remap_cases = [ 151 remap_cases = [
134 ('branding', 'Chrome', 'is_chrome_branded=true'), 152 ('branding', 'Chrome', 'is_chrome_branded=true'),
135 ('buildtype', 'Official', 'is_official_build=true'), 153 ('buildtype', 'Official', 'is_official_build=true'),
136 ('component', 'shared_library', 'is_component_build=true'), 154 ('component', 'shared_library', 'is_component_build=true'),
137 ('clang', '1', 'is_clang=true'), 155 ('clang', '1', 'is_clang=true'),
138 ('target_arch', 'ia32', 'cpu_arch="x86"'), 156 ('target_arch', 'ia32', 'cpu_arch="x86"'),
139 ('target_arch', 'x64', 'cpu_arch="x64"'), 157 ('target_arch', 'x64', 'cpu_arch="x64" force_win64=true'),
140 ('target_arch', 'arm', 'cpu_arch="arm"'), 158 ('target_arch', 'arm', 'cpu_arch="arm"'),
141 ('target_arch', 'mipsel', 'cpu_arch="mipsel"'), 159 ('target_arch', 'mipsel', 'cpu_arch="mipsel"'),
142 ('fastbuild', '0', 'symbol_level=2'), 160 ('fastbuild', '0', 'symbol_level=2'),
143 ('fastbuild', '1', 'symbol_level=1'), 161 ('fastbuild', '1', 'symbol_level=1'),
144 ('fastbuild', '2', 'symbol_level=0'), 162 ('fastbuild', '2', 'symbol_level=0'),
145 ('OS', 'ios', 'os="ios"'), 163 ('OS', 'ios', 'os="ios"'),
146 ('OS', 'android', 'os="android"'), 164 ('OS', 'android', 'os="android"'),
147 ('chromeos', '1', 'os="chromeos"'), 165 ('chromeos', '1', 'os="chromeos"'),
148 ('use_aura', '1', 'use_aura=true'), 166 ('use_aura', '1', 'use_aura=true'),
167 ('use_goma', '1', 'use_goma=true'),
149 ('asan', '1', 'is_asan=true'), 168 ('asan', '1', 'is_asan=true'),
150 ('lsan', '1', 'is_lsan=true'), 169 ('lsan', '1', 'is_lsan=true'),
151 ] 170 ]
152 for i in remap_cases: 171 for i in remap_cases:
153 if i[0] in vars_dict and vars_dict[i[0]] == i[1]: 172 if i[0] in vars_dict and vars_dict[i[0]] == i[1]:
154 gn_args += ' ' + i[2] 173 gn_args += ' ' + i[2]
155 174
156 # These string arguments get passed directly. 175 # These string arguments get passed directly.
157 for v in ['windows_sdk_path']: 176 for v in ['windows_sdk_path']:
158 if v in vars_dict: 177 if v in vars_dict:
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 # to enfore syntax checking. 358 # to enfore syntax checking.
340 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') 359 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
341 if syntax_check and int(syntax_check): 360 if syntax_check and int(syntax_check):
342 args.append('--check') 361 args.append('--check')
343 362
344 print 'Updating projects from gyp files...' 363 print 'Updating projects from gyp files...'
345 sys.stdout.flush() 364 sys.stdout.flush()
346 365
347 # Off we go... 366 # Off we go...
348 sys.exit(gyp.main(args)) 367 sys.exit(gyp.main(args))
OLDNEW
« no previous file with comments | « no previous file | build/toolchain/win/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698