Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 0240489

Browse files
authored
Merge pull request #22 from dart-lang/directory_check
fix an issue with getSdkDir
2 parents 97828ad + 183e28d commit 0240489

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.1.2
4+
5+
- Fix a bug in `getSdkDir` (#21)
6+
37
## 0.1.1
48

59
- Updated to the output for indeterminate progress

lib/cli_util.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import 'dart:io';
99

1010
import 'package:path/path.dart' as path;
1111

12+
import 'src/utils.dart';
13+
1214
/// Return the path to the current Dart SDK.
1315
///
1416
/// This first checks for an explicit SDK listed on the command-line
@@ -17,6 +19,7 @@ import 'package:path/path.dart' as path;
1719
/// [Platform.resolvedExecutable] API.
1820
///
1921
/// Callers should generally prefer using the [getSdkPath] function.
22+
@Deprecated('Clients should generally prefer getSdkPath()')
2023
Directory getSdkDir([List<String> cliArgs]) {
2124
// Look for --dart-sdk on the command line.
2225
if (cliArgs != null) {
@@ -41,20 +44,17 @@ Directory getSdkDir([List<String> cliArgs]) {
4144
// Look relative to the dart executable.
4245
File platformExecutable = new File(Platform.executable);
4346
Directory sdkDirectory = platformExecutable.parent.parent;
44-
if (_isSdkDir(sdkDirectory)) return sdkDirectory;
47+
if (isSdkDir(sdkDirectory)) return sdkDirectory;
4548

4649
// Handle the case where Platform.executable is a sibling of the SDK directory
4750
// (this happens during internal testing).
4851
sdkDirectory =
4952
new Directory(path.join(platformExecutable.parent.path, 'dart-sdk'));
50-
if (_isSdkDir(sdkDirectory)) return sdkDirectory;
53+
if (isSdkDir(sdkDirectory)) return sdkDirectory;
5154

5255
// Use `Platform.resolvedExecutable`.
5356
return new Directory(getSdkPath());
5457
}
5558

5659
/// Return the path to the current Dart SDK.
5760
String getSdkPath() => path.dirname(path.dirname(Platform.resolvedExecutable));
58-
59-
bool _isSdkDir(Directory dir) =>
60-
FileSystemEntity.isDirectorySync(path.join(dir.path, 'version'));

lib/src/utils.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:path/path.dart' as path;
8+
9+
bool isSdkDir(Directory dir) =>
10+
FileSystemEntity.isFileSync(path.join(dir.path, 'version'));

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: cli_util
2-
version: 0.1.1
2+
version: 0.1.2
33
author: Dart Team <[email protected]>
44
description: A library to help in building Dart command-line apps.
55
homepage: https://github.com/dart-lang/cli_util

test/cli_util_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:io';
6+
57
import 'package:cli_util/cli_util.dart';
8+
import 'package:cli_util/src/utils.dart';
69
import 'package:test/test.dart';
710

811
main() => defineTests();
912

1013
void defineTests() {
1114
group('getSdkDir', () {
1215
test('arg parsing', () {
16+
// ignore: deprecated_member_use
1317
expect(getSdkDir(['--dart-sdk', '/dart/sdk']).path, equals('/dart/sdk'));
18+
// ignore: deprecated_member_use
1419
expect(getSdkDir(['--dart-sdk=/dart/sdk']).path, equals('/dart/sdk'));
1520
});
1621

1722
test('finds the SDK without cli args', () {
23+
// ignore: deprecated_member_use
1824
expect(getSdkDir(), isNotNull);
1925
});
2026
});
@@ -24,4 +30,10 @@ void defineTests() {
2430
expect(getSdkPath(), isNotNull);
2531
});
2632
});
33+
34+
group('utils', () {
35+
test('isSdkDir', () {
36+
expect(isSdkDir(new Directory(getSdkPath())), true);
37+
});
38+
});
2739
}

0 commit comments

Comments
 (0)