From 3d0a75f37674d03cfe0e194b4ad199b456e7344d Mon Sep 17 00:00:00 2001 From: elias Date: Tue, 19 Mar 2019 17:28:01 -0500 Subject: [PATCH 01/11] initial reshuffling of opts generation for #23009 --- Cargo.lock | 18 +++++++++++------- components/config/opts.rs | 27 ++++++++++----------------- ports/servo/Cargo.toml | 1 + ports/servo/non_android_main.rs | 18 +++++++++++++++++- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0df2ab8bc76..91a792263e7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -532,7 +532,7 @@ dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1332,8 +1332,11 @@ dependencies = [ [[package]] name = "getopts" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "gfx" @@ -3661,6 +3664,7 @@ dependencies = [ "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.4 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3852,7 +3856,7 @@ dependencies = [ "embedder_traits 0.0.1", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.4 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4298,7 +4302,7 @@ name = "textwrap" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4599,7 +4603,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-width" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -5202,7 +5206,7 @@ dependencies = [ "checksum gaol 0.2.0 (git+https://github.com/servo/gaol)" = "" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" -"checksum getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "b900c08c1939860ce8b54dc6a89e26e00c04c380fd0e09796799bd7f12861e05" +"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum gif 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff3414b424657317e708489d2857d9575f4403698428b040b609b9d1c1a84a2c" "checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604" "checksum gleam 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4b47f5b15742aee359c7895ab98cf2cceecc89bb4feb6f4e42f802d7899877da" @@ -5449,7 +5453,7 @@ dependencies = [ "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-script 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e8bd7bbf020b2885113e6304f68bcc33881c5552657c58d4e9699cd1b6606e81" "checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" -"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" diff --git a/components/config/opts.rs b/components/config/opts.rs index 636733105283..da2211ba35dd 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -607,10 +607,9 @@ pub fn default_opts() -> Opts { } } -pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { - let (app_name, args) = args.split_first().unwrap(); +fn create_global_opts(mut opts: getopts::Options) -> Options { + - let mut opts = Options::new(); opts.optflag("c", "cpu", "CPU painting"); opts.optflag("g", "gpu", "GPU painting"); opts.optopt("o", "output", "Output file", "output.png"); @@ -666,7 +665,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "Shaders will be loaded from the specified directory instead of using the builtin ones.", "", ); - opts.optflag("z", "headless", "Headless mode"); opts.optflag( "f", "hard-fail", @@ -702,7 +700,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "Set custom user agent string (or ios / android / desktop for platform default)", "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)", ); - opts.optflag("M", "multiprocess", "Run in multiprocess mode"); opts.optflag("S", "sandbox", "Run in a sandbox if multiprocess"); opts.optopt( "", @@ -716,12 +713,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "A fixed seed for repeatbility of random pipeline closure.", "", ); - opts.optmulti( - "Z", - "debug", - "A comma-separated string of debug options. Pass help to show available options.", - "", - ); opts.optflag("h", "help", "Print this message"); opts.optopt( "", @@ -735,12 +726,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "Path to find SSL certificates", "/home/servo/resources/certs", ); - opts.optopt( - "", - "content-process", - "Run as a content process and connect to the given pipe", - "servo-ipc-channel.abcdefg", - ); opts.optmulti( "", "pref", @@ -768,6 +753,14 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { opts.optopt("", "profiler-db-name", "Profiler database name", ""); opts.optflag("", "print-pwm", "Print Progressive Web Metrics"); + opts +} + +pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentParsingResult { + let (app_name, args) = args.split_first().unwrap(); + + let opts = create_global_opts(opts); + let opt_match = match opts.parse(args) { Ok(m) => m, Err(f) => args_fail(&f.to_string()), diff --git a/ports/servo/Cargo.toml b/ports/servo/Cargo.toml index 8f798d9cc650..091018623725 100644 --- a/ports/servo/Cargo.toml +++ b/ports/servo/Cargo.toml @@ -40,6 +40,7 @@ webrender_debugger = ["libservo/webrender_debugger"] js_backtrace = ["libservo/js_backtrace"] [target.'cfg(not(target_os = "android"))'.dependencies] +getopts = "0.2.18" backtrace = "0.3" bitflags = "1.0" crossbeam-channel = "0.3" diff --git a/ports/servo/non_android_main.rs b/ports/servo/non_android_main.rs index 7dd8a5008f0c..624bd96f0f81 100644 --- a/ports/servo/non_android_main.rs +++ b/ports/servo/non_android_main.rs @@ -14,6 +14,7 @@ mod resources; mod browser; use backtrace::Backtrace; +use getopts::Options; use servo::{Servo, BrowserId}; use servo::compositing::windowing::WindowEvent; use servo::config::opts::{self, ArgumentParsingResult, parse_url_or_filename}; @@ -63,6 +64,20 @@ fn install_crash_handler() { signal!(Sig::BUS, handler); // handle invalid memory access } +fn create_gluten_opts() -> Options { + let mut opts = Options::new(); + opts.optflag("z", "headless", "Headless mode"); + opts.optflag("M", "multiprocess", "Run in multiprocess mode"); + opts.optmulti( + "Z", + "debug", + "A comma-separated string of debug options. Pass help to show available options.", + "", + ); + + opts +} + pub fn main() { install_crash_handler(); @@ -70,7 +85,8 @@ pub fn main() { // Parse the command line options and store them globally let args: Vec = env::args().collect(); - let opts_result = opts::from_cmdline_args(&args); + let opts = create_gluten_opts(); + let opts_result = opts::from_cmdline_args(opts ,&args); let content_process_token = if let ArgumentParsingResult::ContentProcess(token) = opts_result { Some(token) From 046aa01197b175c0b5b8f7d07548817a1a711dc1 Mon Sep 17 00:00:00 2001 From: elias Date: Thu, 21 Mar 2019 11:19:11 -0500 Subject: [PATCH 02/11] moved multiprocess flag out of opts.rs back into gluten embedder, changed return type of from_cmdline_args to getopts::Result --- components/config/opts.rs | 34 ++++++++++++++-------------- ports/servo/non_android_main.rs | 39 +++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index da2211ba35dd..f161818e9e6c 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -7,7 +7,7 @@ use crate::prefs::{self, PrefValue, PREFS}; use euclid::TypedSize2D; -use getopts::Options; +use getopts::{Options}; use servo_geometry::DeviceIndependentPixel; use servo_url::ServoUrl; use std::borrow::Cow; @@ -485,13 +485,16 @@ pub enum OutputOptions { Stdout(f64), } -fn args_fail(msg: &str) -> ! { +pub fn args_fail(msg: &str) -> ! { writeln!(io::stderr(), "{}", msg).unwrap(); process::exit(1) } static MULTIPROCESS: AtomicBool = AtomicBool::new(false); +#[inline] +pub fn set_multiprocess(b: bool, ord: Ordering) { MULTIPROCESS.store(b, ord) } + #[inline] pub fn multiprocess() -> bool { MULTIPROCESS.load(Ordering::Relaxed) @@ -615,6 +618,15 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { opts.optopt("o", "output", "Output file", "output.png"); opts.optopt("s", "size", "Size of tiles", "512"); opts.optopt("", "device-pixel-ratio", "Device pixels per px", ""); + // one thing at a time + opts.optflag("z", "headless", "Headless mode"); + opts.optmulti( + "Z", + "debug", + "A comma-separated string of debug options. Pass help to show available options.", + "", + ); + opts.optflagopt( "p", "profile", @@ -756,7 +768,7 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { opts } -pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentParsingResult { +pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Result { let (app_name, args) = args.split_first().unwrap(); let opts = create_global_opts(opts); @@ -771,13 +783,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar process::exit(0); }; - // If this is the content process, we'll receive the real options over IPC. So just fill in - // some dummy options for now. - if let Some(content_process) = opt_match.opt_str("content-process") { - MULTIPROCESS.store(true, Ordering::SeqCst); - return ArgumentParsingResult::ContentProcess(content_process); - } - let mut debug_options = DebugOptions::default(); for debug_string in opt_match.opt_strs("Z") { @@ -941,10 +946,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar None => TypedSize2D::new(1024, 740), }; - if opt_match.opt_present("M") { - MULTIPROCESS.store(true, Ordering::SeqCst) - } - let user_agent = match opt_match.opt_str("u") { Some(ref ua) if ua == "ios" => default_user_agent_string(UserAgent::iOS).into(), Some(ref ua) if ua == "android" => default_user_agent_string(UserAgent::Android).into(), @@ -982,7 +983,7 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar let is_printing_version = opt_match.opt_present("v") || opt_match.opt_present("version"); - let opts = Opts { + let mut opts = Opts { is_running_problem_test: is_running_problem_test, url: url_opt, tile_size: tile_size, @@ -1069,7 +1070,8 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar PREFS.set("layout.threads", PrefValue::Number(layout_threads as f64)); } - ArgumentParsingResult::ChromeProcess + // ArgumentParsingResult::ChromeProcess + Ok(opt_match) } pub enum ArgumentParsingResult { diff --git a/ports/servo/non_android_main.rs b/ports/servo/non_android_main.rs index 624bd96f0f81..89192a921a41 100644 --- a/ports/servo/non_android_main.rs +++ b/ports/servo/non_android_main.rs @@ -17,10 +17,11 @@ use backtrace::Backtrace; use getopts::Options; use servo::{Servo, BrowserId}; use servo::compositing::windowing::WindowEvent; -use servo::config::opts::{self, ArgumentParsingResult, parse_url_or_filename}; +use servo::config::opts::{self, ArgumentParsingResult, parse_url_or_filename, set_multiprocess, set_options, args_fail}; use servo::config::servo_version; use servo::servo_config::prefs::PREFS; use servo::servo_url::ServoUrl; +use std::sync::atomic::{Ordering}; use std::env; use std::panic; use std::process; @@ -66,14 +67,15 @@ fn install_crash_handler() { fn create_gluten_opts() -> Options { let mut opts = Options::new(); - opts.optflag("z", "headless", "Headless mode"); opts.optflag("M", "multiprocess", "Run in multiprocess mode"); - opts.optmulti( - "Z", - "debug", - "A comma-separated string of debug options. Pass help to show available options.", - "", - ); + // TODO +// opts.optflag("z", "headless", "Headless mode"); +// opts.optmulti( +// "Z", +// "debug", +// "A comma-separated string of debug options. Pass help to show available options.", +// "", +// ); opts } @@ -86,18 +88,27 @@ pub fn main() { // Parse the command line options and store them globally let args: Vec = env::args().collect(); let opts = create_gluten_opts(); - let opts_result = opts::from_cmdline_args(opts ,&args); + let opt_result = opts::from_cmdline_args(opts ,&args); - let content_process_token = if let ArgumentParsingResult::ContentProcess(token) = opts_result { - Some(token) + let opt_match = match opt_result { + Ok(o) => o, + Err(f) => args_fail(&f.to_string()), + }; + + if let Some(token) = opt_match.opt_str("content-process") { + return servo::run_content_process(token); } else { if opts::get().is_running_problem_test && env::var("RUST_LOG").is_err() { env::set_var("RUST_LOG", "compositing::constellation"); } - None + () }; + if opt_match.opt_present("M") { + set_multiprocess(true, Ordering::SeqCst); + } + // TODO: once log-panics is released, can this be replaced by // log_panics::init()? panic::set_hook(Box::new(|info| { @@ -129,10 +140,6 @@ pub fn main() { error!("{}", msg); })); - if let Some(token) = content_process_token { - return servo::run_content_process(token); - } - if opts::get().is_printing_version { println!("{}", servo_version()); process::exit(0); From 053fa5036e381aef38c69ba8eb1924a0f0e0b4aa Mon Sep 17 00:00:00 2001 From: elias Date: Thu, 21 Mar 2019 13:01:53 -0500 Subject: [PATCH 03/11] remove multiprocessor configuration from global Opt struct entirely --- components/config/opts.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index f161818e9e6c..9f227ca2c1cf 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -135,9 +135,6 @@ pub struct Opts { /// An optional string allowing the user agent to be set for testing. pub user_agent: Cow<'static, str>, - /// Whether we're running in multiprocess mode. - pub multiprocess: bool, - /// Whether we're running inside the sandbox. pub sandbox: bool, @@ -575,7 +572,6 @@ pub fn default_opts() -> Opts { webdriver_port: None, initial_window_size: TypedSize2D::new(1024, 740), user_agent: default_user_agent_string(DEFAULT_USER_AGENT).into(), - multiprocess: false, random_pipeline_closure_probability: None, random_pipeline_closure_seed: None, sandbox: false, @@ -1009,7 +1005,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Re webdriver_port: webdriver_port, initial_window_size: initial_window_size, user_agent: user_agent, - multiprocess: opt_match.opt_present("M"), sandbox: opt_match.opt_present("S"), random_pipeline_closure_probability: random_pipeline_closure_probability, random_pipeline_closure_seed: random_pipeline_closure_seed, @@ -1087,7 +1082,6 @@ lazy_static! { } pub fn set_options(opts: Opts) { - MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst); *OPTIONS.write().unwrap() = opts; } From ea725194803e921cf86c82cce1753f37ce075080 Mon Sep 17 00:00:00 2001 From: elias Date: Tue, 19 Mar 2019 17:28:01 -0500 Subject: [PATCH 04/11] initial reshuffling of opts generation for #23009 --- components/config/opts.rs | 27 ++++++++++----------------- ports/glutin/Cargo.toml | 1 + 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index 49fa0fee3447..18cdc71ae0fe 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -613,10 +613,9 @@ pub fn default_opts() -> Opts { } } -pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { - let (app_name, args) = args.split_first().unwrap(); +fn create_global_opts(mut opts: getopts::Options) -> Options { + - let mut opts = Options::new(); opts.optflag("c", "cpu", "CPU painting"); opts.optflag("g", "gpu", "GPU painting"); opts.optopt("o", "output", "Output file", "output.png"); @@ -672,7 +671,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "Shaders will be loaded from the specified directory instead of using the builtin ones.", "", ); - opts.optflag("z", "headless", "Headless mode"); opts.optflag( "", "angle", @@ -713,7 +711,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "Set custom user agent string (or ios / android / desktop for platform default)", "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)", ); - opts.optflag("M", "multiprocess", "Run in multiprocess mode"); opts.optflag("S", "sandbox", "Run in a sandbox if multiprocess"); opts.optopt( "", @@ -727,12 +724,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "A fixed seed for repeatbility of random pipeline closure.", "", ); - opts.optmulti( - "Z", - "debug", - "A comma-separated string of debug options. Pass help to show available options.", - "", - ); opts.optflag("h", "help", "Print this message"); opts.optopt( "", @@ -746,12 +737,6 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { "Path to find SSL certificates", "/home/servo/resources/certs", ); - opts.optopt( - "", - "content-process", - "Run as a content process and connect to the given pipe", - "servo-ipc-channel.abcdefg", - ); opts.optmulti( "", "pref", @@ -779,6 +764,14 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { opts.optopt("", "profiler-db-name", "Profiler database name", ""); opts.optflag("", "print-pwm", "Print Progressive Web Metrics"); + opts +} + +pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentParsingResult { + let (app_name, args) = args.split_first().unwrap(); + + let opts = create_global_opts(opts); + let opt_match = match opts.parse(args) { Ok(m) => m, Err(f) => args_fail(&f.to_string()), diff --git a/ports/glutin/Cargo.toml b/ports/glutin/Cargo.toml index 2a6f1302d22c..a5b15956ff41 100644 --- a/ports/glutin/Cargo.toml +++ b/ports/glutin/Cargo.toml @@ -43,6 +43,7 @@ webgl_backtrace = ["libservo/webgl_backtrace"] webrender_debugger = ["libservo/webrender_debugger"] [target.'cfg(not(target_os = "android"))'.dependencies] +getopts = "0.2.18" backtrace = "0.3" bitflags = "1.0" crossbeam-channel = "0.3" From 2affc71a9d12d8b9a1584137be10f437692e9a32 Mon Sep 17 00:00:00 2001 From: elias Date: Thu, 21 Mar 2019 11:19:11 -0500 Subject: [PATCH 05/11] moved multiprocess flag out of opts.rs back into gluten embedder, changed return type of from_cmdline_args to getopts::Result --- components/config/opts.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index 18cdc71ae0fe..f0aad94ebd2f 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -7,7 +7,7 @@ use crate::prefs::{self, PrefValue}; use euclid::TypedSize2D; -use getopts::Options; +use getopts::{Options}; use servo_geometry::DeviceIndependentPixel; use servo_url::ServoUrl; use std::borrow::Cow; @@ -490,13 +490,16 @@ pub enum OutputOptions { Stdout(f64), } -fn args_fail(msg: &str) -> ! { +pub fn args_fail(msg: &str) -> ! { writeln!(io::stderr(), "{}", msg).unwrap(); process::exit(1) } static MULTIPROCESS: AtomicBool = AtomicBool::new(false); +#[inline] +pub fn set_multiprocess(b: bool, ord: Ordering) { MULTIPROCESS.store(b, ord) } + #[inline] pub fn multiprocess() -> bool { MULTIPROCESS.load(Ordering::Relaxed) @@ -621,6 +624,15 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { opts.optopt("o", "output", "Output file", "output.png"); opts.optopt("s", "size", "Size of tiles", "512"); opts.optopt("", "device-pixel-ratio", "Device pixels per px", ""); + // one thing at a time + opts.optflag("z", "headless", "Headless mode"); + opts.optmulti( + "Z", + "debug", + "A comma-separated string of debug options. Pass help to show available options.", + "", + ); + opts.optflagopt( "p", "profile", @@ -767,7 +779,7 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { opts } -pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentParsingResult { +pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Result { let (app_name, args) = args.split_first().unwrap(); let opts = create_global_opts(opts); @@ -782,13 +794,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar process::exit(0); }; - // If this is the content process, we'll receive the real options over IPC. So just fill in - // some dummy options for now. - if let Some(content_process) = opt_match.opt_str("content-process") { - MULTIPROCESS.store(true, Ordering::SeqCst); - return ArgumentParsingResult::ContentProcess(content_process); - } - let mut debug_options = DebugOptions::default(); for debug_string in opt_match.opt_strs("Z") { @@ -952,10 +957,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar None => TypedSize2D::new(1024, 740), }; - if opt_match.opt_present("M") { - MULTIPROCESS.store(true, Ordering::SeqCst) - } - let user_agent = match opt_match.opt_str("u") { Some(ref ua) if ua == "ios" => default_user_agent_string(UserAgent::iOS).into(), Some(ref ua) if ua == "android" => default_user_agent_string(UserAgent::Android).into(), @@ -987,7 +988,7 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar let is_printing_version = opt_match.opt_present("v") || opt_match.opt_present("version"); - let opts = Opts { + let mut opts = Opts { is_running_problem_test: is_running_problem_test, url: url_opt, tile_size: tile_size, @@ -1067,7 +1068,8 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> ArgumentPar set_pref!(layout.threads, layout_threads as i64); } - ArgumentParsingResult::ChromeProcess + // ArgumentParsingResult::ChromeProcess + Ok(opt_match) } pub enum ArgumentParsingResult { From 45341b2b765722e7dad19c2caf9b5c3951fe7d3d Mon Sep 17 00:00:00 2001 From: elias Date: Thu, 21 Mar 2019 13:01:53 -0500 Subject: [PATCH 06/11] remove multiprocessor configuration from global Opt struct entirely --- components/config/opts.rs | 6 ------ ports/glutin/Cargo.toml | 1 - 2 files changed, 7 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index f0aad94ebd2f..ea250e033d7e 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -140,9 +140,6 @@ pub struct Opts { /// An optional string allowing the user agent to be set for testing. pub user_agent: Cow<'static, str>, - /// Whether we're running in multiprocess mode. - pub multiprocess: bool, - /// Whether we're running inside the sandbox. pub sandbox: bool, @@ -581,7 +578,6 @@ pub fn default_opts() -> Opts { webdriver_port: None, initial_window_size: TypedSize2D::new(1024, 740), user_agent: default_user_agent_string(DEFAULT_USER_AGENT).into(), - multiprocess: false, random_pipeline_closure_probability: None, random_pipeline_closure_seed: None, sandbox: false, @@ -1015,7 +1011,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Re webdriver_port: webdriver_port, initial_window_size: initial_window_size, user_agent: user_agent, - multiprocess: opt_match.opt_present("M"), sandbox: opt_match.opt_present("S"), random_pipeline_closure_probability: random_pipeline_closure_probability, random_pipeline_closure_seed: random_pipeline_closure_seed, @@ -1085,7 +1080,6 @@ lazy_static! { } pub fn set_options(opts: Opts) { - MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst); *OPTIONS.write().unwrap() = opts; } diff --git a/ports/glutin/Cargo.toml b/ports/glutin/Cargo.toml index a5b15956ff41..2a6f1302d22c 100644 --- a/ports/glutin/Cargo.toml +++ b/ports/glutin/Cargo.toml @@ -43,7 +43,6 @@ webgl_backtrace = ["libservo/webgl_backtrace"] webrender_debugger = ["libservo/webrender_debugger"] [target.'cfg(not(target_os = "android"))'.dependencies] -getopts = "0.2.18" backtrace = "0.3" bitflags = "1.0" crossbeam-channel = "0.3" From 141345590ee5a72093d1077f7e8df0b775d0f0c0 Mon Sep 17 00:00:00 2001 From: elias garcia Date: Sun, 30 Jun 2019 15:15:08 -0500 Subject: [PATCH 07/11] enable glutin to handle its own CLI Opt logic, starting with multiprocess. servo/lib.rs now uses opt::multiprocess() in Servo::new() --- components/servo/lib.rs | 2 +- ports/glutin/Cargo.toml | 1 + ports/glutin/main2.rs | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 0e5ccf2c2ad9..80c71a958379 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -203,7 +203,7 @@ where // Global configuration options, parsed from the command line. let opts = opts::get(); - if !opts.multiprocess { + if !opts::multiprocess() { ServoMedia::init::(); } diff --git a/ports/glutin/Cargo.toml b/ports/glutin/Cargo.toml index 2a6f1302d22c..09b6d0c25001 100644 --- a/ports/glutin/Cargo.toml +++ b/ports/glutin/Cargo.toml @@ -47,6 +47,7 @@ backtrace = "0.3" bitflags = "1.0" crossbeam-channel = "0.3" euclid = "0.19" +getopts = "0.2.11" gleam = "0.6" glutin = "0.21.0" keyboard-types = "0.4.3" diff --git a/ports/glutin/main2.rs b/ports/glutin/main2.rs index 496c0515e19f..10774b44d373 100644 --- a/ports/glutin/main2.rs +++ b/ports/glutin/main2.rs @@ -24,11 +24,13 @@ mod window_trait; use app::App; use backtrace::Backtrace; -use servo::config::opts::{self, ArgumentParsingResult}; +use getopts::Options; +use servo::config::opts::{self, ArgumentParsingResult, args_fail, set_multiprocess}; use servo::config::servo_version; use std::env; use std::panic; use std::process; +use std::sync::atomic::Ordering; use std::thread; pub mod platform { @@ -72,6 +74,14 @@ fn install_crash_handler() { signal!(Sig::BUS, handler); // handle invalid memory access } +fn create_gluten_opts() -> Options { + let mut opts = Options::new(); + opts.optflag("M", "multiprocess", "Run in multiprocess mode"); +// opts.optflag("z", "headless", "Headless mode"); + + opts +} + pub fn main() { install_crash_handler(); @@ -79,18 +89,30 @@ pub fn main() { // Parse the command line options and store them globally let args: Vec = env::args().collect(); - let opts_result = opts::from_cmdline_args(&args); + // Get Glutin only config options to pass to global. + let opts = create_gluten_opts(); + // Get our Opts result to config remaining, Glutin specific, cli opts passed. + let opt_result = opts::from_cmdline_args(opts ,&args); + + let opt_match = match opt_result { + Ok(o) => o, + Err(f) => args_fail(&f.to_string()), + }; - let content_process_token = if let ArgumentParsingResult::ContentProcess(token) = opts_result { - Some(token) + if let Some(token) = opt_match.opt_str("content-process") { + return servo::run_content_process(token); } else { if opts::get().is_running_problem_test && env::var("RUST_LOG").is_err() { env::set_var("RUST_LOG", "compositing::constellation"); } - None + () }; + if opt_match.opt_present("M") { + set_multiprocess(true, Ordering::SeqCst); + } + // TODO: once log-panics is released, can this be replaced by // log_panics::init()? panic::set_hook(Box::new(|info| { @@ -122,9 +144,9 @@ pub fn main() { error!("{}", msg); })); - if let Some(token) = content_process_token { - return servo::run_content_process(token); - } +// if let Some(token) = content_process_token { +// return servo::run_content_process(token); +// } if opts::get().is_printing_version { println!("{}", servo_version()); From 39c447426301e3b8e75583a37ea718e12f698781 Mon Sep 17 00:00:00 2001 From: elias garcia Date: Sun, 30 Jun 2019 16:13:54 -0500 Subject: [PATCH 08/11] removed disable-vsync option from default Opt, split logic between static value and gluten/main2.rs --- components/config/opts.rs | 25 +++++++++++++++---------- ports/glutin/main2.rs | 11 +++++++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index ea250e033d7e..88a806faeee0 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -311,9 +311,6 @@ pub struct DebugOptions { /// Load web fonts synchronously to avoid non-deterministic network-driven reflows. pub load_webfonts_synchronously: bool, - /// Disable vsync in the compositor - pub disable_vsync: bool, - /// Show webrender profiling stats on screen. pub webrender_stats: bool, @@ -365,7 +362,6 @@ impl DebugOptions { "replace-surrogates" => self.replace_surrogates = true, "gc-profile" => self.gc_profile = true, "load-webfonts-synchronously" => self.load_webfonts_synchronously = true, - "disable-vsync" => self.disable_vsync = true, "wr-stats" => self.webrender_stats = true, "wr-record" => self.webrender_record = true, "wr-no-batch" => self.webrender_disable_batch = true, @@ -459,10 +455,6 @@ fn print_debug_usage(app: &str) -> ! { "load-webfonts-synchronously", "Load web fonts synchronously to avoid non-deterministic network-driven reflows", ); - print_option( - "disable-vsync", - "Disable vsync mode in the compositor to allow profiling at more than monitor refresh rate", - ); print_option("wr-stats", "Show WebRender profiler on screen."); print_option("msaa", "Use multisample antialiasing in WebRender."); print_option("full-backtraces", "Print full backtraces for all errors"); @@ -494,14 +486,24 @@ pub fn args_fail(msg: &str) -> ! { static MULTIPROCESS: AtomicBool = AtomicBool::new(false); +static VSYNC: AtomicBool = AtomicBool::new(true); + #[inline] pub fn set_multiprocess(b: bool, ord: Ordering) { MULTIPROCESS.store(b, ord) } +#[inline] +pub fn set_vsync(b: bool, ord: Ordering) { VSYNC.store(b, ord) } + #[inline] pub fn multiprocess() -> bool { MULTIPROCESS.load(Ordering::Relaxed) } +#[inline] +fn disable_vsync() -> bool { + VSYNC.load(Ordering::Relaxed) +} + enum UserAgent { Desktop, Android, @@ -620,7 +622,8 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { opts.optopt("o", "output", "Output file", "output.png"); opts.optopt("s", "size", "Size of tiles", "512"); opts.optopt("", "device-pixel-ratio", "Device pixels per px", ""); - // one thing at a time + + // TODO: Remove -z, e.g. --headlessone from global. opts.optflag("z", "headless", "Headless mode"); opts.optmulti( "Z", @@ -679,6 +682,8 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { "Shaders will be loaded from the specified directory instead of using the builtin ones.", "", ); + + // TODO: Remove --angle from global. opts.optflag( "", "angle", @@ -1030,7 +1035,7 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Re convert_mouse_to_touch: debug_options.convert_mouse_to_touch, exit_after_load: opt_match.opt_present("x"), no_native_titlebar: do_not_use_native_titlebar, - enable_vsync: !debug_options.disable_vsync, + enable_vsync: !disable_vsync(), webrender_stats: debug_options.webrender_stats, use_msaa: debug_options.use_msaa, config_dir: opt_match.opt_str("config-dir").map(Into::into), diff --git a/ports/glutin/main2.rs b/ports/glutin/main2.rs index 10774b44d373..c3443ce50b07 100644 --- a/ports/glutin/main2.rs +++ b/ports/glutin/main2.rs @@ -25,7 +25,7 @@ mod window_trait; use app::App; use backtrace::Backtrace; use getopts::Options; -use servo::config::opts::{self, ArgumentParsingResult, args_fail, set_multiprocess}; +use servo::config::opts::{self, ArgumentParsingResult, args_fail, set_multiprocess, set_vsync}; use servo::config::servo_version; use std::env; use std::panic; @@ -77,7 +77,10 @@ fn install_crash_handler() { fn create_gluten_opts() -> Options { let mut opts = Options::new(); opts.optflag("M", "multiprocess", "Run in multiprocess mode"); -// opts.optflag("z", "headless", "Headless mode"); + opts.optflag("", + "disable-vsync", + "Disable vsync mode in the compositor to allow profiling at more than monitor refresh rate"); + // opts.optflag("z", "headless", "Headless mode"); opts } @@ -113,6 +116,10 @@ pub fn main() { set_multiprocess(true, Ordering::SeqCst); } + if opt_match.opt_present("disable-vsync") { + set_vsync(false, Ordering::SeqCst); + } + // TODO: once log-panics is released, can this be replaced by // log_panics::init()? panic::set_hook(Box::new(|info| { From b5570ab227af361852cf1951fd79d6d0b1c62009 Mon Sep 17 00:00:00 2001 From: elias garcia Date: Sat, 6 Jul 2019 11:48:03 -0500 Subject: [PATCH 09/11] re-added content-process, accidentally removed --- components/config/opts.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/config/opts.rs b/components/config/opts.rs index 88a806faeee0..e1dea36f6276 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -750,6 +750,12 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { "Path to find SSL certificates", "/home/servo/resources/certs", ); + opts.optopt( + "", + "content-process", + "Run as a content process and connect to the given pipe", + "servo-ipc-channel.abcdefg", + ); opts.optmulti( "", "pref", From 0f82d2b2eb6da445b987742502a40d4b642c4c28 Mon Sep 17 00:00:00 2001 From: elias garcia Date: Sat, 6 Jul 2019 12:35:36 -0500 Subject: [PATCH 10/11] removed vsync from global opts --- components/config/opts.rs | 8 ++------ ports/glutin/headed_window.rs | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index e1dea36f6276..7371799bbb7a 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -185,7 +185,7 @@ pub struct Opts { pub no_native_titlebar: bool, /// Enable vsync in the compositor - pub enable_vsync: bool, + // pub enable_vsync: bool, /// True to show webrender profiling stats on screen. pub webrender_stats: bool, @@ -500,9 +500,7 @@ pub fn multiprocess() -> bool { } #[inline] -fn disable_vsync() -> bool { - VSYNC.load(Ordering::Relaxed) -} +pub fn enable_vsync() -> bool { VSYNC.load(Ordering::Relaxed) } enum UserAgent { Desktop, @@ -596,7 +594,6 @@ pub fn default_opts() -> Opts { convert_mouse_to_touch: false, exit_after_load: false, no_native_titlebar: false, - enable_vsync: true, webrender_stats: false, use_msaa: false, config_dir: None, @@ -1041,7 +1038,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Re convert_mouse_to_touch: debug_options.convert_mouse_to_touch, exit_after_load: opt_match.opt_present("x"), no_native_titlebar: do_not_use_native_titlebar, - enable_vsync: !disable_vsync(), webrender_stats: debug_options.webrender_stats, use_msaa: debug_options.use_msaa, config_dir: opt_match.opt_str("config-dir").map(Into::into), diff --git a/ports/glutin/headed_window.rs b/ports/glutin/headed_window.rs index 3026170645ee..dff026cd3d62 100644 --- a/ports/glutin/headed_window.rs +++ b/ports/glutin/headed_window.rs @@ -109,7 +109,7 @@ impl Window { let mut context_builder = glutin::ContextBuilder::new() .with_gl(app::gl_version()) - .with_vsync(opts.enable_vsync); + .with_vsync(opts::enable_vsync()); if opts.use_msaa { context_builder = context_builder.with_multisampling(MULTISAMPLES) From c7db9b35059f4afd38d050b9a15ddb7c180f231c Mon Sep 17 00:00:00 2001 From: elias garcia Date: Sat, 6 Jul 2019 13:08:17 -0500 Subject: [PATCH 11/11] handled angle flag, removed from global --- components/config/opts.rs | 22 ++++++++++------------ ports/glutin/app.rs | 2 +- ports/glutin/main2.rs | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/components/config/opts.rs b/components/config/opts.rs index 7371799bbb7a..4710edfe77d8 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -78,8 +78,7 @@ pub struct Opts { pub headless: bool, - /// Use ANGLE to create the GL context (Windows-only). - pub angle: bool, + // pub angle: bool, /// True to exit on thread failure instead of displaying about:failure. pub hard_fail: bool, @@ -488,12 +487,17 @@ static MULTIPROCESS: AtomicBool = AtomicBool::new(false); static VSYNC: AtomicBool = AtomicBool::new(true); +static ANGLE: AtomicBool = AtomicBool::new(false); + #[inline] pub fn set_multiprocess(b: bool, ord: Ordering) { MULTIPROCESS.store(b, ord) } #[inline] pub fn set_vsync(b: bool, ord: Ordering) { VSYNC.store(b, ord) } +#[inline] +pub fn set_angle(b: bool, ord: Ordering) { ANGLE.store(b, ord) } + #[inline] pub fn multiprocess() -> bool { MULTIPROCESS.load(Ordering::Relaxed) @@ -502,6 +506,9 @@ pub fn multiprocess() -> bool { #[inline] pub fn enable_vsync() -> bool { VSYNC.load(Ordering::Relaxed) } +#[inline] +pub fn angle() -> bool { ANGLE.load(Ordering::Relaxed) } + enum UserAgent { Desktop, Android, @@ -564,7 +571,7 @@ pub fn default_opts() -> Opts { gc_profile: false, load_webfonts_synchronously: false, headless: false, - angle: false, + // angle: false, hard_fail: true, bubble_inline_sizes_separately: false, show_debug_fragment_borders: false, @@ -679,13 +686,6 @@ fn create_global_opts(mut opts: getopts::Options) -> Options { "Shaders will be loaded from the specified directory instead of using the builtin ones.", "", ); - - // TODO: Remove --angle from global. - opts.optflag( - "", - "angle", - "Use ANGLE to create a GL context (Windows-only)", - ); opts.optflag( "f", "hard-fail", @@ -1008,7 +1008,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Re gc_profile: debug_options.gc_profile, load_webfonts_synchronously: debug_options.load_webfonts_synchronously, headless: opt_match.opt_present("z"), - angle: opt_match.opt_present("angle"), hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"), bubble_inline_sizes_separately: bubble_inline_sizes_separately, profile_script_events: debug_options.profile_script_events, @@ -1070,7 +1069,6 @@ pub fn from_cmdline_args(opts: getopts::Options, args: &[String]) -> getopts::Re set_pref!(layout.threads, layout_threads as i64); } - // ArgumentParsingResult::ChromeProcess Ok(opt_match) } diff --git a/ports/glutin/app.rs b/ports/glutin/app.rs index 46e84bdcc70b..fc3ce09c310b 100644 --- a/ports/glutin/app.rs +++ b/ports/glutin/app.rs @@ -185,7 +185,7 @@ fn get_default_url() -> ServoUrl { } pub fn gl_version() -> glutin::GlRequest { - if opts::get().angle { + if opts::angle() { glutin::GlRequest::Specific(glutin::Api::OpenGlEs, (3, 0)) } else { glutin::GlRequest::GlThenGles { diff --git a/ports/glutin/main2.rs b/ports/glutin/main2.rs index c3443ce50b07..1c577b51516c 100644 --- a/ports/glutin/main2.rs +++ b/ports/glutin/main2.rs @@ -25,7 +25,8 @@ mod window_trait; use app::App; use backtrace::Backtrace; use getopts::Options; -use servo::config::opts::{self, ArgumentParsingResult, args_fail, set_multiprocess, set_vsync}; +use servo::config::opts::{self, ArgumentParsingResult, args_fail, set_multiprocess, set_vsync, + set_angle}; use servo::config::servo_version; use std::env; use std::panic; @@ -80,8 +81,14 @@ fn create_gluten_opts() -> Options { opts.optflag("", "disable-vsync", "Disable vsync mode in the compositor to allow profiling at more than monitor refresh rate"); - // opts.optflag("z", "headless", "Headless mode"); + // opts.optflag("z", "headless", "Headless mode"); + /// Use ANGLE to create the GL context (Windows-only). + opts.optflag( + "", + "angle", + "Use ANGLE to create a GL context (Windows-only)", + ); opts } @@ -120,6 +127,10 @@ pub fn main() { set_vsync(false, Ordering::SeqCst); } + if opt_match.opt_present("angle") { + set_angle(true, Ordering::SeqCst); + } + // TODO: once log-panics is released, can this be replaced by // log_panics::init()? panic::set_hook(Box::new(|info| {