@@ -11,6 +11,7 @@ import 'package:path/path.dart' as p;
11
11
import 'package:pub_semver/pub_semver.dart' ;
12
12
13
13
import 'barback/asset_environment.dart' ;
14
+ import 'dart.dart' as dart;
14
15
import 'exceptions.dart' ;
15
16
import 'flutter.dart' as flutter;
16
17
import 'io.dart' ;
@@ -214,6 +215,8 @@ class Entrypoint {
214
215
_packageGraph = new PackageGraph .fromSolveResult (this , result);
215
216
packageGraph.loadTransformerCache ().clearIfOutdated (result.changedPackages);
216
217
218
+ writeTextFile (packagesFile, lockFile.packagesFile (cache, root.name));
219
+
217
220
try {
218
221
if (precompile) {
219
222
await _precompileDependencies (changed: result.changedPackages);
@@ -230,8 +233,6 @@ class Entrypoint {
230
233
// dependencies, it shouldn't fail unless that fails.
231
234
log.exception (error, stackTrace);
232
235
}
233
-
234
- writeTextFile (packagesFile, lockFile.packagesFile (cache, root.name));
235
236
}
236
237
237
238
/// Precompile any transformed dependencies of the entrypoint.
@@ -335,7 +336,8 @@ class Entrypoint {
335
336
Future precompileExecutables ({Iterable <String > changed}) async {
336
337
_deleteExecutableSnapshots (changed: changed);
337
338
338
- var executables = new Map .fromIterable (root.immediateDependencies,
339
+ var executables = new Map <String , List <AssetId >>.fromIterable (
340
+ root.immediateDependencies,
339
341
key: (dep) => dep.name,
340
342
value: (dep) => _executablesForPackage (dep.name));
341
343
@@ -354,25 +356,55 @@ class Entrypoint {
354
356
355
357
var packagesToLoad =
356
358
unionAll (executables.keys.map (packageGraph.transitiveDependencies))
357
- .map ((package) => package.name).toSet ();
358
- var executableIds = unionAll (
359
- executables.values.map ((ids) => ids.toSet ()));
360
- var environment = await AssetEnvironment .create (this , BarbackMode .RELEASE ,
361
- packages: packagesToLoad,
362
- entrypoints: executableIds,
363
- useDart2JS: false );
364
- environment.barback.errors.listen ((error) {
365
- log.error (log.red ("Build error:\n $error " ));
366
- });
359
+ .toSet ();
367
360
368
- await waitAndPrintErrors (executables.keys.map ((package) async {
369
- var dir = p.join (_snapshotPath, package);
370
- cleanDir (dir);
371
- await environment.precompileExecutables (package, dir,
372
- executableIds: executables[package]);
361
+ // Try to avoid starting up an asset server to precompile packages if
362
+ // possible. This is faster and produces better error messages.
363
+ if (packagesToLoad.every (
364
+ (package) => package.pubspec.transformers.isEmpty)) {
365
+ await _precompileExecutablesWithoutBarback (executables);
366
+ } else {
367
+ await _precompileExecutablesWithBarback (executables, packagesToLoad);
368
+ }
369
+ });
370
+ }
371
+
372
+ Future _precompileExecutablesWithoutBarback (
373
+ Map <String , List <AssetId >> executables) {
374
+ return waitAndPrintErrors (executables.keys.map ((package) {
375
+ var dir = p.join (_snapshotPath, package);
376
+ cleanDir (dir);
377
+ return waitAndPrintErrors (executables[package].map ((id) {
378
+ var url = p.toUri (packageGraph.packages[id.package].dir);
379
+ url = url.replace (path: p.url.join (url.path, id.path));
380
+ return dart.snapshot (
381
+ url, p.join (dir, p.url.basename (id.path) + '.snapshot' ),
382
+ packagesFile: p.toUri (packagesFile),
383
+ id: id);
373
384
}));
385
+ }));
386
+ }
387
+
388
+ Future _precompileExecutablesWithBarback (
389
+ Map <String , List <AssetId >> executables, Set <Package > packagesToLoad) async {
390
+ var executableIds = unionAll (
391
+ executables.values.map ((ids) => ids.toSet ()));
392
+ var environment = await AssetEnvironment .create (this , BarbackMode .RELEASE ,
393
+ packages: packagesToLoad.map ((package) => package.name),
394
+ entrypoints: executableIds,
395
+ useDart2JS: false );
396
+ environment.barback.errors.listen ((error) {
397
+ log.error (log.red ("Build error:\n $error " ));
374
398
});
399
+
400
+ await waitAndPrintErrors (executables.keys.map ((package) async {
401
+ var dir = p.join (_snapshotPath, package);
402
+ cleanDir (dir);
403
+ await environment.precompileExecutables (package, dir,
404
+ executableIds: executables[package]);
405
+ }));
375
406
}
407
+
376
408
377
409
/// Deletes outdated cached executable snapshots.
378
410
///
0 commit comments