]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/MakeDeps.java
Remove FrameworkLogger in FrameworkTasks and EdkException in GenBuild. Update EdkLog...
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / MakeDeps.java
index e927f8c9c9188d4ea59114e848d89982a8cd9ae0..76ab8e071500cd7177d109c6be553283535dd651 100644 (file)
@@ -16,17 +16,11 @@ package org.tianocore.framework.tasks;
 \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.HashSet;\r
 import java.util.Iterator;\r
 import java.util.List;\r
-import java.util.Set;\r
-import java.util.StringTokenizer;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
@@ -35,7 +29,8 @@ import org.apache.tools.ant.taskdefs.Execute;
 import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
 import org.apache.tools.ant.types.Commandline;\r
 import org.apache.tools.ant.types.Path;\r
-import org.tianocore.logger.EdkLog;\r
+\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
  Class MakeDeps is used to wrap MakeDeps.exe as an ANT task.\r
@@ -46,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
@@ -78,20 +71,17 @@ public class MakeDeps extends Task {
 \r
         Project prj  = this.getOwningTarget().getProject();\r
         String  toolPath = prj.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
-        FrameworkLogger logger = new FrameworkLogger(prj, "makedeps");\r
-        EdkLog.setLogLevel(prj.getProperty("env.LOGLEVEL"));\r
-        EdkLog.setLogger(logger);\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
@@ -100,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
@@ -112,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
@@ -120,43 +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
-            String inputFileString = cleanupPathName(inputFile.getFile());\r
-            args.append(" -f ");\r
-            args.append(inputFileString);\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
+        for (int i = 0, listLength = includePathList.size(); i < listLength; ++i) {\r
+            args.append(includePathList.get(i).toString());\r
         }\r
-        iterator = includePathList.iterator();\r
-        while (iterator.hasNext()) {\r
-            IncludePath path = (IncludePath)iterator.next();\r
-            includePathArg.append(cleanupPathName(path.getPath()));\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
@@ -171,8 +138,7 @@ public class MakeDeps extends Task {
         runner.setAntRun(prj);\r
         runner.setCommandline(cmd.getCommandline());\r
 \r
-        EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmd.getCommandline()));\r
-        EdkLog.log(EdkLog.EDK_INFO, " ");\r
+        EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmd.getCommandline()));\r
 \r
         int result = 0;\r
         try {\r
@@ -182,13 +148,8 @@ public class MakeDeps extends Task {
         }\r
 \r
         if (result != 0) {\r
-            EdkLog.log(EdkLog.EDK_INFO, "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
@@ -196,16 +157,10 @@ public class MakeDeps extends Task {
     /// Remove any duplicated path separator or inconsistent path separator\r
     ///\r
     private String cleanupPathName(String path) {\r
-        try {\r
-            path = (new File(path)).getCanonicalPath();\r
-        } catch (IOException e) {\r
-            String separator = "\\" + File.separator;\r
-            String duplicateSeparator = separator + "{2}";\r
-            path = Path.translateFile(path);\r
-            path = path.replaceAll(duplicateSeparator, separator);\r
-            return path;\r
-        }\r
-\r
+        String separator = "\\" + File.separator;\r
+        String duplicateSeparator = separator + "{2}";\r
+        path = Path.translateFile(path);\r
+        path = path.replaceAll(duplicateSeparator, separator);\r
         return path;\r
     }\r
 \r
@@ -269,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
@@ -281,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
@@ -335,79 +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
-        Set<String>         lineSet = new HashSet<String>(100); // used to remove duplicated lines\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
-            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
-                    lineSet.add(filePath);\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
-                lineSet.add(cleanupPathName(fileTokens.nextToken()));\r
-            }\r
-\r
-            ///\r
-            /// compose the final file content\r
-            /// \r
-            StringBuffer cleanedLines = new StringBuffer(40960);\r
-            Iterator<String> it = lineSet.iterator();\r
-            while (it.hasNext()) {\r
-                String filePath = it.next();\r
-                cleanedLines.append(filePath);\r
-                cleanedLines.append("\n");\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
@@ -420,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
@@ -450,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