Support MSA build options. Now the build options from four places: 1. tools_def.txt

2. MSA <ModuleBuildOptions>/<Options> 3. FPD <BuildOptions>/<Options> 4. FPD <FrameworkModules>/<ModuleSaBuildOptions>/<Options>. And we do not support "ABC", "XYZ" such format from now on, please only use the simple format like ABC XYZ. 

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1790 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong
2006-10-18 08:22:09 +00:00
parent 01022d98b3
commit b69bb9ba72
7 changed files with 94 additions and 77 deletions

View File

@ -23,8 +23,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.BuildListener;
@ -490,10 +488,6 @@ public class GenBuildTask extends Ant {
String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId); String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);
if (cmdFlags != null) if (cmdFlags != null)
{ {
// Set<String> addset = new LinkedHashSet<String>();
// Set<String> subset = new LinkedHashSet<String>();
// putFlagsToSet(addset, cmdFlags);
// getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
getProject().setProperty(cmd[m] + "_FLAGS", cmdFlags); getProject().setProperty(cmd[m] + "_FLAGS", cmdFlags);
} }
else else
@ -501,7 +495,6 @@ public class GenBuildTask extends Ant {
getProject().setProperty(cmd[m] + "_FLAGS", ""); getProject().setProperty(cmd[m] + "_FLAGS", "");
} }
// //
// Set CC_EXT // Set CC_EXT
// //
@ -718,54 +711,6 @@ public class GenBuildTask extends Ant {
ant.execute(); ant.execute();
} }
/**
Separate the string and instore in set.
<p> String is separated by Java Regulation Expression
"[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
<p>For example: </p>
<pre>
"/nologo", "/W3", "/WX"
"/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
</pre>
@param set store the separated string
@param str string to separate
**/
private void putFlagsToSet(Set<String> set, String str) {
if (str == null || str.length() == 0) {
return;
}
Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
Matcher matcher = myPattern.matcher(str + " ");
while (matcher.find()) {
String item = str.substring(matcher.start(1), matcher.end(1));
set.add(item);
}
}
/**
Generate the final flags string will be used by compile command.
@param add the add flags set
@param sub the sub flags set
@return final flags after add set substract sub set
**/
private String getFlags(Set<String> add, Set<String> sub) {
String result = "";
add.removeAll(sub);
Iterator iter = add.iterator();
while (iter.hasNext()) {
String str = (String) iter.next();
result += str.substring(1, str.length() - 1) + " ";
}
return result;
}
public void setSingleModuleBuild(boolean isSingleModuleBuild) { public void setSingleModuleBuild(boolean isSingleModuleBuild) {
this.isSingleModuleBuild = isSingleModuleBuild; this.isSingleModuleBuild = isSingleModuleBuild;
} }

View File

@ -368,6 +368,13 @@ public class FpdParserForThread extends FpdParserTask {
// //
GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false)); GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));
GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true)); GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));
//
// parse MSA build options
//
GlobalData.addMsaBuildOption(moduleId, parseMsaBuildOptions(false));
GlobalData.addMsaFamilyBuildOption(moduleId, parseMsaBuildOptions(true));
saq.pop(); saq.pop();
} }
} }

View File

@ -516,6 +516,13 @@ public class FpdParserTask extends Task {
// //
GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false)); GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));
GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true)); GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));
//
// parse MSA build options
//
GlobalData.addMsaBuildOption(moduleId, parseMsaBuildOptions(false));
GlobalData.addMsaFamilyBuildOption(moduleId, parseMsaBuildOptions(true));
saq.pop(); saq.pop();
} }
} }
@ -536,6 +543,14 @@ public class FpdParserTask extends Task {
return parseOptions(options); return parseOptions(options);
} }
ToolChainMap parseMsaBuildOptions(boolean toolChainFamilyFlag) throws EdkException {
String[][] options = saq.getMsaBuildOptions(toolChainFamilyFlag);
if (options == null || options.length == 0) {
return new ToolChainMap();
}
return parseOptions(options);
}
private ToolChainMap parseOptions(String[][] options) throws EdkException { private ToolChainMap parseOptions(String[][] options) throws EdkException {
ToolChainMap map = new ToolChainMap(); ToolChainMap map = new ToolChainMap();
int flagIndex = ToolChainElement.ATTRIBUTE.value; int flagIndex = ToolChainElement.ATTRIBUTE.value;

View File

@ -45,11 +45,6 @@ public class GenBuildLogger extends DefaultLogger implements LogMethod {
Project project = null; Project project = null;
///
/// Time of the start of the build
///
private long startTime = System.currentTimeMillis();
/// ///
/// flag to present whether cache all msg or not /// flag to present whether cache all msg or not
/// true means to cache. /// true means to cache.

View File

@ -24,8 +24,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
@ -132,7 +130,10 @@ public class GlobalData {
private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>(); private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>(); private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); private static Map<ModuleIdentification, ToolChainMap> msaBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();
private static Map<ModuleIdentification, ToolChainMap> msaFamilyBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();
// private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
/** /**
Parse framework database (DB) and all SPD files listed in DB to initialize Parse framework database (DB) and all SPD files listed in DB to initialize
the environment for next build. This method will only be executed only once the environment for next build. This method will only be executed only once
@ -437,6 +438,7 @@ public class GlobalData {
msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true)); msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));
msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true)); msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));
msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true)); msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));
msaMap.put("ModuleBuildOptions", cloneXmlObject(msa.getModuleBuildOptions(), true));
return msaMap; return msaMap;
} catch(IOException ex) { } catch(IOException ex) {
EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());
@ -716,6 +718,16 @@ public class GlobalData {
moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption); moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);
} }
public static void addMsaBuildOption(ModuleIdentification moduleId,
ToolChainMap toolChainOption) {
msaBuildOption.put(moduleId, toolChainOption);
}
public static void addMsaFamilyBuildOption(ModuleIdentification moduleId,
ToolChainMap toolChainOption) {
msaFamilyBuildOption.put(moduleId, toolChainOption);
}
public static boolean isCommandSet(String target, String toolchain, String arch) { public static boolean isCommandSet(String target, String toolchain, String arch) {
String[] commands = getToolChainInfo().getCommands(); String[] commands = getToolChainInfo().getCommands();
@ -729,6 +741,22 @@ public class GlobalData {
return false; return false;
} }
/**
Except FLAGS, all attribute are from TOOLS_DEF file.
For FLAGS, information from four places, they are:
<pre>
1. tools_def.txt
2. MSA &lt;BuildOptions&gt;/&lt;Options&gt;
3. FPD &lt;BuildOptions&gt;/&lt;Options&gt;
4. FPD &lt;FrameworkModules&gt;/&lt;ModuleSaBuildOptions&gt;/&lt;Options&gt;
</pre>
@param commandDescription Key: TARGET, TAGNAME, ARCH, COMMANDTYPE, ATTRIBUTE
@param fpdModuleId Module Identification with Arch
@return The corresponding String
@throws EdkException If build option definition error
**/
public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException { public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {
ToolChainKey toolChainKey = new ToolChainKey(commandDescription); ToolChainKey toolChainKey = new ToolChainKey(commandDescription);
ToolChainMap toolChainConfig = toolsDef.getConfig(); ToolChainMap toolChainConfig = toolsDef.getConfig();
@ -746,7 +774,7 @@ public class GlobalData {
} }
// //
// tool's option can be in .fpd and/or .msa file // Tool's option can be in .fpd and/or .msa file
// //
String optionString; String optionString;
ToolChainMap option = null; ToolChainMap option = null;
@ -757,6 +785,22 @@ public class GlobalData {
toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value); toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS, ToolChainElement.ATTRIBUTE.value); toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS, ToolChainElement.ATTRIBUTE.value);
//
// MSA's tool chain family option
//
option = msaFamilyBuildOption.get(fpdModuleId.getModule());
if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) {
setting += (" " + optionString);
}
//
// MSA's tool chain option
//
option = msaBuildOption.get(fpdModuleId.getModule());
if (option != null && (optionString = option.get(toolChainKey)) != null) {
setting += (" " + optionString);
}
// //
// Platform's tool chain family option // Platform's tool chain family option
// //
@ -770,10 +814,7 @@ public class GlobalData {
// //
optionString = platformToolChainOption.get(toolChainKey); optionString = platformToolChainOption.get(toolChainKey);
if (optionString != null) { if (optionString != null) {
Matcher matcher = flagPattern.matcher(optionString + " "); setting += (" " + optionString);
while (matcher.find()) {
setting += (" " + optionString.substring(matcher.start(1), matcher.end(1)));
}
} }
// //
@ -781,10 +822,7 @@ public class GlobalData {
// //
option = moduleToolChainFamilyOption.get(fpdModuleId); option = moduleToolChainFamilyOption.get(fpdModuleId);
if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) { if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) {
Matcher matcher = flagPattern.matcher(optionString + " "); setting += (" " + optionString);
while (matcher.find()) {
setting += (" " + optionString.substring(matcher.start(1), matcher.end(1)));
}
} }
// //
@ -792,10 +830,7 @@ public class GlobalData {
// //
option = moduleToolChainOption.get(fpdModuleId); option = moduleToolChainOption.get(fpdModuleId);
if (option != null && (optionString = option.get(toolChainKey)) != null) { if (option != null && (optionString = option.get(toolChainKey)) != null) {
Matcher matcher = flagPattern.matcher(optionString + " "); setting += (" " + optionString);
while (matcher.find()) {
setting += (" " + optionString.substring(matcher.start(1), matcher.end(1)));
}
} }
return setting; return setting;

View File

@ -493,6 +493,22 @@ public class SurfaceAreaQuery {
return getOptions("PlatformSurfaceArea", xPath, toolChainFamilyFlag); return getOptions("PlatformSurfaceArea", xPath, toolChainFamilyFlag);
} }
public String[][] getMsaBuildOptions(boolean toolChainFamilyFlag) {
String[] xPath;
if (toolChainFamilyFlag == true) {
xPath = new String[] {
"/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
"/Options/Option[@ToolChainFamily]", };
} else {
xPath = new String[] {
"/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
"/Options/Option[@TagName]", };
}
return getOptions("ModuleBuildOptions", xPath, toolChainFamilyFlag);
}
public ToolChainInfo getFpdToolChainInfo() { public ToolChainInfo getFpdToolChainInfo() {
String[] xPath = new String[] { "/PlatformDefinitions" }; String[] xPath = new String[] { "/PlatformDefinitions" };

View File

@ -320,5 +320,9 @@ public class ToolChainMap {
public Set<ToolChainKey> keySet() { public Set<ToolChainKey> keySet() {
return (Set<ToolChainKey>)map.keySet(); return (Set<ToolChainKey>)map.keySet();
} }
public String toString() {
return map + "";
}
} }