File: bootstrap.py

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (91 lines) | stat: -rwxr-xr-x 3,241 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file isn't officially supported by the Chromium project. It's maintained
# on a best-effort basis by volunteers, so some things may be broken from time
# to time. If you encounter errors, it's most often due to files in base that
# have been added or moved since somebody last tried this script. Generally
# such errors are easy to diagnose.
"""Builds gn and generates Chromium's build files.

This script should only be run from a Chromium tarball.  It will not work in a
regular git checkout.  In a regular git checkout, a gn binary is pulled via
DEPS.  To build gn from source in a regular checkout, see
https://gn.googlesource.com/gn/
"""

# This script may be removed if/when gn becomes available in the standard
# repositories for several mainstream Linux distributions.

import optparse
import os
import shutil
import subprocess
import sys

BOOTSTRAP_DIR = os.path.dirname(os.path.abspath(__file__))
GN_ROOT = os.path.dirname(BOOTSTRAP_DIR)
SRC_ROOT = os.path.dirname(os.path.dirname(GN_ROOT))


def main(argv):
  parser = optparse.OptionParser(description=sys.modules[__name__].__doc__)
  parser.add_option(
      '-d',
      '--debug',
      action='store_true',
      help='Do a debug build. Defaults to release build.')
  parser.add_option(
      '-o', '--output', help='place output in PATH', metavar='PATH')
  parser.add_option('-s', '--no-rebuild', help='ignored')
  parser.add_option('--no-clean', help='ignored')
  parser.add_option('--gn-gen-args', help='Args to pass to gn gen --args')
  parser.add_option(
      '--build-path',
      help='The directory in which to build gn, '
      'relative to the src directory. (eg. out/Release)')
  parser.add_option(
      '--with-sysroot',
      action='store_true',
      help='Download and build with the Debian sysroot.')
  parser.add_option('-v', '--verbose', help='ignored')
  parser.add_option('-j', '--jobs', help='Number of jobs')
  options, args = parser.parse_args(argv)
  if args:
    parser.error('Unrecognized command line arguments: %s.' % ', '.join(args))

  if options.build_path:
    build_rel = options.build_path
  elif options.debug:
    build_rel = os.path.join('out', 'Debug')
  else:
    build_rel = os.path.join('out', 'Release')
  out_dir = os.path.join(SRC_ROOT, build_rel)
  gn_path = options.output or os.path.join(out_dir, 'gn')
  gn_build_dir = os.path.join(out_dir, 'gn_build')

  cmd = [
      sys.executable,
      os.path.join(GN_ROOT, 'build', 'gen.py'),
      '--no-last-commit-position',
      '--out-path=' + gn_build_dir,
  ]
  if options.debug:
    cmd.append('--debug')
  subprocess.check_call(cmd)

  shutil.copy2(
      os.path.join(BOOTSTRAP_DIR, 'last_commit_position.h'), gn_build_dir)
  if options.jobs:
    subprocess.check_call(
        ['ninja', '-C', gn_build_dir, 'gn', '-w', 'dupbuild=err', '-j'+str(options.jobs)])
  else:
    subprocess.check_call(
        ['ninja', '-C', gn_build_dir, 'gn', '-w', 'dupbuild=err'])
  shutil.copy2(os.path.join(gn_build_dir, 'gn'), gn_path)


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))