zellij/xtask/src/main.rs
Aram Drevekenin bc628abc12
feat(sessions): add a session manager to switch between sessions, tabs and panes and create new ones (#2721)
* write/read session metadata to disk for all sessions

* switch session client side

* fix tests

* various adjustments

* fix full screen focus bug in tiled panes

* fix tests

* fix permission sorting issue

* cleanups

* add session manager

* fix tests

* various cleanups

* style(fmt): rustfmt

* clear screen before switching sessions

* I hate you clippy

* truncate controls line to width

* version session cache

* attempt to fix plugin tests

* style(fmt): rustfmt

* another attempt to fix the tests in the ci
2023-08-24 13:36:24 +02:00

133 lines
5 KiB
Rust

//! See <https://github.com/matklad/cargo-xtask/>.
//!
//! This binary defines various auxiliary build commands, which are not expressible with just
//! `cargo`. Notably, it provides tests via `cargo test -p xtask` for code generation and `cargo
//! xtask install` for installation of rust-analyzer server and client.
//!
//! This binary is integrated into the `cargo` command line by using an alias in `.cargo/config`.
mod build;
mod ci;
mod clippy;
mod dist;
mod flags;
mod format;
mod pipelines;
mod test;
use anyhow::Context;
use std::{
env,
path::{Path, PathBuf},
time::Instant,
};
use xshell::Shell;
pub struct WorkspaceMember {
crate_name: &'static str,
build: bool,
}
lazy_static::lazy_static! {
pub static ref WORKSPACE_MEMBERS: Vec<WorkspaceMember> = vec![
WorkspaceMember{crate_name: "default-plugins/compact-bar", build: true},
WorkspaceMember{crate_name: "default-plugins/status-bar", build: true},
WorkspaceMember{crate_name: "default-plugins/strider", build: true},
WorkspaceMember{crate_name: "default-plugins/tab-bar", build: true},
WorkspaceMember{crate_name: "default-plugins/fixture-plugin-for-tests", build: true},
WorkspaceMember{crate_name: "default-plugins/session-manager", build: true},
WorkspaceMember{crate_name: "zellij-utils", build: false},
WorkspaceMember{crate_name: "zellij-tile-utils", build: false},
WorkspaceMember{crate_name: "zellij-tile", build: false},
WorkspaceMember{crate_name: "zellij-client", build: false},
WorkspaceMember{crate_name: "zellij-server", build: false},
WorkspaceMember{crate_name: ".", build: true},
];
}
fn main() -> anyhow::Result<()> {
let shell = &Shell::new()?;
let flags = flags::Xtask::from_env()?;
let now = Instant::now();
match flags.subcommand {
flags::XtaskCmd::Deprecated(_flags) => deprecation_notice(),
flags::XtaskCmd::Dist(flags) => pipelines::dist(shell, flags),
flags::XtaskCmd::Build(flags) => build::build(shell, flags),
flags::XtaskCmd::Clippy(flags) => clippy::clippy(shell, flags),
flags::XtaskCmd::Format(flags) => format::format(shell, flags),
flags::XtaskCmd::Test(flags) => test::test(shell, flags),
flags::XtaskCmd::Manpage(_flags) => build::manpage(shell),
// Pipelines
// These are composite commands, made up of multiple "stages" defined above.
flags::XtaskCmd::Make(flags) => pipelines::make(shell, flags),
flags::XtaskCmd::Install(flags) => pipelines::install(shell, flags),
flags::XtaskCmd::Run(flags) => pipelines::run(shell, flags),
flags::XtaskCmd::Ci(flags) => ci::main(shell, flags),
flags::XtaskCmd::Publish(flags) => pipelines::publish(shell, flags),
}?;
let elapsed = now.elapsed().as_secs();
status(&format!("xtask (done after {} s)", elapsed));
println!("\n\n>> Command took {} s", elapsed);
Ok(())
}
fn project_root() -> PathBuf {
Path::new(
&env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()),
)
.ancestors()
.nth(1)
.unwrap()
.to_path_buf()
}
fn asset_dir() -> PathBuf {
crate::project_root().join("zellij-utils").join("assets")
}
pub fn cargo() -> anyhow::Result<PathBuf> {
std::env::var_os("CARGO")
.map_or_else(|| which::which("cargo"), |exe| Ok(PathBuf::from(exe)))
.context("Couldn't find 'cargo' executable")
}
// Set terminal title to 'msg'
pub fn status(msg: &str) {
print!("\u{1b}]0;{}\u{07}", msg);
}
fn deprecation_notice() -> anyhow::Result<()> {
Err(anyhow::anyhow!(
" !!! cargo make has been deprecated by zellij !!!
Our build system is now `cargo xtask`. Don't worry, you won't have to install
anything!
- To get an overview of the new build tasks, run `cargo xtask --help`
- Quick compatibility table:
| cargo make task | cargo xtask equivalent |
| ------------------------------- | ----------------------------- |
| make | xtask |
| make format | xtask format |
| make build | xtask build |
| make test | xtask test |
| make run | xtask run |
| make run -l strider | xtask run -- -l strider |
| make clippy | xtask clippy |
| make clippy -W clippy::pedantic | N/A |
| make install /path/to/binary | xtask install /path/to/binary |
| make publish | xtask publish |
| make manpage | xtask manpage |
In order to disable xtask during the transitioning period: Delete/comment the
`[alias]` section in `.cargo/config.toml` and use `cargo make` as before.
If you're unhappy with `xtask` and decide to disable it, please tell us why so
we can discuss this before making it final for the next release. Thank you!
"
))
}