[m-rev.] For review: Get library building to work in grade Java using subdirectories

James Goddard goddardjames at yahoo.com
Tue Feb 17 11:01:52 AEDT 2004


Estimated hours taken: 4
Branches: main

Get library building to work in grade Java using subdirectories.

compiler/modules.m:
	Jar files were previously being built with incorrect directory
	structures if --use-subdirs was turned on.  This patch corrects the
	problem.


Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.293
diff -u -d -r1.293 modules.m
--- modules.m	16 Feb 2004 01:11:01 -0000	1.293
+++ modules.m	16 Feb 2004 23:45:32 -0000
@@ -4854,10 +4854,35 @@
 		"\t$(RANLIB) $(ALL_RANLIBFLAGS) ", LibFileName, "\n\n"
 	]),
 
+	{ ClassFiles = "$(" ++ MakeVarName ++ ".classes)" },
+	globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
+	globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs),
+	{ AnySubdirs = UseSubdirs `or` UseGradeSubdirs },
+	(
+		{ AnySubdirs = yes },
+		{ JarSubdir = dir.dirname(JarFileName) },
+		module_name_to_file_name(ModuleName, ".class", no, ClassFile),
+		{ ClassSubdir = dir.dirname(ClassFile) },
+		{ MaybeMkJarSubdir = "\t-mkdir " ++ JarSubdir ++ "\n" },
+		% Here we use the `-C' option of jar to change directory during
+		% execution, then use sed to strip away the Mercury/classs/
+		% prefix to the class files.
+		% Otherwise, the class files would be stored as
+		%	Mercury/classs/*.class
+		% within the jar file, which is not what we want.
+		{ ListClassFiles = "-C " ++ ClassSubdir ++ " \\\n" ++
+				"\t\t`echo "" " ++ ClassFiles ++ """" ++
+				" | sed 's| '" ++ ClassSubdir ++ "/| |'`" }
+	;
+		{ AnySubdirs = no },
+		{ MaybeMkJarSubdir = "" },
+		{ ListClassFiles = ClassFiles }
+	),
 	io__write_strings(DepStream, [
 		JarFileName, " : ", "$(", MakeVarName, ".classes)\n",
-		"\t$(JAR) $(JAR_CREATE_FLAGS) ", JarFileName,
-		" $(", MakeVarName, ".classes)\n\n"
+		MaybeMkJarSubdir,
+		"\t$(JAR) $(JAR_CREATE_FLAGS) ", JarFileName, " ",
+		ListClassFiles, "\n\n"
 	]),
 
 	module_name_to_file_name(ModuleName, ".dep", no, DepFileName),
--------------------------------------------------------------------------
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