cli: Fix altering user-provided lib name #3467
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Anchor converts user-provided lib name to snake case:
anchor/cli/src/config.rs
Lines 82 to 91 in 7b6c2b3
This makes the output incompatible with
cargo
becausecargo
tooling does not alter user-provided lib names.For example, if the user sets the lib name to include numbers (in some cases) or uses a non-standard, i.e. non-snake_case, name:
Running
anchor test
results in:And in
.anchor/test-ledger/test-ledger-log.txt
:This is because the build tool (
cargo-build-sbf
) outputs the program binary asmyProgram.so
, but Anchor incorrectly tries to findmy_program.so
.Summary of changes
Fix altering user-provided lib name.
Note: Removing the
to_snake_case
call would have been enough to fix this issue, but thelib_name
method implementation was quite repetitive and unidiomatic, so I thought it would be great to rewrite it to make it more concise and idiomatic.