projectShaderChecks function
What doctor says about a project's shaders (D15, D19): whether its
hook is there to write the engine's bundle, whether its pubspec ships
what the hook writes, whether the bundle there was compiled on the SDK
that builds it now — dart and engineRevision, when known — and
whether every installed plugin's material was compiled in.
A project no GPU backend is a dependency of gets no line; neither does a
project whose packages cannot be resolved, which flutter pub get is the
answer to before anything here is.
Implementation
List<DoctorCheck> projectShaderChecks(
Directory project, {
String? dart,
String? engineRevision,
}) {
final PluginDiscovery discovery;
try {
discovery = discoverPlugins(project);
} on PluginDiscoveryException {
return const <DoctorCheck>[];
}
const backends = <String>{
'flutter3d_impeller',
'flutter3d_webgl',
'flutter3d_webgpu',
};
if (!discovery.dependencies.any(backends.contains)) {
return const <DoctorCheck>[];
}
final checks = <DoctorCheck>[];
final hooked = _hooked(project);
checks.add(
hooked
? const DoctorCheck(
'Shader hook',
DoctorStatus.ok,
'hook/build.dart runs buildAssets, which writes the engine\'s '
'bundle for this SDK',
)
: const DoctorCheck(
'Shader hook',
DoctorStatus.note,
'no hook/build.dart calling buildAssets: the application loads '
'the bundle flutter3d_impeller ships, which carries every '
'stage and holds only on the SDK it was published with',
fix:
'run `flutter3d init`, which writes the hook, or add it by '
'hand (see the quickstart)',
),
);
final pubspec = File('${project.path}/pubspec.yaml').readAsStringSync();
final listed = RegExp(
r'^\s*-\s*flutter3d_generated/shaders/\s*$',
multiLine: true,
).hasMatch(pubspec);
if (hooked) {
checks.add(
listed
? const DoctorCheck(
'Shader assets',
DoctorStatus.ok,
'pubspec.yaml ships flutter3d_generated/shaders/',
)
: const DoctorCheck(
'Shader assets',
DoctorStatus.problem,
'pubspec.yaml does not list flutter3d_generated/shaders/, so '
'the bundle the hook writes is not in the application',
fix:
'add `- flutter3d_generated/shaders/` under flutter: assets: '
'(Flutter does not bundle a directory\'s subdirectories)',
),
);
}
final bundle = File('${project.path}/${EngineBundleStamp.projectAsset}');
if (hooked && !bundle.existsSync()) {
checks.add(
const DoctorCheck(
'Shader bundle',
DoctorStatus.note,
'not built yet',
fix:
'build once (`flutter build` or `flutter run`); the hook writes it',
),
);
} else if (bundle.existsSync()) {
checks.add(
_bundleCheck(bundle, dart: dart, engineRevision: engineRevision),
);
}
final missing = <String>[
for (final package in discovery.packages)
for (final source in _materialSources(package))
if (!_compiledFor(project, source)) '${package.name}: ${source.path}',
];
if (hooked && missing.isNotEmpty) {
checks.add(
DoctorCheck(
'Plugin materials',
DoctorStatus.note,
'${missing.length} not compiled into the project yet: '
'${missing.take(3).join(', ')}${missing.length > 3 ? ', …' : ''}',
fix:
'build once; the hook compiles every installed plugin\'s materials',
),
);
}
return checks;
}