From f51e0982e9a3d8b4aed74a351058d8f3fa256bae Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 23 Oct 2024 20:26:31 +0300 Subject: [PATCH] Reland copy gen snapshot (flutter/engine#56061) Copy gen_snapshots using python's shutil.copy, avoid links Default implementation of copy does it via hardlink, which seems to be causing issues with Gatekeeper on mac. This is reland of 63d8f5cb72d711871736b742a30a45106df21b9a with the fix for the case when target is a link to the source, that was the cause for revert c5ad234e11dd716cd8b136cdef8d1233c594c527 BUG=https://github.com/flutter/flutter/issues/154437 --- .../flutter/ci/licenses_golden/excluded_files | 1 + engine/src/flutter/lib/snapshot/BUILD.gn | 10 ++++-- engine/src/flutter/sky/tools/cp.py | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 engine/src/flutter/sky/tools/cp.py diff --git a/engine/src/flutter/ci/licenses_golden/excluded_files b/engine/src/flutter/ci/licenses_golden/excluded_files index c5c1c44f7f6..e48d183af38 100644 --- a/engine/src/flutter/ci/licenses_golden/excluded_files +++ b/engine/src/flutter/ci/licenses_golden/excluded_files @@ -435,6 +435,7 @@ ../../../flutter/sky/packages/sky_engine/README.md ../../../flutter/sky/packages/sky_engine/lib/_embedder.yaml ../../../flutter/sky/packages/sky_engine/pubspec.yaml +../../../flutter/sky/tools/cp.py ../../../flutter/sky/tools/create_embedder_framework.py ../../../flutter/sky/tools/create_ios_framework.py ../../../flutter/sky/tools/create_macos_binary.py diff --git a/engine/src/flutter/lib/snapshot/BUILD.gn b/engine/src/flutter/lib/snapshot/BUILD.gn index 6c6ce7fce57..47646c7888f 100644 --- a/engine/src/flutter/lib/snapshot/BUILD.gn +++ b/engine/src/flutter/lib/snapshot/BUILD.gn @@ -201,12 +201,18 @@ if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) { gen_snapshot_target = "$dart_src/runtime/bin:$gen_snapshot_target_name($build_toolchain)" - copy(target_name) { + action(target_name) { + script = "//flutter/sky/tools/cp.py" + # The toolchain-specific output directory. For cross-compiles, this is a # clang-x64 or clang-arm64 subdirectory of the top-level build directory. output_dir = get_label_info(gen_snapshot_target, "root_out_dir") - sources = [ "${output_dir}/${gen_snapshot_target_name}" ] + args = [ + rebase_path("${output_dir}/${gen_snapshot_target_name}"), + rebase_path( + "${root_out_dir}/artifacts_$host_cpu/gen_snapshot_${target_cpu}"), + ] outputs = [ "${root_out_dir}/artifacts_$host_cpu/gen_snapshot_${target_cpu}" ] deps = [ gen_snapshot_target ] diff --git a/engine/src/flutter/sky/tools/cp.py b/engine/src/flutter/sky/tools/cp.py new file mode 100755 index 00000000000..13197359689 --- /dev/null +++ b/engine/src/flutter/sky/tools/cp.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2012 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. + +"""Copy a file. + +This module works much like the cp posix command - it takes 2 arguments: +(src, dst) and copies the file with path |src| to |dst|. +""" + +import os +import shutil +import sys + + +def main(src, dst): + # Use copy instead of copyfile to ensure the executable bit is copied. + dstpath = os.path.normpath(dst) + try: + shutil.copy(src, dstpath) + except shutil.SameFileError: + if not (os.path.islink(dstpath) or os.stat(dstpath).st_nlink > 1): + raise + # Copy will fail if the destination is the link to the source. + # If that's the case, then delete the destination link first, + # then repeat the copy. + os.remove(dstpath) + shutil.copy(src, dstpath) + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1], sys.argv[2]))