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