Automatically pass SDK into docgen.dart, and use the SDK for running

pub and the Dart binary. This removes the need to have the SDK in the
PATH when running docgen.

R=efortuna@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32632 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
dgrove@google.com 2014-02-12 23:23:25 +00:00
parent 1b705cbdf0
commit 22d649cf9a
4 changed files with 39 additions and 15 deletions

View file

@ -35,6 +35,12 @@ void main(List<String> arguments) {
var scriptDir = path.dirname(Platform.script.toFilePath());
var introduction = includeSdk ? '' : options['introduction'];
var pubScript = options['sdk'] != null ?
path.join(options['sdk'], 'bin', 'pub') : 'pub';
var dartBinary = options['sdk'] != null ?
path.join(options['sdk'], 'bin', 'dart') : 'dart';
docgen(_files,
packageRoot: options['package-root'],
outputToYaml: !options['json'],
@ -47,6 +53,8 @@ void main(List<String> arguments) {
excludeLibraries: excludedLibraries,
includeDependentPackages: options['include-dependent-packages'],
serve: options['serve'],
dartBinary: dartBinary,
pubScript: pubScript,
noDocs: options['no-docs'],
startPage: startPage);
}
@ -136,6 +144,9 @@ ArgParser _initArgParser() {
'in the directory with its pubspec. Includes documentation for all '
'of its dependent packages.',
defaultsTo: true, negatable: true);
parser.addOption('sdk',
help: 'SDK directory',
defaultsTo: null);
parser.addOption('start-page',
help: 'By default the viewer will start at the SDK introduction page.'
'To start at some other page, e.g. for a package, provide the name '

View file

@ -115,7 +115,8 @@ Future<bool> docgen(List<String> files, {String packageRoot,
bool parseSdk: false, bool append: false, String introFileName: '',
out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [],
bool includeDependentPackages: false, bool serve: false,
bool noDocs: false, String startPage}) {
bool noDocs: false, String startPage,
String pubScript, String dartBinary}) {
var result;
if (!noDocs) {
_Viewer.ensureMovedViewerCode();
@ -125,7 +126,7 @@ Future<bool> docgen(List<String> files, {String packageRoot,
introFileName: introFileName, out: out,
excludeLibraries: excludeLibraries,
includeDependentPackages: includeDependentPackages,
startPage: startPage);
startPage: startPage, pubScript: pubScript, dartBinary: dartBinary);
_Viewer.addBackViewerCode();
if (serve) {
result.then((success) {
@ -247,6 +248,12 @@ class _Generator {
/// --exclude-lib.
static List<String> _excluded;
/// The path of the pub script.
static String _pubScript;
/// The path of Dart binary.
static String _dartBinary;
/// Logger for printing out progress of documentation generation.
static Logger logger = new Logger('Docgen');
@ -265,9 +272,13 @@ class _Generator {
bool includeSdk: false, bool parseSdk: false, bool append: false,
String introFileName: '', out: _DEFAULT_OUTPUT_DIRECTORY,
List<String> excludeLibraries : const [],
bool includeDependentPackages: false, String startPage}) {
bool includeDependentPackages: false, String startPage,
String dartBinary, String pubScript}) {
_excluded = excludeLibraries;
_includePrivate = includePrivate;
_pubScript = pubScript;
_dartBinary = dartBinary;
logger.onRecord.listen((record) => print(record.message));
_ensureOutputDirectory(out, append);
@ -595,7 +606,7 @@ class _Generator {
static List<String> _allDependentPackageDirs(String packageDirectory) {
var packageName = Library.packageNameFor(packageDirectory);
if (packageName == '') return [];
var dependentsJson = Process.runSync('pub', ['list-package-dirs'],
var dependentsJson = Process.runSync(_pubScript, ['list-package-dirs'],
workingDirectory: packageDirectory, runInShell: true);
if (dependentsJson.exitCode != 0) {
print(dependentsJson.stderr);
@ -683,8 +694,9 @@ class _Viewer {
/// Move the generated json/yaml docs directory to the dartdoc-viewer
/// directory, to run as a webpage.
static void _moveDirectoryAndServe() {
var processResult = Process.runSync('pub', ['update'], runInShell: true,
workingDirectory: path.join(_dartdocViewerDir.path, 'client'));
var processResult = Process.runSync(_Generator._pubScript, ['upgrade'],
runInShell: true, workingDirectory: path.join(_dartdocViewerDir.path,
'client'));
print('process output: ${processResult.stdout}');
print('process stderr: ${processResult.stderr}');
@ -700,9 +712,9 @@ class _Viewer {
if (webDocsDir.existsSync()) {
// Compile the code to JavaScript so we can run on any browser.
print('Compile app to JavaScript for viewing.');
var processResult = Process.runSync('dart', ['deploy.dart'],
workingDirectory : path.join(_dartdocViewerDir.path, 'client'),
runInShell: true);
var processResult = Process.runSync(_Generator._dartBinary,
['deploy.dart'], workingDirectory : path.join(_dartdocViewerDir.path,
'client'), runInShell: true);
print('process output: ${processResult.stdout}');
print('process stderr: ${processResult.stderr}');
_runServer();

View file

@ -18,17 +18,18 @@ 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)"
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 "$@"
"--package-root=$BIN_DIR/../packages/" $SNAPSHOT \
docgen "--sdk=$SDK_DIR" "$@"
else
exec "$BIN_DIR"/dart \
"--package-root=$BIN_DIR/../packages/" \
"$BIN_DIR/../pkg/docgen/bin/docgen.dart" "$@"
"$BIN_DIR/../../pkg/docgen/bin/docgen.dart" "--sdk=$SDK_DIR" "$@"
fi

View file

@ -25,9 +25,9 @@ if not defined DART_CONFIGURATION set DART_CONFIGURATION=ReleaseIA32
set BUILD_DIR=%SDK_DIR%\..\build\%DART_CONFIGURATION%
if exist "%SNAPSHOT%" (
"%DART%" "%SNAPSHOT%" "docgen" %*
"%DART%" "%SNAPSHOT%" "docgen" "--sdk=%SDK_DIR" %*
) else (
"%BUILD_DIR%\dart-sdk\bin\dart" "--package-root=%BUILD_DIR%\packages" "%DOCGEN%" %*
"%BUILD_DIR%\dart-sdk\bin\dart" "--package-root=%BUILD_DIR%\packages" "%DOCGEN%" "--sdk=%SDK_DIR" %*
)
endlocal