Skip to content

Commit

Permalink
Merge pull request #5 from sunglim/sdkDir
Browse files Browse the repository at this point in the history
sdkDir returns null if unable to locate Dart SDK
  • Loading branch information
devoncarew committed Nov 27, 2013
2 parents 03d0170 + adfe184 commit d71ef28
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
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
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 d71ef28

Please sign in to comment.