swiftlang / swift-docc-plugin

Swift Package Manager command plugin for Swift-DocC
https://swiftpackageindex.com/apple/swift-docc-plugin/1.3.0/documentation/swiftdoccplugin
Apache License 2.0
316 stars 54 forks source link

Simplify argument parsing and processing in the plugin #88

Closed d-ronnqvist closed 3 weeks ago

d-ronnqvist commented 1 month ago

Bug/issue #, if applicable:

Summary

This greatly simplifies the processing of command line arguments for the plugin itself, for what the plugin prepares for DocC, and for what there plugin prepares for symbol graph extraction.

Like #87, this PR is in preparation for another change. Whenever I've asked people about how they that I structure my PRs they've said that they prefer multiple smaller single-purpose PRs. I'm trying to do just that with this PR.

The purpose of this change is to prepare the code to make it easy to make a follow up PR that intercepts and customizes the --output-dir argument to allow using it when building documentation for more than one target. A secondary purpose of this change is to have a testable (and tested) foundation for parsing and processing the command line arguments in the plugin.

This is very close to a non-functional change, but there are a few minor improvements:

Dependencies

None.

Testing

Nothing in particular. Run bin/tests.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

d-ronnqvist commented 1 month ago

@swift-ci please test

d-ronnqvist commented 1 month ago

To make it easier to review this code, here are a handful of things that are worth calling out:

sofiaromorales commented 4 weeks ago

@d-ronnqvist - Why are we implementing our own command line parser instead of using swift argument parser?

d-ronnqvist commented 4 weeks ago

@d-ronnqvist - Why are we implementing our own command line parser instead of using swift argument parser?

Swift Argument Parses doesn't solve what the DocC Plugin needs to accomplish;

d-ronnqvist commented 4 weeks ago

Would it be possible to consolidate all the information about a given argument, i.e. name, spelling, value, default value, help text in one place?

For the flags with documentation I moved everything except the default value into the DocumentedFlag definition in https://github.com/swiftlang/swift-docc-plugin/pull/88/commits/f14201a7fd5f78addde97c5c1830eeadb3f0bf90.

My reason for not moving the default values is that I find that it gets unnecessarily complicated doing so. There are mostly boolean flags but there are also a couple of non-boolean optional arguments (symbol-graph-access-level now and output-path in a follow up PR). I feel that this is an improvement that we can make in the future if we find a need for it then, but for now I prefer to keep the code simpler.

d-ronnqvist commented 4 weeks ago

@swift-ci please test

d-ronnqvist commented 4 weeks ago

@swift-ci please test

d-ronnqvist commented 3 weeks ago

@swift-ci please test

d-ronnqvist commented 3 weeks ago

@swift-ci please test macOS

d-ronnqvist commented 3 weeks ago

It looks like somewhere between Swift 3e21fc6610cc917 and Swift 54908861448c8e8 caused all of the integration tests to fail with a non-zero exit from swift-symbolgraph-extract with these errors:

<unknown>:0: error: unknown argument: \'-Xlinker\'
<unknown>:0: error: unknown argument: \'-rpath\'
<unknown>:0: error: unknown argument: \'-Xlinker\'
d-ronnqvist commented 3 weeks ago

@swift-ci please test macOS

d-ronnqvist commented 3 weeks ago

I think this will be unblocked tomorrow when https://github.com/swiftlang/swift-package-manager/pull/7903 is available in a development toolchain. If not, we may consider merging https://github.com/swiftlang/swift-docc-plugin/pull/90 while we wait.

d-ronnqvist commented 3 weeks ago

@swift-ci please test macOS

d-ronnqvist commented 3 weeks ago

@swift-ci please test