Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit how the Android port works. #20912

Merged
merged 6 commits into from Jul 31, 2018

new android port: introduce a simple servo library

  • Loading branch information
paulrouget committed Jul 31, 2018
commit baf6635a4c96f80452d98980d38bf1bd041705e8

Some generated files are not rendered by default. Learn more.

@@ -1,10 +1,12 @@
[workspace]
members = [
"ports/servo",
"ports/libsimpleservo/",
"tests/unit/*",
]
default-members = [
"ports/servo",
"ports/libsimpleservo/",
"tests/unit/*",
]
exclude = [".cargo"]
@@ -30,6 +30,3 @@ embedder_traits = { path = "../embedder_traits", features = ["tests"] }

[target.'cfg(not(target_os = "android"))'.dependencies]
dirs = "1.0"

[target.'cfg(target_os = "android")'.dependencies]
android_injected_glue = "0.2"
@@ -6,41 +6,33 @@
//! For linux based platforms, it uses the XDG base directory spec but provides
//! similar abstractions for non-linux platforms.

#[cfg(target_os = "android")]
use android_injected_glue;
#[cfg(target_os = "android")]
use std::ffi::CStr;
use std::path::PathBuf;

#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
pub fn default_config_dir() -> PathBuf {
pub fn default_config_dir() -> Option<PathBuf> {
let mut config_dir = ::dirs::config_dir().unwrap();
config_dir.push("servo");
config_dir.push("default");
config_dir
Some(config_dir)
}

#[cfg(target_os = "android")]
#[allow(unsafe_code)]
pub fn default_config_dir() -> PathBuf {
let dir = unsafe {
CStr::from_ptr((*android_injected_glue::get_app().activity).externalDataPath)
};
PathBuf::from(dir.to_str().unwrap())
pub fn default_config_dir() -> Option<PathBuf> {
None
}

#[cfg(target_os = "macos")]
pub fn default_config_dir() -> PathBuf {
pub fn default_config_dir() -> Option<PathBuf> {
// FIXME: use `config_dir()` ($HOME/Library/Preferences)
// instead of `data_dir()` ($HOME/Library/Application Support) ?
let mut config_dir = ::dirs::data_dir().unwrap();
config_dir.push("Servo");
config_dir
Some(config_dir)
}

#[cfg(target_os = "windows")]
pub fn default_config_dir() -> PathBuf {
pub fn default_config_dir() -> Option<PathBuf> {
let mut config_dir = ::dirs::config_dir().unwrap();
config_dir.push("Servo");
config_dir
Some(config_dir)
}
@@ -4,8 +4,6 @@

#![deny(unsafe_code)]

#[cfg(target_os = "android")]
extern crate android_injected_glue;
#[cfg(not(target_os = "android"))]
extern crate dirs;
extern crate embedder_traits;
@@ -183,9 +183,10 @@ pub fn add_user_prefs() {
init_user_prefs(&mut path);
}
None => {
let mut path = default_config_dir();
if path.join("prefs.json").exists() {
init_user_prefs(&mut path);
if let Some(mut path) = default_config_dir() {
if path.join("prefs.json").exists() {
init_user_prefs(&mut path);
}
}
}
}
@@ -48,6 +48,7 @@ fn test_get_set_reset_extend() {
assert_eq!(*PREFS.get("extra.stuff"), PrefValue::Boolean(false));
}

#[cfg(not(target_os = "android"))]
#[test]
fn test_default_config_dir_create_read_write() {
let json_str = "{\
@@ -56,7 +57,7 @@ fn test_default_config_dir_create_read_write() {
\"shell.homepage\": \"https://google.com\"\
}";
let mut expected_json = String::new();
let config_path = basedir::default_config_dir();
let config_path = basedir::default_config_dir().unwrap();

if !config_path.exists() {
fs::create_dir_all(&config_path).unwrap();
@@ -0,0 +1,46 @@
[package]
name = "libsimpleservo"
version = "0.0.1"
build = "build.rs"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false

[lib]
name = "simpleservo"
crate-type = ["cdylib"]
test = false
bench = false

[dependencies]
libservo = { path = "../../components/servo" }
log = "0.4"
serde_json = "1.0"

[target.'cfg(target_os = "android")'.dependencies]
android_injected_glue = "0.2"
android_logger = "0.6"
# FIXME: use `jni = "0.10.2"` once
# https://github.com/prevoty/jni-rs/pull/98 lands and is published
jni = { git = "https://github.com/paulrouget/jni-rs", branch = "return_javavm" }

[target.'cfg(not(target_os = "macos"))'.dependencies]
libc = "0.2"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.3.2"

[build-dependencies]
gl_generator = "0.9"
cc = "1.0"

[features]
default = ["unstable", "default-except-unstable"]
default-except-unstable = ["webdriver", "max_log_level"]
max_log_level = ["log/release_max_level_info"]
webdriver = ["libservo/webdriver"]
energy-profiling = ["libservo/energy-profiling"]
debugmozjs = ["libservo/debugmozjs"]
unstable = ["libservo/unstable"]
googlevr = ["libservo/googlevr"]
oculusvr = ["libservo/oculusvr"]

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Jun 29, 2018

Member

You probably also want:

default = ["unstable"]
unstable = ["libservo/unstable"]

… and maybe others from ports/servo/Cargo.toml.

This comment has been minimized.

Copy link
@paulrouget

paulrouget Jul 2, 2018

Author Contributor

Done.

@@ -0,0 +1,3 @@
This is a basic wrapper around Servo. While libservo itself (/components/servo/) offers a lot of flexibility,
libsimpleservo (/ports/libsimpleservo/) tries to make it easier to embed Servo, without much configuration needed.
It is limited to only one view (no tabs, no multiple rendering area).
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.