blob: 4789273fbf163d8c813631c3f3f4b165978aa1e1 [file]
#!/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() {
$@ >/dev/null
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: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
# Finally! Generate the snapshot. The instructions buffer is already 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
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