build method
Generates the outputs for a given BuildStep
.
Implementation
@override
Future<void> build(BuildStep buildStep) async {
await _buildPool.withResource(() async {
var dartEntrypointId = buildStep.inputId;
var isAppEntrypoint = await _isAppEntryPoint(dartEntrypointId, buildStep);
if (!isAppEntrypoint) return;
var moduleId =
buildStep.inputId.changeExtension(moduleExtension(vmPlatform));
var module = Module.fromJson(
json.decode(await buildStep.readAsString(moduleId))
as Map<String, dynamic>);
List<Module> transitiveModules;
try {
transitiveModules = await module
.computeTransitiveDependencies(buildStep, throwIfUnsupported: true);
} on UnsupportedModules catch (e) {
var librariesString = (await e.exactLibraries(buildStep).toList())
.map((lib) => AssetId(lib.id.package,
lib.id.path.replaceFirst(moduleLibraryExtension, '.dart')))
.join('\n');
log.warning('''
Skipping compiling ${buildStep.inputId} for the vm because some of its
transitive libraries have sdk dependencies that not supported on this platform:
$librariesString
https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings
''');
return;
}
var transitiveKernelModules = [
module.primarySource.changeExtension(vmKernelModuleExtension),
for (var module in transitiveModules.reversed)
module.primarySource.changeExtension(vmKernelModuleExtension),
];
var appContents = [
for (var dependencyId in transitiveKernelModules)
...await buildStep.readAsBytes(dependencyId)
];
await buildStep.writeAsBytes(
buildStep.inputId.changeExtension(vmKernelEntrypointExtension),
appContents);
});
}