Commit 1f6ed67b authored by Ian Hickson's avatar Ian Hickson

Make 'flutter analyze' support analyzing arbitrary files

Before we didn't know how to find the packages of random files. Now we do.
parent 5fdb0749
...@@ -34,9 +34,24 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -34,9 +34,24 @@ class AnalyzeCommand extends FlutterCommand {
Set<String> pubSpecDirectories = new Set<String>(); Set<String> pubSpecDirectories = new Set<String>();
List<String> dartFiles = argResults.rest.toList(); List<String> dartFiles = argResults.rest.toList();
bool foundAnyInCurrentDirectory = false;
bool foundAnyInFlutterRepo = false;
for (String file in dartFiles) { for (String file in dartFiles) {
// TODO(ianh): figure out how dartanalyzer decides which .packages file to use when given a random file file = path.normalize(path.absolute(file));
pubSpecDirectories.add(path.dirname(file)); String root = path.rootPrefix(file);
while (file != root) {
file = path.dirname(file);
if (FileSystemEntity.isFileSync(path.join(file, 'pubspec.yaml'))) {
pubSpecDirectories.add(file);
if (file == path.normalize(path.absolute(ArtifactStore.flutterRoot))) {
foundAnyInFlutterRepo = true;
} else if (file == path.normalize(path.absolute(path.current))) {
foundAnyInCurrentDirectory = true;
}
break;
}
}
} }
if (argResults['flutter-repo']) { if (argResults['flutter-repo']) {
...@@ -129,8 +144,6 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -129,8 +144,6 @@ class AnalyzeCommand extends FlutterCommand {
} }
} }
bool foundAnyInCurrentDirectory = false;
if (argResults['current-directory']) { if (argResults['current-directory']) {
// ./*.dart // ./*.dart
Directory currentDirectory = new Directory('.'); Directory currentDirectory = new Directory('.');
...@@ -204,7 +217,7 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -204,7 +217,7 @@ class AnalyzeCommand extends FlutterCommand {
} }
} }
if (hadInconsistentRequirements) { if (hadInconsistentRequirements) {
if (argResults['flutter-repo']) if (foundAnyInFlutterRepo)
logging.warning('You may need to run "dart ${path.normalize(path.relative(path.join(ArtifactStore.flutterRoot, 'dev/update_packages.dart')))} --upgrade".'); logging.warning('You may need to run "dart ${path.normalize(path.relative(path.join(ArtifactStore.flutterRoot, 'dev/update_packages.dart')))} --upgrade".');
if (foundAnyInCurrentDirectory) if (foundAnyInCurrentDirectory)
logging.warning('You may need to run "pub upgrade".'); logging.warning('You may need to run "pub upgrade".');
......
...@@ -147,9 +147,9 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -147,9 +147,9 @@ class FlutterCommandRunner extends CommandRunner {
Logger.root.level = Level.FINE; Logger.root.level = Level.FINE;
_globalResults = globalResults; _globalResults = globalResults;
ArtifactStore.flutterRoot = globalResults['flutter-root']; ArtifactStore.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root']));
if (globalResults.wasParsed('package-root')) if (globalResults.wasParsed('package-root'))
ArtifactStore.packageRoot = globalResults['package-root']; ArtifactStore.packageRoot = path.normalize(path.absolute(globalResults['package-root']));
if (globalResults['version']) { if (globalResults['version']) {
print(getVersion(ArtifactStore.flutterRoot)); print(getVersion(ArtifactStore.flutterRoot));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment