diff --git a/components/servo/main.rs b/components/servo/main.rs index 5ffc75d911f..46f320a13e6 100644 --- a/components/servo/main.rs +++ b/components/servo/main.rs @@ -47,47 +47,47 @@ fn main() { env_logger::init().unwrap(); // Parse the command line options and store them globally - if opts::from_cmdline_args(&*get_args()) { - setup_logging(); + opts::from_cmdline_args(&*get_args()); - // Possibly interpret the `HOST_FILE` environment variable - resource_task::global_init(); + setup_logging(); - let window = if opts::get().headless { - None - } else { - Some(app::create_window(std::ptr::null_mut())) + // Possibly interpret the `HOST_FILE` environment variable + resource_task::global_init(); + + let window = if opts::get().headless { + None + } else { + Some(app::create_window(std::ptr::null_mut())) + }; + + // Our wrapper around `Browser` that also implements some + // callbacks required by the glutin window implementation. + let mut browser = BrowserWrapper { + browser: Browser::new(window.clone()), + }; + + maybe_register_glutin_resize_handler(&window, &mut browser); + + browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]); + + // Feed events from the window to the browser until the browser + // says to stop. + loop { + let should_continue = match window { + None => browser.browser.handle_events(Vec::new()), + Some(ref window) => browser.browser.handle_events(window.wait_events()), }; + if !should_continue { + break + } + }; - // Our wrapper around `Browser` that also implements some - // callbacks required by the glutin window implementation. - let mut browser = BrowserWrapper { - browser: Browser::new(window.clone()), - }; + maybe_unregister_glutin_resize_handler(&window); - maybe_register_glutin_resize_handler(&window, &mut browser); - - browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]); - - // Feed events from the window to the browser until the browser - // says to stop. - loop { - let should_continue = match window { - None => browser.browser.handle_events(Vec::new()), - Some(ref window) => browser.browser.handle_events(window.wait_events()), - }; - if !should_continue { - break - } - }; - - maybe_unregister_glutin_resize_handler(&window); - - let BrowserWrapper { - browser - } = browser; - browser.shutdown(); - } + let BrowserWrapper { + browser + } = browser; + browser.shutdown(); } fn maybe_register_glutin_resize_handler(window: &Option>, diff --git a/components/util/lib.rs b/components/util/lib.rs index 8213c4e56c4..4d7cfeec6d6 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -5,7 +5,6 @@ #![feature(alloc)] #![feature(box_syntax)] #![feature(core_intrinsics)] -#![feature(exit_status)] #![feature(fnbox)] #![feature(hashmap_hasher)] #![feature(heap_api)] diff --git a/components/util/opts.rs b/components/util/opts.rs index dbddcfe0f98..3c5be3888bb 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -19,6 +19,7 @@ use std::io::{self, Write}; use std::fs::PathExt; use std::mem; use std::path::Path; +use std::process; use std::ptr; use url::{self, Url}; @@ -159,7 +160,7 @@ fn print_usage(app: &str, opts: &[getopts::OptGroup]) { println!("{}", getopts::usage(&message, opts)); } -pub fn print_debug_usage(app: &str) { +pub fn print_debug_usage(app: &str) -> ! { fn print_option(name: &str, description: &str) { println!("\t{:<35} {}", name, description); } @@ -185,13 +186,15 @@ pub fn print_debug_usage(app: &str) { "Disable the style sharing cache."); println!(""); + + process::exit(0) } -fn args_fail(msg: &str) { +fn args_fail(msg: &str) -> ! { let mut stderr = io::stderr(); stderr.write_all(msg.as_bytes()).unwrap(); stderr.write_all(b"\n").unwrap(); - env::set_exit_status(1); + process::exit(1) } // Always use CPU painting on android. @@ -244,7 +247,7 @@ pub fn default_opts() -> Opts { } } -pub fn from_cmdline_args(args: &[String]) -> bool { +pub fn from_cmdline_args(args: &[String]) { let app_name = args[0].to_string(); let args = args.tail(); @@ -279,15 +282,12 @@ pub fn from_cmdline_args(args: &[String]) -> bool { let opt_match = match getopts::getopts(args, &opts) { Ok(m) => m, - Err(f) => { - args_fail(&f.to_string()); - return false; - } + Err(f) => args_fail(&f.to_string()), }; if opt_match.opt_present("h") || opt_match.opt_present("help") { print_usage(&app_name, &opts); - return false; + process::exit(0); }; let debug_string = match opt_match.opt_str("Z") { @@ -299,14 +299,12 @@ pub fn from_cmdline_args(args: &[String]) -> bool { debug_options.insert(split.clone()); } if debug_options.contains(&"help") { - print_debug_usage(&app_name); - return false; + print_debug_usage(&app_name) } let url = if opt_match.free.is_empty() { print_usage(&app_name, &opts); - args_fail("servo asks that you provide a URL"); - return false; + args_fail("servo asks that you provide a URL") } else { let ref url = opt_match.free[0]; let cwd = env::current_dir().unwrap(); @@ -316,8 +314,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool { if Path::new(url).exists() { Url::from_file_path(&*cwd.join(url)).unwrap() } else { - args_fail(&format!("File not found: {}", url)); - return false; + args_fail(&format!("File not found: {}", url)) } } Err(_) => panic!("URL parsing failed"), @@ -423,7 +420,6 @@ pub fn from_cmdline_args(args: &[String]) -> bool { }; set(opts); - true } static mut EXPERIMENTAL_ENABLED: bool = false; diff --git a/ports/gonk/src/main.rs b/ports/gonk/src/main.rs index 9e3cf9636f7..5046574e859 100644 --- a/ports/gonk/src/main.rs +++ b/ports/gonk/src/main.rs @@ -62,47 +62,47 @@ fn main() { env_logger::init().unwrap(); // Parse the command line options and store them globally - if opts::from_cmdline_args(env::args().collect::>().as_slice()) { - resource_task::global_init(); + opts::from_cmdline_args(env::args().collect::>().as_slice()); - let window = if opts::get().headless { - None - } else { - Some(window::Window::new()) - }; + resource_task::global_init(); - // Our wrapper around `Browser` that also implements some - // callbacks required by the glutin window implementation. - let mut browser = BrowserWrapper { - browser: Browser::new(window.clone()), - }; + let window = if opts::get().headless { + None + } else { + Some(window::Window::new()) + }; - match window { - None => (), - Some(ref window) => input::run_input_loop(&window.event_send) - } + // Our wrapper around `Browser` that also implements some + // callbacks required by the glutin window implementation. + let mut browser = BrowserWrapper { + browser: Browser::new(window.clone()), + }; - browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]); - - // Feed events from the window to the browser until the browser - // says to stop. - loop { - let should_continue = match window { - None => browser.browser.handle_events(vec![WindowEvent::Idle]), - Some(ref window) => { - let events = window.wait_events(); - browser.browser.handle_events(events) - } - }; - if !should_continue { - break - } - } - - let BrowserWrapper { - browser - } = browser; - browser.shutdown(); + match window { + None => (), + Some(ref window) => input::run_input_loop(&window.event_send) } + + browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]); + + // Feed events from the window to the browser until the browser + // says to stop. + loop { + let should_continue = match window { + None => browser.browser.handle_events(vec![WindowEvent::Idle]), + Some(ref window) => { + let events = window.wait_events(); + browser.browser.handle_events(events) + } + }; + if !should_continue { + break + } + } + + let BrowserWrapper { + browser + } = browser; + browser.shutdown(); }