Refactored do to be a cargo alias.
This commit is contained in:
parent
2d7df342e6
commit
71676b6fe2
|
@ -0,0 +1,5 @@
|
||||||
|
[env]
|
||||||
|
DO_CMD = "cargo do"
|
||||||
|
|
||||||
|
[alias]
|
||||||
|
do = ["run", "--manifest-path", "tools/do-tasks/Cargo.toml", "--release", "--quiet", "--"]
|
|
@ -4,10 +4,6 @@
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"type": "lldb",
|
"type": "lldb",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
|
|
|
@ -1,25 +1,8 @@
|
||||||
{
|
{
|
||||||
"spellright.language": [
|
|
||||||
"en"
|
|
||||||
],
|
|
||||||
"spellright.documentTypes": [
|
|
||||||
"markdown",
|
|
||||||
"latex",
|
|
||||||
"plaintext",
|
|
||||||
"rust",
|
|
||||||
"toml",
|
|
||||||
"json"
|
|
||||||
],
|
|
||||||
"rust-analyzer.files.excludeDirs": [
|
"rust-analyzer.files.excludeDirs": [
|
||||||
"tests/build",
|
"tests/build",
|
||||||
],
|
],
|
||||||
"errorLens.exclude": [
|
"rust-analyzer.runnables.overrideCargo": "cargo do rust_analyzer_run",
|
||||||
"file not included in module tree",
|
"rust-analyzer.checkOnSave.overrideCommand": ["cargo", "do", "rust_analyzer_check"],
|
||||||
"code is inactive due to #\\[cfg\\] directives: debug_assertions is enabled"
|
|
||||||
],
|
|
||||||
"rust-analyzer.linkedProjects.disabled": [
|
|
||||||
"Cargo.toml",
|
|
||||||
"tools/do-tasks/Cargo.toml"
|
|
||||||
],
|
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
}
|
}
|
|
@ -2,13 +2,84 @@
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"type": "cargo",
|
"label": "do build",
|
||||||
"command": "fmt",
|
"type": "shell",
|
||||||
|
"command": "cargo do build",
|
||||||
|
"group": "build",
|
||||||
"problemMatcher": [
|
"problemMatcher": [
|
||||||
"$rustc"
|
"$rustc"
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "do build --examples",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo do build --examples",
|
||||||
"group": "build",
|
"group": "build",
|
||||||
"label": "rust: cargo fmt"
|
"problemMatcher": [
|
||||||
|
"$rustc"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "do check",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo do check",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$rustc"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "do prebuild",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo do prebuild",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$rustc"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "do test",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo do test ${input:testGroupID}",
|
||||||
|
"group": "test",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$rustc"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "do run",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo do run ${input:exampleNameID}",
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$rustc"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "do fmt",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo do fmt",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$rustc"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"id": "exampleNameID",
|
||||||
|
"description": "example name",
|
||||||
|
"type": "promptString",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "testGroupID",
|
||||||
|
"description": "test group",
|
||||||
|
"type": "pickString",
|
||||||
|
"options": [
|
||||||
|
"--workspace",
|
||||||
|
"--doc",
|
||||||
|
"--test-crates",
|
||||||
|
"--build *"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
18
README.md
18
README.md
|
@ -81,11 +81,23 @@ You also need the nightly toolchain for building the documentation (`do doc`), a
|
||||||
build the documentation in stable using `cargo doc`, but custom pages like widget items may not
|
build the documentation in stable using `cargo doc`, but custom pages like widget items may not
|
||||||
render properly because of changes in the `cargo-doc` HTML templates.
|
render properly because of changes in the `cargo-doc` HTML templates.
|
||||||
|
|
||||||
## `do`
|
## `cargo do`
|
||||||
|
|
||||||
There is a built-in task runner for managing this project, run `do help` or `./do help` for details.
|
There is a built-in task runner for managing this project, run `cargo do help` or `./do help` for details.
|
||||||
|
|
||||||
The task runner is implemented as a Rust crate in `tools/do-tasks`, the shell script builds it in the first run.
|
The task runner is implemented as a Rust crate in `tools/do-tasks` and an alias in `.cargo/config.toml`,
|
||||||
|
it builds the tool silently in the first run, after it should run without noticeable delay.
|
||||||
|
|
||||||
|
Shell script to run `do` are also provided:
|
||||||
|
|
||||||
|
* cmd.exe: `do help`.
|
||||||
|
* PowerShell: `./do.ps1 help`.
|
||||||
|
* Bash: `/.do help`.
|
||||||
|
|
||||||
|
## VSCode & Rust Analyzer
|
||||||
|
|
||||||
|
Some workspace settings are included in the repository, in particular, `rust-analyzer` "checkOnSave"
|
||||||
|
and runnables are redirected to the `do` tool.
|
||||||
|
|
||||||
[`API docs`]: https://docs.rs/zero-ui
|
[`API docs`]: https://docs.rs/zero-ui
|
||||||
[`cargo-expand`]: https://github.com/dtolnay/cargo-expand
|
[`cargo-expand`]: https://github.com/dtolnay/cargo-expand
|
||||||
|
|
5
do
5
do
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export DO_NAME="do"
|
export DO_CMD=".\do"
|
||||||
export DO_MANIFEST_PATH="tools/do-tasks/Cargo.toml"
|
cargo do $*
|
||||||
cargo run --manifest-path $DO_MANIFEST_PATH --release --quiet -- $*
|
|
5
do.bat
5
do.bat
|
@ -19,6 +19,5 @@ goto next
|
||||||
:done
|
:done
|
||||||
|
|
||||||
:: Run Task
|
:: Run Task
|
||||||
set DO_NAME=do
|
set DO_CMD=do
|
||||||
set DO_MANIFEST_PATH=tools/do-tasks/Cargo.toml
|
cargo do %ARGS%
|
||||||
cargo run --manifest-path %DO_MANIFEST_PATH% --release --quiet -- %ARGS%
|
|
5
do.ps1
5
do.ps1
|
@ -1,3 +1,2 @@
|
||||||
$env:DO_NAME = "do"
|
$env:DO_CMD = ".\do.ps1"
|
||||||
$env:DO_MANIFEST_PATH = "tools/do-tasks/Cargo.toml"
|
cargo do $args
|
||||||
cargo run --manifest-path $env:DO_MANIFEST_PATH --release --quiet -- $args
|
|
|
@ -60,7 +60,9 @@ pub fn record_profile(path: impl AsRef<Path>, about: &[(&str, &str)]) -> Recordi
|
||||||
|
|
||||||
let (sender, recv) = flume::unbounded();
|
let (sender, recv) = flume::unbounded();
|
||||||
|
|
||||||
let worker = thread::Builder::new().name("profiler".to_owned()).spawn(move || {
|
let worker = thread::Builder::new()
|
||||||
|
.name("profiler".to_owned())
|
||||||
|
.spawn(move || {
|
||||||
let mut spans = FxHashMap::<span::Id, Span>::default();
|
let mut spans = FxHashMap::<span::Id, Span>::default();
|
||||||
|
|
||||||
struct Span {
|
struct Span {
|
||||||
|
@ -186,7 +188,8 @@ pub fn record_profile(path: impl AsRef<Path>, about: &[(&str, &str)]) -> Recordi
|
||||||
write!(&mut file, "]}}").unwrap();
|
write!(&mut file, "]}}").unwrap();
|
||||||
|
|
||||||
file.flush().unwrap();
|
file.flush().unwrap();
|
||||||
}).unwrap();
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
tracing::dispatcher::set_global_default(tracing::Dispatch::new(Profiler::new(sender.clone()))).unwrap();
|
tracing::dispatcher::set_global_default(tracing::Dispatch::new(Profiler::new(sender.clone()))).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,15 @@ fn main() {
|
||||||
"run" | "r" => run(args),
|
"run" | "r" => run(args),
|
||||||
"doc" => doc(args),
|
"doc" => doc(args),
|
||||||
"expand" => expand(args),
|
"expand" => expand(args),
|
||||||
|
"check" | "c" => check(args),
|
||||||
"build" | "b" => build(args),
|
"build" | "b" => build(args),
|
||||||
"prebuild" => prebuild(args),
|
"prebuild" => prebuild(args),
|
||||||
"clean" => clean(args),
|
"clean" => clean(args),
|
||||||
"asm" => asm(args),
|
"asm" => asm(args),
|
||||||
|
"rust_analyzer_run" => rust_analyzer_run(args),
|
||||||
|
"rust_analyzer_check" => rust_analyzer_check(args),
|
||||||
"help" | "--help" => help(args),
|
"help" | "--help" => help(args),
|
||||||
_ => fatal(f!("unknown task {:?}, `{} help` to list tasks", task, DO)),
|
_ => fatal(f!("unknown task {:?}, `{} help` to list tasks", task, do_cmd())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +321,12 @@ fn fmt(args: Vec<&str>) {
|
||||||
println("done");
|
println("done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do check, c
|
||||||
|
// Runs clippy on the workspace.
|
||||||
|
fn check(args: Vec<&str>) {
|
||||||
|
cmd("cargo", &["clippy", "--no-deps", "--workspace"], &args);
|
||||||
|
}
|
||||||
|
|
||||||
// do build, b [-e, --example] [--all] [-t, --timing] [<cargo-build-args>]
|
// do build, b [-e, --example] [--all] [-t, --timing] [<cargo-build-args>]
|
||||||
// Compile the main crate and its dependencies.
|
// Compile the main crate and its dependencies.
|
||||||
// USAGE:
|
// USAGE:
|
||||||
|
@ -435,8 +444,10 @@ fn clean(mut args: Vec<&str>) {
|
||||||
}
|
}
|
||||||
cmd("cargo", &["clean", "--manifest-path", &tool_], &args);
|
cmd("cargo", &["clean", "--manifest-path", &tool_], &args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// external because it will delete self.
|
// external because it will delete self.
|
||||||
cmd_external("cargo", &["clean", "--manifest-path", env!("DO_MANIFEST_PATH")], &args);
|
let manifest_path = format!("{}/Cargo.toml", file!().strip_prefix("/src/main.rs").unwrap());
|
||||||
|
cmd_external("cargo", &["clean", "--manifest-path", &manifest_path], &args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,6 +501,18 @@ fn asm(mut args: Vec<&str>) {
|
||||||
cmd("cargo", &asm_args, &args);
|
cmd("cargo", &asm_args, &args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rust_analyzer_run(args: Vec<&str>) {
|
||||||
|
if let Some(&"check") = args.first() {
|
||||||
|
cmd("cargo", &["clippy", "--no-deps"], &args[1..]);
|
||||||
|
} else {
|
||||||
|
cmd("cargo", &args, &[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rust_analyzer_check(args: Vec<&str>) {
|
||||||
|
cmd("cargo", &["clippy", "--no-deps", "--workspace", "--message-format=json"], &args)
|
||||||
|
}
|
||||||
|
|
||||||
// do help, --help [task]
|
// do help, --help [task]
|
||||||
// Prints help for all tasks.
|
// Prints help for all tasks.
|
||||||
// USAGE:
|
// USAGE:
|
||||||
|
@ -499,7 +522,7 @@ fn help(mut args: Vec<&str>) {
|
||||||
println(f!(
|
println(f!(
|
||||||
"\n{}{}{} ({} {})",
|
"\n{}{}{} ({} {})",
|
||||||
c_wb(),
|
c_wb(),
|
||||||
DO,
|
do_cmd(),
|
||||||
c_w(),
|
c_w(),
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
|
@ -510,7 +533,7 @@ fn help(mut args: Vec<&str>) {
|
||||||
if !specific_task {
|
if !specific_task {
|
||||||
println(f!(" {}", env!("CARGO_PKG_DESCRIPTION")));
|
println(f!(" {}", env!("CARGO_PKG_DESCRIPTION")));
|
||||||
println("\nUSAGE:");
|
println("\nUSAGE:");
|
||||||
println(f!(" {} TASK [<TASK-ARGS>]", DO));
|
println(f!(" {} TASK [<TASK-ARGS>]", do_cmd()));
|
||||||
println("\nFLAGS:");
|
println("\nFLAGS:");
|
||||||
println(r#" --dump Redirect output to "dump.log" or other file specified by task."#);
|
println(r#" --dump Redirect output to "dump.log" or other file specified by task."#);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ use std::format_args as f;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::process::{self, Command, Stdio};
|
use std::process::{self, Command, Stdio};
|
||||||
|
|
||||||
// shell script that builds and runs do-tasks.
|
// Command line to run `do`
|
||||||
pub static DO: &str = env!("DO_NAME");
|
pub fn do_cmd() -> String {
|
||||||
|
env::var("DO_CMD").ok().unwrap_or_else(|| "cargo do".to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
// Run a command, args are chained, empty ("") arg strings are filtered, command streams are inherited.
|
// Run a command, args are chained, empty ("") arg strings are filtered, command streams are inherited.
|
||||||
pub fn cmd(cmd: &str, default_args: &[&str], user_args: &[&str]) {
|
pub fn cmd(cmd: &str, default_args: &[&str], user_args: &[&str]) {
|
||||||
|
@ -157,7 +159,7 @@ pub fn args() -> (&'static str, Vec<&'static str>) {
|
||||||
info.dump = take_flag(&mut args, &["--dump"]);
|
info.dump = take_flag(&mut args, &["--dump"]);
|
||||||
|
|
||||||
// prints header
|
// prints header
|
||||||
println(f!("{}Running{}: {}{} {:?} {:?}", c_green(), c_wb(), DO, c_w(), task, args));
|
println(f!("{}Running{}: {}{} {:?} {:?}", c_green(), c_wb(), do_cmd(), c_w(), task, args));
|
||||||
|
|
||||||
(task, args)
|
(task, args)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue