Bug 686466 part 3 - Use a pre-generated nsXREAppData struct instead of application.ini. r=ted,bsmedberg

--HG--
rename : build/application.ini => build/application.ini.in
This commit is contained in:
Mike Hommey 2011-11-22 08:05:59 +01:00
parent 5542d6e6f9
commit 29e01f8469
16 changed files with 202 additions and 79 deletions

View File

@ -73,6 +73,7 @@ CPPSRCS = nsBrowserApp.cpp
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
LOCAL_INCLUDES += -I$(DEPTH)/build
DEFINES += -DXPCOM_GLUE
STL_FLAGS=

View File

@ -36,8 +36,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "application.ini.h"
#include "nsXPCOMGlue.h"
#include "nsXULAppAPI.h"
#if defined(XP_WIN)
#include <windows.h>
#include <stdlib.h>
@ -140,20 +140,7 @@ static const nsDynamicFunctionLoad kXULFuncs[] = {
static int do_main(const char *exePath, int argc, char* argv[])
{
nsCOMPtr<nsILocalFile> appini;
#ifdef XP_WIN
// exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8
// encoded path, so it is safe to convert it
nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), false,
getter_AddRefs(appini));
#else
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false,
getter_AddRefs(appini));
#endif
if (NS_FAILED(rv)) {
return 255;
}
appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));
nsresult rv;
// Allow firefox.exe to launch XULRunner apps via -app <application.ini>
// Note that -app must be the *first* argument.
@ -188,15 +175,32 @@ static int do_main(const char *exePath, int argc, char* argv[])
argc -= 2;
}
nsXREAppData *appData;
rv = XRE_CreateAppData(appini, &appData);
if (NS_FAILED(rv)) {
Output("Couldn't read application.ini");
return 255;
int result;
if (appini) {
nsXREAppData *appData;
rv = XRE_CreateAppData(appini, &appData);
if (NS_FAILED(rv)) {
Output("Couldn't read application.ini");
return 255;
}
result = XRE_main(argc, argv, appData);
XRE_FreeAppData(appData);
} else {
#ifdef XP_WIN
// exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8
// encoded path, so it is safe to convert it
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), PR_FALSE,
getter_AddRefs(appini));
#else
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_FALSE,
getter_AddRefs(appini));
#endif
if (NS_FAILED(rv)) {
return 255;
}
result = XRE_main(argc, argv, &sAppData);
}
int result = XRE_main(argc, argv, appData);
XRE_FreeAppData(appData);
return result;
}
@ -240,6 +244,8 @@ int main(int argc, char* argv[])
Output("Couldn't load XPCOM.\n");
return 255;
}
// Reset exePath so that it is the directory name and not the xpcom dll name
*lastSlash = 0;
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
if (NS_FAILED(rv)) {

View File

@ -54,3 +54,4 @@ MOZ_OFFICIAL_BRANDING_DIRECTORY=browser/branding/official
MOZ_APP_ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
MOZ_PROFILE_MIGRATOR=1
MOZ_EXTENSION_MANAGER=1
MOZ_APP_STATIC_INI=1

View File

@ -71,15 +71,19 @@ DIST_FILES = application.ini
ifdef LIBXUL_SDK
GRE_MILESTONE = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build Milestone)
APP_INI_DEPS = $(LIBXUL_DIST)/bin/platform.ini
else
GRE_MILESTONE = $(shell tail -n 1 $(topsrcdir)/config/milestone.txt 2>/dev/null || tail -1 $(topsrcdir)/config/milestone.txt)
APP_INI_DEPS = $(topsrcdir)/config/milestone.txt
endif
APP_BUILDID := $(shell cat $(DEPTH)/config/buildid)
APP_INI_DEPS += $(DEPTH)/config/buildid
DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DAPP_BUILDID=$(APP_BUILDID)
DEFINES += -DMOZ_APP_VERSION="$(MOZ_APP_VERSION)"
APP_INI_DEPS += $(DEPTH)/config/autoconf.mk
MOZ_SOURCE_STAMP ?= $(firstword $(shell hg -R $(topsrcdir) parent --template="{node|short}\n" 2>/dev/null))
ifdef MOZ_SOURCE_STAMP
@ -150,6 +154,19 @@ leaktest.py: leaktest.py.in
chmod +x $@
GARBAGE += leaktest.py
ifdef MOZ_APP_BASENAME
application.ini: application.ini.in $(APP_INI_DEPS)
$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) $< > $@
GARBAGE += application.ini
ifdef MOZ_APP_STATIC_INI
application.ini.h: appini_header.py application.ini
$(PYTHON) $^ > $@
export:: application.ini.h
GARBAGE += application.ini.h
endif
endif
libs:: $(_LEAKTEST_FILES)
$(INSTALL) $^ $(_LEAKTEST_DIR)

86
build/appini_header.py Normal file
View File

@ -0,0 +1,86 @@
# ***** 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 a build helper for libraries
#
# The Initial Developer of the Original Code is
# the Mozilla Foundation
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mike Hommey <mh@glandium.org>
#
# 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 *****
'''Parses a given application.ini file and outputs the corresponding
XULAppData structure as a C++ header file'''
import ConfigParser
import sys
def main(file):
config = ConfigParser.RawConfigParser()
config.read(file)
flags = set()
try:
if config.getint('XRE', 'EnableExtensionManager') == 1:
flags.add('NS_XRE_ENABLE_EXTENSION_MANAGER')
except: pass
try:
if config.getint('XRE', 'EnableProfileMigrator') == 1:
flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR')
except: pass
try:
if config.getint('Crash Reporter', 'Enabled') == 1:
flags.add('NS_XRE_ENABLE_CRASH_REPORTER')
except: pass
appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s))
appdata['flags'] = ' | '.join(flags) if flags else '0'
appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL'
print '''#include "nsXULAppAPI.h"
static const nsXREAppData sAppData = {
sizeof(nsXREAppData),
NULL, // directory
"%(App:vendor)s",
"%(App:name)s",
"%(App:version)s",
"%(App:buildid)s",
"%(App:id)s",
NULL, // copyright
%(flags)s,
NULL, // xreDirectory
"%(Gecko:minversion)s",
"%(Gecko:maxversion)s",
"%(Crash Reporter:serverurl)s",
%(App:profile)s
};''' % appdata
if __name__ == '__main__':
if len(sys.argv) != 1:
main(sys.argv[1])
else:
print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0]

View File

@ -1,3 +1,8 @@
#if MOZ_APP_STATIC_INI
; This file is not used. If you modify it and want the application to use
; your modifications, start with the "-app /path/to/application.ini"
; argument.
#endif
#if 0
; ***** BEGIN LICENSE BLOCK *****
; Version: MPL 1.1/GPL 2.0/LGPL 2.1

View File

@ -58,6 +58,7 @@ MOZ_EXTENSION_MANAGER = @MOZ_EXTENSION_MANAGER@
MOZ_APP_UA_NAME = @MOZ_APP_UA_NAME@
MOZ_APP_VERSION = @MOZ_APP_VERSION@
MOZ_UA_BUILDID = @MOZ_UA_BUILDID@
MOZ_APP_STATIC_INI = @MOZ_APP_STATIC_INI@
MOZ_PKG_SPECIAL = @MOZ_PKG_SPECIAL@

View File

@ -8535,6 +8535,13 @@ AC_SUBST(FIREFOX_VERSION)
AC_DEFINE_UNQUOTED(MOZ_UA_BUILDID, "$MOZ_UA_BUILDID")
AC_SUBST(MOZ_UA_BUILDID)
# We can't use the static application.ini data when building against
# a libxul SDK.
if test -n "$LIBXUL_SDK"; then
MOZ_APP_STATIC_INI=
fi
AC_SUBST(MOZ_APP_STATIC_INI)
AC_SUBST(MOZ_PKG_SPECIAL)
AC_SUBST(MOZILLA_OFFICIAL)

View File

@ -618,7 +618,6 @@ abstract public class GeckoApp
// This file may not be there, so just log any errors and move on
Log.w(LOG_FILE_NAME, "error removing files", ex);
}
unpackFile(zip, buf, null, "application.ini");
try {
unpackFile(zip, buf, null, "update.locale");
} catch (Exception e) {/* this is non-fatal */}

View File

@ -55,6 +55,7 @@ CPPSRCS = nsBrowserApp.cpp
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
LOCAL_INCLUDES += -I$(DEPTH)/build
DEFINES += -DXPCOM_GLUE
STL_FLAGS=

View File

@ -36,8 +36,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "application.ini.h"
#include "nsXPCOMGlue.h"
#include "nsXULAppAPI.h"
#if defined(XP_WIN)
#include <windows.h>
#include <stdlib.h>
@ -147,20 +147,7 @@ static const nsDynamicFunctionLoad kXULFuncs[] = {
static int do_main(const char *exePath, int argc, char* argv[])
{
nsCOMPtr<nsILocalFile> appini;
#ifdef XP_WIN
// exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8
// encoded path, so it is safe to convert it
nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), false,
getter_AddRefs(appini));
#else
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false,
getter_AddRefs(appini));
#endif
if (NS_FAILED(rv)) {
return 255;
}
appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));
nsresult rv;
// Allow firefox.exe to launch XULRunner apps via -app <application.ini>
// Note that -app must be the *first* argument.
@ -195,15 +182,32 @@ static int do_main(const char *exePath, int argc, char* argv[])
argc -= 2;
}
nsXREAppData *appData;
rv = XRE_CreateAppData(appini, &appData);
if (NS_FAILED(rv)) {
Output("Couldn't read application.ini");
return 255;
int result;
if (appini) {
nsXREAppData *appData;
rv = XRE_CreateAppData(appini, &appData);
if (NS_FAILED(rv)) {
Output("Couldn't read application.ini");
return 255;
}
result = XRE_main(argc, argv, appData);
XRE_FreeAppData(appData);
} else {
#ifdef XP_WIN
// exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8
// encoded path, so it is safe to convert it
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), PR_FALSE,
getter_AddRefs(appini));
#else
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_FALSE,
getter_AddRefs(appini));
#endif
if (NS_FAILED(rv)) {
return 255;
}
result = XRE_main(argc, argv, &sAppData);
}
int result = XRE_main(argc, argv, appData);
XRE_FreeAppData(appData);
return result;
}
@ -269,6 +273,8 @@ int main(int argc, char* argv[])
Output("Couldn't load XPCOM.\n");
return 255;
}
// Reset exePath so that it is the directory name and not the xpcom dll name
*lastSlash = 0;
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
if (NS_FAILED(rv)) {

View File

@ -70,3 +70,4 @@ MOZ_USE_NATIVE_POPUP_WINDOWS=1
MOZ_APP_ID={a23983c0-fd0e-11dc-95ff-0800200c9a66}
MOZ_EXTENSION_MANAGER=1
MOZ_APP_STATIC_INI=1

View File

@ -200,6 +200,11 @@ LOCAL_INCLUDES += \
-I$(topsrcdir)/config \
$(NULL)
ifdef MOZ_APP_STATIC_INI
LOCAL_INCLUDES += -I$(DEPTH)/build
DEFINES += -DMOZ_APP_STATIC_INI
endif
CXXFLAGS += $(TK_CFLAGS) $(MOZ_DBUS_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS)
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)

View File

@ -39,6 +39,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "application.ini.h"
#include <android/log.h>
#include <jni.h>
@ -90,37 +92,6 @@ GeckoStart(void *data)
return 0;
}
nsresult rv;
nsCOMPtr<nsILocalFile> appini;
char* greHome = getenv("GRE_HOME");
if (!greHome) {
LOG("Failed to get GRE_HOME from the env vars");
return 0;
}
nsCAutoString appini_path(greHome);
appini_path.AppendLiteral("/application.ini");
rv = NS_NewNativeLocalFile(appini_path, false, getter_AddRefs(appini));
if (NS_FAILED(rv)) {
LOG("Failed to create nsILocalFile for appdata\n");
return 0;
}
nsXREAppData *appData;
rv = XRE_CreateAppData(appini, &appData);
if (NS_FAILED(rv)) {
LOG("Failed to load application.ini from %s\n", appini_path.get());
return 0;
}
nsCOMPtr<nsILocalFile> xreDir;
rv = NS_NewNativeLocalFile(nsDependentCString(greHome), false, getter_AddRefs(xreDir));
if (NS_FAILED(rv)) {
LOG("Failed to create nsIFile for xreDirectory");
return 0;
}
appData->xreDirectory = xreDir.get();
nsTArray<char *> targs;
char *arg = strtok(static_cast<char *>(data), " ");
while (arg) {
@ -129,13 +100,11 @@ GeckoStart(void *data)
}
targs.AppendElement(static_cast<char *>(nsnull));
int result = XRE_main(targs.Length() - 1, targs.Elements(), appData);
int result = XRE_main(targs.Length() - 1, targs.Elements(), &sAppData);
if (result)
LOG("XRE_main returned %d", result);
XRE_FreeAppData(appData);
mozilla::AndroidBridge::Bridge()->NotifyXreExit();
free(targs[0]);

View File

@ -2767,6 +2767,10 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
return 2;
}
if (!appData.directory) {
NS_IF_ADDREF(appData.directory = appData.xreDirectory);
}
if (appData.size > offsetof(nsXREAppData, minVersion)) {
if (!appData.minVersion) {
Output(true, "Error: Gecko:MinVersion not specified in application.ini\n");

View File

@ -94,6 +94,20 @@ private:
return rv;
}
#elif defined(ANDROID)
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{
// On Android, we use the GRE_HOME variable that is set by the Java
// bootstrap code.
const char *greHome = getenv("GRE_HOME");
if (!greHome)
return NS_ERROR_FAILURE;
snprintf(aResult, MAXPATHLEN, "%s/%s", greHome, "dummy");
aResult[MAXPATHLEN] = '\0';
return NS_OK;
}
#elif defined(XP_UNIX)
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{