Mercurial > hg > icepick
changeset 9:46216729b691
Add exec support and remove old scripts
author | Andrew John Hughes <gnu_andrew@member.fsf.org> |
---|---|
date | Fri, 18 Jan 2008 14:26:17 +0000 |
parents | e7085e31026c |
children | 15425b469aea |
files | ChangeLog Makefile.am autogen.sh configure.ac tools/apt.in tools/javac.in tools/javadoc.in tools/javah.in tools/javap.in tools/library.c tools/wrapper.c tools/wrapper.h |
diffstat | 12 files changed, 240 insertions(+), 256 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Jan 15 23:06:41 2008 +0000 +++ b/ChangeLog Fri Jan 18 14:26:17 2008 +0000 @@ -1,3 +1,30 @@ +2008-01-18 Andrew John Hughes <gnu_andrew@member.fsf.org> + + * Makefile.am: + Add tools subdirectory and remove old + script templates. + * tools/apt.in, + * tools/javac.in, + * tools/javadoc.in, + * tools/javah.in, + * tools/javap.in: + Removed. + * tools/library.c: + Moved to wrapper.c + * tools/wrapper.c: + Added exec support, and #ifdefed out + incomplete JNI support. + * tools/wrapper.h: + Function prototypes. + * autogen.sh: + Check for wrapper.c rather than + javadoc.in. + * configure.ac: + Likewise, and also generate + tools/Makefile as opposed to old + script files and check for a C + compiler. + 2008-01-15 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.am:
--- a/Makefile.am Tue Jan 15 23:06:41 2008 +0000 +++ b/Makefile.am Fri Jan 18 14:26:17 2008 +0000 @@ -2,6 +2,8 @@ ACLOCAL_AMFLAGS = -I m4 ${LOCAL_AUTORECONF_FLAGS} +SUBDIRS = tools + # version info for generated compiler JDK_VERSION = 1.7.0 @@ -17,11 +19,6 @@ JCOMPILER = echo "No compiler found" 1>&2; exit 1 endif -bin_SCRIPTS = tools/apt tools/javac tools/javah tools/javadoc tools/javap -bin_PROGRAMS = - -EXTRA_DIST = tools/apt.in tools/javac.in tools/javah.in tools/javadoc.in tools/javap.in - # All our example java source files OPENJDK_CLASSES = $(LANGTOOLS_SRC_DIR)/src/share/classes TOOLS_JAVA_FILES = $(OPENJDK_CLASSES)/com/sun/tools/apt/Main.java \
--- a/autogen.sh Tue Jan 15 23:06:41 2008 +0000 +++ b/autogen.sh Fri Jan 18 14:26:17 2008 +0000 @@ -8,7 +8,7 @@ cd $srcdir PROJECT=classpath TEST_TYPE=-f -FILE=tools/javadoc.in +FILE=tools/wrapper.c DIE=0
--- a/configure.ac Tue Jan 15 23:06:41 2008 +0000 +++ b/configure.ac Fri Jan 18 14:26:17 2008 +0000 @@ -7,7 +7,7 @@ dnl define([AC_CACHE_SAVE], )dnl AC_INIT([IcePick],[0.01],[distro-pkg-dev@openjdk.java.net],[icepick]) -AC_CONFIG_SRCDIR(tools/javadoc.in) +AC_CONFIG_SRCDIR(tools/wrapper.c) AC_CANONICAL_TARGET @@ -15,6 +15,8 @@ AM_INIT_AUTOMAKE([1.9.0 gnu std-options tar-ustar -Wno-portability]) AC_PREFIX_DEFAULT(/usr/local/icepick) +AC_PROG_CC + dnl ----------------------------------------------------------- dnl Sets the VM name for use in tool wrapper scripts dnl ----------------------------------------------------------- @@ -64,15 +66,6 @@ dnl output files dnl ----------------------------------------------------------- AC_CONFIG_FILES([Makefile -tools/apt -tools/javac -tools/javah -tools/javap -tools/javadoc]) +tools/Makefile]) -AC_CONFIG_COMMANDS([apt],[chmod 755 tools/apt]) -AC_CONFIG_COMMANDS([javac],[chmod 755 tools/javac]) -AC_CONFIG_COMMANDS([javah],[chmod 755 tools/javah]) -AC_CONFIG_COMMANDS([javap],[chmod 755 tools/javap]) -AC_CONFIG_COMMANDS([javadoc],[chmod 755 tools/javadoc]) AC_OUTPUT
--- a/tools/apt.in Tue Jan 15 23:06:41 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#!/bin/sh - -## Copyright (C) 2007 Andrew John Hughes -## -## This file is a part of IcePick. -## -## IcePick is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or (at -## your option) any later version. -## -## IcePick is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with IcePick; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -## USA. -## -## A simple shell script to launch the APT tool. -## - -prefix=@prefix@ -datarootdir=@datarootdir@ -tools_dir=${prefix}/lib -tools_cp=${tools_dir}/tools.jar - -exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" com.sun.tools.apt.Main "$@"
--- a/tools/javac.in Tue Jan 15 23:06:41 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#!/bin/sh - -## Copyright (C) 2007 Andrew John Hughes -## -## This file is a part of IcePick. -## -## IcePick is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or (at -## your option) any later version. -## -## IcePick is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with IcePick; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -## USA. -## -## A simple shell script to launch the javac tool. -## - -prefix=@prefix@ -datarootdir=@datarootdir@ -tools_dir=${prefix}/lib -tools_cp=${tools_dir}/tools.jar - -exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" com.sun.tools.javac.Main "$@"
--- a/tools/javadoc.in Tue Jan 15 23:06:41 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#!/bin/sh - -## Copyright (C) 2007 Andrew John Hughes -## -## This file is a part of IcePick. -## -## IcePick is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or (at -## your option) any later version. -## -## IcePick is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with IcePick; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -## USA. -## -## A simple shell script to launch the javadoc tool. -## - -prefix=@prefix@ -datarootdir=@datarootdir@ -tools_dir=${prefix}/lib -tools_cp=${tools_dir}/tools.jar - -exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" com.sun.tools.javadoc.Main "$@"
--- a/tools/javah.in Tue Jan 15 23:06:41 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#!/bin/sh - -## Copyright (C) 2007 Andrew John Hughes -## -## This file is a part of IcePick. -## -## IcePick is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or (at -## your option) any later version. -## -## IcePick is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with IcePick; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -## USA. -## -## A simple shell script to launch the javah tool. - -prefix=@prefix@ -datarootdir=@datarootdir@ -tools_dir=${prefix}/lib -tools_cp=${tools_dir}/tools.jar - -exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" com.sun.tools.javah.Main "$@"
--- a/tools/javap.in Tue Jan 15 23:06:41 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#!/bin/sh - -## Copyright (C) 2007 Andrew John Hughes -## -## This file is a part of IcePick. -## -## IcePick is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or (at -## your option) any later version. -## -## IcePick is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with IcePick; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -## USA. -## -## A simple shell script to launch the javap tool. - -prefix=@prefix@ -datarootdir=@datarootdir@ -tools_dir=${prefix}/lib -tools_cp=${tools_dir}/tools.jar - -exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" sun.tools.javap.Main "$@"
--- a/tools/library.c Tue Jan 15 23:06:41 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -#include <jni.h> -#include <string.h> -#include <stdlib.h> - -int main(int argc, char** argv) -{ - JNIEnv *env; - JavaVM *vm; - JavaVMInitArgs vm_args; - JavaVMOption options[argc-1]; - char** read_pos; - char** write_pos; - int a; - jint vm_count; - jint main_count; - jint res; - jclass cls; - jmethodID main_method; - jclass string_class; - jobjectArray args; - - vm_args.version = JNI_VERSION_1_2; - vm_args.ignoreUnrecognized = JNI_TRUE; - read_pos = argv + 1; - write_pos = argv; - for (a = 0; a < argc - 1; ++a) - { - if (strncmp(*read_pos, "-J", (size_t)2) == 0) - { - options[vm_count].optionString = *read_pos + 2; - ++vm_count; - } - else - { - *write_pos = *read_pos; - ++write_pos; - ++main_count; - } - ++read_pos; - } - for (a = 0; a < main_count; ++a) - printf("main option %d: %s\n", a, argv[a]); - for (a = 0; a < vm_count; ++a) - printf("vm option %d: %s\n", a, options[a].optionString); - vm_args.options = options; - vm_args.nOptions = vm_count; - - res = JNI_CreateJavaVM(&vm, (void**)&env, &vm_args); - if (res < 0) - { - fprintf(stderr, "Couldn't create Java VM\n"); - exit(-1); - } - cls = (*env)->FindClass(env, "CLASS_NAME"); - if (cls == NULL) { - goto destroy; - } - - main_method = (*env)->GetStaticMethodID(env, cls, "main", - "([Ljava/lang/String;)V"); - if (main_method == NULL) { - goto destroy; - } - - string_class = (*env)->FindClass(env, "java/lang/String"); - args = (*env)->NewObjectArray(env, main_count, string_class, NULL); - if (args == NULL) { - goto destroy; - } - - for (a = 0; a < main_count; ++a) - { - jstring jstr; - - jstr = (*env)->NewStringUTF(env, *argv); - if (jstr == NULL) - goto destroy; - ++argv; - (*env)->SetObjectArrayElement(env, args, a, jstr); - } - - (*env)->CallStaticVoidMethod(env, cls, main_method, args); - - destroy: - if ((*env)->ExceptionOccurred(env)) - (*env)->ExceptionDescribe(env); - (*vm)->DestroyJavaVM(vm); - - return 0; -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/wrapper.c Fri Jan 18 14:26:17 2008 +0000 @@ -0,0 +1,167 @@ +/* wrapper.c - IcePick tools wrapper + Copyright (C) 2008 Andrew John Hughes + +This file is part of IcePick. + +IcePick is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcePick is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcePick; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. +*/ + +#include "wrapper.h" + +#ifdef USE_JNI +int invoke_via_jni(char** vm_options, int vm_count, + char** main_options, int main_count) +{ + JNIEnv *env; + JavaVM *vm; + JavaVMInitArgs vm_args; + JavaVMOption options[vm_count]; + jint res; + jclass cls; + jmethodID main_method; + jclass string_class; + jobjectArray args; + int a; + + for (a = 0; a < vm_count; ++a) + options[a].optionString = *vm_options++; +#ifdef DEBUG + for (a = 0; a < vm_count; ++a) + printf("vm option %d: %s\n", a, options[a].optionString); +#endif + + vm_args.version = JNI_VERSION_1_2; + vm_args.ignoreUnrecognized = JNI_TRUE; + vm_args.options = options; + vm_args.nOptions = vm_count; + + res = JNI_CreateJavaVM(&vm, (void**)&env, &vm_args); + if (res < 0) + { + fprintf(stderr, "Couldn't create Java VM\n"); + exit(-1); + } + cls = (*env)->FindClass(env, "CLASS_NAME"); + if (cls == NULL) { + goto destroy; + } + + main_method = (*env)->GetStaticMethodID(env, cls, "main", + "([Ljava/lang/String;)V"); + if (main_method == NULL) { + goto destroy; + } + + string_class = (*env)->FindClass(env, "java/lang/String"); + args = (*env)->NewObjectArray(env, main_count, string_class, NULL); + if (args == NULL) { + goto destroy; + } + + for (a = 0; a < main_count; ++a) + { + jstring jstr; + + jstr = (*env)->NewStringUTF(env, *argv); + if (jstr == NULL) + goto destroy; + ++argv; + (*env)->SetObjectArrayElement(env, args, a, jstr); + } + + (*env)->CallStaticVoidMethod(env, cls, main_method, args); + + destroy: + if ((*env)->ExceptionOccurred(env)) + (*env)->ExceptionDescribe(env); + return (*vm)->DestroyJavaVM(vm); +} +#endif + +int invoke_via_exec(char** vm_options, int vm_count, + char** main_options, int main_count) +{ + char* argv[vm_count + main_count + 5]; + char** argv_pos; + int a; + + argv_pos = argv; + *argv_pos++ = (char*) VM_BINARY; + *argv_pos++ = (char*) "-classpath"; + *argv_pos++ = (char*) TOOLS_CP; + + for (a = 0; a < vm_count; ++a) + *argv_pos++ = *vm_options++; + + *argv_pos++ = (char*) MAIN_METHOD; + + for (a = 0; a < main_count; ++a) + *argv_pos++ = *main_options++; + +#ifdef DEBUG + for (a = 0; a < vm_count + main_count + 4; ++a) + printf("cmd line option %d: %s\n", a, argv[a]); +#endif + + *argv_pos++ = NULL; + + int res = execvp(VM_BINARY, argv); + if (res) + perror("Error invoking VM"); + return res; +} + +int main(int argc, char** argv) +{ + char** read_pos; + char** write_pos; + int a; + int vm_count = 0; + int main_count = 0; + char* vm_opt[argc-1]; + + read_pos = argv + 1; + write_pos = argv; + for (a = 0; a < argc - 1; ++a) + { + if (strncmp(*read_pos, "-J", (size_t)2) == 0) + { + vm_opt[vm_count] = *read_pos + 2; + ++vm_count; + } + else + { + *write_pos = *read_pos; + ++write_pos; + ++main_count; + } + ++read_pos; + } +#ifdef DEBUG + for (a = 0; a < main_count; ++a) + printf("main option %d: %s\n", a, *argv++); + for (a = 0; a < vm_count; ++a) + printf("vm option %d: %s\n", a, vm_opt[a]); +#endif + +#ifdef USE_JNI + return invoke_via_jni(vm_opt, vm_count, argv, main_count); +#else + return invoke_via_exec(vm_opt, vm_count, argv, main_count); +#endif + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/wrapper.h Fri Jan 18 14:26:17 2008 +0000 @@ -0,0 +1,39 @@ +/* wrapper.h - Declarations for IcePick tools wrapper + Copyright (C) 2008 Andrew John Hughes + +This file is part of IcePick. + +IcePick is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcePick is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcePick; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. +*/ + +#ifndef __WRAPPER_H__ +#define __WRAPPER_H__ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int invoke_via_exec(char** vm_options, int vm_count, + char** main_options, int main_count); + +#ifdef USE_JNI +#include <jni.h> +int invoke_via_jni(char** vm_options, int vm_count, + char** main_options, int main_count); +#endif + +#endif /* __WRAPPER_H__ */