mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-24 23:09:16 +00:00
- Added support for registry-based dependencies in the dependencies section. - Updated the package section to include a project type field. - Introduced a new CLI command `dcr setup` to load and display registry configurations. - Implemented a new module for handling registry operations, including loading and resolving packages from registries. - Enhanced the build process to handle library packaging, including copying headers and libraries to the appropriate target directories. - Updated the CLI to support building library packages and added tests for library package builds. - Improved error handling and output messages during dependency resolution and package fetching.
112 lines
2.5 KiB
Rust
112 lines
2.5 KiB
Rust
#[allow(dead_code)]
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
#[derive(Debug, Clone)]
|
|
#[allow(dead_code)]
|
|
pub enum DepSource {
|
|
Path(String),
|
|
Git {
|
|
url: String,
|
|
branch: Option<String>,
|
|
tag: Option<String>,
|
|
rev: Option<String>,
|
|
},
|
|
Registry {
|
|
version: String,
|
|
features: Option<Vec<String>>,
|
|
},
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug, Clone)]
|
|
pub struct DepSpec {
|
|
pub name: String,
|
|
pub source: DepSource,
|
|
pub include_raw: Option<Vec<String>>,
|
|
pub lib_raw: Option<Vec<String>>,
|
|
pub libs_raw: Option<Vec<String>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct ResolvedDeps {
|
|
pub include_dirs: Vec<String>,
|
|
pub lib_dirs: Vec<String>,
|
|
pub libs: Vec<String>,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn resolve_path(project_root: &Path, raw: &str) -> Result<PathBuf, String> {
|
|
let p = Path::new(raw);
|
|
let full = if p.is_absolute() {
|
|
p.to_path_buf()
|
|
} else {
|
|
project_root.join(p)
|
|
};
|
|
Ok(full)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn resolve_paths(
|
|
base: &Path,
|
|
raw: Option<&[String]>,
|
|
defaults: &[&str],
|
|
profile: &str,
|
|
) -> Result<Vec<PathBuf>, String> {
|
|
let mut out = Vec::new();
|
|
if let Some(raw) = raw {
|
|
for r in raw {
|
|
let expanded = expand_profile(r, profile);
|
|
let p = Path::new(&expanded);
|
|
let full = if p.is_absolute() {
|
|
p.to_path_buf()
|
|
} else {
|
|
base.join(p)
|
|
};
|
|
if !full.exists() {
|
|
return Err(format!("Path does not exist: {}", full.display()));
|
|
}
|
|
out.push(full);
|
|
}
|
|
return Ok(out);
|
|
}
|
|
|
|
for d in defaults {
|
|
let candidate = base.join(d);
|
|
if candidate.exists() {
|
|
out.push(candidate);
|
|
}
|
|
}
|
|
Ok(out)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn expand_profile(raw: &str, profile: &str) -> String {
|
|
raw.replace("{profile}", profile)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn sync_dep_dir(src: &Path, dst: &Path) -> std::io::Result<()> {
|
|
if dst.exists() {
|
|
fs::remove_dir_all(dst)?;
|
|
}
|
|
copy_dir_all(src, dst)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn copy_dir_all(src: &Path, dst: &Path) -> std::io::Result<()> {
|
|
fs::create_dir_all(dst)?;
|
|
for entry in fs::read_dir(src)? {
|
|
let entry = entry?;
|
|
let ty = entry.file_type()?;
|
|
let from = entry.path();
|
|
let to = dst.join(entry.file_name());
|
|
if ty.is_dir() {
|
|
copy_dir_all(&from, &to)?;
|
|
} else {
|
|
fs::copy(&from, &to)?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|