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`)
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

2
osdk/Cargo.lock generated
View File

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

View File

@ -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>) -> 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(&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 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 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(&current_manifest.default_scheme);
}
finalize(current_manifest)
current_manifest
}
/// Get the scheme given the scheme from the command line arguments.