runBuilder function

Future<void> runBuilder (Builder builder, Iterable<AssetId> inputs, AssetReader reader, AssetWriter writer, Resolvers resolvers, { Logger logger, ResourceManager resourceManager, String rootPackage, StageTracker stageTracker: NoOpStageTracker.instance })

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.

Implementation

Future<void> runBuilder(Builder builder, Iterable<AssetId> inputs,
    AssetReader reader, AssetWriter writer, Resolvers resolvers,
    {Logger logger,
    ResourceManager resourceManager,
    String rootPackage,
    StageTracker stageTracker = NoOpStageTracker.instance}) async {
  var shouldDisposeResourceManager = resourceManager == null;
  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,
        rootPackage ?? input.package, resolvers, resourceManager, stageTracker);
    try {
      await builder.build(buildStep);
    } finally {
      await buildStep.complete();
    }
  }

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

  if (shouldDisposeResourceManager) {
    await resourceManager.disposeAll();
    await resourceManager.beforeExit();
  }
}