From 7692c1143e1d0fedfedbf8480fc1f254b5a320f6 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 25 Mar 2025 21:08:08 +0000 Subject: [PATCH] Update the Dart package creation script to copy source files instead of creating symlinks to the source tree (#165242) The use of symlinks and the use of a directory as a GN output path may cause unnecessary rebuilds when Ninja checks file modification times to determine whether build outputs are up to date. Also remove various other unused featues that were copied from the original version of the script in the Mojo project. --- .../src/flutter/build/dart/tools/dart_pkg.py | 116 +----------------- engine/src/flutter/sky/dist/BUILD.gn | 1 - .../flutter/sky/packages/sky_engine/BUILD.gn | 13 +- 3 files changed, 4 insertions(+), 126 deletions(-) diff --git a/engine/src/flutter/build/dart/tools/dart_pkg.py b/engine/src/flutter/build/dart/tools/dart_pkg.py index 45f492fad7..c60e3e0243 100755 --- a/engine/src/flutter/build/dart/tools/dart_pkg.py +++ b/engine/src/flutter/build/dart/tools/dart_pkg.py @@ -14,16 +14,11 @@ import shutil import subprocess import sys -USE_LINKS = sys.platform != 'win32' - -DART_ANALYZE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'dart_analyze.py') - def dart_filter(path): if os.path.isdir(path): return True _, ext = os.path.splitext(path) - # .dart includes '.mojom.dart' return ext == '.dart' @@ -41,21 +36,6 @@ def has_pubspec_yaml(paths): return False -def link(from_root, to_root): - ensure_dir_exists(os.path.dirname(to_root)) - try: - os.unlink(to_root) - except OSError as err: - if err.errno == errno.ENOENT: - pass - - try: - os.symlink(from_root, to_root) - except OSError as err: - if err.errno == errno.EEXIST: - pass - - def copy(from_root, to_root, filter_func=None): if not os.path.exists(from_root): return @@ -84,18 +64,6 @@ def copy(from_root, to_root, filter_func=None): dirs[:] = list(filter(wrapped_filter, dirs)) -def copy_or_link(from_root, to_root, filter_func=None): - if USE_LINKS: - link(from_root, to_root) - else: - copy(from_root, to_root, filter_func) - - -def link_if_possible(from_root, to_root): - if USE_LINKS: - link(from_root, to_root) - - def remove_if_exists(path): try: os.remove(path) @@ -118,47 +86,6 @@ def list_files(from_root, filter_func=None): return file_list -def remove_broken_symlink(path): - if not USE_LINKS: - return - try: - link_path = os.readlink(path) - except OSError as err: - # Path was not a symlink. - if err.errno == errno.EINVAL: - pass - else: - if not os.path.exists(link_path): - remove_if_exists(path) - - -def remove_broken_symlinks(root_dir): - if not USE_LINKS: - return - for current_dir, _, child_files in os.walk(root_dir): - for filename in child_files: - path = os.path.join(current_dir, filename) - remove_broken_symlink(path) - - -def analyze_entrypoints(dart_sdk, package_root, entrypoints): - cmd = ['python', DART_ANALYZE] - cmd.append('--dart-sdk') - cmd.append(dart_sdk) - cmd.append('--entrypoints') - cmd.extend(entrypoints) - cmd.append('--package-root') - cmd.append(package_root) - cmd.append('--no-hints') - try: - subprocess.check_output(cmd, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as err: - print('Failed analyzing %s' % entrypoints) - print(err.output) - return err.returncode - return 0 - - def main(): parser = argparse.ArgumentParser(description='Generate a dart-pkg') parser.add_argument( @@ -177,23 +104,10 @@ def main(): help='Directory where dart_pkg should go', required=True ) - parser.add_argument( - '--package-root', metavar='package_root', help='packages/ directory', required=True - ) parser.add_argument('--stamp-file', metavar='stamp_file', help='timestamp file', required=True) - parser.add_argument( - '--entries-file', metavar='entries_file', help='script entries file', required=True - ) parser.add_argument( '--package-sources', metavar='package_sources', help='Package sources', nargs='+' ) - parser.add_argument( - '--package-entrypoints', - metavar='package_entrypoints', - help='Package entry points for analyzer', - nargs='*', - default=[] - ) parser.add_argument( '--sdk-ext-directories', metavar='sdk_ext_directories', @@ -249,14 +163,7 @@ def main(): for source in args.package_sources: relative_source = os.path.relpath(source, common_source_prefix) target = os.path.join(target_dir, relative_source) - copy_or_link(source, target) - - entrypoint_targets = [] - for source in args.package_entrypoints: - relative_source = os.path.relpath(source, common_source_prefix) - target = os.path.join(target_dir, relative_source) - copy_or_link(source, target) - entrypoint_targets.append(target) + copy(source, target) # Copy sdk-ext sources into pkg directory sdk_ext_dir = os.path.join(target_dir, 'sdk_ext') @@ -266,30 +173,13 @@ def main(): for source in sdk_ext_sources: relative_source = os.path.relpath(source, common_prefix) target = os.path.join(sdk_ext_dir, relative_source) - copy_or_link(source, target) + copy(source, target) common_source_prefix = os.path.dirname(os.path.commonprefix(args.sdk_ext_files)) for source in args.sdk_ext_files: relative_source = os.path.relpath(source, common_source_prefix) target = os.path.join(sdk_ext_dir, relative_source) - copy_or_link(source, target) - - # Symlink packages/ - package_path = os.path.join(args.package_root, args.package_name) - copy_or_link(lib_path, package_path) - - # Link dart-pkg/$package/packages to dart-pkg/packages - link_if_possible(args.package_root, target_packages_dir) - - # Remove any broken symlinks in target_dir and package root. - remove_broken_symlinks(target_dir) - remove_broken_symlinks(args.package_root) - - # If any entrypoints are defined, write them to disk so that the analyzer - # test can find them. - with open(args.entries_file, 'w') as file: - for entrypoint in entrypoint_targets: - file.write(entrypoint + '\n') + copy(source, target) # Write stamp file. with open(args.stamp_file, 'w'): diff --git a/engine/src/flutter/sky/dist/BUILD.gn b/engine/src/flutter/sky/dist/BUILD.gn index cd59f0133a..0f1155f6b2 100644 --- a/engine/src/flutter/sky/dist/BUILD.gn +++ b/engine/src/flutter/sky/dist/BUILD.gn @@ -11,7 +11,6 @@ if (is_android) { source = "$root_gen_dir/dart-pkg/sky_engine" dest = "$root_build_dir/dist/packages/sky_engine" - inputs = [ source ] outputs = [ dest ] args = [ diff --git a/engine/src/flutter/sky/packages/sky_engine/BUILD.gn b/engine/src/flutter/sky/packages/sky_engine/BUILD.gn index 097d9bc4ae..23c1aab4f6 100644 --- a/engine/src/flutter/sky/packages/sky_engine/BUILD.gn +++ b/engine/src/flutter/sky/packages/sky_engine/BUILD.gn @@ -293,9 +293,7 @@ generated_file("_embedder_yaml") { action("sky_engine") { package_name = "sky_engine" pkg_directory = rebase_path("$root_gen_dir/dart-pkg") - package_root = rebase_path("$root_gen_dir/dart-pkg/packages") stamp_file = "$root_gen_dir/dart-pkg/${package_name}.stamp" - entries_file = "$root_gen_dir/dart-pkg/${package_name}.entries" sources = [ "LICENSE", @@ -322,12 +320,7 @@ action("sky_engine") { "$service_isolate_dir/vmservice_server.dart", ] - outputs = [ - "$root_gen_dir/dart-pkg/${package_name}", - "$root_gen_dir/dart-pkg/${package_name}/pubspec.yaml", - "$root_gen_dir/dart-pkg/packages/${package_name}", - stamp_file, - ] + outputs = [ stamp_file ] script = rebase_path("//flutter/build/dart/tools/dart_pkg.py", ".", "//") @@ -340,12 +333,8 @@ action("sky_engine") { rebase_path(dart_sdk_root), "--pkg-directory", pkg_directory, - "--package-root", - package_root, "--stamp-file", rebase_path(stamp_file), - "--entries-file", - rebase_path(entries_file), "--package-sources", ] + rebase_path(sources) + [ "--sdk-ext-directories" ] + rebase_path(sdk_ext_directory) + [ "--sdk-ext-files" ] +