Files
tubestation/servo/components/util/resource_files.rs
Simon Sapin a08ac37856 servo: Merge #3601 - Read user-agent.css at run time. Fix #3516 (from SimonSapin:runtime-ua-stylesheet); r=jdm
When we want to use Servo binaries outside of their `target` build directory, `./resources` is what we’ll need to ship with them.

r? @jdm

Source-Repo: https://github.com/servo/servo
Source-Revision: 8312fde154768c4a5ce133a1aaaf1293529a5558
2014-10-08 00:42:36 -06:00

31 lines
904 B
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::io::{File, IoResult};
use std::io::fs::PathExtensions;
use std::os;
use std::path::Path;
pub fn resources_dir_path() -> Path {
// FIXME: Find a way to not rely on the executable being under `<servo source>/target`.
let mut path = os::self_exe_path().expect("can't get exe path");
path.pop();
path.push("resources");
if !path.is_dir() {
path.pop();
path.pop();
path.push("resources");
}
path
}
pub fn read_resource_file(relative_path_components: &[&str]) -> IoResult<Vec<u8>> {
let mut path = resources_dir_path();
path.push_many(relative_path_components);
let mut file = try!(File::open(&path));
file.read_to_end()
}