Skip to content

Commit

Permalink
Fix fetching sourcemap in genymotion. Fixes facebook#5338
Browse files Browse the repository at this point in the history
Summary:Source maps are broken on Genymotion right now as they aren't being loaded from the correct URL. refer - facebook#5338 (comment)

**Test plan**

Build and install UIExplorer from master branch in genymotion and enable hot reload. When you change a file and save it, you'll see a Yellow box due to source map fetching failed, as per the referenced comment.

Doing the same for this branch doesn't produce any yellow boxes.
Closes facebook#6594

Differential Revision: D3088218

Pulled By: martinbigio

fb-gh-sync-id: 0d1c19cc263de5c6c62061c399eef33fa4ac4a7b
shipit-source-id: 0d1c19cc263de5c6c62061c399eef33fa4ac4a7b
  • Loading branch information
satya164 authored and Facebook Github Bot 6 committed Mar 24, 2016
1 parent c4699d8 commit 6c22a21
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 40 deletions.
10 changes: 9 additions & 1 deletion Libraries/Utilities/HMRClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ Error: ${e.message}`
RCTExceptionsManager && RCTExceptionsManager.dismissRedbox && RCTExceptionsManager.dismissRedbox();
}

let serverHost;

if (Platform.OS === 'android') {
serverHost = require('NativeModules').AndroidConstants.ServerHost;
} else {
serverHost = port ? `${host}:${port}` : host;
}

modules.forEach(({id, code}, i) => {
code = code + '\n\n' + sourceMappingURLs[i];

require('SourceMapsCache').fetch({
text: code,
url: sourceURLs[i],
url: `http://${serverHost}${sourceURLs[i]}`,
sourceMappingURL: sourceMappingURLs[i],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android_library(
react_native_target('java/com/facebook/react/bridge:bridge'),
react_native_target('java/com/facebook/react/common:common'),
react_native_target('java/com/facebook/react/modules/debug:debug'),
react_native_target('java/com/facebook/react/modules/systeminfo:systeminfo'),
react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'),
react_native_dep('third-party/java/infer-annotations:infer-annotations'),
react_native_dep('third-party/java/jsr-305:jsr-305'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@

package com.facebook.react.devsupport;

import javax.annotation.Nullable;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.text.TextUtils;

import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.ConnectionPool;
Expand All @@ -34,6 +26,13 @@
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;

import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import okio.Okio;
import okio.Sink;

Expand All @@ -51,10 +50,6 @@ public class DevServerHelper {
public static final String RELOAD_APP_EXTRA_JS_PROXY = "jsproxy";
private static final String RELOAD_APP_ACTION_SUFFIX = ".RELOAD_APP_ACTION";

private static final String EMULATOR_LOCALHOST = "10.0.2.2:8081";
private static final String GENYMOTION_LOCALHOST = "10.0.3.2:8081";
private static final String DEVICE_LOCALHOST = "localhost:8081";

private static final String BUNDLE_URL_FORMAT =
"http://%s/%s.bundle?platform=android&dev=%s&hot=%s&minify=%s";
private static final String SOURCE_MAP_URL_FORMAT =
Expand Down Expand Up @@ -118,7 +113,7 @@ public String getWebsocketProxyURL() {
* @return the host to use when connecting to the bundle server from the host itself.
*/
private static String getHostForJSProxy() {
return DEVICE_LOCALHOST;
return AndroidInfoHelpers.DEVICE_LOCALHOST;
}

/**
Expand Down Expand Up @@ -149,31 +144,21 @@ private String getDebugServerHost() {
// Check debug server host setting first. If empty try to detect emulator type and use default
// hostname for those
String hostFromSettings = mSettings.getDebugServerHost();

if (!TextUtils.isEmpty(hostFromSettings)) {
return Assertions.assertNotNull(hostFromSettings);
}

// Since genymotion runs in vbox it use different hostname to refer to adb host.
// We detect whether app runs on genymotion and replace js bundle server hostname accordingly
if (isRunningOnGenymotion()) {
return GENYMOTION_LOCALHOST;
}
if (isRunningOnStockEmulator()) {
return EMULATOR_LOCALHOST;
}
FLog.w(
String host = AndroidInfoHelpers.getServerHost();

if (host.equals(AndroidInfoHelpers.DEVICE_LOCALHOST)) {
FLog.w(
ReactConstants.TAG,
"You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' " +
"to forward the debug server's port to the device.");
return DEVICE_LOCALHOST;
}

private boolean isRunningOnGenymotion() {
return Build.FINGERPRINT.contains("vbox");
}
"to forward the debug server's port to the device.");
}

private boolean isRunningOnStockEmulator() {
return Build.FINGERPRINT.contains("generic");
return host;
}

private static String createBundleURL(String host, String jsModulePath, boolean devMode, boolean hmr, boolean jsMinify) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.facebook.react.modules.systeminfo;

import android.os.Build;

public class AndroidInfoHelpers {

public static final String EMULATOR_LOCALHOST = "10.0.2.2:8081";
public static final String GENYMOTION_LOCALHOST = "10.0.3.2:8081";
public static final String DEVICE_LOCALHOST = "localhost:8081";

private static boolean isRunningOnGenymotion() {
return Build.FINGERPRINT.contains("vbox");
}

private static boolean isRunningOnStockEmulator() {
return Build.FINGERPRINT.contains("generic");
}

public static String getServerHost() {
// Since genymotion runs in vbox it use different hostname to refer to adb host.
// We detect whether app runs on genymotion and replace js bundle server hostname accordingly

if (isRunningOnGenymotion()) {
return GENYMOTION_LOCALHOST;
}

if (isRunningOnStockEmulator()) {
return EMULATOR_LOCALHOST;
}

return DEVICE_LOCALHOST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

package com.facebook.react.modules.systeminfo;

import javax.annotation.Nullable;
import android.os.Build;

import com.facebook.react.bridge.BaseJavaModule;

import java.util.HashMap;
import java.util.Map;

import android.os.Build;

import com.facebook.react.bridge.BaseJavaModule;
import javax.annotation.Nullable;

/**
* Module that exposes Android Constants to JS.
Expand All @@ -32,6 +32,7 @@ public String getName() {
public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>();
constants.put("Version", Build.VERSION.SDK_INT);
constants.put("ServerHost", AndroidInfoHelpers.getServerHost());
return constants;
}
}
6 changes: 3 additions & 3 deletions packager/react-packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ class Bundler {
});
}

_sourceHMRURL(platform, host, port, path) {
_sourceHMRURL(platform, path) {
return this._hmrURL(
`http://${host}:${port}`,
'',
platform,
'bundle',
path,
Expand Down Expand Up @@ -217,7 +217,7 @@ class Bundler {
return this._bundle({
...options,
bundle: new HMRBundle({
sourceURLFn: this._sourceHMRURL.bind(this, options.platform, host, port),
sourceURLFn: this._sourceHMRURL.bind(this, options.platform),
sourceMappingURLFn: this._sourceMappingHMRURL.bind(
this,
options.platform,
Expand Down

0 comments on commit 6c22a21

Please sign in to comment.