Supporting Apriori File from build tool.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1949 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong 2006-11-14 07:15:01 +00:00
parent ed7aa83f2e
commit 380191dd24
5 changed files with 218 additions and 6 deletions

View File

@ -1392,4 +1392,27 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
tofile="${DEST_DIR_OUTPUT}/${BASE_NAME}.efi"/>
</sequential>
</macrodef>
<!--
Build macro for Apriori
-->
<macrodef name="Build_Apriori">
<attribute name="FILEPATH" default="."/>
<attribute name="FILENAME"/>
<attribute name="FILEEXT" default="apr"/>
<attribute name="GUID"/>
<sequential>
<mkdir dir="${FV_DIR}/Apriori" />
<gensection inputfile="${FV_DIR}/@{FILEPATH}/@{FILENAME}.@{FILEEXT}"
outputfile="${FV_DIR}/Apriori/@{FILENAME}.sec"
sectiontype="EFI_SECTION_RAW"/>
<genffsfile BaseName="@{FILENAME}" ffsATTRIBCHECKSUM="TRUE" ffsFILETYPE="EFI_FV_FILETYPE_FREEFORM"
fileGuid="@{GUID}" moduleType="BASE" outputDir="${FV_DIR}">
<sectFile fileName="${FV_DIR}/Apriori/@{FILENAME}.sec"/>
</genffsfile>
</sequential>
</macrodef>
</project>

View File

@ -121,7 +121,7 @@ public class FpdParserForThread extends FpdParserTask {
// Gen build.xml
//
String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";
PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);
PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile, aprioriType);
fileGenerator.genBuildFile();
//

View File

@ -91,15 +91,24 @@ public class FpdParserTask extends Task {
///
Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();
///
/// Mapping from FV apriori file to its type (PEI or DXE)
///
Map<String, String> aprioriType = new HashMap<String, String>();
///
/// FpdParserTask can specify some ANT properties.
///
private Vector<Property> properties = new Vector<Property>();
SurfaceAreaQuery saq = null;
boolean isUnified = true;
boolean isUnified = true;
public static String PEI_APRIORI_GUID = "00000000-0000-0000-0000-000000000000";
public static String DXE_APRIORI_GUID = "fc510ee7-ffdc-11d4-bd41-0080c73c8881";
/**
Public construct method. It is necessary for ANT task.
**/
@ -163,7 +172,7 @@ public class FpdParserTask extends Task {
// Gen build.xml
//
String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";
PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);
PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile, aprioriType);
fileGenerator.genBuildFile();
//
@ -318,6 +327,33 @@ public class FpdParserTask extends Task {
if (files != null) {
bw.write("[files]");
bw.newLine();
Set<FpdModuleIdentification> modules = null;
if ( (modules = getPeiApriori(validFv[i])) != null) {
//
// Special GUID - validFv[i].FFS
//
String str = ffsCommonDir + File.separatorChar + "FV" + File.separatorChar + PEI_APRIORI_GUID + "-" + validFv[i] + ".FFS";
bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));
bw.newLine();
File aprioriFile = new File(getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".apr");
aprioriType.put(validFv[i], PEI_APRIORI_GUID);
genAprioriFile(modules, aprioriFile);
} else if((modules = getDxeApriori(validFv[i])) != null) {
//
// Special GUID - validFv[i].FFS
//
String str = ffsCommonDir + File.separatorChar + "FV" + File.separatorChar + DXE_APRIORI_GUID + "-" + validFv[i] + ".FFS";
bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));
bw.newLine();
File aprioriFile = new File(getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".apr");
aprioriType.put(validFv[i], DXE_APRIORI_GUID);
genAprioriFile(modules, aprioriFile);
}
for (int j = 0; j < files.length; j++) {
String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);
bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));
@ -375,7 +411,7 @@ public class FpdParserTask extends Task {
}
String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";
PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);
PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile, aprioriType);
fileGenerator.genBuildFile();
Ant ant = new Ant();
@ -688,6 +724,97 @@ public class FpdParserTask extends Task {
return archs;
}
private void genAprioriFile(Set<FpdModuleIdentification> modules, File file) {
try {
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
Iterator<FpdModuleIdentification> iter = modules.iterator();
while(iter.hasNext()) {
bw.write(iter.next().getModule().getGuid());
bw.newLine();
}
bw.flush();
bw.close();
fw.close();
} catch (IOException ex) {
BuildException buildException = new BuildException("Generation of the Apriori file [" + file.getPath() + "] failed!\n" + ex.getMessage());
buildException.setStackTrace(ex.getStackTrace());
throw buildException;
}
}
private Set<FpdModuleIdentification> getPeiApriori(String fvName) throws EdkException {
Node node = saq.getPeiApriori(fvName);
Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();
if (node == null) {
return null;
}
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childItem = childNodes.item(i);
if (childItem.getNodeType() == Node.ELEMENT_NODE) {
//
// Find child elements "IncludeModules"
//
if (childItem.getNodeName().compareTo("IncludeModules") == 0) {
//
// result will be updated
//
processNodes(childItem, result);
} else if (childItem.getNodeName().compareTo("FvName") == 0) {
} else if (childItem.getNodeName().compareTo("InfFileName") == 0) {
} else {
//
// Report Warning
//
EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised element " + childItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='APRIORI' Identifier='0']");
}
}
}
return result;
}
private Set<FpdModuleIdentification> getDxeApriori(String fvName) throws EdkException {
Node node = saq.getDxeApriori(fvName);
Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();
if (node == null) {
return null;
}
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childItem = childNodes.item(i);
if (childItem.getNodeType() == Node.ELEMENT_NODE) {
//
// Find child elements "IncludeModules"
//
if (childItem.getNodeName().compareTo("IncludeModules") == 0) {
//
// result will be updated
//
processNodes(childItem, result);
} else if (childItem.getNodeName().compareTo("FvName") == 0) {
} else if (childItem.getNodeName().compareTo("InfFileName") == 0) {
} else {
//
// Report Warning
//
EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised element " + childItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='APRIORI' Identifier='1']");
}
}
}
return result;
}
private Set<FpdModuleIdentification> getModuleSequenceForFv(String fvName) throws EdkException {
Node node = saq.getFpdModuleSequence(fvName);
Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();

View File

@ -64,6 +64,8 @@ public class PlatformBuildFileGenerator {
private File platformBuildFile = null;
private Map<String, String> aprioriType = null;
private Project project;
private String info = "DO NOT EDIT \n"
@ -72,13 +74,14 @@ public class PlatformBuildFileGenerator {
+ "Abstract:\n"
+ "Auto-generated ANT build file for building EFI Modules and Platforms\n";
public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile){
public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile, Map<String, String> aprioriType){
this.project = project;
this.outfiles = outfiles;
this.isUnified = isUnified;
this.fvs = fvs;
this.saq = saq;
this.platformBuildFile = new File(platformBuildFile);
this.aprioriType = aprioriType;
}
/**
@ -193,6 +196,39 @@ public class PlatformBuildFileGenerator {
Element ele = document.createElement("target");
ele.setAttribute("name", "modules");
//
// Try to build apriori if necessary
//
//
// For every Target and ToolChain
//
String[] targetList = GlobalData.getToolChainInfo().getTargets();
for (int i = 0; i < targetList.length; i++){
String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
for(int j = 0; j < toolchainList.length; j++){
//
// Prepare FV_DIR
//
String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar
+ targetList[i] + "_"
+ toolchainList[j];
File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");
Element fvEle = document.createElement("var");
fvEle.setAttribute("name", "FV_DIR");
fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));
ele.appendChild(fvEle);
Iterator<String> aprIter = aprioriType.keySet().iterator();
while (aprIter.hasNext()) {
String fvName = aprIter.next();
Element moduleEle = document.createElement("Build_Apriori");
moduleEle.setAttribute("FILENAME", fvName);
moduleEle.setAttribute("GUID", aprioriType.get(fvName));
ele.appendChild(moduleEle);
}
}
}
//
// Get all valid FV name
//

View File

@ -2011,6 +2011,32 @@ public class SurfaceAreaQuery {
}
}
public Node getPeiApriori(String fvName) {
String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName + "']" };
Object[] result = get("PlatformSurfaceArea", xPath);
if (result == null || result.length == 0) {
return null;
}
UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
return a.getDomNode();
}
public Node getDxeApriori(String fvName) {
String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName + "']" };
Object[] result = get("PlatformSurfaceArea", xPath);
if (result == null || result.length == 0) {
return null;
}
UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
return a.getDomNode();
}
public Node getFpdModuleSequence(String fvName) {
String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName + "']" };
Object[] result = get("PlatformSurfaceArea", xPath);