Fixed EDKT498(enchance makedep tool to support asm file), EDKT500(dep file needs...
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / MakeDeps.java
index 20cf44b..f1fb824 100644 (file)
@@ -14,9 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.framework.tasks;\r
 \r
+import java.io.BufferedInputStream;\r
 import java.io.BufferedReader;\r
 import java.io.BufferedWriter;\r
 import java.io.File;\r
+import java.io.FileInputStream;\r
 import java.io.FileReader;\r
 import java.io.FileWriter;\r
 import java.io.IOException;\r
@@ -44,6 +46,7 @@ public class MakeDeps extends Task {
     //\r
     // private members, use set/get to access them\r
     //\r
+    private String      targetFile = "";\r
     private String      depsFilePath = "";\r
     private IncludePath includePathList = new IncludePath();\r
     private Input       inputFileList = new Input();\r
@@ -54,7 +57,7 @@ public class MakeDeps extends Task {
     //\r
     // regular expression for "#include ..." directive\r
     // \r
-    private static final Pattern incPattern = Pattern.compile("[\n\r \t]*#[ \t]*include[ \t\"<]+([^\n\r\"<>]+)");\r
+    private static final Pattern incPattern = Pattern.compile("[\n\r]+[ \t#]*[ \t]*include[ \t]+[\"<]*([^\n\r\"<>]+)[>\"]*[\n\r]+");\r
 \r
     public MakeDeps() {\r
 \r
@@ -69,6 +72,13 @@ public class MakeDeps extends Task {
      @throws    BuildException\r
      **/\r
     public void execute() throws BuildException {\r
+        //\r
+        // if target file is specified and it hasn't been generated, don't generate\r
+        // dep file\r
+        // \r
+        if (targetFile.length() != 0 && (new File(targetFile)).exists() == false) {\r
+            return;\r
+        }\r
         //\r
         // check if the dependency list file is uptodate or not\r
         //\r
@@ -124,6 +134,14 @@ public class MakeDeps extends Task {
         FileTimeStamp.update(depsFilePath, depsFile.lastModified());\r
     }\r
 \r
+    public void setTargetFile(String name) {\r
+        targetFile = name;\r
+    }\r
+\r
+    public String getTargetFile() {\r
+        return targetFile;\r
+    }\r
+\r
     /**\r
      Set method for "DepsFile" attribute\r
 \r
@@ -280,24 +298,30 @@ public class MakeDeps extends Task {
             if (!srcFile.exists()) {\r
                 continue;\r
             }\r
-\r
             //\r
             // try cache first\r
             // \r
             Set<String> incFiles = includesCache.get(src);\r
             if (incFiles == null) {\r
                 incFiles = new HashSet<String>();\r
-                FileReader fileReader = null;\r
-                BufferedReader bufReader = null;\r
+                FileInputStream fileReader = null;\r
+                BufferedInputStream bufReader = null;\r
                 String fileContent = "";\r
                 int fileLength = (int)srcFile.length();\r
 \r
                 try {\r
-                    fileReader = new FileReader(srcFile);\r
-                    bufReader  = new BufferedReader(fileReader);\r
-                    char[] buf = new char[fileLength];\r
+                    fileReader = new FileInputStream(srcFile);\r
+                    bufReader  = new BufferedInputStream(fileReader);\r
+                    byte[] buf = new byte[fileLength];\r
 \r
                     bufReader.read(buf, 0, fileLength);\r
+                    //\r
+                    // check if the file is utf-16 encoded\r
+                    // \r
+                    if (buf[0] == (byte)0xff || buf[0] == (byte)0xfe) {\r
+                        fileContent = new String(buf, "UTF-16");\r
+                        buf = fileContent.getBytes("UTF-8");\r
+                    }\r
                     fileContent = new String(buf);\r
                 } catch (IOException e) {\r
                     throw new BuildException(e.getMessage());\r