[m-rev.] For review: Fix a Java CLASSPATH-related bug

James Goddard goddardjames at yahoo.com
Thu Feb 19 21:59:58 AEDT 2004


> It would be better to use io__get_environment_variable to get the previous
> value.  (Only a little better, since io__get_environment_variable is itself
> not completely portable, but still...)

Here's a new patch that uses this approach, and should work with both
Java and C back-ends.

------------------------------------------------------------------------------
Estimated hours taken: 4
Branches: main

Fix a Java CLASSPATH-related bug.

compiler/compile_target_code.m:
	Prepend the current CLASSPATH when setting the new classpath, so as to
	preserve the accumulating nature of the variable.  Otherwise, setting
	the CLASSPATH environmental variable will be overridden by the mercury
	classpath, if it is present.

compiler/modules.m:
	Added new predicate get_env_classpath/3, which fetches the current
	value of the environment variable CLASSPATH.


Index: compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.53
diff -u -d -r1.53 compile_target_code.m
--- compile_target_code.m	19 Feb 2004 00:58:28 -0000	1.53
+++ compile_target_code.m	19 Feb 2004 10:23:10 -0000
@@ -670,17 +670,21 @@
 	{ join_string_list(JavaFlagsList, "", "", " ", JAVAFLAGS) },
 
 	globals__io_lookup_accumulating_option(java_classpath,
-	 	Java_Incl_Dirs),
-	( { Java_Incl_Dirs = [] } ->
-		{ InclOpt = "" }
-	;
-		% XXX PathSeparator should be ";" on Windows
-		{ PathSeparator = ":" },
-		{ join_string_list(Java_Incl_Dirs, "", "",
+		 	Java_Incl_Dirs),
+	% XXX PathSeparator should be ";" on Windows
+	{ PathSeparator = ":" },
+	% We prepend the current CLASSPATH to preserve the accumulating
+	% nature of this variable.
+	get_env_classpath(EnvClasspath),
+	{ join_string_list([EnvClasspath|Java_Incl_Dirs], "", "",
 			PathSeparator, ClassPath) },
-		{ InclOpt = string__append_list([
-			"-classpath ", quote_arg(ClassPath), " "]) }
-	),
+	{ ClassPath = "" ->
+		InclOpt = ""
+	;
+		InclOpt = string__append_list([
+				"-classpath ", quote_arg(ClassPath), " "])
+	},
+
 	globals__io_lookup_bool_option(target_debug, Target_Debug),
 	{ Target_Debug = yes ->
 		Target_DebugOpt = "-g "
Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.297
diff -u -d -r1.297 modules.m
--- modules.m	19 Feb 2004 10:12:57 -0000	1.297
+++ modules.m	19 Feb 2004 10:19:47 -0000
@@ -805,6 +805,11 @@
 :- pred list_class_files_for_jar(module_name::in, string::in, string::out,
 		io__state::di, io__state::uo) is det.
 
+	% get_env_classpath:
+	%	Obtain the value of the environment variable CLASSPATH.
+
+:- pred get_env_classpath(string::out, io__state::di, io__state::uo) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -7282,6 +7287,21 @@
 	;
 		{ AnySubdirs = no },
 		{ ListClassFiles = ClassFiles }
	).
+
+get_env_classpath(Classpath) -->
+	io__get_environment_var("CLASSPATH", MaybeCP),
+	(
+		{ MaybeCP = yes(Classpath) }
+	;
+		{ MaybeCP = no },
+		io__get_environment_var("java.class.path", MaybeJCP),
+		{
+			MaybeJCP = yes(Classpath)
+		;
+			MaybeJCP = no,
+			Classpath = ""
+		}
+	).
 
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list