runBuilder function Null safety

Future<void> runBuilder(
  1. Builder builder,
  2. Iterable<AssetId> inputs,
  3. AssetReader reader,
  4. AssetWriter writer,
  5. Resolvers? resolvers,
  6. {Logger? logger,
  7. ResourceManager? resourceManager,
  8. StageTracker stageTracker = NoOpStageTracker.instance,
  9. void reportUnusedAssetsForInput(
    1. AssetId input,
    2. Iterable<AssetId> assets

Run builder with each asset in inputs as the primary input.

Builds for all inputs are run asynchronously and ordering is not guaranteed. The log instance inside the builds will be scoped to logger which is defaulted to a Logger name 'runBuilder'.

If a resourceManager is provided it will be used and it will not be automatically disposed of (its up to the caller to dispose of it later). If one is not provided then one will be created and disposed at the end of this function call.

If reportUnusedAssetsForInput is provided then all calls to BuildStep.reportUnusedAssets in builder will be forwarded to this function with the associated primary input.


Future<void> runBuilder(Builder builder, Iterable<AssetId> inputs,
    AssetReader reader, AssetWriter writer, Resolvers? resolvers,
    {Logger? logger,
    ResourceManager? resourceManager,
    StageTracker stageTracker = NoOpStageTracker.instance,
    void Function(AssetId input, Iterable<AssetId> assets)?
        reportUnusedAssetsForInput}) async {
  var shouldDisposeResourceManager = resourceManager == null;
  final resources = resourceManager ?? ResourceManager();
  logger ??= Logger('runBuilder');
  //TODO(nbosch) check overlapping outputs?
  Future<void> buildForInput(AssetId input) async {
    var outputs = expectedOutputs(builder, input);
    if (outputs.isEmpty) return;
    var buildStep = BuildStepImpl(
        input, outputs, reader, writer, resolvers, resources,
        stageTracker: stageTracker,
        reportUnusedAssets: reportUnusedAssetsForInput == null
            ? null
            : (assets) => reportUnusedAssetsForInput(input, assets));
    try {
    } finally {
      await buildStep.complete();

  await scopeLogAsync(() => Future.wait(, logger);

  if (shouldDisposeResourceManager) {
    await resources.disposeAll();
    await resources.beforeExit();