Allow running pub with --preview-dart-2

- Make a snapshot in Dart 2 mode
- Check for the VM argument `--preview-dart-2` and run the correct
  snapshot

Towards fixing https://github.com/dart-lang/sdk/issues/32188

Change-Id: I56d5e7f268ff40b80783fae571981705536280f2
Reviewed-on: https://dart-review.googlesource.com/54743
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
This commit is contained in:
Nate Bosch 2018-05-18 20:27:29 +00:00 committed by commit-bot@chromium.org
parent 7aacf7e188
commit 2ff2af7921
4 changed files with 42 additions and 4 deletions

View file

@ -46,6 +46,7 @@ declare_args() {
# ........dartdevk.dart.snapshot
# ........kernel_summary_worker.dart.snapshot
# ........pub.dart.snapshot
# ........pub2.dart.snapshot
#.........resources/
#...........dartdoc/
#..............packages
@ -133,6 +134,10 @@ _platform_sdk_snapshots = [
"pub",
"../utils/pub",
],
[
"pub2",
"../utils/pub:pub2",
],
]
_full_sdk_snapshots = [
@ -172,6 +177,10 @@ _full_sdk_snapshots = [
"pub",
"../utils/pub",
],
[
"pub2",
"../utils/pub:pub2",
],
[
"kernel-service",
"../utils/kernel-service",

View file

@ -15,13 +15,20 @@ function follow_links() {
echo "$file"
}
function array_contains() {
local needle="$1"
local element
shift
for element; do [ "$element" = "$needle" ] && return 0; done
return 1
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
PROG_NAME="$(follow_links "$BASH_SOURCE")"
# Handle the case where dart-sdk/bin has been symlinked to.
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SNAPSHOT="$BIN_DIR/snapshots/pub.dart.snapshot"
unset VM_OPTIONS
declare -a VM_OPTIONS
@ -34,4 +41,10 @@ fi
# Run the pub snapshot.
DART="$BIN_DIR/dart"
exec "$DART" "${VM_OPTIONS[@]}" "$SNAPSHOT" "$@"
if array_contains "--preview-dart-2" "${VM_OPTIONS[@]}"; then
SNAPSHOT="$BIN_DIR/snapshots/pub2.dart.snapshot"
exec "$DART" "${VM_OPTIONS[@]}" "$SNAPSHOT" "$@"
else
SNAPSHOT="$BIN_DIR/snapshots/pub.dart.snapshot"
exec "$DART" "${VM_OPTIONS[@]}" "$SNAPSHOT" "$@"
fi

View file

@ -18,13 +18,21 @@ rem Remove trailing backslash if there is one
IF %SDK_DIR:~-1%==\ set SDK_DIR=%SDK_DIR:~0,-1%
set VM_OPTIONS=
set USING_DART_2=
rem We allow extra vm options to be passed in through an environment variable.
if not "_%DART_VM_OPTIONS%_" == "__" (
set VM_OPTIONS=%VM_OPTIONS% %DART_VM_OPTIONS%
for %%o in (%DART_VM_OPTIONS%) do (
if "%%o" equ "--preview-dart-2" set USING_DART_2=y
)
)
"%BIN_DIR%\dart" %VM_OPTIONS% "%BIN_DIR%\snapshots\pub.dart.snapshot" %*
if defined USING_DART_2 (
"%BIN_DIR%\dart" %VM_OPTIONS% "%BIN_DIR%\snapshots\pub2.dart.snapshot" %*
) else (
"%BIN_DIR%\dart" %VM_OPTIONS% "%BIN_DIR%\snapshots\pub.dart.snapshot" %*
)
endlocal
@ -42,4 +50,4 @@ if not "%current%"=="" call :follow_links "%current%", result
endlocal & set %~2=%result%
goto :eof
:end
:end

View file

@ -8,3 +8,11 @@ application_snapshot("pub") {
main_dart = "../../third_party/pkg/pub/bin/pub.dart"
training_args = [ "--help" ]
}
application_snapshot("pub2") {
main_dart = "../../third_party/pkg/pub/bin/pub.dart"
training_args = [ "--help" ]
vm_args = [
"--preview-dart-2",
]
}