From 46bf911c59f96da885eab709b36cf9215c1e875f Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 29 Oct 2019 20:30:13 -0700 Subject: [PATCH] Set the install name at link time for darwin dylibs (flutter/engine#13428) --- .../shell/platform/darwin/ios/BUILD.gn | 19 ++------- .../shell/platform/darwin/macos/BUILD.gn | 24 +++-------- .../flutter/shell/platform/embedder/BUILD.gn | 26 ++++-------- .../flutter/sky/tools/change_install_name.py | 42 ------------------- 4 files changed, 19 insertions(+), 92 deletions(-) delete mode 100755 engine/src/flutter/sky/tools/change_install_name.py diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index f29737c336..a66c3bf48c 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -42,6 +42,8 @@ shared_library("create_flutter_framework_dylib") { output_name = "Flutter" + ldflags = [ "-Wl,-install_name,@rpath/Flutter.framework/Flutter" ] + sources = [ "framework/Source/FlutterAppDelegate.mm", "framework/Source/FlutterAppDelegate_Internal.h", @@ -137,13 +139,9 @@ shared_library("create_flutter_framework_dylib") { ] } -action("copy_dylib_and_update_framework_install_name") { +copy("copy_dylib") { visibility = [ ":*" ] - script = "$flutter_root/sky/tools/change_install_name.py" - inputs = [ - script, - ] sources = [ "$root_out_dir/libFlutter.dylib", ] @@ -151,15 +149,6 @@ action("copy_dylib_and_update_framework_install_name") { "$_flutter_framework_dir/Flutter", ] - args = [ - "--dylib", - rebase_path(sources[0]), - "--install_name", - "@rpath/Flutter.framework/Flutter", - "--output", - rebase_path(outputs[0]), - ] - deps = [ ":create_flutter_framework_dylib", ] @@ -275,7 +264,7 @@ ios_app("FlutterTests") { group("flutter_framework") { deps = [ ":copy_and_verify_framework_headers", - ":copy_dylib_and_update_framework_install_name", + ":copy_dylib", ":copy_framework_icu", ":copy_framework_info_plist", ":copy_framework_module_map", diff --git a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn index c1afe22787..ff598fb807 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn @@ -26,6 +26,7 @@ group("macos") { _flutter_framework_name = "FlutterMacOS" _flutter_framework_filename = "$_flutter_framework_name.framework" _flutter_framework_dir = "$root_out_dir/$_flutter_framework_filename" +_framework_binary_subpath = "Versions/A/$_flutter_framework_name" # The headers that will be copied to the framework and be accessed from outside # the Flutter engine source root. @@ -84,9 +85,10 @@ source_set("flutter_framework_source") { shared_library("flutter_framework_dylib") { visibility = [ ":*" ] - output_name = "$_flutter_framework_name" + ldflags = [ "-Wl,-install_name,@rpath/$_flutter_framework_filename/$_framework_binary_subpath" ] + deps = [ ":flutter_framework_source", ] @@ -119,28 +121,14 @@ executable("flutter_desktop_darwin_unittests") { ] } -action("copy_dylib_and_update_framework_install_name") { +copy("copy_dylib") { visibility = [ ":*" ] - script = "$flutter_root/sky/tools/change_install_name.py" - framework_binary_subpath = "Versions/A/$_flutter_framework_name" - inputs = [ - script, - ] sources = [ "$root_out_dir/lib$_flutter_framework_name.dylib", ] outputs = [ - "$_flutter_framework_dir/$framework_binary_subpath", - ] - - args = [ - "--dylib", - rebase_path(sources[0]), - "--install_name", - "@rpath/$_flutter_framework_filename/$framework_binary_subpath", - "--output", - rebase_path(outputs[0]), + "$_flutter_framework_dir/$_framework_binary_subpath", ] deps = [ @@ -225,7 +213,7 @@ action("_generate_symlinks") { "$_flutter_framework_name.stamp", ] deps = [ - ":copy_dylib_and_update_framework_install_name", + ":copy_dylib", ":copy_framework_headers", ":copy_framework_icu", ":copy_framework_info_plist", diff --git a/engine/src/flutter/shell/platform/embedder/BUILD.gn b/engine/src/flutter/shell/platform/embedder/BUILD.gn index 7ffa95a45d..50b700228d 100644 --- a/engine/src/flutter/shell/platform/embedder/BUILD.gn +++ b/engine/src/flutter/shell/platform/embedder/BUILD.gn @@ -14,6 +14,8 @@ shell_gpu_configuration("embedder_gpu_configuration") { enable_metal = false } +_framework_binary_subpath = "Versions/A/FlutterEmbedder" + # Template for the embedder build. Used to allow building it multiple times with # different flags. template("embedder_source_set") { @@ -138,6 +140,10 @@ shared_library("flutter_engine_library") { output_name = "flutter_engine" + if (is_mac && !embedder_for_target) { + ldflags = [ "-Wl,-install_name,@rpath/FlutterEmbedder.framework/$_framework_binary_subpath" ] + } + deps = [ ":embedder", ] @@ -204,28 +210,14 @@ if (is_mac && !embedder_for_target) { ] } - action("install_dylib") { + copy("copy_dylib") { visibility = [ ":*" ] - script = "$flutter_root/sky/tools/change_install_name.py" - framework_binary_subpath = "Versions/A/FlutterEmbedder" - inputs = [ - script, - ] sources = [ "$root_out_dir/libflutter_engine.dylib", ] outputs = [ - "$_flutter_embedder_framework_dir/$framework_binary_subpath", - ] - - args = [ - "--dylib", - rebase_path(sources[0]), - "--install_name", - "@rpath/FlutterEmbedder.framework/$framework_binary_subpath", - "--output", - rebase_path(outputs[0]), + "$_flutter_embedder_framework_dir/$_framework_binary_subpath", ] deps = [ @@ -253,11 +245,11 @@ if (is_mac && !embedder_for_target) { "FlutterEmbedder.stamp", ] deps = [ + ":copy_dylib", ":copy_framework_headers", ":copy_icu", ":copy_info_plist", ":copy_module_map", - ":install_dylib", ] } diff --git a/engine/src/flutter/sky/tools/change_install_name.py b/engine/src/flutter/sky/tools/change_install_name.py deleted file mode 100755 index 7b41c674c3..0000000000 --- a/engine/src/flutter/sky/tools/change_install_name.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# Copyright 2013 The Flutter Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import argparse -import subprocess -import sys -import os - - -def main(): - parser = argparse.ArgumentParser( - description='Changes the install name of a dylib') - - parser.add_argument('--dylib', type=str) - parser.add_argument('--install_name', type=str) - # install_name_tool operates in place, which can't be expressed in GN, so - # this tool copies to a new location first, then operates on the copy. - parser.add_argument('--output', type=str) - - args = parser.parse_args() - - subprocess.check_call([ - '/usr/bin/env', - 'cp', - '-fp', - args.dylib, - args.output, - ]) - - subprocess.check_call([ - '/usr/bin/env', - 'xcrun', - 'install_name_tool', - '-id', - args.install_name, - args.output, - ]) - -if __name__ == '__main__': - sys.exit(main())