From b0f933facc6f141087f55fe13dd84437b4ea6aa5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Wed, 18 Jun 2025 07:18:22 -0700 Subject: [PATCH] [gn] Fix precompile_tools=true gn_dart_compile_exe.py wrapper stopped working because we rearranged something in the prebuilt SDK. However we no longer need it because we can ask `compile exe` itself to produce the depfile. TEST=manually R=kustermann@google.com Change-Id: If5e64ede08b4e146a7bf033e7ef2d1809f40de1f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435500 Reviewed-by: Martin Kustermann Commit-Queue: Slava Egorov --- build/gn_dart_compile_exe.py | 151 ----------------------------------- utils/BUILD.gn | 21 ++--- 2 files changed, 7 insertions(+), 165 deletions(-) delete mode 100755 build/gn_dart_compile_exe.py diff --git a/build/gn_dart_compile_exe.py b/build/gn_dart_compile_exe.py deleted file mode 100755 index 41bba66592c..00000000000 --- a/build/gn_dart_compile_exe.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2014 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. -"""Helper script for GN to run `dart compile exe` and produce a depfile. - -Run with: - python3 gn_dart_compile_exe.py \ - --dart-binary \ - --entry-point \ - --output \ - --sdk-hash \ - --packages \ - --depfile - -This is workaround for `dart compile exe` not supporting --depfile option -in the current version of prebuilt SDK. Once we roll in a new version -of checked in SDK we can remove this helper. -""" - -import argparse -import os -import sys -import subprocess -from tempfile import TemporaryDirectory - - -def parse_args(argv): - parser = argparse.ArgumentParser() - parser.add_argument("--dart-sdk", - required=True, - help="Path to the prebuilt Dart SDK") - parser.add_argument("--sdk-hash", required=True, help="SDK hash") - parser.add_argument("--entry-point", - required=True, - help="Dart entry point to precompile") - parser.add_argument("--output", - required=True, - help="Path to resulting executable ") - parser.add_argument("--packages", - required=True, - help="Path to package config file") - parser.add_argument("--depfile", - required=True, - help="Path to depfile to write") - return parser.parse_args(argv) - - -# Run a command, swallowing the output unless there is an error. -def run_command(command): - try: - subprocess.check_output(command, stderr=subprocess.STDOUT) - return True - except subprocess.CalledProcessError as e: - print("Command failed: " + " ".join(command) + "\n" + "output: " + - _decode(e.output)) - return False - except OSError as e: - print("Command failed: " + " ".join(command) + "\n" + "output: " + - _decode(e.strerror)) - return False - - -def _decode(bytes): - return bytes.decode("utf-8") - - -def main(argv): - args = parse_args(argv[1:]) - - # Unless the path is absolute, this script is designed to run binaries - # produced by the current build, which is the current working directory when - # this script is run. - prebuilt_sdk = os.path.abspath(args.dart_sdk) - - dart_binary = os.path.join(prebuilt_sdk, "bin", "dart") - if not os.path.isfile(dart_binary): - print("Binary not found: " + dart_binary) - return 1 - - dartaotruntime_binary = os.path.join(prebuilt_sdk, "bin", "dartaotruntime") - if not os.path.isfile(dartaotruntime_binary): - print("Binary not found: " + dartaotruntime_binary) - return 1 - - gen_kernel_snapshot = os.path.join(prebuilt_sdk, "bin", "snapshots", - "gen_kernel_aot.dart.snapshot") - if not os.path.isfile(gen_kernel_snapshot): - print("Binary not found: " + gen_kernel_snapshot) - return 1 - - platform_dill = os.path.join(prebuilt_sdk, "lib", "_internal", - "vm_platform.dill") - if not os.path.isfile(platform_dill): - print("Binary not found: " + platform_dill) - return 1 - - # Compile the executable. - ok = run_command([ - dart_binary, - "compile", - "exe", - "--packages", - args.packages, - f"-Dsdk_hash={args.sdk_hash}", - "-o", - args.output, - args.entry_point, - ]) - if not ok: - return 1 - - # Collect dependencies by using gen_kernel. - with TemporaryDirectory() as tmpdir: - output_dill = os.path.join(tmpdir, "output.dill") - ok = run_command([ - dartaotruntime_binary, - gen_kernel_snapshot, - "--platform", - platform_dill, - "--packages", - args.packages, - "--depfile", - args.depfile, - "-o", - output_dill, - args.entry_point, - ]) - if not ok: - return 1 - - # Fix generated depfile to refer to the output file name instead - # of referring to the temporary dill file we have generated. - with open(args.depfile, "r") as f: - content = f.read() - (target_name, deps) = content.split(": ", 1) - if target_name != output_dill: - print( - "ERROR: Something is wrong with generated depfile: expected {output_dill} as target, but got {target_name}" - ) - return 1 - with open(args.depfile, "w") as f: - f.write(args.output) - f.write(": ") - f.write(deps) - - return 0 - - -if __name__ == "__main__": - sys.exit(main(sys.argv)) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 15fc3c1cd77..0112e732aa1 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -8,7 +8,7 @@ import("../sdk_args.gni") _dart_root = get_path_info("..", "abspath") template("aot_compile_using_prebuilt_sdk") { - action(target_name) { + prebuilt_dart_action(target_name) { forward_variables_from(invoker, [ "deps", @@ -17,31 +17,24 @@ template("aot_compile_using_prebuilt_sdk") { "visibility", ]) - script = "$_dart_root/build/gn_dart_compile_exe.py" - inputs = [ invoker.entry_point, invoker.package_config, ] - outputs = [ invoker.output ] - depfile = invoker.output + ".d" - # TODO(vegorov): support RBE by using rewrapper script. args = [ - "--dart-sdk", - rebase_path("$_dart_root/tools/sdks/dart-sdk", root_build_dir), - "--sdk-hash", - "$sdk_hash", - "--entry-point", - rebase_path(invoker.entry_point, root_build_dir), - "--output", - rebase_path(invoker.output, root_build_dir), + "compile", + "exe", "--packages", rebase_path(invoker.package_config, root_build_dir), + "-Dsdk_hash=$sdk_hash", "--depfile", rebase_path(depfile, root_build_dir), + "-o", + rebase_path(invoker.output, root_build_dir), + rebase_path(invoker.entry_point, root_build_dir), ] } }