bug 578493 - Set env vars before loading libraries r=mwu
authorBrad Lassey <blassey@mozilla.com>
Fri, 16 Jul 2010 11:52:01 -0400
changeset 47825 8e58befb03a5be475c766b99d3c59ffd3d560c95
parent 47824 0c4c442e5bb8d54814afbd5a3b008a5fac4ac3a6
child 47826 0f1fddce41e12d15d5c08a47b5cabf23d3201e55
push id14431
push userblassey@mozilla.com
push dateFri, 16 Jul 2010 18:32:52 +0000
treeherderautoland@0f1fddce41e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs578493
milestone2.0b2pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 578493 - Set env vars before loading libraries r=mwu
embedding/android/GeckoApp.java
embedding/android/GeckoAppShell.java
embedding/android/Makefile.in
embedding/android/utils/Makefile.in
embedding/android/utils/nsGeckoUtils.cpp
widget/src/android/AndroidJNI.cpp
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -62,34 +62,16 @@ abstract public class GeckoApp
 
     void launch()
     {
         // unpack files in the components directory
         unpackComponents();
         // and then fire us up
         Intent i = getIntent();
         String env = i.getStringExtra("env0");
-        Log.i("GeckoApp", "env0: "+ env);
-        for (int c = 1; env != null; c++) {
-            GeckoAppShell.putenv(env);
-            env = i.getStringExtra("env" + c);
-            Log.i("GeckoApp", "env"+ c +": "+ env);
-        }
-        String tmpdir = System.getProperty("java.io.tmpdir");
-        if (tmpdir == null) {
-          try {
-            File f = Environment.getDownloadCacheDirectory();
-            dalvik.system.TemporaryDirectory.setUpDirectory(f);
-            tmpdir = f.getPath();
-          } catch (Exception e) {
-            Log.e("GeckoApp", "error setting up tmp dir" + e);
-          }
-        }
-        GeckoAppShell.putenv("TMPDIR=" + tmpdir);
-
         GeckoAppShell.runGecko(getApplication().getPackageResourcePath(),
                                i.getStringExtra("args"),
                                i.getDataString());
     }
 
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
--- a/embedding/android/GeckoAppShell.java
+++ b/embedding/android/GeckoAppShell.java
@@ -89,17 +89,38 @@ class GeckoAppShell
     // java-side stuff
     public static void loadGeckoLibs() {
         // The package data lib directory isn't placed in ld.so's
         // search path, so we have to manually load libraries that
         // libxul will depend on.  Not ideal.
 
         // MozAlloc
         System.loadLibrary("mozalloc");
-
+        System.loadLibrary("mozutils");
+                
+        Intent i = GeckoApp.mAppContext.getIntent();
+        String env = i.getStringExtra("env0");
+        Log.i("GeckoApp", "env0: "+ env);
+        for (int c = 1; env != null; c++) {
+            GeckoAppShell.putenv(env);
+            env = i.getStringExtra("env" + c);
+            Log.i("GeckoApp", "env"+ c +": "+ env);
+        }
+        String tmpdir = System.getProperty("java.io.tmpdir");
+        if (tmpdir == null) {
+          try {
+            File f = Environment.getDownloadCacheDirectory();
+            dalvik.system.TemporaryDirectory.setUpDirectory(f);
+            tmpdir = f.getPath();
+          } catch (Exception e) {
+            Log.e("GeckoApp", "error setting up tmp dir" + e);
+          }
+        }
+        GeckoAppShell.putenv("TMPDIR=" + tmpdir);
+        
         // NSPR
         System.loadLibrary("nspr4");
         System.loadLibrary("plc4");
         System.loadLibrary("plds4");
 
         // SQLite
         System.loadLibrary("mozsqlite3");
 
--- a/embedding/android/Makefile.in
+++ b/embedding/android/Makefile.in
@@ -64,26 +64,28 @@ GARBAGE += \
   Restarter.java \
   gecko.ap_  \
   gecko-unaligned.apk  \
   gecko-unsigned-unaligned.apk \
   $(NULL)
 
 GARBAGE_DIRS += res libs dist classes
 
+DIRS = utils
+
 # Bug 567884 - Need a way to find appropriate icons during packaging
 ifeq ($(MOZ_APP_NAME),fennec)
 ICON_PATH = $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/content/fennec_48x48.png
 ICON_PATH_HI = $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/content/fennec_72x72.png
 else
 ICON_PATH = $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/content/icon48.png
 ICON_PATH_HI = $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/content/icon64.png
 endif
 
-NATIVE_LIBS = $(shell cat $(DIST)/bin/dependentlibs.list) libxpcom.so libnssckbi.so libfreebl3.so
+NATIVE_LIBS = $(shell cat $(DIST)/bin/dependentlibs.list) libxpcom.so libnssckbi.so libfreebl3.so libmozutils.so
 FULL_LIBS = $(addprefix libs/armeabi/,$(NATIVE_LIBS))
 
 # We'll strip all the libs by default, due to size, but we might
 # want to have a non-stripped version for debugging.  We should
 # really pull out debuginfo and stuff.
 ifdef NO_STRIP
 DO_STRIP=echo not stripping
 else
@@ -140,26 +142,26 @@ gecko.ap_: AndroidManifest.xml res/drawa
 libs/armeabi/%: $(DIST)/lib/%
 	@$(NSINSTALL) -D libs/armeabi
 	@cp -L -v $< $@
 	@$(DO_STRIP) $@
 
 # Bug 567873 - Android packaging should use standard packaging code
 dist: FORCE
 	$(NSINSTALL) -D dist/components
-	rm -f dist/components/*
-	@(for f in $(DIST)/bin/components/* ; do ln -sf ../../$$f dist/components ; done)
+	rm -rf dist/components/*
+	@(for f in $(DIST)/bin/components/* ; do $(NSINSTALL) $$f dist/components ; done)
 	$(NSINSTALL) -D dist/chrome
-	rm -f dist/chrome/*
-	@(for f in $(DIST)/bin/chrome/* ; do ln -sf ../../$$f dist/chrome ; done)
+	rm -rf dist/chrome/*
+	@(for f in $(DIST)/bin/chrome/* ; do $(NSINSTALL) $$f dist/chrome ; done)
 	$(NSINSTALL) -D dist/defaults
-	rm -f dist/defaults/*
-	@(for f in $(DIST)/bin/defaults/* ; do ln -sf ../../$$f dist/defaults ; done )
+	rm -rf dist/defaults/*
+	@(for f in $(DIST)/bin/defaults/* ; do $(NSINSTALL) $$f dist/defaults ; done )
 	@(for PREF in $(DIST)/bin/defaults/pref/*.js ; do cat "$$PREF" >> dist/defaults/prefs.js ; echo >> dist/defaults/prefs.js ; done )
-	rm dist/defaults/pref
+	rm -rf dist/defaults/pref
 	@(for f in $(DIST_LINK_FILES) ; do if [ -e $(DIST)/bin/$$f ] ; then echo $$f ; ln -sf ../$(DIST)/bin/$$f dist ; fi ; done)
 
 gecko-unsigned-unaligned.apk: gecko.ap_ classes.dex dist $(FULL_LIBS)
 	$(APKBUILDER) $@ -v $(APKBUILDER_FLAGS) -z gecko.ap_ -f classes.dex -nf `pwd`/libs -rf dist
 
 gecko-unaligned.apk: gecko-unsigned-unaligned.apk
 	cp gecko-unsigned-unaligned.apk $@
 ifdef JARSIGNER
new file mode 100644
--- /dev/null
+++ b/embedding/android/utils/Makefile.in
@@ -0,0 +1,50 @@
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (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.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is the Mozilla browser.
+#
+# The Initial Developer of the Original Code is
+#   Mozilla Foundation
+# Portions created by the Initial Developer are Copyright (C) 2010
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Brad Lassey <blassey@mozilla.com>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH		= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+MODULE         = mozutils
+LIBRARY_NAME   = mozutils
+FORCE_SHARED_LIB = 1
+
+CPPSRCS = nsGeckoUtils.cpp
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/embedding/android/utils/nsGeckoUtils.cpp
@@ -0,0 +1,58 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Android code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Brad Lassey <blassey@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include <jni.h>
+#include <stdlib.h>
+
+extern "C" {
+  void JNICALL Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map);
+}
+
+__attribute__ ((visibility("default")))
+void JNICALL
+Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map)
+{
+    const char* str;
+    // XXX: java doesn't give us true UTF8, we should figure out something 
+    // better to do here
+    str = jenv->GetStringUTFChars(map, NULL);
+    if (str == NULL)
+        return;
+    putenv(strdup(str));
+    jenv->ReleaseStringUTFChars(map, str);
+}
+
--- a/widget/src/android/AndroidJNI.cpp
+++ b/widget/src/android/AndroidJNI.cpp
@@ -51,17 +51,16 @@ using namespace mozilla;
 
 /* Forward declare all the JNI methods as extern "C" */
 
 extern "C" {
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_nativeInit(JNIEnv *, jclass);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(JNIEnv *, jclass, jobject event);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobject sv);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setInitialSize(JNIEnv *jenv, jclass, int width, int height);
-    NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *, jclass);
 }
 
 
 /*
  * Incoming JNI methods
  */
 
@@ -89,28 +88,13 @@ Java_org_mozilla_gecko_GeckoAppShell_set
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_setInitialSize(JNIEnv *jenv, jclass, int width, int height)
 {
     nsWindow::SetInitialAndroidBounds(gfxIntSize(width, height));
 }
 
 NS_EXPORT void JNICALL
-Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map)
-{
-    const char* str;
-    str = jenv->GetStringUTFChars(map, NULL);
-    if (str == NULL)
-        return;
-#ifdef DEBUG
-    __android_log_print(ANDROID_LOG_INFO, "GeckoJNI", "putenv(%s)", str);
-#endif
-    putenv(strdup(str));
-    jenv->ReleaseStringUTFChars(map, str);
-    
-}
-
-NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *jenv, jclass jc)
 {
     if (nsAppShell::gAppShell)
         nsAppShell::gAppShell->OnResume();
 }