Bug 470971 - Add ability to pass the GRE dir to xpcshell, r=ted - fixed patch: XRE_GetBinaryPath gets the file of the executable: we want to pass the parent directory to XPCOM.

This commit is contained in:
Benjamin Smedberg 2009-01-20 14:56:44 -05:00
Родитель 88555bd99d
Коммит 834ec83fc3
4 изменённых файлов: 99 добавлений и 3 удалений

Просмотреть файл

@ -186,6 +186,7 @@ MOZ_FIX_LINK_PATHS=@MOZ_FIX_LINK_PATHS@
XPCOM_FROZEN_LDOPTS=@XPCOM_FROZEN_LDOPTS@ XPCOM_FROZEN_LDOPTS=@XPCOM_FROZEN_LDOPTS@
XPCOM_LIBS=@XPCOM_LIBS@ XPCOM_LIBS=@XPCOM_LIBS@
LIBXUL_LIBS=@LIBXUL_LIBS@
MOZ_TIMELINE=@MOZ_TIMELINE@ MOZ_TIMELINE=@MOZ_TIMELINE@
ENABLE_STRIP = @ENABLE_STRIP@ ENABLE_STRIP = @ENABLE_STRIP@

Просмотреть файл

@ -7254,6 +7254,8 @@ if test -n "$MOZ_ENABLE_LIBXUL" -a -n "$BUILD_STATIC_LIBS"; then
AC_MSG_ERROR([--enable-libxul is not compatible with --enable-static]) AC_MSG_ERROR([--enable-libxul is not compatible with --enable-static])
fi fi
AC_SUBST(LIBXUL_LIBS)
if test -n "$MOZ_ENABLE_LIBXUL"; then if test -n "$MOZ_ENABLE_LIBXUL"; then
XPCOM_LIBS="$LIBXUL_LIBS" XPCOM_LIBS="$LIBXUL_LIBS"
AC_DEFINE(MOZ_ENABLE_LIBXUL) AC_DEFINE(MOZ_ENABLE_LIBXUL)

Просмотреть файл

@ -50,6 +50,7 @@ REQUIRES = xpconnect \
xpcom \ xpcom \
js \ js \
caps \ caps \
xulapp \
$(NULL) $(NULL)
CPPSRCS = xpcshell.cpp CPPSRCS = xpcshell.cpp
@ -60,8 +61,8 @@ endif
LIBS = \ LIBS = \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
$(LIBXUL_LIBS) \
$(MOZ_JS_LIBS) \ $(MOZ_JS_LIBS) \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \ $(NSPR_LIBS) \
$(NULL) $(NULL)

Просмотреть файл

@ -45,8 +45,10 @@
/* XPConnect JavaScript interactive shell. */ /* XPConnect JavaScript interactive shell. */
#include <stdio.h> #include <stdio.h>
#include "nsXULAppAPI.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsStringAPI.h"
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsIXPCScriptable.h" #include "nsIXPCScriptable.h"
#include "nsIInterfaceInfo.h" #include "nsIInterfaceInfo.h"
@ -57,12 +59,16 @@
#include "nsIComponentRegistrar.h" #include "nsIComponentRegistrar.h"
#include "nsILocalFile.h" #include "nsILocalFile.h"
#include "nsStringAPI.h" #include "nsStringAPI.h"
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "jsapi.h" #include "jsapi.h"
#include "jsdbgapi.h" #include "jsdbgapi.h"
#include "jsprf.h" #include "jsprf.h"
#include "nscore.h" #include "nscore.h"
#include "nsMemory.h" #include "nsMemory.h"
#include "nsIGenericFactory.h" #include "nsIGenericFactory.h"
#include "nsISupportsImpl.h"
#include "nsIJSRuntimeService.h" #include "nsIJSRuntimeService.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
@ -91,6 +97,22 @@
#include "nsIJSContextStack.h" #include "nsIJSContextStack.h"
class XPCShellDirProvider : public nsIDirectoryServiceProvider
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
XPCShellDirProvider() { }
~XPCShellDirProvider() { }
PRBool SetGREDir(const char *dir);
void ClearGREDir() { mGREDir = nsnull; }
private:
nsCOMPtr<nsILocalFile> mGREDir;
};
/***************************************************************************/ /***************************************************************************/
#ifdef JS_THREADSAFE #ifdef JS_THREADSAFE
@ -919,7 +941,7 @@ static int
usage(void) usage(void)
{ {
fprintf(gErrFile, "%s\n", JS_GetImplementationVersion()); fprintf(gErrFile, "%s\n", JS_GetImplementationVersion());
fprintf(gErrFile, "usage: xpcshell [-PswWxCij] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n"); fprintf(gErrFile, "usage: xpcshell [-g gredir] [-PswWxCij] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n");
return 2; return 2;
} }
@ -1548,9 +1570,39 @@ main(int argc, char **argv, char **envp)
gErrFile = stderr; gErrFile = stderr;
gOutFile = stdout; gOutFile = stdout;
gInFile = stdin; gInFile = stdin;
NS_LogInit();
nsCOMPtr<nsILocalFile> appFile;
rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appFile));
if (NS_FAILED(rv)) {
printf("Couldn't figure application file.\n");
return 1;
}
nsCOMPtr<nsIFile> appDir;
rv = appFile->GetParent(getter_AddRefs(appDir));
if (NS_FAILED(rv)) {
printf("Couldn't get application directory.\n");
return 1;
}
XPCShellDirProvider dirprovider;
if (argc > 1 && !strcmp(argv[1], "-g")) {
if (argc < 3)
return usage();
if (!dirprovider.SetGREDir(argv[2])) {
printf("SetGREDir failed.\n");
return 1;
}
argc -= 2;
argv += 2;
}
{ {
nsCOMPtr<nsIServiceManager> servMan; nsCOMPtr<nsIServiceManager> servMan;
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); rv = NS_InitXPCOM2(getter_AddRefs(servMan), appDir, &dirprovider);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
printf("NS_InitXPCOM failed!\n"); printf("NS_InitXPCOM failed!\n");
return 1; return 1;
@ -1716,9 +1768,49 @@ main(int argc, char **argv, char **envp)
bogus = nsnull; bogus = nsnull;
#endif #endif
appDir = nsnull;
appFile = nsnull;
dirprovider.ClearGREDir();
NS_LogTerm();
#ifdef XP_MACOSX #ifdef XP_MACOSX
FinishAutoreleasePool(); FinishAutoreleasePool();
#endif #endif
return result; return result;
} }
PRBool
XPCShellDirProvider::SetGREDir(const char *dir)
{
nsresult rv = XRE_GetFileFromPath(dir, getter_AddRefs(mGREDir));
return NS_SUCCEEDED(rv);
}
NS_IMETHODIMP_(nsrefcnt)
XPCShellDirProvider::AddRef()
{
return 2;
}
NS_IMETHODIMP_(nsrefcnt)
XPCShellDirProvider::Release()
{
return 1;
}
NS_IMPL_QUERY_INTERFACE1(XPCShellDirProvider, nsIDirectoryServiceProvider)
NS_IMETHODIMP
XPCShellDirProvider::GetFile(const char *prop, PRBool *persistent,
nsIFile* *result)
{
if (mGREDir && !strcmp(prop, NS_GRE_DIR)) {
*persistent = PR_TRUE;
NS_ADDREF(*result = mGREDir);
return NS_OK;
}
return NS_ERROR_FAILURE;
}