Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/test_base/src/dadk_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ 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.2.0"
version = "0.3.1"
edition = "2021"
authors = [
"longjin <[email protected]>",
Expand Down
24 changes: 23 additions & 1 deletion dadk-config/src/common/target_arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ pub enum TargetArch {
X86_64,
RiscV64,
AArch64,
LoongArch64,
}

impl TargetArch {
/// 期望的目标处理器架构(如果修改了枚举,那一定要修改这里)
pub const EXPECTED: [&'static str; 3] = ["x86_64", "riscv64", "aarch64"];
pub const EXPECTED: [&'static str; 4] = ["x86_64", "riscv64", "aarch64", "loongarch64"];
}

impl TryFrom<&str> for TargetArch {
Expand All @@ -24,6 +25,7 @@ impl TryFrom<&str> for TargetArch {
"x86_64" => Ok(TargetArch::X86_64),
"riscv64" => Ok(TargetArch::RiscV64),
"aarch64" => Ok(TargetArch::AArch64),
"loongarch64" => Ok(TargetArch::LoongArch64),
_ => Err(format!("Unknown target arch: {}", value)),
}
}
Expand All @@ -35,6 +37,7 @@ impl From<TargetArch> for &str {
TargetArch::X86_64 => "x86_64",
TargetArch::RiscV64 => "riscv64",
TargetArch::AArch64 => "aarch64",
TargetArch::LoongArch64 => "loongarch64",
}
}
}
Expand Down Expand Up @@ -80,6 +83,7 @@ impl Display for TargetArch {
TargetArch::X86_64 => write!(f, "x86_64"),
TargetArch::RiscV64 => write!(f, "riscv64"),
TargetArch::AArch64 => write!(f, "aarch64"),
TargetArch::LoongArch64 => write!(f, "loongarch64"),
}
}
}
Expand All @@ -105,6 +109,9 @@ mod tests {

let aarch64 = TargetArch::try_from("aarch64").unwrap();
assert_eq!(aarch64, TargetArch::AArch64);

let loongarch64 = TargetArch::try_from("loongarch64").unwrap();
assert_eq!(loongarch64, TargetArch::LoongArch64);
}

#[test]
Expand All @@ -121,6 +128,12 @@ mod tests {

let riscv64: &str = TargetArch::RiscV64.into();
assert_eq!(riscv64, "riscv64");

let aarch64: &str = TargetArch::AArch64.into();
assert_eq!(aarch64, "aarch64");

let loongarch64: &str = TargetArch::LoongArch64.into();
assert_eq!(loongarch64, "loongarch64");
}

#[test]
Expand All @@ -141,6 +154,15 @@ mod tests {
let json_riscv64 = r#""riscv64""#;
let riscv64: TargetArch = serde_json::from_str(json_riscv64).unwrap();
assert_eq!(riscv64, TargetArch::RiscV64);

let json_aarch64 = r#""aarch64""#;
let aarch64: TargetArch = serde_json::from_str(json_aarch64).unwrap();

assert_eq!(aarch64, TargetArch::AArch64);

let json_loongarch64 = r#""loongarch64""#;
let loongarch64: TargetArch = serde_json::from_str(json_loongarch64).unwrap();
assert_eq!(loongarch64, TargetArch::LoongArch64);
}

#[test]
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 @@ impl BuildConfig {
}

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

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

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

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

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

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions dadk-config/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub struct Metadata {
pub cache_root_dir: PathBuf,

/// User configuration directory path
/// 这个字段只是临时用于兼容旧版本,v0.2版本重构完成后会删除
#[deprecated(note = "This field is deprecated and will be removed in DADK 0.2")]
/// 这个字段只是临时用于兼容旧版本,v1.0版本重构完成后会删除
#[deprecated(note = "This field is deprecated and will be removed in DADK 1.0")]
#[serde(default = "default_user_config_dir", rename = "user-config-dir")]
pub user_config_dir: PathBuf,
}
Expand Down Expand Up @@ -256,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
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
2 changes: 1 addition & 1 deletion dadk-config/templates/config/userapp_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build-once = false
install-once = false

# 目标架构
# 可选值:"x86_64", "aarch64", "riscv64"
# 可选值:"x86_64", "aarch64", "riscv64", "loongarch64"
target-arch = ["x86_64"]

# 任务源
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.2.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.2.0", path = "../dadk-config" }
dadk-config = { version = "0.3.0", path = "../dadk-config" }
derive_builder = "0.20.0"
lazy_static = "1.4.0"
log = "0.4.17"
Expand Down
Loading