aboutsummaryrefslogtreecommitdiff
path: root/servers/build_tools.py
blob: 9dbe28e8ba01c01c0e85f99a3e21e26c76e21728 (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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
#
# Copyright 2018 - The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the',  help="License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an',  help="AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import argparse
import logging
import multiprocessing
import os
import platform
import sys

from server_config import ServerConfig

from utils import (
    PYTHON_EXE,
    AOSP_ROOT,
    is_presubmit,
    run,
    log_system_info,
    config_logging,
)


def main(argv):
    config_logging()
    log_system_info()

    # We don't want to be too aggressive with concurrency.
    test_cpu_count = int(multiprocessing.cpu_count() / 4)

    # The build bots tend to be overloaded, so we want to restrict
    # cpu usage to prevent strange timeout issues we have seen in the past.
    # We can increment this once we are building on our own controlled macs
    if platform.system() == "Darwin":
        test_cpu_count = 2

    parser = argparse.ArgumentParser(
        description="Configures the android emulator cmake project so it can be build"
    )
    parser.add_argument(
        "--out_dir", type=str, required=True, help="The output directory"
    )
    parser.add_argument(
        "--dist_dir", type=str, required=True, help="The destination directory"
    )
    parser.add_argument(
        "--build-id",
        type=str,
        default=[],
        required=True,
        dest="build_id",
        help="The emulator build number",
    )
    parser.add_argument(
        "--test_jobs",
        type=int,
        default=test_cpu_count,
        dest="test_jobs",
        help="Specifies  the number of tests to run simultaneously",
    )
    parser.add_argument(
        "--target",
        type=str,
        default=platform.system(),
        help="The build target, defaults to current os",
    )
    parser.add_argument(
        "--qtwebengine",
        action="store_true",
        help="Build emulator with QtWebEngine libraries",
    )
    parser.add_argument(
        "--gfxstream",
        action="store_true",
        help="Build the emulator with the gfxstream libraries",
    )
    parser.add_argument(
        "--enable_system_rust",
        action="store_true",
        help="Build the emulator with the System Rust on the host machine",
    )
    parser.add_argument(
        "--gfxstream_only", action="store_true", help="Build gfxstream libraries only"
    )
    parser.add_argument("--crosvm", action="store_true", help="Build crosvm")
    parser.add_argument(
        "--generate", action="store_true", help="Generate and replaceqemu files only."
    )
    parser.add_argument(
        "--with_debug", action="store_true", help="Build debug instead of release"
    )

    args = parser.parse_args()

    os.environ["GIT_DISCOVERY_ACROSS_FILESYSTEM"] = "1"

    target = platform.system().lower()

    if args.target:
        target = args.target.lower()

    if not os.path.isabs(args.out_dir):
        args.out_dir = os.path.join(AOSP_ROOT, args.out_dir)

    # This how we are going to launch the python build script
    launcher = [
        PYTHON_EXE,
        os.path.join(
            AOSP_ROOT, "external", "qemu", "android", "build", "python", "cmake.py"
        ),
    ]

    gfxstream_arg = "--gfxstream"
    crosvm_arg = "--crosvm"

    cmd = [
        "--out",
        args.out_dir,
        "--sdk_build_number",
        args.build_id,
        "--target",
        target,
        "--dist",
        args.dist_dir,
        "--test_jobs",
        str(args.test_jobs),
    ]

    # Standard arguments for both debug & production.
    if args.qtwebengine:
        cmd.append("--qtwebengine")
    if args.gfxstream_only:
        cmd.append("--gfxstream_only")
    if args.gfxstream:
        cmd.append(gfxstream_arg)
    if args.crosvm:
        cmd.append(crosvm_arg)
    if args.enable_system_rust:
        cmd = cmd + ["--feature", "enable_system_rust"]
    if args.with_debug:
        cmd = cmd + ["--config", "debug"]

    # Make sure the dist directory exists.
    os.makedirs(args.dist_dir, exist_ok=True)

    # Kick of builds for 2 targets. (debug/release)
    presubmit = is_presubmit(args.build_id)

    if presubmit:
        logging.info("Not uploading symbols for presubmit builds.")
    else:
        cmd = cmd + ["--crash", "prod"]

    with ServerConfig(presubmit, args) as cfg:
        if not target == "windows":
            # sccache does not (yet?) make life better on windows in gce.
            cmd = cmd + ["--ccache", cfg.sccache]

        run(launcher + cmd, cfg.get_env(), "bld")

        # Let's run the e2e tests.
        if (presubmit  # We disable the IntegrationTests due to stability issues.
            and target == "linux"
            and not args.gfxstream_only
        ):
            run(launcher + cmd + ["--task", "IntegrationTest"], cfg.get_env(), "tst")

    logging.info("Build completed!")


if __name__ == "__main__":
    try:
        main(sys.argv)
        sys.exit(0)
    except (Exception, KeyboardInterrupt) as exc:
        sys.exit(exc)