Enable use of RUST_LOG with mach run --android.

This commit is contained in:
Josh Matthews 2018-09-20 14:14:41 -04:00
parent a6dbfdd29f
commit f7516f57a7
7 changed files with 31 additions and 15 deletions

View file

@ -12,6 +12,7 @@ use jni::objects::{GlobalRef, JClass, JObject, JString, JValue};
use jni::sys::{jboolean, jfloat, jint, jstring, JNI_TRUE}; use jni::sys::{jboolean, jfloat, jint, jstring, JNI_TRUE};
use log::Level; use log::Level;
use std; use std;
use std::borrow::Cow;
use std::os::raw::c_void; use std::os::raw::c_void;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -49,6 +50,7 @@ pub fn Java_com_mozilla_servoview_JNIServo_init(
activity: JObject, activity: JObject,
args: JString, args: JString,
url: JString, url: JString,
log_str: JString,
callbacks_obj: JObject, callbacks_obj: JObject,
width: jint, width: jint,
height: jint, height: jint,
@ -58,14 +60,17 @@ pub fn Java_com_mozilla_servoview_JNIServo_init(
// Note: Android debug logs are stripped from a release build. // Note: Android debug logs are stripped from a release build.
// debug!() will only show in a debug build. Use info!() if logs // debug!() will only show in a debug build. Use info!() if logs
// should show up in adb logcat with a release build. // should show up in adb logcat with a release build.
android_logger::init_once( let mut filter = Filter::default()
Filter::default() .with_min_level(Level::Debug)
.with_min_level(Level::Debug) .with_allowed_module_path("simpleservo::api")
.with_allowed_module_path("simpleservo::api") .with_allowed_module_path("simpleservo::jniapi")
.with_allowed_module_path("simpleservo::jniapi") .with_allowed_module_path("simpleservo::gl_glue::egl");
.with_allowed_module_path("simpleservo::gl_glue::egl"), let log_str = env.get_string(log_str).ok();
Some("simpleservo") let log_str = log_str.as_ref().map_or(Cow::Borrowed(""), |s| s.to_string_lossy());
); for module in log_str.split(',') {
filter = filter.with_allowed_module_path(module);
}
android_logger::init_once(filter, Some("simpleservo"));
} }
info!("init"); info!("init");

View file

@ -99,6 +99,9 @@ class PostBuildCommands(CommandBase):
] ]
json_params = shell_quote(json.dumps(params)) json_params = shell_quote(json.dumps(params))
extra = "-e servoargs " + json_params extra = "-e servoargs " + json_params
rust_log = env.get("RUST_LOG", None)
if rust_log:
extra += " -e servolog " + rust_log
script += [ script += [
"am start " + extra + " com.mozilla.servo/com.mozilla.servo.MainActivity", "am start " + extra + " com.mozilla.servo/com.mozilla.servo.MainActivity",
"sleep 0.5", "sleep 0.5",

View file

@ -71,7 +71,8 @@ public class MainActivity extends Activity implements Servo.Client {
} }
String args = getIntent().getStringExtra("servoargs"); String args = getIntent().getStringExtra("servoargs");
mServoView.setServoArgs(args); String log = getIntent().getStringExtra("servolog");
mServoView.setServoArgs(args, log);
setupUrlField(); setupUrlField();
} }

View file

@ -22,6 +22,7 @@ public class JNIServo {
public native void init(Activity activity, public native void init(Activity activity,
String args, String args,
String url, String url,
String logstr,
Callbacks callbacks, Callbacks callbacks,
int width, int height, boolean log); int width, int height, boolean log);

View file

@ -24,7 +24,9 @@ public class Servo {
GfxCallbacks gfxcb, GfxCallbacks gfxcb,
Client client, Client client,
Activity activity, Activity activity,
String args, String url, String args,
String url,
String logstr,
int width, int height, boolean log) { int width, int height, boolean log) {
mRunCallback = runCallback; mRunCallback = runCallback;
@ -34,7 +36,7 @@ public class Servo {
Callbacks cbs = new Callbacks(client, gfxcb); Callbacks cbs = new Callbacks(client, gfxcb);
mRunCallback.inGLThread(() -> { mRunCallback.inGLThread(() -> {
mJNI.init(activity, args, url, cbs, width, height, log); mJNI.init(activity, args, url, logstr, cbs, width, height, log);
}); });
} }

View file

@ -38,6 +38,7 @@ public class ServoSurface {
private Servo mServo; private Servo mServo;
private Client mClient = null; private Client mClient = null;
private String mServoArgs = ""; private String mServoArgs = "";
private String mServoLog = "";
private String mInitialUri = null; private String mInitialUri = null;
private Activity mActivity; private Activity mActivity;
@ -53,8 +54,9 @@ public class ServoSurface {
mClient = client; mClient = client;
} }
public void setServoArgs(String args) { public void setServoArgs(String args, String log) {
mServoArgs = args != null ? args : ""; mServoArgs = args != null ? args : "";
mServoLog = log != null ? log : "";
} }
public void setActivity(Activity activity) { public void setActivity(Activity activity) {
@ -204,7 +206,7 @@ public class ServoSurface {
inUIThread(() -> { inUIThread(() -> {
final boolean showLogs = true; final boolean showLogs = true;
String uri = mInitialUri == null ? null : mInitialUri; String uri = mInitialUri == null ? null : mInitialUri;
mServo = new Servo(this, surface, mClient, mActivity, mServoArgs, uri, mWidth, mHeight, showLogs); mServo = new Servo(this, surface, mClient, mActivity, mServoArgs, uri, mServoLog, mWidth, mHeight, showLogs);
}); });
Looper.loop(); Looper.loop();

View file

@ -41,6 +41,7 @@ public class ServoView extends GLSurfaceView
private Uri mInitialUri = null; private Uri mInitialUri = null;
private boolean mAnimating; private boolean mAnimating;
private String mServoArgs = ""; private String mServoArgs = "";
private String mServoLog = "";
private GestureDetector mGestureDetector; private GestureDetector mGestureDetector;
private ScaleGestureDetector mScaleGestureDetector; private ScaleGestureDetector mScaleGestureDetector;
@ -72,8 +73,9 @@ public class ServoView extends GLSurfaceView
initGestures(context); initGestures(context);
} }
public void setServoArgs(String args) { public void setServoArgs(String args, String log) {
mServoArgs = args != null ? args : ""; mServoArgs = args != null ? args : "";
mServoLog = log != null ? log : "";
} }
public void reload() { public void reload() {
@ -139,7 +141,7 @@ public class ServoView extends GLSurfaceView
int height = getHeight(); int height = getHeight();
inGLThread(() -> { inGLThread(() -> {
String uri = mInitialUri == null ? null : mInitialUri.toString(); String uri = mInitialUri == null ? null : mInitialUri.toString();
mServo = new Servo(this, this, mClient, mActivity, mServoArgs, uri, width, height, showLogs); mServo = new Servo(this, this, mClient, mActivity, mServoArgs, uri, mServoLog, width, height, showLogs);
}); });
} }