Add a snapshot for docgen and use it in the build

R=efortuna@google.com, ricow@google.com, rnystrom@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32025 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
alanknight@google.com 2014-01-27 18:40:34 +00:00
parent fed22c0018
commit 3730236bdf
8 changed files with 103 additions and 11 deletions

View file

@ -87,7 +87,7 @@ def GenerateAllDocs(docgen_options):
# from the SDK and includes only the ones from pkg. So right now our only option
# is to do everything in one pass.
doc_dir = join(DART_DIR, 'pkg')
cmd_lst = [DART_EXECUTABLE, '--old_gen_heap_size=1024',
cmd_lst = [DART_EXECUTABLE,
'--package-root=%s' % PACKAGE_ROOT, 'docgen.dart', '--include-sdk' ]
cmd_str = ' '.join(AddUserDocgenOptions(cmd_lst, docgen_options, True))
# Try to run all pkg docs together at once as it's fastest.

View file

@ -27,9 +27,7 @@ set BUILD_DIR=%SDK_DIR%\..\build\%DART_CONFIGURATION%
if exist "%SNAPSHOT%" (
"%DART%" "%SNAPSHOT%" "dartdoc" "--library-root=%SDK_DIR%" %*
) else (
:: The trailing forward slash in --package-root is required because of issue
:: 9499.
"%BUILD_DIR%\dart-sdk\bin\dart" "--package-root=%BUILD_DIR%\packages/" "%DARTDOC%" %*
"%BUILD_DIR%\dart-sdk\bin\dart" "--package-root=%BUILD_DIR%\packages" "%DARTDOC%" %*
)
endlocal

34
sdk/bin/docgen Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
# Copyright (c) 2014, 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.
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)"
unset SNAPSHOT
SNAPSHOT="$BIN_DIR/snapshots/utils_wrapper.dart.snapshot"
if test -f $SNAPSHOT; then
# TODO(ahe): Remove the following line when we are relatively sure it works.
echo Using snapshot $SNAPSHOT 1>&2
exec "$BIN_DIR"/dart \
"--package-root=$BIN_DIR/../packages/" $SNAPSHOT docgen "$@"
else
exec "$BIN_DIR"/dart \
"--package-root=$BIN_DIR/../packages/" \
"$BIN_DIR/../pkg/docgen/bin/docgen.dart" "$@"
fi

49
sdk/bin/docgen.bat Normal file
View file

@ -0,0 +1,49 @@
@echo off
REM Copyright (c) 2014, 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
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%
set DOCGEN=%SDK_DIR%\pkg\docgen\bin\docgen.dart
set DART=%BIN_DIR%\dart
set SNAPSHOT=%BIN_DIR%\snapshots\utils_wrapper.dart.snapshot
if not defined DART_CONFIGURATION set DART_CONFIGURATION=ReleaseIA32
set BUILD_DIR=%SDK_DIR%\..\build\%DART_CONFIGURATION%
if exist "%SNAPSHOT%" (
"%DART%" "%SNAPSHOT%" "dartdoc" "--library-root=%SDK_DIR%" %*
) else (
"%BUILD_DIR%\dart-sdk\bin\dart" "--package-root=%BUILD_DIR%\packages" "%DOCGEN%" %*
)
endlocal
exit /b %errorlevel%
:follow_links
setlocal
for %%i in (%1) do set result=%%~fi
set current=
for /f "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

@ -105,7 +105,7 @@ def CopyShellScript(src_file, dest_dir):
def CopyDartScripts(home, sdk_root):
for executable in ['dart2js', 'dartanalyzer', 'dartdoc', 'pub']:
for executable in ['dart2js', 'dartanalyzer', 'dartdoc', 'docgen', 'pub']:
CopyShellScript(os.path.join(home, 'sdk', 'bin', executable),
os.path.join(sdk_root, 'bin'))

View file

@ -63,6 +63,8 @@
'../../sdk/bin/dart.bat',
'../../sdk/bin/dart2js',
'../../sdk/bin/dart2js.bat',
'../../sdk/bin/docgen',
'../../sdk/bin/docgen.bat',
'../../tools/only_in_release_mode.py',
# We sit inside the api_docs directory, so make sure it has run
# before we do. Otherwise it might run later and delete us.
@ -76,10 +78,7 @@
'../../tools/only_in_release_mode.py',
'<@(_outputs)',
'--',
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
'--old_gen_heap_size=1024',
'--package-root=<(PRODUCT_DIR)/packages/',
'../../pkg/docgen/bin/docgen.dart',
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart-sdk/bin/docgen<(script_suffix)',
'--out=<(PRODUCT_DIR)/api_docs/docgen',
'--json',
'--include-sdk',

View file

@ -35,6 +35,7 @@
'--output_dir=<(SHARED_INTERMEDIATE_DIR)',
'--dart2js_main=sdk/lib/_internal/compiler/implementation/dart2js.dart',
'--dartdoc_main=sdk/lib/_internal/dartdoc/bin/dartdoc.dart',
'--docgen_main=pkg/docgen/bin/docgen.dart',
'--package_root=<(PRODUCT_DIR)/packages/',
],
},

View file

@ -19,11 +19,13 @@ Future<String> getVersion(var rootPath) {
Future<String> getSnapshotGenerationFile(var args, var rootPath) {
var dart2js = rootPath.resolve(args["dart2js_main"]);
var dartdoc = rootPath.resolve(args["dartdoc_main"]);
var docgen = rootPath.resolve(args["docgen_main"]);
return getVersion(rootPath).then((version) {
var snapshotGenerationText =
"""
import '${dart2js.toFilePath(windows: false)}' as dart2jsMain;
import '${dartdoc.toFilePath(windows: false)}' as dartdocMain;
import '${docgen.toFilePath(windows: false)}' as docgenMain;
import 'dart:io';
void main(List<String> arguments) {
@ -34,6 +36,8 @@ void main(List<String> arguments) {
dart2jsMain.main(arguments.skip(1).toList());
} else if (tool == "dartdoc") {
dartdocMain.main(arguments.skip(1).toList());
} else if (tool == "docgen") {
docgenMain.main(arguments.skip(1).toList());
}
}
@ -72,6 +76,9 @@ Future createSnapshot(var dart_file, var packageRoot) {
dart_file])
.then((result) {
if (result.exitCode != 0) {
print("Could not generate snapshot: result code ${result.exitCode}");
print(result.stdout);
print(result.stderr);
throw "Could not generate snapshot";
}
});
@ -80,11 +87,14 @@ Future createSnapshot(var dart_file, var packageRoot) {
/**
* Takes the following arguments:
* --output_dir=val The full path to the output_dir.
* --dart2js_main=val The path to the dart2js main script releative to root.
* --dart2js_main=val The path to the dart2js main script relative to root.
* --dartdoc_main=val The path to the dartdoc main script relative to root.
* --docgen_main=val The path to the docgen main script relative to root.
* --package-root=val The package-root used to find packages for the snapshot.
*/
void main(List<String> arguments) {
var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main",
"--package_root"];
"--docgen_main", "--package_root"];
var args = {};
for (var argument in arguments) {
var argumentSplit = argument.split("=");
@ -96,6 +106,7 @@ void main(List<String> arguments) {
}
if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main";
if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main";
if (!args.containsKey("docgen_main")) throw "Please specify docgen_main";
if (!args.containsKey("output_dir")) throw "Please specify output_dir";
if (!args.containsKey("package_root")) throw "Please specify package_root";