X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fglobal%2FGlobalData.java;h=74a2d4fe435987ffe6758d044d583e32068b8e44;hb=e485bb4bff9dbd617d73f2b93b840c4e2c54d6db;hp=bc2e359b0745a5d570c953674c2dbd28f0bc3107;hpb=250258de0d6ed07201db565101d45f4d92729bce;p=mirror_edk2.git
diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
index bc2e359b07..74a2d4fe43 100644
--- a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
+++ b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
@@ -1,10 +1,10 @@
/** @file
- GlobalData class.
-
+ GlobalData class.
+
GlobalData provide initializing, instoring, querying and update global data.
It is a bridge to intercommunicate between multiple component, such as AutoGen,
- PCD and so on.
-
+ PCD and so on.
+
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -17,7 +17,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
package org.tianocore.build.global;
import java.io.File;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -27,633 +26,810 @@ import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.xmlbeans.XmlObject;
-import org.tianocore.FilenameDocument;
-import org.tianocore.FilenameDocument.Filename;
+
+import org.tianocore.common.exception.EdkException;
+import org.tianocore.common.logger.EdkLog;
+import org.tianocore.pcd.entity.MemoryDatabaseManager;
+import org.tianocore.DbPathAndFilename;
import org.tianocore.FrameworkDatabaseDocument;
-import org.tianocore.MsaFilesDocument;
-import org.tianocore.MsaFilesDocument.MsaFiles.MsaFile;
-import org.tianocore.MsaHeaderDocument.MsaHeader;
-import org.tianocore.MsaLibHeaderDocument.MsaLibHeader;
-import org.tianocore.PackageListDocument;
-import org.tianocore.PackageSurfaceAreaDocument;
-import org.tianocore.build.autogen.CommonDefinition;
-import org.tianocore.build.fpd.FpdParserTask;
-import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
+import org.tianocore.ModuleSurfaceAreaDocument;
+import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
+import org.tianocore.build.id.FpdModuleIdentification;
+import org.tianocore.build.id.ModuleIdentification;
+import org.tianocore.build.id.PackageIdentification;
+import org.tianocore.build.id.PlatformIdentification;
+import org.tianocore.build.toolchain.ToolChainAttribute;
+import org.tianocore.build.toolchain.ToolChainConfig;
+import org.tianocore.build.toolchain.ToolChainElement;
+import org.tianocore.build.toolchain.ToolChainInfo;
+import org.tianocore.build.toolchain.ToolChainKey;
+import org.tianocore.build.toolchain.ToolChainMap;
/**
GlobalData provide initializing, instoring, querying and update global data.
It is a bridge to intercommunicate between multiple component, such as AutoGen,
- PCD and so on.
-
-
Note that all global information are initialized incrementally. All data will
- parse and record only it is necessary during build time.
-
+ PCD and so on.
+
+ Note that all global information are initialized incrementally. All data will
+ parse and record only of necessary during build time.
+
@since GenBuild 1.0
**/
public class GlobalData {
-
///
- /// means no surface area information for module
- ///
- public static final int NO_SA = 0;
-
- ///
- /// means only MSA
- ///
- public static final int ONLY_MSA = 1;
-
- ///
- /// means only Library MSA
- ///
- public static final int ONLY_LIBMSA = 2;
-
- ///
- /// means both MSA and MBD
- ///
- public static final int MSA_AND_MBD = 3;
-
- ///
- /// means both Library MSA and Library MBD
+ /// Record current WORKSPACE Directory
///
- public static final int LIBMSA_AND_LIBMBD = 4;
+ private static String workspaceDir = "";
///
/// Be used to ensure Global data will be initialized only once.
///
- public static boolean globalFlag = false;
+ private static boolean globalFlag = false;
///
- /// Record current WORKSPACE Directory
+ /// Framework Database information: package list and platform list
///
- private static String workspaceDir = "";
+ private static Set packageList = new HashSet();
- ///
- /// Two columns: Package Name (Key), Package Path(ralative to WORKSPACE)
- ///
- private static final Map packageInfo = new HashMap();
+ private static Set platformList = new HashSet();
///
- /// spdTable
- /// Key: Package Name, Value: SPD detail info
+ /// Every detail SPD informations: Module list, Library class definition,
+ /// Package header file, GUID/PPI/Protocol definitions
///
- private static final Map spdTable = new HashMap();
+ private static final Map spdTable = new HashMap();
///
- /// Three columns:
- /// 1. Module Name | BaseName (Key)
- /// 2. Module Path + Msa file name (relative to Package)
- /// 3. Package Name (This module belong to which package)
+ /// Build informations are divided into three parts:
+ /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
///
- private static final Map moduleInfo = new HashMap();
+ private static Map> nativeMsa = new HashMap>();
- ///
- /// List all libraries for current build module
- /// Key: Library BaseName, Value: output library path+name
- ///
- private static final Map libraries = new HashMap();
+ private static Map> fpdModuleSA= new HashMap>();
- ///
- /// Store every module's relative library instances BaseName
- /// Key: Module BaseName, Value: All library instances module depends on.
- ///
- private static final Map > moduleLibraryMap = new HashMap >();
+ private static XmlObject fpdBuildOptions;
- ///
- /// Key: Module BaseName, Value: original MSA info
- ///
- private static final Map > nativeMsa = new HashMap >();
+ private static XmlObject fpdDynamicPcds;
///
- /// Key: Module BaseName, Value: original MBD info
+ /// Parsed modules list
///
- private static final Map > nativeMbd = new HashMap >();
+ private static Map> parsedModules = new HashMap>();
///
- /// Two columns: Module Name or Base Name as Key
- /// Value is a HashMap with overridden data from MSA/MBD or/and Platform
+ /// built modules list with ARCH, TARGET, TOOLCHAIN
///
- private static final Map > parsedModules = new HashMap >();
+ private static Set builtModules = new HashSet();
///
- /// List all built Module; Value is Module BaseName + Arch. TBD
+ /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
///
- private static final Set builtModules = new HashSet();
+ private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
///
- /// Library instance information table which recored the library and it's
- /// constructor and distructor function
+ /// build target + tool chain family/tag name + arch + command types + command options
///
- private static final Map libInstanceInfo = new HashMap();
-
///
- /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
+ /// Tool Chain Data
+ /// toolsDef - build tool program information
+ /// fpdBuildOption - all modules's build options for tool tag or tool chain families
+ /// moduleSaBuildOption - build options for a specific module
///
- private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
+ private static ToolChainConfig toolsDef;
- /**
- Query the module's absolute path with module base name.
-
- @param moduleName the base name of the module
- @return the absolute module path
- **/
- public synchronized static String getModulePath(String moduleName) {
- String[] info = moduleInfo.get(moduleName);
- String packagePath = (String) packageInfo.get(info[1]);
- File convertFile = new File(workspaceDir + File.separatorChar + packagePath + File.separatorChar + info[0]);
- return convertFile.getParent();
- }
+ private static ToolChainInfo toolChainInfo;
+ private static ToolChainInfo toolChainEnvInfo;
+ private static ToolChainInfo toolChainPlatformInfo;
- /**
- Query the module's absolute MSA file path with module base name.
-
- @param moduleName the base name of the module
- @return the absolute MSA file name
- @throws BuildException
- Base name is not registered in any SPD files
- **/
- private synchronized static String getMsaFilename(String moduleName) throws BuildException {
- String[] info = moduleInfo.get(moduleName);
- if (info == null) {
- throw new BuildException("Module base name [" + moduleName + "] can't found in all SPD.");
- }
- String packagePath = (String) packageInfo.get(info[1]);
- File convertFile = new File(workspaceDir + File.separatorChar + packagePath + File.separatorChar + info[0]);
- return convertFile.getPath();
- }
-
- /**
- Query the module's absolute MBD file path with module base name.
-
- @param moduleName the base name of the module
- @return the absolute MBD file name
- @throws BuildException
- Base name is not registered in any SPD files
- **/
- private synchronized static String getMbdFilename(String moduleName) throws BuildException {
- String[] info = moduleInfo.get(moduleName);
- if (info == null) {
- throw new BuildException("Info: Module base name [" + moduleName + "] can't found in all SPD.");
- }
- String packagePath = (String) packageInfo.get(info[1]);
- File convertFile = new File(workspaceDir + File.separatorChar + packagePath + File.separatorChar + info[0]);
- return convertFile.getPath().substring(0, convertFile.getPath().length() - 4) + ".mbd";
- }
-
- /**
- Get the current WORKSPACE Directory.
- @return current workspace directory
- **/
- public synchronized static String getWorkspacePath() {
- return workspaceDir;
- }
-
- /**
- Query package relative path to WORKSPACE_DIR with package name.
-
- @param packageName the name of the package
- @return the path relative to WORKSPACE_DIR
- **/
- public synchronized static String getPackagePath(String packageName) {
- return (String) packageInfo.get(packageName);
- }
-
- /**
- Query package (which the module belongs to) relative path to WORSPACE_DIR.
-
- @param moduleName the base name of the module
- @return the relative path to WORKSPACE_DIR of the package which the module belongs to
- **/
- public synchronized static String getPackagePathForModule(String moduleName) {
- String[] info = moduleInfo.get(moduleName);
- String packagePath = (String) packageInfo.get(info[1]);
- return packagePath;
- }
+ private static ToolChainMap platformToolChainOption;
+ private static ToolChainMap platformToolChainFamilyOption;
- /**
- Query the package name which the module belongs to with the module's base name.
-
- @param moduleName the base name of the module
- @return the package name which the module belongs to
- **/
- public synchronized static String getPackageNameForModule(String moduleName) {
- return moduleInfo.get(moduleName)[1];
- }
+ private static Map moduleToolChainOption = new HashMap();
+ private static Map moduleToolChainFamilyOption = new HashMap();
/**
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
- in the whole build process.
-
+ in the whole build process.
+
@param workspaceDatabaseFile the file name of framework database
@param workspaceDir current workspace directory path
@throws BuildException
- Framework Dababase or SPD or MSA file is not valid
+ Framework Dababase or SPD or MSA file is not valid
**/
- public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir) throws BuildException {
+ public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException {
+ //
+ // ensure this method will be revoked only once
+ //
if (globalFlag) {
return;
}
globalFlag = true;
- GlobalData.workspaceDir = workspaceDir;
- File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
- try {
- FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);
- List packages = db.getFrameworkDatabase().getPackageList()
- .getPackageList();
- Iterator iter = packages.iterator();
- while (iter.hasNext()) {
- PackageListDocument.PackageList.Package packageItem = (PackageListDocument.PackageList.Package) iter
- .next();
- String name = packageItem.getPackageNameArray(0).getStringValue();
- String path = packageItem.getPathArray(0).getStringValue();
- packageInfo.put(name, path);
- File spdFile = new File(workspaceDir + File.separatorChar + path + File.separatorChar + name + ".spd");
- initPackageInfo(spdFile.getPath(), name);
- //
- // SPD Parse.
- //
- PackageSurfaceAreaDocument spdDoc = (PackageSurfaceAreaDocument) XmlObject.Factory.parse(spdFile);
- Spd spd = new Spd(spdDoc, path);
- spdTable.put(name, spd);
- }
+ //
+ // Backup workspace directory. It will be used by other method
+ //
+ GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");
+
+ //
+ // Parse tools definition file
+ //
+ //
+ // If ToolChain has been set up before, do nothing.
+ // CONF dir + tools definition file name
+ //
+ File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
+ System.out.println("Using tool definiton file [" + toolsDefFile.getPath() + "].");
+ try {
+ toolsDef = new ToolChainConfig(toolsDefFile);
} catch (Exception e) {
- throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());
+ throw new BuildException(e.getMessage());
}
- }
- /**
- Parse every MSA files, get base name from MSA Header. And record those
- values to ModuleInfo.
-
- @param packageFilename the file name of the package
- @param packageName the name of the package
- @throws BuildException
- SPD or MSA file is not valid
- **/
- private synchronized static void initPackageInfo(String packageFilename, String packageName) throws BuildException {
- File packageFile = new File(packageFilename);
+ //
+ // Parse Framework Database
+ //
+ File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
try {
- PackageSurfaceAreaDocument spd = (PackageSurfaceAreaDocument) XmlObject.Factory.parse(packageFile);
- List msaFilenameList;
-
- List msasList = spd.getPackageSurfaceArea().getMsaFiles()
- .getMsaFileList();
- if (msasList.size() == 0) {
- msaFilenameList = spd.getPackageSurfaceArea().getMsaFiles().getFilenameList();
- } else {
- msaFilenameList = new ArrayList(msasList.size());
- Iterator msasIter = msasList.iterator();
- while (msasIter.hasNext()) {
- MsaFilesDocument.MsaFiles.MsaFile msaFile = (MsaFilesDocument.MsaFiles.MsaFile)msasIter.next();
- msaFilenameList.add(msaFile.getFilename());
+ FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);
+ //
+ // validate FrameworkDatabaseFile
+ //
+ if (!db.validate()) {
+ throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");
+ }
+ //
+ // Get package list
+ //
+ if (db.getFrameworkDatabase().getPackageList() != null ) {
+ List packages = db.getFrameworkDatabase().getPackageList().getFilenameList();
+ Iterator iter = packages.iterator();
+ while (iter.hasNext()) {
+ String fileName = iter.next().getStringValue();
+ Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));
+ packageList.add(spd.getPackageId());
+ spdTable.put(spd.getPackageId(), spd);
}
}
- Iterator msaFilenameIter = msaFilenameList.iterator();
- while (msaFilenameIter.hasNext()) {
- FilenameDocument.Filename msaFilename = (FilenameDocument.Filename)msaFilenameIter.next();
- String filename = msaFilename.getStringValue();
- File msaFile = new File(workspaceDir + File.separatorChar + GlobalData.getPackagePath(packageName)
- + File.separatorChar + filename);
- SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();
- Map map = surfaceAreaParser.parseFile(msaFile);
- String baseName = "";
- XmlObject header = null;
- if ((header = map.get("MsaHeader")) != null) {
- if (((MsaHeader) header).isSetBaseName()) {
- baseName = ((MsaHeader) header).getBaseName().getStringValue();
- } else {
- baseName = ((MsaHeader) header).getModuleName();
+ //
+ // Get platform list
+ //
+ if (db.getFrameworkDatabase().getPlatformList() != null) {
+ List platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();
+ Iterator iter = platforms.iterator();
+ while (iter.hasNext()) {
+ String fileName = iter.next().getStringValue();
+ File fpdFile = new File(workspaceDir + File.separatorChar + fileName);
+ if ( !fpdFile.exists() ) {
+ throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");
+ }
+ XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);
+ //
+ // Verify FPD file, if is invalid, throw Exception
+ //
+ if (!fpdDoc.validate()) {
+ throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");
}
- } else if ((header = map.get("MsaLibHeader")) != null) {
- baseName = ((MsaLibHeader) header).getBaseName().getStringValue();
- } else {
- continue;
+ //
+ // We can change Map to XmlObject
+ //
+ //
+ // TBD check SPD or FPD is existed in FS
+ //
+ Map fpdDocMap = new HashMap();
+ fpdDocMap.put("PlatformSurfaceArea", fpdDoc);
+ SurfaceAreaQuery.setDoc(fpdDocMap);
+ PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader();
+ platformId.setFpdFile(fpdFile);
+ platformList.add(platformId);
}
- nativeMsa.put(baseName, map);
- String[] info = { filename, packageName };
- moduleInfo.put(baseName, info);
}
} catch (Exception e) {
- throw new BuildException("Parse package description file [" + packageFile.getPath() + "] Error.\n"
- + e.getMessage());
+ throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage());
}
}
/**
- Query the libraries which the module depends on.
-
- @param moduleName the base name of the module
- @return the libraries which the module depends on
+ Get the current WORKSPACE Directory.
+
+ @return current workspace directory
**/
- public synchronized static String[] getModuleLibrary(String moduleName, String arch) {
- Set set = moduleLibraryMap.get(moduleName + "-" + arch);
- return set.toArray(new String[set.size()]);
+ public synchronized static String getWorkspacePath() {
+ return workspaceDir;
}
+
/**
- Register module's library list which it depends on for later use.
-
- @param moduleName the base name of the module
- @param libraryList the libraries which the module depends on
- **/
- public synchronized static void addModuleLibrary(String moduleName, String arch, Set libraryList) {
- moduleLibraryMap.put(moduleName + "-" + arch, libraryList);
+ Get the MSA file name with absolute path
+ */
+ public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {
+ File msaFile = null;
+ //
+ // TBD. Do only when package is null.
+ //
+ Iterator iter = packageList.iterator();
+ while (iter.hasNext()) {
+ PackageIdentification packageId = (PackageIdentification)iter.next();
+ Spd spd = spdTable.get(packageId);
+ msaFile = spd.getModuleFile(moduleId);
+ if (msaFile != null ) {
+ break ;
+ }
+ }
+ if (msaFile == null){
+ throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");
+ } else {
+ return msaFile;
+ }
}
- /**
- Query the library absolute file name with library name.
-
- @param library the base name of the library
- @return the library absolute file name
- **/
- public synchronized static String getLibrary(String library, String arch) {
- return libraries.get(library + "-" + arch);
+ public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) {
+ //
+ // If package already defined in module
+ //
+ if (moduleId.getPackage() != null) {
+ return moduleId.getPackage();
+ }
+
+ PackageIdentification packageId = null;
+ Iterator iter = packageList.iterator();
+ while (iter.hasNext()) {
+ packageId = (PackageIdentification)iter.next();
+ moduleId.setPackage(packageId);
+ Spd spd = spdTable.get(packageId);
+ if (spd.getModuleFile(moduleId) != null ) {
+ break ;
+ }
+ }
+ if (packageId == null){
+ throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");
+ } else {
+ return packageId;
+ }
}
/**
- Register library absolute file name for later use.
-
- @param library the base name of the library
- @param resultPath the library absolute file name
+ Difference between build and parse: ToolChain and Target
**/
- public synchronized static void addLibrary(String library, String arch, String resultPath) {
- libraries.put(library + "-" + arch, resultPath);
+ public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {
+ return builtModules.contains(moduleId);
}
- /**
- Whether the module with ARCH has built in the previous build.
-
- @param moduleName the base name of the module
- @param arch current build ARCH
- @return true if the module has built in previous, otherwise return false
- **/
- public synchronized static boolean isModuleBuilt(String moduleName, String arch) {
- return builtModules.contains(moduleName + "-" + arch);
+ public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {
+ builtModules.add(fpdModuleId);
}
- /**
- Register the module with ARCH has built.
-
- @param moduleName the base name of the module
- @param arch current build ARCH
- **/
- public synchronized static void registerBuiltModule(String moduleName, String arch) {
- builtModules.add(moduleName + "-" + arch);
+
+ public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) {
+ Map result = new HashMap();
+ Set keySet = doc.keySet();
+ Iterator iter = keySet.iterator();
+ while (iter.hasNext()){
+ String key = (String)iter.next();
+ XmlObject item = cloneXmlObject(doc.get(key), true);
+ result.put(key, item);
+ }
+ fpdModuleSA.put(fpdModuleId, result);
}
- /**
- Whether the module's surface area has parsed in the previous build.
-
- @param moduleName the base name of the module
- @return true if the module's surface area has parsed in previous, otherwise
- return false
- **/
- public synchronized static boolean isModuleParsed(String moduleName) {
- return parsedModules.containsKey(moduleName);
+ public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {
+ return fpdModuleSA.containsKey(fpdModuleId);
}
/**
- Query overrided module surface area information. If current is Package
- or Platform build, also include the information from FPD file.
-
- Note that surface area parsing is incremental. That means the method will
- only to parse the MSA and MBD files when never parsed before.
+ Query module surface area information.
+
+ Note that surface area parsing is incremental. That means the method will
+ only parse the MSA files if necessary.
- @param moduleName the base name of the module
- @return the overrided module surface area information
- @throws BuildException
- MSA or MBD is not valid
+ @param fpdModuleId Module ID with arch
+ @return ModuleSA info and MSA info for fpdModuleId
+ @throws BuildException Can't find MSA
**/
- public synchronized static Map getDoc(String moduleName) throws BuildException {
- if (parsedModules.containsKey(moduleName)) {
- return parsedModules.get(moduleName);
- }
- Map msaMap = getNativeMsa(moduleName);
- Map mbdMap = getNativeMbd(moduleName);
- OverrideProcess op = new OverrideProcess();
- Map map = op.override(mbdMap, msaMap);
+ public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {
+ if (parsedModules.containsKey(fpdModuleId)) {
+ return parsedModules.get(fpdModuleId);
+ }
+ Map doc = new HashMap();
+ ModuleIdentification moduleId = fpdModuleId.getModule();
//
- // IF IT IS A PALTFORM BUILD, OVERRIDE FROM PLATFORM
+ // First part: get the MSA files info
//
- if (FpdParserTask.platformBuildOptions != null) {
- Map platformMap = new HashMap();
- platformMap.put("BuildOptions", FpdParserTask.platformBuildOptions);
- Map overrideMap = op.override(platformMap, OverrideProcess.deal(map));
- GlobalData.registerModule(moduleName, overrideMap);
- return overrideMap;
- } else {
- parsedModules.put(moduleName, map);
- return map;
+ doc.putAll(getNativeMsa(moduleId));
+
+ //
+ // Second part: put build options
+ //
+ doc.put("BuildOptions", fpdBuildOptions);
+
+ //
+ // Third part: get Module info from FPD, such as Library instances, PCDs
+ //
+ if (fpdModuleSA.containsKey(fpdModuleId)){
+ //
+ // merge module info in FPD to final Doc
+ // For Library Module, do nothing here
+ //
+ doc.putAll(fpdModuleSA.get(fpdModuleId));
}
+ parsedModules.put(fpdModuleId, doc);
+ return doc;
}
+ public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws BuildException {
+ FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
+ return getDoc(fpdModuleId);
+ }
/**
- Query the native MSA information with module base name.
-
- Note that MSA parsing is incremental. That means the method will
+ Query the native MSA information with module base name.
+
+
Note that MSA parsing is incremental. That means the method will
only to parse the MSA files when never parsed before.
-
+
@param moduleName the base name of the module
@return the native MSA information
@throws BuildException
MSA file is not valid
**/
- public synchronized static Map getNativeMsa(String moduleName) throws BuildException {
- if (nativeMsa.containsKey(moduleName)) {
- return nativeMsa.get(moduleName);
+ public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws BuildException {
+ if (nativeMsa.containsKey(moduleId)) {
+ return nativeMsa.get(moduleId);
}
- String msaFilename = getMsaFilename(moduleName);
- File msaFile = new File(msaFilename);
+ File msaFile = getMsaFile(moduleId);
+ Map msaMap = getNativeMsa(msaFile);
+ nativeMsa.put(moduleId, msaMap);
+ return msaMap;
+ }
+
+ public synchronized static Map getNativeMsa(File msaFile) throws BuildException {
if (!msaFile.exists()) {
- throw new BuildException("Info: Surface Area file [" + msaFile.getPath() + "] can't found.");
+ throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");
}
- SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();
- Map map = surfaceAreaParser.parseFile(msaFile);
- nativeMsa.put(moduleName, map);
- return map;
- }
-
- /**
- Query the native MBD information with module base name.
-
- Note that MBD parsing is incremental. That means the method will
- only to parse the MBD files when never parsed before.
-
- @param moduleName the base name of the module
- @return the native MBD information
- @throws BuildException
- MBD file is not valid
- **/
- public synchronized static Map getNativeMbd(String moduleName) throws BuildException {
- if (nativeMbd.containsKey(moduleName)) {
- return nativeMbd.get(moduleName);
+ try {
+ ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
+ //
+ // Validate File if they accord with XML Schema
+ //
+ if ( !doc.validate()){
+ throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");
+ }
+ //
+ // parse MSA file
+ //
+ ModuleSurfaceArea msa= doc.getModuleSurfaceArea();
+ Map msaMap = new HashMap();
+ msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));
+ msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));
+ msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));
+ msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));
+ msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));
+ msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));
+ msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));
+ msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));
+ msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));
+ msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));
+ return msaMap;
}
- String mbdFilename = getMbdFilename(moduleName);
- File mbdFile = new File(mbdFilename);
- if (!mbdFile.exists()) {
- return null;
- //throw new BuildException("Info: Surface Area file [" + mbdFile.getPath() + "] can't found.");
+ catch (Exception ex){
+ throw new BuildException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage() );
}
- SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();
- Map map = surfaceAreaParser.parseFile(mbdFile);
- nativeMbd.put(moduleName, map);
+ }
+
+ public static Map getFpdBuildOptions() {
+ Map map = new HashMap();
+ map.put("BuildOptions", fpdBuildOptions);
return map;
}
- /**
- Register module overrided surface area information. If has existed, then update.
-
- @param moduleName the base name of the module
- @param map the overrided surface area information
- **/
- public synchronized static void registerModule(String moduleName, Map map) {
- parsedModules.put(moduleName, map);
+ public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {
+ GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);
+ }
+
+ public static XmlObject getFpdDynamicPcds() {
+ return fpdDynamicPcds;
+ }
+
+ public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {
+ GlobalData.fpdDynamicPcds = fpdDynamicPcds;
+ }
+
+ public static Set getModules(PackageIdentification packageId){
+ Spd spd = spdTable.get(packageId);
+ if (spd == null ) {
+ Set dummy = new HashSet();
+ return dummy;
+ } else {
+ return spd.getModules();
+ }
}
/**
- *
- * @param protocolName
- * @return
+ * The header file path is relative to workspace dir
*/
- public synchronized static String[] getProtocolInfoGuid(String protocolName) {
- Set set = spdTable.keySet();
- Iterator iter = set.iterator();
- String[] cNameGuid = null;
+ public static String[] getLibraryClassHeaderFiles(
+ PackageIdentification[] packages, String name)
+ throws BuildException {
+ if (packages == null) {
+ // throw Exception or not????
+ return new String[0];
+ }
+ String[] result = null;
+ for (int i = 0; i < packages.length; i++) {
+ Spd spd = spdTable.get(packages[i]);
+ //
+ // If find one package defined the library class
+ //
+ if ((result = spd.getLibClassIncluder(name)) != null) {
+ return result;
+ }
+ }
+ //
+ // If can't find library class declaration in every package
+ //
+ throw new BuildException("Can not find library class [" + name
+ + "] declaration in any SPD package!");
+ }
- while (iter.hasNext()) {
- Spd spd = (Spd) spdTable.get(iter.next());
- cNameGuid = spd.getProtocolNameGuidArray(protocolName);
- if (cNameGuid != null) {
- break;
+ /**
+ * The header file path is relative to workspace dir
+ */
+ public static String getPackageHeaderFiles(PackageIdentification packages,
+ String moduleType) throws BuildException {
+ if (packages == null) {
+ return new String("");
+ }
+ Spd spd = spdTable.get(packages);
+ //
+ // If can't find package header file, skip it
+ //
+ String temp = null;
+ if (spd != null) {
+ if ((temp = spd.getPackageIncluder(moduleType)) != null) {
+ return temp;
+ } else {
+ temp = "";
+ return temp;
}
+ } else {
+ return null;
}
- return cNameGuid;
}
- public synchronized static String[] getPpiInfoGuid(String ppiName) {
- Set set = spdTable.keySet();
- Iterator iter = set.iterator();
- String[] cNameGuid = null;
+ /**
+ * return two values: {cName, GuidValue}
+ */
+ public static String[] getGuid(List packages, String name)
+ throws BuildException {
+ if (packages == null) {
+ // throw Exception or not????
+ return new String[0];
+ }
+ String[] result = null;
+ Iterator item = packages.iterator();
+ while (item.hasNext()){
+ Spd spd = spdTable.get(item.next());
+ //
+ // If find one package defined the GUID
+ //
+ if ((result = spd.getGuid(name)) != null) {
+ return result;
+ }
+ }
- while (iter.hasNext()) {
- Spd spd = (Spd) spdTable.get(iter.next());
- cNameGuid = spd.getPpiCnameGuidArray(ppiName);
+ return null;
+ }
- if (cNameGuid != null) {
- break;
+ /**
+ * return two values: {cName, GuidValue}
+ */
+ public static String[] getPpiGuid(List packages,
+ String name) throws BuildException {
+ if (packages == null) {
+ return new String[0];
+ }
+ String[] result = null;
+ Iterator item = packages.iterator();
+ while (item.hasNext()){
+ Spd spd = spdTable.get(item.next());
+ //
+ // If find one package defined the Ppi GUID
+ //
+ if ((result = spd.getPpi(name)) != null) {
+ return result;
}
}
- return cNameGuid;
+ return null;
}
/**
- *
- * @param guidName
- * @return
+ * return two values: {cName, GuidValue}
*/
- public synchronized static String[] getGuidInfoGuid(String guidName) {
- String[] cNameGuid = null;
- Set set = spdTable.keySet();
- Iterator iter = set.iterator();
+ public static String[] getProtocolGuid(List packages,
+ String name) throws BuildException {
+ if (packages == null) {
+ return new String[0];
+ }
+ String[] result = null;
+ Iterator item = packages.iterator();
+ while (item.hasNext()){
+ Spd spd = spdTable.get(item.next());
+ //
+ // If find one package defined the protocol GUID
+ //
+ if ((result = spd.getProtocol(name))!= null){
+ return result;
+ }
+ }
+ return null;
- while (iter.hasNext()) {
- Spd spd = (Spd) spdTable.get(iter.next());
- cNameGuid = spd.getGuidNameArray(guidName);
- if (cNameGuid != null) {
- break;
+ }
+
+ public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {
+ Iterator iter = platformList.iterator();
+ while(iter.hasNext()){
+ PlatformIdentification platformId = (PlatformIdentification)iter.next();
+ if (platformId.getName().equalsIgnoreCase(name)) {
+ return platformId;
}
}
- return cNameGuid;
+ throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!");
}
- public synchronized static String getLibClassIncluder(String libName) {
- String libIncluder = null;
- Set set = spdTable.keySet();
- Iterator iter = set.iterator();
+ public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {
+ File file = new File(workspaceDir + File.separatorChar + filename);
+ Iterator iter = platformList.iterator();
+ while(iter.hasNext()){
+ PlatformIdentification platformId = (PlatformIdentification)iter.next();
+ if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {
+ return platformId;
+ }
+ }
+ throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");
+ }
- while (iter.hasNext()) {
- String packageName = (String) iter.next();
- Spd spd = (Spd) spdTable.get(packageName);
- libIncluder = spd.getLibClassIncluder(libName);
- String packagePath = spd.packagePath;
- if (packagePath != null) {
- packagePath = packagePath.replace('\\', File.separatorChar);
- packagePath = packagePath.replace('/', File.separatorChar);
- } else {
- packagePath = packageName;
+ public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {
+ Iterator iter = packageList.iterator();
+ while(iter.hasNext()){
+ PackageIdentification packageItem = (PackageIdentification)iter.next();
+ if (packageItem.equals(packageId)) {
+ packageId.setName(packageItem.getName());
+ packageId.setSpdFile(packageItem.getSpdFile());
+ return packageId;
}
- if (libIncluder != null) {
- libIncluder = libIncluder.replace('\\', File.separatorChar);
- libIncluder = libIncluder.replace('/', File.separatorChar);
- libIncluder = packageName + File.separatorChar + libIncluder;
- break;
+ }
+ throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");
+ }
+
+ public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {
+ PackageIdentification packageId = getPackageForModule(moduleId);
+ moduleId.setPackage(packageId);
+ Spd spd = spdTable.get(packageId);
+ if (spd == null) {
+ throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");
+ }
+ Set modules = spd.getModules();
+ Iterator iter = modules.iterator();
+ while (iter.hasNext()) {
+ ModuleIdentification item = iter.next();
+ if (item.equals(moduleId)) {
+ moduleId.setName(item.getName());
+ moduleId.setModuleType(item.getModuleType());
+ moduleId.setMsaFile(item.getMsaFile());
+ return moduleId;
}
}
- return libIncluder;
+ throw new BuildException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");
}
- public synchronized static String getModuleInfoByPackageName(String packageName, String moduleType) {
- Spd spd;
- String includeFile = null;
- String includeStr = "";
- String cleanPath = "";
+ public synchronized static Set getPackageList(){
+ return packageList;
+ }
- spd = (Spd) spdTable.get(packageName);
- includeFile = spd.getModuleTypeIncluder(moduleType);
- if (includeFile != null) {
- includeFile = includeFile.replace('\\', File.separatorChar);
- includeFile = includeFile.replace('/', File.separatorChar);
- includeStr = CommonDefinition.include + " <" + includeStr;
- cleanPath = spd.packagePath;
- cleanPath = cleanPath.replace('\\', File.separatorChar);
- cleanPath = cleanPath.replace('/', File.separatorChar);
+ /**
+ BUGBUG: It is a walk around method. If do not clone, can't query info with
+ XPath correctly.
+
+ @param object XmlObject
+ @param deep flag for deep clone
+ @return XmlObject after clone
+ @throws BuildException parse original XmlObject error.
+ **/
+ private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {
+ if ( object == null) {
+ return null;
+ }
+ XmlObject result = null;
+ try {
+ result = XmlObject.Factory.parse(object.getDomNode()
+ .cloneNode(deep));
+ } catch (Exception ex) {
+ throw new BuildException(ex.getMessage());
+ }
+ return result;
+ }
- if (cleanPath.charAt(spd.packagePath.length() - 1) != File.separatorChar) {
- cleanPath = cleanPath + File.separatorChar;
+ ///
+ /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
+ ///
+ public static ToolChainInfo getToolChainInfo() {
+ if (toolChainInfo == null) {
+ toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);
+ if (toolChainPlatformInfo != null) {
+ toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);
}
- includeStr = includeStr + cleanPath;
- includeStr = includeStr + includeFile;
- includeStr = includeStr + ">\r\n";
+ toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
+ toolChainInfo.normalize();
+ System.out.println("Current build tool chain information summary: ");
+ System.out.println(toolChainInfo + "");
}
+ return toolChainInfo;
+ }
- return includeStr;
+ public static void setPlatformToolChainFamilyOption(ToolChainMap map) {
+ platformToolChainFamilyOption = map;
}
- public synchronized static void setLibInstanceInfo(String libName, String libConstructor, String libDesturctor) {
- String[] libConsDes = new String[2];
- libConsDes[0] = libConstructor;
- libConsDes[1] = libDesturctor;
+ public static void setPlatformToolChainOption(ToolChainMap map) {
+ platformToolChainOption = map;
+ }
- libInstanceInfo.put(libName, libConsDes);
+ public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,
+ ToolChainMap toolChainOption) {
+ moduleToolChainOption.put(fpdModuleId, toolChainOption);
}
- public synchronized static boolean isHaveLibInstance(String libName) {
- return libInstanceInfo.containsKey(libName);
+ public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,
+ ToolChainMap toolChainOption) {
+ moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);
}
- public synchronized static String getLibInstanceConstructor(String libName) {
- String[] libInstanceValue;
- libInstanceValue = libInstanceInfo.get(libName);
- if (libInstanceValue != null) {
- return libInstanceValue[0];
- } else {
- return null;
+ public static boolean isCommandSet(String target, String toolchain, String arch) {
+ String[] commands = getToolChainInfo().getCommands();
+
+ for (int i = 0; i < commands.length; ++i) {
+ String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});
+ if (cmdName != null && cmdName.length() != 0) {
+ return true;
+ }
}
+
+ return false;
}
- public synchronized static String getLibInstanceDestructor(String libName) {
- String[] libInstanceValue;
- libInstanceValue = libInstanceInfo.get(libName);
- if (libInstanceValue != null) {
- return libInstanceValue[1];
- } else {
- return null;
+ public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {
+ ToolChainKey toolChainKey = new ToolChainKey(commandDescription);
+ ToolChainMap toolChainConfig = toolsDef.getConfig();
+ String setting = null;
+
+ if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {
+ setting = toolChainConfig.get(toolChainKey);
+ if (setting == null) {
+ setting = "";
+ }
+ return setting;
+ }
+
+ //
+ // get module specific options, if any
+ //
+ // tool tag first
+ ToolChainMap option = moduleToolChainOption.get(fpdModuleId);
+ ToolChainKey toolChainFamilyKey = null;
+
+ if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {
+ //
+ // then tool chain family
+ //
+ toolChainFamilyKey = new ToolChainKey(commandDescription);
+ toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
+ String family = toolChainConfig.get(toolChainFamilyKey);
+ toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
+ toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
+
+ option = moduleToolChainFamilyOption.get(fpdModuleId);
+ if (option != null) {
+ setting = option.get(toolChainFamilyKey);
+ }
+ }
+
+ //
+ // get platform options, if any
+ //
+ if (setting == null) {
+ // tool tag first
+ if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {
+ // then tool chain family
+ if (toolChainFamilyKey == null) {
+ toolChainFamilyKey = new ToolChainKey(commandDescription);
+ toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
+ String family = toolChainConfig.get(toolChainFamilyKey);
+ toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
+ toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
+ }
+
+ setting = platformToolChainFamilyOption.get(toolChainFamilyKey);
+ }
+ }
+
+ if (setting == null) {
+ setting = "";
}
+
+ return setting;
}
+ public static void setToolChainEnvInfo(ToolChainInfo envInfo) {
+ toolChainEnvInfo = envInfo;
+ }
+ public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {
+ toolChainPlatformInfo = platformInfo;
+ }
+
+ //
+ // for PCD
+ //
public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
return pcdDbManager;
}
+
+ //
+ // For PCD get tokenSpaceGUid
+ //
+ public synchronized static String getGuidInfoFromCname(String cName){
+ String cNameGuid = null;
+ String guid = null;
+ Set set = spdTable.keySet();
+ Iterator iter = set.iterator();
+
+ if (iter == null) {
+ return null;
+ }
+
+ while (iter.hasNext()){
+ Spd spd = (Spd) spdTable.get(iter.next());
+ guid = spd.getGuidFromCname(cName);
+ if (guid != null){
+ cNameGuid = guid;
+ break;
+ }
+ }
+ return cNameGuid;
+ }
+
+ //
+ // For PCD
+ //
+ public synchronized static Map
+ getFpdModuleSaXmlObject(String xmlObjectName) {
+ Set fpdModuleSASet = fpdModuleSA.keySet();
+ Iterator item = fpdModuleSASet.iterator();
+
+
+ Map SAPcdBuildDef = new HashMap();
+ Map SANode = new HashMap();
+ FpdModuleIdentification moduleId;
+ while (item.hasNext()) {
+
+ moduleId = (FpdModuleIdentification) item.next();
+ SANode = fpdModuleSA.get(moduleId);
+ try{
+ if (SANode.get(xmlObjectName)!= null){
+ SAPcdBuildDef.put(moduleId,
+ (XmlObject) SANode.get(xmlObjectName));
+
+ }
+ } catch (Exception e){
+ EdkLog.log(EdkLog.EDK_INFO, e.getMessage());
+ }
+ }
+ return SAPcdBuildDef;
+ }
+
+ public synchronized static Map getFpdPcdBuildDefinitions() {
+ Map pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");
+
+ return pcdBuildDef;
+ }
}
+