aboutsummaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorFabrice Desré <fabrice@desre.org>2017-02-16 17:17:25 -0800
committerFabrice Desré <fabrice@desre.org>2017-02-16 21:17:39 -0800
commit9f631b94ec4241f818991156c06276e8e82fc70d (patch)
tree68a74407d6b70317bf5b150a836aa8bf022f4517 /support
parent05623b36a15b594bbc690fcd8e3b642995618de1 (diff)
downloadservo-9f631b94ec4241f818991156c06276e8e82fc70d.tar.gz
servo-9f631b94ec4241f818991156c06276e8e82fc70d.zip
Cleanup of the Android specific code.
Diffstat (limited to 'support')
-rw-r--r--support/android/apk/jni/main.c58
-rw-r--r--support/android/apk/src/com/mozilla/servo/MainActivity.java4
-rw-r--r--support/android/build-apk/src/main.rs190
3 files changed, 96 insertions, 156 deletions
diff --git a/support/android/apk/jni/main.c b/support/android/apk/jni/main.c
deleted file mode 100644
index beddf906059..00000000000
--- a/support/android/apk/jni/main.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-//BEGIN_INCLUDE(all)
-#include <jni.h>
-#include <errno.h>
-#include <dlfcn.h>
-#include <stdlib.h>
-
-#include <android/log.h>
-#include <android_native_app_glue.h>
-
-#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "servo-wrapper", __VA_ARGS__))
-#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "servo-wrapper", __VA_ARGS__))
-
-/**
- * This is the main entry point of a native application that is using
- * android_native_app_glue. It runs in its own thread, with its own
- * event loop for receiving input events and doing other things.
- */
-void android_main(struct android_app* state) {
- LOGI("in android_main");
- void* libservo = dlopen("libservo.so", RTLD_NOW);
- if (libservo == NULL) {
- LOGI("failed to load servo lib: %s", dlerror());
- return;
- }
-
- LOGI("loaded libservo.so");
- void (*android_main)(struct android_app*);
- *(void**)(&android_main) = dlsym(libservo, "android_main");
- if (android_main) {
- LOGI("go into android_main()");
- (*android_main)(state);
- return;
- }
-}
-//END_INCLUDE(all)
-
-int main(int argc, char* argv[])
-{
- LOGI("WAT");
- return 0;
-}
diff --git a/support/android/apk/src/com/mozilla/servo/MainActivity.java b/support/android/apk/src/com/mozilla/servo/MainActivity.java
index f85146fc0ff..31973499cc0 100644
--- a/support/android/apk/src/com/mozilla/servo/MainActivity.java
+++ b/support/android/apk/src/com/mozilla/servo/MainActivity.java
@@ -16,10 +16,12 @@ import java.util.zip.ZipFile;
public class MainActivity extends android.app.NativeActivity {
- private static final String LOGTAG="servo_wrapper";
+ private static final String LOGTAG="ServoWrapper";
static {
Log.i(LOGTAG, "Loading the NativeActivity");
+ // libmain.so contains all of Servo native code with the injected glue.
System.loadLibrary("main");
+ Log.i(LOGTAG, "libmain.so loaded");
}
private void set_url(String url) {
diff --git a/support/android/build-apk/src/main.rs b/support/android/build-apk/src/main.rs
index e836eb859ce..10a140540ff 100644
--- a/support/android/build-apk/src/main.rs
+++ b/support/android/build-apk/src/main.rs
@@ -72,11 +72,11 @@ fn main() {
}
let ndkcmd = Command::new(ndk_path.join("ndk-build"))
- .arg("-B")
- .stdout(Stdio::inherit())
- .stderr(Stdio::inherit())
- .current_dir(directory.clone())
- .status();
+ .arg("-B")
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .current_dir(directory.clone())
+ .status();
if ndkcmd.is_err() || ndkcmd.unwrap().code().unwrap() != 0 {
println!("Error while executing program `ndk-build`, or missing program.");
process::exit(1);
@@ -91,13 +91,13 @@ fn main() {
// Copy over the resources
let cpcmd = Command::new("cp")
- .arg("-R")
- .arg(&resdir)
- .arg(&directory.join("assets"))
- .stdout(Stdio::inherit())
- .stderr(Stdio::inherit())
- .current_dir(directory.clone())
- .status();
+ .arg("-R")
+ .arg(&resdir)
+ .arg(&directory.join("assets"))
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .current_dir(directory.clone())
+ .status();
if cpcmd.is_err() || cpcmd.unwrap().code().unwrap() != 0 {
println!("Error while copying files from the resources dir to the assets dir");
process::exit(1);
@@ -105,18 +105,18 @@ fn main() {
// Update the project
let androidcmd = Command::new(sdk_path.join("tools").join("android"))
- .arg("update")
- .arg("project")
- .arg("--name")
- .arg("Servo")
- .arg("--target")
- .arg(&android_platform)
- .arg("--path")
- .arg(".")
- .stdout(Stdio::inherit())
- .stderr(Stdio::inherit())
- .current_dir(directory.clone())
- .status();
+ .arg("update")
+ .arg("project")
+ .arg("--name")
+ .arg("Servo")
+ .arg("--target")
+ .arg(&android_platform)
+ .arg("--path")
+ .arg(".")
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .current_dir(directory.clone())
+ .status();
if androidcmd.is_err() || androidcmd.unwrap().code().unwrap() != 0 {
println!("Error while updating the project with the android command");
process::exit(1);
@@ -129,8 +129,7 @@ fn main() {
} else {
antcmd.arg("release");
}
- let antresult = antcmd
- .stdout(Stdio::inherit())
+ let antresult = antcmd.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(directory.clone())
.status();
@@ -143,73 +142,72 @@ fn main() {
// Release builds also need to be signed. For now, we use a simple debug
// signing key.
if debug {
- fs::copy(&directory.join("bin").join("Servo-debug.apk"),
- &args.output).unwrap();
+ fs::copy(&directory.join("bin").join("Servo-debug.apk"), &args.output).unwrap();
} else {
let keystore_dir = env::home_dir().expect("Please have a home directory");
let keystore_dir = Path::new(&keystore_dir).join(".keystore");
let keytoolcmd = Command::new("keytool")
- .arg("-list")
- .arg("-storepass")
- .arg("android")
- .arg("-alias")
- .arg("androiddebugkey")
- .arg("-keystore")
- .arg(&keystore_dir)
- .stdout(Stdio::inherit())
- .stderr(Stdio::inherit())
- .current_dir(directory.clone())
- .status();
+ .arg("-list")
+ .arg("-storepass")
+ .arg("android")
+ .arg("-alias")
+ .arg("androiddebugkey")
+ .arg("-keystore")
+ .arg(&keystore_dir)
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .current_dir(directory.clone())
+ .status();
if keytoolcmd.is_err() || keytoolcmd.unwrap().code().unwrap() != 0 {
let keytoolcreatecmd = Command::new("keytool")
- .arg("-genkeypair")
- .arg("-keystore")
- .arg(&keystore_dir)
- .arg("-storepass")
- .arg("android")
- .arg("-alias")
- .arg("androiddebugkey")
- .arg("-keypass")
- .arg("android")
- .arg("-dname")
- .arg("CN=Android Debug,O=Android,C=US")
- .arg("-keyalg")
- .arg("RSA")
- .arg("-validity")
- .arg("365")
- .stdout(Stdio::inherit())
- .stderr(Stdio::inherit())
- .current_dir(directory.clone())
- .status();
- if keytoolcreatecmd.is_err() ||
- keytoolcreatecmd.unwrap().code().unwrap() != 0 {
- println!("Error while using `keytool` to create the debug keystore.");
- process::exit(1);
- }
+ .arg("-genkeypair")
+ .arg("-keystore")
+ .arg(&keystore_dir)
+ .arg("-storepass")
+ .arg("android")
+ .arg("-alias")
+ .arg("androiddebugkey")
+ .arg("-keypass")
+ .arg("android")
+ .arg("-dname")
+ .arg("CN=Android Debug,O=Android,C=US")
+ .arg("-keyalg")
+ .arg("RSA")
+ .arg("-validity")
+ .arg("365")
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .current_dir(directory.clone())
+ .status();
+ if keytoolcreatecmd.is_err() || keytoolcreatecmd.unwrap().code().unwrap() != 0 {
+ println!("Error while using `keytool` to create the debug keystore.");
+ process::exit(1);
+ }
}
let jarsigncmd = Command::new("jarsigner")
- .arg("-digestalg")
- .arg("SHA1")
- .arg("-sigalg")
- .arg("MD5withRSA")
- .arg("-storepass")
- .arg("android")
- .arg("-keystore")
- .arg(&keystore_dir)
- .arg(&directory.join("bin").join("Servo-release-unsigned.apk"))
- .arg("androiddebugkey")
- .stdout(Stdio::inherit())
- .stderr(Stdio::inherit())
- .current_dir(directory.clone())
- .status();
+ .arg("-digestalg")
+ .arg("SHA1")
+ .arg("-sigalg")
+ .arg("MD5withRSA")
+ .arg("-storepass")
+ .arg("android")
+ .arg("-keystore")
+ .arg(&keystore_dir)
+ .arg(&directory.join("bin").join("Servo-release-unsigned.apk"))
+ .arg("androiddebugkey")
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .current_dir(directory.clone())
+ .status();
if jarsigncmd.is_err() || jarsigncmd.unwrap().code().unwrap() != 0 {
println!("Error while using `jarsign` to sign the APK.");
process::exit(1);
}
fs::copy(&directory.join("bin").join("Servo-release-unsigned.apk"),
- &args.output).unwrap();
+ &args.output)
+ .unwrap();
}
}
@@ -233,16 +231,16 @@ fn parse_arguments() -> (Args, Vec<String>) {
loop {
let arg = match args.next() {
- None => return (
- Args {
+ None => {
+ return (Args {
output: result_output.expect("Could not find -o argument"),
root_path: result_root_path.expect("Could not find -r enlistment root argument"),
target_path: result_target_path.expect("Could not find -t target path argument"),
shared_libraries: result_shared_libraries,
},
- result_passthrough
- ),
- Some(arg) => arg
+ result_passthrough)
+ },
+ Some(arg) => arg,
};
match &*arg {
@@ -250,12 +248,12 @@ fn parse_arguments() -> (Args, Vec<String>) {
result_output = Some(PathBuf::from(args.next().expect("-o must be followed by the output name")));
},
"-r" => {
- result_root_path =
- Some(PathBuf::from(args.next().expect("-r must be followed by the enlistment root directory")));
+ result_root_path = Some(PathBuf::from(args.next()
+ .expect("-r must be followed by the enlistment root directory")));
},
"-t" => {
- result_target_path =
- Some(PathBuf::from(args.next().expect("-t must be followed by the target output directory")));
+ result_target_path = Some(PathBuf::from(args.next()
+ .expect("-t must be followed by the target output directory")));
},
"-l" => {
let name = args.next().expect("-l must be followed by a library name");
@@ -264,13 +262,13 @@ fn parse_arguments() -> (Args, Vec<String>) {
// Also pass these through.
result_passthrough.push(arg);
result_passthrough.push(name);
- }
+ },
_ => {
if arg.starts_with("-l") {
result_shared_libraries.insert(vec!["lib", &arg[2..], ".so"].concat());
}
result_passthrough.push(arg)
- }
+ },
};
}
}
@@ -287,15 +285,13 @@ fn find_native_libs(args: &Args) -> HashMap<String, PathBuf> {
(Some(file_name), Some(extension)) => {
let file_name = file_name.to_str().unwrap();
- if file_name.starts_with("lib") &&
- extension == "so" &&
- args.shared_libraries.contains(file_name) {
- println!("Adding the file {:?}", file_name);
- native_shared_libs.insert(file_name.to_string(), path.to_path_buf().clone());
- break;
+ if file_name.starts_with("lib") && extension == "so" && args.shared_libraries.contains(file_name) {
+ println!("Adding the file {:?}", file_name);
+ native_shared_libs.insert(file_name.to_string(), path.to_path_buf().clone());
+ break;
}
- }
- _ => {}
+ },
+ _ => {},
}
}