Switch dartfmt in the SDK to run dart_style.

BUG=https://code.google.com/p/dart/issues/detail?id=22400
R=pquitslund@google.com, ricow@google.com

Review URL: https://codereview.chromium.org//950483002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44108 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
rnystrom@google.com 2015-02-27 23:00:35 +00:00
parent 0036014d8a
commit 1cae12abdc
6 changed files with 120 additions and 39 deletions

View file

@ -3,8 +3,8 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Run dartfmt.dart on the Dart VM. This script assumes the Dart SDK's directory
# structure.
# Run dart_style/bin/format.dart on the Dart VM. This script assumes the Dart
# repo's directory structure.
function follow_links() {
file="$1"
@ -20,34 +20,25 @@ PROG_NAME="$(follow_links "$BASH_SOURCE")"
# Handle the case where dart-sdk/bin has been symlinked to.
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
SDK_DIR="$(cd "${BIN_DIR}/.." ; pwd -P)"
SNAPSHOT="$BIN_DIR/snapshots/dartfmt.dart.snapshot"
DART="$BIN_DIR/dart"
if test -f "$SNAPSHOT"; then
# We are running the snapshot in the built SDK.
DART="$BIN_DIR/dart"
exec "$DART" "$SNAPSHOT" "$@"
DART_ROOT="$(cd "${SDK_DIR}/.." ; pwd -P)"
DARTFMT="$DART_ROOT/third_party/pkg/dart_style/bin/format.dart"
if [ -z "$DART_CONFIGURATION" ];
then
DART_CONFIGURATION="ReleaseIA32"
fi
if [[ `uname` == 'Darwin' ]]; then
BUILD_DIR="$DART_ROOT/xcodebuild/$DART_CONFIGURATION"
else
# We are running dartfmt from source in the development repo.
if [ -z "$DART_CONFIGURATION" ];
then
DART_CONFIGURATION="ReleaseIA32"
fi
BUILD_DIR="$DART_ROOT/out/$DART_CONFIGURATION"
fi
# TODO(pquitslund): this bit seems wrong, but was cribbed verbatim from pub
# Need to revisit and fix
if [[ `uname` == 'Darwin' ]];
then
BUILD_DIR="$SDK_DIR/../xcodebuild/$DART_CONFIGURATION"
else
BUILD_DIR="$SDK_DIR/../out/$DART_CONFIGURATION"
fi
PACKAGE_ROOT="$BUILD_DIR/packages/"
DART="$BUILD_DIR/dart-sdk/bin/dart"
PKG_DIR="$BUILD_DIR/packages"
DARTFMT="$SDK_DIR/../pkg/analyzer/bin/formatter.dart"
exec "$DART" "--package-root=$PKG_DIR" "$DARTFMT" "$@"
fi
exec "$DART" "--package-root=$PACKAGE_ROOT" "$DARTFMT" "$@"

View file

@ -11,27 +11,44 @@ call :follow_links "%DIR_NAME%", RETURNED_BIN_DIR
rem Get rid of surrounding quotes.
for %%i in ("%RETURNED_BIN_DIR%") do set BIN_DIR=%%~fi
set DART=%BIN_DIR%\dart
rem Get absolute full name for SDK_DIR.
for %%i in ("%BIN_DIR%\..\") do set SDK_DIR=%%~fi
rem Remove trailing backslash if there is one
IF %SDK_DIR:~-1%==\ set SDK_DIR=%SDK_DIR:~0,-1%
if %SDK_DIR:~-1%==\ set SDK_DIR=%SDK_DIR:~0,-1%
set DARTFMT=%SDK_DIR%\..\packages\analyzer\bin\formatter.dart
set DART=%BIN_DIR%\dart
set SNAPSHOT=%BIN_DIR%\snapshots\dartfmt.dart.snapshot
rem Get absolute full name for DART_ROOT.
for %%i in ("%SDK_DIR%\..\") do set DART_ROOT=%%~fi
rem Remove trailing backslash if there is one
if %DART_ROOT:~-1%==\ set DART_ROOT=%DART_ROOT:~0,-1%
if exist "%SNAPSHOT%" (
"%DART%" "%SNAPSHOT%" %*
) else (
"%DART%" "%DARTFMT%" %*
)
set DARTFMT=%DART_ROOT%\third_party\pkg\dart_style\bin\format.dart
rem DART_CONFIGURATION defaults to ReleaseIA32
if "%DART_CONFIGURATION%"=="" set DART_CONFIGURATION=ReleaseIA32
set BUILD_DIR=%DART_ROOT%\build\%DART_CONFIGURATION%
set PACKAGE_ROOT=%BUILD_DIR%\packages
"%DART%" "--package-root=%PACKAGE_ROOT%" "%DARTFMT%" %*
endlocal
exit /b %errorlevel%
rem Follow the symbolic links (junctions points) using `dir to determine the
rem canonical path. Output with a link looks something like this
rem
rem 01/03/2013 10:11 PM <JUNCTION> abc def
rem [c:\dart_bleeding\dart-repo.9\dart\build\ReleaseIA32\dart-sdk]
rem
rem So in the output of 'dir /a:l "targetdir"' we are looking for a filename
rem surrounded by right angle bracket and left square bracket. Once we get
rem the filename, which is name of the link, we recursively follow that.
:follow_links
setlocal
for %%i in (%1) do set result=%%~fi

29
sdk/bin/dartfmt_sdk Executable file
View file

@ -0,0 +1,29 @@
#!/bin/bash
# Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Run dart_style/bin/format.dart on the Dart VM. This script assumes the Dart
# SDK's directory structure.
function follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# 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)"
SDK_DIR="$(cd "${BIN_DIR}/.." ; pwd -P)"
SNAPSHOT="$BIN_DIR/snapshots/dartfmt.dart.snapshot"
# We are running the snapshot in the built SDK.
DART="$BIN_DIR/dart"
exec "$DART" "$SNAPSHOT" "$@"

44
sdk/bin/dartfmt_sdk.bat Normal file
View file

@ -0,0 +1,44 @@
@echo off
REM Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
REM for details. All rights reserved. Use of this source code is governed by a
REM BSD-style license that can be found in the LICENSE file.
setlocal
rem Handle the case where dart-sdk/bin has been symlinked to.
set DIR_NAME_WITH_SLASH=%~dp0
set DIR_NAME=%DIR_NAME_WITH_SLASH:~0,-1%%
call :follow_links "%DIR_NAME%", RETURNED_BIN_DIR
rem Get rid of surrounding quotes.
for %%i in ("%RETURNED_BIN_DIR%") do set BIN_DIR=%%~fi
set DART=%BIN_DIR%\dart
set SNAPSHOT=%BIN_DIR%\snapshots\dartfmt.dart.snapshot
"%DART%" "%SNAPSHOT%" %*
endlocal
exit /b %errorlevel%
rem Follow the symbolic links (junctions points) using `dir to determine the
rem canonical path. Output with a link looks something like this
rem
rem 01/03/2013 10:11 PM <JUNCTION> abc def
rem [c:\dart_bleeding\dart-repo.9\dart\build\ReleaseIA32\dart-sdk]
rem
rem So in the output of 'dir /a:l "targetdir"' we are looking for a filename
rem surrounded by right angle bracket and left square bracket. Once we get
rem the filename, which is name of the link, we recursively follow that.
:follow_links
setlocal
for %%i in (%1) do set result=%%~fi
set current=
for /f "usebackq tokens=2 delims=[]" %%i in (`dir /a:l "%~dp1" 2^>nul ^
^| find "> %~n1 ["`) do (
set current=%%i
)
if not "%current%"=="" call :follow_links "%current%", result
endlocal & set %~2=%result%
goto :eof
:end

View file

@ -112,7 +112,7 @@ def CopyShellScript(src_file, dest_dir):
def CopyDartScripts(home, sdk_root):
for executable in ['dart2js_sdk', 'dartanalyzer_sdk', 'dartfmt', 'docgen',
for executable in ['dart2js_sdk', 'dartanalyzer_sdk', 'dartfmt_sdk', 'docgen',
'dartdocgen', 'pub_sdk']:
CopyShellScript(os.path.join(home, 'sdk', 'bin', executable),
os.path.join(sdk_root, 'bin'))

View file

@ -18,7 +18,7 @@
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
'../../sdk/lib/_internal/libraries.dart',
'<(SHARED_INTERMEDIATE_DIR)/packages.stamp',
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../pkg/analyzer"])',
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../third_party/pkg/dart_style"])',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/dartfmt.dart.snapshot',
@ -27,7 +27,7 @@
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
'--snapshot=<(SHARED_INTERMEDIATE_DIR)/dartfmt.dart.snapshot',
'--package-root=<(PRODUCT_DIR)/packages/',
'../../pkg/analyzer/bin/formatter.dart',
'../../third_party/pkg/dart_style/bin/format.dart',
],
},
],