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

allow bacon to run without Cargo.toml file #256

Merged
merged 1 commit into from
Nov 9, 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
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bacon"
version = "3.2.0"
version = "3.2.1-no-cargo"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/bacon"
description = "background rust compiler"
Expand Down
12 changes: 4 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn run(
w: &mut W,
mut settings: Settings,
args: &Args,
location: MissionLocation,
location: Context,
) -> Result<()> {
let event_source = EventSource::with_options(EventSourceOptions {
combine_keys: false,
Expand All @@ -54,7 +54,7 @@ pub fn run(
break;
}
};
let mission = Mission::new(&location, concrete_job_ref, job, &settings)?;
let mission = location.mission(concrete_job_ref, job, &settings)?;
let do_after = app::run_mission(w, mission, &event_source, message.take())?;
match do_after {
DoAfterMission::NextJob(job_ref) => {
Expand Down Expand Up @@ -88,14 +88,10 @@ fn run_mission(

// build the watcher detecting and transmitting mission file changes
let ignorer = time!(Info, mission.ignorer());
let mission_watcher = Watcher::new(
&mission.files_to_watch,
&mission.directories_to_watch,
ignorer,
)?;
let mission_watcher = Watcher::new(&mission.paths_to_watch, ignorer)?;

// create the watcher for config file changes
let config_watcher = Watcher::new(&mission.settings.config_files, &[], None)?;
let config_watcher = Watcher::new(&mission.settings.config_files, None)?;

// create the executor, mission, and state
let mut executor = MissionExecutor::new(&mission)?;
Expand Down
10 changes: 5 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ pub fn run() -> anyhow::Result<()> {
return Ok(());
}

let location = MissionLocation::new(&args)?;
info!("mission location: {:#?}", &location);
let context = Context::new(&args)?;
info!("mission context: {:#?}", &context);

if args.init {
let package_config_path = location.package_config_path();
let package_config_path = context.package_config_path();
if !package_config_path.exists() {
fs::write(&package_config_path, DEFAULT_PACKAGE_CONFIG.trim_start())?;
eprintln!("bacon project configuration file written.");
Expand All @@ -73,7 +73,7 @@ pub fn run() -> anyhow::Result<()> {
return Ok(());
}

let settings = Settings::read(&args, &location)?;
let settings = Settings::read(&args, &context)?;

if args.list_jobs {
print_jobs(&settings);
Expand All @@ -86,7 +86,7 @@ pub fn run() -> anyhow::Result<()> {
#[cfg(windows)]
w.queue(EnableMouseCapture)?;
w.flush()?;
let result = app::run(&mut w, settings, &args, location);
let result = app::run(&mut w, settings, &args, context);
#[cfg(windows)]
w.queue(DisableMouseCapture)?;
w.queue(cursor::Show)?;
Expand Down
24 changes: 20 additions & 4 deletions src/conf/keybindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ use {
crate::*,
crokey::*,
serde::Deserialize,
std::collections::{
HashMap,
hash_map,
std::{
collections::{
HashMap,
hash_map,
},
fmt,
},
};

/// A mapping from key combinations to actions.
///
/// Several key combinations can go to the same action.
#[derive(Debug, Clone, Deserialize)]
#[derive(Clone, Deserialize)]
pub struct KeyBindings {
#[serde(flatten)]
map: HashMap<KeyCombination, Action>,
Expand Down Expand Up @@ -131,6 +134,19 @@ impl<'a> IntoIterator for &'a KeyBindings {
}
}

impl fmt::Debug for KeyBindings {
fn fmt(
&self,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
let mut ds = f.debug_struct("KeyBindings");
for (kc, action) in &self.map {
ds.field(&kc.to_string(), &action.to_string());
}
ds.finish()
}
}

#[test]
fn test_deserialize_keybindings() {
#[derive(Deserialize)]
Expand Down
13 changes: 8 additions & 5 deletions src/conf/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use {
crate::*,
anyhow::*,
anyhow::{
Result,
bail,
},
std::{
collections::HashMap,
path::PathBuf,
Expand Down Expand Up @@ -84,7 +87,7 @@ impl Settings {
/// * args given as arguments, coming from the cli call
pub fn read(
args: &Args,
location: &MissionLocation,
context: &Context,
) -> Result<Self> {
let mut settings = Settings::default();

Expand All @@ -107,10 +110,10 @@ impl Settings {
settings.apply_config(&config);
}

let workspace_config_path = location.workspace_config_path();
let package_config_path = location.package_config_path();
let workspace_config_path = context.workspace_config_path();
let package_config_path = context.package_config_path();

if package_config_path != workspace_config_path {
if let Some(workspace_config_path) = workspace_config_path {
if workspace_config_path.exists() {
info!("loading workspace level bacon.toml");
let workspace_config = Config::from_path(&workspace_config_path)?;
Expand Down
Loading