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
//\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
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
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