You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Nico Seessle <ni...@seessle.de> on 2000/09/20 00:08:49 UTC

Javac and maximum length of command line for external compiler

Could be changed for example like this. Only checks for limitations on known
system and should do everything "as normal" on unknown system, except it
issued a "Note" to the log if an IOException occurs and no temporary file
was used. This note *must* be changed (if it should be included at all)
since it doesn't contain a valid contact for error reporting.

Another possibility would have been to use default limit of 4096 (defined by
POSIX if read the AIX includefile correcly), but I hope most OS today don't
have such a small limit?

Would it be better to include this in a config file (and how?)?

Index: Javac.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.jav
a,v
retrieving revision 1.41
diff -u -r1.41 Javac.java
--- Javac.java 2000/09/19 16:13:51 1.41
+++ Javac.java 2000/09/19 21:59:34
@@ -113,6 +113,8 @@
     private Path bootclasspath;
     private Path extdirs;
     private static String lSep = System.getProperty("line.separator");
+    private static String antWorkingDirectory =
System.getProperty("user.dir");
+    private static String myos = System.getProperty("os.name");

     protected Vector compileList = new Vector();

@@ -706,17 +708,11 @@
     private int executeJikesCompile(String[] args, int firstFileName) {
         String[] commandArray = null;
         File tmpFile = null;
+
+        boolean useTmpFile = checkLimits(args, firstFileName);

         try {
-            String myos = System.getProperty("os.name");
-
-            // Windows has a 32k limit on total arg size, so
-            // create a temporary file to store all the arguments
-
-            // There have been reports that 300 files could be compiled
-            // so 250 is a conservative approach
-            if (myos.toLowerCase().indexOf("windows") >= 0
-                && args.length > 250) {
+            if (useTmpFile)

                 PrintWriter out = null;
                 try {
                     tmpFile = new File("jikes"+(new
Random(System.currentTimeMillis())).nextLong());
@@ -736,6 +732,7 @@
                     }
                 }
             } else {
+                // Should be safe to let the JVM do it the "normal" way
                 commandArray = args;
             }

@@ -749,6 +746,14 @@
                 exe.execute();
                 return exe.getExitValue();
             } catch (IOException e) {
+                if (!useTmpFile)

+                    log("Note: Using a large number of arguments is known
to be problematic", Project.MSG_INFO);
+                    log("      on some operating systems. If you think this
error may be", Project.MSG_INFO);
+                    log("      caused by such a cicumstance please mail
<???> with the", Project.MSG_INFO);
+                    log("      maximum length a command line can take on
your OS.", Project.MSG_INFO);
+                    log("      Please specify " + myos + " as the reference
for your OS", Project.MSG_INFO);
+                    log("      including the version of the OS and the JDK
used. Thanks.", Project.MSG_INFO);
+                }
                 throw new BuildException("Error running Jikes compiler",
e);
             }
         } finally {
@@ -756,6 +761,50 @@
                 tmpFile.delete();
             }
         }
+    }
+
+    /**
+     * Given an array of commandline arguments checks if it's required
+     * to use a temporary file for compilation (if it's possible at
+     * all)
+     *
+     * @param args the arguments the compiler required
+     * @param firstFileName index of the first filename in the args
+     */
+    private boolean checkLimits(String[] args, int firstFileName)

+        boolean needTmpFile = false;
+
+        int limit = -1; // -1 means unlimited
+        int length = 0;
+
+        if (myos.toLowerCase().indexOf("windows") >= 0)

+            // Windows has a 32k limit on total arg size
+            limit = 32000;
+
+            // If we are not on JDK 1.3 and we need to do a chdir
+            // the Limit is only about 4k (using cmd.exe).
+            if (!Project.getJavaVersion().equals(Project.JAVA_1_3) &&
+
!project.getBaseDir().getAbsolutePath().equals(antWorkingDirectory))

+                limit = 4000;
+            }
+        } else if (myos.toLowerCase().indexOf("linux") >= 0) {
+            limit = 90000;
+        } else if (myos.toLowerCase().indexOf("aix") >= 0) {
+            limit = 20000;
+        }
+
+        // Is there a known limit on the current OS?
+        if (limit != -1)

+            for (int i = 0; i < args.length; i++)

+                length += args[i].length();
+            }
+
+            // If it's exceeded we need a tempfile
+            if (length > limit) {
+                needTmpFile = true;
+            }
+        }
+        return needTmpFile;
     }

     /**




Re: Javac and maximum length of command line for external compiler

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "NS" == Nico Seessle <ni...@seessle.de> writes:

 NS> I don't know if I understand you correctly? Do you mean we should
 NS> *always* use 4k as the limit, or just use 4k as the default and
 NS> set this higher if we are sure it will be safe?

Unless somebody wants to cary the burden of updating the limits every
time a new number is known (including something like "it is 32k unless
you have service pack xy installed where it must be set to 31k or
...")  I'd say the first.

Stefan

Re: Javac and maximum length of command line for external compiler

Posted by Nico Seessle <ni...@seessle.de>.
----- Original Message -----
From: "Stefan Bodewig" <bo...@bost.de>
To: <an...@jakarta.apache.org>
Sent: Wednesday, September 20, 2000 5:13 PM
Subject: Re: Javac and maximum length of command line for external compiler


> >>>>> "NS" == Nico Seessle <ni...@seessle.de> writes:
>
>  NS> Another possibility would have been to use default limit of 4096
>  NS> (defined by POSIX if read the AIX includefile correcly), but I
>  NS> hope most OS today don't have such a small limit?
>
> Unless we get a reference that says we can safely assume a limit
> > 4096, I'd rather use this as a limit in every case. I don't really
> feel like supporting a comprehensive list of OSs with their limits.
>

I don't know if I understand you correctly? Do you mean we should *always*
use 4k as the limit, or just use 4k as the default and set this higher if we
are sure it will be safe?

Nico



Re: Javac and maximum length of command line for external compiler

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "NS" == Nico Seessle <ni...@seessle.de> writes:

 NS> Another possibility would have been to use default limit of 4096
 NS> (defined by POSIX if read the AIX includefile correcly), but I
 NS> hope most OS today don't have such a small limit?

Unless we get a reference that says we can safely assume a limit 
> 4096, I'd rather use this as a limit in every case. I don't really
feel like supporting a comprehensive list of OSs with their limits.

Known OSs Ant is being used on (there've been users reporting success
here) include Mac OS, OS/2 and AS/400 as well as a whole bunch of
other Unices (apart from AIX). I'm still waiting for the first user to
tell us she's using Ant on OpenVMS successfully.

Stefan