From d946661a82d929b61603cf60fa2fd51fae654926 Mon Sep 17 00:00:00 2001 From: jwang36 Date: Tue, 19 Sep 2006 05:55:19 +0000 Subject: [PATCH] 1) Added dependency check for flashmap, genfvimage, peirebase tasks 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 | 2 +- .../framework/tasks/FlashMapTask.java | 149 ++++++++++++++++++ .../framework/tasks/GenFvImageTask.java | 132 ++++++++++++++++ .../framework/tasks/NestElement.java | 2 +- .../framework/tasks/PeiReBaseTask.java | 18 +++ .../tianocore/framework/tasks/ToolArg.java | 9 ++ .../tianocore/build/fpd/FpdParserTask.java | 6 + 7 files changed, 316 insertions(+), 2 deletions(-) diff --git a/EdkNt32Pkg/Nt32.fpd b/EdkNt32Pkg/Nt32.fpd index 6cfd3c3bac..2947fa0b20 100644 --- a/EdkNt32Pkg/Nt32.fpd +++ b/EdkNt32Pkg/Nt32.fpd @@ -7209,7 +7209,7 @@ - + diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java index be6c21a292..5265f7c7d6 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/FlashMapTask.java @@ -135,6 +135,16 @@ public class FlashMapTask extends Task implements EfiDefine { @throws BuidException **/ public void execute() throws BuildException { + if (isUptodate()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, headerFile.toFileList() + + imageOutFile.toFileList() + + mcoFile.toFileList() + + dscFile.toFileList() + + asmIncFile.toFileList() + + outStrFile + + " is/are up-to-date!"); + return; + } Project project = this.getOwningTarget().getProject(); // @@ -598,4 +608,143 @@ public class FlashMapTask extends Task implements EfiDefine { public void setOutputDir(String outputDir) { this.outputDir = outputDir; } + + // + // Dependency check + // + private boolean isUptodate() { + long srcTimeStamp = 0; + String srcName = ""; + long dstTimeStamp = 0; + String dstName = ""; + long timeStamp = 0; + + if (!flashDefFile.isEmpty()) { + srcName = flashDefFile.getValue(); + timeStamp = new File(srcName).lastModified(); + if (timeStamp > srcTimeStamp) { + srcTimeStamp = timeStamp; + } + } + + if (!mciFile.isEmpty()) { + srcName = mciFile.getValue(); + timeStamp = new File(srcName).lastModified(); + if (timeStamp > srcTimeStamp) { + srcTimeStamp = timeStamp; + } + } + + if (!fdImage.isEmpty()) { + srcName = fdImage.getValue(); + timeStamp = new File(srcName).lastModified(); + if (timeStamp > srcTimeStamp) { + srcTimeStamp = timeStamp; + } + } + + if (inStrFile.length() != 0) { + srcName = inStrFile; + timeStamp = new File(srcName).lastModified(); + if (timeStamp > srcTimeStamp) { + srcTimeStamp = timeStamp; + } + } + + if (!mciFileArray.isEmpty()) { + for (int i = 0; i < mciFileArray.nameList.size(); ++i) { + srcName += mciFileArray.nameList.get(i) + " "; + timeStamp = new File(mciFileArray.nameList.get(i)).lastModified(); + if (timeStamp > srcTimeStamp) { + srcTimeStamp = timeStamp; + } + } + } + + if (!headerFile.isEmpty()) { + dstName = headerFile.getValue(); + File dstFile = new File(dstName); + if (!dstFile.isAbsolute()) { + dstName = outputDir + File.separator + dstName; + dstFile = new File(dstName); + } + + if (srcTimeStamp > dstFile.lastModified()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!"); + return false; + } + } + + if (!imageOutFile.isEmpty()) { + dstName = imageOutFile.getValue(); + File dstFile = new File(dstName); + if (!dstFile.isAbsolute()) { + dstName = outputDir + File.separator + dstName; + dstFile = new File(dstName); + } + + if (srcTimeStamp > dstFile.lastModified()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!"); + return false; + } + } + + if (!mcoFile.isEmpty()) { + dstName = mcoFile.getValue(); + File dstFile = new File(dstName); + if (!dstFile.isAbsolute()) { + dstName = outputDir + File.separator + dstName; + dstFile = new File(dstName); + } + + if (srcTimeStamp > dstFile.lastModified()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!"); + return false; + } + } + + if (!dscFile.isEmpty()) { + dstName = dscFile.getValue(); + File dstFile = new File(dstName); + if (!dstFile.isAbsolute()) { + dstName = outputDir + File.separator + dstName; + dstFile = new File(dstName); + } + + if (srcTimeStamp > dstFile.lastModified()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!"); + return false; + } + } + + if (!asmIncFile.isEmpty()) { + dstName = asmIncFile.getValue(); + File dstFile = new File(dstName); + if (!dstFile.isAbsolute()) { + dstName = outputDir + File.separator + dstName; + dstFile = new File(dstName); + } + + if (srcTimeStamp > dstFile.lastModified()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!"); + return false; + } + } + + if (outStrFile.length() != 0) { + dstName = outStrFile; + File dstFile = new File(dstName); + if (!dstFile.isAbsolute()) { + dstName = outputDir + File.separator + dstName; + dstFile = new File(dstName); + } + + if (srcTimeStamp > dstFile.lastModified()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, srcName + " has been changed since last build!"); + return false; + } + } + + return true; + } } diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java index cba7a4e4bc..d37156dd70 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java @@ -23,6 +23,16 @@ import org.apache.tools.ant.taskdefs.LogStreamHandler; import org.apache.tools.ant.types.Commandline; import java.io.File; +import java.io.InputStreamReader; +import java.lang.ProcessBuilder; +import java.util.LinkedList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.List; +import java.util.StringTokenizer; +import java.util.Iterator; +import java.io.BufferedReader; +import java.io.FileReader; import org.tianocore.common.logger.EdkLog; @@ -38,6 +48,10 @@ public class GenFvImageTask extends Task implements EfiDefine{ // static final private String toolName = "GenFvImage"; // + // Pattern to match the section header (e.g. [options], [files]) + // + static final private Pattern sectionHeader = Pattern.compile("\\[([^\\[\\]]+)\\]"); + // // The name of input inf file // private FileArg infFile = new FileArg(); @@ -56,6 +70,11 @@ public class GenFvImageTask extends Task implements EfiDefine{ Project project = this.getOwningTarget().getProject(); String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); + if (isUptodate()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, infFile.toFileList() + " is uptodate!"); + return; + } + String command; if (path == null) { command = toolName; @@ -142,4 +161,117 @@ public class GenFvImageTask extends Task implements EfiDefine{ public void setOutputDir(String outputDir) { this.outputDir = outputDir; } + + // + // dependency check + // + private boolean isUptodate() { + String infName = this.infFile.getValue(); + String fvName = ""; + List ffsFiles = new LinkedList(); + File inf = new File(infName); + + try { + FileReader reader = new FileReader(inf); + BufferedReader in = new BufferedReader(reader); + String str; + + // + // Read the inf file line by line + // + boolean inFiles = false; + boolean inOptions = false; + while ((str = in.readLine()) != null) { + str = str.trim(); + if (str.length() == 0) { + continue; + } + + Matcher matcher = sectionHeader.matcher(str); + if (matcher.find()) { + // + // We take care of only "options" and "files" section + // + String sectionName = str.substring(matcher.start(1), matcher.end(1)); + if (sectionName.equalsIgnoreCase("options")) { + inOptions = true; + inFiles = false; + } else if (sectionName.equalsIgnoreCase("files")) { + inFiles = true; + inOptions = false; + } else { + inFiles = false; + inOptions = false; + } + continue; + } + + // + // skip invalid line + // + int equalMarkPos = str.indexOf("="); + if (equalMarkPos < 0) { + continue; + } + + // + // we have only interest in EFI_FILE_NAME + // + String fileNameFlag = str.substring(0, equalMarkPos).trim(); + String fileName = str.substring(equalMarkPos + 1).trim(); + if (!fileNameFlag.equalsIgnoreCase("EFI_FILE_NAME") + || fileName.length() == 0) { + continue; + } + + if (inFiles) { + // + // files specified beneath the [files] section are source files + // + ffsFiles.add(fileName); + } else if (inOptions) { + // + // file specified beneath the [options] section is the target file + // + fvName = outputDir + File.separator + fileName; + } + } + } catch (Exception ex) { + throw new BuildException(ex.getMessage()); + } + + // + // if destionation file doesn't exist, we need to generate it. + // + File fvFile = new File(fvName); + if (!fvFile.exists()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, fvName + " doesn't exist!"); + return false; + } + + // + // the inf file itself will be taken as source file, check its timestamp + // against the target file + // + long fvFileTimeStamp = fvFile.lastModified(); + if (inf.lastModified() > fvFileTimeStamp) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, infName + " has been changed since last build!"); + return false; + } + + // + // no change in the inf file, we need to check each source files in it + // against the target file + // + for (Iterator it = ffsFiles.iterator(); it.hasNext(); ) { + String fileName = (String)it.next(); + File file = new File(fileName); + if (file.lastModified() > fvFileTimeStamp) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, fileName + " has been changed since last build!"); + return false; + } + } + + return true; + } } diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/NestElement.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/NestElement.java index be1d88aa35..271dee6c88 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/NestElement.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/NestElement.java @@ -32,7 +32,7 @@ public class NestElement extends DataType { // The name list. All the name strings got from setXXX methods will be put // in here. // - private List nameList = new ArrayList(); + protected List nameList = new ArrayList(); /** Insert content in the newElement into this NestElement diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java index 76a396c2b5..1f8a4d1f3c 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java @@ -67,6 +67,10 @@ public class PeiReBaseTask extends Task implements EfiDefine { @throws BuidException **/ public void execute() throws BuildException { + if (isUptodate()) { + EdkLog.log(this, EdkLog.EDK_VERBOSE, outputFile.toFileList() + " is up-to-date!"); + return; + } Project project = this.getOwningTarget().getProject(); @@ -247,4 +251,18 @@ public class PeiReBaseTask extends Task implements EfiDefine { public void setMapFile(String mapFile) { this.mapFile.setArg(" -M ", mapFile); } + + // + // Dependency check + // + private boolean isUptodate() { + File srcFile = new File(inputFile.getValue()); + File dstFile = new File(outputFile.getValue()); + + if (srcFile.lastModified() > dstFile.lastModified()) { + return false; + } + + return true; + } } diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ToolArg.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ToolArg.java index 2694f036de..ade6817955 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ToolArg.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ToolArg.java @@ -139,4 +139,13 @@ public class ToolArg extends NestElement { public String toString() { return super.toString(prefix); } + + /** + Check if the argument is empty or not + + @return boolean + **/ + public boolean isEmpty() { + return (prefix.length() == 0) && (nameList.isEmpty()); + } } diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java index 3d2c36ad21..addb43a6cf 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java @@ -193,6 +193,12 @@ public class FpdParserTask extends Task { getProject().setProperty("FV_FILENAME", validFv[i]); File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".inf")); + if (fvFile.exists() && (fvFile.lastModified() >= fpdFile.lastModified())) { + // + // don't re-generate FV.inf if fpd has not been changed + // + continue; + } fvFile.getParentFile().mkdirs(); try {