mirror of
https://github.com/servo/servo.git
synced 2025-08-15 02:15:33 +01:00
Allow prefs to be overridden from a file and set WPT-specific prefs from file (#33163)
* Allow prefs to be passed in from a separate file Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add wpt-prefs.json for setting WPT-specific prefs Signed-off-by: Daniel Adams <msub2official@gmail.com> * fix argument to read_prefs_file Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update test_parse_pref test Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add line in executorservo.py to read from wpt-prefs.json Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update MANIFEST.json Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update expectations Signed-off-by: Daniel Adams <msub2official@gmail.com> * Disable dom.webxr.test for interfaces test Signed-off-by: Daniel Adams <msub2official@gmail.com> --------- Signed-off-by: Daniel Adams <msub2official@gmail.com>
This commit is contained in:
parent
2db9032e72
commit
e85491b5fc
10 changed files with 36 additions and 15 deletions
|
@ -45,6 +45,12 @@ pub fn main() {
|
|||
"A preference to set to disable",
|
||||
"dom.webgpu.enabled=false",
|
||||
);
|
||||
opts.optmulti(
|
||||
"",
|
||||
"prefs-file",
|
||||
"Load in additional prefs from a file.",
|
||||
"--prefs-file /path/to/prefs.json",
|
||||
);
|
||||
|
||||
let opts_matches;
|
||||
let content_process_token;
|
||||
|
|
|
@ -22,15 +22,17 @@ pub fn register_user_prefs(opts_matches: &Matches) {
|
|||
.filter(|path| path.exists());
|
||||
|
||||
let mut userprefs = if let Some(path) = user_prefs_path {
|
||||
let mut file = File::open(path).expect("Error opening user prefs");
|
||||
let mut txt = String::new();
|
||||
file.read_to_string(&mut txt)
|
||||
.expect("Can't read user prefs file");
|
||||
prefs::read_prefs_map(&txt).expect("Can't parse user prefs file")
|
||||
read_prefs_file(path.to_str().expect("Failed to read user prefs"))
|
||||
} else {
|
||||
HashMap::new()
|
||||
};
|
||||
|
||||
let prefs_from_files: Vec<HashMap<String, PrefValue>> = opts_matches
|
||||
.opt_strs("prefs-file")
|
||||
.iter()
|
||||
.map(|path| read_prefs_file(path))
|
||||
.collect();
|
||||
|
||||
let argprefs: HashMap<String, PrefValue> = opts_matches
|
||||
.opt_strs("pref")
|
||||
.iter()
|
||||
|
@ -54,16 +56,30 @@ pub fn register_user_prefs(opts_matches: &Matches) {
|
|||
})
|
||||
.collect();
|
||||
|
||||
// --pref overrides user prefs.json
|
||||
// Apply --prefs-file prefs first
|
||||
for prefs in prefs_from_files {
|
||||
userprefs.extend(prefs);
|
||||
}
|
||||
|
||||
// Then apply individually passed prefs from --pref
|
||||
userprefs.extend(argprefs);
|
||||
|
||||
prefs::add_user_prefs(userprefs);
|
||||
}
|
||||
|
||||
fn read_prefs_file(path: &str) -> HashMap<String, PrefValue> {
|
||||
let mut file = File::open(path).expect("Error opening user prefs");
|
||||
let mut txt = String::new();
|
||||
file.read_to_string(&mut txt)
|
||||
.expect("Can't read user prefs file");
|
||||
prefs::read_prefs_map(&txt).expect("Can't parse user prefs file")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_parse_pref(arg: &str) {
|
||||
let mut opts = getopts::Options::new();
|
||||
opts.optmulti("", "pref", "", "");
|
||||
opts.optmulti("", "prefs-file", "", "");
|
||||
let args = vec!["servo".to_string(), "--pref".to_string(), arg.to_string()];
|
||||
let matches = match opts::from_cmdline_args(opts, &args) {
|
||||
opts::ArgumentParsingResult::ContentProcess(m, _) => m,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue