From 498e9021f57d5c739fbc1a79434ed4697db7275d Mon Sep 17 00:00:00 2001 From: wuyizhong Date: Tue, 12 Sep 2006 07:16:25 +0000 Subject: [PATCH] =?utf8?q?Update=20LOG=20process.=201.=20Sort=20all=20log?= =?utf8?q?=20messages=20by=20module.=20Logs=20at=20the=20bottom=20of=20bui?= =?utf8?q?ld.log=20is=20all=20logs=20already=20print=20to=20cmd=202.=20Onc?= =?utf8?q?e=20one=20module=20occurs=20error,=20print=20all=20logs=20belong?= =?utf8?q?s=20to=20this=20module=E2=80=99s?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1516 6f19259b-4bc3-4df7-8a09-765794883524 --- .../tianocore/build/FrameworkBuildTask.java | 2 +- .../org/tianocore/build/GenBuildTask.java | 2 +- .../org/tianocore/build/GenBuildThread.java | 26 +++++-- .../build/fpd/FpdParserForThread.java | 27 ++++--- .../build/global/GenBuildLogger.java | 78 +++++++++++++++---- 5 files changed, 102 insertions(+), 33 deletions(-) diff --git a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java index 45a46b0fe6..df9c2422be 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java @@ -103,7 +103,7 @@ public class FrameworkBuildTask extends Task{ /// /// The concurrent thread number /// - public static int MAX_CONCURRENT_THREAD_NUMBER = 1; + public static int MAX_CONCURRENT_THREAD_NUMBER = 2; /// /// there are three type: all (build), clean and cleanall diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java index a541f87779..7990989d23 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java @@ -600,7 +600,7 @@ public class GenBuildTask extends Ant { ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch()); String propertyLibs = ""; for (int i = 0; i < libinstances.length; i++) { - propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib"; + propertyLibs += getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib" + " "; } getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/")); diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java index 9c8e47c4ef..3490c10ad8 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java +++ b/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java @@ -24,6 +24,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Property; import org.tianocore.build.GenBuildTask; import org.tianocore.build.fpd.FpdParserForThread; +import org.tianocore.build.global.GenBuildLogger; import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.common.logger.EdkLog; @@ -65,7 +66,9 @@ public class GenBuildThread implements Runnable { } status = FpdParserForThread.STATUS_START_RUN; + thread.start(); + return true; } @@ -129,27 +132,40 @@ public class GenBuildThread implements Runnable { newProject.setInputHandler(project.getInputHandler()); Iterator listenerIter = project.getBuildListeners().iterator(); + GenBuildLogger newLogger = null; while (listenerIter.hasNext()) { - newProject.addBuildListener((BuildListener)listenerIter.next()); + BuildListener item = (BuildListener)listenerIter.next(); + if (item instanceof GenBuildLogger) { + newLogger = (GenBuildLogger)((GenBuildLogger)item).clone(); + newLogger.setId(fpdModuleId); + newProject.addBuildListener(newLogger); + } else { + newProject.addBuildListener(item); + } } project.initSubProject(newProject); - + genBuildTask.setProject(newProject); genBuildTask.setExternalProperties(properties); genBuildTask.parentId = parentModuleId; - + genBuildTask.execute(); } catch (BuildException be) { - FpdParserForThread.tg.interrupt(); + EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, moduleId + " with Arch " + arch +" build error. \n" + be.getMessage()); - FpdParserForThread.isError = true; + + if (FpdParserForThread.errorModule == null) { + FpdParserForThread.errorModule = fpdModuleId; + } synchronized (FpdParserForThread.deamonSemaphore) { + FpdParserForThread.subCount(); FpdParserForThread.deamonSemaphore.notifyAll(); } + return ; } diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserForThread.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserForThread.java index 8767b8ff97..de9a28c7d5 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserForThread.java +++ b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserForThread.java @@ -67,7 +67,7 @@ public class FpdParserForThread extends FpdParserTask { public static ThreadGroup tg = new ThreadGroup("Framework"); - public static boolean isError = false; + public static FpdModuleIdentification errorModule = null; /** Public construct method. It is necessary for ANT task. @@ -163,10 +163,7 @@ public class FpdParserForThread extends FpdParserTask { // Waiting for all thread over, or time out // synchronized (deamonSemaphore) { - // - // Initialize BUGBUG - // - + while (true) { // // If all modules are already built @@ -231,15 +228,22 @@ public class FpdParserForThread extends FpdParserTask { try { deamonSemaphore.wait(); - if (isError) { + + // + // if find error. Let other threads to finish + // + if (errorModule != null) { + while (currentRunNumber > 0) { + deamonSemaphore.wait(); + } + GenBuildLogger.setCacheEnable(false); - EdkLog.flushLogToFile(new File(buildDir + File.separatorChar + "build.log")); - GenBuildLogger.maskAllLog(true); - FpdParserForThread.tg.destroy(); - GenBuildLogger.maskAllLog(false); + GenBuildLogger.flushErrorModuleLog(errorModule); - throw new BuildException("One thread error. "); + EdkLog.flushLogToFile(new File(buildDir + File.separatorChar + "build.log")); + + throw new BuildException(errorModule + " build error. "); } } catch (InterruptedException ex) { BuildException e = new BuildException("Thread wait Error. \n" + ex.getMessage()); @@ -270,7 +274,6 @@ public class FpdParserForThread extends FpdParserTask { ant.execute(); EdkLog.flushLogToFile(new File(buildDir + File.separatorChar + "build.log")); - } diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java b/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java index 898fbc70df..93ed51e0f3 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java @@ -24,7 +24,8 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.StringReader; -import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Vector; @@ -36,13 +37,13 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.util.StringUtils; -import org.tianocore.build.id.Identification; +import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.common.logger.EdkLog; import org.tianocore.common.logger.LogMethod; public class GenBuildLogger extends DefaultLogger implements LogMethod { - private Project project = null; + Project project = null; /// /// flag to present whether cache all msg or not @@ -52,9 +53,9 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod { private static boolean enableFlag = true; - private static Map> map = new HashMap >(256); + private static Map> map = new LinkedHashMap >(256); - private Identification id = null; + private FpdModuleIdentification id = null; public GenBuildLogger () { @@ -64,11 +65,6 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod { this.project = project; } - public GenBuildLogger (Project project, Identification id) { - this.project = project; - this.id = id; - } - /** Rules: flag = false: means no cache Action: Print it to console @@ -108,6 +104,16 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod { break; } } + + public static void flushErrorModuleLog(FpdModuleIdentification errorModuleId) { + List errorLogs = map.get(errorModuleId); + if (errorLogs != null) { + EdkLog.log("ErrorLog", EdkLog.EDK_ERROR, errorModuleId + " error logs: "); + for(int i = 0; i < errorLogs.size(); i++) { + EdkLog.log(EdkLog.EDK_ERROR, errorLogs.get(i)); + } + } + } public void flushToFile(File file) { // @@ -117,10 +123,33 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod { log("Logging", msg, Project.MSG_INFO); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); - List allMessages = map.get(null); - for(int i = 0; i < allMessages.size(); i++) { - bw.write(allMessages.get(i)); + Iterator iter = map.keySet().iterator(); + List mainLogs = null; + while (iter.hasNext()) { + FpdModuleIdentification item = iter.next(); + if(item == null) { + mainLogs = map.get(item); + continue ; + } + bw.write(">>>>>>>>>>>>>"); + bw.write(" " + item + " Build Log "); + bw.write(">>>>>>>>>>>>>"); + bw.newLine(); + List allMessages = map.get(item); + for(int i = 0; i < allMessages.size(); i++) { + bw.write(allMessages.get(i)); + bw.newLine(); + } + } + if (mainLogs != null) { + bw.write(">>>>>>>>>>>>>"); + bw.write(" Main Logs (already print to command) "); + bw.write(">>>>>>>>>>>>>"); bw.newLine(); + for(int i = 0; i < mainLogs.size(); i++) { + bw.write(mainLogs.get(i)); + bw.newLine(); + } } bw.flush(); bw.close(); @@ -197,7 +226,6 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod { } else if(!flag) { printMessage(msg, out, currentLevel); } - log(msg); } } @@ -222,4 +250,26 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod { map.put(this.id, list); } } + + public Object clone() { + GenBuildLogger newLogger = new GenBuildLogger(); + // + // Transfer emacs mode, out, err, level to new Logger + // + newLogger.setEmacsMode(this.emacsMode); + newLogger.setOutputPrintStream(this.out); + newLogger.setErrorPrintStream(this.err); + newLogger.setMessageOutputLevel(this.msgOutputLevel); + + // + // Transfer project + // + newLogger.project = this.project; + return newLogger; + } + + public void setId(FpdModuleIdentification id) { + this.id = id; + } + } \ No newline at end of file -- 2.39.2