Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Nov 3, 2023
1 parent b5f5b09 commit fa600c9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/infra/cli/src/commands/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl OrderedCommand for CheckCommand {
}

fn check_cargo() -> Result<()> {
return CargoWorkspace::get_check_command("check")?.run();
return CargoWorkspace::get_command("check")?.run();
}

fn check_npm() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/infra/cli/src/commands/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl OrderedCommand for LintCommand {
}

fn run_clippy() -> Result<()> {
return CargoWorkspace::get_check_command("clippy")?.run();
return CargoWorkspace::get_command("clippy")?.run();
}

fn run_cargo_fmt() -> Result<()> {
Expand Down
14 changes: 9 additions & 5 deletions crates/infra/cli/src/commands/setup/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ use anyhow::Result;
use infra_utils::{commands::Command, github::GitHub};

pub fn setup_cargo() -> Result<()> {
return if GitHub::is_running_in_ci() {
Command::new("cargo").arg("fetch").flag("--locked").run()
} else {
Command::new("cargo").arg("fetch").run()
};
let mut command = Command::new("cargo").arg("fetch");

if GitHub::is_running_in_ci() {
// In CI, run with '--locked' to make sure `Cargo.lock` is up to date.
// Don't use '--frozen', because the cache is rarely up to date.
command = command.flag("--locked");
}

return command.run();
}
10 changes: 2 additions & 8 deletions crates/infra/cli/src/commands/test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::{ClapExtensions, OrderedCommand, Terminal};
use anyhow::Result;
use clap::{Parser, ValueEnum};
use infra_utils::{commands::Command, github::GitHub};
use infra_utils::{cargo::CargoWorkspace, commands::Command, github::GitHub};

#[derive(Clone, Debug, Default, Parser)]
pub struct TestController {
Expand Down Expand Up @@ -35,13 +35,7 @@ impl OrderedCommand for TestCommand {
}

fn test_cargo() -> Result<()> {
let mut command = Command::new("cargo")
.arg("test")
.flag("--quiet")
.flag("--offline")
.flag("--all")
.flag("--all-targets")
.flag("--all-features");
let mut command = CargoWorkspace::get_command("test")?.flag("--quiet");

if GitHub::is_running_in_ci() {
command = command.flag("--no-fail-fast");
Expand Down
22 changes: 16 additions & 6 deletions crates/infra/utils/src/cargo/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,30 @@ impl CargoWorkspace {
return cargo_toml.write_string(updated_contents);
}

pub fn get_check_command(subcommand: impl AsRef<str>) -> Result<Command> {
pub fn get_command(subcommand: impl AsRef<str>) -> Result<Command> {
let mut command = Command::new("cargo")
.arg(subcommand.as_ref())
.flag("--offline")
.flag(
// Cargo will periodically try to update its manifest/local cache from internet before running these
// commands. This periodically means 1min+ interruptions for local development, and even blocking
// development completely if you are working offline. Using '--offline' prevents that, making sure
// that the command always reuses the dependencies already downloaded by 'infra setup'.
"--offline",
)
.flag("--all")
.flag("--all-targets")
.flag("--all-features");

if GitHub::is_running_in_ci() {
// Using `$RUSTFLAGS' or '--' overrides any rustflags from `.cargo/config.toml'.
// Using this syntax instead, as it is concatinated with the existing flags:
let rustflags = serde_json::to_string(&["--deny", "warnings"])?;

command = command.property("--config", format!("build.rustflags = {rustflags}"));
// Using this syntax instead, as it is concatenated with the existing flags:
command = command.property(
"--config",
format!(
"build.rustflags = {rustflags}",
rustflags = serde_json::to_string(&["--deny", "warnings"])?,
),
);
}

return Ok(command);
Expand Down

0 comments on commit fa600c9

Please sign in to comment.