File: gnrt_stdlib.py

package info (click to toggle)
chromium 145.0.7632.109-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,974,804 kB
  • sloc: cpp: 36,197,696; ansic: 7,602,761; javascript: 3,563,590; python: 1,649,324; xml: 838,427; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,022; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (67 lines) | stat: -rwxr-xr-x 2,140 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python3
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
'''Builds the gnrt tool and runs it to generate stdlib GN rules.
'''

import argparse
import os
import sys
import tempfile

# Get variables and helpers from Clang update script.
sys.path.append(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'clang',
                 'scripts'))
from build import (RunCommand)
from update import (CHROMIUM_DIR)

sys.path.append(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'crates'))
from run_gnrt import RunGnrt

from build_bindgen import (EXE)
from build_rust import (RustTargetTriple, RUST_SRC_DIR, RUST_BETA_SYSROOT_DIR,
                        InstallRustBetaSysroot)
from update_rust import (RUST_REVISION)

BUILD_RUST_PY_PATH = os.path.join(CHROMIUM_DIR, 'tools', 'rust',
                                  'build_rust.py')

def main():
    parser = argparse.ArgumentParser(
        description='build and run gnrt for stdlib')
    parser.add_argument(
        '--skip-prep',
        action='store_true',
        help='do not fetch dependencies, assuming a previous successful run.')
    parser.add_argument(
        '--out-dir',
        help='cache artifacts in specified directory instead of a temp dir.')
    args = parser.parse_args()

    if not args.skip_prep:
        # This step gets the dependencies in the Rust git checkout.
        RunCommand([BUILD_RUST_PY_PATH, '--sync-for-gnrt'])

        # Get a Rust sysroot to build gnrt with.
        InstallRustBetaSysroot(RUST_REVISION, [RustTargetTriple()])

    # Build and run gnrt to update the stdlib GN rules.
    if args.out_dir:
        run_gnrt(RUST_BETA_SYSROOT_DIR, args.out_dir)
    else:
        with tempfile.TemporaryDirectory() as out_dir:
            run_gnrt(RUST_BETA_SYSROOT_DIR, out_dir)


def run_gnrt(sysroot_dir, out_dir):
    gnrt_args = [
        'gen', f'--for-std={os.path.relpath(RUST_SRC_DIR, CHROMIUM_DIR)}'
    ]
    RunGnrt(sysroot_dir, out_dir, gnrt_args)


if __name__ == '__main__':
    sys.exit(main())