From cad36ecdabf17f1492616628d4e83ad0b9aad2ec Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Tue, 13 Aug 2024 12:34:07 +0000 Subject: [PATCH] Don't inherit OSDK manifest values from workspace root --- docs/src/osdk/reference/manifest.md | 8 ++-- osdk/Cargo.lock | 2 +- osdk/src/config/manifest.rs | 69 +++++++++-------------------- 3 files changed, 26 insertions(+), 53 deletions(-) diff --git a/docs/src/osdk/reference/manifest.md b/docs/src/osdk/reference/manifest.md index 74c60a4c1..aeceb262e 100644 --- a/docs/src/osdk/reference/manifest.md +++ b/docs/src/osdk/reference/manifest.md @@ -15,10 +15,10 @@ one is of the workspace (in the same directory as the workspace's `Cargo.toml`) and one of the crate (in the same directory as the crate's `Cargo.toml`). -OSDK will first refer to the crate-level manifest, then -query the workspace-level manifest for undefined fields. -In other words, missing fields of the crate manifest -will inherit values from the workspace manifest. +OSDK will firstly try to find the crate-level manifest. +If the crate-level manifest is found, OSDK uses it only. +If the manifest is not found, OSDK will look into the +workspace-level manifest. ## Configurations diff --git a/osdk/Cargo.lock b/osdk/Cargo.lock index 4eefec4c6..6ee3668a0 100644 --- a/osdk/Cargo.lock +++ b/osdk/Cargo.lock @@ -146,7 +146,7 @@ dependencies = [ [[package]] name = "cargo-osdk" -version = "0.6.2" +version = "0.7.0" dependencies = [ "assert_cmd", "clap", diff --git a/osdk/src/config/manifest.rs b/osdk/src/config/manifest.rs index 2cb750e63..287461003 100644 --- a/osdk/src/config/manifest.rs +++ b/osdk/src/config/manifest.rs @@ -50,60 +50,33 @@ impl TomlManifest { .unwrap(), ) }; - // All the custom schemes should inherit settings from the default scheme, this is a helper. - fn finalize(current_manifest: Option) -> TomlManifest { - let Some(mut current_manifest) = current_manifest else { - error_msg!( - "Cannot find `OSDK.toml` in the current directory or the workspace root" - ); - process::exit(Errno::GetMetadata as _); - }; - for scheme in current_manifest.map.values_mut() { - scheme.inherit(¤t_manifest.default_scheme); - } - current_manifest - } // Search for OSDK.toml in the current directory first. - let current_manifest_path = PathBuf::from("OSDK.toml").canonicalize().ok(); - let mut current_manifest = match ¤t_manifest_path { - Some(path) => deserialize_toml_manifest(path), - None => None, - }; - // Then search in the workspace root. - let workspace_manifest_path = workspace_root.join("OSDK.toml").canonicalize().ok(); - // The case that the current directory is also the workspace root. - if let Some(current) = ¤t_manifest_path { - if let Some(workspace) = &workspace_manifest_path { - if current == workspace { - return finalize(current_manifest); + let current_manifest_path = PathBuf::from("OSDK.toml").canonicalize(); + let current_manifest = match ¤t_manifest_path { + Ok(path) => deserialize_toml_manifest(path), + Err(_) => { + // If not found, search in the workspace root. + if let Ok(workspace_manifest_path) = workspace_root.join("OSDK.toml").canonicalize() + { + deserialize_toml_manifest(workspace_manifest_path) + } else { + None } } - } - let workspace_manifest = match workspace_manifest_path { - Some(path) => deserialize_toml_manifest(path), - None => None, }; - // The current manifest should inherit settings from the workspace manifest. - if let Some(workspace_manifest) = workspace_manifest { - if current_manifest.is_none() { - current_manifest = Some(workspace_manifest); - } else { - // Inherit one scheme at a time. - let current_manifest = current_manifest.as_mut().unwrap(); - current_manifest - .default_scheme - .inherit(&workspace_manifest.default_scheme); - for (scheme_string, scheme) in workspace_manifest.map { - let current_scheme = current_manifest - .map - .entry(scheme_string) - .or_insert_with(Scheme::empty); - current_scheme.inherit(&scheme); - } - } + + let Some(mut current_manifest) = current_manifest else { + error_msg!("Cannot find `OSDK.toml` in the current directory or the workspace root"); + process::exit(Errno::GetMetadata as _); + }; + + // All the schemes should inherit from the default scheme. + for scheme in current_manifest.map.values_mut() { + scheme.inherit(¤t_manifest.default_scheme); } - finalize(current_manifest) + + current_manifest } /// Get the scheme given the scheme from the command line arguments.