Skip to content

Commit 6241b55

Browse files
authored
Fix flutter root exception (#1714)
* Move SDK library expectation to all subcategories * Retype has been removed * Improve error message when FLUTTER_ROOT is needed but not set * Add a test for the new exception * Make the test work even when FLUTTER_ROOT is already in the environemnt * Allow the pub warning as well, since if pub get hasn't been run yet that's the error users will see
1 parent adbd2bb commit 6241b55

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lib/src/dartdoc_options.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,13 +1022,12 @@ Future<List<DartdocOption>> createDartdocOptions() async {
10221022
// This could be a ArgOnly, but trying to not provide too many ways
10231023
// to set the flutter root.
10241024
new DartdocOptionSyntheticOnly<String>(
1025-
'flutterRoot',
1026-
(DartdocSyntheticOption<String> option, Directory dir) =>
1027-
resolveTildePath(Platform.environment['FLUTTER_ROOT']),
1028-
isDir: true,
1029-
help: 'Root of the Flutter SDK, specified from environment.',
1030-
mustExist: true,
1031-
),
1025+
'flutterRoot',
1026+
(DartdocSyntheticOption<String> option, Directory dir) =>
1027+
resolveTildePath(Platform.environment['FLUTTER_ROOT']),
1028+
isDir: true,
1029+
help: 'Root of the Flutter SDK, specified from environment.',
1030+
mustExist: true),
10321031
new DartdocOptionArgOnly<bool>('hideSdkText', false,
10331032
hide: true,
10341033
help:
@@ -1120,8 +1119,12 @@ Future<List<DartdocOption>> createDartdocOptions() async {
11201119
if (!option.parent['sdkDocs'].valueAt(dir) &&
11211120
(option.root['topLevelPackageMeta'].valueAt(dir) as PackageMeta)
11221121
.requiresFlutter) {
1123-
return pathLib.join(option.root['flutterRoot'].valueAt(dir), 'bin',
1124-
'cache', 'dart-sdk');
1122+
String flutterRoot = option.root['flutterRoot'].valueAt(dir);
1123+
if (flutterRoot == null) {
1124+
throw new DartdocOptionError(
1125+
'Top level package requires Flutter but FLUTTER_ROOT environment variable not set');
1126+
}
1127+
return pathLib.join(flutterRoot, 'bin', 'cache', 'dart-sdk');
11251128
}
11261129
return defaultSdkDir.absolute.path;
11271130
}, help: 'Path to the SDK directory.', isDir: true, mustExist: true),

test/compare_output_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ String get _testPackageDocsPath =>
2727
String get _testPackagePath =>
2828
pathLib.fromUri(_currentFileUri.resolve('../testing/test_package'));
2929

30+
String get _testPackageFlutterPluginPath => pathLib
31+
.fromUri(_currentFileUri.resolve('../testing/test_package_flutter_plugin'));
32+
3033
void main() {
3134
group('compare outputs', () {
3235
Directory tempDir;
@@ -44,6 +47,21 @@ void main() {
4447
}
4548
});
4649

50+
test('Validate missing FLUTTER_ROOT exception is clean', () async {
51+
var args = <String>[dartdocBin];
52+
var result = Process.runSync(Platform.resolvedExecutable, args,
53+
environment: new Map.from(Platform.environment)
54+
..remove('FLUTTER_ROOT'),
55+
includeParentEnvironment: false,
56+
workingDirectory: _testPackageFlutterPluginPath);
57+
expect(
58+
result.stderr,
59+
contains(new RegExp(
60+
'Top level package requires Flutter but FLUTTER_ROOT environment variable not set|test_package_flutter_plugin requires the Flutter SDK, version solving failed')));
61+
expect(result.stderr, isNot(contains('asynchronous gap')));
62+
expect(result.exitCode, isNot(0));
63+
});
64+
4765
test("Validate --version works", () async {
4866
var args = <String>[dartdocBin, '--version'];
4967
var result = Process.runSync(Platform.resolvedExecutable, args,

0 commit comments

Comments
 (0)