提交 e1dacd83 编写于 作者: A Adam Barth

Switch sdk_xcode_harness to use flutter build aot (#2706)

Switch sdk_xcode_harness to use flutter build aot

This patch moves a bunch of complexity out of FlutterApplication.xcodeproj and
into `flutter build aot`, which will make it easier for developers to create
their own FlutterApplication.xcodeproj.
上级 ba267f5c
#!/bin/sh
# Copyright 2015 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.
RunCommand() {
echo "♦ " $@
$@
return $?
}
EchoError() {
echo "$@" 1>&2
}
AssertExists() {
RunCommand ls $1
if [ $? -ne 0 ]; then
EchoError "The path $1 does not exist"
exit -1
fi
return 0
}
GenerateBinaryInclude() {
local input=$1
local output=$2
AssertExists ${input}
# Check that an input file was specified
if [[ -z "${output}" ]]; then
EchoError "Isolate buffer output file unspecified"
exit -1
fi
# Check that xxd is available on the system
RunCommand which xxd
if [[ $? -ne 0 ]]; then
EchoError "Could not find |xxd| to generate buffers for ${input}"
exit -1
fi
# Remove old build artifacts
RunCommand rm -f #{output}
# Since there is no flag to specify the symbol name to xxd, we change to the
# directory of the input file and invoke xxd from there
RunCommand pushd $(dirname ${input})
local input_basename=${input##*/}
RunCommand xxd --include ${input_basename} ${output}
if [[ $? -ne 0 ]]; then
EchoError "|xxd| invocation failed to generate ${output}"
fi
RunCommand popd
AssertExists $2
}
SnapshotProject() {
if [ $CURRENT_ARCH == "x86_64" ]; then
echo "Script snapshots are used on the simulator as the fully JIT enabled"
echo "Dart VM is available. There is no need to incur the cost of"
echo "precompilation. The packager has already done the heavy lifting."
return 0
fi
# Check that the caller has provided a project path
if [[ -z "$1" ]]; then
EchoError "The path to the dart project must be specified"
exit -1
fi
local project_path="$1"
RunCommand cd ${project_path}
# Check if 'pub get' has been run
RunCommand ls ${project_path}/packages
if [ $? -ne 0 ]; then
EchoError "The project does not have a packages directory"
EchoError "Did you forget to run 'pub get'?"
exit -1
fi
local packages=${project_path}/packages
# Resolve symlinks to point to the url mapping values
# For dart:mojo.internal
local mojo_internal_path="$(readlink ${packages}/mojo)/../sdk_ext/internal.dart"
AssertExists $mojo_internal_path
# For dart:ui
local ui_path="$(readlink ${packages}/sky_engine)/../sdk_ext/dart_ui.dart"
if [[ "${ui_path:0:1}" != "/" ]]; then
ui_path="${packages}/${ui_path}"
fi
AssertExists $ui_path
# For dart:jni
local jni_path="$(readlink ${packages}/sky_engine)/../sdk_ext/dart_jni/jni.dart"
if [[ "${jni_path:0:1}" != "/" ]]; then
jni_path="${packages}/${jni_path}"
fi
AssertExists $jni_path
# For dart:vmservice_sky
local vm_service_path="$(readlink ${packages}/sky_engine)/../sdk_ext/dart/runtime/bin/vmservice/vmservice_io.dart"
if [[ "${vm_service_path:0:1}" != "/" ]]; then
vm_service_path="${packages}/${vm_service_path}"
fi
AssertExists $vm_service_path
local main_path="${project_path}/lib/main.dart"
AssertExists $main_path
local src_dir=${SOURCE_ROOT}/Tools/common
local derived_dir=${SOURCE_ROOT}/FlutterApplication/Generated
RunCommand mkdir -p $derived_dir
AssertExists $src_dir
AssertExists $derived_dir
AssertExists ${FLUTTER_ARCH_TOOLS_PATH}
# Remove old build artifacts
RunCommand rm -f ${derived_dir}/kDartVmIsolateSnapshotBuffer.c
RunCommand rm -f ${derived_dir}/kDartIsolateSnapshotBuffer.c
RunCommand rm -f ${derived_dir}/InstructionsSnapshot.S
if [[ $DART_EXPERIMENTAL_INTERPRETER == "1" ]]; then
# In case the experimental interpreter is enabled, we need a generic
# script snapshot instead of a precompilation snapshot.
RunCommand ${FLUTTER_ARCH_TOOLS_PATH}/Snapshotter \
--vm_isolate_snapshot=${derived_dir}/kDartVmIsolateSnapshotBuffer \
--isolate_snapshot=${derived_dir}/kDartIsolateSnapshotBuffer \
--package_root=${packages} \
--url_mapping=dart:mojo.internal,${mojo_internal_path} \
--url_mapping=dart:ui,${ui_path} \
--url_mapping=dart:jni,${jni_path} \
--url_mapping=dart:vmservice_sky,$vm_service_path \
--conditional_directives \
${src_dir}/snapshot.dart
local dummy_snapshot=${derived_dir}/InstructionsSnapshot.S
RunCommand rm -f ${dummy_snapshot}
RunCommand touch ${dummy_snapshot}
else
# Generate the precompilation snapshot. The instructions buffer is in an
# assembly file which can be directly used by the linker. For the VM isolate
# snapshot buffer and isolate snapshot buffer, we name the file to match
# the name of the symbol the VM expects at runtime. On these binary files,
# we invoke xxd.
#
# Note about "checked mode": Precompilation snapshots are never in checked
# mode. The flag is also ignored by the standalone VM. So there is no sense
# in generating the larger snapshot. For development purposes, a
# non-precompilation-enabled VM is used.
RunCommand ${FLUTTER_ARCH_TOOLS_PATH}/Snapshotter \
--vm_isolate_snapshot=${derived_dir}/kDartVmIsolateSnapshotBuffer \
--isolate_snapshot=${derived_dir}/kDartIsolateSnapshotBuffer \
--assembly=${derived_dir}/InstructionsSnapshot.S \
--embedder_entry_points_manifest=${src_dir}/EmbedderEntryPoints \
--package_root=${packages} \
--url_mapping=dart:mojo.internal,${mojo_internal_path} \
--url_mapping=dart:ui,${ui_path} \
--url_mapping=dart:vmservice_sky,$vm_service_path \
--conditional_directives \
$main_path
fi
if [[ $? -ne 0 ]]; then
EchoError "Snapshotter failed for $1 ..."
exit -1
fi
# The instruction buffer is already generated, the isolates need to be packed
# into C files
GenerateBinaryInclude \
${derived_dir}/kDartVmIsolateSnapshotBuffer \
${derived_dir}/kDartVmIsolateSnapshotBuffer.c \
GenerateBinaryInclude \
${derived_dir}/kDartIsolateSnapshotBuffer \
${derived_dir}/kDartIsolateSnapshotBuffer.c \
# Remove intermediate build artifacts
RunCommand rm -f ${derived_dir}/kDartVmIsolateSnapshotBuffer
RunCommand rm -f ${derived_dir}/kDartIsolateSnapshotBuffer
echo "Precompilation snapshot successfully created for ${project_path} ..."
return $?
}
SnapshotProject $1
......@@ -4,5 +4,4 @@
#include "Local.xcconfig"
FLUTTER_ARCH_TOOLS_PATH=${SOURCE_ROOT}/Tools/${PLATFORM_NAME}
DART_EXPERIMENTAL_INTERPRETER={{ interpreter }}
// Copyright 2015 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.
const char IntentionallyEmpty = '\0';
// Copyright 2015 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.
#if __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <stdint.h>
#include <stddef.h>
extern double FlutterApplicationVersionNumber;
extern const unsigned char FlutterApplicationVersionString[];
extern const uint8_t* kInstructionsSnapshot;
extern const uint8_t* kDartIsolateSnapshotBuffer;
extern const uint8_t* kDartVmIsolateSnapshotBuffer;
#if __cplusplus
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
// Copyright 2016 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.
#if (__arm__ || __aarch64__)
#include "Generated/InstructionsSnapshot.S"
#endif
// Copyright 2015 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.
#if (__arm__ || __aarch64__)
#include "Generated/kDartIsolateSnapshotBuffer.c"
#endif
// Copyright 2015 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.
#if (__arm__ || __aarch64__)
#include "Generated/kDartVmIsolateSnapshotBuffer.c"
#endif
#!/bin/sh
# Copyright 2015 The Chromium Authors. All rights reserved.
# Copyright 2016 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.
......@@ -22,16 +22,13 @@ AssertExists() {
return 0
}
PackageProject() {
BuildApp() {
# Check that the project path was specified
if [[ -z "$1" ]]; then
EchoError "Project path not specified"
exit -1
fi
# The 'flutter' command assumes the 'dart' binary is in $PATH
RunCommand export PATH=${PATH}:${DART_SDK_PATH}/bin
AssertExists $1
local project_path=$1
......@@ -39,42 +36,49 @@ PackageProject() {
RunCommand mkdir -p $derived_dir
AssertExists $derived_dir
local dart_main=${project_path}/lib/main.dart
AssertExists $dart_main
local packages=${project_path}/.packages
AssertExists $packages
# Remove old build artifacts
RunCommand rm -f ${derived_dir}/app.so
RunCommand rm -f ${derived_dir}/app.flx
local src_dir=${SOURCE_ROOT}/Tools/common
AssertExists $src_dir
RunCommand pushd ${project_path}
if [[ $CURRENT_ARCH != "x86_64" ]]; then
local interpreter_flag="--interpreter"
if [[ "$DART_EXPERIMENTAL_INTERPRETER" != "1" ]]; then
interpreter_flag=""
fi
RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build aot \
--target-platform=ios \
--release \
--output-dir=${derived_dir} \
${interpreter_flag}
if [[ $? -ne 0 ]]; then
EchoError "Failed to build $1."
exit -1
fi
else
RunCommand touch ${derived_dir}/app.so
fi
local precompilation_flag=""
if [[ $CURRENT_ARCH != "x86_64" ]] && [[ "$DART_EXPERIMENTAL_INTERPRETER" != "1" ]]; then
precompilation_flag="--precompiled"
fi
# Generate the new FLX file. The pub command must be run from the directory
# containing the pubspec
RunCommand pushd ${project_path}
RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build flx \
--target ${dart_main} \
--output-file ${derived_dir}/app.flx \
--packages ${packages} \
${precompilation_flag} \
RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build flx \
--output-file=${derived_dir}/app.flx \
${precompilation_flag} \
if [[ $? -ne 0 ]]; then
EchoError "Failed to package $1 ..."
EchoError "Failed to package $1."
exit -1
fi
RunCommand popd
echo "Project $1 successfully packaged..."
echo "Project $1 built and packaged successfully."
return 0
}
PackageProject $1
BuildApp $1
......@@ -13,26 +13,7 @@ template("sky_ios_sdk") {
sdk_name = invoker.sdk_name
sdk_dir = "$root_out_dir/$sdk_name"
tools_dir_name = "Tools"
tools_dir = "$tools_dir_name/common"
# The architecture specific suffixes are chosen to match the ${PLATFORM_NAME}
# used by the .xcconfig files
arch_tools_dir = "$tools_dir_name/iphoneos"
if (use_ios_simulator) {
arch_tools_dir = "$tools_dir_name/iphonesimulator"
}
copy("copy_snapshotter") {
snapshotter_target = "//dart/runtime/bin:gen_snapshot($dart_host_toolchain)"
snapshotter_directory = get_label_info(snapshotter_target, "root_out_dir")
snapshotter_name = get_label_info(snapshotter_target, "name")
sources = [ "$snapshotter_directory/$snapshotter_name" ]
outputs = [ "$sdk_dir/$arch_tools_dir/Snapshotter" ]
deps = [ snapshotter_target ]
}
tools_dir = "Tools/common"
action("copy_flutter_framework") {
stamp_file = "$root_build_dir/copy_flutter_framework.stamp"
......@@ -56,16 +37,9 @@ template("sky_ios_sdk") {
deps = [ "//sky/shell:flutter_framework" ]
}
copy("embedder_entry_points") {
sources = [ "//sky/engine/bindings/dart_vm_entry_points.txt" ]
outputs = [ "$sdk_dir/$tools_dir/EmbedderEntryPoints" ]
}
copy("ios_xcode_scripts") {
sources = [
"//sky/build/SnapshotterInvoke",
"//sky/build/PackagerInvoke",
"//sky/engine/bindings/snapshot.dart",
"//sky/build/sdk_xcode_harness/$tools_dir/BuildFlutterApp",
]
outputs = [ "$sdk_dir/$tools_dir/{{source_file_part}}" ]
}
......@@ -130,9 +104,7 @@ template("sky_ios_sdk") {
deps = [
":copy_flutter_framework",
":copy_sdk_xcode_harness",
":copy_snapshotter",
":copy_user_editable_files",
":embedder_entry_points",
":flutter_xcconfig",
":ios_xcode_scripts",
]
......
......@@ -298,8 +298,7 @@ const char* kDataSnapshotName = "kDataSnapshot";
#if OS(IOS)
const char* kDartApplicationLibraryPath =
"FlutterApplication.framework/FlutterApplication";
const char* kDartApplicationLibraryPath = "app.so";
static void* DartLookupSymbolInLibrary(const char* symbol_name,
const char* library) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册