Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add root env vars to fix --color=always problem #263

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- more lenient detection of warnings and errors due to 'miri run' not supporting `--color` - Fix #251
- eslint analyzer (set `analyzer = "eslint"` in your job definition)
- new `ignore` job parameter, accepts a list of glob patterns
- allow defining environment vars for all jobs - Fix #261 and #124

<a name="v3.2.0"></a>
### v3.2.0 - 2024/11/04
Expand Down
17 changes: 5 additions & 12 deletions bacon.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# a bacon.toml file dedicated to the bacon tool

default_job = "check-all"
env.CARGO_TERM_COLOR = "always"

[jobs]

[jobs.check]
command = [
"cargo", "check",
"--color", "always",
]
command = ["cargo", "check"]
need_stdout = false
default_watch = false
watch = ["src"]
Expand All @@ -17,7 +15,6 @@ watch = ["src"]
command = [
"cargo", "check",
"--all-targets",
"--color", "always",
]
need_stdout = false

Expand All @@ -27,7 +24,6 @@ command = [
"+nightly",
"check",
"--all-targets",
"--color", "always",
]
need_stdout = false

Expand All @@ -38,26 +34,23 @@ command = [
]

[jobs.test]
command = [
"cargo", "test", "--color", "always",
]
command = ["cargo", "test"]
need_stdout = true

[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--no-deps"]
command = ["cargo", "doc", "--no-deps"]
need_stdout = false

# If the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = ["cargo", "doc", "--color", "always", "--no-deps", "--open"]
command = ["cargo", "doc", "--no-deps", "--open"]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

[jobs.clippy-all]
command = [
"cargo", "clippy",
"--color", "always",
"--",
"-A", "clippy::bool_to_int_with_if",
"-A", "clippy::collapsible_else_if",
Expand Down
31 changes: 9 additions & 22 deletions defaults/default-bacon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
# https://github.com/Canop/bacon/blob/main/defaults/default-bacon.toml

default_job = "check"
env.CARGO_TERM_COLOR = "always"

[jobs.check]
command = ["cargo", "check", "--color", "always"]
command = ["cargo", "check"]
need_stdout = false

[jobs.check-all]
command = ["cargo", "check", "--all-targets", "--color", "always"]
command = ["cargo", "check", "--all-targets"]
need_stdout = false

# Run clippy on the default target
[jobs.clippy]
command = [
"cargo", "clippy",
"--color", "always",
]
command = ["cargo", "clippy"]
need_stdout = false

# Run clippy on all targets
Expand All @@ -29,49 +27,40 @@ need_stdout = false
# command = [
# "cargo", "clippy",
# "--all-targets",
# "--color", "always",
# "--",
# "-A", "clippy::bool_to_int_with_if",
# "-A", "clippy::collapsible_if",
# "-A", "clippy::derive_partial_eq_without_eq",
# ]
# need_stdout = false
[jobs.clippy-all]
command = [
"cargo", "clippy",
"--all-targets",
"--color", "always",
]
command = ["cargo", "clippy", "--all-targets"]
need_stdout = false

# This job lets you run
# - all tests: bacon test
# - a specific test: bacon test -- config::test_default_files
# - the tests of a package: bacon test -- -- -p config
[jobs.test]
command = [
"cargo", "test", "--color", "always",
"--", "--color", "always", # see https://github.com/Canop/bacon/issues/124
]
command = ["cargo", "test"]
need_stdout = true

[jobs.nextest]
command = [
"cargo", "nextest", "run",
"--color", "always",
"--hide-progress-bar", "--failure-output", "final"
]
need_stdout = true
analyzer = "nextest"

[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--no-deps"]
command = ["cargo", "doc", "--no-deps"]
need_stdout = false

# If the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = ["cargo", "doc", "--color", "always", "--no-deps", "--open"]
command = ["cargo", "doc", "--no-deps", "--open"]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

Expand All @@ -82,7 +71,6 @@ on_success = "back" # so that we don't open the browser at each change
[jobs.run]
command = [
"cargo", "run",
"--color", "always",
# put launch parameters for your program behind a `--` separator
]
need_stdout = true
Expand All @@ -100,7 +88,6 @@ background = true
[jobs.run-long]
command = [
"cargo", "run",
"--color", "always",
# put launch parameters for your program behind a `--` separator
]
need_stdout = true
Expand All @@ -113,7 +100,7 @@ on_change_strategy = "kill_then_restart"
# Call it as
# bacon ex -- my-example
[jobs.ex]
command = ["cargo", "run", "--color", "always", "--example"]
command = ["cargo", "run", "--example"]
need_stdout = true
allow_warnings = true

Expand Down
4 changes: 4 additions & 0 deletions src/conf/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ pub struct Config {
pub watch: Option<Vec<String>>,

pub wrap: Option<bool>,

/// Env vars to set for all job executions
#[serde(default)]
pub env: HashMap<String, String>,
}

impl Config {
Expand Down
14 changes: 5 additions & 9 deletions src/conf/settings.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use {
crate::*,
anyhow::{
Result,
bail,
},
std::{
collections::HashMap,
path::PathBuf,
time::Duration,
},
anyhow::{bail, Result},
std::{collections::HashMap, path::PathBuf, time::Duration},
};

/// The settings used in the application.
Expand Down Expand Up @@ -45,6 +38,7 @@ pub struct Settings {
pub summary: bool,
pub watch: Vec<String>,
pub wrap: bool,
pub env: HashMap<String, String>,
}

impl Default for Settings {
Expand Down Expand Up @@ -72,6 +66,7 @@ impl Default for Settings {
config_files: Default::default(),
default_watch: true,
watch: Default::default(),
env: Default::default(),
}
}
}
Expand Down Expand Up @@ -156,6 +151,7 @@ impl Settings {
&mut self,
config: &Config,
) {
self.env.extend(config.env.clone());
if let Some(b) = config.summary {
self.summary = b;
}
Expand Down
12 changes: 9 additions & 3 deletions src/mission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
crate::*,
lazy_regex::regex_replace_all,
rustc_hash::FxHashSet,
std::collections::HashMap,
std::path::PathBuf,
};

Expand Down Expand Up @@ -114,11 +115,16 @@ impl<'s> Mission<'s> {
tokens.next().unwrap(), // implies a check in the job
);
command.with_stdout(self.need_stdout());

let envs: HashMap<&String, &String> = self
.settings
.env
.iter()
.chain(self.job.env.iter())
.collect();
if !self.job.extraneous_args {
command.args(tokens);
command.current_dir(&self.execution_directory);
command.envs(&self.job.env);
command.envs(envs);
debug!("command: {:#?}", &command);
return command;
}
Expand Down Expand Up @@ -197,7 +203,7 @@ impl<'s> Mission<'s> {
}
}
command.current_dir(&self.execution_directory);
command.envs(&self.job.env);
command.envs(envs);
debug!("command builder: {:#?}", &command);
command
}
Expand Down