From 24714d69f0504ee8e783dca43b2566d212fdaeb6 Mon Sep 17 00:00:00 2001 From: Jomocool <2512364506@qq.com> Date: Thu, 14 Nov 2024 22:48:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dadk-config/src/common/task.rs | 18 ++++++++++-- dadk-config/tests/test_user_config.rs | 2 +- dadk-user/src/executor/mod.rs | 42 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/dadk-config/src/common/task.rs b/dadk-config/src/common/task.rs index 11787ac..24f348d 100644 --- a/dadk-config/src/common/task.rs +++ b/dadk-config/src/common/task.rs @@ -46,12 +46,26 @@ pub struct BuildConfig { /// 构建命令 #[serde(rename = "build-command")] pub build_command: Option, + /// 构建前执行的脚本 + #[serde(rename = "pre-build")] + pub pre_build: Option, + #[serde(rename = "post-build")] + /// 构建后执行的脚本 + pub post_build: Option, } impl BuildConfig { #[allow(dead_code)] - pub fn new(build_command: Option) -> Self { - Self { build_command } + pub fn new( + build_command: Option, + pre_build: Option, + post_build: Option, + ) -> Self { + Self { + build_command, + pre_build, + post_build, + } } pub fn validate(&self) -> Result<()> { diff --git a/dadk-config/tests/test_user_config.rs b/dadk-config/tests/test_user_config.rs index 50c5028..1b2e0e5 100644 --- a/dadk-config/tests/test_user_config.rs +++ b/dadk-config/tests/test_user_config.rs @@ -51,7 +51,7 @@ fn test_parse_dadk_user_config(ctx: &mut DadkConfigTestContext) { version: "0.1.2".to_string(), }, ], - build: BuildConfig::new(Some("make install".to_string())), + build: BuildConfig::new(Some("make install".to_string()), None, None), install: InstallConfig::new(Some(PathBuf::from("/bin"))), clean: CleanConfig::new(Some("make clean".to_string())), envs: vec![ diff --git a/dadk-user/src/executor/mod.rs b/dadk-user/src/executor/mod.rs index f25e8ec..146b918 100644 --- a/dadk-user/src/executor/mod.rs +++ b/dadk-user/src/executor/mod.rs @@ -149,8 +149,12 @@ impl Executor { match self.action { Action::Build => { + // 构建前的工作 + self.pre_build()?; // 构建任务 self.build()?; + // 构建完毕后的工作 + self.post_build()?; } Action::Install => { // 把构建结果安装到DragonOS @@ -172,6 +176,25 @@ impl Executor { return Ok(()); } + fn pre_build(&mut self) -> Result<(), ExecutorError> { + if let Some(pre_build) = self.entity.task().build.pre_build { + let output = Command::new(pre_build) + .output() + .expect("Failed to execute pre_build script"); + + // 检查脚本执行结果 + if output.status.success() { + info!("Pre-build script executed successfully"); + } else { + error!("Pre-build script failed"); + return Err(ExecutorError::TaskFailed( + "Pre-build script failed".to_string(), + )); + } + } + Ok(()) + } + fn build(&mut self) -> Result<(), ExecutorError> { if let Some(status) = self.task_log().build_status() { if let Some(build_time) = self.task_log().build_time() { @@ -191,6 +214,25 @@ impl Executor { return self.do_build(); } + fn post_build(&mut self) -> Result<(), ExecutorError> { + if let Some(post_build) = self.entity.task().build.post_build { + let output = Command::new(post_build) + .output() + .expect("Failed to execute post_build script"); + + // 检查脚本执行结果 + if output.status.success() { + info!("Post-build script executed successfully"); + } else { + error!("Post-build script failed"); + return Err(ExecutorError::TaskFailed( + "Post-buildscript failed".to_string(), + )); + } + } + Ok(()) + } + /// # 执行build操作 fn do_build(&mut self) -> Result<(), ExecutorError> { // 确认源文件就绪 From 9cd07b5ec981f040be2ed1fcb111950570d2d005 Mon Sep 17 00:00:00 2001 From: Jomocool <2512364506@qq.com> Date: Sat, 16 Nov 2024 18:58:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dadk-config/templates/config/userapp_config.toml | 6 ++++++ dadk-config/tests/test_user_config.rs | 6 +++++- dadk-user/src/executor/mod.rs | 9 ++++++--- dadk-user/src/parser/mod.rs | 1 - 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dadk-config/templates/config/userapp_config.toml b/dadk-config/templates/config/userapp_config.toml index 5556bca..5b3d0ae 100644 --- a/dadk-config/templates/config/userapp_config.toml +++ b/dadk-config/templates/config/userapp_config.toml @@ -44,6 +44,12 @@ revision = "01cdc56863" # (可选)构建命令 build-command = "make install" +# (可选)预构建脚本路径 +pre-build = "config/pre_build.sh" + +# (可选)构建后脚本路径 +post-build = "config/post_build.sh" + # 安装相关信息 [install] diff --git a/dadk-config/tests/test_user_config.rs b/dadk-config/tests/test_user_config.rs index 1b2e0e5..149c321 100644 --- a/dadk-config/tests/test_user_config.rs +++ b/dadk-config/tests/test_user_config.rs @@ -51,7 +51,11 @@ fn test_parse_dadk_user_config(ctx: &mut DadkConfigTestContext) { version: "0.1.2".to_string(), }, ], - build: BuildConfig::new(Some("make install".to_string()), None, None), + build: BuildConfig::new( + Some("make install".to_string()), + Some(PathBuf::from("config/pre_build.sh")), + Some(PathBuf::from("config/post_build.sh")), + ), install: InstallConfig::new(Some(PathBuf::from("/bin"))), clean: CleanConfig::new(Some("make clean".to_string())), envs: vec![ diff --git a/dadk-user/src/executor/mod.rs b/dadk-user/src/executor/mod.rs index 804ec0a..877358a 100644 --- a/dadk-user/src/executor/mod.rs +++ b/dadk-user/src/executor/mod.rs @@ -199,7 +199,7 @@ impl Executor { fn build(&mut self) -> Result<(), ExecutorError> { if let Some(status) = self.task_log().build_status() { if let Some(build_time) = self.task_log().build_time() { - let mut last_modified = last_modified_time(&self.entity.file_path(), build_time)?; + let mut last_modified = last_modified_time(&self.entity.file_path(), build_time)?; last_modified = core::cmp::max( last_modified, last_modified_time(&self.src_work_dir(), build_time)?, @@ -232,7 +232,7 @@ impl Executor { } else { error!("Post-build script failed"); return Err(ExecutorError::TaskFailed( - "Post-buildscript failed".to_string(), + "Post-build script failed".to_string(), )); } } @@ -280,7 +280,10 @@ impl Executor { } } } - log::trace!("dadk-user: to do install {}", self.entity.task().name_version()); + log::trace!( + "dadk-user: to do install {}", + self.entity.task().name_version() + ); return self.do_install(); } diff --git a/dadk-user/src/parser/mod.rs b/dadk-user/src/parser/mod.rs index 6997f97..0f7ecc2 100644 --- a/dadk-user/src/parser/mod.rs +++ b/dadk-user/src/parser/mod.rs @@ -221,7 +221,6 @@ impl Parser { // 从toml文件中解析出DADKTask let mut task: DADKTask = Self::parse_toml_file(config_file)?; - // 去除字符串中的空白字符 task.trim(); From d5c40905a131767f04e69233e59078124135c180 Mon Sep 17 00:00:00 2001 From: Jomocool <2512364506@qq.com> Date: Sun, 17 Nov 2024 17:19:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/user-manual/README.md | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/docs/user-manual/README.md b/docs/user-manual/README.md index 1d01e47..625e40d 100644 --- a/docs/user-manual/README.md +++ b/docs/user-manual/README.md @@ -1,3 +1,90 @@ # 用户指南 +## 用户程序配置文件模版 +在dadk-config/templates/config/目录下,可以找到用户程序的配置文件模版`userapp_config.toml` +```toml +# 用户程序名称 +name = "userapp_config" + +# 版本号 +version = "0.2.0" + +# 用户程序描述信息 +description = "" + +# (可选)默认: false 是否只构建一次,如果为true,DADK会在构建成功后,将构建结果缓存起来,下次构建时,直接使用缓存的构建结果 +build-once = false + +# (可选) 默认: false 是否只安装一次,如果为true,DADK会在安装成功后,不再重复安装 +install-once = false + +# 目标架构 +# 可选值:"x86_64", "aarch64", "riscv64" +target-arch = ["x86_64"] + +# 任务源 +[task-source] + +# 构建类型 +# 可选值:"build-from_source", "install-from-prebuilt" +type = "build-from-source" + +# 构建来源 +# "build_from_source" 可选值:"git", "local", "archive" +# "install_from_prebuilt" 可选值:"local", "archive" +source = "git" + +# 路径或URL +source-path = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/test_git.git" + +# git标签或分支 +# 注意: branch和revision只能二选一,且source要设置为"git" +revision = "01cdc56863" +# branch = "test" + +# 构建相关信息 +[build] + +# (可选)构建命令 +build-command = "make install" + +# (可选)预构建脚本路径 +pre-build = "config/pre_build.sh" + +# (可选)构建后脚本路径 +post-build = "config/post_build.sh" + +# 安装相关信息 +[install] + +# (可选)安装到DragonOS的路径 +in-dragonos-path = "/bin" + +# 清除相关信息 +[clean] + +# (可选)清除命令 +clean-command = "make clean" + +# (可选)依赖项 +# 注意:如果没有依赖项,忽略此项,不允许只留一个[[depends]] +[[depends]] +name = "depend1" +version = "0.1.1" + +[[depends]] +name = "depend2" +version = "0.1.2" + +# (可选)环境变量 +[[envs]] +key = "PATH" +value = "/usr/bin" + +[[envs]] +key = "LD_LIBRARY_PATH" +value = "/usr/lib" + +``` + TODO