Skip to content

Switch stanc.exe to use Cmdliner for cli#1478

Merged
WardBrian merged 7 commits intomasterfrom
cmdliner
Jan 2, 2025
Merged

Switch stanc.exe to use Cmdliner for cli#1478
WardBrian merged 7 commits intomasterfrom
cmdliner

Conversation

@WardBrian
Copy link
Copy Markdown
Member

I mentioned this in #1477. The use of imperative style argument parsing in stanc.exe led to some weird code patterns and didn't give us type-checking guarantees about each setting actually being available (or, conversely, being used).

This PR switches to using the cmdliner library: https://erratique.ch/software/cmdliner. This is by the same author as the fmt library we already use, and is used by opam itself. I think it might already be installed on most of our switches as a result, but if not it's a very minimal addition.

Submission Checklist

  • Run unit tests
  • Documentation
    • If a user-facing facing change was made, the documentation PR is here: TBD

Release notes

Improved the command-line argument parser for stanc. Existing flags are still supported, but new aliases may be available. See the new and improved stanc --help for details.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 6 lines in your changes missing coverage. Please review.

Project coverage is 90.05%. Comparing base (f777719) to head (10439aa).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
src/stanc/stanc.ml 82.60% 4 Missing ⚠️
src/stanc/CLI.ml 98.03% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1478      +/-   ##
==========================================
+ Coverage   89.72%   90.05%   +0.33%     
==========================================
  Files          65       66       +1     
  Lines       10693    10751      +58     
==========================================
+ Hits         9594     9682      +88     
+ Misses       1099     1069      -30     
Files with missing lines Coverage Δ
src/driver/Entry.ml 92.40% <100.00%> (+5.39%) ⬆️
src/frontend/Debugging.ml 100.00% <ø> (+80.00%) ⬆️
src/stanc/CLI.ml 98.03% <98.03%> (ø)
src/stanc/stanc.ml 85.00% <82.60%> (+2.44%) ⬆️

... and 6 files with indirect coverage changes

@WardBrian WardBrian force-pushed the cmdliner branch 2 times, most recently from 75b386e to 68ff259 Compare December 16, 2024 21:09
@WardBrian WardBrian marked this pull request as ready for review December 16, 2024 21:26
@WardBrian
Copy link
Copy Markdown
Member Author

Okay, I think I finally excised the ghosts in the multiarch jenkins build for this...

@WardBrian
Copy link
Copy Markdown
Member Author

Note for reviewers: The review is probably easiest to do commit-by-commit, with the actual code changes all happening in the first commit. The second is some documentation, which can be reviewed, and the third is the result of a lot of jenkins tweaking to keep the build happy, which can probably be skipped if you're willing to trust the fact that it is building.

src/stanc/CLI.ml Outdated
; print_lir
; debug_generate_data
; debug_generate_inits
; debug_data_json= Option.map ~f:In_channel.read_all debug_data_file }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crashes if the provided --debug-data-file cannot be read. Do we have an existing test for that? Looks like test/integration/cli-args/debug-generate-data.t only has error cases where either no data file is provided or the file is well-formed JSON that does not contain the expected data.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this, and a separate issue where it would crash if the file existed, but could not be opened

Comment on lines -116 to +118
MULTIARCH_DOCKER_TAG = 'multiarch-ocaml-4.14-v2'
MULTIARCH_DOCKER_TAG = 'multiarch-ocaml-4.14-v2-and-cmdliner'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know anything about Jenkins, but what's the reason for the tag change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to re-build the multiarch images to add cmdliner. Because they don't install the developer-only dependencies like ocamlformat, I guess they didn't have it already.

This was a headache, and it's definitely non-obvious how the multiarch build works, see #1480

@WardBrian WardBrian merged commit 0419d50 into master Jan 2, 2025
@WardBrian WardBrian deleted the cmdliner branch January 2, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants