Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate towards exclusively using serde for Config #7456

Merged
merged 20 commits into from
Oct 9, 2019

Conversation

alexcrichton
Copy link
Member

This series of commits was spawned off a thought I had while reading #7253 (comment), although it ended up not really touching on that at all. I was a little unsettled about how unstructured the config accesses are throughout Cargo and we had sort of two systems (one serde which is nice, one which is more manual) for reading config values.

This PR converts everything to run through serde for deserializing values, except for get_list which is funky. There's only one usage of that with the paths key though and we can probably fix this soon-ish.

In any case, the highlights of this PR are:

  • This PR is surprisingly large. I did a lot of movement in config.rs to try to make the file smaller and more understandable.
  • The Value type which retains information about where it was deserialized from is very special, and has special treatment with serde's data model. That's what allows us to use that and serde at the same time.
  • The ConfigRelativePath and ConfigKey structures have been revamped internally, but morally serve the same purposes as before.
  • Cargo now has structured struct access for a bunch of its configuration (net, http, build, etc). I would ideally like to move toward a world where this is the only way to read configuration, or at least everything conventionally runs through those paths.
  • Functionally, this PR should have no difference other than tweaks to error messages here and there, and perhaps more strict validation on commands where we validate more configuration on each run than we previously did.
  • This isn't a 100% transition for Cargo yet, but I figured it would be a good idea to post this and get some feedback first.
  • In the long run I want to remove get_env, get_cv, and get_*_priv from Config as internal details. I'd like to move this all to de.rs and have it walk down the tree of configuration as we deserialize a value. For now though these all remain in place and that refactoring is left to a future PR.

@alexcrichton
Copy link
Member Author

r? @ehuss

@rust-highfive rust-highfive assigned ehuss and unassigned nrc Sep 27, 2019
@rust-highfive
Copy link

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2019
@bors
Copy link
Contributor

bors commented Sep 30, 2019

☔ The latest upstream changes (presumably #7308) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member Author

r? @ehuss

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

This looks great!

src/cargo/util/config/mod.rs Outdated Show resolved Hide resolved
src/cargo/util/config/mod.rs Show resolved Hide resolved
src/cargo/ops/registry.rs Outdated Show resolved Hide resolved
src/cargo/util/config/key.rs Outdated Show resolved Hide resolved
src/cargo/util/config/de.rs Show resolved Hide resolved
Also make it a little less allocation-heavy by tweaking the API to
encourage incremental building of the key and incremental destruction as
we walk throughout the configuration tree.
Rewrite helpers like `get_bool` to use `get::<Option<Value<bool>>>`
instead of duplicating the logic that's already with the typed access of
configuration. This is more along the effort to centralize all
deserialization of configuration into typed values instead of using
ad-hoc accessors in a number of locations.
This callsite doesn't need the full power of `get_list`, knowing the
definition path of each element along the list.
Gives us one nice place to access and document all HTTP-related configuration
Going through and removing users of raw `get_*` functions!
Less need for `get_bool` and friends!
Add a typed structure which lists all `build` key configuration
throughout Cargo.
No need for lots of extra helpers/parsing when using serde!
@alexcrichton
Copy link
Member Author

Ok updated! Want to take another look @ehuss?

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks, r=me with small fixes.

/// single string or a string list itself. For example these deserialize to
/// equivalent values:
///
/// ```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// ```
/// ```toml

// updated with `push` methods and looks like `CARGO_FOO_BAR` for pushing
// `foo` and then `bar`.
env: String,
// The current environment variable this configuration key maps to. This is
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The current environment variable this configuration key maps to. This is
// The current toml key this configuration key maps to. This is

@alexcrichton
Copy link
Member Author

@bors: r=ehuss

@bors
Copy link
Contributor

bors commented Oct 9, 2019

📌 Commit 9a12e48 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 9, 2019
@bors
Copy link
Contributor

bors commented Oct 9, 2019

⌛ Testing commit 9a12e48 with merge 94bf478...

bors added a commit that referenced this pull request Oct 9, 2019
Migrate towards exclusively using serde for `Config`

This series of commits was spawned off a thought I had while reading #7253 (comment), although it ended up not really touching on that at all. I was a little unsettled about how unstructured the config accesses are throughout Cargo and we had sort of two systems (one serde which is nice, one which is more manual) for reading config values.

This PR converts everything to run through serde for deserializing values, except for `get_list` which is funky. There's only one usage of that with the `paths` key though and we can probably fix this soon-ish.

In any case, the highlights of this PR are:

* This PR is surprisingly large. I did a lot of movement in `config.rs` to try to make the file smaller and more understandable.
* The `Value` type which retains information about where it was deserialized from is very special, and has special treatment with serde's data model. That's what allows us to use that and serde at the same time.
* The `ConfigRelativePath` and `ConfigKey` structures have been revamped internally, but morally serve the same purposes as before.
* Cargo now has structured `struct` access for a bunch of its configuration (`net`, `http`, `build`, etc). I would ideally like to move toward a world where this is the *only* way to read configuration, or at least everything conventionally runs through those paths.
* Functionally, this PR should have no difference other than tweaks to error messages here and there, and perhaps more strict validation on commands where we validate more configuration on each run than we previously did.
* This isn't a 100% transition for Cargo yet, but I figured it would be a good idea to post this and get some feedback first.
* In the long run I want to remove `get_env`, `get_cv`, and `get_*_priv` from `Config` as internal details. I'd like to move this all to `de.rs` and have it walk down the tree of configuration as we deserialize a value. For now though these all remain in place and that refactoring is left to a future PR.
@bors
Copy link
Contributor

bors commented Oct 9, 2019

☀️ Test successful - checks-azure
Approved by: ehuss
Pushing 94bf478 to master...

@bors bors merged commit 9a12e48 into rust-lang:master Oct 9, 2019
@bors bors deleted the config-only-serde branch October 9, 2019 17:29
tmandry added a commit to tmandry/rust that referenced this pull request Oct 16, 2019
…chton

Update cargo, cc, books

Update `cc` to include new parallel building support.

## nomicon

3 commits in 4374786f0b4bf0606b35d5c30a9681f342e5707b..5004ad30d69f93553ceef74439fea2159d1f769e
2019-09-17 18:33:21 +0200 to 2019-10-12 19:52:40 +0200
- further clarify C11 and C/C++11 terminology (rust-lang/nomicon#169)
- atomics: C11 -&gt; C++20 (rust-lang/nomicon#168)
- use sound/unsound terminology

## cargo

12 commits in a429e8cc4614a46a86322a0777a477e2baa83f1c..3a9abe3f065554a7fbc59f440df2baba4a6e47ee
2019-10-04 17:36:12 +0000 to 2019-10-15 15:55:35 +0000
- Fix typo in git index initialization error path (rust-lang/cargo#7512)
- Reject feature flags in a virtual workspace. (rust-lang/cargo#7507)
- Rename `overrides` to `package` in profiles. (rust-lang/cargo#7504)
- Allow publishing with dev-dependencies without a version. (rust-lang/cargo#7333)
- Stabilize cache-messages (rust-lang/cargo#7450)
- don't lock the package cache when cleaning target dir. (rust-lang/cargo#7502)
- Document rustc wrapper (rust-lang/cargo#7499)
- Migrate towards exclusively using serde for `Config` (rust-lang/cargo#7456)
- Re-enable some MSVC tests. (rust-lang/cargo#7492)
- when -Z unstable-options not specified, don't validate --profile (rust-lang/cargo#7489)
- Improve error message for cyclic dependencies (rust-lang/cargo#7470)
- Some minor clippy fixes. (rust-lang/cargo#7484)

## book

7 commits in 04806c80be0f54b1290287e3f85e84bdfc0b6ec7..9bb8b161963fcebc9d9ccd732ba26f42108016d5
2019-10-01 20:20:22 -0400 to 2019-10-14 18:42:55 -0500
- Make a portion of text less ambiguous (rust-lang/book#2092)
- fix heading level (rust-lang/book#2117)
- Add missing "of" before `"duck typing"`. (rust-lang/book#1951)
- ch18-03: no need to debug print destructured int (rust-lang/book#1991)
- Subtle fix to introduce ? on Option in Chapter 9.2 (rust-lang/book#2047)
- make wording clearer (rust-lang/book#1976)
- Update the version of rand we use

## rust-by-example

5 commits in a6288e7407a6c4c19ea29de6d43f40c803883f21..0b111eaae36cc4b4997684be853882a59e2c7ca7
2019-10-01 10:09:14 -0300 to 2019-10-14 18:34:25 -0300
- Some fix to three files (rust-lang/rust-by-example#1280)
- Add reference to Generics (rust-lang/rust-by-example#1281)
- Confusing and long sentence (rust-lang/rust-by-example#1282)
- Explicit mention of slice range meaning (rust-lang/rust-by-example#1277)
- Updated aliasing for nll (rust-lang/rust-by-example#1276)
bors added a commit to rust-lang/rust that referenced this pull request Oct 16, 2019
Update cargo, books

## nomicon

3 commits in 4374786f0b4bf0606b35d5c30a9681f342e5707b..5004ad30d69f93553ceef74439fea2159d1f769e
2019-09-17 18:33:21 +0200 to 2019-10-12 19:52:40 +0200
- further clarify C11 and C/C++11 terminology (rust-lang/nomicon#169)
- atomics: C11 -&gt; C++20 (rust-lang/nomicon#168)
- use sound/unsound terminology

## cargo

12 commits in a429e8cc4614a46a86322a0777a477e2baa83f1c..3a9abe3f065554a7fbc59f440df2baba4a6e47ee
2019-10-04 17:36:12 +0000 to 2019-10-15 15:55:35 +0000
- Fix typo in git index initialization error path (rust-lang/cargo#7512)
- Reject feature flags in a virtual workspace. (rust-lang/cargo#7507)
- Rename `overrides` to `package` in profiles. (rust-lang/cargo#7504)
- Allow publishing with dev-dependencies without a version. (rust-lang/cargo#7333)
- Stabilize cache-messages (rust-lang/cargo#7450)
- don't lock the package cache when cleaning target dir. (rust-lang/cargo#7502)
- Document rustc wrapper (rust-lang/cargo#7499)
- Migrate towards exclusively using serde for `Config` (rust-lang/cargo#7456)
- Re-enable some MSVC tests. (rust-lang/cargo#7492)
- when -Z unstable-options not specified, don't validate --profile (rust-lang/cargo#7489)
- Improve error message for cyclic dependencies (rust-lang/cargo#7470)
- Some minor clippy fixes. (rust-lang/cargo#7484)

## book

7 commits in 04806c80be0f54b1290287e3f85e84bdfc0b6ec7..9bb8b161963fcebc9d9ccd732ba26f42108016d5
2019-10-01 20:20:22 -0400 to 2019-10-14 18:42:55 -0500
- Make a portion of text less ambiguous (rust-lang/book#2092)
- fix heading level (rust-lang/book#2117)
- Add missing "of" before `"duck typing"`. (rust-lang/book#1951)
- ch18-03: no need to debug print destructured int (rust-lang/book#1991)
- Subtle fix to introduce ? on Option in Chapter 9.2 (rust-lang/book#2047)
- make wording clearer (rust-lang/book#1976)
- Update the version of rand we use

## rust-by-example

5 commits in a6288e7407a6c4c19ea29de6d43f40c803883f21..0b111eaae36cc4b4997684be853882a59e2c7ca7
2019-10-01 10:09:14 -0300 to 2019-10-14 18:34:25 -0300
- Some fix to three files (rust-lang/rust-by-example#1280)
- Add reference to Generics (rust-lang/rust-by-example#1281)
- Confusing and long sentence (rust-lang/rust-by-example#1282)
- Explicit mention of slice range meaning (rust-lang/rust-by-example#1277)
- Updated aliasing for nll (rust-lang/rust-by-example#1276)
@ehuss ehuss added this to the 1.40.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants