Simplify path handling logic in dependency checker and devFS (#8414)
* Simplify path handling logic in dependency checker and devFS Simplification will make it easier to port this to Windows. * Roll Engine to 0a7b177c330367904597a6129b3eb653d29dfca0
This commit is contained in:
parent
adf3b90df2
commit
e7bde11cc3
@ -1 +1 @@
|
|||||||
335daf19304ffbbf96c1e1ff840e546f17ce50d6
|
0a7b177c330367904597a6129b3eb653d29dfca0
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import '../artifacts.dart';
|
import '../artifacts.dart';
|
||||||
import '../base/file_system.dart';
|
|
||||||
import '../base/process.dart';
|
import '../base/process.dart';
|
||||||
|
|
||||||
class DartDependencySetBuilder {
|
class DartDependencySetBuilder {
|
||||||
@ -30,16 +29,6 @@ class DartDependencySetBuilder {
|
|||||||
|
|
||||||
String output = runSyncAndThrowStdErrOnError(args);
|
String output = runSyncAndThrowStdErrOnError(args);
|
||||||
|
|
||||||
final List<String> lines = LineSplitter.split(output).toList();
|
return new Set<String>.from(LineSplitter.split(output));
|
||||||
final Set<String> minimalDependencies = new Set<String>();
|
|
||||||
for (String line in lines) {
|
|
||||||
if (!line.startsWith('package:')) {
|
|
||||||
// We convert the uris so that they are relative to the project
|
|
||||||
// root.
|
|
||||||
line = fs.path.relative(line, from: projectRootPath);
|
|
||||||
}
|
|
||||||
minimalDependencies.add(line);
|
|
||||||
}
|
|
||||||
return minimalDependencies;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
import 'asset.dart';
|
import 'asset.dart';
|
||||||
import 'base/file_system.dart';
|
import 'base/file_system.dart';
|
||||||
import 'dart/dependencies.dart';
|
import 'dart/dependencies.dart';
|
||||||
import 'dart/package_map.dart';
|
|
||||||
import 'globals.dart';
|
import 'globals.dart';
|
||||||
|
|
||||||
class DependencyChecker {
|
class DependencyChecker {
|
||||||
@ -18,10 +17,7 @@ class DependencyChecker {
|
|||||||
/// if it cannot be determined.
|
/// if it cannot be determined.
|
||||||
bool check(DateTime threshold) {
|
bool check(DateTime threshold) {
|
||||||
_dependencies.clear();
|
_dependencies.clear();
|
||||||
PackageMap packageMap;
|
|
||||||
// Parse the package map.
|
|
||||||
try {
|
try {
|
||||||
packageMap = new PackageMap(builder.packagesFilePath)..load();
|
|
||||||
_dependencies.add(builder.packagesFilePath);
|
_dependencies.add(builder.packagesFilePath);
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
printTrace('DependencyChecker: could not parse .packages file:\n$e\n$st');
|
printTrace('DependencyChecker: could not parse .packages file:\n$e\n$st');
|
||||||
@ -29,16 +25,7 @@ class DependencyChecker {
|
|||||||
}
|
}
|
||||||
// Build the set of Dart dependencies.
|
// Build the set of Dart dependencies.
|
||||||
try {
|
try {
|
||||||
Set<String> dependencies = builder.build();
|
_dependencies.addAll(builder.build());
|
||||||
for (String path in dependencies) {
|
|
||||||
// Ensure all paths are absolute.
|
|
||||||
if (path.startsWith('package:')) {
|
|
||||||
path = packageMap.pathForPackage(Uri.parse(path));
|
|
||||||
} else {
|
|
||||||
path = fs.path.join(builder.projectRootPath, path);
|
|
||||||
}
|
|
||||||
_dependencies.add(path);
|
|
||||||
}
|
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
printTrace('DependencyChecker: error determining .dart dependencies:\n$e\n$st');
|
printTrace('DependencyChecker: error determining .dart dependencies:\n$e\n$st');
|
||||||
return true;
|
return true;
|
||||||
|
@ -461,10 +461,10 @@ class DevFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _shouldIgnore(String devicePath) {
|
bool _shouldIgnore(String devicePath) {
|
||||||
List<String> ignoredPrefixes = <String>['android/',
|
List<String> ignoredPrefixes = <String>['android' + fs.path.separator,
|
||||||
getBuildDirectory(),
|
getBuildDirectory(),
|
||||||
'ios/',
|
'ios' + fs.path.separator,
|
||||||
'.pub/'];
|
'.pub' + fs.path.separator];
|
||||||
for (String ignoredPrefix in ignoredPrefixes) {
|
for (String ignoredPrefix in ignoredPrefixes) {
|
||||||
if (devicePath.startsWith(ignoredPrefix))
|
if (devicePath.startsWith(ignoredPrefix))
|
||||||
return true;
|
return true;
|
||||||
@ -473,16 +473,14 @@ class DevFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _scanDirectory(Directory directory,
|
Future<bool> _scanDirectory(Directory directory,
|
||||||
{String directoryName,
|
{String directoryNameOnDevice,
|
||||||
bool recursive: false,
|
bool recursive: false,
|
||||||
bool ignoreDotFiles: true,
|
bool ignoreDotFiles: true,
|
||||||
String packagesDirectoryName,
|
|
||||||
Set<String> fileFilter}) async {
|
Set<String> fileFilter}) async {
|
||||||
String prefix = directoryName;
|
if (directoryNameOnDevice == null) {
|
||||||
if (prefix == null) {
|
directoryNameOnDevice = fs.path.relative(directory.path, from: rootDirectory.path);
|
||||||
prefix = fs.path.relative(directory.path, from: rootDirectory.path);
|
if (directoryNameOnDevice == '.')
|
||||||
if (prefix == '.')
|
directoryNameOnDevice = '';
|
||||||
prefix = '';
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Stream<FileSystemEntity> files =
|
Stream<FileSystemEntity> files =
|
||||||
@ -508,24 +506,8 @@ class DevFS {
|
|||||||
}
|
}
|
||||||
final String relativePath =
|
final String relativePath =
|
||||||
fs.path.relative(file.path, from: directory.path);
|
fs.path.relative(file.path, from: directory.path);
|
||||||
final String devicePath = fs.path.join(prefix, relativePath);
|
final String devicePath = fs.path.join(directoryNameOnDevice, relativePath);
|
||||||
bool filtered = false;
|
if ((fileFilter != null) && !fileFilter.contains(file.absolute.path)) {
|
||||||
if ((fileFilter != null) &&
|
|
||||||
!fileFilter.contains(devicePath)) {
|
|
||||||
if (packagesDirectoryName != null) {
|
|
||||||
// Double check the filter for packages/packagename/
|
|
||||||
final String packagesDevicePath =
|
|
||||||
fs.path.join(packagesDirectoryName, relativePath);
|
|
||||||
if (!fileFilter.contains(packagesDevicePath)) {
|
|
||||||
// File was not in the filter set.
|
|
||||||
filtered = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// File was not in the filter set.
|
|
||||||
filtered = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (filtered) {
|
|
||||||
// Skip files that are not included in the filter.
|
// Skip files that are not included in the filter.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -548,27 +530,26 @@ class DevFS {
|
|||||||
PackageMap packageMap = new PackageMap(_packagesFilePath);
|
PackageMap packageMap = new PackageMap(_packagesFilePath);
|
||||||
|
|
||||||
for (String packageName in packageMap.map.keys) {
|
for (String packageName in packageMap.map.keys) {
|
||||||
Uri uri = packageMap.map[packageName];
|
Uri packageUri = packageMap.map[packageName];
|
||||||
// This project's own package.
|
String packagePath = fs.path.fromUri(packageUri);
|
||||||
final bool isProjectPackage = uri.toString() == 'lib/';
|
Directory packageDirectory = fs.directory(packageUri);
|
||||||
final String directoryName =
|
String directoryNameOnDevice = fs.path.join('packages', packageName);
|
||||||
isProjectPackage ? 'lib' : fs.path.join('packages', packageName);
|
bool packageExists;
|
||||||
// If this is the project's package, we need to pass both
|
|
||||||
// package:<package_name> and lib/ as paths to be checked against
|
if (fs.path.isWithin(rootDirectory.path, packagePath)) {
|
||||||
// the filter because we must support both package: imports and relative
|
// We already scanned everything under the root directory.
|
||||||
// path imports within the project's own code.
|
packageExists = packageDirectory.existsSync();
|
||||||
final String packagesDirectoryName =
|
directoryNameOnDevice = fs.path.relative(packagePath, from: rootDirectory.path);
|
||||||
isProjectPackage ? fs.path.join('packages', packageName) : null;
|
} else {
|
||||||
Directory directory = fs.directory(uri);
|
packageExists =
|
||||||
bool packageExists =
|
await _scanDirectory(packageDirectory,
|
||||||
await _scanDirectory(directory,
|
directoryNameOnDevice: directoryNameOnDevice,
|
||||||
directoryName: directoryName,
|
recursive: true,
|
||||||
recursive: true,
|
fileFilter: fileFilter);
|
||||||
packagesDirectoryName: packagesDirectoryName,
|
}
|
||||||
fileFilter: fileFilter);
|
|
||||||
if (packageExists) {
|
if (packageExists) {
|
||||||
sb ??= new StringBuffer();
|
sb ??= new StringBuffer();
|
||||||
sb.writeln('$packageName:$directoryName');
|
sb.writeln('$packageName:$directoryNameOnDevice');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sb != null) {
|
if (sb != null) {
|
||||||
|
@ -98,18 +98,7 @@ class HotRunner extends ResidentRunner {
|
|||||||
new DartDependencySetBuilder(
|
new DartDependencySetBuilder(
|
||||||
mainPath, projectRootPath, packagesFilePath);
|
mainPath, projectRootPath, packagesFilePath);
|
||||||
try {
|
try {
|
||||||
Set<String> dependencies = dartDependencySetBuilder.build();
|
_dartDependencies = new Set<String>.from(dartDependencySetBuilder.build());
|
||||||
_dartDependencies = new Set<String>();
|
|
||||||
for (String path in dependencies) {
|
|
||||||
// We need to tweak package: uris so that they reflect their devFS
|
|
||||||
// location.
|
|
||||||
if (path.startsWith('package:')) {
|
|
||||||
// Swap out package: for packages/ because we place all package
|
|
||||||
// sources under packages/.
|
|
||||||
path = path.replaceFirst('package:', 'packages/');
|
|
||||||
}
|
|
||||||
_dartDependencies.add(path);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
printStatus('Error detected in application source code:', emphasis: true);
|
printStatus('Error detected in application source code:', emphasis: true);
|
||||||
printError('$error');
|
printError('$error');
|
||||||
|
@ -21,8 +21,8 @@ void main() {
|
|||||||
DartDependencySetBuilder builder =
|
DartDependencySetBuilder builder =
|
||||||
new DartDependencySetBuilder(mainPath, testPath, packagesPath);
|
new DartDependencySetBuilder(mainPath, testPath, packagesPath);
|
||||||
Set<String> dependencies = builder.build();
|
Set<String> dependencies = builder.build();
|
||||||
expect(dependencies.contains('main.dart'), isTrue);
|
expect(dependencies.contains(mainPath), isTrue);
|
||||||
expect(dependencies.contains('foo.dart'), isTrue);
|
expect(dependencies.contains(fs.path.join(testPath, 'foo.dart')), isTrue);
|
||||||
});
|
});
|
||||||
testUsingContext('syntax_error', () {
|
testUsingContext('syntax_error', () {
|
||||||
final String testPath = fs.path.join(dataPath, 'syntax_error');
|
final String testPath = fs.path.join(dataPath, 'syntax_error');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user