-
Notifications
You must be signed in to change notification settings - Fork 8.3k
feat: migrate to new constraint-based loading strategy #8251
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,6 +208,7 @@ v2_enum_from_core!( | |
| } | ||
| ); | ||
|
|
||
| // TODO(mbolin): Support in-repo layer. | ||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)] | ||
| #[serde(tag = "type", rename_all = "camelCase")] | ||
| #[ts(tag = "type")] | ||
|
|
@@ -216,17 +217,63 @@ pub enum ConfigLayerSource { | |
| /// Managed preferences layer delivered by MDM (macOS only). | ||
| #[serde(rename_all = "camelCase")] | ||
| #[ts(rename_all = "camelCase")] | ||
| Mdm { domain: String, key: String }, | ||
| Mdm { | ||
| domain: String, | ||
| key: String, | ||
| }, | ||
|
|
||
| /// Managed config layer from a file (usually `managed_config.toml`). | ||
| #[serde(rename_all = "camelCase")] | ||
| #[ts(rename_all = "camelCase")] | ||
| System { file: AbsolutePathBuf }, | ||
| /// Session-layer overrides supplied via `-c`/`--config`. | ||
| SessionFlags, | ||
| /// User config layer from a file (usually `config.toml`). | ||
| System { | ||
| file: AbsolutePathBuf, | ||
| }, | ||
|
|
||
| /// User config layer from $CODEX_HOME/config.toml. This layer is special | ||
| /// in that it is expected to be: | ||
| /// - writable by the user | ||
| /// - generally outside the workspace directory | ||
| #[serde(rename_all = "camelCase")] | ||
| #[ts(rename_all = "camelCase")] | ||
| User { file: AbsolutePathBuf }, | ||
| User { | ||
| file: AbsolutePathBuf, | ||
| }, | ||
|
|
||
| /// Session-layer overrides supplied via `-c`/`--config`. | ||
| SessionFlags, | ||
|
|
||
| /// `managed_config.toml` was designed to be a config that was loaded | ||
| /// as the last layer on top of everything else. This scheme did not quite | ||
| /// work out as intended, but we keep this variant as a "best effort" while | ||
| /// we phase out `managed_config.toml` in favor of `requirements.toml`. | ||
| LegacyManagedConfigTomlFromFile { | ||
| file: AbsolutePathBuf, | ||
| }, | ||
|
|
||
| LegacyManagedConfigTomlFromMdm, | ||
| } | ||
|
|
||
| impl ConfigLayerSource { | ||
| /// A settings from a layer with a higher precedence will override a setting | ||
| /// from a layer with a lower precedence. | ||
| pub fn precedence(&self) -> i16 { | ||
| match self { | ||
| ConfigLayerSource::Mdm { .. } => 0, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ConfigLayerSource::System { .. } => 10, | ||
| ConfigLayerSource::User { .. } => 20, | ||
| ConfigLayerSource::SessionFlags => 30, | ||
| ConfigLayerSource::LegacyManagedConfigTomlFromFile { .. } => 40, | ||
| ConfigLayerSource::LegacyManagedConfigTomlFromMdm => 50, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Compares [ConfigLayerSource] by precedence, so `A < B` means settings from | ||
| /// layer `A` will be overridden by settings from layer `B`. | ||
| impl PartialOrd for ConfigLayerSource { | ||
| fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
| Some(self.precedence().cmp(&other.precedence())) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema, TS)] | ||
|
|
@@ -344,7 +391,7 @@ pub struct ConfigWriteResponse { | |
| pub status: WriteStatus, | ||
| pub version: String, | ||
| /// Canonical path to the config file that was written. | ||
| pub file_path: String, | ||
| pub file_path: AbsolutePathBuf, | ||
| pub overridden_metadata: Option<OverriddenMetadata>, | ||
| } | ||
|
|
||
|
|
@@ -357,6 +404,7 @@ pub enum ConfigWriteErrorCode { | |
| ConfigValidationError, | ||
| ConfigPathNotFound, | ||
| ConfigSchemaUnknownKey, | ||
| UserLayerNotFound, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding a small comment here about what lower / higher precedence means in practice. I'd probably explain it multiple ways that mean the same thing such that readers can pick the most understandable one.
"Higher precedence configs are applied last."
"Higher precedence configs overwrite values from lower precendence configs". etc.