blob: 7963583fce2f226fe5ffae34fb2868e4de91548c [file] [log] [blame]
#!/bin/bash
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MOD_TOOL_DIR=${DIR}/../mod
SNAPSHOT_PATH=${MOD_TOOL_DIR}/bin/mod.dart.snapshot
# Find the dart executable.
UNAME_OUT="$(uname -s)"
case "${UNAME_OUT}" in
Linux*)
PLATFORM=linux
LAST_MODIFIED_FILE=$(find ${MOD_TOOL_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
;;
Darwin*)
PLATFORM=mac
LAST_MODIFIED_FILE=$(find ${MOD_TOOL_DIR} -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" ")
;;
esac
DART_BIN=${FUCHSIA_DIR}/third_party/dart/tools/sdks/${PLATFORM}/dart-sdk/bin
DART=${DART_BIN}/dart
PUB=${DART_BIN}/pub
if [ ! -x ${DART} ]; then
echo "Failed to find dart executable."
exit 1
fi
# Check if the snapshot is available, and use it if possible.
if [[ ! ( "${SNAPSHOT_PATH}" -ot "${LAST_MODIFIED_FILE}" ) ]]; then
${DART} "${SNAPSHOT_PATH}" "$@"
EXIT_CODE=$?
if [ ${EXIT_CODE} != 253 ]; then
exit ${EXIT_CODE}
fi
fi
# Create a snapshot and execute it.
pushd ${MOD_TOOL_DIR} > /dev/null
${PUB} get
${DART} --snapshot=${SNAPSHOT_PATH} bin/mod.dart
echo
popd > /dev/null
${DART} "${SNAPSHOT_PATH}" "$@"