- 
                Notifications
    
You must be signed in to change notification settings  - Fork 110
 
Description
Hi, I am writing this seeking for help, since it's quite complicated to find resources on the best way to create Builders 🙂
For our project, we created our own Builder for a specific task. From an input file containing annotated elements, we'd like to obtain a .rpc.dart generated file. Then, we want to apply the retrofit builder  on this generated file, to obtain the output, a generated file with .g.dart extension.
For this, we created rpc_generator using source_gen. The build.yaml file looks like this:
builders:
  rpc_generator:
    import: "package:rpc_generator/rpc_generator.dart"
    builder_factories: ["rpcBuilder"]
    build_extensions: { ".dart": [".rpc.dart"] }
    auto_apply: dependents
    build_to: source
    runs_before: ["retrofit_generator"]
    applies_builders: ["retrofit_generator"]
rpc_generator.dart contains the following:
Builder rpcBuilder(BuilderOptions options) => generatorFactoryBuilder(options);
And finally, the builder and generator themselves:
Builder generatorFactoryBuilder(BuilderOptions _) {
  return PartBuilder(
    [const RpcGenerator()],
    '.rpc.dart',
    header: '''
    // coverage:ignore-file
    // GENERATED CODE - DO NOT MODIFY BY HAND
        ''',
  );
}
class RpcGenerator extends Generator {
  const RpcGenerator();
  @override
  Future<String> generate(LibraryReader library, BuildStep buildStep) async {
     ...
  }
}
In local, we have this build.yaml file to call our Builder on our files:
global_options:
  freezed:
    runs_before:
      - json_serializable
  json_serializable:
    runs_before:
      - retrofit_generator
      - rpc_generator
targets:
  $default:
    builders:
      ...
      rpc_generator:rpcBuilder:
        generate_for:
          - lib/api/rpc/*.api.dart;
          - lib/api/*.api.dart
My questions are the following:
- We used a 
PartBuilderbecause we have to keep both outputs from ourBuilderandretrofitbuilder. But is it possible to do better for this task? Like have aSharedPartBuilderthat first generate a.g.dartcontaining our generated code, then runretrofitbuilder on this generated code and combine both outputs in a single.g.dartfile ? - When launching 
dart run build_runner build --delete-conflicting-outputsin local, a warning appears:Warning: Configuring `rpc_generator:rpcBuilder` in target `data:data` but this is not a known Builder. Yet, our files are generating correctly. However, when our CI launches the same command through GitHub Actions, the files are not generated. I do not understand why this warning is triggered and why thebuild_runnerbehavior changes from local to remote ? - In our local 
build.yamlfile, we HAVE to call the builder like this:rpc_generator:rpcBuilder:, otherwise the files are not generated if we only putrpc_generator:. From what I understood, if the builder has the same name as its package, we should be able to callrpc_generator:directly without having to specify the builder factory. Do you have an idea why this is happening? 
Thanks in advance for your help 🙂 I can provide more details if needed.