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

Config Profiles (RFC 2282 Part 2) #5506

Merged
merged 2 commits into from
Jun 2, 2018
Merged

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented May 10, 2018

Notes:

  • -Z config-profile CLI option is required to use.
  • Config values no longer reject mixed base types (integer, string, boolean) in order to support the mixed types in profiles.

@rust-highfive
Copy link

r? @matklad

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

@ehuss
Copy link
Contributor Author

ehuss commented May 10, 2018

Questions:

  • Do you care much about item visibility? I've been a little sloppy throwing pub onto things that could be a little tighter.
  • I implemented a bunch of warnings/validations, but I can imagine some of them could be noisy (and it is a lot of code). We can rip them out or change them if they look like they'll be too problematic.
    • The unknown key check could use serde_ignore, but then you lose the ability to know exactly which file the value came from (and warnings would be duplicated for every manifest in a workspace). I can switch it though, and remove ~40 lines of yucky code.

@matklad
Copy link
Member

matklad commented May 10, 2018

Do you care much about item visibility? I've been a little sloppy throwing pub onto things that could be a little tighter.

Not really, but, all other things being equal, reasonable module structure and clear interfaces are a win. The only hard concern around visibility is that RLS uses cargo as a library, so we need to make sure it has access to all stuff it needs.

I am not sure I'll have a change to review this today, but on the first sight this is great!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

This is looking great, thanks so much @ehuss!

fn validate_config(config: &Config, warnings: &mut Vec<String>) -> CargoResult<()> {
static VALIDATE_ONCE: atomic::AtomicBool = atomic::ATOMIC_BOOL_INIT;

if VALIDATE_ONCE.swap(true, atomic::Ordering::SeqCst) {
Copy link
Member

Choose a reason for hiding this comment

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

Could this perhaps be a flag stored directly in the Config instance instead of globally?

}

// cv: Value<HashMap<String, CV>>
if let Some(cv) = config.get_table("profile")? {
Copy link
Member

Choose a reason for hiding this comment

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

Could this use a match with an early return to avoid indentation?

}
// Warn about incorrect key names.
for profile_cv in cv.val.values() {
if let ConfigValue::Table(ref profile, _) = *profile_cv {
Copy link
Member

Choose a reason for hiding this comment

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

Should this warn if the value isn't a table?

@@ -844,13 +841,17 @@ impl ConfigValue {
};
}
}
(expected, found) => {
Copy link
Member

Choose a reason for hiding this comment

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

Could a comment be added here indicating that this block is intended for "you can't switch types between tables/arrays, but you can switch other key value types"?

return Ok(None);
}
if let Some(util::config::Value { val, .. }) =
config.get_table(&format!("profile.{}", name))?
Copy link
Member

Choose a reason for hiding this comment

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

One of the downsides of get_table is that it doesn't work well with environment variables so I think that for any new features we ideally want to avoid get_table as much as possible. I saw above that get_table is used a lot in validation which I think is fine, but would it be possible for these values to read from the environment as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that a little bit. IIUC, it will need to manually get every key, and it wouldn't be able to use serde to do the automatic conversion. I can give it a shot, though I think that will make the patch a little longer.

(Another crazy idea would be to implement a custom Deserializer for Config that would handle everything, but I'm not sure if that would work, and would be a fair amount of code.)

Copy link
Member

Choose a reason for hiding this comment

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

Heh yeah I think you're spot on. The manual deserialization here hopefully isn't too bad, but I agree that a Config deserializer is probably what we want long-term.

Notes:
- `-Z config-profile` CLI option is required to use.
- Config values no longer reject mixed base types (integer, string, boolean) in order to support the mixed types in profiles.
Also, require "override" feature if used in a config.
@ehuss
Copy link
Contributor Author

ehuss commented May 31, 2018

I've updated with the new API. I decided to use LazyCell to store the profiles in Config to ensure they are validated only once instead of using the global atomic. I haven't used LazyCell before, so I wasn't familiar with it, but it seems to work pretty well.

@alexcrichton
Copy link
Member

r=me, this looks fantastic! @matklad want to take a final look though?

@matklad
Copy link
Member

matklad commented Jun 2, 2018

"this looks fantastic" is a very accurate description of this PR!

@bors r=alexcrichton

@bors
Copy link
Contributor

bors commented Jun 2, 2018

📌 Commit 84a80d8 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 2, 2018

⌛ Testing commit 84a80d8 with merge 9f09778...

bors added a commit that referenced this pull request Jun 2, 2018
Config Profiles (RFC 2282 Part 2)

Notes:
- `-Z config-profile` CLI option is required to use.
- Config values no longer reject mixed base types (integer, string, boolean) in order to support the mixed types in profiles.
@bors
Copy link
Contributor

bors commented Jun 2, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 9f09778 to master...

@bors bors merged commit 84a80d8 into rust-lang:master Jun 2, 2018
@ehuss ehuss mentioned this pull request Jan 23, 2020
bors added a commit that referenced this pull request Jan 31, 2020
Stabilize config-profile.

This is a proposal to stabilize config-profiles. This feature was proposed in [RFC 2282](rust-lang/rfcs#2282) and implemented in #5506. Tracking issue is rust-lang/rust#48683.

This is intended to land in 1.43 which will reach the stable channel on April 23rd.

This is a fairly straightforward extension of profiles where the exact same syntax from `Cargo.toml` can be specified in a config file. Environment variables are supported for everything except the `package` override table, where we do not support the ability to read arbitrary keys in the environment name.
@ehuss ehuss added this to the 1.28.0 milestone Feb 6, 2022
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.

5 participants