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

Side by Side Diff: tools/gn/bootstrap/bootstrap.py

Issue 2064513002: GN: Add Windows support to bootstrap.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « AUTHORS ('k') | tools/gn/bootstrap/build.ninja.template » ('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 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # This file isn't officially supported by the Chromium project. It's maintained 6 # This file isn't officially supported by the Chromium project. It's maintained
7 # on a best-effort basis by volunteers, so some things may be broken from time 7 # on a best-effort basis by volunteers, so some things may be broken from time
8 # to time. If you encounter errors, it's most often due to files in base that 8 # to time. If you encounter errors, it's most often due to files in base that
9 # have been added or moved since somebody last tried this script. Generally 9 # have been added or moved since somebody last tried this script. Generally
10 # such errors are easy to diagnose. 10 # such errors are easy to diagnose.
(...skipping 11 matching lines...) Expand all
22 import os 22 import os
23 import shutil 23 import shutil
24 import subprocess 24 import subprocess
25 import sys 25 import sys
26 import tempfile 26 import tempfile
27 27
28 BOOTSTRAP_DIR = os.path.dirname(os.path.abspath(__file__)) 28 BOOTSTRAP_DIR = os.path.dirname(os.path.abspath(__file__))
29 GN_ROOT = os.path.dirname(BOOTSTRAP_DIR) 29 GN_ROOT = os.path.dirname(BOOTSTRAP_DIR)
30 SRC_ROOT = os.path.dirname(os.path.dirname(GN_ROOT)) 30 SRC_ROOT = os.path.dirname(os.path.dirname(GN_ROOT))
31 31
32 is_win = sys.platform.startswith('win')
32 is_linux = sys.platform.startswith('linux') 33 is_linux = sys.platform.startswith('linux')
33 is_mac = sys.platform.startswith('darwin') 34 is_mac = sys.platform.startswith('darwin')
34 is_posix = is_linux or is_mac 35 is_posix = is_linux or is_mac
35 36
36 def check_call(cmd, **kwargs): 37 def check_call(cmd, **kwargs):
37 logging.debug('Running: %s', ' '.join(cmd)) 38 logging.debug('Running: %s', ' '.join(cmd))
39 if cmd and cmd[0].endswith('.py'):
40 cmd.insert(0, sys.executable)
38 subprocess.check_call(cmd, cwd=GN_ROOT, **kwargs) 41 subprocess.check_call(cmd, cwd=GN_ROOT, **kwargs)
39 42
40 def mkdir_p(path): 43 def mkdir_p(path):
41 try: 44 try:
42 os.makedirs(path) 45 os.makedirs(path)
43 except OSError as e: 46 except OSError as e:
44 if e.errno == errno.EEXIST and os.path.isdir(path): 47 if e.errno == errno.EEXIST and os.path.isdir(path):
45 pass 48 pass
46 else: raise 49 else: raise
47 50
(...skipping 11 matching lines...) Expand all
59 build_rel = os.path.join('out', 'Debug') 62 build_rel = os.path.join('out', 'Debug')
60 else: 63 else:
61 build_rel = os.path.join('out', 'Release') 64 build_rel = os.path.join('out', 'Release')
62 build_root = os.path.join(SRC_ROOT, build_rel) 65 build_root = os.path.join(SRC_ROOT, build_rel)
63 66
64 print 'Building gn manually in a temporary directory for bootstrapping...' 67 print 'Building gn manually in a temporary directory for bootstrapping...'
65 build_gn_with_ninja_manually(tempdir, options) 68 build_gn_with_ninja_manually(tempdir, options)
66 temp_gn = os.path.join(tempdir, 'gn') 69 temp_gn = os.path.join(tempdir, 'gn')
67 out_gn = os.path.join(build_root, 'gn') 70 out_gn = os.path.join(build_root, 'gn')
68 71
72 if is_win:
73 temp_gn += '.exe'
74 out_gn += '.exe'
75
69 if options.no_rebuild: 76 if options.no_rebuild:
70 mkdir_p(build_root) 77 mkdir_p(build_root)
71 shutil.copy2(temp_gn, out_gn) 78 shutil.copy2(temp_gn, out_gn)
72 else: 79 else:
73 print 'Building gn using itself to %s...' % build_rel 80 print 'Building gn using itself to %s...' % build_rel
74 build_gn_with_gn(temp_gn, build_root, options) 81 build_gn_with_gn(temp_gn, build_root, options)
75 82
76 if options.output: 83 if options.output:
77 # Preserve the executable permission bit. 84 # Preserve the executable permission bit.
78 shutil.copy2(out_gn, options.output) 85 shutil.copy2(out_gn, options.output)
(...skipping 27 matching lines...) Expand all
106 os.makedirs(build_dir) 113 os.makedirs(build_dir)
107 return run_build(build_dir, options) 114 return run_build(build_dir, options)
108 else: 115 else:
109 with scoped_tempdir() as tempdir: 116 with scoped_tempdir() as tempdir:
110 return run_build(tempdir, options) 117 return run_build(tempdir, options)
111 except subprocess.CalledProcessError as e: 118 except subprocess.CalledProcessError as e:
112 print >> sys.stderr, str(e) 119 print >> sys.stderr, str(e)
113 return 1 120 return 1
114 return 0 121 return 0
115 122
123 def write_compiled_message(root_gen_dir, source):
124 path = os.path.join(root_gen_dir, os.path.dirname(source))
125 mkdir_p(path)
126 check_call([
127 'mc.exe',
128 '-r', path, '-h', path,
129 '-u', '-um',
130 os.path.join(SRC_ROOT, source),
131 ])
116 132
117 def write_buildflag_header_manually(root_gen_dir, header, flags): 133 def write_buildflag_header_manually(root_gen_dir, header, flags):
118 mkdir_p(os.path.join(root_gen_dir, os.path.dirname(header))) 134 mkdir_p(os.path.join(root_gen_dir, os.path.dirname(header)))
119 with tempfile.NamedTemporaryFile() as f: 135
136 temp_path = os.path.join(root_gen_dir, header + '.tmp')
brettw 2016/06/13 18:19:43 I don't understand this change. Was the tempfile p
timn 2016/06/13 18:56:30 It "works", but not for our use case here. write_
137 with open(temp_path, 'w') as f:
120 f.write('--flags') 138 f.write('--flags')
121 for name,value in flags.items(): 139 for name,value in flags.items():
122 f.write(' ' + name + '=' + value) 140 f.write(' ' + name + '=' + value)
123 f.flush()
124 141
125 check_call([ 142 check_call([
126 os.path.join(SRC_ROOT, 'build', 'write_buildflag_header.py'), 143 os.path.join(SRC_ROOT, 'build', 'write_buildflag_header.py'),
127 '--output', header, 144 '--output', header,
128 '--gen-dir', root_gen_dir, 145 '--gen-dir', root_gen_dir,
129 '--definitions', f.name, 146 '--definitions', temp_path,
130 ]) 147 ])
131 148
149 os.remove(temp_path)
132 150
133 def build_gn_with_ninja_manually(tempdir, options): 151 def build_gn_with_ninja_manually(tempdir, options):
134 root_gen_dir = os.path.join(tempdir, 'gen') 152 root_gen_dir = os.path.join(tempdir, 'gen')
135 mkdir_p(root_gen_dir) 153 mkdir_p(root_gen_dir)
136 154
137 write_buildflag_header_manually(root_gen_dir, 'base/allocator/features.h', 155 write_buildflag_header_manually(root_gen_dir, 'base/allocator/features.h',
138 {'USE_EXPERIMENTAL_ALLOCATOR_SHIM': 'true' if is_linux else 'false'}) 156 {'USE_EXPERIMENTAL_ALLOCATOR_SHIM': 'true' if is_linux else 'false'})
139 157
140 write_buildflag_header_manually(root_gen_dir, 'base/debug/debugging_flags.h', 158 write_buildflag_header_manually(root_gen_dir, 'base/debug/debugging_flags.h',
141 {'ENABLE_PROFILING': 'false'}) 159 {'ENABLE_PROFILING': 'false'})
142 160
143 if is_mac: 161 if is_mac:
144 # //base/build_time.cc needs base/generated_build_date.h, 162 # //base/build_time.cc needs base/generated_build_date.h,
145 # and this file is only included for Mac builds. 163 # and this file is only included for Mac builds.
146 mkdir_p(os.path.join(root_gen_dir, 'base')) 164 mkdir_p(os.path.join(root_gen_dir, 'base'))
147 check_call([ 165 check_call([
148 os.path.join(SRC_ROOT, 'build', 'write_build_date_header.py'), 166 os.path.join(SRC_ROOT, 'build', 'write_build_date_header.py'),
149 os.path.join(root_gen_dir, 'base', 'generated_build_date.h'), 167 os.path.join(root_gen_dir, 'base', 'generated_build_date.h'),
150 'default' 168 'default'
151 ]) 169 ])
152 170
153 write_ninja(os.path.join(tempdir, 'build.ninja'), root_gen_dir, options) 171 if is_win:
172 write_buildflag_header_manually(root_gen_dir, 'base/win/base_features.h',
173 {'SINGLE_MODULE_MODE_HANDLE_VERIFIER': 'true'})
174
175 write_compiled_message(root_gen_dir,
176 'base/trace_event/etw_manifest/chrome_events_win.man')
177
178 write_gn_ninja(os.path.join(tempdir, 'build.ninja'),
179 root_gen_dir, options)
154 cmd = ['ninja', '-C', tempdir] 180 cmd = ['ninja', '-C', tempdir]
155 if options.verbose: 181 if options.verbose:
156 cmd.append('-v') 182 cmd.append('-v')
157 cmd.append('gn') 183
184 if is_win:
185 cmd.append('gn.exe')
186 else:
187 cmd.append('gn')
188
158 check_call(cmd) 189 check_call(cmd)
159 190
160 def write_ninja(path, root_gen_dir, options): 191 def write_ninja(path, static_libraries, executables,
161 cc = os.environ.get('CC', '') 192 cc, cxx, ar, ld,
162 cxx = os.environ.get('CXX', '') 193 cflags=[], cflags_cc=[], ldflags=[],
194 include_dirs=[], solibs=[]):
195 ninja_header_lines = [
196 'cc = ' + cc,
197 'cxx = ' + cxx,
198 'ar = ' + ar,
199 'ld = ' + ld,
200 '',
201 ]
202
203 if is_win:
204 template_filename = 'build_vs.ninja.template'
205 elif is_mac:
206 template_filename = 'build_mac.ninja.template'
207 else:
208 template_filename = 'build.ninja.template'
209
210 with open(os.path.join(GN_ROOT, 'bootstrap', template_filename)) as f:
211 ninja_template = f.read()
212
213 if is_win:
214 executable_ext = '.exe'
215 library_ext = '.lib'
216 object_ext = '.obj'
217 else:
218 executable_ext = ''
219 library_ext = '.a'
220 object_ext = '.o'
221
222 def escape_path_ninja(path):
223 return path.replace('$ ', '$$ ').replace(' ', '$ ').replace(':', '$:')
224
225 def src_to_obj(path):
226 return escape_path_ninja('%s' % os.path.splitext(path)[0] + object_ext)
227
228 def library_to_a(library):
229 return '%s%s' % (library, library_ext)
230
231 ninja_lines = []
232 def build_source(src_file, settings):
233 ninja_lines.extend([
234 'build %s: %s %s' % (src_to_obj(src_file),
235 settings['tool'],
236 escape_path_ninja(
237 os.path.join(SRC_ROOT, src_file))),
238 ' includes = %s' % ' '.join(
239 ['-I' + escape_path_ninja(dirname) for dirname in
240 include_dirs + settings.get('include_dirs', [])]),
241 ' cflags = %s' % ' '.join(cflags + settings.get('cflags', [])),
242 ' cflags_cc = %s' %
243 ' '.join(cflags_cc + settings.get('cflags_cc', [])),
244 ])
245
246 for library, settings in static_libraries.iteritems():
247 for src_file in settings['sources']:
248 build_source(src_file, settings)
249
250 ninja_lines.append('build %s: alink_thin %s' % (
251 library_to_a(library),
252 ' '.join([src_to_obj(src_file) for src_file in settings['sources']])))
253
254 for executable, settings in executables.iteritems():
255 for src_file in settings['sources']:
256 build_source(src_file, settings)
257
258 ninja_lines.extend([
259 'build %s%s: link %s | %s' % (
260 executable, executable_ext,
261 ' '.join([src_to_obj(src_file) for src_file in settings['sources']]),
262 ' '.join([library_to_a(library) for library in settings['libs']])),
263 ' ldflags = %s' % ' '.join(ldflags),
264 ' solibs = %s' % ' '.join(solibs),
265 ' libs = %s' % ' '.join(
266 [library_to_a(library) for library in settings['libs']]),
267 ])
268
269 ninja_lines.append('') # Make sure the file ends with a newline.
270
271 with open(path, 'w') as f:
272 f.write('\n'.join(ninja_header_lines))
273 f.write(ninja_template)
274 f.write('\n'.join(ninja_lines))
275
276 def write_gn_ninja(path, root_gen_dir, options):
brettw 2016/06/13 18:19:43 I don't understand the new distinction you're maki
timn 2016/06/13 18:56:30 write_ninja is just a helper method that does the
277 if is_win:
278 cc = os.environ.get('CC', 'cl.exe')
279 cxx = os.environ.get('CXX', 'cl.exe')
280 ld = os.environ.get('LD', 'link.exe')
281 ar = os.environ.get('AR', 'lib.exe')
282 else:
283 cc = os.environ.get('CC', 'cc')
284 cxx = os.environ.get('CXX', 'c++')
285 ld = os.environ.get('LD', cxx)
286 ar = os.environ.get('AR', 'ar')
287
163 cflags = os.environ.get('CFLAGS', '').split() 288 cflags = os.environ.get('CFLAGS', '').split()
164 cflags_cc = os.environ.get('CXXFLAGS', '').split() 289 cflags_cc = os.environ.get('CXXFLAGS', '').split()
165 ld = os.environ.get('LD', cxx)
166 ldflags = os.environ.get('LDFLAGS', '').split() 290 ldflags = os.environ.get('LDFLAGS', '').split()
167 include_dirs = [root_gen_dir, SRC_ROOT] 291 include_dirs = [root_gen_dir, SRC_ROOT]
168 libs = [] 292 libs = []
169 293
170 # //base/allocator/allocator_extension.cc needs this macro defined, 294 # //base/allocator/allocator_extension.cc needs this macro defined,
171 # otherwise there would be link errors. 295 # otherwise there would be link errors.
172 cflags.extend(['-DNO_TCMALLOC']) 296 cflags.extend(['-DNO_TCMALLOC'])
173 297
174 if is_posix: 298 if is_posix:
175 if options.debug: 299 if options.debug:
176 cflags.extend(['-O0', '-g']) 300 cflags.extend(['-O0', '-g'])
177 else: 301 else:
178 cflags.extend(['-O2', '-g0']) 302 cflags.extend(['-O2', '-g0'])
179 303
180 cflags.extend([ 304 cflags.extend([
181 '-D_FILE_OFFSET_BITS=64', 305 '-D_FILE_OFFSET_BITS=64',
306 '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS',
182 '-pthread', 307 '-pthread',
183 '-pipe', 308 '-pipe',
184 '-fno-exceptions' 309 '-fno-exceptions'
185 ]) 310 ])
186 cflags_cc.extend(['-std=c++11', '-Wno-c++11-narrowing']) 311 cflags_cc.extend(['-std=c++11', '-Wno-c++11-narrowing'])
312 elif is_win:
313 if not options.debug:
314 cflags.extend(['/Ox', '/DNDEBUG', '/GL'])
315 ldflags.extend(['/LTCG', '/OPT:REF', '/OPT:ICF'])
316
317 cflags.extend([
318 '/FS',
319 '/Gy',
320 '/W3', '/wd4244',
321 '/Zi',
322 '/DWIN32_LEAN_AND_MEAN', '/DNOMINMAX',
323 '/D_CRT_SECURE_NO_DEPRECATE', '/D_SCL_SECURE_NO_DEPRECATE',
324 '/D_WIN32_WINNT=0x0A00', '/DWINVER=0x0A00',
325 '/DUNICODE', '/D_UNICODE',
326 ])
327 cflags_cc.extend([
328 '/GR-',
329 '/D_HAS_EXCEPTIONS=0',
330 ])
331 # TODO(tim): Support for 64bit builds?
332 ldflags.extend(['/MACHINE:x86', '/DEBUG'])
187 333
188 static_libraries = { 334 static_libraries = {
189 'base': {'sources': [], 'tool': 'cxx', 'include_dirs': []}, 335 'base': {'sources': [], 'tool': 'cxx', 'include_dirs': []},
190 'dynamic_annotations': {'sources': [], 'tool': 'cc', 'include_dirs': []}, 336 'dynamic_annotations': {'sources': [], 'tool': 'cc', 'include_dirs': []},
191 'gn': {'sources': [], 'tool': 'cxx', 'include_dirs': []}, 337 'gn_lib': {'sources': [], 'tool': 'cxx', 'include_dirs': []},
338 }
339
340 executables = {
341 'gn': {'sources': ['tools/gn/gn_main.cc'],
342 'tool': 'cxx', 'include_dirs': [], 'libs': []},
192 } 343 }
193 344
194 for name in os.listdir(GN_ROOT): 345 for name in os.listdir(GN_ROOT):
195 if not name.endswith('.cc'): 346 if not name.endswith('.cc'):
196 continue 347 continue
197 if name.endswith('_unittest.cc'): 348 if name.endswith('_unittest.cc'):
198 continue 349 continue
199 if name == 'run_all_unittests.cc': 350 if name == 'run_all_unittests.cc':
200 continue 351 continue
352 if name == 'gn_main.cc':
353 continue
201 full_path = os.path.join(GN_ROOT, name) 354 full_path = os.path.join(GN_ROOT, name)
202 static_libraries['gn']['sources'].append( 355 static_libraries['gn_lib']['sources'].append(
203 os.path.relpath(full_path, SRC_ROOT)) 356 os.path.relpath(full_path, SRC_ROOT))
204 357
205 static_libraries['dynamic_annotations']['sources'].extend([ 358 static_libraries['dynamic_annotations']['sources'].extend([
206 'base/third_party/dynamic_annotations/dynamic_annotations.c', 359 'base/third_party/dynamic_annotations/dynamic_annotations.c',
207 'base/third_party/superfasthash/superfasthash.c', 360 'base/third_party/superfasthash/superfasthash.c',
208 ]) 361 ])
209 static_libraries['base']['sources'].extend([ 362 static_libraries['base']['sources'].extend([
210 'base/allocator/allocator_check.cc', 363 'base/allocator/allocator_check.cc',
211 'base/allocator/allocator_extension.cc', 364 'base/allocator/allocator_extension.cc',
212 'base/at_exit.cc', 365 'base/at_exit.cc',
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 'base/process/process_iterator.cc', 418 'base/process/process_iterator.cc',
266 'base/process/process_metrics.cc', 419 'base/process/process_metrics.cc',
267 'base/profiler/scoped_profile.cc', 420 'base/profiler/scoped_profile.cc',
268 'base/profiler/scoped_tracker.cc', 421 'base/profiler/scoped_tracker.cc',
269 'base/profiler/tracked_time.cc', 422 'base/profiler/tracked_time.cc',
270 'base/run_loop.cc', 423 'base/run_loop.cc',
271 'base/sequence_checker_impl.cc', 424 'base/sequence_checker_impl.cc',
272 'base/sequenced_task_runner.cc', 425 'base/sequenced_task_runner.cc',
273 'base/sha1.cc', 426 'base/sha1.cc',
274 'base/strings/pattern.cc', 427 'base/strings/pattern.cc',
275 'base/strings/string16.cc',
276 'base/strings/string_number_conversions.cc', 428 'base/strings/string_number_conversions.cc',
277 'base/strings/string_piece.cc', 429 'base/strings/string_piece.cc',
278 'base/strings/string_split.cc', 430 'base/strings/string_split.cc',
279 'base/strings/string_util.cc', 431 'base/strings/string_util.cc',
280 'base/strings/string_util_constants.cc', 432 'base/strings/string_util_constants.cc',
281 'base/strings/stringprintf.cc', 433 'base/strings/stringprintf.cc',
282 'base/strings/utf_string_conversion_utils.cc', 434 'base/strings/utf_string_conversion_utils.cc',
283 'base/strings/utf_string_conversions.cc', 435 'base/strings/utf_string_conversions.cc',
284 'base/synchronization/cancellation_flag.cc', 436 'base/synchronization/cancellation_flag.cc',
285 'base/synchronization/lock.cc', 437 'base/synchronization/lock.cc',
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 'base/files/file_posix.cc', 497 'base/files/file_posix.cc',
346 'base/files/file_util_posix.cc', 498 'base/files/file_util_posix.cc',
347 'base/files/memory_mapped_file_posix.cc', 499 'base/files/memory_mapped_file_posix.cc',
348 'base/message_loop/message_pump_libevent.cc', 500 'base/message_loop/message_pump_libevent.cc',
349 'base/posix/file_descriptor_shuffle.cc', 501 'base/posix/file_descriptor_shuffle.cc',
350 'base/posix/safe_strerror.cc', 502 'base/posix/safe_strerror.cc',
351 'base/process/kill_posix.cc', 503 'base/process/kill_posix.cc',
352 'base/process/process_handle_posix.cc', 504 'base/process/process_handle_posix.cc',
353 'base/process/process_metrics_posix.cc', 505 'base/process/process_metrics_posix.cc',
354 'base/process/process_posix.cc', 506 'base/process/process_posix.cc',
507 'base/strings/string16.cc',
355 'base/synchronization/condition_variable_posix.cc', 508 'base/synchronization/condition_variable_posix.cc',
356 'base/synchronization/lock_impl_posix.cc', 509 'base/synchronization/lock_impl_posix.cc',
357 'base/synchronization/read_write_lock_posix.cc', 510 'base/synchronization/read_write_lock_posix.cc',
358 'base/synchronization/waitable_event_posix.cc', 511 'base/synchronization/waitable_event_posix.cc',
359 'base/sys_info_posix.cc', 512 'base/sys_info_posix.cc',
360 'base/threading/platform_thread_internal_posix.cc', 513 'base/threading/platform_thread_internal_posix.cc',
361 'base/threading/platform_thread_posix.cc', 514 'base/threading/platform_thread_posix.cc',
362 'base/threading/thread_local_posix.cc', 515 'base/threading/thread_local_posix.cc',
363 'base/threading/thread_local_storage_posix.cc', 516 'base/threading/thread_local_storage_posix.cc',
364 'base/threading/worker_pool_posix.cc', 517 'base/threading/worker_pool_posix.cc',
(...skipping 14 matching lines...) Expand all
379 'base/third_party/libevent/poll.c', 532 'base/third_party/libevent/poll.c',
380 'base/third_party/libevent/select.c', 533 'base/third_party/libevent/select.c',
381 'base/third_party/libevent/signal.c', 534 'base/third_party/libevent/signal.c',
382 'base/third_party/libevent/strlcpy.c', 535 'base/third_party/libevent/strlcpy.c',
383 ], 536 ],
384 'tool': 'cc', 537 'tool': 'cc',
385 'include_dirs': [], 538 'include_dirs': [],
386 'cflags': cflags + ['-DHAVE_CONFIG_H'], 539 'cflags': cflags + ['-DHAVE_CONFIG_H'],
387 } 540 }
388 541
389
390 if is_linux: 542 if is_linux:
391 libs.extend(['-lrt']) 543 libs.extend(['-lrt', '-latomic'])
392 ldflags.extend(['-pthread']) 544 ldflags.extend(['-pthread'])
393 545
394 static_libraries['xdg_user_dirs'] = { 546 static_libraries['xdg_user_dirs'] = {
395 'sources': [ 547 'sources': [
396 'base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc', 548 'base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
397 ], 549 ],
398 'tool': 'cxx', 550 'tool': 'cxx',
399 } 551 }
400 static_libraries['base']['sources'].extend([ 552 static_libraries['base']['sources'].extend([
401 'base/allocator/allocator_shim.cc', 553 'base/allocator/allocator_shim.cc',
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 'base/threading/platform_thread_mac.mm', 599 'base/threading/platform_thread_mac.mm',
448 'base/trace_event/malloc_dump_provider.cc', 600 'base/trace_event/malloc_dump_provider.cc',
449 ]) 601 ])
450 static_libraries['libevent']['include_dirs'].extend([ 602 static_libraries['libevent']['include_dirs'].extend([
451 os.path.join(SRC_ROOT, 'base', 'third_party', 'libevent', 'mac') 603 os.path.join(SRC_ROOT, 'base', 'third_party', 'libevent', 'mac')
452 ]) 604 ])
453 static_libraries['libevent']['sources'].extend([ 605 static_libraries['libevent']['sources'].extend([
454 'base/third_party/libevent/kqueue.c', 606 'base/third_party/libevent/kqueue.c',
455 ]) 607 ])
456 608
457
458 if is_mac:
459 template_filename = 'build_mac.ninja.template'
460 else:
461 template_filename = 'build.ninja.template'
462
463 with open(os.path.join(GN_ROOT, 'bootstrap', template_filename)) as f:
464 ninja_template = f.read()
465
466 def src_to_obj(path):
467 return '%s' % os.path.splitext(path)[0] + '.o'
468
469 ninja_lines = []
470 for library, settings in static_libraries.iteritems():
471 for src_file in settings['sources']:
472 ninja_lines.extend([
473 'build %s: %s %s' % (src_to_obj(src_file),
474 settings['tool'],
475 os.path.join(SRC_ROOT, src_file)),
476 ' includes = %s' % ' '.join(
477 ['-I' + dirname for dirname in
478 include_dirs + settings.get('include_dirs', [])]),
479 ' cflags = %s' % ' '.join(cflags + settings.get('cflags', [])),
480 ' cflags_cc = %s' %
481 ' '.join(cflags_cc + settings.get('cflags_cc', [])),
482 ])
483 if cc:
484 ninja_lines.append(' cc = %s' % cc)
485 if cxx:
486 ninja_lines.append(' cxx = %s' % cxx)
487
488 ninja_lines.append('build %s.a: alink_thin %s' % (
489 library,
490 ' '.join([src_to_obj(src_file) for src_file in settings['sources']])))
491
492 if is_mac:
493 libs.extend([ 609 libs.extend([
494 '-framework', 'AppKit', 610 '-framework', 'AppKit',
495 '-framework', 'CoreFoundation', 611 '-framework', 'CoreFoundation',
496 '-framework', 'Foundation', 612 '-framework', 'Foundation',
497 '-framework', 'Security', 613 '-framework', 'Security',
498 ]); 614 ])
499 615
500 ninja_lines.extend([ 616 if is_win:
501 'build gn: link %s' % ( 617 static_libraries['base']['sources'].extend([
502 ' '.join(['%s.a' % library for library in static_libraries])), 618 'base/base_paths_win.cc',
503 ' ldflags = %s' % ' '.join(ldflags), 619 'base/cpu.cc',
504 ' libs = %s' % ' '.join(libs), 620 'base/debug/close_handle_hook_win.cc',
505 ]) 621 'base/debug/debugger.cc',
506 if ld: 622 'base/debug/debugger_win.cc',
507 ninja_lines.append(' ld = %s' % ld) 623 'base/debug/profiler.cc',
508 else: 624 'base/debug/stack_trace_win.cc',
509 ninja_lines.append(' ld = $ldxx') 625 'base/file_version_info_win.cc',
626 'base/files/file_enumerator_win.cc',
627 'base/files/file_path_watcher_win.cc',
628 'base/files/file_util_win.cc',
629 'base/files/file_win.cc',
630 'base/files/memory_mapped_file_win.cc',
631 'base/logging_win.cc',
632 'base/memory/memory_pressure_monitor_win.cc',
633 'base/memory/shared_memory_handle_win.cc',
634 'base/memory/shared_memory_win.cc',
635 'base/message_loop/message_pump_win.cc',
636 'base/native_library_win.cc',
637 'base/power_monitor/power_monitor_device_source_win.cc',
638 'base/process/kill_win.cc',
639 'base/process/launch_win.cc',
640 'base/process/memory_win.cc',
641 'base/process/process_handle_win.cc',
642 'base/process/process_info_win.cc',
643 'base/process/process_iterator_win.cc',
644 'base/process/process_metrics_win.cc',
645 'base/process/process_win.cc',
646 'base/profiler/native_stack_sampler_win.cc',
647 'base/profiler/win32_stack_frame_unwinder.cc',
648 'base/rand_util.cc',
649 'base/rand_util_win.cc',
650 'base/strings/sys_string_conversions_win.cc',
651 'base/sync_socket_win.cc',
652 'base/synchronization/condition_variable_win.cc',
653 'base/synchronization/lock_impl_win.cc',
654 'base/synchronization/read_write_lock_win.cc',
655 'base/synchronization/waitable_event_watcher_win.cc',
656 'base/synchronization/waitable_event_win.cc',
657 'base/sys_info_win.cc',
658 'base/threading/platform_thread_win.cc',
659 'base/threading/thread_local_storage_win.cc',
660 'base/threading/thread_local_win.cc',
661 'base/threading/worker_pool_win.cc',
662 'base/time/time_win.cc',
663 'base/timer/hi_res_timer_manager_win.cc',
664 'base/trace_event/heap_profiler_allocation_register_win.cc',
665 'base/trace_event/trace_event_etw_export_win.cc',
666 'base/trace_event/winheap_dump_provider_win.cc',
667 'base/win/enum_variant.cc',
668 'base/win/event_trace_controller.cc',
669 'base/win/event_trace_provider.cc',
670 'base/win/i18n.cc',
671 'base/win/iat_patch_function.cc',
672 'base/win/iunknown_impl.cc',
673 'base/win/message_window.cc',
674 'base/win/object_watcher.cc',
675 'base/win/pe_image.cc',
676 'base/win/process_startup_helper.cc',
677 'base/win/registry.cc',
678 'base/win/resource_util.cc',
679 'base/win/scoped_bstr.cc',
680 'base/win/scoped_handle.cc',
681 'base/win/scoped_process_information.cc',
682 'base/win/scoped_variant.cc',
683 'base/win/shortcut.cc',
684 'base/win/startup_information.cc',
685 'base/win/wait_chain.cc',
686 'base/win/win_util.cc',
687 'base/win/windows_version.cc',
688 'base/win/wrapped_window_proc.cc',
689 ])
510 690
511 ninja_lines.append('') # Make sure the file ends with a newline. 691 libs.extend([
692 'kernel32.lib',
693 'user32.lib',
694 'shell32.lib',
695 'ole32.lib',
696 'winmm.lib',
697 'ws2_32.lib',
698 'userenv.lib',
699 'version.lib',
700 'dbghelp.lib',
701 ])
512 702
513 with open(path, 'w') as f: 703 # we just build static libraries that GN needs
514 f.write(ninja_template + '\n'.join(ninja_lines)) 704 executables['gn']['libs'].extend(static_libraries.keys())
515 705
706 write_ninja(path, static_libraries, executables, cc, cxx, ar, ld,
707 cflags, cflags_cc, ldflags, include_dirs, libs)
516 708
517 def build_gn_with_gn(temp_gn, build_dir, options): 709 def build_gn_with_gn(temp_gn, build_dir, options):
518 gn_gen_args = options.gn_gen_args or '' 710 gn_gen_args = options.gn_gen_args or ''
519 if not options.debug: 711 if not options.debug:
520 gn_gen_args += ' is_debug=false' 712 gn_gen_args += ' is_debug=false'
521 cmd = [temp_gn, 'gen', build_dir, '--args=%s' % gn_gen_args] 713 cmd = [temp_gn, 'gen', build_dir, '--args=%s' % gn_gen_args]
522 check_call(cmd) 714 check_call(cmd)
523 715
524 cmd = ['ninja', '-C', build_dir] 716 cmd = ['ninja', '-C', build_dir]
525 if options.verbose: 717 if options.verbose:
526 cmd.append('-v') 718 cmd.append('-v')
527 cmd.append('gn') 719 cmd.append('gn')
528 check_call(cmd) 720 check_call(cmd)
529 721
530 if not options.debug: 722 if not options.debug and not is_win:
531 check_call(['strip', os.path.join(build_dir, 'gn')]) 723 check_call(['strip', os.path.join(build_dir, 'gn')])
532 724
533 725
534 if __name__ == '__main__': 726 if __name__ == '__main__':
535 sys.exit(main(sys.argv[1:])) 727 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « AUTHORS ('k') | tools/gn/bootstrap/build.ninja.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698