| # 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. | |
| """Backs `fx build-forkserver`: turns the Python build forkserver on or off. | |
| enable and disable regenerate $FUCHSIA_BUILD_DIR, if it is set and has been | |
| configured (has an args.gn), so the next build uses the new setting. | |
| """ | |
| import argparse | |
| import os | |
| import pathlib | |
| import subprocess | |
| import sys | |
| from build.scripts.python_forkserver import setting | |
| def main(argv: list[str]) -> int: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("action", choices=["enable", "disable", "status"]) | |
| args = parser.parse_args(argv) | |
| fuchsia_dir = pathlib.Path(os.environ["FUCHSIA_DIR"]) | |
| if args.action != "status": | |
| setting.save(fuchsia_dir, enabled=args.action == "enable") | |
| build_dir = os.environ.get("FUCHSIA_BUILD_DIR") | |
| if build_dir and (fuchsia_dir / build_dir / "args.gn").is_file(): | |
| fx = fuchsia_dir / "scripts" / "fx" | |
| returncode = subprocess.run([fx, "gen"]).returncode | |
| if returncode: | |
| return returncode | |
| state = "on" if setting.load(fuchsia_dir) else "off" | |
| print(f"The Python build forkserver is {state} for {fuchsia_dir}.") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main(sys.argv[1:])) |