Adding new Logger instead of Ant's.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1502 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong 2006-09-08 09:22:36 +00:00
parent 4917d9ddc3
commit 2eb7d78dcd
13 changed files with 308 additions and 118 deletions

View File

@ -42,6 +42,8 @@ public class CompressSection implements Section, FfsTypes{
//
List<Object> SectList = new ArrayList<Object>();
public static Object semaphore = new Object();
/**
toBuffer
@ -85,6 +87,8 @@ public class CompressSection implements Section, FfsTypes{
}
Do.close();
synchronized (semaphore) {
//
// Call compress
//
@ -144,6 +148,7 @@ public class CompressSection implements Section, FfsTypes{
//
//di.close();
//compressOut.delete();
}
}
catch (Exception e){

View File

@ -154,11 +154,9 @@ public class FfsProcess {
}
Vector<String> sectionList = new Vector<String>();
XmlCursor cursor = null;
try {
cursor = ffsXmlObject.newCursor();
} catch (Exception e) {
return null;
}
int mode = MODE_NONE;
Element genffsfileEle = document.createElement("genffsfile");
genffsfileEle.setAttribute("outputDir", "${BIN_DIR}");

View File

@ -581,7 +581,7 @@ public class GenBuildTask extends Ant {
//
// Call AutoGen to generate AutoGen.c and AutoGen.h
//
AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch(), saq);
AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch(), saq, parentId);
autogen.genAutogen();
//

View File

@ -131,7 +131,16 @@ public class GenBuildThread implements Runnable {
Iterator listenerIter = project.getBuildListeners().iterator();
while (listenerIter.hasNext()) {
newProject.addBuildListener((BuildListener) listenerIter.next());
BuildListener item = (BuildListener) listenerIter.next();
// if (item instanceof BuildLogger) {
// BuildLogger newLogger = new GenBuildLogger(newProject);
// BuildLogger oldLogger = (BuildLogger)item;
// newLogger.setEmacsMode(true);
// EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, "########");
// } else {
newProject.addBuildListener(item);
// }
}
project.initSubProject(newProject);
@ -146,7 +155,7 @@ public class GenBuildThread implements Runnable {
status = FpdParserForThread.STATUS_END_RUN;
EdkLog.log("GenBuildThread", fpdModuleId + " build finished. ");
EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, fpdModuleId + " build finished. ");
//
//

View File

@ -14,21 +14,26 @@ package org.tianocore.build;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.tianocore.build.exception.GenBuildException;
import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.SurfaceAreaQuery;
import org.tianocore.build.id.FpdModuleIdentification;
@ -90,7 +95,7 @@ public class ModuleBuildFileGenerator {
@throws BuildException
Error throws during BaseName_build.xml generating.
**/
public void genBuildFile(String buildFilename) throws BuildException {
public void genBuildFile(String buildFilename) throws GenBuildException, EdkException {
FfsProcess fp = new FfsProcess();
DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
try {
@ -229,8 +234,22 @@ public class ModuleBuildFileGenerator {
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
xformer.transform(source, result);
} catch (Exception ex) {
throw new BuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage());
} catch (ParserConfigurationException ex) {
GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage());
e.setStackTrace(ex.getStackTrace());
throw e;
} catch (FileNotFoundException ex) {
GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage());
e.setStackTrace(ex.getStackTrace());
throw e;
} catch (TransformerConfigurationException ex) {
GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage());
e.setStackTrace(ex.getStackTrace());
throw e;
} catch (TransformerException ex) {
GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage());
e.setStackTrace(ex.getStackTrace());
throw e;
}
}

View File

@ -119,6 +119,8 @@ public class AutoGen {
private SurfaceAreaQuery saq = null;
private ModuleIdentification parentId = null;
/**
Construct function
@ -133,12 +135,13 @@ public class AutoGen {
@param arch
Target architecture.
**/
public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq) {
public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq, ModuleIdentification parentId) {
this.outputPath = outputPath;
this.moduleId = moduleId;
this.arch = arch;
this.fvDir = fvDir;
this.saq = saq;
this.parentId = parentId;
}
/**
@ -496,7 +499,8 @@ public class AutoGen {
arch,
false,
null,
pcdDriverType);
pcdDriverType,
parentId);
this.myPcdAutogen.execute();
if (this.myPcdAutogen != null) {
@ -653,7 +657,8 @@ public class AutoGen {
arch,
true,
saq.getModulePcdEntryNameArray(),
pcdDriverType);
pcdDriverType,
parentId);
this.myPcdAutogen.execute();
if (this.myPcdAutogen != null) {
fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);

View File

@ -25,6 +25,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Ant;
import org.apache.xmlbeans.XmlObject;
import org.tianocore.build.global.GenBuildLogger;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.OutputManager;
import org.tianocore.build.id.FpdModuleIdentification;
@ -60,6 +61,10 @@ public class FpdParserForThread extends FpdParserTask {
public static int currentRunNumber = 0;
public static int totalNumber = 0;
public static int remainNumber = 0;
/**
Public construct method. It is necessary for ANT task.
**/
@ -71,6 +76,8 @@ public class FpdParserForThread extends FpdParserTask {
**/
public void execute() throws BuildException {
this.setTaskName(".........");
//
// Parse FPD file
//
@ -93,7 +100,7 @@ public class FpdParserForThread extends FpdParserTask {
// Prepare FV_DIR
//
String ffsCommonDir = buildDir + File.separatorChar
+ targetList[i] + File.separatorChar
+ targetList[i] + "_"
+ toolchainList[j];
File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");
fvDir.mkdirs();
@ -144,8 +151,10 @@ public class FpdParserForThread extends FpdParserTask {
ant.init();
ant.execute();
EdkLog.log(this, "Task number is " + allThreads.size());
remainNumber = totalNumber = allThreads.size();
EdkLog.log(this, EdkLog.EDK_ALWAYS, "Total thread number is " + totalNumber);
GenBuildLogger.setCacheEnable(true);
//
// Waiting for all thread over, or time out
//
@ -162,6 +171,9 @@ public class FpdParserForThread extends FpdParserTask {
break ;
}
int percentage = (totalNumber - remainNumber) * 100 / totalNumber;
EdkLog.log(this, EdkLog.EDK_ALWAYS, percentage + "% finished. Has built " + (totalNumber - remainNumber) + " modules of " + totalNumber + " total. ");
Set<FpdModuleIdentification> currentQueueModules = fvs.get(queueList.get(currentQueueCode));
if (currentQueueModules == null) {
@ -192,35 +204,37 @@ public class FpdParserForThread extends FpdParserTask {
//
// Exist ready thread
//
EdkLog.log(this, "## Exist ready thread");
// EdkLog.log(this, EdkLog.EDK_ALWAYS, "Exist ready thread");
} else if (existNoneReady && currentRunNumber == 0) {
//
// No active thread, but still have dependency not read thread
//
throw new BuildException("Found can't resolve dependencies. ");
throw new BuildException("Existing some modules can't resolve depedencies. ");
} else if (!existNoneReady && currentRunNumber == 0) {
//
// Current queue build finish, move to next
//
EdkLog.log(this, "## Current queue build finish, move to next");
EdkLog.log(this, EdkLog.EDK_ALWAYS, "Current queue build finish, move to next");
++currentQueueCode;
continue ;
} else {
//
// active thread exist, but no ready thread
//
EdkLog.log(this, "## active thread exist, but no ready thread" + currentRunNumber);
EdkLog.log(this, EdkLog.EDK_ALWAYS, "Active thread exist, but no ready thread. Current running number is " + currentRunNumber);
}
try {
deamonSemaphore.wait();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InterruptedException ex) {
BuildException e = new BuildException("Thread wait Error. \n" + ex.getMessage());
e.setStackTrace(ex.getStackTrace());
throw e;
}
}
}
GenBuildLogger.setCacheEnable(false);
//
// call fvs, postbuild
//
@ -240,6 +254,8 @@ public class FpdParserForThread extends FpdParserTask {
ant.init();
ant.execute();
EdkLog.flushLogToFile(new File(buildDir + File.separatorChar + "build.log"));
}
@ -358,6 +374,7 @@ public class FpdParserForThread extends FpdParserTask {
public synchronized static void subCount() {
synchronized (countSemaphore) {
--currentRunNumber;
--remainNumber;
}
}
}

View File

@ -18,52 +18,63 @@
package org.tianocore.build.global;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
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.common.logger.EdkLog;
import org.tianocore.common.logger.LogMethod;
public class GenBuildLogger implements LogMethod {
public class GenBuildLogger extends DefaultLogger implements LogMethod {
private Project project = null;
///
/// flag to present whether cache all msg or not
/// true means not to cache.
/// true means to cache.
///
private boolean flag = true;
private static boolean flag = false;
private List<String> v = null;
private static Map<Identification, List<String>> map = new HashMap<Identification, List<String> >(256);
private Identification id = null;
public GenBuildLogger () {
}
public GenBuildLogger (Project project) {
this.project = project;
}
public GenBuildLogger (Project project, boolean flag) {
public GenBuildLogger (Project project, Identification id) {
this.project = project;
this.flag = flag;
//
// Only flag is false, v will be initialized and used.
//
if (!flag) {
v = new Vector<String>(2048);
}
this.id = id;
}
/**
Rules: flag = true: means no cache Action: Print it to console
Rules: flag = false: means no cache Action: Print it to console
flag = false: mean cache all msg exception some special Action: loglevel
flag = true: mean cache all msg exception some special Action: loglevel
is EDK_ALWAYS -- Print but no cache loglevel is EDK_ERROR -- Print and
cache the msg others -- No print and cache the msg
**/
public synchronized void putMessage(Object msgSource, int msgLevel,
String msg) {
public synchronized void putMessage(Object msgSource, int msgLevel, String msg) {
if (this.project == null) {
return;
}
@ -73,51 +84,47 @@ public class GenBuildLogger implements LogMethod {
//
switch (msgLevel) {
case EdkLog.EDK_ALWAYS:
log(msgSource, msg, Project.MSG_INFO);
//
// Do some special
//
log(msgSource, msg, Project.MSG_ERR);
break;
case EdkLog.EDK_ERROR:
if (flag) {
log(msgSource, msg, Project.MSG_ERR);
} else {
log(msgSource, msg, Project.MSG_ERR);
v.add(msg);
}
break;
case EdkLog.EDK_WARNING:
if (flag) {
log(msgSource, msg, Project.MSG_WARN);
} else {
v.add(msg);
}
break;
case EdkLog.EDK_INFO:
if (flag) {
log(msgSource, msg, Project.MSG_INFO);
} else {
v.add(msg);
}
break;
case EdkLog.EDK_VERBOSE:
if (flag) {
log(msgSource, msg, Project.MSG_VERBOSE);
} else {
v.add(msg);
}
break;
case EdkLog.EDK_DEBUG:
if (flag) {
log(msgSource, msg, Project.MSG_DEBUG);
} else {
v.add(msg);
}
break;
}
}
public void flushToFile(File file) {
//
// Sort msg and store to the file (TBD)
// Put all messages in map to file
//
String msg = "Writing log to file [" + file.getPath() + "]";
log("Logging", msg, Project.MSG_INFO);
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
List<String> allMessages = map.get(null);
for(int i = 0; i < allMessages.size(); i++) {
bw.write(allMessages.get(i));
bw.newLine();
}
bw.flush();
bw.close();
} catch (IOException e) {
new BuildException("Writing log error. " + e.getMessage());
}
}
@ -125,9 +132,8 @@ public class GenBuildLogger implements LogMethod {
if (msgSource instanceof Task) {
this.project.log((Task)msgSource, msg, level);
} else if (msgSource instanceof String){
//
// Pad 12 space to keep message
// Pad 12 space to keep message in unify format
//
msg = msg.replaceAll("\n", "\n ");
this.project.log(String.format("%12s", "[" + msgSource + "] ") + msg, level);
@ -135,4 +141,76 @@ public class GenBuildLogger implements LogMethod {
this.project.log(msg, level);
}
}
public void targetStarted(BuildEvent event) {
if (!flag) {
super.targetStarted(event);
}
}
public void messageLogged(BuildEvent event) {
int currentLevel = event.getPriority();
//
// If current level is upper than Ant Level, skip it
//
if (currentLevel <= this.msgOutputLevel) {
String originalMessage = event.getMessage();
StringBuffer message = new StringBuffer();
if (!emacsMode && event.getTask() != null) {
String label = String.format("%12s", "[" + event.getTask().getTaskName() + "] ");
//
// Append label first
//
message.append(label);
//
// Format all output message's line separator
//
try {
BufferedReader r = new BufferedReader(new StringReader(originalMessage));
boolean ifFirstLine = true;
String line = null;
while ((line = r.readLine()) != null) {
if (!ifFirstLine) {
message.append(StringUtils.LINE_SEP);
}
ifFirstLine = false;
message.append(line);
}
} catch (IOException e) {
message.append(originalMessage);
}
} else {
message.append(originalMessage);
}
String msg = message.toString();
if (currentLevel == Project.MSG_ERR) {
printMessage(msg, err, currentLevel);
} else if(currentLevel == Project.MSG_WARN) {
printMessage(msg, out, currentLevel);
} else if(!flag) {
printMessage(msg, out, currentLevel);
}
log(msg);
}
}
public static void setCacheEnable(boolean enable) {
flag = enable;
}
protected synchronized void log(String message) {
//
// cache log
//
if (map.containsKey(this.id)) {
map.get(this.id).add(message);
} else {
List<String> list = new Vector<String>(1024);
list.add(message);
map.put(this.id, list);
}
}
}

View File

@ -162,7 +162,7 @@ public class GlobalData {
// CONF dir + tools definition file name
//
File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
EdkLog.log("Init", "Using tool definition file [" + toolsDefFile.getPath() + "].");
EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "].");
toolsDef = new ToolChainConfig(toolsDefFile);
@ -686,8 +686,8 @@ public class GlobalData {
}
toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
toolChainInfo.normalize();
EdkLog.log("Init", "Current build tool chain information summary: ");
EdkLog.log("Init", toolChainInfo + "");
EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: ");
EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + "");
}
return toolChainInfo;
}

View File

@ -21,6 +21,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.tianocore.build.FrameworkBuildTask;
import org.tianocore.build.autogen.CommonDefinition;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.id.ModuleIdentification;
@ -72,6 +73,7 @@ public class PCDAutoGenAction extends BuildAction {
///
private String[] pcdNameArrayInMsa;
private UsageIdentification parentId = null;
/**
Set parameter moduleId
@ -142,7 +144,8 @@ public class PCDAutoGenAction extends BuildAction {
String arch,
boolean isBuildUsedLibrary,
String[] pcdNameArrayInMsa,
CommonDefinition.PCD_DRIVER_TYPE pcdDriverType) {
CommonDefinition.PCD_DRIVER_TYPE pcdDriverType,
ModuleIdentification parentId) {
dbManager = null;
hAutoGenString = "";
cAutoGenString = "";
@ -154,6 +157,15 @@ public class PCDAutoGenAction extends BuildAction {
arch,
moduleId.getVersion(),
moduleId.getModuleType()));
if (parentId != null) {
this.parentId = new UsageIdentification(parentId.getName(),
parentId.getGuid(),
parentId.getPackage().getName(),
parentId.getPackage().getGuid(),
arch,
parentId.getVersion(),
parentId.getModuleType());
}
setIsBuildUsedLibrary(isBuildUsedLibrary);
setPcdNameArrayInMsa(pcdNameArrayInMsa);
setPcdDriverType(pcdDriverType);
@ -211,6 +223,53 @@ public class PCDAutoGenAction extends BuildAction {
boolean found = false;
usageInstanceArray = null;
if (FrameworkBuildTask.multithread) {
if (parentId == null) {
usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);
} else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {
usageContext = dbManager.getUsageInstanceArrayById(parentId);
//
// For building library package, although all module are library, but PCD entries of
// these library should be used to autogen.
//
if (usageContext == null) {
usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);
} else {
usageInstanceArray = new ArrayList<UsageInstance>();
//
// Try to find all PCD defined in library's PCD in all <PcdEntry> in module's
// <ModuleSA> in FPD file.
//
for (index = 0; index < pcdNameArrayInMsa.length; index++) {
found = false;
for (index2 = 0; index2 < usageContext.size(); index2 ++) {
if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {
usageInstanceArray.add(usageContext.get(index2));
found = true;
break;
}
}
if (!found) {
//
// All library's PCD should instanted in module's <ModuleSA> who
// use this library instance. If not, give errors.
//
throw new BuildActionException (String.format("Module %s using library instance %s; the PCD %s " +
"is required by this library instance, but can not be found " +
"in the %s's <ModuleSA> in the FPD file!",
MemoryDatabaseManager.CurrentModuleName,
moduleName,
pcdNameArrayInMsa[index],
MemoryDatabaseManager.CurrentModuleName
));
}
}
}
}
} else {
if (!isBuildUsedLibrary) {
usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);
MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;
@ -257,7 +316,7 @@ public class PCDAutoGenAction extends BuildAction {
}
}
}
}
if (usageInstanceArray == null) {
return;
}

View File

@ -9,4 +9,4 @@
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
ant -f $WORKSPACE/build.xml $*
ant -logger org.tianocore.build.global.GenBuildLogger -f $WORKSPACE/build.xml $*

View File

@ -9,4 +9,4 @@
@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@REM
ant -f %WORKSPACE%/build.xml %*
ant -logger org.tianocore.build.global.GenBuildLogger -f %WORKSPACE%/build.xml %*