cgrindel / rules_swift_package_manager

Collection of utilities and Bazel rules to aid in the development and maintenance of Swift repositories using Bazel.
Apache License 2.0
72 stars 26 forks source link

Customize Gazelle Behavior? #1197

Open jflan-dd opened 4 weeks ago

jflan-dd commented 4 weeks ago

It it feasible to customize the behavior of gazelle when generating local BUILD files?

In our project we define different "layers" which are reflected in the folder structure on disk. So for example there's a Networking folder, which contains lots of individual packages and our current tooling automatically appends "Networking" to the end of the package name. So for the code in Layers/Networking/Address/Sources will create a package named "AddressNetworking".

Are there any customization points to replicate this logic for the update_build_files command?

cgrindel commented 3 weeks ago

Not at this time. However, I am open to suggestions on how we might be able to support this.

jflan-dd commented 2 weeks ago

Maybe we could take inspiration from Swiftlint's extra_rules setup: https://github.com/jpsim/swiftlint-bazel-example

Add a step in here somewhere that defaults to an empty implementation, but could be overridden similarly to Swiftlint. https://github.com/cgrindel/rules_swift_package_manager/blob/44f29685a2957a86a0412a1eef71ff61244ea3fb/gazelle/generate.go#L84-L97

Related: Could I use this section to accomplish what I need?

    // If the name is specified by a directive, short cirucit and return that:
    sc := swiftcfg.GetSwiftConfig(args.Config)
cgrindel commented 1 week ago

Could I use this section to accomplish what I need?

I think that it will. I forgot that we had that directive. There are examples of the swift_default_module_name directive in the repo. Here is one:

# gazelle:swift_default_module_name SnapkitExample