mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Integrate autoninja.py with fast_local_dev_server.py
- Starts the build server when the build starts. - Writes tty filename to env variable. - Tells the build server about the current build so it does not exit until autoninja does, even if idle. - Cancels pending tasks on Ctrl+c. Change-Id: I86bb9852bd0975f381b049b9ff21c38eef7cef9d Bug: 370589852 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5917985 Reviewed-by: Junji Watanabe <jwata@google.com> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Reviewed-by: Fumitoshi Ukai <ukai@google.com> Auto-Submit: Mohamed Heikal <mheikal@chromium.org> Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
This commit is contained in:
2
OWNERS
2
OWNERS
@@ -20,6 +20,8 @@ per-file ninja*=dpranke@google.com
|
|||||||
per-file ninja*=thakis@chromium.org
|
per-file ninja*=thakis@chromium.org
|
||||||
per-file ninja*=file://BUILD_OWNERS
|
per-file ninja*=file://BUILD_OWNERS
|
||||||
per-file post_build_ninja_summary.py=file://BUILD_OWNERS
|
per-file post_build_ninja_summary.py=file://BUILD_OWNERS
|
||||||
|
per-file android_build_server_helper.py=mheikal@chromium.org
|
||||||
|
per-file android_build_server_helper.py=agrieve@chromium.org
|
||||||
|
|
||||||
# GN
|
# GN
|
||||||
per-file gn*=dpranke@google.com
|
per-file gn*=dpranke@google.com
|
||||||
|
|||||||
64
android_build_server_helper.py
Normal file
64
android_build_server_helper.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
# Copyright 2024 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.
|
||||||
|
|
||||||
|
import contextlib
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import gclient_paths
|
||||||
|
|
||||||
|
|
||||||
|
def _register_build_id(local_dev_server_path, build_id):
|
||||||
|
subprocess.run([
|
||||||
|
local_dev_server_path, '--register-build-id', build_id, '--builder-pid',
|
||||||
|
str(os.getpid())
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def _print_status(local_dev_server_path, build_id):
|
||||||
|
subprocess.run([local_dev_server_path, '--print-status', build_id])
|
||||||
|
|
||||||
|
|
||||||
|
def _get_server_path():
|
||||||
|
src_dir = gclient_paths.GetPrimarySolutionPath()
|
||||||
|
return os.path.join(src_dir, 'build/android/fast_local_dev_server.py')
|
||||||
|
|
||||||
|
|
||||||
|
def _set_signal_handler(local_dev_server_path, build_id):
|
||||||
|
original_sigint_handler = signal.getsignal(signal.SIGINT)
|
||||||
|
|
||||||
|
def _kill_handler(signum, frame):
|
||||||
|
# Cancel the pending build tasks if user CTRL+c early.
|
||||||
|
print('Canceling pending build_server tasks', file=sys.stderr)
|
||||||
|
subprocess.run([local_dev_server_path, '--cancel-build', build_id])
|
||||||
|
original_sigint_handler(signum, frame)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, _kill_handler)
|
||||||
|
|
||||||
|
|
||||||
|
def _start_server(local_dev_server_path):
|
||||||
|
subprocess.Popen([local_dev_server_path, '--exit-on-idle', '--quiet'],
|
||||||
|
start_new_session=True)
|
||||||
|
|
||||||
|
|
||||||
|
def _set_tty_env():
|
||||||
|
stdout_name = os.readlink('/proc/self/fd/1')
|
||||||
|
os.environ.setdefault("AUTONINJA_STDOUT_NAME", stdout_name)
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def build_server_context(build_id, use_android_build_server=False):
|
||||||
|
if not use_android_build_server:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
_set_tty_env()
|
||||||
|
server_path = _get_server_path()
|
||||||
|
_start_server(server_path)
|
||||||
|
# Tell the build server about us.
|
||||||
|
_register_build_id(server_path, build_id)
|
||||||
|
_set_signal_handler(server_path, build_id)
|
||||||
|
yield
|
||||||
|
_print_status(server_path, build_id)
|
||||||
59
autoninja.py
59
autoninja.py
@@ -15,7 +15,6 @@ settings.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import logging
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -28,6 +27,7 @@ import time
|
|||||||
import uuid
|
import uuid
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
import android_build_server_helper
|
||||||
import build_telemetry
|
import build_telemetry
|
||||||
import gclient_paths
|
import gclient_paths
|
||||||
import gclient_utils
|
import gclient_utils
|
||||||
@@ -226,6 +226,7 @@ def _main_inner(input_args, build_id, should_collect_logs=False):
|
|||||||
use_remoteexec = False
|
use_remoteexec = False
|
||||||
use_reclient = _get_use_reclient_value(output_dir)
|
use_reclient = _get_use_reclient_value(output_dir)
|
||||||
use_siso = _get_use_siso_default(output_dir)
|
use_siso = _get_use_siso_default(output_dir)
|
||||||
|
use_android_build_server = False
|
||||||
|
|
||||||
# Attempt to auto-detect remote build acceleration. We support gn-based
|
# Attempt to auto-detect remote build acceleration. We support gn-based
|
||||||
# builds, where we look for args.gn in the build tree, and cmake-based
|
# builds, where we look for args.gn in the build tree, and cmake-based
|
||||||
@@ -257,6 +258,9 @@ def _main_inner(input_args, build_id, should_collect_logs=False):
|
|||||||
if k == "use_reclient" and v == "false":
|
if k == "use_reclient" and v == "false":
|
||||||
use_reclient = False
|
use_reclient = False
|
||||||
continue
|
continue
|
||||||
|
if k == "android_static_analysis" and v == '"build_server"':
|
||||||
|
use_android_build_server = True
|
||||||
|
continue
|
||||||
if use_reclient is None:
|
if use_reclient is None:
|
||||||
use_reclient = use_remoteexec
|
use_reclient = use_remoteexec
|
||||||
|
|
||||||
@@ -322,28 +326,33 @@ def _main_inner(input_args, build_id, should_collect_logs=False):
|
|||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Build ID consistently used in other tools. e.g. Reclient, ninjalog.
|
# Build ID consistently used in other tools. e.g. Reclient, ninjalog.
|
||||||
os.environ.setdefault("SISO_BUILD_ID", build_id)
|
os.environ.setdefault("SISO_BUILD_ID", build_id)
|
||||||
if use_remoteexec:
|
with android_build_server_helper.build_server_context(
|
||||||
if use_reclient and not t_specified:
|
build_id,
|
||||||
return reclient_helper.run_siso(
|
use_android_build_server=use_android_build_server):
|
||||||
[
|
if use_remoteexec:
|
||||||
'siso',
|
if use_reclient and not t_specified:
|
||||||
'ninja',
|
return reclient_helper.run_siso(
|
||||||
# Do not authenticate when using Reproxy.
|
[
|
||||||
'-project=',
|
'siso',
|
||||||
'-reapi_instance=',
|
'ninja',
|
||||||
] + input_args[1:],
|
# Do not authenticate when using Reproxy.
|
||||||
should_collect_logs)
|
'-project=',
|
||||||
return siso.main(["siso", "ninja"] + input_args[1:])
|
'-reapi_instance=',
|
||||||
if not project:
|
] + input_args[1:],
|
||||||
project = _siso_rbe_project()
|
should_collect_logs)
|
||||||
if not t_specified and project and not offline:
|
return siso.main(["siso", "ninja"] + input_args[1:])
|
||||||
print(
|
if not project:
|
||||||
'Missing "use_remoteexec=true". No remote execution',
|
project = _siso_rbe_project()
|
||||||
file=sys.stderr,
|
if not t_specified and project and not offline:
|
||||||
)
|
print(
|
||||||
return siso.main(["siso", "ninja", "--offline"] + input_args[1:])
|
'Missing "use_remoteexec=true". No remote execution',
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return siso.main(["siso", "ninja", "--offline"] +
|
||||||
|
input_args[1:])
|
||||||
|
|
||||||
if os.path.exists(siso_marker):
|
if os.path.exists(siso_marker):
|
||||||
print(
|
print(
|
||||||
@@ -443,9 +452,11 @@ def _main_inner(input_args, build_id, should_collect_logs=False):
|
|||||||
# are being used.
|
# are being used.
|
||||||
_print_cmd(ninja_args)
|
_print_cmd(ninja_args)
|
||||||
|
|
||||||
if use_reclient and not t_specified:
|
with android_build_server_helper.build_server_context(
|
||||||
return reclient_helper.run_ninja(ninja_args, should_collect_logs)
|
build_id, use_android_build_server=use_android_build_server):
|
||||||
return ninja.main(ninja_args)
|
if use_reclient and not t_specified:
|
||||||
|
return reclient_helper.run_ninja(ninja_args, should_collect_logs)
|
||||||
|
return ninja.main(ninja_args)
|
||||||
|
|
||||||
|
|
||||||
def _upload_ninjalog(args, exit_code, build_duration):
|
def _upload_ninjalog(args, exit_code, build_duration):
|
||||||
|
|||||||
18
siso.py
18
siso.py
@@ -39,9 +39,21 @@ def checkOutdir(args):
|
|||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
# Propagate signals to siso process so that it can run cleanup steps.
|
# Do not raise KeyboardInterrupt on SIGINT so as to give siso time to run
|
||||||
# Siso will be terminated immediately after the second Ctrl-C.
|
# cleanup tasks. Siso will be terminated immediately after the second
|
||||||
signal.signal(signal.SIGINT, lambda signum, frame: None)
|
# Ctrl-C.
|
||||||
|
original_sigint_handler = signal.getsignal(signal.SIGINT)
|
||||||
|
|
||||||
|
def _ignore(signum, frame):
|
||||||
|
try:
|
||||||
|
# Call the original signal handler.
|
||||||
|
original_sigint_handler(signum, frame)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
# Do not reraise KeyboardInterrupt so as to not kill siso too early.
|
||||||
|
pass
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, _ignore)
|
||||||
|
|
||||||
if not sys.platform.startswith('win'):
|
if not sys.platform.startswith('win'):
|
||||||
signal.signal(signal.SIGTERM, lambda signum, frame: None)
|
signal.signal(signal.SIGTERM, lambda signum, frame: None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user