Skip to content

Commit 7102d39

Browse files
leoafariasnex3
andauthored
Added parent look up for dart-sdk license (#61)
Co-authored-by: Natalie Weizenbaum <[email protected]>
1 parent d4130af commit 7102d39

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 1.0.0-beta.11
22

3+
* Properly load the Dart SDK license when it's in the directory above the SDK,
4+
as in a Homebrew installation.
5+
36
* Use the latest version of the `xml` package.
47

58
# 1.0.0-beta.10

lib/src/utils.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ Future<String> get license => _licenseMemo.runOnce(() async {
8686
// from Dart Team packages.
8787
var licenses = <String, List<String>>{};
8888
var thisPackageLicense = _readLicense(".");
89+
8990
if (thisPackageLicense != null) {
9091
licenses[thisPackageLicense] = [humanName.value];
9192
}
9293

93-
licenses
94-
.putIfAbsent(
95-
File(p.join(sdkDir.path, 'LICENSE')).readAsStringSync(), () => [])
96-
.add("Dart SDK");
94+
licenses.putIfAbsent(_readSdkLicense(), () => []).add("Dart SDK");
9795

9896
// Parse the package config rather than the pubspec so we include transitive
9997
// dependencies. This also includes dev dependencies, but it's possible those
@@ -132,6 +130,19 @@ final _licenseMemo = AsyncMemoizer<String>();
132130
final _licenseRegExp =
133131
RegExp(r"^(([a-zA-Z0-9]+[-_])?(LICENSE|COPYING)|UNLICENSE)(\..*)?$");
134132

133+
/// Returns the contents of the `LICENSE` file in [sdkDir].
134+
String _readSdkLicense() {
135+
final dartLicense = File(p.join(sdkDir.path, 'LICENSE'));
136+
137+
if (dartLicense.existsSync()) {
138+
return dartLicense.readAsStringSync();
139+
} else {
140+
// Homebrew's Dart SDK installation puts the license in the directory above
141+
// the SDK, so if it's not in the SDK itself check there.
142+
return File(p.join(sdkDir.parent.path, 'LICENSE')).readAsStringSync();
143+
}
144+
}
145+
135146
/// Returns the contents of the `LICENSE` file in [dir], with various possible
136147
/// filenames and extensions, or `null`.
137148
String _readLicense(String dir) {

0 commit comments

Comments
 (0)