1) Added dependency check for flashmap, genfvimage, peirebase tasks
authorjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 Sep 2006 05:55:19 +0000 (05:55 +0000)
committerjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 Sep 2006 05:55:19 +0000 (05:55 +0000)
2) Added code in FpdParserTask.java to avoid re-generate FV.inf file
3) Added isEmpty() to ToolArg class to check if an argument is empty or not

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1556 6f19259b-4bc3-4df7-8a09-765794883524

EdkNt32Pkg/Nt32.fpd
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/NestElement.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ToolArg.java
Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java

index 6cfd3c3..2947fa0 100644 (file)
     </Ffs>\r
   </BuildOptions>\r
   <UserExtensions UserID="TianoCore" Identifier="1">\r
-    <concat destfile="${FV_DIR}/FV_RECOVERY.fd" binary="true">\r
+    <concat destfile="${FV_DIR}/FV_RECOVERY.fd" binary="true" force="no">\r
       <fileset dir="${FV_DIR}" includes="*.fv"/>\r
     </concat>\r
     <!--Generate Run.cmd file. This file will call SecMain.exe to start shell.-->\r
index be6c21a..5265f7c 100644 (file)
@@ -135,6 +135,16 @@ public class FlashMapTask extends Task implements EfiDefine {
       @throws BuidException\r
      **/\r
     public void execute() throws BuildException {\r
+        if (isUptodate()) {\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, headerFile.toFileList() \r
+                                                 + imageOutFile.toFileList()\r
+                                                 + mcoFile.toFileList()\r
+                                                 + dscFile.toFileList()\r
+                                                 + asmIncFile.toFileList()\r
+                                                 + outStrFile\r
+                                                 + " is/are up-to-date!");\r
+            return;\r
+        }\r
 \r
         Project project = this.getOwningTarget().getProject();\r
         //\r
@@ -598,4 +608,143 @@ public class FlashMapTask extends Task implements EfiDefine {
     public void setOutputDir(String outputDir) {\r
         this.outputDir = outputDir;\r
     }\r
+\r
+    //\r
+    // Dependency check\r
+    // \r
+    private boolean isUptodate() {\r
+        long srcTimeStamp = 0;\r
+        String srcName = "";\r
+        long dstTimeStamp = 0;\r
+        String dstName = "";\r
+        long timeStamp = 0;\r
+\r
+        if (!flashDefFile.isEmpty()) {\r
+            srcName = flashDefFile.getValue();\r
+            timeStamp = new File(srcName).lastModified();\r
+            if (timeStamp > srcTimeStamp) {\r
+                srcTimeStamp = timeStamp;\r
+            }\r
+        }\r
+\r
+        if (!mciFile.isEmpty()) {\r
+            srcName = mciFile.getValue();\r
+            timeStamp = new File(srcName).lastModified();\r
+            if (timeStamp > srcTimeStamp) {\r
+                srcTimeStamp = timeStamp;\r
+            }\r
+        }\r
+\r
+        if (!fdImage.isEmpty()) {\r
+            srcName = fdImage.getValue();\r
+            timeStamp = new File(srcName).lastModified();\r
+            if (timeStamp > srcTimeStamp) {\r
+                srcTimeStamp = timeStamp;\r
+            }\r
+        }\r
+\r
+        if (inStrFile.length() != 0) {\r
+            srcName = inStrFile;\r
+            timeStamp = new File(srcName).lastModified();\r
+            if (timeStamp > srcTimeStamp) {\r
+                srcTimeStamp = timeStamp;\r
+            }\r
+        }\r
+\r
+        if (!mciFileArray.isEmpty()) {\r
+            for (int i = 0; i < mciFileArray.nameList.size(); ++i) {\r
+                srcName += mciFileArray.nameList.get(i) + " ";\r
+                timeStamp = new File(mciFileArray.nameList.get(i)).lastModified();\r
+                if (timeStamp > srcTimeStamp) {\r
+                    srcTimeStamp = timeStamp;\r
+                }\r
+            }\r
+        }\r
+\r
+        if (!headerFile.isEmpty()) {\r
+            dstName = headerFile.getValue();\r
+            File dstFile = new File(dstName);\r
+            if (!dstFile.isAbsolute()) {\r
+                dstName = outputDir + File.separator + dstName;\r
+                dstFile = new File(dstName);\r
+            }\r
+\r
+            if (srcTimeStamp > dstFile.lastModified()) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        if (!imageOutFile.isEmpty()) {\r
+            dstName = imageOutFile.getValue();\r
+            File dstFile = new File(dstName);\r
+            if (!dstFile.isAbsolute()) {\r
+                dstName = outputDir + File.separator + dstName;\r
+                dstFile = new File(dstName);\r
+            }\r
+\r
+            if (srcTimeStamp > dstFile.lastModified()) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        if (!mcoFile.isEmpty()) {\r
+            dstName = mcoFile.getValue();\r
+            File dstFile = new File(dstName);\r
+            if (!dstFile.isAbsolute()) {\r
+                dstName = outputDir + File.separator + dstName;\r
+                dstFile = new File(dstName);\r
+            }\r
+\r
+            if (srcTimeStamp > dstFile.lastModified()) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        if (!dscFile.isEmpty()) {\r
+            dstName = dscFile.getValue();\r
+            File dstFile = new File(dstName);\r
+            if (!dstFile.isAbsolute()) {\r
+                dstName = outputDir + File.separator + dstName;\r
+                dstFile = new File(dstName);\r
+            }\r
+\r
+            if (srcTimeStamp > dstFile.lastModified()) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        if (!asmIncFile.isEmpty()) {\r
+            dstName = asmIncFile.getValue();\r
+            File dstFile = new File(dstName);\r
+            if (!dstFile.isAbsolute()) {\r
+                dstName = outputDir + File.separator + dstName;\r
+                dstFile = new File(dstName);\r
+            }\r
+\r
+            if (srcTimeStamp > dstFile.lastModified()) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        if (outStrFile.length() != 0) {\r
+            dstName = outStrFile;\r
+            File dstFile = new File(dstName);\r
+            if (!dstFile.isAbsolute()) {\r
+                dstName = outputDir + File.separator + dstName;\r
+                dstFile = new File(dstName);\r
+            }\r
+\r
+            if (srcTimeStamp > dstFile.lastModified()) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        return true;\r
+    }\r
 }\r
index cba7a4e..d37156d 100644 (file)
@@ -23,6 +23,16 @@ import org.apache.tools.ant.taskdefs.LogStreamHandler;
 import org.apache.tools.ant.types.Commandline;\r
 \r
 import java.io.File;\r
+import java.io.InputStreamReader;\r
+import java.lang.ProcessBuilder;\r
+import java.util.LinkedList;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+import java.util.List;\r
+import java.util.StringTokenizer;\r
+import java.util.Iterator;\r
+import java.io.BufferedReader;\r
+import java.io.FileReader;\r
 \r
 import org.tianocore.common.logger.EdkLog;\r
 \r
@@ -38,6 +48,10 @@ public class GenFvImageTask extends Task implements EfiDefine{
     //\r
     static final private String toolName = "GenFvImage";\r
     //\r
+    // Pattern to match the section header (e.g. [options], [files])\r
+    // \r
+    static final private Pattern sectionHeader = Pattern.compile("\\[([^\\[\\]]+)\\]");\r
+    //\r
     // The name of input inf file\r
     //\r
     private FileArg infFile = new FileArg();\r
@@ -56,6 +70,11 @@ public class GenFvImageTask extends Task implements EfiDefine{
         Project project = this.getOwningTarget().getProject();\r
         String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
 \r
+        if (isUptodate()) {\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, infFile.toFileList() + " is uptodate!");\r
+            return;\r
+        }\r
+\r
         String command;\r
         if (path == null) {\r
             command = toolName;\r
@@ -142,4 +161,117 @@ public class GenFvImageTask extends Task implements EfiDefine{
     public void setOutputDir(String outputDir) {\r
         this.outputDir = outputDir;\r
     }\r
+\r
+    //\r
+    // dependency check\r
+    // \r
+    private boolean isUptodate() {\r
+        String infName = this.infFile.getValue();\r
+        String fvName = "";\r
+        List<String> ffsFiles = new LinkedList<String>();\r
+        File inf = new File(infName);\r
+\r
+        try {\r
+            FileReader reader = new FileReader(inf);\r
+            BufferedReader in = new BufferedReader(reader);\r
+            String str;\r
+\r
+            //\r
+            // Read the inf file line by line\r
+            // \r
+            boolean inFiles = false;\r
+            boolean inOptions = false;\r
+            while ((str = in.readLine()) != null) {\r
+                str = str.trim();\r
+                if (str.length() == 0) {\r
+                    continue;\r
+                }\r
+\r
+                Matcher matcher = sectionHeader.matcher(str);\r
+                if (matcher.find()) {\r
+                    //\r
+                    // We take care of only "options" and "files" section\r
+                    // \r
+                    String sectionName = str.substring(matcher.start(1), matcher.end(1));\r
+                    if (sectionName.equalsIgnoreCase("options")) {\r
+                        inOptions = true;\r
+                        inFiles = false;\r
+                    } else if (sectionName.equalsIgnoreCase("files")) {\r
+                        inFiles = true;\r
+                        inOptions = false;\r
+                    } else {\r
+                        inFiles = false;\r
+                        inOptions = false;\r
+                    }\r
+                    continue;\r
+                }\r
+\r
+                //\r
+                // skip invalid line\r
+                // \r
+                int equalMarkPos = str.indexOf("=");\r
+                if (equalMarkPos < 0) {\r
+                    continue;\r
+                }\r
+\r
+                //\r
+                // we have only interest in EFI_FILE_NAME\r
+                // \r
+                String fileNameFlag = str.substring(0, equalMarkPos).trim();\r
+                String fileName = str.substring(equalMarkPos + 1).trim();\r
+                if (!fileNameFlag.equalsIgnoreCase("EFI_FILE_NAME")\r
+                    || fileName.length() == 0) {\r
+                    continue;\r
+                }\r
+\r
+                if (inFiles) {\r
+                    //\r
+                    // files specified beneath the [files] section are source files\r
+                    // \r
+                    ffsFiles.add(fileName);\r
+                } else if (inOptions) {\r
+                    //\r
+                    // file specified beneath the [options] section is the target file\r
+                    // \r
+                    fvName = outputDir + File.separator + fileName;\r
+                }\r
+            }\r
+        } catch (Exception ex) {\r
+            throw new BuildException(ex.getMessage());\r
+        }\r
+\r
+        //\r
+        // if destionation file doesn't exist, we need to generate it.\r
+        // \r
+        File fvFile = new File(fvName);\r
+        if (!fvFile.exists()) {\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, fvName + " doesn't exist!");\r
+            return false;\r
+        }\r
+\r
+        //\r
+        // the inf file itself will be taken as source file, check its timestamp\r
+        // against the target file\r
+        // \r
+        long fvFileTimeStamp = fvFile.lastModified();\r
+        if (inf.lastModified() > fvFileTimeStamp) {\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, infName + " has been changed since last build!");\r
+            return false;\r
+        }\r
+\r
+        //\r
+        // no change in the inf file, we need to check each source files in it\r
+        // against the target file\r
+        // \r
+        for (Iterator it = ffsFiles.iterator(); it.hasNext(); ) {\r
+            String fileName = (String)it.next();\r
+            File file = new File(fileName);\r
+            if (file.lastModified() > fvFileTimeStamp) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, fileName + " has been changed since last build!");\r
+                return false;\r
+            }\r
+        }\r
+\r
+        return true;\r
+    }\r
 }\r
index be1d88a..271dee6 100644 (file)
@@ -32,7 +32,7 @@ public class NestElement extends DataType {
     // The name list. All the name strings got from setXXX methods will be put\r
     // in here.\r
     //\r
-    private List<String> nameList = new ArrayList<String>();\r
+    protected List<String> nameList = new ArrayList<String>();\r
 \r
     /**\r
        Insert content in the newElement into this NestElement\r
index 76a396c..1f8a4d1 100644 (file)
@@ -67,6 +67,10 @@ public class PeiReBaseTask extends Task implements EfiDefine {
       @throws BuidException\r
      **/\r
     public void execute() throws BuildException {\r
+        if (isUptodate()) {\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, outputFile.toFileList() + " is up-to-date!");\r
+            return;\r
+        }\r
 \r
         Project project = this.getOwningTarget().getProject();\r
 \r
@@ -247,4 +251,18 @@ public class PeiReBaseTask extends Task implements EfiDefine {
     public void setMapFile(String mapFile) {\r
         this.mapFile.setArg(" -M ", mapFile);\r
     }\r
+\r
+    //\r
+    // Dependency check\r
+    // \r
+    private boolean isUptodate() {\r
+        File srcFile = new File(inputFile.getValue());\r
+        File dstFile = new File(outputFile.getValue());\r
+\r
+        if (srcFile.lastModified() > dstFile.lastModified()) {\r
+            return false;\r
+        }\r
+\r
+        return true;\r
+    }\r
 }\r
index 2694f03..ade6817 100644 (file)
@@ -139,4 +139,13 @@ public class ToolArg extends NestElement {
     public String toString() {\r
         return super.toString(prefix);\r
     }\r
+\r
+    /**\r
+       Check if the argument is empty or not\r
+\r
+       @return boolean\r
+     **/\r
+    public boolean isEmpty() {\r
+        return (prefix.length() == 0) && (nameList.isEmpty());\r
+    }\r
 }\r
index 3d2c36a..addb43a 100644 (file)
@@ -193,6 +193,12 @@ public class FpdParserTask extends Task {
             getProject().setProperty("FV_FILENAME", validFv[i]);\r
 \r
             File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".inf"));\r
+            if (fvFile.exists() && (fvFile.lastModified() >= fpdFile.lastModified())) {\r
+                //\r
+                // don't re-generate FV.inf if fpd has not been changed\r
+                // \r
+                continue;\r
+            }\r
             fvFile.getParentFile().mkdirs();\r
 \r
             try {\r