]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/userdefine/CommandLineUserDefine.java
To fix EDKT341. Still existing issues for VfrCompile.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / userdefine / CommandLineUserDefine.java
index 00e3ac620a6330be0bfebf1ddef58db958a15cf7..56e82de188c38130a83f3895521e4a36e8b6d5f9 100644 (file)
@@ -19,6 +19,7 @@ package net.sf.antcontrib.cpptasks.userdefine;
 import java.io.File;\r
 import java.util.Iterator;\r
 import java.util.LinkedHashSet;\r
+import java.util.Map;\r
 import java.util.Set;\r
 import java.util.StringTokenizer;\r
 import java.util.Vector;\r
@@ -31,6 +32,9 @@ import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.DirectoryScanner;\r
 import org.apache.tools.ant.Project;\r
+import org.apache.tools.ant.types.Environment;\r
+import org.apache.tools.ant.types.Path;\r
+import org.apache.tools.ant.types.Environment.Variable;\r
 \r
 /**\r
  * \r
@@ -40,7 +44,9 @@ public class CommandLineUserDefine {
     String includePathDelimiter = null;\r
 \r
     String outputDelimiter = null;\r
-\r
+    \r
+    private static String pathName = null;\r
+    \r
     public void command(CCTask cctask, UserDefineDef userdefine) {\r
         boolean isGccCommand = userdefine.getFamily().equalsIgnoreCase("GCC");\r
         File workdir;\r
@@ -136,6 +142,7 @@ public class CommandLineUserDefine {
         // if have source file append source file in command line.\r
         //\r
         Set allSrcFiles = new LinkedHashSet();\r
+\r
         for (int i = 0; i < srcSets.size(); i++) {\r
             ConditionalFileSet srcSet = (ConditionalFileSet) srcSets\r
                             .elementAt(i);\r
@@ -144,7 +151,6 @@ public class CommandLineUserDefine {
                 // Find matching source files\r
                 //\r
                 DirectoryScanner scanner = srcSet.getDirectoryScanner(project);\r
-                \r
                 //\r
                 // Check each source file - see if it needs compilation\r
                 //\r
@@ -207,19 +213,57 @@ public class CommandLineUserDefine {
         for (int j = 0; j < fileNames.length; j++) {\r
             cmd[index++] = fileNames[j];\r
         }\r
+        \r
+//        StringBuffer logLine = new StringBuffer();\r
+//        for(int i = 0; i < cmd.length; i++) {\r
+//            logLine.append(cmd[i] + " ");\r
+//        }\r
+//        project.log(logLine.toString(), Project.MSG_VERBOSE);\r
 \r
-        int retval = runCommand(cctask, workdir, cmd);\r
+        int retval = 0;\r
         \r
+        if (userdefine.getDpath() == null || userdefine.getDpath().trim().length() == 0) {\r
+            retval = runCommand(cctask, workdir, cmd, null);\r
+        } else {\r
+            String existPath = System.getenv(getPathName());\r
+            Environment newEnv = new Environment();\r
+            Variable var = new Variable();\r
+            var.setKey(getPathName());\r
+            var.setPath(new Path(project, userdefine.getDpath() + ";" + existPath));\r
+            newEnv.addVariable(var);\r
+            retval = runCommand(cctask, workdir, cmd, newEnv);\r
+        }\r
+        \r
+\r
         if (retval != 0) {\r
             throw new BuildException(userdefine.getCmd()\r
                             + " failed with return code " + retval, cctask\r
                             .getLocation());\r
         }\r
     }\r
+    \r
+    private String getPathName() {\r
+        if (pathName != null) {\r
+            return pathName;\r
+        }\r
+        Map allEnv = System.getenv();\r
+        Iterator iter = allEnv.keySet().iterator();\r
+        while (iter.hasNext()) {\r
+            String key = (String)iter.next();\r
+            if(key.equalsIgnoreCase("PATH")) {\r
+                pathName = key;\r
+                break ;\r
+            }\r
+        }\r
+        return pathName;\r
+    }\r
 \r
-    protected int runCommand(CCTask task, File workingDir, String[] cmdline)\r
+    protected int runCommand(CCTask task, File workingDir, String[] cmdline, Environment env)\r
                     throws BuildException {\r
-        return CUtil.runCommand(task, workingDir, cmdline, false, null);\r
+        //\r
+        // Write command to File\r
+        //\r
+        return CUtil.runCommand(task, workingDir, cmdline, false, env);\r
 \r
     }\r
 }\r