Skip to content

Commit

Permalink
Sync .packages file as a normal input file. (flutter#16467)
Browse files Browse the repository at this point in the history
* Sync .packages file as regular file.

Currently .packages file is treated specially as DevFSStringContent to accommodate package-file rewrite when it is sent to the device for dart1 compilation. In dart2 we need to treat .packages as regular file because from frontend perspective it's just a normal input file.
  • Loading branch information
aam authored Apr 11, 2018
1 parent fea7d3c commit 4c22123
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/flutter_tools/lib/src/devfs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,10 @@ class DevFS {
await _scanDirectory(rootDirectory,
recursive: true,
fileFilter: fileFilter);
final bool previewDart2 = generator != null;
if (fs.isFileSync(_packagesFilePath)) {
printTrace('Scanning package files');
await _scanPackages(fileFilter);
await _scanPackages(fileFilter, previewDart2);
}
if (bundle != null) {
printTrace('Scanning asset files');
Expand Down Expand Up @@ -475,7 +476,7 @@ class DevFS {
assetPathsToEvict.add(archivePath);
}
});
if (generator != null) {
if (previewDart2) {
// We run generator even if [dirtyEntries] was empty because we want
// to keep logic of accepting/rejecting generator's output simple:
// we must accept/reject generator's output after every [update] call.
Expand Down Expand Up @@ -580,9 +581,11 @@ class DevFS {
return true;
}
assert((file is Link) || (file is File));
if (ignoreDotFiles && fs.path.basename(file.path).startsWith('.')) {
// Skip dot files.
return true;
final String basename = fs.path.basename(file.path);
if (ignoreDotFiles && basename.startsWith('.')) {
// Skip dot files, but not the '.packages' file (even though in dart1
// mode devfs['.packages'] will be overwritten with synthesized string content).
return basename != '.packages';
}
return false;
}
Expand Down Expand Up @@ -688,7 +691,7 @@ class DevFS {
);
}

Future<Null> _scanPackages(Set<String> fileFilter) async {
Future<Null> _scanPackages(Set<String> fileFilter, bool previewDart2) async {
StringBuffer sb;
final PackageMap packageMap = new PackageMap(_packagesFilePath);

Expand Down Expand Up @@ -721,6 +724,14 @@ class DevFS {
sb.writeln('$packageName:$directoryUriOnDevice');
}
}
if (previewDart2) {
// When in previewDart2 mode we don't update .packages-file entry
// so actual file will get invalidated in frontend.
// We don't need to synthesize device-correct .packages file because
// it is not going to be used on the device anyway - compilation
// is done on the host.
return;
}
if (sb != null) {
final DevFSContent content = _entries[fs.path.toUri('.packages')];
if (content is DevFSStringContent && content.string == sb.toString()) {
Expand Down

0 comments on commit 4c22123

Please sign in to comment.