mirror of
https://github.com/zellij-org/zellij.git
synced 2026-10-11 22:50:07 +00:00
fix(build): remove manpage, honor CARGO_TARGET_DIR, add cargo argument passthrough, remove clippy (#5426)
* fix(build): remove manpage, honor CARGO_TARGET_DIR, add cargo argument passthrough, remove clippy * add pr
This commit is contained in:
+7
-47
@@ -3,7 +3,6 @@
|
||||
//! Currently has the following functions:
|
||||
//!
|
||||
//! - [`build`]: Builds general cargo projects (i.e. zellij components) with `cargo build`
|
||||
//! - [`manpage`]: Builds the manpage with `mandown`
|
||||
use crate::{flags, metadata, WorkspaceMember};
|
||||
use anyhow::Context;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -99,6 +98,7 @@ pub fn build(sh: &Shell, flags: flags::Build) -> anyhow::Result<()> {
|
||||
},
|
||||
}
|
||||
}
|
||||
base_cmd = base_cmd.args(&flags.args);
|
||||
base_cmd.run().with_context(err_context)?;
|
||||
}
|
||||
}
|
||||
@@ -218,11 +218,7 @@ fn plugin_name_of(member: &WorkspaceMember) -> anyhow::Result<&'static str> {
|
||||
}
|
||||
|
||||
fn plugin_stamp_path() -> PathBuf {
|
||||
PathBuf::from(
|
||||
std::env::var_os("CARGO_TARGET_DIR")
|
||||
.unwrap_or(crate::project_root().join("target").into_os_string()),
|
||||
)
|
||||
.join(".xtask-plugins-stamp")
|
||||
crate::target_dir().join(".xtask-plugins-stamp")
|
||||
}
|
||||
|
||||
fn write_plugin_stamp(sh: &Shell) {
|
||||
@@ -322,14 +318,11 @@ fn move_plugin_to_assets(sh: &Shell, plugin_name: &str) -> anyhow::Result<()> {
|
||||
.with_extension("wasm");
|
||||
|
||||
// Get plugin path
|
||||
let plugin = PathBuf::from(
|
||||
std::env::var_os("CARGO_TARGET_DIR")
|
||||
.unwrap_or(crate::project_root().join("target").into_os_string()),
|
||||
)
|
||||
.join("wasm32-wasip1")
|
||||
.join("release")
|
||||
.join(plugin_name)
|
||||
.with_extension("wasm");
|
||||
let plugin = crate::target_dir()
|
||||
.join("wasm32-wasip1")
|
||||
.join("release")
|
||||
.join(plugin_name)
|
||||
.with_extension("wasm");
|
||||
|
||||
if !plugin.is_file() {
|
||||
return Err(anyhow::anyhow!("No plugin found at '{}'", plugin.display()))
|
||||
@@ -341,36 +334,3 @@ fn move_plugin_to_assets(sh: &Shell, plugin_name: &str) -> anyhow::Result<()> {
|
||||
let to = asset_name.as_path();
|
||||
sh.copy_file(from, to).with_context(err_context)
|
||||
}
|
||||
|
||||
/// Build the manpage with `mandown`.
|
||||
// mkdir -p ${root_dir}/assets/man
|
||||
// mandown ${root_dir}/docs/MANPAGE.md 1 > ${root_dir}/assets/man/zellij.1
|
||||
pub fn manpage(sh: &Shell) -> anyhow::Result<()> {
|
||||
let err_context = "failed to generate manpage";
|
||||
|
||||
let mandown = mandown(sh).context(err_context)?;
|
||||
|
||||
let project_root = crate::project_root();
|
||||
let asset_dir = &project_root.join("assets").join("man");
|
||||
sh.create_dir(asset_dir).context(err_context)?;
|
||||
let _pd = sh.push_dir(asset_dir);
|
||||
|
||||
cmd!(sh, "{mandown} {project_root}/docs/MANPAGE.md 1")
|
||||
.read()
|
||||
.and_then(|text| sh.write_file("zellij.1", text))
|
||||
.context(err_context)
|
||||
}
|
||||
|
||||
/// Get the path to a `mandown` executable.
|
||||
///
|
||||
/// If the executable isn't found, an error is returned instead.
|
||||
fn mandown(_sh: &Shell) -> anyhow::Result<PathBuf> {
|
||||
match which::which("mandown") {
|
||||
Ok(path) => Ok(path),
|
||||
Err(e) => {
|
||||
eprintln!("!! 'mandown' wasn't found but is needed for this build step.");
|
||||
eprintln!("!! Please install it with: `cargo install mandown`");
|
||||
Err(e).context("Couldn't find 'mandown' executable")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -55,6 +55,7 @@ fn e2e_build(sh: &Shell) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web: false,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.context(err_context)?;
|
||||
@@ -62,7 +63,7 @@ fn e2e_build(sh: &Shell) -> anyhow::Result<()> {
|
||||
// Copy plugins to e2e data-dir
|
||||
let plugin_dir = crate::asset_dir().join("plugins");
|
||||
let project_root = crate::project_root();
|
||||
let data_dir = project_root.join("target").join("e2e-data");
|
||||
let data_dir = crate::target_dir().join("e2e-data");
|
||||
let plugins: Vec<_> = std::fs::read_dir(plugin_dir)
|
||||
.context(err_context)?
|
||||
.filter_map(|dir_entry| {
|
||||
@@ -153,6 +154,7 @@ fn build_release(sh: &Shell, no_web: bool) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.context(err_context)?;
|
||||
@@ -227,10 +229,6 @@ fn cross_compile(sh: &Shell, target: &OsString, no_web: bool) -> anyhow::Result<
|
||||
let err_context = || format!("failed to cross-compile for {target:?}");
|
||||
|
||||
crate::cargo()
|
||||
.and_then(|cargo| {
|
||||
cmd!(sh, "{cargo} install mandown").run()?;
|
||||
Ok(cargo)
|
||||
})
|
||||
.and_then(|cargo| {
|
||||
cmd!(sh, "{cargo} install cross")
|
||||
.run()
|
||||
@@ -245,9 +243,9 @@ fn cross_compile(sh: &Shell, target: &OsString, no_web: bool) -> anyhow::Result<
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.and_then(|_| build::manpage(sh))
|
||||
.with_context(err_context)?;
|
||||
|
||||
cross()
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
//! Handle running `cargo clippy` on the sources.
|
||||
use crate::{build, flags, WorkspaceMember};
|
||||
use anyhow::Context;
|
||||
use std::path::{Path, PathBuf};
|
||||
use xshell::{cmd, Shell};
|
||||
|
||||
pub fn clippy(sh: &Shell, _flags: flags::Clippy) -> anyhow::Result<()> {
|
||||
let _pd = sh.push_dir(crate::project_root());
|
||||
|
||||
build::build(
|
||||
sh,
|
||||
flags::Build {
|
||||
release: false,
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web: false,
|
||||
},
|
||||
)
|
||||
.context("failed to run task 'clippy'")?;
|
||||
|
||||
let cargo = check_clippy()
|
||||
.and_then(|_| crate::cargo())
|
||||
.context("failed to run task 'clippy'")?;
|
||||
|
||||
for WorkspaceMember { crate_name, .. } in crate::workspace_members().iter() {
|
||||
let _pd = sh.push_dir(Path::new(crate_name));
|
||||
// Tell the user where we are now
|
||||
println!();
|
||||
let msg = format!(">> Running clippy on '{crate_name}'");
|
||||
crate::status(&msg);
|
||||
println!("{}", msg);
|
||||
|
||||
cmd!(sh, "{cargo} clippy --all-targets --all-features")
|
||||
.run()
|
||||
.with_context(|| format!("failed to run task 'clippy' on '{crate_name}'"))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_clippy() -> anyhow::Result<PathBuf> {
|
||||
which::which("cargo-clippy").context(
|
||||
"Couldn't find 'clippy' executable. Please install it with `rustup component add clippy`",
|
||||
)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
+12
-22
@@ -39,9 +39,6 @@ xflags::xflags! {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the manpage
|
||||
cmd manpage {}
|
||||
|
||||
cmd proto {}
|
||||
|
||||
/// Publish zellij and all the sub-crates
|
||||
@@ -56,13 +53,7 @@ xflags::xflags! {
|
||||
optional --cargo-registry registry: OsString
|
||||
}
|
||||
|
||||
/// Package zellij for distribution (result found in ./target/dist)
|
||||
cmd dist {}
|
||||
|
||||
/// Run `cargo clippy` on all crates
|
||||
cmd clippy {}
|
||||
|
||||
/// Sequentially call: format, build, test, clippy
|
||||
/// Sequentially call: format, build, test
|
||||
cmd make {
|
||||
/// Build in release mode without debug symbols
|
||||
optional -r, --release
|
||||
@@ -77,6 +68,10 @@ xflags::xflags! {
|
||||
required destination: PathBuf
|
||||
/// Compile without web server support
|
||||
optional --no-web
|
||||
/// Extra arguments appended to the native `cargo build` invocation
|
||||
/// (e.g. `--no-default-features`, `--features ...`, `--offline`, `--locked`, `-j N`).
|
||||
/// Not applied to the wasm plugin build.
|
||||
repeated args: OsString
|
||||
}
|
||||
|
||||
/// Run debug version of zellij
|
||||
@@ -128,6 +123,10 @@ xflags::xflags! {
|
||||
optional --no-plugins
|
||||
/// Compile without web support
|
||||
optional --no-web
|
||||
/// Extra arguments appended to the native `cargo build` invocation
|
||||
/// (e.g. `--no-default-features`, `--features ...`, `--offline`, `--locked`, `-j N`).
|
||||
/// Not applied to the wasm plugin build.
|
||||
repeated args: OsString
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,11 +142,8 @@ pub struct Xtask {
|
||||
pub enum XtaskCmd {
|
||||
Deprecated(Deprecated),
|
||||
Ci(Ci),
|
||||
Manpage(Manpage),
|
||||
Proto(Proto),
|
||||
Publish(Publish),
|
||||
Dist(Dist),
|
||||
Clippy(Clippy),
|
||||
Make(Make),
|
||||
Install(Install),
|
||||
Run(Run),
|
||||
@@ -194,9 +190,6 @@ pub struct BuildRelease {
|
||||
pub no_web: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Manpage;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Proto;
|
||||
|
||||
@@ -208,12 +201,6 @@ pub struct Publish {
|
||||
pub cargo_registry: Option<OsString>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Dist;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Clippy;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Make {
|
||||
pub release: bool,
|
||||
@@ -224,6 +211,7 @@ pub struct Make {
|
||||
#[derive(Debug)]
|
||||
pub struct Install {
|
||||
pub destination: PathBuf,
|
||||
pub args: Vec<OsString>,
|
||||
|
||||
pub no_web: bool,
|
||||
}
|
||||
@@ -260,6 +248,8 @@ pub struct IntegrationTest {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Build {
|
||||
pub args: Vec<OsString>,
|
||||
|
||||
pub release: bool,
|
||||
pub plugins_only: bool,
|
||||
pub no_plugins: bool,
|
||||
|
||||
+7
-8
@@ -8,8 +8,6 @@
|
||||
|
||||
mod build;
|
||||
mod ci;
|
||||
mod clippy;
|
||||
mod dist;
|
||||
mod flags;
|
||||
mod format;
|
||||
mod integration_test;
|
||||
@@ -127,13 +125,10 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
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::IntegrationTest(flags) => integration_test::integration_test(shell, flags),
|
||||
flags::XtaskCmd::Manpage(_flags) => build::manpage(shell),
|
||||
flags::XtaskCmd::Proto(_flags) => build::proto(shell),
|
||||
// Pipelines
|
||||
// These are composite commands, made up of multiple "stages" defined above.
|
||||
@@ -164,6 +159,13 @@ fn asset_dir() -> PathBuf {
|
||||
crate::project_root().join("zellij-utils").join("assets")
|
||||
}
|
||||
|
||||
pub fn target_dir() -> PathBuf {
|
||||
match env::var_os("CARGO_TARGET_DIR") {
|
||||
Some(dir) => PathBuf::from(dir),
|
||||
None => crate::project_root().join("target"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cargo() -> anyhow::Result<PathBuf> {
|
||||
std::env::var_os("CARGO")
|
||||
.map_or_else(|| which::which("cargo"), |exe| Ok(PathBuf::from(exe)))
|
||||
@@ -193,11 +195,8 @@ anything!
|
||||
| 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
|
||||
|
||||
+11
-41
@@ -1,7 +1,7 @@
|
||||
//! Composite pipelines for the build system.
|
||||
//!
|
||||
//! Defines multiple "pipelines" that run specific individual steps in sequence.
|
||||
use crate::{build, clippy, format, metadata, test};
|
||||
use crate::{build, format, metadata, test};
|
||||
use crate::{flags, WorkspaceMember};
|
||||
use anyhow::Context;
|
||||
use xshell::{cmd, Shell};
|
||||
@@ -13,7 +13,6 @@ use xshell::{cmd, Shell};
|
||||
/// - format
|
||||
/// - build
|
||||
/// - test
|
||||
/// - clippy
|
||||
pub fn make(sh: &Shell, flags: flags::Make) -> anyhow::Result<()> {
|
||||
let err_context = || format!("failed to run pipeline 'make' with args {flags:?}");
|
||||
|
||||
@@ -32,6 +31,7 @@ pub fn make(sh: &Shell, flags: flags::Make) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: false,
|
||||
no_web: flags.no_web,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
})
|
||||
@@ -44,7 +44,6 @@ pub fn make(sh: &Shell, flags: flags::Make) -> anyhow::Result<()> {
|
||||
},
|
||||
)
|
||||
})
|
||||
.and_then(|_| clippy::clippy(sh, flags::Clippy {}))
|
||||
.with_context(err_context)
|
||||
}
|
||||
|
||||
@@ -54,7 +53,6 @@ pub fn make(sh: &Shell, flags: flags::Make) -> anyhow::Result<()> {
|
||||
///
|
||||
/// - [`build`](build::build) (release, plugins only)
|
||||
/// - [`build`](build::build) (release, without plugins)
|
||||
/// - [`manpage`](build::manpage)
|
||||
/// - Copy the executable to [target file](flags::Install::destination)
|
||||
pub fn install(sh: &Shell, flags: flags::Install) -> anyhow::Result<()> {
|
||||
let err_context = || format!("failed to run pipeline 'install' with args {flags:?}");
|
||||
@@ -67,6 +65,7 @@ pub fn install(sh: &Shell, flags: flags::Install) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web: flags.no_web,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.and_then(|_| {
|
||||
@@ -78,13 +77,10 @@ pub fn install(sh: &Shell, flags: flags::Install) -> anyhow::Result<()> {
|
||||
no_plugins: true,
|
||||
plugins_only: false,
|
||||
no_web: flags.no_web,
|
||||
args: flags.args.clone(),
|
||||
},
|
||||
)
|
||||
})
|
||||
.and_then(|_| {
|
||||
// Generate man page
|
||||
build::manpage(sh)
|
||||
})
|
||||
.with_context(err_context)?;
|
||||
|
||||
// Copy binary to destination
|
||||
@@ -96,8 +92,11 @@ pub fn install(sh: &Shell, flags: flags::Install) -> anyhow::Result<()> {
|
||||
.join(&flags.destination)
|
||||
};
|
||||
sh.change_dir(crate::project_root());
|
||||
sh.copy_file("target/release/zellij", &destination)
|
||||
.with_context(err_context)
|
||||
sh.copy_file(
|
||||
crate::target_dir().join("release").join("zellij"),
|
||||
&destination,
|
||||
)
|
||||
.with_context(err_context)
|
||||
}
|
||||
|
||||
/// Run zellij debug build.
|
||||
@@ -148,6 +147,7 @@ pub fn run(sh: &Shell, mut flags: flags::Run) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web: flags.no_web,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.and_then(|_| crate::cargo())
|
||||
@@ -193,37 +193,6 @@ pub fn run(sh: &Shell, mut flags: flags::Run) -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Bundle all distributable content to `target/dist`.
|
||||
///
|
||||
/// This includes the optimized zellij executable from the [`install`] pipeline, the man page, the
|
||||
/// `.desktop` file and the application logo.
|
||||
pub fn dist(sh: &Shell, _flags: flags::Dist) -> anyhow::Result<()> {
|
||||
let err_context = || "failed to run pipeline 'dist'";
|
||||
|
||||
sh.change_dir(crate::project_root());
|
||||
if sh.path_exists("target/dist") {
|
||||
sh.remove_path("target/dist").with_context(err_context)?;
|
||||
}
|
||||
sh.create_dir("target/dist")
|
||||
.map_err(anyhow::Error::new)
|
||||
.and_then(|_| {
|
||||
install(
|
||||
sh,
|
||||
flags::Install {
|
||||
destination: crate::project_root().join("./target/dist/zellij"),
|
||||
no_web: false,
|
||||
},
|
||||
)
|
||||
})
|
||||
.with_context(err_context)?;
|
||||
|
||||
sh.create_dir("target/dist/man")
|
||||
.and_then(|_| sh.copy_file("assets/man/zellij.1", "target/dist/man/zellij.1"))
|
||||
.and_then(|_| sh.copy_file("assets/zellij.desktop", "target/dist/zellij.desktop"))
|
||||
.and_then(|_| sh.copy_file("assets/logo.png", "target/dist/logo.png"))
|
||||
.with_context(err_context)
|
||||
}
|
||||
|
||||
/// Actions for the user to choose from to resolve publishing errors/conflicts.
|
||||
enum UserAction {
|
||||
Retry,
|
||||
@@ -323,6 +292,7 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web: false,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.context(err_context)?;
|
||||
|
||||
@@ -17,6 +17,7 @@ pub fn test(sh: &Shell, flags: flags::Test) -> anyhow::Result<()> {
|
||||
no_plugins: false,
|
||||
plugins_only: true,
|
||||
no_web: flags.no_web,
|
||||
args: vec![],
|
||||
},
|
||||
)
|
||||
.context(err_context)?;
|
||||
|
||||
Reference in New Issue
Block a user