Repository navigation
fix: Cargo の同じ取得元・同じ版の宣言をまとめて書き換える - #22
Merged
Merged
Conversation
同じ依存を [dependencies] と [dev-dependencies] に同じ取得元・同じ版で書くと (dev 側にだけ features を足す、Rust でよくある書き方)、writer の曖昧判定で 更新を拒否していた。「2 updates」と表示しながら Cargo.toml を 1 バイトも 書けず、exit code 2 になる。更新の行とエラーも宣言の数だけ並んでいた。 - Cargo の parse で、実パッケージ名・依存キー・版の指定の生表記・git の取得元 (URL・参照・公開用に併記した version) が一致する宣言を 1 依存にまとめる。 update_version / update_git_tag は全依存セクションの同名の宣言を書き換える ので、1 回の書き換えで全宣言が新しい版になる。is_dev は、本番の宣言が 1 つでもあれば本番にする - Cargo.toml を書き換えない git の branch / rev / 既定ブランチの更新には、 曖昧判定を当てない - 版や取得元が食い違って拒否するときも、エラーは依存キーごとに 1 行にする Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
概要
Cargo.toml で同じ依存を
[dependencies]と[dev-dependencies]に同じ取得元・同じ版で書くと (dev 側にだけfeaturesを足す、Rust でよくある書き方)、書き込みの段階でRefusing to update ambiguous dependencyになり、更新できずに exit code 2 になっていた。git のタグの依存・crates.io の依存・Cargo.toml を書き換えない branch の git 依存のどれでも起き、更新の行とエラーも宣言の数だけ並んでいた。同じ取得元・同じ版を指す宣言を parse の段階で 1 依存にまとめ、1 回の書き換えで全宣言を新しい版にする。
原因
ManifestWriter::apply_updatesは書き込む前にマニフェストを parse し直し、manifest_name()が同じ宣言が 2 件以上あれば、版や取得元を比べずに拒否する。この判定は git の参照の種類で分ける処理より前にあったので、Cargo.toml を書き換えない branch / rev の git 依存も拒否していたCargoTomlParser::parseはセクションごとに宣言を 1 件ずつ返し、同じ依存をまとめていなかったupdate_version/update_git_tag) は、全依存セクションの同名の宣言をすべて書き換える作りになっている。宣言の版がそろっていれば、1 回の書き換えで全宣言が新しい版になる変更内容
CargoTomlParser::parseで、実パッケージ名・依存キー・版の指定の生表記・git の取得元 (URL・参照・公開用に併記したversion) が一致する宣言を 1 依存にまとめる (CargoDeclarations)。Gradle のpush_unique_declarationと同じ考え方。featuresなどの付帯指定とis_devはキーに含めない。is_devは、本番の宣言が 1 つでもあれば本番にするdocs/usageとdocs/ecosystemsの英日、AGENTS.md) を更新設計の判断
codex と相談して決めた。
"1.0"と"^1.0"は Cargo では同じ意味だが、まとめずに拒否のままにする。要求範囲を忠実に比べる正規化を持たないので、誤更新を避ける側に倒すversionを併記している場合は、それもキーに入れる。同じ URL・タグでも、要求する版が違えば同等の宣言とは言えないis_devは最初の宣言を残すのではなく AND で合成する。[dev-dependencies]がターゲット固有の[dependencies]より先に読まれるので、最初の宣言を残すだけだと本番の依存が dev 扱いになる範囲外
update_git_tagは依存セクションに加えて[patch.<registry>]の同名の宣言の tag も書き換える (以前からの振る舞い)。[patch]側が別の URL (fork など) を指していても書き換わる。今回の Issue とは別の問題なので、この PR では触らない。検証
make ci(fmt-check・clippy・全テスト): pass (lib 2444 / e2e 26 / integration 75)test_parse_merges_declarations_with_same_source_and_version: git のタグ・crates.io・branch・引用符違いの宣言が 1 依存にまとまるtest_parse_keeps_declarations_with_different_source_or_version: 版・1.0と^1.0・タグ・URL・取得元の種類・併記したversionが食い違う宣言はまとめないtest_parse_keeps_same_key_renamed_to_different_packages: 依存キーが同じでもpackageが違えばまとめないtest_parse_merged_declaration_is_production_when_any_declaration_istest_apply_updates_rust_same_git_tag_in_dependencies_and_dev_dependencies: 両方の tag が書き換わるtest_apply_updates_rust_same_registry_version_in_dependencies_and_dev_dependencies: 両方の版が書き換わるtest_apply_updates_rust_same_git_branch_in_dependencies_and_dev_dependencies: Cargo.toml を変えず、エラーにしないtest_apply_updates_rust_unwritten_git_update_is_not_refused_beside_registry_declaration: branch・rev・既定ブランチの git の更新は通し、同名の crates.io の更新だけを拒否するtest_apply_updates_rust_mismatched_declarations_report_one_error: 食い違う宣言は拒否し、エラーは 1 行1 updateで exit 0。版が食い違う構成は、エラー 1 行で拒否する (exit 2)CargoDeclarationsのコメントがその例外を書いていない) を反映したCloses #20
🤖 Generated with Claude Code