diff options
| author | Bernard Xiong <[email protected]> | 2025-06-25 15:06:45 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-25 15:06:45 +0800 |
| commit | 5a2352eb64f5a1039b37368f2a9c199db32957a0 (patch) | |
| tree | f2153efa40eaef9ee4b3c66ad2eb74ea7d29b8d0 /tools/hello | |
| parent | 8e9872a55456b38d28b0d7d076905be84d0af7a2 (diff) | |
[scons] code cleanup for scons script. (#10429)
* [scons] move project_generation to targets; code clean for building.py.
Diffstat (limited to 'tools/hello')
| -rw-r--r-- | tools/hello/README.md | 49 | ||||
| -rw-r--r-- | tools/hello/SConscript | 4 | ||||
| -rw-r--r-- | tools/hello/hello.c | 22 | ||||
| -rw-r--r-- | tools/hello/hello.h | 29 | ||||
| -rw-r--r-- | tools/hello/package.json | 20 |
5 files changed, 124 insertions, 0 deletions
diff --git a/tools/hello/README.md b/tools/hello/README.md new file mode 100644 index 0000000000..c7a8a0d004 --- /dev/null +++ b/tools/hello/README.md @@ -0,0 +1,49 @@ +# Hello Component + +这是一个使用package.json配置的RT-Thread组件示例,展示了如何使用package.json来替代传统的SConscript中DefineGroup的方式。 + +## 文件结构 + +``` +hello/ +├── hello.h # 头文件 +├── hello.c # 源文件 +├── package.json # 组件配置文件 +├── SConscript # 构建脚本 +└── README.md # 说明文档 +``` + +## package.json配置说明 + +package.json文件包含了组件的所有构建信息: + +- `name`: 组件名称 +- `version`: 版本号 +- `description`: 组件描述 +- `author`: 作者信息 +- `license`: 许可证 +- `source_files`: 源文件列表 +- `CPPPATH`: 头文件搜索路径 +- `CPPDEFINES`: 预定义宏 +- `depends`: 依赖的组件 + +## 使用方法 + +1. 将hello文件夹复制到你的RT-Thread项目的components目录下 +2. 在应用代码中包含头文件: + ```c + #include "hello.h" + ``` +3. 调用hello_world函数: + ```c + hello_world(); // 输出: Hello World! + ``` + +## 构建过程 + +SConscript文件会: +1. 导入package.py模块 +2. 调用BuildPackage函数处理package.json +3. 自动创建DefineGroup并返回构建对象 + +这种方式比传统的SConscript更加简洁和易于维护。
\ No newline at end of file diff --git a/tools/hello/SConscript b/tools/hello/SConscript new file mode 100644 index 0000000000..d75ecc66d7 --- /dev/null +++ b/tools/hello/SConscript @@ -0,0 +1,4 @@ +from package import * + +objs = BuildPackage() +Return('objs') diff --git a/tools/hello/hello.c b/tools/hello/hello.c new file mode 100644 index 0000000000..f8c6fcc9c6 --- /dev/null +++ b/tools/hello/hello.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-06-21 Bernard First version + */ + +#include <rtthread.h> +#include "hello.h" + +/** + * @brief Hello world function implementation + * + * This function prints "Hello World!" to the console using rt_kprintf + */ +void hello_world(void) +{ + rt_kprintf("Hello World!\n"); +} diff --git a/tools/hello/hello.h b/tools/hello/hello.h new file mode 100644 index 0000000000..b1f81388c9 --- /dev/null +++ b/tools/hello/hello.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-06-21 Bernard First version + */ + +#ifndef __HELLO_H__ +#define __HELLO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Hello world function + * + * This function prints "Hello World!" to the console + */ +void hello_world(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __HELLO_H__ */ diff --git a/tools/hello/package.json b/tools/hello/package.json new file mode 100644 index 0000000000..1e390882b1 --- /dev/null +++ b/tools/hello/package.json @@ -0,0 +1,20 @@ +{ + "name": "hello", + "version": "1.0.0", + "description": "Hello World component for RT-Thread", + "author": "RT-Thread Development Team", + "license": "Apache-2.0", + "type": "rt-package", + "source_files": [ + "hello.c" + ], + "CPPPATH": [ + "." + ], + "CPPDEFINES": [ + "HELLO" + ], + "depends": [ + "" + ] +}
\ No newline at end of file |
