Don't inherit OSDK manifest values from workspace root

This commit is contained in:
Zhang Junyang 2024-08-13 12:34:07 +00:00 committed by Tate, Hongliang Tian
parent c2a8342752
commit cad36ecdab
3 changed files with 26 additions and 53 deletions

View File

@ -15,10 +15,10 @@ one is of the workspace
(in the same directory as the workspace's `Cargo.toml`) (in the same directory as the workspace's `Cargo.toml`)
and one of the crate and one of the crate
(in the same directory as the crate's `Cargo.toml`). (in the same directory as the crate's `Cargo.toml`).
OSDK will first refer to the crate-level manifest, then OSDK will firstly try to find the crate-level manifest.
query the workspace-level manifest for undefined fields. If the crate-level manifest is found, OSDK uses it only.
In other words, missing fields of the crate manifest If the manifest is not found, OSDK will look into the
will inherit values from the workspace manifest. workspace-level manifest.
## Configurations ## Configurations

2
osdk/Cargo.lock generated
View File

@ -146,7 +146,7 @@ dependencies = [
[[package]] [[package]]
name = "cargo-osdk" name = "cargo-osdk"
version = "0.6.2" version = "0.7.0"
dependencies = [ dependencies = [
"assert_cmd", "assert_cmd",
"clap", "clap",

View File

@ -50,60 +50,33 @@ impl TomlManifest {
.unwrap(), .unwrap(),
) )
}; };
// All the custom schemes should inherit settings from the default scheme, this is a helper.
fn finalize(current_manifest: Option<TomlManifest>) -> TomlManifest { // Search for OSDK.toml in the current directory first.
let current_manifest_path = PathBuf::from("OSDK.toml").canonicalize();
let current_manifest = match &current_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 Some(mut current_manifest) = current_manifest else { let Some(mut current_manifest) = current_manifest else {
error_msg!( error_msg!("Cannot find `OSDK.toml` in the current directory or the workspace root");
"Cannot find `OSDK.toml` in the current directory or the workspace root"
);
process::exit(Errno::GetMetadata as _); process::exit(Errno::GetMetadata as _);
}; };
// All the schemes should inherit from the default scheme.
for scheme in current_manifest.map.values_mut() { for scheme in current_manifest.map.values_mut() {
scheme.inherit(&current_manifest.default_scheme); scheme.inherit(&current_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 &current_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) = &current_manifest_path {
if let Some(workspace) = &workspace_manifest_path {
if current == workspace {
return finalize(current_manifest);
}
}
}
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 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);
}
}
}
finalize(current_manifest)
} }
/// Get the scheme given the scheme from the command line arguments. /// Get the scheme given the scheme from the command line arguments.