mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 15:20:51 +00:00
Fixed:
- Path dependencies now work correctly: `dcr add` stores them as `{ path =
"./..." }` tables, `is_registry_dep` properly distinguishes registry strings
from path/git strings, and `deps/mod.rs` resolves both table-form and
legacy string-form path dependencies
- Registry dependency paths no longer hardcoded to `project_root/dcr-index`;
now use `package_root_from_registry_info()` which resolves relative to the
registry cache root (`~/.dcr/`)
- Registry dependencies are now actually built: `build_project_at()` is
called when `include_dir` or `lib_dir` is missing
Added:
- `SIGINT`/`Ctrl+C` handler via `ctrlc` crate — `dcr build` now checks
`BUILD_INTERRUPTED` flag at key points and aborts cleanly
- `utils/build.rs` — extracted shared utilities: `parse_version_info`,
`normalize_target_os`, `resolve_compiler`, `primary_language`,
`resolve_pkg_config_flags` and config helpers. Eliminates code duplication
between `cli/build.rs`, `cli/run.rs`, `cli/clean.rs`, `cli/gen.rs`
- `utils/fs.rs::with_dir` — extracted common directory-scoped execution
- `run_command_sync_output` in `builder/common.rs` with global `OUTPUT_MUTEX`
— synchronized compiler output across all backends (unix_cc, gas, nasm, msvc)
- New helper functions in `deps/register.rs`: `get_registry_cache_root`,
`package_root_from_registry_info`, `registry_include_dir`, `registry_lib_dir`,
`path_from_string_dep`
- Unit tests for `register.rs` (`is_registry_dep`, `package_root_from_registry_info`),
`deps/mod.rs` (`path_dep_path`, `push_default_lib_dirs`),
`utils/build.rs` (`normalize_target_os`, `parse_version_info`)
Removed:
- Removed unused dependencies `indicatif` and `console` from `Cargo.toml`
This commit is contained in:
@@ -35,6 +35,47 @@ pub fn get_index_path() -> PathBuf {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_registry_cache_root() -> PathBuf {
|
||||
get_index_path()
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
}
|
||||
|
||||
pub fn package_root_from_registry_info(pkg_info: &JsonValue) -> Result<PathBuf, String> {
|
||||
let raw_path = pkg_info
|
||||
.get("path")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or("Registry package is missing path")?;
|
||||
if raw_path.trim().is_empty() {
|
||||
return Err("Registry package path is empty".to_string());
|
||||
}
|
||||
|
||||
let path = Path::new(raw_path);
|
||||
let full_path = if path.is_absolute() {
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
get_registry_cache_root().join(path)
|
||||
};
|
||||
|
||||
if full_path.file_name().and_then(|v| v.to_str()) == Some("dcr.toml") {
|
||||
return full_path
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
.ok_or_else(|| format!("Invalid registry package path: {}", full_path.display()));
|
||||
}
|
||||
|
||||
Ok(full_path)
|
||||
}
|
||||
|
||||
pub fn registry_include_dir(dep_root: &Path) -> PathBuf {
|
||||
dep_root.join("target").join("include")
|
||||
}
|
||||
|
||||
pub fn registry_lib_dir(dep_root: &Path) -> PathBuf {
|
||||
dep_root.join("target").join("lib")
|
||||
}
|
||||
|
||||
pub fn resolve_package_from_registry(name: &str) -> Result<JsonValue, String> {
|
||||
let config = get_registry_config().ok_or("No registry config found")?;
|
||||
let mut registries: Vec<(&String, &Registry)> = config.registry.iter().collect();
|
||||
@@ -63,8 +104,9 @@ pub fn resolve_package_from_registry(name: &str) -> Result<JsonValue, String> {
|
||||
}
|
||||
|
||||
pub fn is_registry_dep(value: &TomlValue) -> bool {
|
||||
if value.is_str() {
|
||||
return true;
|
||||
if let Some(raw) = value.as_str() {
|
||||
let raw = raw.trim();
|
||||
return !is_path_like_string(raw) && !is_git_like_string(raw);
|
||||
}
|
||||
if let Some(table) = value.as_table() {
|
||||
return !table.contains_key("git")
|
||||
@@ -74,3 +116,81 @@ pub fn is_registry_dep(value: &TomlValue) -> bool {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn path_from_string_dep(value: &TomlValue) -> Option<&str> {
|
||||
let raw = value.as_str()?.trim();
|
||||
if let Some(path) = raw.strip_prefix("path:") {
|
||||
return Some(path);
|
||||
}
|
||||
if is_path_like_string(raw) {
|
||||
return Some(raw);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn is_path_like_string(raw: &str) -> bool {
|
||||
raw.starts_with("path:")
|
||||
|| raw.starts_with("./")
|
||||
|| raw.starts_with("../")
|
||||
|| raw.starts_with('/')
|
||||
|| raw.starts_with("~/")
|
||||
|| raw.contains('\\')
|
||||
}
|
||||
|
||||
fn is_git_like_string(raw: &str) -> bool {
|
||||
raw.starts_with("git:")
|
||||
|| raw.starts_with("github:")
|
||||
|| raw.starts_with("gitlab:")
|
||||
|| raw.starts_with("http://")
|
||||
|| raw.starts_with("https://")
|
||||
|| raw.starts_with("git@")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use toml::map::Map;
|
||||
|
||||
#[test]
|
||||
fn registry_dep_detection_excludes_local_and_git_strings() {
|
||||
assert!(is_registry_dep(&TomlValue::String("1.2.3".to_string())));
|
||||
assert!(!is_registry_dep(&TomlValue::String(
|
||||
"path:./libs/mylib".to_string()
|
||||
)));
|
||||
assert!(!is_registry_dep(&TomlValue::String(
|
||||
"./libs/mylib".to_string()
|
||||
)));
|
||||
assert!(!is_registry_dep(&TomlValue::String(
|
||||
"git:https://example.com/repo.git".to_string()
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_dep_detection_excludes_source_tables() {
|
||||
let mut path_table = Map::new();
|
||||
path_table.insert(
|
||||
"path".to_string(),
|
||||
TomlValue::String("./libs/mylib".to_string()),
|
||||
);
|
||||
assert!(!is_registry_dep(&TomlValue::Table(path_table)));
|
||||
|
||||
let mut registry_table = Map::new();
|
||||
registry_table.insert("features".to_string(), TomlValue::Array(Vec::new()));
|
||||
assert!(is_registry_dep(&TomlValue::Table(registry_table)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_package_root_accepts_package_dir_or_manifest_path() {
|
||||
let pkg = serde_json::json!({ "path": "/tmp/pkg" });
|
||||
assert_eq!(
|
||||
package_root_from_registry_info(&pkg).unwrap(),
|
||||
PathBuf::from("/tmp/pkg")
|
||||
);
|
||||
|
||||
let pkg = serde_json::json!({ "path": "/tmp/pkg/dcr.toml" });
|
||||
assert_eq!(
|
||||
package_root_from_registry_info(&pkg).unwrap(),
|
||||
PathBuf::from("/tmp/pkg")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user