[m-rev.] for review: make it possible to run the installed Java version of the compiler

Julien Fischer jfischer at opturion.com
Fri Sep 4 11:42:14 AEST 2015


For review by anyone

----------------

Make it possible to run the installed Java version of the compiler.

Make it possible to run the installed Java version of the compiler by
installing versions of the wrapper scripts for 'mercury_compile' and
'mfilterjavac' that have the CLASSPATH set to point to the installed versions
of the standard library Java archives.

The wrapper script generated in the compiler directory is not suitable for this
because as generated it sets the CLASSPATH relative to the compiler directory,
not the installation directory.  Modifying that file is not a good idea since
that will mean that then the compiler cannot be executed in situ.  Instead we
provide a handwritten version of the wrapper script in the scripts directory
that is installed in place of the generated one.  Ditto for mfilterjavac.

While this does create a small maintenance problem, I think that any other
approach, for example, modifying the generation of wrapper scripts to account
for this, is going to be a larger maintenance problem.

TODO:
    - handle batch file launchers for Windows.
    - handle other exectuables in the Mercury system (although most of
      these are not so important in this context).

compiler/Mmakefile:
mfilterjavac/Mmakefile:
     Do not install generated wrapper scripts from these directories in the Java
     grade.

scripts/mercury_compile.sh-java:
scripts/mfilterjavac.sh-java:
     Java wrappers scripts for the installed versions of the compiler
     and mfilterjavac.

scripts/Mmakefile:
     In the Java grade install the wrapper scripts for the compiler and
     mfilterjavac from this directory.

Julien.

diff --git a/compiler/Mmakefile b/compiler/Mmakefile
index 9b00027..0e2fce7 100644
--- a/compiler/Mmakefile
+++ b/compiler/Mmakefile
@@ -261,11 +261,21 @@ install_mercury: install_compiler
  install_dirs:
  	-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)

+# If the compiler is built in the Java grade then we need to install Java
+# archive containing its class files (currently called top_level.jar), but
+# *not* the generated wrapper script 'mercury_compile' from this directory.
+# The latter will set the CLASSPATH variable relative to this directory and
+# won't work when moved to the installation directory.  Instead we use the
+# version of the wrapper script from the scripts directory and leave the
+# one here alone.
+#
  .PHONY: install_compiler
-install_compiler: mercury_compile install_dirs
-	cp `vpath_find mercury_compile$(EXT_FOR_EXE)` $(INSTALL_MERC_BIN_DIR)
  ifeq ($(findstring java,$(GRADE)),java)
+install_compiler: mercury_compile install_dirs
  	cp `vpath_find top_level.jar` $(INSTALL_MERC_BIN_DIR)
+else
+install_compiler: mercury_compile install_dirs
+	cp `vpath_find mercury_compile$(EXT_FOR_EXE)` $(INSTALL_MERC_BIN_DIR)
  endif

  #-----------------------------------------------------------------------------#
diff --git a/mfilterjavac/Mmakefile b/mfilterjavac/Mmakefile
index 01122af..f758c0c 100644
--- a/mfilterjavac/Mmakefile
+++ b/mfilterjavac/Mmakefile
@@ -135,13 +135,19 @@ realclean_local:

  # Installation target

+# See the comment above the 'install_compiler' target in compiler/Mmakefile
+# for the reasons why we handle the java grade specially here.
+#
  .PHONY: install
+ifeq ($(findstring java,$(GRADE)),java)
+install: mfilterjavac
+	-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
+	cp `vpath_find mfilterjavac.jar` $(INSTALL_MERC_BIN_DIR)
+else
  install: mfilterjavac
  	-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
  	cp `vpath_find mfilterjavac$(EXT_FOR_EXE)` \
  		$(INSTALL_MERC_BIN_DIR)/mfilterjavac$(EXT_FOR_EXE)
-ifeq ($(findstring java,$(GRADE)),java)
-	cp `vpath_find mfilterjavac.jar` $(INSTALL_MERC_BIN_DIR)
  endif

  #-----------------------------------------------------------------------------#
diff --git a/scripts/Mmakefile b/scripts/Mmakefile
index bbf2813..8cd6bf6 100644
--- a/scripts/Mmakefile
+++ b/scripts/Mmakefile
@@ -137,6 +137,12 @@ install_scripts: $(SCRIPTS) install_dirs
  	done
  	cp *.in *.sh-subr $(SCRIPTS) $(INSTALL_RECONF_DIR)/scripts
  	-rm -f $(INSTALL_BINDIR)/mmake.old
+ifeq ($(findstring java,$(GRADE)),java)
+	cp mercury_compile.sh-java $(INSTALL_MERC_BIN_DIR)/mercury_compile
+	cp mfilterjavac.sh-java $(INSTALL_MERC_BIN_DIR)/mfilterjavac
+	chmod a+x $(INSTALL_MERC_BIN_DIR)/mercury_compile \
+		$(INSTALL_MERC_BIN_DIR)/mfilterjavac
+endif

  .PHONY: install_config
  install_config: Mercury.config install_dirs
diff --git a/scripts/mercury_compile.sh-java b/scripts/mercury_compile.sh-java
index e69de29..9d31834 100755
--- a/scripts/mercury_compile.sh-java
+++ b/scripts/mercury_compile.sh-java
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# This script invokes the _installed_ version of the Mercury compiler when it
+# is built in the Java grade.
+
+DIR=${0%/*}
+DIR=$( cd "${DIR}" && pwd -P )
+case $WINDIR in
+   '') SEP=':' ;;
+   *)  SEP=';' ;;
+esac
+JARDIR="$DIR/../lib/mercury/lib/java"
+CLASSPATH="$DIR/top_level.jar"${SEP}$CLASSPATH${SEP}$JARDIR/mer_rt.jar${SEP}$JARDIR/mer_std.jar${SEP}$JARDIR/mer_browser.jar${SEP}$JARDIR/mer_mdbcomp.jar
+export CLASSPATH
+JAVA=${JAVA:-/usr/bin/java}
+exec "$JAVA" jmercury.top_level "$@"
diff --git a/scripts/mfilterjavac.sh-java b/scripts/mfilterjavac.sh-java
index e69de29..f818364 100755
--- a/scripts/mfilterjavac.sh-java
+++ b/scripts/mfilterjavac.sh-java
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# This script invokes the _installed_ version of the mfilterjavac when it
+# is built in the Java grade.
+
+DIR=${0%/*}
+DIR=$( cd "${DIR}" && pwd -P )
+case $WINDIR in
+   '') SEP=':' ;;
+   *)  SEP=';' ;;
+esac
+JARDIR="$DIR/../lib/mercury/lib/java"
+CLASSPATH="$DIR/mfilterjavac.jar"${SEP}$CLASSPATH${SEP}$JARDIR/mer_rt.jar${SEP}$JARDIR/mer_std.jar${SEP}$JARDIR/mer_browser.jar${SEP}$JARDIR/mer_mdbcomp.jar
+export CLASSPATH
+JAVA=${JAVA:-/usr/bin/java}
+exec "$JAVA" jmercury.mfilterjavac "$@"



More information about the reviews mailing list