mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 13:48:23 +02:00
<!-- Please describe your changes on the following line: --> This PR removes the `util` crate. * Replaced the `spawn_named` and `clamp` functions by appropriate uses of `std:🧵:Builder::spawn`, `std::cmp::min` and `std::cmp::max`. * Moved `opts`, `prefs` and `resource_files` into a new `config` crate. * Moved `remutex` and `geometry` into their own crates. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes do not require tests because they are refactorings <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 4eb653817f87e5fb47de34356f558eb76ecbca9f --HG-- rename : servo/components/util/Cargo.toml => servo/components/config/Cargo.toml rename : servo/components/util/basedir.rs => servo/components/config/basedir.rs rename : servo/components/util/lib.rs => servo/components/config/lib.rs rename : servo/components/util/opts.rs => servo/components/config/opts.rs rename : servo/components/util/prefs.rs => servo/components/config/prefs.rs rename : servo/components/util/resource_files.rs => servo/components/config/resource_files.rs rename : servo/components/util/geometry.rs => servo/components/geometry/lib.rs rename : servo/components/util/remutex.rs => servo/components/remutex/lib.rs rename : servo/tests/unit/util/lib.rs => servo/tests/unit/servo_config/lib.rs rename : servo/tests/unit/util/opts.rs => servo/tests/unit/servo_config/opts.rs rename : servo/tests/unit/util/prefs.rs => servo/tests/unit/servo_config/prefs.rs rename : servo/tests/unit/util/remutex.rs => servo/tests/unit/servo_remutex/lib.rs
67 lines
1.9 KiB
Rust
67 lines
1.9 KiB
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/. */
|
|
|
|
#[cfg(not(target_os = "android"))]
|
|
use std::env;
|
|
use std::fs::File;
|
|
use std::io::{self, Read};
|
|
use std::path::{Path, PathBuf};
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
lazy_static! {
|
|
static ref CMD_RESOURCE_DIR: Arc<Mutex<Option<String>>> = {
|
|
Arc::new(Mutex::new(None))
|
|
};
|
|
}
|
|
|
|
pub fn set_resources_path(path: Option<String>) {
|
|
let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
|
|
*dir = path;
|
|
}
|
|
|
|
#[cfg(target_os = "android")]
|
|
pub fn resources_dir_path() -> io::Result<PathBuf> {
|
|
Ok(PathBuf::from("/sdcard/servo/"))
|
|
}
|
|
|
|
#[cfg(not(target_os = "android"))]
|
|
pub fn resources_dir_path() -> io::Result<PathBuf> {
|
|
let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
|
|
|
|
if let Some(ref path) = *dir {
|
|
return Ok(PathBuf::from(path));
|
|
}
|
|
|
|
// FIXME: Find a way to not rely on the executable being
|
|
// under `<servo source>[/$target_triple]/target/debug`
|
|
// or `<servo source>[/$target_triple]/target/release`.
|
|
let mut path = try!(env::current_exe());
|
|
// Follow symlink
|
|
path = try!(path.canonicalize());
|
|
|
|
while path.pop() {
|
|
path.push("resources");
|
|
if path.is_dir() {
|
|
break;
|
|
}
|
|
path.pop();
|
|
// Check for Resources on mac when using a case sensitive filesystem.
|
|
path.push("Resources");
|
|
if path.is_dir() {
|
|
break;
|
|
}
|
|
path.pop();
|
|
}
|
|
*dir = Some(path.to_str().unwrap().to_owned());
|
|
Ok(path)
|
|
}
|
|
|
|
pub fn read_resource_file<P: AsRef<Path>>(relative_path: P) -> io::Result<Vec<u8>> {
|
|
let mut path = try!(resources_dir_path());
|
|
path.push(relative_path);
|
|
let mut file = try!(File::open(&path));
|
|
let mut data = Vec::new();
|
|
try!(file.read_to_end(&mut data));
|
|
Ok(data)
|
|
}
|