Skip to content

Commit 77ad885

Browse files
authored
Merge pull request #112 into 007/docker-multiarch from Vitus213/fk_merge
feat(version):把版本号后延,减少重复代码
2 parents 118df96 + 680d5b2 commit 77ad885

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+678
-948
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/test_base/src/dadk_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl TestContext for DadkConfigTestContext {
4242
// 设置workdir
4343
std::env::set_current_dir(&test_base_path).expect("Failed to setup test base path");
4444

45-
let r = DadkConfigTestContext { test_base_path };
45+
4646

47-
r
47+
DadkConfigTestContext { test_base_path }
4848
}
4949
}
5050

dadk-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dadk-config"
3-
version = "0.2.0"
3+
version = "0.3.1"
44
edition = "2021"
55
authors = [
66
"longjin <[email protected]>",

dadk-config/src/common/target_arch.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ pub enum TargetArch {
99
X86_64,
1010
RiscV64,
1111
AArch64,
12+
LoongArch64,
1213
}
1314

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

1920
impl TryFrom<&str> for TargetArch {
@@ -24,6 +25,7 @@ impl TryFrom<&str> for TargetArch {
2425
"x86_64" => Ok(TargetArch::X86_64),
2526
"riscv64" => Ok(TargetArch::RiscV64),
2627
"aarch64" => Ok(TargetArch::AArch64),
28+
"loongarch64" => Ok(TargetArch::LoongArch64),
2729
_ => Err(format!("Unknown target arch: {}", value)),
2830
}
2931
}
@@ -35,6 +37,7 @@ impl From<TargetArch> for &str {
3537
TargetArch::X86_64 => "x86_64",
3638
TargetArch::RiscV64 => "riscv64",
3739
TargetArch::AArch64 => "aarch64",
40+
TargetArch::LoongArch64 => "loongarch64",
3841
}
3942
}
4043
}
@@ -80,6 +83,7 @@ impl Display for TargetArch {
8083
TargetArch::X86_64 => write!(f, "x86_64"),
8184
TargetArch::RiscV64 => write!(f, "riscv64"),
8285
TargetArch::AArch64 => write!(f, "aarch64"),
86+
TargetArch::LoongArch64 => write!(f, "loongarch64"),
8387
}
8488
}
8589
}
@@ -105,6 +109,9 @@ mod tests {
105109

106110
let aarch64 = TargetArch::try_from("aarch64").unwrap();
107111
assert_eq!(aarch64, TargetArch::AArch64);
112+
113+
let loongarch64 = TargetArch::try_from("loongarch64").unwrap();
114+
assert_eq!(loongarch64, TargetArch::LoongArch64);
108115
}
109116

110117
#[test]
@@ -121,6 +128,12 @@ mod tests {
121128

122129
let riscv64: &str = TargetArch::RiscV64.into();
123130
assert_eq!(riscv64, "riscv64");
131+
132+
let aarch64: &str = TargetArch::AArch64.into();
133+
assert_eq!(aarch64, "aarch64");
134+
135+
let loongarch64: &str = TargetArch::LoongArch64.into();
136+
assert_eq!(loongarch64, "loongarch64");
124137
}
125138

126139
#[test]
@@ -141,6 +154,15 @@ mod tests {
141154
let json_riscv64 = r#""riscv64""#;
142155
let riscv64: TargetArch = serde_json::from_str(json_riscv64).unwrap();
143156
assert_eq!(riscv64, TargetArch::RiscV64);
157+
158+
let json_aarch64 = r#""aarch64""#;
159+
let aarch64: TargetArch = serde_json::from_str(json_aarch64).unwrap();
160+
161+
assert_eq!(aarch64, TargetArch::AArch64);
162+
163+
let json_loongarch64 = r#""loongarch64""#;
164+
let loongarch64: TargetArch = serde_json::from_str(json_loongarch64).unwrap();
165+
assert_eq!(loongarch64, TargetArch::LoongArch64);
144166
}
145167

146168
#[test]

dadk-config/src/common/task.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl BuildConfig {
6969
}
7070

7171
pub fn validate(&self) -> Result<()> {
72-
return Ok(());
72+
Ok(())
7373
}
7474

7575
pub fn trim(&mut self) {
@@ -101,7 +101,7 @@ impl InstallConfig {
101101
"InstallConfig: in_dragonos_path should be an Absolute path",
102102
));
103103
}
104-
return Ok(());
104+
Ok(())
105105
}
106106

107107
pub fn trim(&mut self) {}
@@ -121,7 +121,7 @@ impl CleanConfig {
121121
}
122122

123123
pub fn validate(&self) -> Result<()> {
124-
return Ok(());
124+
Ok(())
125125
}
126126

127127
pub fn trim(&mut self) {
@@ -153,7 +153,7 @@ impl Dependency {
153153
if self.version.is_empty() {
154154
return Err(Error::msg("version is empty"));
155155
}
156-
return Ok(());
156+
Ok(())
157157
}
158158

159159
pub fn trim(&mut self) {
@@ -162,7 +162,7 @@ impl Dependency {
162162
}
163163

164164
pub fn name_version(&self) -> String {
165-
return format!("{}-{}", self.name, self.version);
165+
format!("{}-{}", self.name, self.version)
166166
}
167167
}
168168

@@ -200,7 +200,7 @@ impl TaskEnv {
200200
if self.key.is_empty() {
201201
return Err(Error::msg("Env: key is empty"));
202202
}
203-
return Ok(());
203+
Ok(())
204204
}
205205
}
206206

dadk-config/src/manifest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ pub struct Metadata {
8787
pub cache_root_dir: PathBuf,
8888

8989
/// User configuration directory path
90-
/// 这个字段只是临时用于兼容旧版本,v0.2版本重构完成后会删除
91-
#[deprecated(note = "This field is deprecated and will be removed in DADK 0.2")]
90+
/// 这个字段只是临时用于兼容旧版本,v1.0版本重构完成后会删除
91+
#[deprecated(note = "This field is deprecated and will be removed in DADK 1.0")]
9292
#[serde(default = "default_user_config_dir", rename = "user-config-dir")]
9393
pub user_config_dir: PathBuf,
9494
}
@@ -256,7 +256,7 @@ mod tests {
256256
temp_file.write_all(toml_content.as_bytes())?;
257257
let path = temp_file.path().to_path_buf();
258258
let manifest = DadkManifestFile::load(&path)?;
259-
assert_eq!(manifest.used_default, true);
259+
assert!(manifest.used_default);
260260
assert_eq!(
261261
manifest.metadata.rootfs_config,
262262
PathBuf::from("config/rootfs.toml")

dadk-config/src/rootfs/fstype.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ mod tests {
3333
#[test]
3434
fn test_deserialize_fat32_lowercase() {
3535
let r = deserialize_fs_type("fat32");
36-
assert_eq!(r.is_ok(), true);
36+
assert!(r.is_ok());
3737
let fs_type = r.unwrap();
3838
assert_eq!(fs_type, FsType::Fat32);
3939
}
4040

4141
#[test]
4242
fn test_deserialize_fat32_mixed_case() {
4343
let r = deserialize_fs_type("FAT32");
44-
assert_eq!(r.is_ok(), true);
44+
assert!(r.is_ok());
4545
let fs_type = r.unwrap();
4646
assert_eq!(fs_type, FsType::Fat32);
4747
}

dadk-config/src/utils.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ pub fn apply_kv_array(
9090

9191
key_strings.insert(key, arg.to_owned());
9292
continue;
93+
} else if single_value_keys.contains(&arg.as_str()) || multi_value_keys.contains(arg) {
94+
return Err(anyhow!("Invalid argument: {}", arg));
9395
} else {
94-
if single_value_keys.contains(&arg.as_str()) || multi_value_keys.contains(arg) {
95-
return Err(anyhow!("Invalid argument: {}", arg));
96-
} else {
97-
key_strings.insert(arg.to_owned(), arg.to_owned());
98-
}
96+
key_strings.insert(arg.to_owned(), arg.to_owned());
9997
}
10098
}
10199

dadk-config/templates/config/userapp_config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ build-once = false
1414
install-once = false
1515

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

2020
# 任务源

dadk-config/tests/test_boot_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const BOOT_CONFIG_FILE_NAME: &str = "config/boot.toml";
1111
#[test]
1212
fn test_load_boot_config_template(ctx: &DadkConfigTestContext) {
1313
let boot_config_path = ctx.templates_dir().join(BOOT_CONFIG_FILE_NAME);
14-
assert_eq!(boot_config_path.exists(), true);
15-
assert_eq!(boot_config_path.is_file(), true);
14+
assert!(boot_config_path.exists());
15+
assert!(boot_config_path.is_file());
1616
let _manifest = BootConfigFile::load(&boot_config_path).expect("Failed to load boot config");
1717
// TODO 校验 manifest 中的字段是否齐全
1818
}

0 commit comments

Comments
 (0)