Skip to content

Commit

Permalink
sdkDir returns null if unable to locate Dart SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
sunglim committed Nov 27, 2013
1 parent 03d0170 commit adfe184
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/grinder_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import 'dart:io';
import 'grinder.dart';

/**
* Return the path to the current Dart SDK.
* Return the path to the current Dart SDK. This will return `null` if we are
* unable to locate the Dart SDK.
*/
Directory get sdkDir {
// look for --dart-sdk on the command line
Expand All @@ -27,8 +28,10 @@ Directory get sdkDir {
}

// look relative to the dart executable
// TODO: file a bug re: the path to the executable and the cwd
return new File(Platform.executable).parent.parent;
// TODO: file a bug re: the path to the executable and the cwd.
Directory maybeSdkDirectory = new File(Platform.executable).parent.parent;
return joinFile(maybeSdkDirectory, ['version']).existsSync() ?
maybeSdkDirectory : null;
}

File get dartVM => joinFile(sdkDir, ['bin', _execName('dart')]);
Expand Down
6 changes: 5 additions & 1 deletion test/grinder_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

library grinder_utils_test;

import 'dart:io';

import 'package:grinder/grinder.dart';
import 'package:unittest/unittest.dart';

main() {
group('grinder.utils', () {
test('get sdkDir', () {
expect(sdkDir, isNotNull);
if (Platform.environment['DART_SDK'] != null) {
expect(sdkDir, isNotNull);
}
});
});
}

0 comments on commit adfe184

Please sign in to comment.