Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dadk-user): 增加目录依赖 #79

Merged
merged 5 commits into from
Nov 17, 2024
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
18 changes: 16 additions & 2 deletions dadk-config/src/common/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,26 @@ pub struct BuildConfig {
/// 构建命令
#[serde(rename = "build-command")]
pub build_command: Option<String>,
/// 构建前执行的脚本
#[serde(rename = "pre-build")]
pub pre_build: Option<PathBuf>,
#[serde(rename = "post-build")]
/// 构建后执行的脚本
pub post_build: Option<PathBuf>,
}

impl BuildConfig {
#[allow(dead_code)]
pub fn new(build_command: Option<String>) -> Self {
Self { build_command }
pub fn new(
build_command: Option<String>,
pre_build: Option<PathBuf>,
post_build: Option<PathBuf>,
) -> Self {
Self {
build_command,
pre_build,
post_build,
}
}

pub fn validate(&self) -> Result<()> {
Expand Down
6 changes: 6 additions & 0 deletions dadk-config/templates/config/userapp_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ revision = "01cdc56863"
# (可选)构建命令
build-command = "make install"

# (可选)预构建脚本路径
pre-build = "config/pre_build.sh"

# (可选)构建后脚本路径
post-build = "config/post_build.sh"

# 安装相关信息
[install]

Expand Down
6 changes: 5 additions & 1 deletion dadk-config/tests/test_user_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
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![
Expand Down
42 changes: 42 additions & 0 deletions dadk-user/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@

match self.action {
Action::Build => {
// 构建前的工作
self.pre_build()?;
// 构建任务
self.build()?;
// 构建完毕后的工作
self.post_build()?;
}
Action::Install => {
// 把构建结果安装到DragonOS
Expand All @@ -173,6 +177,25 @@
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");

Check warning on line 188 in dadk-user/src/executor/mod.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/mod.rs#L182-L188

Added lines #L182 - L188 were not covered by tests
} else {
error!("Pre-build script failed");
return Err(ExecutorError::TaskFailed(
"Pre-build script failed".to_string(),
));

Check warning on line 193 in dadk-user/src/executor/mod.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/mod.rs#L190-L193

Added lines #L190 - L193 were not covered by tests
}
}
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() {
Expand All @@ -197,6 +220,25 @@
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");

Check warning on line 231 in dadk-user/src/executor/mod.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/mod.rs#L225-L231

Added lines #L225 - L231 were not covered by tests
} else {
error!("Post-build script failed");
return Err(ExecutorError::TaskFailed(
"Post-build script failed".to_string(),
));

Check warning on line 236 in dadk-user/src/executor/mod.rs

View check run for this annotation

Codecov / codecov/patch

dadk-user/src/executor/mod.rs#L233-L236

Added lines #L233 - L236 were not covered by tests
}
}
Ok(())
}

/// # 执行build操作
fn do_build(&mut self) -> Result<(), ExecutorError> {
// 确认源文件就绪
Expand Down
87 changes: 87 additions & 0 deletions docs/user-manual/README.md
Original file line number Diff line number Diff line change
@@ -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
Loading