Bug 333618 - Use xpidl for generating Java interfaces. r=timeless/bsmedberg, sr=bsmedberg.

This commit is contained in:
pedemont%us.ibm.com 2006-08-28 15:24:32 +00:00
parent 71e69147fc
commit d47f09f9df
9 changed files with 709 additions and 269 deletions

View File

@ -466,15 +466,10 @@ ifdef ENABLE_TESTS
tier_99_dirs += tools/test-harness
endif
# Don't build the Java interfaces when cross compiling since that depends on the
# program GenerateJavaInterfaces (which doesn't work when cross compiling).
# This ifndef can be removed when bug 333618 is checked in.
ifndef CROSS_COMPILE
# This should be built last, after all IDL files in the tree have been processed
ifdef MOZ_JAVAXPCOM
tier_99_dirs += extensions/java/xpcom/interfaces
endif
endif
default alldep all::
$(RM) -rf $(DIST)/sdk

View File

@ -490,6 +490,11 @@ XPIDL_COMPILE = $(CYGWIN_WRAPPER) $(LIBXUL_DIST)/bin/xpidl$(BIN_SUFFIX)
XPIDL_LINK = $(CYGWIN_WRAPPER) $(LIBXUL_DIST)/bin/xpt_link$(BIN_SUFFIX)
endif
# Java macros
JAVA_GEN_DIR = _javagen
JAVA_DIST_DIR = $(DEPTH)/$(JAVA_GEN_DIR)
JAVA_IFACES_PKG_NAME = org/mozilla/xpcom
REQ_INCLUDES = $(foreach d,$(REQUIRES),-I$(DIST)/include/$d) -I$(DIST)/include
ifdef LIBXUL_SDK
REQ_INCLUDES_SDK = $(foreach d,$(REQUIRES),-I$(LIBXUL_SDK)/include/$d) -I$(LIBXUL_SDK)/include

View File

@ -1279,6 +1279,13 @@ $(SDK_PUBLIC) $(PUBLIC)::
@if test ! -d $@; then echo Creating $@; rm -rf $@; $(NSINSTALL) -D $@; else true; fi
endif
ifdef MOZ_JAVAXPCOM
ifneq ($(XPIDLSRCS)$(SDK_XPIDLSRCS),)
$(JAVA_DIST_DIR)::
$(NSINSTALL) -D $@
endif
endif
ifneq ($(XPI_NAME),)
export::
@if test ! -d $(FINAL_TARGET); then echo Creating $(FINAL_TARGET); rm -fr $(FINAL_TARGET); $(NSINSTALL) -D $(FINAL_TARGET); else true; fi
@ -1498,6 +1505,45 @@ endif
endif # SDK_XPIDLSRCS
ifdef MOZ_JAVAXPCOM
ifneq ($(XPIDLSRCS)$(SDK_XPIDLSRCS),)
JAVA_XPIDLSRCS = $(XPIDLSRCS) $(SDK_XPIDLSRCS)
# A single IDL file can contain multiple interfaces, which result in multiple
# Java interface files. So use hidden dependency files.
JAVADEPFILES = $(addprefix $(JAVA_GEN_DIR)/.,$(JAVA_XPIDLSRCS:.idl=.java.pp))
$(JAVA_GEN_DIR):
$(NSINSTALL) -D $@
GARBAGE_DIRS += $(JAVA_GEN_DIR)
# generate .java files into _javagen/[package name dirs]
_JAVA_GEN_DIR = $(JAVA_GEN_DIR)/$(JAVA_IFACES_PKG_NAME)
$(_JAVA_GEN_DIR):
$(NSINSTALL) -D $@
$(JAVA_GEN_DIR)/.%.java.pp: %.idl $(XPIDL_COMPILE) $(_JAVA_GEN_DIR)
$(REPORT_BUILD)
$(ELOG) $(XPIDL_COMPILE) -m java -w -I$(srcdir) -I$(IDL_DIR) -o $(_JAVA_GEN_DIR)/$* $(_VPATH_SRCS)
@touch $@
# "Install" generated Java interfaces. We segregate them based on the XPI_NAME.
# If XPI_NAME is not set, install into the "default" directory.
ifneq ($(XPI_NAME),)
JAVA_INSTALL_DIR = $(JAVA_DIST_DIR)/$(XPI_NAME)
else
JAVA_INSTALL_DIR = $(JAVA_DIST_DIR)/default
endif
export:: $(JAVA_DIST_DIR) $(JAVADEPFILES)
cd $(JAVA_GEN_DIR) && find . -name "*.java" \
-exec sh -c "dirname {} | sed 's/^\.\///' | xargs -I % $(NSINSTALL) $(IFLAGS1) {} ../$(JAVA_INSTALL_DIR)/%" \;
endif # XPIDLSRCS || SDK_XPIDLSRCS
endif # MOZ_JAVAXPCOM
################################################################################
# Copy each element of EXTRA_COMPONENTS to $(FINAL_TARGET)/components
ifdef EXTRA_COMPONENTS

View File

@ -46,9 +46,5 @@ DIRS = src
TOOL_DIRS = glue
ifndef CROSS_COMPILE
TOOL_DIRS += tools/genifaces
endif
include $(topsrcdir)/config/rules.mk

View File

@ -56,68 +56,53 @@ JAVA_SRCS = \
$(srcdir)/VersionComparator.java \
$(NULL)
GEN_JAVA_SRCS = \
IXPCOMError.java \
$(NULL)
# install jars into SDK
SDK_LIBRARY = $(JARFILE) $(JARFILE_SRC)
GARBAGE += $(JARFILE) $(JARFILE_SRC) $(GEN_JAVA_SRCS) java.files .done
GARBAGE_DIRS += _javagen org
GARBAGE += $(JARFILE) $(JARFILE_SRC) java.files
GARBAGE_DIRS += org
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH),WINNT)
RUN =
OUTPUT_DIR = $(shell cygpath -w $(CURDIR)/_javagen/org/mozilla/xpcom)
else
RUN = $(DIST)/bin/run-mozilla.sh
OUTPUT_DIR = $(CURDIR)/_javagen/org/mozilla/xpcom
endif
# XXX Need to copy Java source files to correct directory structure, until
# bug 328901 is fixed.
_javagen/org/mozilla/xpcom/.iface_done: $(JAVA_SRCS) $(DIST)/bin/GenerateJavaInterfaces$(BIN_SUFFIX)
@if test ! -d _javagen/org/mozilla/xpcom; then \
touch .done; \
$(INSTALL) -m 644 .done _javagen/org/mozilla/xpcom; \
fi
JAVA_SRCS_DIR = _java/org/mozilla/xpcom
GARBAGE_DIRS += _java
$(JAVA_SRCS_DIR)::
$(NSINSTALL) -D $@
$(JAVA_SRCS_DIR)/Mozilla.java: $(JAVA_SRCS_DIR)
@echo Copying Java source files
@$(INSTALL) -m 644 $(JAVA_SRCS) \
_javagen/org/mozilla/xpcom
@$(INSTALL) -m 644 $(GEN_JAVA_SRCS) _javagen/org/mozilla/xpcom
@echo Generating Java interface files
$(RUN) $(DIST)/bin/GenerateJavaInterfaces$(BIN_SUFFIX) -d $(OUTPUT_DIR)
@touch $@
$(INSTALL) -m 644 $(JAVA_SRCS) $<
$(JAVA_SRCS_DIR)/IXPCOMError.java: $(topsrcdir)/xpcom/base/nsError.h gen-nsError.pl Makefile Makefile.in $(JAVA_SRCS_DIR)
$(PERL) $(srcdir)/../gen-nsError.pl < $< > $@
# Don't include the interface nsIPref, since it depends on the obsolete
# interface nsIFileSpec.
IGNORE_IFACES_NAMES = nsIPref
ifneq (,$(IGNORE_IFACES_NAMES))
IGNORE_IFACES = $(patsubst %, ! -name "*%.java", $(IGNORE_IFACES_NAMES))
endif
# Using the temporary "java.files" avoids an "argument list too long"
# error on Windows when using *.java
org/mozilla/xpcom/.class_done: _javagen/org/mozilla/xpcom/.iface_done
@echo Compiling Java interface classes
find _javagen -name "*.java" > java.files
$(JAVAC) $(JAVAC_FLAGS) -classpath . -d . -sourcepath _javagen @java.files
@touch $@
org/mozilla/xpcom/Mozilla.class: $(JAVA_SRCS_DIR)/IXPCOMError.java $(JAVA_SRCS_DIR)/Mozilla.java
@echo Compiling Java classes
find _java -name "*.java" > java.files
find $(JAVA_DIST_DIR)/default -name "*.java" $(IGNORE_IFACES) >> java.files
$(JAVAC) $(JAVAC_FLAGS) -classpath . -d . -sourcepath _java -sourcepath $(JAVA_DIST_DIR)/default @java.files
$(JARFILE): org/mozilla/xpcom/.class_done Makefile
$(JARFILE): org/mozilla/xpcom/Mozilla.class Makefile
$(JAR) cf $@ org
$(JARFILE_SRC): $(JARFILE)
$(JAR) cf $@ -C _javagen org
IXPCOMError.java: $(topsrcdir)/xpcom/base/nsError.h gen-nsError.pl Makefile Makefile.in
$(PERL) $(srcdir)/../gen-nsError.pl < $< > $@
export:: IXPCOMError.java
# Temporarily copy these not only to dist/sdk/lib but to dist/bin/sdk/lib
TEMP_SDK_DIR = $(DIST)/bin/sdk/lib
$(TEMP_SDK_DIR)::
$(NSINSTALL) -D $@
export:: $(JARFILE) $(JARFILE_SRC) $(TEMP_SDK_DIR)
$(INSTALL) $(IFLAGS2) $^
$(JAR) cf $@ -C _java org
$(JAR) uf $@ -C $(JAVA_DIST_DIR)/default org
$(ZIP) -d $@ $(patsubst %, $(JAVA_IFACES_PKG_NAME)/%.java, $(IGNORE_IFACES_NAMES))
# Build the implementation Java classes, which depend on these interfaces
export::
export:: $(JARFILE) $(JARFILE_SRC)
$(MAKE) -C ../src jarfile

View File

@ -111,7 +111,7 @@ _javagen/org/mozilla/xpcom/internal/.iface_done: $(JAVA_SRCS)
# Using the temporary "java.files" avoids an "argument list too long"
# error on Windows when using *.java
org/mozilla/xpcom/internal/.class_done: _javagen/org/mozilla/xpcom/internal/.iface_done
org/mozilla/xpcom/internal/.class_done: _javagen/org/mozilla/xpcom/internal/.iface_done ../interfaces/MozillaInterfaces.jar
@echo Compiling Java implementation classes
find _javagen -name "*.java" > java.files
$(JAVAC) $(JAVAC_FLAGS) \

View File

@ -128,6 +128,7 @@ typedef struct IncludePathEntry {
struct TreeState {
FILE *file;
char *filename;
/* Maybe supplied by -o. Not related to (g_)basename from string.h or glib */
char *basename;
IDL_ns ns;
@ -137,6 +138,13 @@ struct TreeState {
void *priv; /* mode-private data */
};
struct java_priv_data {
GHashTable *typedefTable;
GHashTable *keywords;
char *filename;
GHashTable *nonIDLIfaces;
};
/*
* Process an IDL file, generating InterfaceInfo, documentation and headers as
* appropriate.

View File

@ -41,6 +41,7 @@
*/
#include "xpidl.h"
#include <limits.h>
#ifdef XP_MAC
#include <stat.h>
@ -765,12 +766,17 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
real_outname = g_strdup_printf("%s.%s", out_basename, mode->suffix);
}
/* Use binary write for typelib mode */
fopen_mode = (strcmp(mode->mode, "typelib")) ? "w" : "wb";
state.file = fopen(real_outname, fopen_mode);
if (!state.file) {
perror("error opening output file");
return 0;
/* don't create/open file here for Java */
if (strcmp(mode->mode, "java") == 0) {
state.filename = real_outname;
} else {
/* Use binary write for typelib mode */
fopen_mode = (strcmp(mode->mode, "typelib")) ? "w" : "wb";
state.file = fopen(real_outname, fopen_mode);
if (!state.file) {
perror("error opening output file");
return 0;
}
}
} else {
state.file = stdout;
@ -784,8 +790,11 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
if (emitter->emit_epilog)
emitter->emit_epilog(&state);
if (state.file != stdout)
fclose(state.file);
if (strcmp(mode->mode, "java") != 0) {
if (state.file != stdout)
fclose(state.file);
}
free(state.basename);
free(outname);
g_hash_table_foreach(callback_state.already_included, free_ghash_key, NULL);
@ -797,16 +806,18 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
if (top)
IDL_tree_free(top);
if (real_outname != NULL) {
/*
* Delete partial output file on failure. (Mac does this in the plugin
* driver code, if the compiler returns failure.)
*/
if (strcmp(mode->mode, "java") != 0) {
if (real_outname != NULL) {
/*
* Delete partial output file on failure. (Mac does this in the
* plugin driver code, if the compiler returns failure.)
*/
#if defined(XP_UNIX) || defined(XP_WIN)
if (!ok)
unlink(real_outname);
if (!ok)
unlink(real_outname);
#endif
g_free(real_outname);
g_free(real_outname);
}
}
return ok;

File diff suppressed because it is too large Load Diff