Skip to content
Open
844 changes: 492 additions & 352 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions crates/test_base/src/dadk_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ impl TestContext for DadkConfigTestContext {
// 设置workdir
std::env::set_current_dir(&test_base_path).expect("Failed to setup test base path");

let r = DadkConfigTestContext { test_base_path };

r
DadkConfigTestContext { test_base_path }
}
}

Expand Down
2 changes: 1 addition & 1 deletion dadk-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dadk-config"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = [
"longjin <[email protected]>",
Expand Down
13 changes: 13 additions & 0 deletions dadk-config/src/common/target_arch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use serde::{Deserialize, Deserializer, Serialize};

/// 目标处理器架构
Expand Down Expand Up @@ -75,6 +77,17 @@
}
}

impl Display for TargetArch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TargetArch::X86_64 => write!(f, "x86_64"),
TargetArch::RiscV64 => write!(f, "riscv64"),
TargetArch::AArch64 => write!(f, "aarch64"),
TargetArch::LoongArch64 => write!(f, "loongarch64"),

Check warning on line 86 in dadk-config/src/common/target_arch.rs

View check run for this annotation

Codecov / codecov/patch

dadk-config/src/common/target_arch.rs#L81-L86

Added lines #L81 - L86 were not covered by tests
}
}

Check warning on line 88 in dadk-config/src/common/target_arch.rs

View check run for this annotation

Codecov / codecov/patch

dadk-config/src/common/target_arch.rs#L88

Added line #L88 was not covered by tests
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
12 changes: 6 additions & 6 deletions dadk-config/src/common/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

pub fn validate(&self) -> Result<()> {
return Ok(());
Ok(())
}

pub fn trim(&mut self) {
Expand Down Expand Up @@ -101,7 +101,7 @@
"InstallConfig: in_dragonos_path should be an Absolute path",
));
}
return Ok(());
Ok(())
}

pub fn trim(&mut self) {}
Expand All @@ -121,7 +121,7 @@
}

pub fn validate(&self) -> Result<()> {
return Ok(());
Ok(())
}

pub fn trim(&mut self) {
Expand Down Expand Up @@ -153,7 +153,7 @@
if self.version.is_empty() {
return Err(Error::msg("version is empty"));
}
return Ok(());
Ok(())

Check warning on line 156 in dadk-config/src/common/task.rs

View check run for this annotation

Codecov / codecov/patch

dadk-config/src/common/task.rs#L156

Added line #L156 was not covered by tests
}

pub fn trim(&mut self) {
Expand All @@ -162,7 +162,7 @@
}

pub fn name_version(&self) -> String {
return format!("{}-{}", self.name, self.version);
format!("{}-{}", self.name, self.version)

Check warning on line 165 in dadk-config/src/common/task.rs

View check run for this annotation

Codecov / codecov/patch

dadk-config/src/common/task.rs#L165

Added line #L165 was not covered by tests
}
}

Expand Down Expand Up @@ -200,7 +200,7 @@
if self.key.is_empty() {
return Err(Error::msg("Env: key is empty"));
}
return Ok(());
Ok(())
}
}

Expand Down
11 changes: 10 additions & 1 deletion dadk-config/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ fn check_used_default() -> bool {
pub struct Metadata {
/// Target processor architecture
pub arch: TargetArch,

/// DADK builder version for isolating unstable features
#[serde(default = "default_dadk_builder_version", rename = "builder-version")]
pub builder_version: String,

/// Rootfs configuration file path
#[serde(default = "default_rootfs_config_path", rename = "rootfs-config")]
pub rootfs_config: PathBuf,
Expand Down Expand Up @@ -88,6 +93,10 @@ pub struct Metadata {
pub user_config_dir: PathBuf,
}

fn default_dadk_builder_version() -> String {
"v1".to_string()
}

/// Returns the default path for the rootfs configuration file.
fn default_rootfs_config_path() -> PathBuf {
set_used_default();
Expand Down Expand Up @@ -247,7 +256,7 @@ mod tests {
temp_file.write_all(toml_content.as_bytes())?;
let path = temp_file.path().to_path_buf();
let manifest = DadkManifestFile::load(&path)?;
assert_eq!(manifest.used_default, true);
assert!(manifest.used_default);
assert_eq!(
manifest.metadata.rootfs_config,
PathBuf::from("config/rootfs.toml")
Expand Down
4 changes: 2 additions & 2 deletions dadk-config/src/rootfs/fstype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ mod tests {
#[test]
fn test_deserialize_fat32_lowercase() {
let r = deserialize_fs_type("fat32");
assert_eq!(r.is_ok(), true);
assert!(r.is_ok());
let fs_type = r.unwrap();
assert_eq!(fs_type, FsType::Fat32);
}

#[test]
fn test_deserialize_fat32_mixed_case() {
let r = deserialize_fs_type("FAT32");
assert_eq!(r.is_ok(), true);
assert!(r.is_ok());
let fs_type = r.unwrap();
assert_eq!(fs_type, FsType::Fat32);
}
Expand Down
7 changes: 5 additions & 2 deletions dadk-config/src/rootfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ pub mod partition;

mod utils;

use std::{fs, path::PathBuf};
use std::{
fs,
path::{Path, PathBuf},
};

use anyhow::Result;
use fstype::FsType;
Expand All @@ -20,7 +23,7 @@ pub struct RootFSConfigFile {

impl RootFSConfigFile {
pub const LBA_SIZE: usize = 512;
pub fn load(path: &PathBuf) -> Result<Self> {
pub fn load(path: &Path) -> Result<Self> {
// 读取文件内容
let content = fs::read_to_string(path)?;
Self::load_from_str(&content)
Expand Down
8 changes: 3 additions & 5 deletions dadk-config/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ pub fn apply_kv_array(

key_strings.insert(key, arg.to_owned());
continue;
} else if single_value_keys.contains(&arg.as_str()) || multi_value_keys.contains(arg) {
return Err(anyhow!("Invalid argument: {}", arg));
} else {
if single_value_keys.contains(&arg.as_str()) || multi_value_keys.contains(arg) {
return Err(anyhow!("Invalid argument: {}", arg));
} else {
key_strings.insert(arg.to_owned(), arg.to_owned());
}
key_strings.insert(arg.to_owned(), arg.to_owned());
}
}

Expand Down
4 changes: 2 additions & 2 deletions dadk-config/templates/dadk-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ rootfs-config = "config/rootfs.toml"
boot-config = "config/boot.toml"

# System root directory folder (DADK will copy the files in this directory to the root directory of the disk image)
sysroot-dir = "bin/sysroot"
sysroot-dir = "bin/x86_64/sysroot"

# DADK Root Cache directory path
cache-root-dir = "bin/dadk_cache"
cache-root-dir = "bin/x86_64/dadk_cache"

# User configuration directory path
# 这个字段只是临时用于兼容旧版本,v0.2版本重构完成后会删除
Expand Down
4 changes: 2 additions & 2 deletions dadk-config/tests/test_boot_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const BOOT_CONFIG_FILE_NAME: &str = "config/boot.toml";
#[test]
fn test_load_boot_config_template(ctx: &DadkConfigTestContext) {
let boot_config_path = ctx.templates_dir().join(BOOT_CONFIG_FILE_NAME);
assert_eq!(boot_config_path.exists(), true);
assert_eq!(boot_config_path.is_file(), true);
assert!(boot_config_path.exists());
assert!(boot_config_path.is_file());
let _manifest = BootConfigFile::load(&boot_config_path).expect("Failed to load boot config");
// TODO 校验 manifest 中的字段是否齐全
}
6 changes: 3 additions & 3 deletions dadk-config/tests/test_dadk_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const DADK_MANIFEST_FILE_NAME: &str = "dadk-manifest.toml";
#[test]
fn test_load_dadk_manifest_template(ctx: &DadkConfigTestContext) {
let manifest_path = ctx.templates_dir().join(DADK_MANIFEST_FILE_NAME);
assert_eq!(manifest_path.exists(), true);
assert_eq!(manifest_path.is_file(), true);
assert!(manifest_path.exists());
assert!(manifest_path.is_file());
let manifest = DadkManifestFile::load(&manifest_path).expect("Failed to load manifest");
// 验证 dadk-manifest.toml 已经包含了所有字段
assert_eq!(manifest.used_default, false);
assert!(!manifest.used_default);
}
4 changes: 2 additions & 2 deletions dadk-config/tests/test_rootfs_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const ROOTFS_CONFIG_FILE_NAME: &str = "config/rootfs.toml";
#[test]
fn test_load_rootfs_manifest_template(ctx: &DadkConfigTestContext) {
let rootfs_manifest_path = ctx.templates_dir().join(ROOTFS_CONFIG_FILE_NAME);
assert_eq!(rootfs_manifest_path.exists(), true);
assert_eq!(rootfs_manifest_path.is_file(), true);
assert!(rootfs_manifest_path.exists());
assert!(rootfs_manifest_path.is_file());
let manifest =
RootFSConfigFile::load(&rootfs_manifest_path).expect("Failed to load rootfs manifest");
assert_eq!(manifest.partition.partition_type, PartitionType::None);
Expand Down
4 changes: 2 additions & 2 deletions dadk-user/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dadk-user"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
description = "DragonOS Application Development Kit - user prog build"
license = "GPL-2.0-only"
Expand All @@ -9,7 +9,7 @@ license = "GPL-2.0-only"
anyhow = { version = "1.0.90", features = ["std", "backtrace"] }
chrono = { version = "=0.4.35", features = ["serde"] }
clap = { version = "=4.5.20", features = ["derive"] }
dadk-config = { version = "0.3.0", path = "../dadk-config" }
dadk-config = { version = "0.3.1", path = "../dadk-config" }
derive_builder = "0.20.0"
lazy_static = "1.4.0"
log = "0.4.17"
Expand Down
36 changes: 18 additions & 18 deletions dadk-user/src/executor/cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
path::PathBuf,
path::{Path, PathBuf},
sync::{Arc, Once},
};

Expand Down Expand Up @@ -86,7 +86,7 @@
// 设置环境变量
std::env::set_var("DADK_CACHE_ROOT", CACHE_ROOT.get().to_str().unwrap());
info!("Cache root dir: {:?}", CACHE_ROOT.get());
return Ok(());
Ok(())
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -122,7 +122,7 @@

result.create()?;

return Ok(result);
Ok(result)
}

fn get_path(task: &DADKTask, cache_type: CacheDirType) -> PathBuf {
Expand All @@ -143,33 +143,33 @@
)
}
};
abs_path(&PathBuf::from(cache_dir))
abs_path(Path::new(&cache_dir))
}

pub fn build_dir(entity: Arc<SchedEntity>) -> Result<PathBuf, ExecutorError> {
return Ok(Self::new(entity.clone(), CacheDirType::Build)?.path);
Ok(Self::new(entity.clone(), CacheDirType::Build)?.path)

Check warning on line 150 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L150

Added line #L150 was not covered by tests
}

pub fn source_dir(entity: Arc<SchedEntity>) -> Result<PathBuf, ExecutorError> {
return Ok(Self::new(entity.clone(), CacheDirType::Source)?.path);
Ok(Self::new(entity.clone(), CacheDirType::Source)?.path)

Check warning on line 154 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L154

Added line #L154 was not covered by tests
}

pub fn build_dir_env_key(entity: &Arc<SchedEntity>) -> Result<String, ExecutorError> {
let name_version_env = entity.task().name_version_env();
return Ok(format!(
Ok(format!(

Check warning on line 159 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L159

Added line #L159 was not covered by tests
"{}_{}",
Self::DADK_BUILD_CACHE_DIR_ENV_KEY_PREFIX,
name_version_env
));
))

Check warning on line 163 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L163

Added line #L163 was not covered by tests
}

pub fn source_dir_env_key(entity: &Arc<SchedEntity>) -> Result<String, ExecutorError> {
let name_version_env = entity.task().name_version_env();
return Ok(format!(
Ok(format!(

Check warning on line 168 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L168

Added line #L168 was not covered by tests
"{}_{}",
Self::DADK_SOURCE_CACHE_DIR_ENV_KEY_PREFIX,
name_version_env
));
))

Check warning on line 172 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L172

Added line #L172 was not covered by tests
}

pub fn need_source_cache(entity: &Arc<SchedEntity>) -> bool {
Expand Down Expand Up @@ -210,7 +210,7 @@
));
}

return Ok(());
Ok(())
}

/// 判断缓存目录是否为空
Expand All @@ -223,7 +223,7 @@
return Ok(false);
}

return Ok(true);
Ok(true)
}

/// # 递归删除自身目录
Expand All @@ -235,7 +235,7 @@
if path.exists() {
std::fs::remove_dir_all(path).map_err(|e| ExecutorError::IoError(e.to_string()))?;
}
return Ok(());
Ok(())

Check warning on line 238 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L238

Added line #L238 was not covered by tests
}
}

Expand All @@ -248,7 +248,7 @@
const TASK_LOG_FILE_NAME: &'static str = "task_log.toml";
pub fn new(entity: Arc<SchedEntity>) -> Result<Self, ExecutorError> {
let dir = CacheDir::new(entity.clone(), CacheDirType::TaskData)?;
return Ok(Self { dir });
Ok(Self { dir })
}

/// # 获取任务日志
Expand All @@ -257,17 +257,17 @@
if path.exists() {
let content = std::fs::read_to_string(&path).unwrap();
let task_log: TaskLog = toml::from_str(&content).unwrap();
return task_log;
task_log

Check warning on line 260 in dadk-user/src/executor/cache.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/cache.rs#L260

Added line #L260 was not covered by tests
} else {
return TaskLog::new();
TaskLog::new()
}
}

/// # 设置任务日志
pub fn save_task_log(&self, task_log: &TaskLog) -> Result<(), ExecutorError> {
let path = self.dir.path.join(Self::TASK_LOG_FILE_NAME);
let content = toml::to_string(task_log).unwrap();
std::fs::write(&path, content).map_err(|e| ExecutorError::IoError(e.to_string()))?;
return Ok(());
std::fs::write(path, content).map_err(|e| ExecutorError::IoError(e.to_string()))?;
Ok(())
}
}
Loading