This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Big rewrite of the application #30
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ee3a030
Run `cargo fmt` (reformat all files without checking the result)
LukasKalbertodt d96d05a
Cleanup functions in `cargo.rs` and reformat some other things
LukasKalbertodt fbd03d1
Cleanup `main.rs`
LukasKalbertodt 2860c9f
Add comments and cleanup
LukasKalbertodt f65af1b
Some cleanup in `compile.rs`
LukasKalbertodt 09e2677
Rewrite of the whole program (one feature still missing!)
LukasKalbertodt 0791767
Put magic constants into `config.rs` and cleanup some code
LukasKalbertodt 15ff8b2
Remove unnessessary deps, update deps and add my name to authors
LukasKalbertodt f2c5e2a
Fix debug output
LukasKalbertodt 2e8e849
Remove unnecessary IGNORED_FILES regex
LukasKalbertodt 342e647
Remove unnecessary `build` call, since it's implied by `test`
LukasKalbertodt 8606461
Add ids of tracking issues to FIXME comments
LukasKalbertodt b5baeae
Add "examples" as watched folder and ignore errors from `watch` (fixe…
LukasKalbertodt 6038af0
Re-add feature: only one job is running at every point in time
LukasKalbertodt 9af1f17
Rewrite process waiting to prepare for process-cancel feature
LukasKalbertodt aceace5
Add feature: `cargo run` processes are killed upon file changes
LukasKalbertodt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ authors = [ | |
"Gabor Nagy <[email protected]>", | ||
"Ivan Jager <[email protected]>", | ||
"Christopher Brickley <[email protected]>", | ||
"Lukas Kalbertodt <[email protected]>", | ||
] | ||
|
||
description = "Utility for cargo to compile projects when sources change" | ||
|
@@ -27,8 +28,8 @@ keywords = [ | |
[dependencies] | ||
docopt = "^0.6.78" | ||
env_logger = "^0.3.2" | ||
lazy_static = "0.1.15" | ||
log = "^0.3.4" | ||
notify = "^2.5.4" | ||
regex = "^0.1.44" | ||
rustc-serialize = "^0.3.16" | ||
time = "^0.1.34" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,50 @@ | ||
//! Utilities for working with cargo, | ||
//! Utilities for working with cargo and rust files | ||
|
||
use config; | ||
use regex::Regex; | ||
use std::env; | ||
use std::ffi::OsStr; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
use std::process::Stdio; | ||
|
||
macro_rules! Sl(($v:expr) => (String::from_utf8_lossy($v.as_slice()))); | ||
|
||
/// Returns the closest ancestor Path containing a Cargo.toml. | ||
/// Returns the closest ancestor path containing a `Cargo.toml`. | ||
/// | ||
/// Returns None if no ancestor Path contains a Cargo.toml, or if | ||
/// the limit of 10 ancestors has been run through. | ||
/// Returns `None` if no ancestor path contains a `Cargo.toml`, or if | ||
/// the limit of MAX_ANCESTORS ancestors has been reached. | ||
pub fn root() -> Option<PathBuf> { | ||
let mut wd = match env::current_dir() { | ||
Err(_) => { return None; }, | ||
Ok(w) => w | ||
}; | ||
|
||
fn contains_manifest(path: &mut PathBuf) -> bool { | ||
match fs::read_dir(path) { | ||
Ok(mut entries) => | ||
entries.any(|ent| match ent { | ||
Err(_) => false, | ||
Ok(ref ent) => { | ||
ent.path().file_name() == Some(OsStr::new("Cargo.toml")) | ||
} | ||
}), | ||
Err(_) => false | ||
/// Checks if the directory contains `Cargo.toml` | ||
fn contains_manifest(path: &PathBuf) -> bool { | ||
fs::read_dir(path).map(|entries| { | ||
entries.filter_map(|res| res.ok()) | ||
.any(|ent| &ent.file_name() == "Cargo.toml") | ||
}).unwrap_or(false) | ||
} | ||
} | ||
|
||
for _ in 0..11 { | ||
if contains_manifest(&mut wd) { | ||
return Some(wd) | ||
} | ||
if !wd.pop() { break } | ||
} | ||
// From the current directory we work our way up, looking for `Cargo.toml` | ||
env::current_dir().ok().and_then(|mut wd| { | ||
for _ in 0..config::MAX_ANCESTORS { | ||
if contains_manifest(&mut wd) { | ||
return Some(wd); | ||
} | ||
if !wd.pop() { | ||
break; | ||
} | ||
} | ||
|
||
None | ||
}) | ||
} | ||
|
||
None | ||
lazy_static! { | ||
static ref IGNORED_FILES: Vec<Regex> = { | ||
config::IGNORED_FILES.iter().map(|s| { | ||
// FIXME: This should use the compile-time `regex!` macros, when | ||
// syntax extensions become stabilized (see #32) | ||
Regex::new(s).expect("Couldn't parse regex") | ||
}).collect() | ||
}; | ||
} | ||
|
||
/// Runs one or more cargo commands and displays the output. | ||
pub fn run(cmds: &str) { | ||
let cmds_vec: Vec<&str> = cmds.split_whitespace().collect(); | ||
println!("\n$ cargo {}", cmds); | ||
match Command::new("cargo") | ||
.stderr(Stdio::inherit()) | ||
.stdout(Stdio::inherit()) | ||
.args(&cmds_vec) | ||
.output() { | ||
Ok(o) => println!("-> {}", o.status), | ||
Err(e) => println!("Failed to execute 'cargo {}': {}", cmds, e) | ||
}; | ||
/// Checks if the given filename should be ignored | ||
pub fn is_ignored_file(f: &str) -> bool { | ||
IGNORED_FILES.iter().any(|fr| fr.is_match(f)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// These commands are executed when no arguments are given to `cargo watch` | ||
pub const DEFAULT_COMMANDS: [&'static str; 1] = ["test"]; | ||
|
||
/// How many parent folders are searched for a `Cargo.toml` | ||
pub const MAX_ANCESTORS: u32 = 10; | ||
|
||
/// Which subdirectories are being watched for changes | ||
pub const WATCH_DIRS: [&'static str; 3] = ["src", "tests", "benches"]; | ||
|
||
/// Changes on files whose names match one of these regexes are ignored | ||
pub const IGNORED_FILES: [&'static str; 3] = [ | ||
// FIXME: It should be possible to trigger on non-.rs changes (see #31) | ||
r"[^.][^r][^s]$", | ||
r"^\.", | ||
r"^~", | ||
]; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#33 could just be fixed right there, while we're at it.