Skip to content

Commit

Permalink
Implement Gradle flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Sep 30, 2017
1 parent ffa0338 commit e931300
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 21 deletions.
29 changes: 21 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/servo/Cargo.toml
Expand Up @@ -17,6 +17,8 @@ max_log_level = ["log/release_max_level_info"]
webdriver = ["webdriver_server"]
energy-profiling = ["profile_traits/energy-profiling"]
debugmozjs = ["script/debugmozjs"]
googlevr = ["webvr/googlevr"]
oculusvr = ["webvr/oculusvr"]

[dependencies]
bluetooth_traits = {path = "../bluetooth_traits"}
Expand Down
6 changes: 5 additions & 1 deletion components/webvr/Cargo.toml
Expand Up @@ -9,13 +9,17 @@ publish = false
name = "webvr"
path = "lib.rs"

[features]
googlevr = ['rust-webvr/googlevr']
oculusvr = ['rust-webvr/oculusvr']

[dependencies]
canvas_traits = {path = "../canvas_traits"}
euclid = "0.15"
ipc-channel = "0.8"
log = "0.3"
msg = {path = "../msg"}
rust-webvr = {version = "0.8", features = ["openvr"]}
rust-webvr = {version = "0.9", features = ["openvr"]}
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}
webvr_traits = {path = "../webvr_traits" }
2 changes: 1 addition & 1 deletion components/webvr_traits/Cargo.toml
Expand Up @@ -12,5 +12,5 @@ path = "lib.rs"
[dependencies]
ipc-channel = "0.8"
msg = {path = "../msg"}
rust-webvr-api = {version = "0.8", features = ["serde-serialization"]}
rust-webvr-api = {version = "0.9", features = ["serde-serialization"]}
serde = "1.0"
2 changes: 2 additions & 0 deletions ports/servo/Cargo.toml
Expand Up @@ -34,6 +34,8 @@ max_log_level = ["log/release_max_level_info"]
webdriver = ["libservo/webdriver_server"]
energy-profiling = ["libservo/energy-profiling"]
debugmozjs = ["libservo/debugmozjs"]
googlevr = ["libservo/googlevr"]
oculusvr = ["libservo/oculusvr"]

[dependencies]
backtrace = "0.3"
Expand Down
5 changes: 5 additions & 0 deletions python/servo/build_commands.py
Expand Up @@ -309,6 +309,11 @@ def build(self, target=None, release=False, dev=False, jobs=None,
env['CPPFLAGS'] = ' '.join(["--sysroot", env['ANDROID_SYSROOT']])
env["CMAKE_ANDROID_ARCH_ABI"] = self.config["android"]["lib"]
env["CMAKE_TOOLCHAIN_FILE"] = path.join(self.android_support_dir(), "toolchain.cmake")
# Set output dir for gradle aar files
aar_out_dir = self.android_aar_dir()
if not os.path.exists(aar_out_dir):
os.makedirs(aar_out_dir)
env["AAR_OUT_DIR"] = aar_out_dir

cargo_binary = "cargo" + BIN_SUFFIX

Expand Down
3 changes: 3 additions & 0 deletions python/servo/command_base.py
Expand Up @@ -551,6 +551,9 @@ def android_support_dir(self):
def android_build_dir(self, dev):
return path.join(self.get_target_dir(), self.config["android"]["target"], "debug" if dev else "release")

def android_aar_dir(self):
return path.join(self.context.topdir, "target", "android_aar")

def handle_android_target(self, target):
if target == "arm-linux-androideabi":
self.config["android"]["platform"] = "android-18"
Expand Down
11 changes: 9 additions & 2 deletions python/servo/package_commands.py
Expand Up @@ -180,7 +180,10 @@ class PackageCommands(CommandBase):
@CommandArgument('--target', '-t',
default=None,
help='Package for given target platform')
def package(self, release=False, dev=False, android=None, debug=False, debugger=None, target=None):
@CommandArgument('--flavor', '-f',
default=None,
help='Package using the given Gradle flavor')
def package(self, release=False, dev=False, android=None, debug=False, debugger=None, target=None, flavor=None):
env = self.build_env()
if android is None:
android = self.config["build"]["android"]
Expand All @@ -206,7 +209,11 @@ def package(self, release=False, dev=False, android=None, debug=False, debugger=
else:
build_mode = "Release"

task_name = "assemble" + build_type + build_mode
flavor_name = "Main"
if flavor is not None:
flavor_name = flavor.title()

task_name = "assemble" + flavor_name + build_type + build_mode
try:
with cd(path.join("support", "android", "apk")):
subprocess.check_call(["./gradlew", "--no-daemon", task_name], env=env)
Expand Down
19 changes: 18 additions & 1 deletion support/android/apk/app/build.gradle
Expand Up @@ -33,6 +33,17 @@ android {
}
}

productFlavors {
main {
}
googlevr {
minSdkVersion 21
}
oculusvr {
minSdkVersion 21
}
}

sourceSets {
main {
java.srcDirs = ['src/main/java']
Expand Down Expand Up @@ -145,7 +156,9 @@ android {
// Call our custom NDK Build task using flavor parameters
tasks.all {
compileTask ->
Pattern pattern = Pattern.compile(/^transformJackWithJackFor([\w\d]+)(Debug|Release)/);
// Parse architecture name from gradle task name:
// Examples: transformJackWithJackForMainArmv7Release, transformJackWithJackForOculusvrArmv7Release
Pattern pattern = Pattern.compile(/^transformJackWithJackFor[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)/);
Matcher matcher = pattern.matcher(compileTask.name);
// You can use this alternative pattern when jackCompiler is disabled
// Pattern pattern = Pattern.compile(/^compile([\w\d]+)(Debug|Release)/);
Expand Down Expand Up @@ -194,6 +207,10 @@ dependencies {
}
}
}

googlevrCompile 'com.google.vr:sdk-base:1.70.0'
googlevrCompile(name:'GVRService', ext:'aar')
oculusvrCompile(name:'OVRService', ext:'aar')
}

// Utility methods
Expand Down
19 changes: 19 additions & 0 deletions support/android/apk/app/src/googlevr/AndroidManifest.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mozilla.servo">
<application>
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:enableVrMode="@string/gvr_vr_mode_component"
android:resizeableActivity="false">
<!-- Intent filter that enables this app to be launched from the
Daydream Home menu. -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.google.intent.category.DAYDREAM"/>
</intent-filter>
</activity>
</application>

</manifest>
<!-- END_INCLUDE(manifest) -->
Expand Up @@ -11,9 +11,11 @@
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.webkit.URLUtil;
import android.widget.FrameLayout;

import com.mozilla.servo.BuildConfig;

Expand Down Expand Up @@ -66,20 +68,44 @@ public void onCreate(Bundle savedInstanceState) {
}

JSONObject preferences = loadPreferences();
boolean keepScreenOn = preferences.optBoolean("shell.keep_screen_on.enabled", false);
mFullScreen = !preferences.optBoolean("shell.native-titlebar.enabled", false);
String orientation = preferences.optString("shell.native-orientation", "both");

// Handle orientation preference
if (orientation.equalsIgnoreCase("portrait")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
boolean keepScreenOn = false;

if (BuildConfig.FLAVOR.contains("vr")) {
// Force fullscreen mode and keep screen on for VR experiences.
keepScreenOn = true;
mFullScreen = true;
}
else if (orientation.equalsIgnoreCase("landscape")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else {
keepScreenOn = preferences.optBoolean("shell.keep_screen_on.enabled", false);
mFullScreen = !preferences.optBoolean("shell.native-titlebar.enabled", false);

String orientation = preferences.optString("shell.native-orientation", "both");

// Handle orientation preference
if (orientation.equalsIgnoreCase("portrait")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else if (orientation.equalsIgnoreCase("landscape")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}

super.onCreate(savedInstanceState);

// NativeActivity ignores the Android view hierarchy because it’s designed
// to take over the surface from the window to directly draw to it.
// Inject a custom SurfaceView in order to support adding views on top of the browser.
// (e.g. Native Banners, Daydream GVRLayout or other native views)
getWindow().takeSurface(null);
FrameLayout layout = new FrameLayout(this);
layout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
SurfaceView nativeSurface = new SurfaceView(this);
nativeSurface.getHolder().addCallback(this);
layout.addView(nativeSurface, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
setContentView(layout);

// Handle keep screen on preference
if (keepScreenOn) {
keepScreenOn();
Expand Down
10 changes: 10 additions & 0 deletions support/android/apk/app/src/oculusvr/AndroidManifest.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mozilla.servo">>
<application>
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
<activity android:name=".MainActivity" android:screenOrientation="landscape">
</activity>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->
3 changes: 3 additions & 0 deletions support/android/apk/build.gradle
Expand Up @@ -11,6 +11,9 @@ buildscript {
allprojects {
repositories {
jcenter()
flatDir {
dirs rootDir.absolutePath + "/../../../target/android_aar"
}
}

buildDir = rootDir.absolutePath + "/../../../target/gradle"
Expand Down

0 comments on commit e931300

Please sign in to comment.