]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/MakeDeps.java
Modify FV attribute editor and generate FvImage Attributes in FPD file.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / MakeDeps.java
index c538403b36ce167ab1e4d08214d7f221e5162411..76ab8e071500cd7177d109c6be553283535dd651 100644 (file)
@@ -14,6 +14,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.framework.tasks;\r
 \r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.io.LineNumberReader;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
 import org.apache.tools.ant.Task;\r
@@ -22,17 +30,7 @@ import org.apache.tools.ant.taskdefs.LogStreamHandler;
 import org.apache.tools.ant.types.Commandline;\r
 import org.apache.tools.ant.types.Path;\r
 \r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.io.LineNumberReader;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.StringTokenizer;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
  Class MakeDeps is used to wrap MakeDeps.exe as an ANT task.\r
@@ -43,8 +41,6 @@ public class MakeDeps extends Task {
     // private members, use set/get to access them\r
     //\r
     private static final String cmdName = "MakeDeps";\r
-    private static final String target  = "dummy";\r
-    private String              includePath = null;\r
     private String              depsFile = null;\r
     private String              subDir = null;\r
     private boolean             quietMode = true;\r
@@ -75,16 +71,17 @@ public class MakeDeps extends Task {
 \r
         Project prj  = this.getOwningTarget().getProject();\r
         String  toolPath = prj.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
+\r
         ///\r
         /// compose full tool path\r
         ///\r
         if (toolPath == null || toolPath.length() == 0) {\r
-            toolPath = "./" + cmdName;\r
+            toolPath = cmdName;\r
         } else {\r
             if (toolPath.endsWith("/") || toolPath.endsWith("\\")) {\r
                 toolPath = toolPath + cmdName;\r
             } else {\r
-                toolPath = toolPath + "/" + cmdName;\r
+                toolPath = toolPath + File.separator + cmdName;\r
             }\r
         }\r
 \r
@@ -93,10 +90,10 @@ public class MakeDeps extends Task {
         ///\r
         StringBuffer args = new StringBuffer(4096);\r
         if (ignoreError) {\r
-            args.append(" -ignorenotfound");\r
+            args.append(" -ignorenotfound ");\r
         }\r
         if (quietMode) {\r
-            args.append(" -q");\r
+            args.append(" -q ");\r
         }\r
         if (subDir != null && subDir.length() > 0) {\r
             args.append(" -s ");\r
@@ -105,7 +102,7 @@ public class MakeDeps extends Task {
 \r
         ///\r
         /// if there's no source files, we can do nothing about dependency\r
-        /// \r
+        ///\r
         if (inputFileList.size() == 0) {\r
             throw new BuildException("No source files specified to scan");\r
         }\r
@@ -113,42 +110,20 @@ public class MakeDeps extends Task {
         ///\r
         /// compose source file arguments\r
         ///\r
-        Iterator iterator = inputFileList.iterator();\r
-        while (iterator.hasNext()) {\r
-            Input inputFile = (Input)iterator.next();\r
-            args.append(" -f ");\r
-            args.append(cleanupPathName(inputFile.getFile()));\r
+        for (int i = 0, listLength = inputFileList.size(); i < listLength; ++i) {\r
+            args.append(inputFileList.get(i).toString());\r
         }\r
 \r
-        ///\r
-        /// compose search pathes argument\r
-        ///\r
-        StringBuffer includePathArg = new StringBuffer(4096);\r
-        if (includePath != null && includePath.length() > 0) {\r
-            StringTokenizer pathTokens = new StringTokenizer(includePath, ";");\r
-            while (pathTokens.hasMoreTokens()) {\r
-                String tmpPath = pathTokens.nextToken().trim();\r
-                if (tmpPath.length() == 0) {\r
-                    continue;\r
-                }\r
-\r
-                includePathArg.append(" -i ");\r
-                includePathArg.append(cleanupPathName(tmpPath));\r
-            }\r
-        }\r
-        iterator = includePathList.iterator();\r
-        while (iterator.hasNext()) {\r
-            IncludePath path = (IncludePath)iterator.next();\r
-            includePathArg.append(cleanupPathName(path.getPath()));\r
+        for (int i = 0, listLength = includePathList.size(); i < listLength; ++i) {\r
+            args.append(includePathList.get(i).toString());\r
         }\r
-        args.append(includePathArg);\r
 \r
         ///\r
         /// We don't need a real target. So just a "dummy" is given\r
         ///\r
         args.append(" -target dummy");\r
         args.append(" -o ");\r
-        args.append(cleanupPathName(depsFile));\r
+        args.append(depsFile);\r
 \r
         ///\r
         /// prepare to execute the tool\r
@@ -163,6 +138,8 @@ public class MakeDeps extends Task {
         runner.setAntRun(prj);\r
         runner.setCommandline(cmd.getCommandline());\r
 \r
+        EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmd.getCommandline()));\r
+\r
         int result = 0;\r
         try {\r
             result = runner.execute();\r
@@ -171,13 +148,8 @@ public class MakeDeps extends Task {
         }\r
 \r
         if (result != 0) {\r
-            log ("MakeDeps failed");\r
-            return;\r
-        }\r
-\r
-        // change the old DEP file format (makefile compatible) to just file list\r
-        if (!cleanup()) {\r
-            throw new BuildException(depsFile + " was not generated");\r
+            EdkLog.log(this, EdkLog.EDK_INFO, "MakeDeps failed!");\r
+            throw new BuildException("MakeDeps: failed to generate dependency file!");\r
         }\r
     }\r
 \r
@@ -189,7 +161,6 @@ public class MakeDeps extends Task {
         String duplicateSeparator = separator + "{2}";\r
         path = Path.translateFile(path);\r
         path = path.replaceAll(duplicateSeparator, separator);\r
-\r
         return path;\r
     }\r
 \r
@@ -253,7 +224,7 @@ public class MakeDeps extends Task {
      @param     dir     The name of sub-directory in which source files will be scanned\r
      **/\r
     public void setSubDir(String dir) {\r
-        subDir = dir;\r
+        subDir = cleanupPathName(dir);\r
     }\r
 \r
     /**\r
@@ -265,31 +236,13 @@ public class MakeDeps extends Task {
         return subDir;\r
     }\r
 \r
-    /**\r
-     Set method for "IncludePath" attribute\r
-\r
-     @param     path    The name of include path\r
-     **/\r
-    public void setIncludePath(String path) {\r
-        includePath = cleanupPathName(path);\r
-    }\r
-\r
-    /**\r
-     Get method for "IncludePath" attribute\r
-\r
-     @returns   The name of include path\r
-     **/\r
-    public String getIncludePath() {\r
-        return includePath;\r
-    }\r
-\r
     /**\r
      Set method for "ExtraDeps" attribute\r
 \r
      @param     deps    The name of dependency file specified separately\r
      **/\r
     public void setExtraDeps(String deps) {\r
-        extraDeps = deps;\r
+        extraDeps = cleanupPathName(deps);\r
     }\r
 \r
     /**\r
@@ -319,71 +272,6 @@ public class MakeDeps extends Task {
         inputFileList.add(inputFile);\r
     }\r
 \r
-    /**\r
-     The original file generated by MakeDeps.exe is for makefile uses. The target\r
-     part (before :) is not useful for ANT. This method will do the removal.\r
-\r
-     @returns   true    if cleaned files is saved successfully\r
-     @returns   false   if error occurs in file I/O system\r
-     **/\r
-    private boolean cleanup() {\r
-        File df = new File(depsFile);\r
-\r
-        if (!df.exists()) {\r
-            return false;\r
-        }\r
-\r
-        LineNumberReader    lineReader = null;\r
-        FileReader          fileReader = null;\r
-        try {\r
-            fileReader = new FileReader(df);\r
-            lineReader = new LineNumberReader(fileReader);\r
-\r
-            ///\r
-            /// clean-up each line in deps file\r
-            //\r
-            String line = null;\r
-            StringBuffer cleanedLines = new StringBuffer(4096);\r
-            while ((line = lineReader.readLine()) != null) {\r
-                Pattern pattern = Pattern.compile(target + "[ ]*:[ ]*(.+)");\r
-                Matcher matcher = pattern.matcher(line);\r
-\r
-                while (matcher.find()) {\r
-                    ///\r
-                    /// keep the file name after ":"\r
-                    ///\r
-                    String filePath = line.substring(matcher.start(1), matcher.end(1));\r
-                    filePath = cleanupPathName(filePath);\r
-                    cleanedLines.append(filePath);\r
-                    cleanedLines.append("\n");\r
-                }\r
-            }\r
-            lineReader.close();\r
-            fileReader.close();\r
-\r
-            ///\r
-            /// we may have explicitly specified dependency files\r
-            ///\r
-            StringTokenizer fileTokens = new StringTokenizer(extraDeps, ";");\r
-            while (fileTokens.hasMoreTokens()) {\r
-                cleanedLines.append(cleanupPathName(fileTokens.nextToken()));\r
-                cleanedLines.append("\n");\r
-            }\r
-\r
-            ///\r
-            /// overwrite old dep file with new content\r
-            ///\r
-            FileWriter fileWriter = null;\r
-            fileWriter = new FileWriter(df);\r
-            fileWriter.write(cleanedLines.toString());\r
-            fileWriter.close();\r
-        } catch (IOException e) {\r
-            log (e.getMessage());\r
-        }\r
-\r
-        return true;\r
-    }\r
-\r
     /**\r
      Check if the dependency list file should be (re-)generated or not.\r
 \r
@@ -396,26 +284,29 @@ public class MakeDeps extends Task {
             return false;\r
         }\r
 \r
-        ///\r
-        /// If the source file(s) is newer than dependency list file, we need to\r
-        /// re-generate the dependency list file\r
-        ///\r
+        //\r
+        // If the source file(s) is newer than dependency list file, we need to\r
+        // re-generate the dependency list file\r
+        //\r
         long depsFileTimeStamp = df.lastModified();\r
-        Iterator iterator = inputFileList.iterator();\r
+        Iterator<Input> iterator = (Iterator<Input>)inputFileList.iterator();\r
         while (iterator.hasNext()) {\r
-            Input inputFile = (Input)iterator.next();\r
-            File sf = new File(inputFile.getFile());\r
-            if (sf.lastModified() > depsFileTimeStamp) {\r
-                return false;\r
+            Input inputFile = iterator.next();\r
+            List<String> fileList = inputFile.getNameList();\r
+            for (int i = 0, length = fileList.size(); i < length; ++i) {\r
+                File sf = new File(fileList.get(i));\r
+                if (sf.lastModified() > depsFileTimeStamp) {\r
+                    return false;\r
+                }\r
             }\r
         }\r
 \r
-        ///\r
-        /// If the source files haven't been changed since last time the dependency\r
-        /// list file was generated, we need to check each file in the file list to\r
-        /// see if any of them is changed or not. If anyone of them is newer than\r
-        /// the dependency list file, MakeDeps.exe is needed to run again.\r
-        ///\r
+        //\r
+        // If the source files haven't been changed since last time the dependency\r
+        // list file was generated, we need to check each file in the file list to\r
+        // see if any of them is changed or not. If anyone of them is newer than\r
+        // the dependency list file, MakeDeps.exe is needed to run again.\r
+        //\r
         LineNumberReader    lineReader = null;\r
         FileReader          fileReader = null;\r
         boolean             ret = true;\r
@@ -426,7 +317,10 @@ public class MakeDeps extends Task {
             String line = null;\r
             while ((line = lineReader.readLine()) != null) {\r
                 File sourceFile = new File(line);\r
-                if (sourceFile.lastModified() > depsFileTimeStamp) {\r
+                //\r
+                // If a file cannot be found (moved or removed) or newer, regenerate the dep file\r
+                // \r
+                if ((!sourceFile.exists()) || (sourceFile.lastModified() > depsFileTimeStamp)) {\r
                     ret = false;\r
                     break;\r
                 }\r