Unverified Commit 4c221231 authored by Alexander Aprelev's avatar Alexander Aprelev Committed by GitHub

Sync .packages file as a normal input file. (#16467)

* 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.
parent fea7d3c8
...@@ -422,9 +422,10 @@ class DevFS { ...@@ -422,9 +422,10 @@ class DevFS {
await _scanDirectory(rootDirectory, await _scanDirectory(rootDirectory,
recursive: true, recursive: true,
fileFilter: fileFilter); fileFilter: fileFilter);
final bool previewDart2 = generator != null;
if (fs.isFileSync(_packagesFilePath)) { if (fs.isFileSync(_packagesFilePath)) {
printTrace('Scanning package files'); printTrace('Scanning package files');
await _scanPackages(fileFilter); await _scanPackages(fileFilter, previewDart2);
} }
if (bundle != null) { if (bundle != null) {
printTrace('Scanning asset files'); printTrace('Scanning asset files');
...@@ -475,7 +476,7 @@ class DevFS { ...@@ -475,7 +476,7 @@ class DevFS {
assetPathsToEvict.add(archivePath); assetPathsToEvict.add(archivePath);
} }
}); });
if (generator != null) { if (previewDart2) {
// We run generator even if [dirtyEntries] was empty because we want // We run generator even if [dirtyEntries] was empty because we want
// to keep logic of accepting/rejecting generator's output simple: // to keep logic of accepting/rejecting generator's output simple:
// we must accept/reject generator's output after every [update] call. // we must accept/reject generator's output after every [update] call.
...@@ -580,9 +581,11 @@ class DevFS { ...@@ -580,9 +581,11 @@ class DevFS {
return true; return true;
} }
assert((file is Link) || (file is File)); assert((file is Link) || (file is File));
if (ignoreDotFiles && fs.path.basename(file.path).startsWith('.')) { final String basename = fs.path.basename(file.path);
// Skip dot files. if (ignoreDotFiles && basename.startsWith('.')) {
return true; // 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; return false;
} }
...@@ -688,7 +691,7 @@ class DevFS { ...@@ -688,7 +691,7 @@ class DevFS {
); );
} }
Future<Null> _scanPackages(Set<String> fileFilter) async { Future<Null> _scanPackages(Set<String> fileFilter, bool previewDart2) async {
StringBuffer sb; StringBuffer sb;
final PackageMap packageMap = new PackageMap(_packagesFilePath); final PackageMap packageMap = new PackageMap(_packagesFilePath);
...@@ -721,6 +724,14 @@ class DevFS { ...@@ -721,6 +724,14 @@ class DevFS {
sb.writeln('$packageName:$directoryUriOnDevice'); 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) { if (sb != null) {
final DevFSContent content = _entries[fs.path.toUri('.packages')]; final DevFSContent content = _entries[fs.path.toUri('.packages')];
if (content is DevFSStringContent && content.string == sb.toString()) { if (content is DevFSStringContent && content.string == sb.toString()) {
......
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