-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: longjin <[email protected]>
- Loading branch information
Showing
5 changed files
with
95 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 环境变量 | ||
|
||
## 1. DADK为什么设置环境变量? | ||
|
||
在构建用户程序的过程中,DADK会设置一些环境变量,使得: | ||
|
||
- 构建脚本能够知道把构建产物放到哪里。 | ||
- 构建脚本能够知道它的依赖项的构建输出目录在哪里,以便引用它们。 | ||
|
||
## 2. 环境变量的分类 | ||
|
||
在DADK构建用户程序的过程中,环境变量分为两种: | ||
|
||
- 全局环境变量:这些变量在所有构建任务中都可用。 | ||
- 任务环境变量:这些变量仅在当前任务中可用。通过[dadk用户程序配置文件](https://github.com/DragonOS-Community/DADK/blob/main/dadk-config/templates/config/userapp_config.toml)的`envs`字段设置。 | ||
|
||
## 3. 全局环境变量 | ||
|
||
|
||
|
||
### 3.1 变量列表 | ||
|
||
DADK在构建用户程序的过程中,将会设置以下全局环境变量: | ||
|
||
- `DADK_CACHE_ROOT`:DADK的缓存根目录。您可以在编译脚本中,通过引用该环境变量,来获得DADK的缓存根目录。 | ||
- `DADK_BUILD_CACHE_DIR_任务名_任务版本`:DADK的任务构建结果缓存目录。当您要引用其他软件库的构建结果时,可以通过该环境变量来获得。 | ||
同时,您也要在构建您的app时,把构建结果放到您的软件库的构建结果缓存目录(通过对应的环境变量获得)中。 | ||
- `DADK_SOURCE_CACHE_DIR_任务名_任务版本`:DADK的某个任务的源码目录。当您要引用其他软件库的源码目录时,可以通过该环境变量来获得。 | ||
- `DADK_CURRENT_BUILD_DIR`:当前任务的构建结果输出目录。您可以在编译脚本中,通过引用该环境变量,来获得当前任务的构建结果输出目录。构建完成时,您的构建脚本应当把构建结果放到该目录中。 | ||
|
||
### 3.2 名称字符替换 | ||
|
||
由于环境变量的名称不能包含某些字符,而全局环境变量会引用任务的名称、版本号信息。 | ||
因此,在设置环境变量时,DADK会对变量名称进行字符替换。 | ||
|
||
具体规则如下: | ||
|
||
- 将所有字母转为大写。 | ||
- 按照下表对其他字符进行替换 | ||
|
||
|
||
| 原字符 | 替换字符 | | ||
| ------ | -------- | | ||
| `.` | `_` | | ||
| `-` | `_` | | ||
| `\t` | `_` | | ||
| 空格 | `_` | | ||
| `+` | `_` | | ||
| `*` | `_` | | ||
|
||
**举例**:对于任务`libc-0.1.0`,其构建结果缓存目录的全局环境变量名为`DADK_BUILD_CACHE_DIR_LIBC_0_1_0`。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 构建用户程序 | ||
|
||
::: tip | ||
在阅读本文之前,请确保你已经读过了[Quick Start](./quickstart.md) | ||
::: | ||
|
||
## DADK的工作原理 | ||
|
||
DADK使用`(任务名,任务版本)`二元组来标识每个构建目标。 | ||
|
||
当使用DADK构建DragonOS应用时,DADK会根据用户的配置文件,自动完成以下工作: | ||
|
||
- 解析配置文件,生成DADK任务列表 | ||
- 根据DADK任务列表,进行拓扑排序。这一步会自动处理任务的依赖关系。 | ||
- 收集环境变量信息,并根据DADK任务列表,设置全局环境变量、任务环境变量。 | ||
- 根据拓扑排序后的DADK任务列表,自动执行任务。 | ||
- 从各个任务的输出缓存目录中,收集构建结果,拷贝到`bin/sysroot`目录下。 | ||
|
||
## 我该如何编写我的构建脚本? | ||
|
||
你可以参考这个示例: | ||
|
||
- [http server示例程序](https://code.dragonos.org.cn/xref/DragonOS-0.1.10/user/apps/http_server/Makefile) | ||
|
||
原理就是,在构建阶段时,把程序拷贝到`DADK_CURRENT_BUILD_DIR`目录下。 | ||
|
||
## 我该如何编写dadk用户程序编译配置文件? | ||
|
||
DADK用户程序编译配置文件的模版里面,有详细的注释,你可以参考这个: | ||
|
||
- [userapp_config.toml](https://github.com/DragonOS-Community/DADK/blob/main/dadk-config/templates/config/userapp_config.toml) |