When using an aggregate builder, I notice that the generate_for option on the TargetBuilderConfig in the build.yaml changes behaviour. The builder will only output if the target builder is set to default where as for normal builders setting the generate_for does work as expected.
This is my folder structure
lib
- entity_a.dart
- entity_b.dart
protos
where using the default generate_for of **
seems to work and outputs one proto file with aggregated content in the protos folder. But upon setting the generate_for to lib/**.dart
it will stop outputting the proto file. But why?
This is my target build.yaml
targets:
$default:
builders:
package_name|builder_name:
enabled: true
generate_for:
- lib/**.dart
Which only works when removing the generate_for. And this is my build.yaml in my generator package.
builders:
builder_name:
import: "package:package_name/builders.dart"
builder_factories: ["build"]
build_extensions: {'$package$': ['protos/model.proto']}
build_to: source
auto_apply: root_package
And this is my builder
import 'package:build/build.dart';
import 'package:glob/glob.dart';
Builder build(BuilderOptions options) => ProtoBuilder();
class ProtoBuilder implements Builder {
static final _allFilesInLib = Glob('**.dart');
static AssetId _allDartFiles(BuildStep buildStep) {
return AssetId(
buildStep.inputId.package,
'protos/model.proto',
);
}
@override
Map<String, List<String>> get buildExtensions {
return const {
r'$package$': ['protos/model.proto'],
};
}
@override
Future<void> build(BuildStep buildStep) async {
final files = <String>[];
await for (final input in buildStep.findAssets(_allFilesInLib)) {
files.add(input.path);
}
final output = _allDartFiles(buildStep);
return buildStep.writeAsString(output, files.join('n'));
}
}