diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d12d6..7a7bfa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.2 + +- Fix a bug in `getSdkDir` (#21) + ## 0.1.1 - Updated to the output for indeterminate progress diff --git a/lib/cli_util.dart b/lib/cli_util.dart index 5d32e78..d58be7a 100644 --- a/lib/cli_util.dart +++ b/lib/cli_util.dart @@ -9,6 +9,8 @@ import 'dart:io'; import 'package:path/path.dart' as path; +import 'src/utils.dart'; + /// Return the path to the current Dart SDK. /// /// This first checks for an explicit SDK listed on the command-line @@ -17,6 +19,7 @@ import 'package:path/path.dart' as path; /// [Platform.resolvedExecutable] API. /// /// Callers should generally prefer using the [getSdkPath] function. +@Deprecated('Clients should generally prefer getSdkPath()') Directory getSdkDir([List cliArgs]) { // Look for --dart-sdk on the command line. if (cliArgs != null) { @@ -41,13 +44,13 @@ Directory getSdkDir([List cliArgs]) { // Look relative to the dart executable. File platformExecutable = new File(Platform.executable); Directory sdkDirectory = platformExecutable.parent.parent; - if (_isSdkDir(sdkDirectory)) return sdkDirectory; + if (isSdkDir(sdkDirectory)) return sdkDirectory; // Handle the case where Platform.executable is a sibling of the SDK directory // (this happens during internal testing). sdkDirectory = new Directory(path.join(platformExecutable.parent.path, 'dart-sdk')); - if (_isSdkDir(sdkDirectory)) return sdkDirectory; + if (isSdkDir(sdkDirectory)) return sdkDirectory; // Use `Platform.resolvedExecutable`. return new Directory(getSdkPath()); @@ -55,6 +58,3 @@ Directory getSdkDir([List cliArgs]) { /// Return the path to the current Dart SDK. String getSdkPath() => path.dirname(path.dirname(Platform.resolvedExecutable)); - -bool _isSdkDir(Directory dir) => - FileSystemEntity.isDirectorySync(path.join(dir.path, 'version')); diff --git a/lib/src/utils.dart b/lib/src/utils.dart new file mode 100644 index 0000000..66bab2f --- /dev/null +++ b/lib/src/utils.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2017, 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. + +import 'dart:io'; + +import 'package:path/path.dart' as path; + +bool isSdkDir(Directory dir) => + FileSystemEntity.isFileSync(path.join(dir.path, 'version')); diff --git a/pubspec.yaml b/pubspec.yaml index baead10..af9075d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: cli_util -version: 0.1.1 +version: 0.1.2 author: Dart Team description: A library to help in building Dart command-line apps. homepage: https://github.com/dart-lang/cli_util diff --git a/test/cli_util_test.dart b/test/cli_util_test.dart index 7cbdcf9..82fb83c 100644 --- a/test/cli_util_test.dart +++ b/test/cli_util_test.dart @@ -2,7 +2,10 @@ // 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. +import 'dart:io'; + import 'package:cli_util/cli_util.dart'; +import 'package:cli_util/src/utils.dart'; import 'package:test/test.dart'; main() => defineTests(); @@ -10,11 +13,14 @@ main() => defineTests(); void defineTests() { group('getSdkDir', () { test('arg parsing', () { + // ignore: deprecated_member_use expect(getSdkDir(['--dart-sdk', '/dart/sdk']).path, equals('/dart/sdk')); + // ignore: deprecated_member_use expect(getSdkDir(['--dart-sdk=/dart/sdk']).path, equals('/dart/sdk')); }); test('finds the SDK without cli args', () { + // ignore: deprecated_member_use expect(getSdkDir(), isNotNull); }); }); @@ -24,4 +30,10 @@ void defineTests() { expect(getSdkPath(), isNotNull); }); }); + + group('utils', () { + test('isSdkDir', () { + expect(isSdkDir(new Directory(getSdkPath())), true); + }); + }); }