Skip to content

Commit

Permalink
chore(xtask): Upgrade xshell
Browse files Browse the repository at this point in the history
Gets rid of an unexpected_cfgs warning.

Signed-off-by: Kévin Commaille <[email protected]>
  • Loading branch information
zecakeh committed Nov 29, 2024
1 parent 1072d0a commit 09aac52
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 60 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
fs_extra = "1"
uniffi_bindgen = { workspace = true }
xshell = "0.1.17"
xshell = "0.2.7"

[package.metadata.release]
release = false
59 changes: 39 additions & 20 deletions xtask/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::{
};

use clap::{Args, Subcommand};
use xshell::{cmd, pushd};
use xshell::cmd;

use crate::{build_docs, workspace, DenyWarnings, Result, NIGHTLY};
use crate::{build_docs, sh, workspace, DenyWarnings, Result, NIGHTLY};

const WASM_TIMEOUT_ENV_KEY: &str = "WASM_BINDGEN_TEST_TIMEOUT";
const WASM_TIMEOUT_VALUE: &str = "120";
Expand Down Expand Up @@ -100,7 +100,8 @@ enum WasmFeatureSet {

impl CiArgs {
pub fn run(self) -> Result<()> {
let _p = pushd(workspace::root_path()?)?;
let sh = sh();
let _p = sh.push_dir(workspace::root_path()?);

match self.cmd {
Some(cmd) => match cmd {
Expand Down Expand Up @@ -132,8 +133,10 @@ impl CiArgs {
}

fn check_bindings() -> Result<()> {
cmd!("rustup run stable cargo build -p matrix-sdk-crypto-ffi -p matrix-sdk-ffi").run()?;
let sh = sh();
cmd!(sh, "rustup run stable cargo build -p matrix-sdk-crypto-ffi -p matrix-sdk-ffi").run()?;
cmd!(
sh,
"
rustup run stable cargo run -p uniffi-bindgen -- generate
--library
Expand All @@ -145,6 +148,7 @@ fn check_bindings() -> Result<()> {
)
.run()?;
cmd!(
sh,
"
rustup run stable cargo run -p uniffi-bindgen -- generate
--library
Expand All @@ -160,27 +164,32 @@ fn check_bindings() -> Result<()> {
}

fn check_examples() -> Result<()> {
cmd!("rustup run stable cargo check -p example-*").run()?;
let sh = sh();
cmd!(sh, "rustup run stable cargo check -p example-*").run()?;
Ok(())
}

fn check_style() -> Result<()> {
cmd!("rustup run {NIGHTLY} cargo fmt -- --check").run()?;
let sh = sh();
cmd!(sh, "rustup run {NIGHTLY} cargo fmt -- --check").run()?;
Ok(())
}

fn check_typos() -> Result<()> {
let sh = sh();
// FIXME: Print install instructions if command-not-found (needs an xshell
// change: https://github.com/matklad/xshell/issues/46)
cmd!("typos").run()?;
cmd!(sh, "typos").run()?;
Ok(())
}

fn check_clippy() -> Result<()> {
cmd!("rustup run {NIGHTLY} cargo clippy --all-targets --features testing -- -D warnings")
let sh = sh();
cmd!(sh, "rustup run {NIGHTLY} cargo clippy --all-targets --features testing -- -D warnings")
.run()?;

cmd!(
sh,
"rustup run {NIGHTLY} cargo clippy --workspace --all-targets
--exclude matrix-sdk-crypto --exclude xtask
--no-default-features
Expand All @@ -190,6 +199,7 @@ fn check_clippy() -> Result<()> {
.run()?;

cmd!(
sh,
"rustup run {NIGHTLY} cargo clippy --all-targets -p matrix-sdk-crypto
--no-default-features -- -D warnings"
)
Expand Down Expand Up @@ -223,11 +233,12 @@ fn run_feature_tests(cmd: Option<FeatureSet>) -> Result<()> {
(FeatureSet::SsoLogin, "--features sso-login,testing"),
]);

let sh = sh();
let run = |arg_set: &str| {
cmd!("rustup run stable cargo nextest run -p matrix-sdk")
cmd!(sh, "rustup run stable cargo nextest run -p matrix-sdk")
.args(arg_set.split_whitespace())
.run()?;
cmd!("rustup run stable cargo test --doc -p matrix-sdk")
cmd!(sh, "rustup run stable cargo test --doc -p matrix-sdk")
.args(arg_set.split_whitespace())
.run()
};
Expand All @@ -247,25 +258,31 @@ fn run_feature_tests(cmd: Option<FeatureSet>) -> Result<()> {
}

fn run_crypto_tests() -> Result<()> {
cmd!("rustup run stable cargo clippy -p matrix-sdk-crypto -- -D warnings").run()?;
cmd!("rustup run stable cargo nextest run -p matrix-sdk-crypto --no-default-features --features testing").run()?;
cmd!("rustup run stable cargo nextest run -p matrix-sdk-crypto --features=testing").run()?;
cmd!("rustup run stable cargo test --doc -p matrix-sdk-crypto --features=testing").run()?;
let sh = sh();
cmd!(sh, "rustup run stable cargo clippy -p matrix-sdk-crypto -- -D warnings").run()?;
cmd!(sh, "rustup run stable cargo nextest run -p matrix-sdk-crypto --no-default-features --features testing").run()?;
cmd!(sh, "rustup run stable cargo nextest run -p matrix-sdk-crypto --features=testing")
.run()?;
cmd!(sh, "rustup run stable cargo test --doc -p matrix-sdk-crypto --features=testing").run()?;
cmd!(
sh,
"rustup run stable cargo clippy -p matrix-sdk-crypto --features=experimental-algorithms -- -D warnings"
)
.run()?;
cmd!(
sh,
"rustup run stable cargo nextest run -p matrix-sdk-crypto --features=experimental-algorithms,testing"
).run()?;
cmd!(
sh,
"rustup run stable cargo test --doc -p matrix-sdk-crypto --features=experimental-algorithms,testing"
)
.run()?;

cmd!("rustup run stable cargo nextest run -p matrix-sdk-crypto-ffi").run()?;
cmd!(sh, "rustup run stable cargo nextest run -p matrix-sdk-crypto-ffi").run()?;

cmd!(
sh,
"rustup run stable cargo nextest run -p matrix-sdk-sqlite --features crypto-store,testing"
)
.run()?;
Expand Down Expand Up @@ -308,8 +325,9 @@ fn run_wasm_checks(cmd: Option<WasmFeatureSet>) -> Result<()> {
),
]);

let sh = sh();
let run = |arg_set: &str| {
cmd!("rustup run stable cargo clippy --target wasm32-unknown-unknown")
cmd!(sh, "rustup run stable cargo clippy --target wasm32-unknown-unknown")
.args(arg_set.split_whitespace())
.args(["--", "-D", "warnings"])
.env(WASM_TIMEOUT_ENV_KEY, WASM_TIMEOUT_VALUE)
Expand Down Expand Up @@ -370,14 +388,15 @@ fn run_wasm_pack_tests(cmd: Option<WasmFeatureSet>) -> Result<()> {
),
]);

let sh = sh();
let run = |(folder, arg_set): (&str, &str)| {
let _pwd = pushd(folder)?;
cmd!("pwd").env(WASM_TIMEOUT_ENV_KEY, WASM_TIMEOUT_VALUE).run()?; // print dir so we know what might have failed
cmd!("wasm-pack test --node -- ")
let _pwd = sh.push_dir(folder);
cmd!(sh, "pwd").env(WASM_TIMEOUT_ENV_KEY, WASM_TIMEOUT_VALUE).run()?; // print dir so we know what might have failed
cmd!(sh, "wasm-pack test --node -- ")
.args(arg_set.split_whitespace())
.env(WASM_TIMEOUT_ENV_KEY, WASM_TIMEOUT_VALUE)
.run()?;
cmd!("wasm-pack test --firefox --headless --")
cmd!(sh, "wasm-pack test --firefox --headless --")
.args(arg_set.split_whitespace())
.env(WASM_TIMEOUT_ENV_KEY, WASM_TIMEOUT_VALUE)
.run()
Expand Down
17 changes: 12 additions & 5 deletions xtask/src/fixup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{Args, Subcommand};
use xshell::{cmd, pushd};
use xshell::cmd;

use crate::{workspace, Result, NIGHTLY};
use crate::{sh, workspace, Result, NIGHTLY};

#[derive(Args)]
pub struct FixupArgs {
Expand All @@ -21,7 +21,8 @@ enum FixupCommand {

impl FixupArgs {
pub fn run(self) -> Result<()> {
let _p = pushd(workspace::root_path()?)?;
let sh = sh();
let _p = sh.push_dir(workspace::root_path()?);

match self.cmd {
Some(cmd) => match cmd {
Expand All @@ -41,25 +42,30 @@ impl FixupArgs {
}

fn fix_style() -> Result<()> {
cmd!("rustup run {NIGHTLY} cargo fmt").run()?;
let sh = sh();
cmd!(sh, "rustup run {NIGHTLY} cargo fmt").run()?;
Ok(())
}

fn fix_typos() -> Result<()> {
let sh = sh();
// FIXME: Print install instructions if command-not-found (needs an xshell
// change: https://github.com/matklad/xshell/issues/46)
cmd!("typos --write-changes").run()?;
cmd!(sh, "typos --write-changes").run()?;
Ok(())
}

fn fix_clippy() -> Result<()> {
let sh = sh();
cmd!(
sh,
"rustup run {NIGHTLY} cargo clippy --all-targets
--fix --allow-dirty --allow-staged
-- -D warnings "
)
.run()?;
cmd!(
sh,
"rustup run {NIGHTLY} cargo clippy --workspace --all-targets
--fix --allow-dirty --allow-staged
--exclude matrix-sdk-crypto --exclude xtask
Expand All @@ -68,6 +74,7 @@ fn fix_clippy() -> Result<()> {
)
.run()?;
cmd!(
sh,
"rustup run {NIGHTLY} cargo clippy --all-targets -p matrix-sdk-crypto
--allow-dirty --allow-staged --fix
--no-default-features -- -D warnings"
Expand Down
15 changes: 10 additions & 5 deletions xtask/src/kotlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::fs::create_dir_all;
use camino::{Utf8Path, Utf8PathBuf};
use clap::{Args, Subcommand, ValueEnum};
use uniffi_bindgen::{bindings::KotlinBindingGenerator, library_mode::generate_bindings};
use xshell::{cmd, pushd};
use xshell::cmd;

use crate::{workspace, Result};
use crate::{sh, workspace, Result};

struct PackageValues {
name: &'static str,
Expand Down Expand Up @@ -59,7 +59,8 @@ enum KotlinCommand {

impl KotlinArgs {
pub fn run(self) -> Result<()> {
let _p = pushd(workspace::root_path()?)?;
let sh = sh();
let _p = sh.push_dir(workspace::root_path()?);

match self.cmd {
KotlinCommand::BuildAndroidLibrary {
Expand Down Expand Up @@ -130,8 +131,12 @@ fn build_for_android_target(
dest_dir: &str,
package_name: &str,
) -> Result<Utf8PathBuf> {
cmd!("cargo ndk --target {target} -o {dest_dir} build --profile {profile} -p {package_name}")
.run()?;
let sh = sh();
cmd!(
sh,
"cargo ndk --target {target} -o {dest_dir} build --profile {profile} -p {package_name}"
)
.run()?;

// The builtin dev profile has its files stored under target/debug, all
// other targets have matching directory names
Expand Down
17 changes: 15 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ mod release;
mod swift;
mod workspace;

use std::rc::Rc;

use ci::CiArgs;
use clap::{Parser, Subcommand};
use fixup::FixupArgs;
use kotlin::KotlinArgs;
use release::ReleaseArgs;
use swift::SwiftArgs;
use xshell::cmd;
use xshell::{cmd, Shell};

const NIGHTLY: &str = "nightly-2024-11-26";

Expand Down Expand Up @@ -66,11 +68,22 @@ fn build_docs(
rustdocflags += " -Dwarnings";
}

let sh = sh();
// Keep in sync with .github/workflows/docs.yml
cmd!("rustup run {NIGHTLY} cargo doc --no-deps --workspace --features docsrs")
cmd!(sh, "rustup run {NIGHTLY} cargo doc --no-deps --workspace --features docsrs")
.env("RUSTDOCFLAGS", rustdocflags)
.args(extra_args)
.run()?;

Ok(())
}

thread_local! {
/// The shared shell API.
static SH: Rc<Shell> = Rc::new(Shell::new().unwrap())
}

/// Get a reference to the shared shell API.
fn sh() -> Rc<Shell> {
SH.with(|sh| sh.clone())
}
Loading

0 comments on commit 09aac52

Please sign in to comment.