Let docgen detect a dart-sdk directory that's differently named, and do it correctly on bleeding edge

BUG=
R=ricow@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42112 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
alanknight@google.com 2014-12-04 17:10:15 +00:00
parent 2323df0dab
commit 71dd6daaad
4 changed files with 22 additions and 18 deletions

View file

@ -55,7 +55,8 @@ void main(List<String> arguments) {
pubScript: pubScript,
noDocs: options['no-docs'],
startPage: startPage,
indentJSON: indentJSON);
indentJSON: indentJSON,
sdk: options['sdk']);
}
/**

View file

@ -44,7 +44,7 @@ Future<bool> docgen(List<String> files, {String packageRoot,
bool includeDependentPackages: false, bool compile: false,
bool serve: false, bool noDocs: false, String startPage,
String pubScript : 'pub', String dartBinary: 'dart',
bool indentJSON: false}) {
bool indentJSON: false, String sdk}) {
var result;
if (!noDocs) {
viewer.ensureMovedViewerCode();
@ -55,7 +55,7 @@ Future<bool> docgen(List<String> files, {String packageRoot,
excludeLibraries: excludeLibraries,
includeDependentPackages: includeDependentPackages,
startPage: startPage, pubScriptValue: pubScript,
dartBinaryValue: dartBinary, indentJSON: indentJSON);
dartBinaryValue: dartBinary, indentJSON: indentJSON, sdk: sdk);
viewer.addBackViewerCode();
if (compile || serve) {
result.then((success) {

View file

@ -61,7 +61,7 @@ Future<bool> generateDocumentation(List<String> files, {String packageRoot,
bool parseSdk: false, String introFileName: '',
out: DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries: const [], bool
includeDependentPackages: false, String startPage, String dartBinaryValue,
String pubScriptValue, bool indentJSON: false}) {
String pubScriptValue, bool indentJSON: false, String sdk}) {
_excluded = excludeLibraries;
dartBinary = dartBinaryValue;
pubScript = pubScriptValue;
@ -80,7 +80,7 @@ Future<bool> generateDocumentation(List<String> files, {String packageRoot,
}
return getMirrorSystem(allLibraries, includePrivate,
packageRoot: updatedPackageRoot, parseSdk: parseSdk)
packageRoot: updatedPackageRoot, parseSdk: parseSdk, sdkRoot: sdk)
.then((MirrorSystem mirrorSystem) {
if (mirrorSystem.libraries.isEmpty) {
throw new StateError('No library mirrors were created.');
@ -110,7 +110,8 @@ Future<bool> generateDocumentation(List<String> files, {String packageRoot,
/// Analyzes set of libraries by getting a mirror system and triggers the
/// documentation of the libraries.
Future<MirrorSystem> getMirrorSystem(List<Uri> libraries,
bool includePrivate, {String packageRoot, bool parseSdk: false}) {
bool includePrivate, {String packageRoot, bool parseSdk: false,
String sdkRoot}) {
if (libraries.isEmpty) throw new StateError('No Libraries.');
includePrivateMembers = includePrivate;
@ -118,10 +119,12 @@ Future<MirrorSystem> getMirrorSystem(List<Uri> libraries,
// Finds the root of SDK library based off the location of docgen.
// We have two different places to look, depending if we're in a development
// repo or in a built SDK, either sdk or dart-sdk respectively
var root = rootDirectory;
var sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk')));
if (!new Directory(sdkRoot).existsSync()) {
sdkRoot = path.normalize(path.absolute(path.join(root, 'dart-sdk')));
if (sdkRoot == null) {
var root = rootDirectory;
sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk')));
if (!new Directory(sdkRoot).existsSync()) {
sdkRoot = path.normalize(path.absolute(path.join(root, 'dart-sdk')));
}
}
logger.info('SDK Root: ${sdkRoot}');
return analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot);

View file

@ -12,19 +12,19 @@ import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';
/// Helper accessor to determine the full pathname of the root of the dart
/// checkout. We can be in one of three situations:
/// 1) Running from pkg/docgen/bin/docgen.dart
/// 2) Running from a snapshot in a build,
/// e.g. xcodebuild/ReleaseIA32/dart-sdk/bin
/// 3) Running from a built distribution,
/// e.g. ...somename/dart-sdk/bin/snapshots
/// checkout if we are running without the --sdk parameter specified. That
/// normally means we are running directly from source, and we expect to
/// find the root as the directory above 'pkg'. The only other time this
/// would happen is running a snapshot directly, rather than from the
/// dartdocgen script, where we look for the dart-sdk directory. If not
/// using the script and not in a normal directory structure, you'll need
/// to pass the --sdk parameter.
String get rootDirectory {
if (_rootDirectoryCache != null) return _rootDirectoryCache;
var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath()));
var root = scriptDir;
var base = path.basename(root);
// When we find dart-sdk or sdk we are one level below the root.
while (base != 'dart-sdk' && base != 'sdk' && base != 'pkg') {
while (base != 'dart-sdk' && base != 'pkg') {
root = path.dirname(root);
base = path.basename(root);
if (root == base) {