SF.net SVN: ant-contrib: [149] cpptasks/trunk/src/main/java/net/sf/ antcontrib/cpptasks

[email protected] Mon, 04 Feb 2008 23:39:54 -0800
Newsgroups gmane.comp.java.ant-contrib.devel
Message-ID <[email protected]>
Revision: 149
          http://ant-contrib.svn.sourceforge.net/ant-contrib/?rev=149&view=rev
Author:   carnold
Date:     2008-02-04 23:39:54 -0800 (Mon, 04 Feb 2008)

Log Message:
-----------
Bug 980130: Add VS 2008 project generation, fix VS 2005 issues

Modified Paths:
--------------
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java	2008-02-03 21:50:19 UTC (rev 148)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java	2008-02-05 07:39:54 UTC (rev 149)
@@ -28,6 +28,8 @@
 import org.apache.tools.ant.taskdefs.LogStreamHandler;
 import org.apache.tools.ant.types.Commandline;
 import org.apache.tools.ant.types.Environment;
+import org.apache.tools.ant.util.StringUtils;
+
 /**
  * Some utilities used by the CC and Link tasks.
  *
@@ -484,4 +486,14 @@
     public static boolean isSignificantlyAfter(long time1, long time2) {
       return time1 > (time2 + FILETIME_EPSILON);
     }
+
+
+    public static String toWindowsPath(final String path) {
+      if (File.separatorChar != '\\' && path.indexOf(File.separatorChar) != -1) {
+          return StringUtils.replace(path, File.separator, "\\");
+      }
+      return path;
+  }
+    
+
 }

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java	2008-02-03 21:50:19 UTC (rev 148)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java	2008-02-05 07:39:54 UTC (rev 149)
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright 2004 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -199,10 +199,10 @@
     String buildDirPath = CUtil.getRelativePath(basePath, buildDir);
 
     writer.write("# PROP BASE Output_Dir \"");
-    writer.write(toWindowsPath(buildDirPath));
+    writer.write(CUtil.toWindowsPath(buildDirPath));
     writer.write("\"\r\n");
     writer.write("# PROP BASE Intermediate_Dir \"");
-    writer.write(toWindowsPath(objDirPath));
+    writer.write(CUtil.toWindowsPath(objDirPath));
     writer.write("\"\r\n");
     writer.write("# PROP BASE Target_Dir \"\"\r\n");
     writer.write("# PROP Use_MFC 0\r\n");
@@ -213,10 +213,10 @@
       writer.write("0\r\n");
     }
     writer.write("# PROP Output_Dir \"");
-    writer.write(toWindowsPath(buildDirPath));
+    writer.write(CUtil.toWindowsPath(buildDirPath));
     writer.write("\"\r\n");
     writer.write("# PROP Intermediate_Dir \"");
-    writer.write(toWindowsPath(objDirPath));
+    writer.write(CUtil.toWindowsPath(objDirPath));
     writer.write("\"\r\n");
     writer.write("# PROP Target_Dir \"\"\r\n");
     writeCompileOptions(writer, basePath, compilerConfig);
@@ -338,7 +338,7 @@
           if (dep.getFile() != null) {
             String projName = toProjectName(dep.getName());
             projectDeps.add(projName);
-            String depProject = toWindowsPath(
+            String depProject = CUtil.toWindowsPath(
                       CUtil.getRelativePath(basePath,
                               new File(dep.getFile() + ".dsp")));
             writeWorkspaceProject(writer, projName, depProject, dep.getDependsList());
@@ -397,7 +397,7 @@
         && !relativePath.startsWith("\\")) {
       relativePath = ".\\" + relativePath;
     }
-    writer.write(toWindowsPath(relativePath));
+    writer.write(CUtil.toWindowsPath(relativePath));
     writer.write("\r\n# End Source File\r\n");
   }
 
@@ -515,7 +515,7 @@
     for (int i = 0; i < includePath.length; i++) {
       options.append(" /I \"");
       String relPath = CUtil.getRelativePath(baseDir, includePath[i]);
-      options.append(toWindowsPath(relPath));
+      options.append(CUtil.toWindowsPath(relPath));
       options.append('"');
     }
 
@@ -563,13 +563,6 @@
 	      || lcPath.indexOf("microsoft") != -1;
   }
 
-  private static String toWindowsPath(final String path) {
-      if (File.separatorChar != '\\' && path.indexOf(File.separatorChar) != -1) {
-          return StringUtils.replace(path, File.separator, "\\");
-      }
-      return path;
-  }
-
   /**
    * Writes link options.
    * @param writer Writer writer
@@ -613,11 +606,11 @@
           //      must quote
           if (relPath.indexOf(' ') > 0) {
             options.append(" \"");
-            options.append(toWindowsPath(relPath));
+            options.append(CUtil.toWindowsPath(relPath));
             options.append("\"");
           } else {
             options.append(' ');
-            options.append(toWindowsPath(relPath));
+            options.append(CUtil.toWindowsPath(relPath));
           }
         }
       }

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java	2008-02-03 21:50:19 UTC (rev 148)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java	2008-02-05 07:39:54 UTC (rev 149)
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright 2004-2006 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -88,6 +88,19 @@
         this.trueLiteral = trueArg;
         this.falseLiteral = falseArg;
     }
+    
+ /**
+  *  Determines if source file has a system path,
+  *    that is part of the compiler or platform.
+  *   @param source source, may not be null.
+  *   @return true is source file appears to be system library
+  *         and its path should be discarded.
+  */
+  private static boolean isSystemPath(final File source) {
+	  String lcPath = source.toString().toLowerCase(java.util.Locale.US);
+	  return lcPath.indexOf("platformsdk") != -1
+	      || lcPath.indexOf("microsoft") != -1;
+  }
 
     /**
      * Get configuration name.
@@ -128,7 +141,7 @@
                                       final CCTask task) {
         File outFile = task.getOutfile();
         File buildDir = outFile.getParentFile();
-        return CUtil.getRelativePath(basePath, buildDir);
+        return CUtil.toWindowsPath(CUtil.getRelativePath(basePath, buildDir));
     }
 
     /**
@@ -140,7 +153,7 @@
     private String getIntermediateDirectory(final String basePath,
                                             final CCTask task) {
         File objDir = task.getObjdir();
-        return CUtil.getRelativePath(basePath, objDir);
+        return CUtil.toWindowsPath(CUtil.getRelativePath(basePath, objDir));
     }
 
 
@@ -224,12 +237,15 @@
      * @return value of AdditionalIncludeDirectories property.
      */
     private String getAdditionalIncludeDirectories(
+            final String basePath,
             final CommandLineCompilerConfiguration compilerConfig) {
         StringBuffer includeDirs = new StringBuffer();
         String[] args = compilerConfig.getPreArguments();
         for (int i = 0; i < args.length; i++) {
             if (args[i].startsWith("/I")) {
-                includeDirs.append(args[i].substring(2));
+                includeDirs.append(CUtil.toWindowsPath(
+                    CUtil.getRelativePath(basePath, 
+                        new File(args[i].substring(2)))));
                 includeDirs.append(';');
             }
         }
@@ -432,6 +448,7 @@
      * @throws SAXException thrown if error during serialization.
      */
     private void writeCompilerElement(final ContentHandler content,
+            final String basePath,
             final CommandLineCompilerConfiguration compilerConfig)
             throws SAXException {
         AttributesImpl attributes = new AttributesImpl();
@@ -439,7 +456,7 @@
         addAttribute(attributes, "Optimization",
                 getOptimization(compilerConfig));
         addAttribute(attributes, "AdditionalIncludeDirectories",
-                getAdditionalIncludeDirectories(compilerConfig));
+                getAdditionalIncludeDirectories(basePath, compilerConfig));
         addAttribute(attributes, "PreprocessorDefinitions",
                 getPreprocessorDefinitions(compilerConfig));
         addAttribute(attributes, "MinimalRebuild",
@@ -559,18 +576,26 @@
           //   if file was not compiled or otherwise generated
           //
           if (targets.get(linkSources[i].getName()) == null) {
-            String relPath = CUtil.getRelativePath(basePath, linkSources[i]);
             //
+            //   if source appears to be a system library or object file
+            //      just output the name of the file (advapi.lib for example)
+            //      otherwise construct a relative path.
+            //
+            String relPath = linkSources[i].getName();
+            if (!isSystemPath(linkSources[i])) {
+                relPath = CUtil.getRelativePath(basePath, linkSources[i]);
+            }
+            //
             //   if path has an embedded space then
             //      must quote
             if (relPath.indexOf(' ') > 0) {
               buf.append('\"');
-              buf.append(relPath);
+              buf.append(CUtil.toWindowsPath(relPath));
               buf.append('\"');
             } else {
                buf.append(relPath);
             }
-            buf.append(';');
+            buf.append(' ');
           }
         }
         if (buf.length() > 0) {
@@ -689,7 +714,7 @@
 
         writeConfigurationStartTag(content, basePath, task, compilerConfig);
 
-        writeCompilerElement(content, compilerConfig);
+        writeCompilerElement(content, basePath, compilerConfig);
 
         writeLinkerElement(content, basePath, linkTarget, targets);
 

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java	2008-02-03 21:50:19 UTC (rev 148)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java	2008-02-05 07:39:54 UTC (rev 149)
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright 2004-2006 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -126,6 +126,10 @@
    * <td>Microsoft Visual C++ 2005</td>
    * </tr>
    * <tr>
+   * <td>msvc9</td>
+   * <td>Microsoft Visual C++ 2008</td>
+   * </tr>
+   * <tr>
    * <td>xcode</td>
    * <td>Apple Xcode</td>
    * </tr>

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java	2008-02-03 21:50:19 UTC (rev 148)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java	2008-02-05 07:39:54 UTC (rev 149)
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright 2004-2006 The Ant-Contrib project
+ * Copyright 2004-2008 The Ant-Contrib project
  *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -51,6 +51,10 @@
  * <td>Microsoft Visual C++ 2005</td>
  * </tr>
  * <tr>
+ * <td>msvc9</td>
+ * <td>Microsoft Visual C++ 2008</td>
+ * </tr>
+ * <tr>
  * <td>xcode</td>
  * <td>Apple Xcode</td>
  * </tr>
@@ -66,7 +70,7 @@
    */
   private static String[] values = new String[] {
       "cbuilderx", "msvc5",
-      "msvc6", "msvc7", "msvc71", "msvc8", "xcode"};
+      "msvc6", "msvc7", "msvc71", "msvc8", "msvc9", "xcode"};
 
   /**
    * Project writers associated with enumeration values.
@@ -77,6 +81,7 @@
       new VisualStudioNETProjectWriter("7.00", "TRUE", "FALSE"),
       new VisualStudioNETProjectWriter("7.10", "TRUE", "FALSE"),
       new VisualStudioNETProjectWriter("8.00", "true", "false"),
+      new VisualStudioNETProjectWriter("9.00", "true", "false"),
       new XcodeProjectWriter()};
 
   /**


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/