Skip to content

Commit

Permalink
feat(xtask): cargo check-style 现在和 CI/build 一致
Browse files Browse the repository at this point in the history
  • Loading branch information
YdrMaster committed May 12, 2022
1 parent ebd4de4 commit 3d0186d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 68 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ARCH ?= x86_64

.PHONY: help setup rootfs libc-test image test-image check doc clean
.PHONY: help setup update rootfs libc-test other-test image check doc clean

# print top level help
help:
Expand Down Expand Up @@ -40,6 +40,7 @@ check:
doc:
cargo doc --open

# clean targets
clean:
cargo clean
rm -rf rootfs
Expand Down
16 changes: 14 additions & 2 deletions docs/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

1. 先决条件

目前受关注的开发环境为较新版本的 Ubuntu,建议使用 Ubuntu20.04Ubuntu22.04
本文假设读者使用二者之一
目前已测试的开发环境包括 Ubuntu20.04Ubuntu22.04 和 Debian11,
Ubuntu22.04 不能正确编译 x86_64 的 libc 测试
若不需要烧写到物理硬件,使用 WSL2 或其他虚拟机的操作与真机并无不同之处。

在开始之前,确保你的计算机上安装了 git 和 rustup。要在虚拟环境开发或测试,需要 QEMU。
Expand Down Expand Up @@ -44,6 +44,12 @@
make help
```

6. 推到仓库前,现在本机执行测试

```bash
make check # CI/build 的一部分,未来会实现更多快速测试指令
```

## Linux 模式

zCore 根据向用户提供的系统调用的不同,可分为 zircon 模式和 linux 模式。
Expand All @@ -67,6 +73,12 @@ make rootfs ARCH=riscv64
make libc-test <ARCH=?>
```

要执行 CI 的其他测试,需要向文件系统中添加相应测试集:

```bash
make other-test <ARCH=?>
```

要以裸机模式启动 zCore,需要构造将放到设备或虚拟环境中的镜像文件:

```bash
Expand Down
18 changes: 18 additions & 0 deletions xtask/CHANGLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

最新的更新将出现在最上方。

## 20220512(YdrMaster)

`cargo check-style` 现在会依 CI/build 的方式工作。

## 20220511(YdrMaster)

### 目录结构定义
Expand All @@ -23,3 +27,17 @@
### 实现变更

- 使用 `std::os::unix::fs::symlink` 建立符号链接,不再依赖 `ln` 应用程序;

## 20220506(YdrMaster)

顶层的 Makefile 已经尽量迁移到 rust,并在子项目 README.md 中更新了子命令说明。

计划提起一次 PR。

## 20220504(YdrMaster)

初步的计划是先尽量将 Makefile 转化为类型安全且更有可能工程化结构化的 Rust xtask。
尤其是要将 zCore 目录内外的两个 Makefile 合并。

目前已经架空了外面 Makefile 的 rootfs 指令,这个指令是用于将加载到内存的最小系统的。
外面的 Makefile 还剩打包镜像、启动某些测试集的功能,但目前命令之间不正交,还需要进一步梳理。
16 changes: 0 additions & 16 deletions xtask/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,3 @@
- [x] 打包可烧写到其他存储介质的 zCore 镜像
- [ ] 启动与 Qemu 关联的 GDB 以支持内核调试
- [ ] 自动化测试:实现与 CI 的逻辑一致性

## 进度日志

- 2022/05/06

顶层的 Makefile 已经尽量迁移到 rust,并在子项目 README.md 中更新了子命令说明。

计划提起一次 PR。

- 2022/05/04

初步的计划是先尽量将 Makefile 转化为类型安全且更有可能工程化结构化的 Rust xtask。
尤其是要将 zCore 目录内外的两个 Makefile 合并。

目前已经架空了外面 Makefile 的 rootfs 指令,这个指令是用于将加载到内存的最小系统的。
外面的 Makefile 还剩打包镜像、启动某些测试集的功能,但目前命令之间不正交,还需要进一步梳理。
34 changes: 1 addition & 33 deletions xtask/src/arch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! 平台相关的操作。
use crate::{dir, download::wget, CommandExt, ALPINE_ROOTFS_VERSION, ALPINE_WEBSITE};
use crate::{dir, download::wget, make::Make, CommandExt, ALPINE_ROOTFS_VERSION, ALPINE_WEBSITE};
use dircpy::copy_dir;
use std::{
ffi::{OsStr, OsString},
Expand Down Expand Up @@ -239,38 +239,6 @@ impl Arch {
}
}

struct Make(Command);

impl AsRef<Command> for Make {
fn as_ref(&self) -> &Command {
&self.0
}
}

impl AsMut<Command> for Make {
fn as_mut(&mut self) -> &mut Command {
&mut self.0
}
}

impl CommandExt for Make {}

impl Make {
fn new(j: Option<usize>) -> Self {
let mut make = Self(Command::new("make"));
match j {
Some(0) => {}
Some(j) => {
make.arg(format!("-j{j}"));
}
None => {
make.arg("-j");
}
}
make
}
}

struct Tar(Command);

impl AsRef<Command> for Tar {
Expand Down
10 changes: 10 additions & 0 deletions xtask/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl Cargo {
Self::new("clippy")
}

pub fn doc() -> Self {
Self::new("doc")
}

pub fn all_features(&mut self) -> &mut Self {
self.arg("--all-features");
self
Expand Down Expand Up @@ -68,8 +72,14 @@ impl Cargo {
self
}

#[allow(unused)]
pub fn target(&mut self, target: impl AsRef<OsStr>) -> &mut Self {
self.arg("--target").arg(target);
self
}

pub fn package(&mut self, package: impl AsRef<OsStr>) -> &mut Self {
self.arg("--package").arg(package);
self
}
}
36 changes: 20 additions & 16 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ mod dir;
mod download;
mod dump;
mod git;
mod make;

use arch::Arch;
use cargo::Cargo;
use git::Git;
use make::Make;

const ALPINE_WEBSITE: &str = "https://dl-cdn.alpinelinux.org/alpine/v3.12/releases";
const ALPINE_ROOTFS_VERSION: &str = "3.12.0";
Expand Down Expand Up @@ -179,28 +181,30 @@ fn unset_git_proxy(global: bool) {

/// 风格检查。
fn check_style() {
println!("fmt -----------------------------------------");
println!("Check workspace");
Cargo::fmt().arg("--all").arg("--").arg("--check").invoke();
println!("clippy --------------------------------------");
Cargo::clippy().all_features().invoke();
println!("clippy x86_64 zircon smp=1 ------------------");
Cargo::doc().all_features().arg("--no-deps").invoke();
println!("Check libos");
Cargo::clippy()
.features(false, &["zircon"])
.target("x86_64.json")
.args(&["-Z", "build-std=core,alloc"])
.args(&["-Z", "build-std-features=compiler-builtins-mem"])
.current_dir("zCore")
.env("SMP", "1")
.package("zcore")
.features(false, &["zircon libos"])
.invoke();
println!("clippy riscv64 linux smp=4 ------------------");
Cargo::clippy()
.features(false, &["linux", "board-qemu"])
.target("riscv64.json")
.args(&["-Z", "build-std=core,alloc"])
.args(&["-Z", "build-std-features=compiler-builtins-mem"])
.package("zcore")
.features(false, &["linux libos"])
.invoke();
println!("Check bare-metal");
Make::new(None)
.arg("clippy")
.env("ARCH", "x86_64")
.current_dir("zCore")
.invoke();
Make::new(None)
.arg("clippy")
.env("ARCH", "riscv64")
.env("LINUX", "1")
.current_dir("zCore")
.env("SMP", "4")
.env("PLATFORM", "board-qemu")
.invoke();
}

Expand Down
34 changes: 34 additions & 0 deletions xtask/src/make.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::CommandExt;
use std::process::Command;

pub(crate) struct Make(Command);

impl AsRef<Command> for Make {
fn as_ref(&self) -> &Command {
&self.0
}
}

impl AsMut<Command> for Make {
fn as_mut(&mut self) -> &mut Command {
&mut self.0
}
}

impl CommandExt for Make {}

impl Make {
pub fn new(j: Option<usize>) -> Self {
let mut make = Self(Command::new("make"));
match j {
Some(0) => {}
Some(j) => {
make.arg(format!("-j{j}"));
}
None => {
make.arg("-j");
}
}
make
}
}

0 comments on commit 3d0186d

Please sign in to comment.