precompileExecutables method

Future<void> precompileExecutables()

Precompiles all _builtExecutables.

Implementation

Future<void> precompileExecutables() async {
  final executables = await _builtExecutables;

  if (executables.isEmpty) return;

  await log.progress('Building package executables', () async {
    if (isCachedGlobal) {
      /// Global snapshots might linger in the cache if we don't remove old
      /// snapshots when it is re-activated.
      cleanDir(_snapshotPath);
    } else {
      ensureDir(_snapshotPath);
    }
    // Don't do more than `Platform.numberOfProcessors - 1` compilations
    // concurrently. Though at least one.
    final pool = Pool(max(Platform.numberOfProcessors - 1, 1));
    return waitAndPrintErrors(
      executables.map((executable) async {
        await pool.withResource(() async {
          return _precompileExecutable(executable);
        });
      }),
    );
  });
}