diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index 44e9daf04..0cb6e8487 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -34,7 +34,5 @@ jobs: printf "\n" >> user/libs/libc/src/include/internal/bindings/bindings.rs - name: Check format - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + run: | + FMT_CHECK=1 make fmt diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 6716a47d6..000000000 --- a/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[workspace] -resolver = "2" - -members = [ - "kernel", - "user/libs/libc/", -] diff --git a/Makefile b/Makefile index 876a19c16..39316c440 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,16 @@ export NM=$(DragonOS_GCC)/x86_64-elf-nm export AR=$(DragonOS_GCC)/x86_64-elf-ar export OBJCOPY=$(DragonOS_GCC)/x86_64-elf-objcopy +# 检查是否需要进行fmt --check +# 解析命令行参数 +FMT_CHECK?=0 + +ifeq ($(FMT_CHECK), 1) + FMT_CHECK=--check +else + FMT_CHECK= +endif + .PHONY: all all: kernel user @@ -142,6 +152,11 @@ run-docker: $(MAKE) write_diskimage || exit 1 $(MAKE) qemu +fmt: + @echo "格式化代码" + FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel + FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user + help: @echo "编译:" @echo " make all -j - 本地编译,不运行,n为要用于编译的CPU核心数" diff --git a/docs/introduction/build_system.md b/docs/introduction/build_system.md index 38e91cd56..c4f007033 100644 --- a/docs/introduction/build_system.md +++ b/docs/introduction/build_system.md @@ -236,6 +236,7 @@ make run-docker - 清理编译产生的文件: `make clean` - 编译文档: `make docs` (需要手动安装sphinx以及docs下的`requirements.txt`中的依赖) - 清理文档: `make clean-docs` +- 格式化代码: `make fmt` :::{note} 如果您需要在vnc中运行DragonOS,请在上述命令后加上`-vnc`后缀。如:`make run-vnc` diff --git a/kernel/Makefile b/kernel/Makefile index f27404730..043c45c69 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -6,4 +6,8 @@ all: clean: rm -f Cargo.lock - $(MAKE) -C src clean \ No newline at end of file + $(MAKE) -C src clean + +.PHONY: fmt +fmt: + cargo fmt --all $(FMT_CHECK) \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 3d8081580..000000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,3 +0,0 @@ -[toolchain] -channel = "nightly-2023-01-21" -components = ["rust-src"] \ No newline at end of file diff --git a/user/Makefile b/user/Makefile index da796370b..1e400f33c 100644 --- a/user/Makefile +++ b/user/Makefile @@ -112,4 +112,8 @@ clean: cd $$subdir && $(MAKE) clean;\ cd .. ;\ done - \ No newline at end of file + +.PHONY: fmt +fmt: + FMT_CHECK=$(FMT_CHECK) $(MAKE) -C libs + FMT_CHECK=$(FMT_CHECK) $(MAKE) -C apps \ No newline at end of file diff --git a/user/apps/Makefile b/user/apps/Makefile index d3d39ff4d..4daffef42 100644 --- a/user/apps/Makefile +++ b/user/apps/Makefile @@ -9,4 +9,7 @@ $(user_apps_sub_dirs): ECHO $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(sys_libs_dir)" all: $(user_apps_sub_dirs) - \ No newline at end of file + +.PHONY: clean +fmt: + @echo "格式化代码: user/apps" diff --git a/user/libs/Makefile b/user/libs/Makefile index aa2e6fe2b..4d3da120a 100644 --- a/user/libs/Makefile +++ b/user/libs/Makefile @@ -16,4 +16,9 @@ clean: echo "Clean in dir: $$subdir";\ cd $$subdir && $(MAKE) clean;\ cd .. ;\ - done \ No newline at end of file + done + +.PHONY: clean +fmt: + @echo "格式化代码: user/libs" + FMT_CHECK=$(FMT_CHECK) $(MAKE) -C libc fmt diff --git a/user/libs/libc/Makefile b/user/libs/libc/Makefile index 735c2bf72..c805b5f9d 100644 --- a/user/libs/libc/Makefile +++ b/user/libs/libc/Makefile @@ -4,4 +4,8 @@ all: clean: rm -f Cargo.lock - $(MAKE) -C src clean \ No newline at end of file + $(MAKE) -C src clean + +.PHONY: fmt +fmt: + cargo fmt --all $(FMT_CHECK)