runMaterialCompiler function

int runMaterialCompiler(
  1. MaterialCompiler compiler,
  2. List<String> arguments
)

What a backend package's compiler executable runs: compiler asked for the request in the file arguments[0], its section written to the file arguments[1]. Answers the exit code: 0 for a section written, 65 for a refusal (its sentence on stderr), 64 for arguments that are not two files.

How a backend from outside ships its materials in a project. Its package names the executable in its pubspec, beside the backend it is:

flutter3d_backend:
  backend: acme_vk          # MaterialCompiler.backend
  section: acme_vk          # MaterialCompiler.bundleSection
  compiler: bin/material_compiler.dart

and the executable is one line, exit(runMaterialCompiler(const AcmeVkMaterialCompiler(), arguments)). flutter3d_build's hook finds it among the project's dependencies and asks it for its section of the engine's bundle and of every plugin material, as it asks impellerc.

Implementation

int runMaterialCompiler(MaterialCompiler compiler, List<String> arguments) {
  if (arguments.length != 2) {
    stderr.writeln(
      'usage: <compiler> <request.json> <section>: the request a build wrote, '
      'and where the section goes',
    );
    return 64;
  }
  final MaterialCompileResult result;
  try {
    result = compiler.compile(
      decodeMaterialCompileRequest(File(arguments[0]).readAsStringSync()),
    );
  } on MaterialCompileException catch (refused) {
    stderr.writeln(refused.message);
    return 65;
  } on FormatException catch (error) {
    stderr.writeln('the request did not read: ${error.message}');
    return 64;
  }
  final section = result.section;
  File(
    arguments[1],
  ).writeAsBytesSync(Uint8List.sublistView(section), flush: true);
  for (final note in result.notes) {
    stdout.writeln(note);
  }
  return 0;
}