Auto merge of #5992 - zmike:random-fixups, r=larsbergstrom

Attempt to not panic as much if the resources/ dir is not where it's expected to be.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5992)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-05-12 13:26:22 -05:00
commit 76225bdccb
3 changed files with 44 additions and 27 deletions

View file

@ -9,6 +9,7 @@ use selectors::matching::{SelectorMap, Rule};
use selectors::matching::DeclarationBlock as GenericDeclarationBlock;
use selectors::parser::PseudoElement;
use selectors::tree::TNode;
use std::process;
use util::resource_files::read_resource_file;
use util::smallvec::VecLike;
@ -59,13 +60,21 @@ impl Stylist {
// FIXME: presentational-hints.css should be at author origin with zero specificity.
// (Does it make a difference?)
for &filename in ["user-agent.css", "servo.css", "presentational-hints.css"].iter() {
let ua_stylesheet = Stylesheet::from_bytes(
&read_resource_file(&[filename]).unwrap(),
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent);
stylist.add_stylesheet(ua_stylesheet);
match read_resource_file(&[filename]) {
Ok(res) => {
let ua_stylesheet = Stylesheet::from_bytes(
&res,
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent);
stylist.add_stylesheet(ua_stylesheet);
}
Err(..) => {
error!("Stylist::new() failed at loading {}!", filename);
process::exit(1);
}
}
}
stylist
}
@ -154,12 +163,20 @@ impl Stylist {
}
pub fn add_quirks_mode_stylesheet(&mut self) {
self.add_stylesheet(Stylesheet::from_bytes(
&read_resource_file(&["quirks-mode.css"]).unwrap(),
Url::parse("chrome:///quirks-mode.css").unwrap(),
None,
None,
Origin::UserAgent))
match read_resource_file(&["quirks-mode.css"]) {
Ok(res) => {
self.add_stylesheet(Stylesheet::from_bytes(
&res,
Url::parse("chrome:///quirks-mode.css").unwrap(),
None,
None,
Origin::UserAgent));
}
Err(..) => {
error!("Stylist::add_quirks_mode_stylesheet() failed at loading 'quirks-mode.css'!");
process::exit(1);
}
}
}
pub fn add_stylesheet(&mut self, stylesheet: Stylesheet) {

View file

@ -25,14 +25,23 @@ pub fn resources_dir_path() -> PathBuf {
// or `<servo source>/components/servo/target/release`.
let mut path = env::current_exe().ok().expect("can't get exe path");
path.pop();
path.pop();
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
if !path.is_dir() { // resources dir not in same dir as exe?
path.pop();
path.pop();
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
path.pop();
path.pop();
path.push("resources");
}
}
}
path
}