smithy-lang / smithy-dafny

Apache License 2.0
7 stars 8 forks source link

Add missing configuration/features to Smithy build plugin #356

Open robin-aws opened 1 month ago

robin-aws commented 1 month ago

The number and complexity of CLI arguments are getting out of hand. We already have an alternate interface into the code generation logic as a Smithy build plugin, which supports configuration via a smithy-build.json. It also supports standard Smithy features such as projections because it hooks into the full Smithy model building pipeline.

This task is to add the missing necessary configuration knobs to our smithy-build.json configuration handler so that we can migrate off the CLI.

(More specific design for how these options should map to smithy-build.json configuration pending...)

robin-aws commented 1 month ago

Note the scope of this issue is only for CLI options that are relevant in --aws-sdk mode, since we only have the dafny-client-plugin plugin so far. Some options will only be needed for the dafny-library-plugin we have yet to create: https://github.com/smithy-lang/smithy-dafny/issues/153

robin-aws commented 1 month ago

Here is some more detail on the scope of this task vs. future ones.

One key difference between the CLI and the Smithy build plugin is how they use input and output. The CLI has options like --library-root pointing to the source code directory, and options like --output-java that allow it to write code anywhere on disk. The Smithy CLI/Gradle plugin only gives Smithy build plugins parsed/resolved/validated Smithy models as input, and expects output to only be written to a build directory like build/sources/dafny-client-plugin.

I believe the best way to bridge this gap is with an additional shared Gradle plugin that can be executed after invoking the smithy-gradle-plugin task to build a model. This plugin would provide the connection between the contents of a directory that the Smithy build plugin outputs like <project-root>/build/sources/dafny-client-plugin/runtimes/java/smithy-generated and where that code is checked in, i.e. <project-root>/runtimes/java/smithy-generated. The --patch-files-dir and --update-patch-files features of the CLI would also move to this plugin.

The plugin would have three different tasks (or at least modes of a single task):

It looks like this is the only missing "feature" to make this work. For the record here is the analysis I did of the current set of CLI options:

CLI options that need new smithy-build.json equivalents

CLI options that already have smithy-build.json equivalents

CLI options not yet relevant (because they will apply to dafny-library-codegen instead)