This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: -classpath switch patch
- From: Per Bothner <per at bothner dot com>
- To: Per Bothner <per at bothner dot com>
- Cc: Nic Ferrier <nferrier at tapsellferrier dot co dot uk>, java-patches at gcc dot gnu dot org
- Date: Fri, 22 Feb 2002 21:32:10 -0800
- Subject: Re: -classpath switch patch
- References: <3C70D730.4000604@jatak.com> <3C7142F0.6050003@bothner.com> <3C7169EE.4040903@waitaki.otago.ac.nz> <87664u1kfx.fsf_-_@tf1.tapsellferrier.co.uk> <3C7185DB.6040301@waitaki.otago.ac.nz> <3C718A7F.1060501@bothner.com> <873czy1gxg.fsf@tf1.tapsellferrier.co.uk> <15473.41698.385817.823287@makita.cygnus.com> <87r8niz2pp.fsf@tf1.tapsellferrier.co.uk> <3C71A5AF.2010608@waitaki.otago.ac.nz> <15473.43041.412371.618641@makita.cygnus.com> <87k7t8xmmb.fsf@tf1.tapsellferrier.co.uk> <87n0y4knnd.fsf@creche.redhat.com> <3C76F474.9090105@bothner.com>
I took a look at jcf-path.c, and one thing led to another.
Here is my patch to fix path processing. It supports
--CLASSPATH as a synonym for --classpath; --bootclasspath,
and --wholeclasspath in place of the current --CLASSPATH.
I also fixed a logic problem, where jcf_path_init was
called *after* option processing, not before. Finally,
I changed "." to not be part of the "system" or built-in
class, but as an default for the non-builtin path, following
what JDK does.
One question I have is whether this is overkill. Specifically,
is there any real reason to have --wholeclasspath? I tend to
think not, unless there is some signicant difference between
--wholeclasspath PATH and --classpath PATH--bootclasspath "".
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
2002-02-22 Per Bothner <per@bothner.com>
Make --CLASSPATH by a synonym for --classpath and -classpath.
Implement --bootclasspath and --wholeclasspath.
* jcf-path.c (classpath_u): Renamed static to classpath_user.
(classpath_while): Renamed static to classpath_whole.
(init_done): Does to make sure jcf_path_initis only done once.
(jcf_path_CLASSPATH_arg): Just call jcf_path_classpath_arg.
(jcf_path_bootclasspath_arg): New function.
(jcf_path_wholeclasspath_arg): New function - does what
jcf_path_CLASSPATH_arg used to do.
* jcf.h (jcf_path_bootclasspath_arg, jcf_path_wholeclasspath_arg):
New declarations.
* jvspec.c (jvgenmain_spec): Also accept -fbootclasspath*
and -fwholeclasspath*.
(lang_specific_driver): Translate -bootclasspath and -wholeclasspath.
lang-options.h: Add --bootclasspath and --wholeclasspath.
* lang.c (decode_lang_options): Do jcf_path_init first.
Also process -fbootclasspath and -wholeclasspath.
* gjavah.c: Also handle --bootclasspath and --wholeclasspath.
* jcf-dump.c: Also handle --bootclasspath and --wholeclasspath.
"." is not part of system path, but is the defalt for --classpath.
* jcf-path.c (jcf_path_init): Don't add "." to sys_dirs.
(jcf_path_seal): Add "." if no CLASSPATH specified.
Note: Do we want --wholeclasspath?
Note: Also need to update gcj.texi.
Note: gcc.c needs separate patch and ChangeLog entry.
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.293
diff -u -p -r1.293 gcc.c
--- gcc.c 2002/02/20 07:24:06 1.293
+++ gcc.c 2002/02/23 04:28:38
@@ -908,6 +908,8 @@ static const struct option_map option_ma
{"--assemble", "-S", 0},
{"--assert", "-A", "a"},
{"--classpath", "-fclasspath=", "aj"},
+ {"--bootclasspath", "-fbootclasspath=", "aj"},
+ {"--wholeclasspath", "-fwholeclasspath=", "aj"},
{"--CLASSPATH", "-fCLASSPATH=", "aj"},
{"--comments", "-C", 0},
{"--compile", "-c", 0},
Index: java/gjavah.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/gjavah.c,v
retrieving revision 1.84
diff -u -p -r1.84 gjavah.c
--- gjavah.c 2002/02/20 23:12:24 1.84
+++ gjavah.c 2002/02/23 04:28:39
@@ -2101,24 +2101,28 @@ DEFUN(process_file, (jcf, out),
/* This is used to mark options with no short value. */
#define LONG_OPT(Num) ((Num) + 128)
-#define OPT_classpath LONG_OPT (0)
-#define OPT_CLASSPATH LONG_OPT (1)
-#define OPT_HELP LONG_OPT (2)
-#define OPT_TEMP LONG_OPT (3)
-#define OPT_VERSION LONG_OPT (4)
-#define OPT_PREPEND LONG_OPT (5)
-#define OPT_FRIEND LONG_OPT (6)
-#define OPT_ADD LONG_OPT (7)
-#define OPT_APPEND LONG_OPT (8)
-#define OPT_M LONG_OPT (9)
-#define OPT_MM LONG_OPT (10)
-#define OPT_MG LONG_OPT (11)
-#define OPT_MD LONG_OPT (12)
-#define OPT_MMD LONG_OPT (13)
+#define OPT_classpath LONG_OPT (0)
+#define OPT_bootclasspath LONG_OPT (1)
+#define OPT_wholeclasspath LONG_OPT (2)
+#define OPT_CLASSPATH LONG_OPT (3)
+#define OPT_HELP LONG_OPT (4)
+#define OPT_TEMP LONG_OPT (5)
+#define OPT_VERSION LONG_OPT (6)
+#define OPT_PREPEND LONG_OPT (7)
+#define OPT_FRIEND LONG_OPT (8)
+#define OPT_ADD LONG_OPT (9)
+#define OPT_APPEND LONG_OPT (10)
+#define OPT_M LONG_OPT (11)
+#define OPT_MM LONG_OPT (12)
+#define OPT_MG LONG_OPT (13)
+#define OPT_MD LONG_OPT (14)
+#define OPT_MMD LONG_OPT (15)
static const struct option options[] =
{
{ "classpath", required_argument, NULL, OPT_classpath },
+ { "bootclasspath", required_argument, NULL, OPT_bootclasspath },
+ { "wholeclasspath" required_argument, NULL, OPT_wholeclasspath },
{ "CLASSPATH", required_argument, NULL, OPT_CLASSPATH },
{ "help", no_argument, NULL, OPT_HELP },
{ "stubs", no_argument, &stubs, 1 },
@@ -2158,10 +2162,11 @@ help ()
printf (" -friend TEXT Insert TEXT as `friend' declaration\n");
printf (" -prepend TEXT Insert TEXT before start of class\n");
printf ("\n");
- printf (" --CLASSPATH PATH Set path to find .class files, overriding\n\
- built-in class path\n");
printf (" --classpath PATH Set path to find .class files\n");
printf (" -IDIR Append directory to class path\n");
+ printf (" --bootclasspath PATH Override built-in class path\n");
+ printf (" --wholeclasspath PATH Set path to find .class files, overriding\n\
+ built-in class path\n");
printf (" -d DIRECTORY Set output directory name\n");
printf (" -o FILE Set output file name\n");
printf (" -td DIRECTORY Set temporary directory name\n");
@@ -2239,6 +2244,14 @@ DEFUN(main, (argc, argv),
case OPT_classpath:
jcf_path_classpath_arg (optarg);
+ break;
+
+ case OPT_bootclasspath:
+ jcf_path_bootclasspath_arg (optarg);
+ break;
+
+ case OPT_wholeclasspath:
+ jcf_path_wholeclasspath_arg (optarg);
break;
case OPT_CLASSPATH:
Index: java/jcf-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-dump.c,v
retrieving revision 1.42
diff -u -p -r1.42 jcf-dump.c
--- jcf-dump.c 2002/02/20 23:12:24 1.42
+++ jcf-dump.c 2002/02/23 04:28:40
@@ -773,15 +773,19 @@ DEFUN(process_class, (jcf),
/* This is used to mark options with no short value. */
#define LONG_OPT(Num) ((Num) + 128)
-#define OPT_classpath LONG_OPT (0)
-#define OPT_CLASSPATH LONG_OPT (1)
-#define OPT_HELP LONG_OPT (2)
-#define OPT_VERSION LONG_OPT (3)
-#define OPT_JAVAP LONG_OPT (4)
+#define OPT_classpath LONG_OPT (0)
+#define OPT_bootclasspath LONG_OPT (1)
+#define OPT_wholeclasspath LONG_OPT (2)
+#define OPT_CLASSPATH LONG_OPT (3)
+#define OPT_HELP LONG_OPT (4)
+#define OPT_VERSION LONG_OPT (5)
+#define OPT_JAVAP LONG_OPT (6)
static const struct option options[] =
{
{ "classpath", required_argument, NULL, OPT_classpath },
+ { "bootclasspath", required_argument, NULL, OPT_bootclasspath },
+ { "wholeclasspath",required_argument, NULL, OPT_wholeclasspath },
{ "CLASSPATH", required_argument, NULL, OPT_CLASSPATH },
{ "help", no_argument, NULL, OPT_HELP },
{ "verbose", no_argument, NULL, 'v' },
@@ -806,10 +810,11 @@ help ()
printf (" -c Disassemble method bodies\n");
printf (" --javap Generate output in `javap' format\n");
printf ("\n");
- printf (" --CLASSPATH PATH Set path to find .class files, overriding\n\
- built-in class path\n");
printf (" --classpath PATH Set path to find .class files\n");
printf (" -IDIR Append directory to class path\n");
+ printf (" --bootclasspath PATH Override built-in class path\n");
+ printf (" --wholeclasspath PATH Set path to find .class files, overriding\n\
+ built-in class path\n");
printf (" -o FILE Set output file name\n");
printf ("\n");
printf (" --help Print this help, then exit\n");
@@ -874,6 +879,14 @@ DEFUN(main, (argc, argv),
case OPT_classpath:
jcf_path_classpath_arg (optarg);
+ break;
+
+ case OPT_bootclasspath:
+ jcf_path_bootclasspath_arg (optarg);
+ break;
+
+ case OPT_wholeclasspath:
+ jcf_path_wholeclasspath_arg (optarg);
break;
case OPT_CLASSPATH:
Index: java/jcf-path.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-path.c,v
retrieving revision 1.18
diff -u -p -r1.18 jcf-path.c
--- jcf-path.c 2002/02/20 23:12:24 1.18
+++ jcf-path.c 2002/02/23 04:28:40
@@ -1,6 +1,6 @@
/* Handle CLASSPATH, -classpath, and path searching.
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -72,7 +72,9 @@ static void add_path PARAMS ((struct ent
built-in system directory (only libgcj.jar)
CLASSPATH environment variable
-classpath option overrides $CLASSPATH
- -CLASSPATH option overrides $CLASSPATH, -classpath, and built-in
+ -CLASSPATH option is a synonym for -classpath (for compatibility)
+ -wholeclasspath overrides $CLASSPATH, -classpath, and built-in
+ -bootclasspath overrides built-in
-I prepends path to list
We implement this by keeping several path lists, and then simply
@@ -85,10 +87,10 @@ static struct entry *include_dirs;
static struct entry *classpath_env;
/* This holds the -classpath command-line option. */
-static struct entry *classpath_u;
+static struct entry *classpath_user;
-/* This holds the -CLASSPATH command-line option. */
-static struct entry *classpath_l;
+/* This holds the -wholeclasspath command-line option. */
+static struct entry *classpath_whole;
/* This holds the default directories. Some of these will have the
"system" flag set. */
@@ -222,6 +224,8 @@ add_path (entp, cp, is_system)
}
}
+static int init_done = 0;
+
/* Initialize the path module. */
void
jcf_path_init ()
@@ -231,7 +235,9 @@ jcf_path_init ()
struct stat stat_b;
int found = 0, len;
- add_entry (&sys_dirs, ".", 0);
+ if (init_done)
+ return;
+ init_done = 1;
sep[0] = DIR_SEPARATOR;
sep[1] = '\0';
@@ -285,15 +291,25 @@ jcf_path_init ()
}
/* Call this when -CLASSPATH is seen on the command line.
+ Backwardscompatibility - same as -classpath.
+*/
+void
+jcf_path_CLASSPATH_arg (path)
+ const char *path;
+{
+ jcf_path_classpath_arg (path);
+}
+
+/* Call this when -wholeclasspath is seen on the command line.
This is the override-all switch, even the built in classes
are overridden.
*/
void
-jcf_path_CLASSPATH_arg (path)
+jcf_path_wholeclasspath_arg (path)
const char *path;
{
- free_entry (&classpath_l);
- add_path (&classpath_l, path, 0);
+ free_entry (&classpath_whole);
+ add_path (&classpath_whole, path, 0);
}
/* Call this when -classpath is seen on the command line.
@@ -303,10 +319,20 @@ void
jcf_path_classpath_arg (path)
const char *path;
{
- free_entry (&classpath_u);
- add_path (&classpath_u, path, 0);
+ free_entry (&classpath_user);
+ add_path (&classpath_user, path, 0);
}
+/* Call this when -bootclasspath is seen on the command line.
+ */
+void
+jcf_path_bootclasspath_arg (path)
+ const char *path;
+{
+ free_entry (&sys_dirs);
+ add_path (&sys_dirs, path, 1);
+}
+
/* Call this when -I is seen on the command line. */
void
jcf_path_include_arg (path)
@@ -328,25 +354,29 @@ jcf_path_seal (print)
sealed = include_dirs;
include_dirs = NULL;
- if (classpath_l)
+ if (classpath_whole)
{
- secondary = classpath_l;
- classpath_l = NULL;
+ secondary = classpath_whole;
+ classpath_whole = NULL;
do_system = 0;
}
- else if (classpath_u)
+ else if (classpath_user)
{
- secondary = classpath_u;
- classpath_u = NULL;
+ secondary = classpath_user;
+ classpath_user = NULL;
}
else
{
+ if (! classpath_env)
+ add_entry (&classpath_env, ".", 0);
+
secondary = classpath_env;
classpath_env = NULL;
}
+
- free_entry (&classpath_l);
- free_entry (&classpath_u);
+ free_entry (&classpath_whole);
+ free_entry (&classpath_user);
free_entry (&classpath_env);
append_entry (&sealed, secondary);
Index: java/jcf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf.h,v
retrieving revision 1.28
diff -u -p -r1.28 jcf.h
--- jcf.h 2002/02/20 23:12:24 1.28
+++ jcf.h 2002/02/23 04:28:40
@@ -273,6 +273,8 @@ extern void jcf_dependency_print_dummies
extern void jcf_path_init PARAMS ((void));
extern void jcf_path_CLASSPATH_arg PARAMS ((const char *));
extern void jcf_path_classpath_arg PARAMS ((const char *));
+extern void jcf_path_bootclasspath_arg PARAMS ((const char *));
+extern void jcf_path_wholeclasspath_arg PARAMS ((const char *));
extern void jcf_path_include_arg PARAMS ((const char *));
extern void jcf_path_seal PARAMS ((int));
extern void *jcf_path_start PARAMS ((void));
Index: java/jvspec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jvspec.c,v
retrieving revision 1.51
diff -u -p -r1.51 jvspec.c
--- jvspec.c 2001/12/23 16:07:13 1.51
+++ jvspec.c 2002/02/23 04:28:41
@@ -1,6 +1,6 @@
/* Specific flags and argument handling of the front-end of the
GNU compiler for the Java(TM) language.
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -64,8 +64,10 @@ static const char jvgenmain_spec[] =
%{<fcompile-resource*}\
%{<femit-class-file} %{<femit-class-files} %{<fencoding*}\
%{<fuse-boehm-gc} %{<fhash-synchronization} %{<fjni}\
- %{<findirect-dispatch} \
- %{<fclasspath*} %{<fCLASSPATH*} %{<foutput-class-dir}\
+ %{<findirect-dispatch}\
+ %{<fclasspath*} %{<fCLASSPATH*}\
+ %{<fbootclasspath*} %{<fwholeclasspath*}\
+ %{<foutput-class-dir}\
%{<fuse-divide-subroutine} %{<fno-use-divide-subroutine}\
%{<fcheck-references} %{<fno-check-references}\
%{<ffilelist-file}\
@@ -288,6 +290,8 @@ lang_specific_driver (in_argc, in_argv,
quote = argv[i];
}
else if (strcmp(argv[i], "-classpath") == 0
+ || strcmp(argv[i], "-bootclasspath") == 0
+ || strcmp(argv[i], "-wholeclasspath") == 0
|| strcmp(argv[i], "-CLASSPATH") == 0)
{
quote = argv[i];
@@ -478,6 +482,8 @@ lang_specific_driver (in_argc, in_argv,
}
if (strcmp (argv[i], "-classpath") == 0
+ || strcmp (argv[i], "-bootclasspath") == 0
+ || strcmp (argv[i], "-wholeclasspath") == 0
|| strcmp (argv[i], "-CLASSPATH") == 0)
{
arglist[j] = concat ("-f", argv[i]+1, "=", argv[i+1], NULL);
Index: java/lang-options.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang-options.h,v
retrieving revision 1.29
diff -u -p -r1.29 lang-options.h
--- lang-options.h 2002/02/20 23:12:24 1.29
+++ lang-options.h 2002/02/23 04:28:41
@@ -32,10 +32,14 @@ DEFINE_LANG_NAME ("Java")
N_("Disable automatic array bounds checking") },
{ "-fjni",
N_("Assume native functions are implemented using JNI") },
- { "--CLASSPATH",
+ { "--wholeclasspath",
N_("Set class path and suppress system path") },
+ { "--bootclasspath",
+ N_("Replace system path") },
{ "--classpath",
N_("Set class path") },
+ { "--CLASSPATH",
+ N_("Set class path (deprecated: use --classpath instead)") },
{ "--main",
N_("Choose class whose main method should be used") },
{ "--encoding",
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.85
diff -u -p -r1.85 lang.c
--- lang.c 2002/02/20 23:12:24 1.85
+++ lang.c 2002/02/23 04:28:41
@@ -257,6 +259,8 @@ java_decode_option (argc, argv)
{
char *p = argv[0];
+ jcf_path_init ();
+
if (strcmp (p, "-version") == 0)
{
version_flag = 1;
@@ -310,6 +314,20 @@ java_decode_option (argc, argv)
if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
{
jcf_path_classpath_arg (p + sizeof (CLARG) - 1);
+ return 1;
+ }
+#undef CLARG
+#define CLARG "-fbootclasspath="
+ if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
+ {
+ jcf_path_bootclasspath_arg (p + sizeof (CLARG) - 1);
+ return 1;
+ }
+#undef CLARG
+#define CLARG "-fwholeclasspath="
+ if (strncmp (p, CLARG, sizeof (CLARG) - 1) == 0)
+ {
+ jcf_path_wholeclasspath_arg (p + sizeof (CLARG) - 1);
return 1;
}
#undef CLARG