Skip to content

Instantly share code, notes, and snippets.

@killerswan
Last active December 31, 2015 08:09
Show Gist options
  • Save killerswan/7958687 to your computer and use it in GitHub Desktop.
Save killerswan/7958687 to your computer and use it in GitHub Desktop.
not UTF-8 encoded?
$ ./bin/testloop-rs
""
"error: bin/testloop-rs is not UTF-8 encoded\ntask 'rustc' failed at 'explicit failure', /Users/kevin/code/rust/src/libsyntax/diagnostic.rs:102\ntask '<main>' failed at 'explicit failure', /Users/kevin/code/rust/src/librustc/lib.rs:398\n"
ExitStatus(101)
task '<main>' failed at 'Unhandled condition: io_error: io::IoError{kind: OtherIoError, desc: "no such file or directory", detail: None}', /Users/kevin/code/rust/src/libstd/condition.rs:131
extern mod extra;
use std::os;
use std::io;
#[main]
fn testloop () {
let args = os::args();
let mut has_changed = false;
let mut latest = last_modified();
let timer = io::timer::Timer::new();
while true {
let (has_changed, latest) = sources_modified_since(latest);
if has_changed {
request_build(args)
}
io::timer::sleep(200);
}
os::set_exit_status(0);
}
fn last_modified() -> u64 {
return 0;
}
fn sources_modified_since(last_modified: u64) -> (bool, u64) {
return (true, 0);
}
fn run(exe: &str, args: &[~str]) {
let ps: std::run::ProcessOutput = std::run::process_output(exe, args);
let out: &str = std::str::from_utf8(ps.output);
let err: &str = std::str::from_utf8(ps.error);
let stat: std::io::process::ProcessExit = ps.status;
println!("{:?}", out);
println!("{:?}", err);
println!("{:?}", stat);
}
fn request_build(args: &[~str]) {
// TODO: check for existence of args[0]
let args_ = [~"-o", ~"loop_test", ~"--test", args.head().to_str(), ~"--allow", ~"dead_code", ~"--opt-level", ~"0"];
run("/usr/local/bin/rustc", args_);
run("./loop_test", args.tail());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment