Skip to content

Commit d153010

Browse files
committed
[flutter_tools] Fix flutter doctor path validation for symlinked SDKs
When Flutter is installed via a symlink or directory junction (such as via Scoop on Windows), binaries found on PATH resolve to their target destination while flutterRoot was compared using its unresolved path. This caused FlutterValidator to issue bogus warnings that flutter and dart binaries were outside the Flutter SDK checkout. Resolve flutterRoot symbolically when verifying SDK binary containment, falling back to the unresolved path if resolution fails, while preserving the user-configured path for display and recommendations. Fixes #191936
1 parent 0e6f506 commit d153010

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

‎packages/flutter_tools/lib/src/doctor.dart‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,13 @@ class FlutterValidator extends DoctorValidator {
739739
);
740740
}
741741
final String resolvedFlutterPath = flutterBin.resolveSymbolicLinksSync();
742-
if (!_filePathContainsDirPath(flutterRoot, resolvedFlutterPath)) {
742+
var resolvedFlutterRoot = flutterRoot;
743+
try {
744+
resolvedFlutterRoot = _fileSystem.directory(flutterRoot).resolveSymbolicLinksSync();
745+
} on FileSystemException {
746+
// If the root does not exist or cannot be resolved, retain the un-resolved path.
747+
}
748+
if (!_filePathContainsDirPath(resolvedFlutterRoot, resolvedFlutterPath)) {
743749
final hint =
744750
'Warning: `$binary` on your path resolves to '
745751
'$resolvedFlutterPath, which is not inside your current Flutter '

‎packages/flutter_tools/test/general.shard/flutter_validator_test.dart‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,67 @@ void main() {
648648
);
649649
});
650650

651+
testWithoutContext(
652+
'allows flutter and dart binaries from a symlinked Flutter SDK on Windows',
653+
() async {
654+
const flutterRoot = r'C:\sdk\flutter_current';
655+
const realFlutterRoot = r'C:\sdk\real_flutter';
656+
const osName = 'Microsoft Windows';
657+
final FileSystem fs = MemoryFileSystem.test(style: FileSystemStyle.windows);
658+
fs.directory(fs.path.join(realFlutterRoot, 'bin')).createSync(recursive: true);
659+
fs.file(fs.path.join(realFlutterRoot, 'bin', 'flutter')).createSync();
660+
fs.file(fs.path.join(realFlutterRoot, 'bin', 'dart')).createSync();
661+
fs.link(flutterRoot).createSync(realFlutterRoot);
662+
663+
final flutterValidator = FlutterValidator(
664+
platform: FakePlatform(operatingSystem: 'windows', localeName: 'en_US.UTF-8'),
665+
flutterVersion: () => FakeFlutterVersion(frameworkVersion: '1.0.0', branch: 'beta'),
666+
devToolsVersion: () => '2.8.0',
667+
artifacts: Artifacts.test(),
668+
fileSystem: fs,
669+
processManager: FakeProcessManager.empty(),
670+
operatingSystemUtils: FakeOperatingSystemUtils(
671+
name: osName,
672+
fs: fs,
673+
whichLookup: <String, File>{
674+
'flutter': fs.file(fs.path.join(flutterRoot, 'bin', 'flutter')),
675+
'dart': fs.file(fs.path.join(flutterRoot, 'bin', 'dart')),
676+
},
677+
),
678+
flutterRoot: () => flutterRoot,
679+
featureFlags: TestFeatureFlags(),
680+
);
681+
682+
final ValidationResult result = await flutterValidator.validate();
683+
expect(
684+
result,
685+
_matchDoctorValidation(
686+
validationType: ValidationType.success,
687+
statusInfo: 'Channel beta, 1.0.0, on $osName, locale en_US.UTF-8',
688+
messages: contains(
689+
const ValidationMessage(
690+
r'Flutter version 1.0.0 on channel beta at C:\sdk\flutter_current',
691+
),
692+
),
693+
),
694+
);
695+
expect(
696+
result.messages.where(
697+
(ValidationMessage message) =>
698+
message.message.contains('Warning: `flutter` on your path resolves to'),
699+
),
700+
isEmpty,
701+
);
702+
expect(
703+
result.messages.where(
704+
(ValidationMessage message) =>
705+
message.message.contains('Warning: `dart` on your path resolves to'),
706+
),
707+
isEmpty,
708+
);
709+
},
710+
);
711+
651712
testWithoutContext('detects flutter and dart from outside flutter sdk', () async {
652713
final FileSystem fs = MemoryFileSystem.test();
653714
final flutterValidator = FlutterValidator(

0 commit comments

Comments
 (0)