Skip to content

Commit

Permalink
Hide Tokio crates behind cfg gate for Redox (#317)
Browse files Browse the repository at this point in the history
* Hide tokio behind gate for redox

* Move common shell logic to 'inner_main'

* Move tokio stuffs to cfg gate

* Move futures dependency to not(target_os = redox) gate
  • Loading branch information
hgoldstein authored and mmstick committed Jun 20, 2017
1 parent eea59ea commit b1014bf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ name = "ion"
[dependencies]
bitflags = "0.9.1"
fnv = "1.0"
futures = "0.1"
glob = "0.2"
liner = "0.2"
permutate = "0.3"
unicode-segmentation = "1.2"
smallvec = "0.4"
smallstring = "0.1"

[target.'cfg(not(target_os = "redox"))'.dependencies]
futures = "0.1"
tokio-core = "0.1"
tokio-signal = "0.1"

Expand Down
66 changes: 39 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#[macro_use]
extern crate bitflags;
extern crate fnv;
extern crate futures;
extern crate glob;
extern crate liner;
extern crate smallvec;
extern crate smallstring;
extern crate tokio_core;
extern crate tokio_signal;

#[cfg(not(target_os = "redox"))] extern crate futures;
#[cfg(not(target_os = "redox"))] extern crate tokio_core;
#[cfg(not(target_os = "redox"))] extern crate tokio_signal;

#[cfg(all(unix, not(target_os = "redox")))]
extern crate users as users_unix;
Expand All @@ -30,36 +31,41 @@ use std::io::{stderr, Write, ErrorKind};
use builtins::Builtin;
use shell::Shell;

use tokio_core::reactor::Core;
use futures::{Future, Stream};
#[cfg(not(target_os = "redox"))] use tokio_core::reactor::Core;
#[cfg(not(target_os = "redox"))] use futures::{Future, Stream};

use std::sync::mpsc;
use std::thread;

fn inner_main(sigint_rx : mpsc::Receiver<bool>) {
let builtins = Builtin::map();
let mut shell = Shell::new(&builtins, sigint_rx);
shell.evaluate_init_file();

if "1" == shell.variables.get_var_or_empty("HISTORY_FILE_ENABLED") {
shell.context.history.set_file_name(shell.variables.get_var("HISTORY_FILE"));
match shell.context.history.load_history() {
Ok(()) => {
// pass
}
Err(ref err) if err.kind() == ErrorKind::NotFound => {
let history_filename = shell.variables.get_var_or_empty("HISTORY_FILE");
let _ = writeln!(stderr(), "ion: failed to find history file {}: {}", history_filename, err);
},
Err(err) => {
let _ = writeln!(stderr(), "ion: failed to load history: {}", err);
}
}
}
shell.execute();
}


#[cfg(not(target_os = "redox"))]
fn main() {
let (sigint_tx, sigint_rx) = mpsc::channel();

thread::spawn(move || {
let builtins = Builtin::map();
let mut shell = Shell::new(&builtins, sigint_rx);
shell.evaluate_init_file();

if "1" == shell.variables.get_var_or_empty("HISTORY_FILE_ENABLED") {
shell.context.history.set_file_name(shell.variables.get_var("HISTORY_FILE"));
match shell.context.history.load_history() {
Ok(()) => {
// pass
}
Err(ref err) if err.kind() == ErrorKind::NotFound => {
let history_filename = shell.variables.get_var_or_empty("HISTORY_FILE");
let _ = writeln!(stderr(), "ion: failed to find history file {}: {}", history_filename, err);
},
Err(err) => {
let _ = writeln!(stderr(), "ion: failed to load history: {}", err);
}
}
}
shell.execute();
});
thread::spawn(move || inner_main(sigint_rx));

let mut core = Core::new().unwrap();
let handle = core.handle();
Expand All @@ -71,3 +77,9 @@ fn main() {
});
core.run(signal_handler).unwrap();
}

#[cfg(target_os = "redox")]
fn main() {
let (_, sigint_rx) = mpsc::channel();
inner_main(sigint_rx);
}

0 comments on commit b1014bf

Please sign in to comment.