diff --git a/lib/web_ui/dev/felt b/lib/web_ui/dev/felt index b1f3e3b3c7105..08cc3c041224e 100755 --- a/lib/web_ui/dev/felt +++ b/lib/web_ui/dev/felt @@ -30,6 +30,11 @@ OUT_DIR="${ENGINE_SRC_DIR}/out" HOST_DEBUG_UNOPT_DIR="${ENGINE_SRC_DIR}/out/host_debug_unopt" DART_SDK_DIR="${ENGINE_SRC_DIR}/out/host_debug_unopt/dart-sdk" GN="${FLUTTER_DIR}/tools/gn" +DART_TOOL_DIR="${WEB_UI_DIR}/.dart_tool" +SNAPSHOT_PATH="${DART_TOOL_DIR}/felt.snapshot" +STAMP_PATH="${DART_TOOL_DIR}/felt.snapshot.stamp" +SCRIPT_PATH="${DEV_DIR}/felt.dart" +REVISION="$(cd "$FLUTTER_DIR"; git rev-parse HEAD)" if [ ! -d "${OUT_DIR}" ] || [ ! -d "${HOST_DEBUG_UNOPT_DIR}" ] then @@ -39,10 +44,24 @@ then ninja -C $HOST_DEBUG_UNOPT_DIR fi -echo "Running \`pub get\` in 'engine/src/flutter/lib/web_ui'" -(cd "$WEB_UI_DIR"; $DART_SDK_DIR/bin/pub get) +# Invalidate cache if: +# * SNAPSHOT_PATH is not a file, or +# * STAMP_PATH is not a file with nonzero size, or +# * Contents of STAMP_PATH is not our local git HEAD revision, or +# * pubspec.yaml last modified after pubspec.lock +# +# To force invalidate the cache run `felt clean` or `rm .dart_tool/felt.shapshot.stamp` +if [[ ! -f $SNAPSHOT_PATH || ! -s "$STAMP_PATH" || "$(cat "$STAMP_PATH")" != "$REVISION" || "$WEB_UI_DIR/pubspec.yaml" -nt "$WEB_UI_DIR/pubspec.lock" ]]; then + echo "Snapshotting the felt tool for faster subsequent runs." + echo "Running \`pub get\` in 'engine/src/flutter/lib/web_ui'" + (cd "$WEB_UI_DIR"; $DART_SDK_DIR/bin/pub get) -echo "Running \`pub get\` in 'engine/src/flutter/web_sdk/web_engine_tester'" -(cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; $DART_SDK_DIR/bin/pub get) + echo "Running \`pub get\` in 'engine/src/flutter/web_sdk/web_engine_tester'" + (cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; $DART_SDK_DIR/bin/pub get) + mkdir -p $DART_TOOL_DIR -$DART_SDK_DIR/bin/dart "$DEV_DIR/felt.dart" $@ + "$DART_SDK_DIR/bin/dart" --snapshot="$SNAPSHOT_PATH" --packages="$WEB_UI_DIR/.packages" "$SCRIPT_PATH" + echo "$REVISION" > "$STAMP_PATH" +fi + +$DART_SDK_DIR/bin/dart --packages="$WEB_UI_DIR/.packages" "$SNAPSHOT_PATH" $@