| # Copyright 2026 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| # Whether Python build actions run on the per-build Python forkserver | |
| # (//build/scripts/python_forkserver/README.md). | |
| # | |
| # By default, `fx build-forkserver enable` turns it on for every build | |
| # directory of a checkout by writing FX_BUILD_INTERNAL_PYTHON_FORKSERVER=1 to | |
| # //.fx/config/python_forkserver. A missing file, or anything else, is off. | |
| # `fx build` reads the same file with the same rule (setting.py) to decide | |
| # whether to start a server. | |
| # | |
| # Editing the file regenerates the build (GN tracks read_file()) at the start | |
| # of the next build, so the commands and the server agree. Creating or deleting | |
| # it doesn't (path_exists() isn't tracked), so `fx build-forkserver` empties the | |
| # file rather than deleting it, and regenerates the current build directory. | |
| # | |
| # Individual builds can also override this setting directly via the | |
| # `enable_python_forkserver` GN argument. | |
| # LINT.IfChange(rule) | |
| _default_enable_python_forkserver = false | |
| _config = "//.fx/config/python_forkserver" | |
| if (path_exists(_config)) { | |
| _default_enable_python_forkserver = | |
| filter_include(read_file(_config, "list lines"), | |
| [ "FX_BUILD_INTERNAL_PYTHON_FORKSERVER=1" ]) != [] | |
| } | |
| # LINT.ThenChange(//build/scripts/python_forkserver/setting.py:rule) | |
| declare_args() { | |
| # Run Python build actions through the per-build Python forkserver. | |
| # Defaults to the checkout-wide setting in //.fx/config/python_forkserver | |
| # (managed by `fx build-forkserver`), and can be overridden per build dir. | |
| enable_python_forkserver = _default_enable_python_forkserver | |
| } | |
| # Put python_forkserver_client_args right after the interpreter flags of a | |
| # `python_exe_src -S` command to run its script on the build's Python | |
| # forkserver: python3 -S <client.py> SCRIPT ARGS. Both lists are empty when the | |
| # forkserver is off, so that it stays out of the build graph and toggling it | |
| # rebuilds the commands. python_forkserver_client is for `inputs`. | |
| # | |
| # Both are also empty in traced builds (build_should_trace_actions): fsatrace's | |
| # LD_PRELOAD only sees the processes it starts, not the forkserver's workers, | |
| # so traced builds run every Python command directly. | |
| import("//build/tracer/tracer.gni") | |
| python_forkserver_client = [] | |
| if (enable_python_forkserver && !build_should_trace_actions) { | |
| python_forkserver_client = [ "//build/scripts/python_forkserver/client.py" ] | |
| } | |
| python_forkserver_client_args = | |
| rebase_path(python_forkserver_client, root_build_dir) |