X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FFrameworkTasks%2Forg%2Ftianocore%2Fframework%2Ftasks%2FMakeDeps.java;h=76ab8e071500cd7177d109c6be553283535dd651;hb=91f7d582299ddc08babbff1624df3fd136a37ee9;hp=5c4de1a78ef232edfb92b151195f64d845a381ef;hpb=ff225cbbae618da0eb4ad54064a40e7dd4e343df;p=mirror_edk2.git diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/MakeDeps.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/MakeDeps.java index 5c4de1a78e..76ab8e0715 100644 --- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/MakeDeps.java +++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/MakeDeps.java @@ -16,17 +16,11 @@ package org.tianocore.framework.tasks; import java.io.File; import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.LineNumberReader; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -47,8 +41,6 @@ public class MakeDeps extends Task { // private members, use set/get to access them // private static final String cmdName = "MakeDeps"; - private static final String target = "dummy"; - private String includePath = null; private String depsFile = null; private String subDir = null; private boolean quietMode = true; @@ -79,20 +71,17 @@ public class MakeDeps extends Task { Project prj = this.getOwningTarget().getProject(); String toolPath = prj.getProperty("env.FRAMEWORK_TOOLS_PATH"); - FrameworkLogger logger = new FrameworkLogger(prj, "makedeps"); - EdkLog.setLogLevel(prj.getProperty("env.LOGLEVEL")); - EdkLog.setLogger(logger); /// /// compose full tool path /// if (toolPath == null || toolPath.length() == 0) { - toolPath = "./" + cmdName; + toolPath = cmdName; } else { if (toolPath.endsWith("/") || toolPath.endsWith("\\")) { toolPath = toolPath + cmdName; } else { - toolPath = toolPath + "/" + cmdName; + toolPath = toolPath + File.separator + cmdName; } } @@ -101,10 +90,10 @@ public class MakeDeps extends Task { /// StringBuffer args = new StringBuffer(4096); if (ignoreError) { - args.append(" -ignorenotfound"); + args.append(" -ignorenotfound "); } if (quietMode) { - args.append(" -q"); + args.append(" -q "); } if (subDir != null && subDir.length() > 0) { args.append(" -s "); @@ -121,43 +110,20 @@ public class MakeDeps extends Task { /// /// compose source file arguments /// - Iterator iterator = inputFileList.iterator(); - while (iterator.hasNext()) { - Input inputFile = (Input)iterator.next(); - String inputFileString = cleanupPathName(inputFile.getFile()); - args.append(" -f "); - args.append(inputFileString); + for (int i = 0, listLength = inputFileList.size(); i < listLength; ++i) { + args.append(inputFileList.get(i).toString()); } - /// - /// compose search pathes argument - /// - StringBuffer includePathArg = new StringBuffer(4096); - if (includePath != null && includePath.length() > 0) { - StringTokenizer pathTokens = new StringTokenizer(includePath, ";"); - while (pathTokens.hasMoreTokens()) { - String tmpPath = pathTokens.nextToken().trim(); - if (tmpPath.length() == 0) { - continue; - } - - includePathArg.append(" -i "); - includePathArg.append(cleanupPathName(tmpPath)); - } - } - iterator = includePathList.iterator(); - while (iterator.hasNext()) { - IncludePath path = (IncludePath)iterator.next(); - includePathArg.append(cleanupPathName(path.getPath())); + for (int i = 0, listLength = includePathList.size(); i < listLength; ++i) { + args.append(includePathList.get(i).toString()); } - args.append(includePathArg); /// /// We don't need a real target. So just a "dummy" is given /// args.append(" -target dummy"); args.append(" -o "); - args.append(cleanupPathName(depsFile)); + args.append(depsFile); /// /// prepare to execute the tool @@ -172,7 +138,7 @@ public class MakeDeps extends Task { runner.setAntRun(prj); runner.setCommandline(cmd.getCommandline()); - EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmd.getCommandline())); + EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmd.getCommandline())); int result = 0; try { @@ -182,13 +148,8 @@ public class MakeDeps extends Task { } if (result != 0) { - EdkLog.log(EdkLog.EDK_INFO, "MakeDeps failed!"); - return; - } - - // change the old DEP file format (makefile compatible) to just file list - if (!cleanup()) { - throw new BuildException(depsFile + " was not generated!"); + EdkLog.log(this, EdkLog.EDK_INFO, "MakeDeps failed!"); + throw new BuildException("MakeDeps: failed to generate dependency file!"); } } @@ -263,7 +224,7 @@ public class MakeDeps extends Task { @param dir The name of sub-directory in which source files will be scanned **/ public void setSubDir(String dir) { - subDir = dir; + subDir = cleanupPathName(dir); } /** @@ -275,31 +236,13 @@ public class MakeDeps extends Task { return subDir; } - /** - Set method for "IncludePath" attribute - - @param path The name of include path - **/ - public void setIncludePath(String path) { - includePath = cleanupPathName(path); - } - - /** - Get method for "IncludePath" attribute - - @returns The name of include path - **/ - public String getIncludePath() { - return includePath; - } - /** Set method for "ExtraDeps" attribute @param deps The name of dependency file specified separately **/ public void setExtraDeps(String deps) { - extraDeps = deps; + extraDeps = cleanupPathName(deps); } /** @@ -329,75 +272,6 @@ public class MakeDeps extends Task { inputFileList.add(inputFile); } - /** - The original file generated by MakeDeps.exe is for makefile uses. The target - part (before :) is not useful for ANT. This method will do the removal. - - @returns true if cleaned files is saved successfully - @returns false if error occurs in file I/O system - **/ - private boolean cleanup() { - File df = new File(depsFile); - - if (!df.exists()) { - return false; - } - - LineNumberReader lineReader = null; - FileReader fileReader = null; - Set lineSet = new HashSet(100); // used to remove duplicated lines - try { - fileReader = new FileReader(df); - lineReader = new LineNumberReader(fileReader); - - /// - /// clean-up each line in deps file - // - String line = null; - while ((line = lineReader.readLine()) != null) { - String[] filePath = line.split(" : "); - if (filePath.length == 2) { - /// - /// keep the file name after ":" - /// - lineSet.add(cleanupPathName(filePath[1])); - } - } - lineReader.close(); - fileReader.close(); - - /// - /// we may have explicitly specified dependency files - /// - StringTokenizer fileTokens = new StringTokenizer(extraDeps, ";"); - while (fileTokens.hasMoreTokens()) { - lineSet.add(cleanupPathName(fileTokens.nextToken())); - } - - /// - /// compose the final file content - /// - StringBuffer cleanedLines = new StringBuffer(40960); - Iterator it = lineSet.iterator(); - while (it.hasNext()) { - String filePath = it.next(); - cleanedLines.append(filePath); - cleanedLines.append("\n"); - } - /// - /// overwrite old dep file with new content - /// - FileWriter fileWriter = null; - fileWriter = new FileWriter(df); - fileWriter.write(cleanedLines.toString()); - fileWriter.close(); - } catch (IOException e) { - log (e.getMessage()); - } - - return true; - } - /** Check if the dependency list file should be (re-)generated or not. @@ -410,26 +284,29 @@ public class MakeDeps extends Task { return false; } - /// - /// If the source file(s) is newer than dependency list file, we need to - /// re-generate the dependency list file - /// + // + // If the source file(s) is newer than dependency list file, we need to + // re-generate the dependency list file + // long depsFileTimeStamp = df.lastModified(); - Iterator iterator = inputFileList.iterator(); + Iterator iterator = (Iterator)inputFileList.iterator(); while (iterator.hasNext()) { - Input inputFile = (Input)iterator.next(); - File sf = new File(inputFile.getFile()); - if (sf.lastModified() > depsFileTimeStamp) { - return false; + Input inputFile = iterator.next(); + List fileList = inputFile.getNameList(); + for (int i = 0, length = fileList.size(); i < length; ++i) { + File sf = new File(fileList.get(i)); + if (sf.lastModified() > depsFileTimeStamp) { + return false; + } } } - /// - /// If the source files haven't been changed since last time the dependency - /// list file was generated, we need to check each file in the file list to - /// see if any of them is changed or not. If anyone of them is newer than - /// the dependency list file, MakeDeps.exe is needed to run again. - /// + // + // If the source files haven't been changed since last time the dependency + // list file was generated, we need to check each file in the file list to + // see if any of them is changed or not. If anyone of them is newer than + // the dependency list file, MakeDeps.exe is needed to run again. + // LineNumberReader lineReader = null; FileReader fileReader = null; boolean ret = true; @@ -440,7 +317,10 @@ public class MakeDeps extends Task { String line = null; while ((line = lineReader.readLine()) != null) { File sourceFile = new File(line); - if (sourceFile.lastModified() > depsFileTimeStamp) { + // + // If a file cannot be found (moved or removed) or newer, regenerate the dep file + // + if ((!sourceFile.exists()) || (sourceFile.lastModified() > depsFileTimeStamp)) { ret = false; break; }