summaryrefslogtreecommitdiffstats
path: root/chromium/tools/crates/crates.py
blob: 317cf7d3ed60f4f3a8b213506802b5f0fa096fc7 (plain)
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
#!/usr/bin/env vpython3
# Copyright 2021 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.

# BUG: How do we get link-cplusplus to link libc++ into its crate? It generates
# from its build.rs `cargo:rustc-link-lib=c++` which we could handle, and then
# do nothing here. Or we can add a flag to third_party.toml to have us add
# libc++ (via a dummy c++ source set) as a dependency of link-cplusplus.

from __future__ import annotations

import argparse
import sys

from lib import download
from lib import gen

parser = argparse.ArgumentParser(description="Third-party Rust crate tools.")
subparsers = parser.add_subparsers()

download_parser = subparsers.add_parser("download")
download_parser.add_argument(
    "crate_name", help="The crate name to be downloaded from crates.io")
download_parser.add_argument(
    "crate_version",
    help=("The version of the crate to be downloaded from crates.io. " +
          "Usually just the major version number, such as '1'"))
download_parser.add_argument(
    "--security-critical",
    required=True,
    choices=["yes", "no"],
    help="Whether the crate is considered to be security critical")
download_parser.add_argument(
    "--license",
    type=str,
    help=("The license of the crate, if an approved license can't be found " +
          "automatically"))
download_parser.add_argument("--verbose",
                             action="store_true",
                             help="Used for debugging of this tool.")
download_parser.set_defaults(func=download.run)

gen_parser = subparsers.add_parser("gen")
gen_parser.add_argument(
    "--target",
    help=("The single target to generate BUILD.gn files for, from " +
          "'rustc --print=target-list'. When not specified, the BUILD.gn " +
          "files are generated for all Chromium targets. Used for faster " +
          "debugging of this tool."))
gen_parser.add_argument("--verbose",
                        action="store_true",
                        help="Used for debugging of this tool.")
gen_parser.add_argument(
    "--with-tests",
    action="store_true",
    help="Whether to generate build rules for crate unit tests.")
gen_parser.set_defaults(func=gen.run)

args = parser.parse_args()
if "func" not in args:
    parser.print_usage()
else:
    args.func(args)