]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Change to new XML Schema.
authorwuyizhong <wuyizhong@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Jun 2006 18:17:09 +0000 (18:17 +0000)
committerwuyizhong <wuyizhong@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Jun 2006 18:17:09 +0000 (18:17 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@687 6f19259b-4bc3-4df7-8a09-765794883524

43 files changed:
Tools/Source/GenBuild/org/tianocore/build/ExpandTask.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/FfsProcess.java
Tools/Source/GenBuild/org/tianocore/build/FileProcess.java
Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/OutputDirSetup.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/OutputDirSetupTask.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java
Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
Tools/Source/GenBuild/org/tianocore/build/exception/AutoGenException.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/exception/EdkException.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/fpd/FpdModuleIdentification.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Tools/Source/GenBuild/org/tianocore/build/global/GlobalShare.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/global/LibBuildFileGenerator.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/global/ModuleIdentification.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/global/OutputManager.java
Tools/Source/GenBuild/org/tianocore/build/global/OverrideProcess.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaParser.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
Tools/Source/GenBuild/org/tianocore/build/id/FpdModuleIdentification.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/id/Identification.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/id/PlatformIdentification.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainAttribute.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainElement.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainFactory.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainKey.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainTask.java

diff --git a/Tools/Source/GenBuild/org/tianocore/build/ExpandTask.java b/Tools/Source/GenBuild/org/tianocore/build/ExpandTask.java
deleted file mode 100644 (file)
index c4c53e0..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/** @file\r
-  This file is ANT task Expand. \r
-  \r
-  Expand task is used to prepare ANT properties for further build. \r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-package org.tianocore.build;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Task;\r
-\r
-import org.tianocore.build.global.GlobalData;\r
-\r
-/**\r
-  Expand task is used to prepare ANT properties for further build. \r
-  <p>Current, prepare the dependent Library instance list for <code>LIBS</code></p>\r
\r
-  @since GenBuild 1.0\r
-**/\r
-public class ExpandTask extends Task {\r
-    \r
-    /**\r
-      Public construct method. It is necessary for ANT task.\r
-    **/\r
-    public ExpandTask () {\r
-    }\r
-    \r
-    /**\r
-      ANT task's entry point, will be called after init().\r
-      \r
-      Set <code>LIBS</code> for further build usage. \r
-    **/\r
-    public void execute() throws BuildException {\r
-        String basename = getProject().getProperty("BASE_NAME");\r
-        String arch = getProject().getProperty("ARCH");\r
-        arch = arch.toUpperCase();\r
-        String[] libraries = GlobalData.getModuleLibrary(basename, arch);\r
-        String str = "";\r
-        for (int i = 0; i < libraries.length; i ++){\r
-            str += " " + GlobalData.getLibrary(libraries[i], arch);\r
-        }\r
-        getProject().setProperty("LIBS", str);\r
-       \r
-    }\r
-}\r
index 267a50e4e36bd9c1c2490ecafe8d115790f0d116..02eca2abef22f0b333ac1ca6e8c21cce88334d5a 100644 (file)
@@ -26,6 +26,10 @@ import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;\r
 import org.apache.xmlbeans.XmlCursor;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.tools.ant.Project;\r
 import org.apache.xmlbeans.XmlCursor;\r
 import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.BuildOptionsDocument;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
 import org.w3c.dom.NamedNodeMap;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
 import org.w3c.dom.NamedNodeMap;\r
@@ -60,6 +64,8 @@ public class FfsProcess {
     /// Xml Document Node for corresponding FFS layout\r
     ///\r
     private Node ffs;\r
     /// Xml Document Node for corresponding FFS layout\r
     ///\r
     private Node ffs;\r
+    \r
+    private BuildOptionsDocument.BuildOptions.Ffs ffsXmlObject;\r
 \r
     ///\r
     /// ANT script to call GenFfs\r
 \r
     ///\r
     /// ANT script to call GenFfs\r
@@ -131,11 +137,31 @@ public class FfsProcess {
       @throws BuildException\r
               If specified COMMON_FILE XML file is not valide.\r
     **/\r
       @throws BuildException\r
               If specified COMMON_FILE XML file is not valide.\r
     **/\r
-    public boolean initSections(String buildType, Project project) throws BuildException {\r
+    public boolean initSections(String buildType, Project project, FpdModuleIdentification fpdModuleId) throws BuildException {\r
         //\r
         //\r
-        // first try to sections defined in PLATFORM level\r
+        // Firstly, try to find in ModuleSA\r
         //\r
         //\r
-\r
+//        BuildOptionsDocument.BuildOptions.Ffs[] ffsArray = SurfaceAreaQuery.getModuleFfs();\r
+//        for (int i = 0; i < ffsArray.length; i++) {\r
+//            if (isMatch(ffsArray[i].getFfsKey(), buildType)) {\r
+//                ffsXmlObject = ffsArray[i];\r
+//                return true;\r
+//            }\r
+//        }\r
+        \r
+        //\r
+        // secondly, try to sections defined in PLATFORM level\r
+        //\r
+        SurfaceAreaQuery.push(GlobalData.getFpdBuildOptions());\r
+        BuildOptionsDocument.BuildOptions.Ffs[] ffsArray = SurfaceAreaQuery.getFpdFfs();\r
+        SurfaceAreaQuery.pop();\r
+        for (int i = 0; i < ffsArray.length; i++) {\r
+            if (isMatch(ffsArray[i].getFfsKey(), buildType)) {\r
+                ffsXmlObject = ffsArray[i];\r
+                return true;\r
+            }\r
+        }\r
+        \r
         //\r
         // if module specify sections itself, it's okay\r
         // otherwise find sections from WORKSPACE default setting with\r
         //\r
         // if module specify sections itself, it's okay\r
         // otherwise find sections from WORKSPACE default setting with\r
@@ -194,22 +220,30 @@ public class FfsProcess {
     **/\r
     public String[] getGenSectionElements(Document document, String basename, String guid, String targetFilename) {\r
         this.basename = basename;\r
     **/\r
     public String[] getGenSectionElements(Document document, String basename, String guid, String targetFilename) {\r
         this.basename = basename;\r
-        if (ffs == null) {\r
+        if (ffs == null && ffsXmlObject == null) {\r
             return new String[0];\r
         }\r
         Vector<String> sectionList = new Vector<String>();\r
         XmlCursor cursor = null;\r
         try {\r
             return new String[0];\r
         }\r
         Vector<String> sectionList = new Vector<String>();\r
         XmlCursor cursor = null;\r
         try {\r
-            cursor = XmlObject.Factory.parse(ffs).newCursor();\r
+            if (ffsXmlObject == null) {\r
+                cursor = XmlObject.Factory.parse(ffs).newCursor();\r
+            }\r
+            else {\r
+                cursor = ffsXmlObject.newCursor();\r
+            }\r
         } catch (Exception e) {\r
             return null;\r
         }\r
         int mode = MODE_NONE;\r
         Element root = document.createElement("genffsfile");\r
         root.setAttribute("outputDir", "${BIN_DIR}");\r
         } catch (Exception e) {\r
             return null;\r
         }\r
         int mode = MODE_NONE;\r
         Element root = document.createElement("genffsfile");\r
         root.setAttribute("outputDir", "${BIN_DIR}");\r
+        root.setAttribute("moduleType", "${MODULE_TYPE}");\r
         root.setAttribute("BaseName", basename);\r
         root.setAttribute("fileGuid", guid);\r
         root.setAttribute("BaseName", basename);\r
         root.setAttribute("fileGuid", guid);\r
-        cursor.toFirstChild();\r
+        if (ffsXmlObject == null) {\r
+            cursor.toFirstChild();\r
+        }\r
         if (cursor.toFirstChild()) {\r
             do {\r
                 if (cursor.getName().getLocalPart().equalsIgnoreCase("Attribute")) {\r
         if (cursor.toFirstChild()) {\r
             do {\r
                 if (cursor.getName().getLocalPart().equalsIgnoreCase("Attribute")) {\r
@@ -315,7 +349,7 @@ public class FfsProcess {
             // outputPath = "${DEST_DIR_OUTPUT}">\r
             //\r
             ele = doc.createElement("tool");\r
             // outputPath = "${DEST_DIR_OUTPUT}">\r
             //\r
             ele = doc.createElement("tool");\r
-            ele.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "bin"\r
+            ele.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "Bin"\r
                                          + File.separatorChar + "GenCRC32Section");\r
             ele.setAttribute("outputPath", "${DEST_DIR_OUTPUT}");\r
         }\r
                                          + File.separatorChar + "GenCRC32Section");\r
             ele.setAttribute("outputPath", "${DEST_DIR_OUTPUT}");\r
         }\r
@@ -365,7 +399,7 @@ public class FfsProcess {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-       Get the corresponding section file suffix.\r
+      Get the corresponding section file suffix.\r
        \r
       @param type Section type\r
       @return Corresponding section file extension\r
        \r
       @param type Section type\r
       @return Corresponding section file extension\r
index 87650af8278864c14d8150ccf3a8800d77a1767e..e615802c009c5beed8610fdab7a82e79db26f85b 100644 (file)
@@ -16,6 +16,7 @@ package org.tianocore.build;
 import java.io.File;\r
 import java.util.Set;\r
 \r
 import java.io.File;\r
 import java.util.Set;\r
 \r
+import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
 import org.apache.tools.ant.Project;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
@@ -29,17 +30,24 @@ import org.w3c.dom.Node;
   by its extension. Following is the current supported extensions. </p>\r
   \r
   <pre>   \r
   by its extension. Following is the current supported extensions. </p>\r
   \r
   <pre>   \r
-          .c         |      C_Code\r
-          .asm       |      Assembly\r
-          .s         |      IPF_Assembly_Code\r
-          .h         |      Header\r
-          .lib       |      Static_Library\r
-          .i         |      IPF_PP_Code\r
-          .vfr       |      Vfr\r
-          .uni       |      Unicode\r
-          .dxs       |      Dependency_File\r
-          .bmp       |      Graphics\r
-          .efi       |      EFI\r
+ Source File Suffix     File Type       Description\r
+    .h                   CHeader      C header file\r
+    .c                   CCode        C source file\r
+    .inc                 ASMHeader    Assembly header file\r
+    .asm                 ASM          Assembly source file, usually for IA32 and X64 Arch and MSFT tool chain\r
+    .S                   ASM          Assembly source file, usually for IPF Arch\r
+    .s                   ASM          Assembly source file, usually for IA32 and X64 Arch and GCC tool chain\r
+    .uni                 UNI          Unicode file\r
+    .vfr                 VFR          Visual Forms Representation File\r
+    .fv                  FV           Firmware Volume\r
+    .SEC                 FFS          Firmware File System file\r
+    .PEI                 FFS          Firmware File System file\r
+    .DXE                 FFS          Firmware File System file\r
+    .APP                 FFS          Firmware File System file\r
+    .FVI                 FFS          Firmware File System file\r
+    .FFS                 FFS          Firmware File System file\r
+    .bmp                 BMP          Graphic File\r
+    .i                   PPCode       IPF PreProcessor Code\r
   </pre>\r
   \r
   @since GenBuild 1.0\r
   </pre>\r
   \r
   @since GenBuild 1.0\r
@@ -48,13 +56,25 @@ public class FileProcess {
     ///\r
     ///  The mapping information about source suffix, result suffix, file type.\r
     ///\r
     ///\r
     ///  The mapping information about source suffix, result suffix, file type.\r
     ///\r
-    public final String[][] fileTypes = { { ".c", ".obj", "C_Code" }, { ".asm", ".obj", "Assembly" },\r
-                                         { ".s", ".obj", "IPF_Assembly_Code" }, { ".h", "", "Header" },\r
-                                         { ".lib", "", "Static_Library" }, { ".src", ".c", "" },\r
-                                         { ".i", ".obj", "IPF_PP_Code" }, { ".vfr", ".obj", "Vfr" },\r
-                                         { ".uni", "", "Unicode" }, { ".dxs", "", "Dependency_File" },\r
-                                         { ".bmp", "", "Graphics" }, { ".efi", "", "EFI" } };\r
-\r
+    public final String[][] fileTypes = { {".h", "", "CHeader" }, \r
+                                          {".c", "", "CCode" },\r
+                                          {".inc", "", "ASMHeader" },\r
+                                          {".asm", "", "ASM" }, \r
+                                          {".S", "", "ASM" },\r
+                                          {".s", "", "ASM" },\r
+                                          {".uni", "", "UNI" },\r
+                                          {".vfr", "", "VFR" },\r
+                                          {".dxs", "", "DPX"},\r
+                                          {".fv", "", "FV" },\r
+                                          {".efi", "", "EFI" },\r
+                                          {".SEC", "", "FFS" },\r
+                                          {".PEI", "", "FFS" },\r
+                                          {".DXE", "", "FFS" },\r
+                                          {".APP", "", "FFS" },\r
+                                          {".FYI", "", "FFS" },\r
+                                          {".FFS", "", "FFS" },\r
+                                          {".bmp", "", "BMP" },\r
+                                          {".i", "", "PPCode"}};\r
     ///\r
     /// Current ANT context. \r
     ///\r
     ///\r
     /// Current ANT context. \r
     ///\r
@@ -64,11 +84,6 @@ public class FileProcess {
     /// Current module's include pathes\r
     ///\r
     private Set<String> includes;\r
     /// Current module's include pathes\r
     ///\r
     private Set<String> includes;\r
-\r
-    ///\r
-    /// Current source files. \r
-    ///\r
-    private Set<String> sourceFiles;\r
     \r
     ///\r
     /// Xml Document.\r
     \r
     ///\r
     /// Xml Document.\r
@@ -93,11 +108,10 @@ public class FileProcess {
       @param sourceFiles Modules source files\r
       @param document XML document\r
     **/\r
       @param sourceFiles Modules source files\r
       @param document XML document\r
     **/\r
-    public void init(Project project, Set<String> includes, Set<String> sourceFiles, Document document) {\r
+    public void init(Project project, Set<String> includes, Document document) {\r
         this.document = document;\r
         this.includes = includes;\r
         this.project = project;\r
         this.document = document;\r
         this.includes = includes;\r
         this.project = project;\r
-        this.sourceFiles = sourceFiles;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
@@ -140,16 +154,16 @@ public class FileProcess {
       @param filename Source file name\r
       @param root Root node\r
     **/\r
       @param filename Source file name\r
       @param root Root node\r
     **/\r
-    public synchronized void parseFile(String filename, Node root) {\r
+    public synchronized void parseFile(String filename, Node root) throws BuildException {\r
         boolean flag = false;\r
         for (int i = 0; i < fileTypes.length; i++) {\r
         boolean flag = false;\r
         for (int i = 0; i < fileTypes.length; i++) {\r
-            if (filename.toLowerCase().endsWith(fileTypes[i][0])) {\r
+            if (filename.endsWith(fileTypes[i][0])) {\r
                 flag = true;\r
                 parseFile(filename, fileTypes[i][2], root);\r
             }\r
         }\r
         if (!flag) {\r
                 flag = true;\r
                 parseFile(filename, fileTypes[i][2], root);\r
             }\r
         }\r
         if (!flag) {\r
-            System.out.println("Warning: File " + filename + " is not known from its suffix.");\r
+            throw new BuildException("File [" + filename + "] is not known from its suffix.");\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -167,31 +181,58 @@ public class FileProcess {
     **/\r
     public synchronized void parseFile(String filename, String filetype, Node root) {\r
         if (unicodeFirst) {\r
     **/\r
     public synchronized void parseFile(String filename, String filetype, Node root) {\r
         if (unicodeFirst) {\r
-            if ( ! filetype.equalsIgnoreCase("Unicode")){\r
+            if ( ! filetype.equalsIgnoreCase("UNI")){\r
                 return ;\r
             }\r
             unicodeExist= true;\r
         } else {\r
                 return ;\r
             }\r
             unicodeExist= true;\r
         } else {\r
-            if (filetype.equalsIgnoreCase("Unicode")){\r
+            if (filetype.equalsIgnoreCase("UNI")){\r
                 return ;\r
             }\r
         }\r
                 return ;\r
             }\r
         }\r
-        sourceFiles.add(filename);\r
-        if (filetype.equalsIgnoreCase("Header")) {\r
+        \r
+        //\r
+        // If file is C or ASM header file, skip it\r
+        //\r
+        if (filetype.equalsIgnoreCase("CHeader") || filetype.equalsIgnoreCase("ASMHeader")) {\r
             return;\r
         }\r
             return;\r
         }\r
-        if (filetype.equalsIgnoreCase("IPF_PP_Code")) {\r
+        \r
+        //\r
+        // If file is pre-processor file, skip it\r
+        // \r
+        if (filetype.equalsIgnoreCase("PPCode")) {\r
             return;\r
         }\r
             return;\r
         }\r
+        \r
+        //\r
+        // If define CC_EXT in tools_def.txt file, the source file with \r
+        // different suffix is skipped\r
+        //\r
+        String toolsDefExtName = project.getProperty(filetype + "_EXT");\r
+        if (toolsDefExtName != null) {\r
+            String[] exts = toolsDefExtName.split(" ");\r
+            for (int i = 0; i < exts.length; i++) {\r
+                if ( ! filename.endsWith(exts[i])) {\r
+                    return ;\r
+                }\r
+            }\r
+        }\r
+        \r
         String module_path = project.getProperty("MODULE_DIR");\r
         File moduleFile = new File(module_path);\r
         File sourceFile = new File(filename);\r
         String module_path = project.getProperty("MODULE_DIR");\r
         File moduleFile = new File(module_path);\r
         File sourceFile = new File(filename);\r
+        \r
+        //\r
         // If source file is AutoGen.c, then Filepath is .\r
         // If source file is AutoGen.c, then Filepath is .\r
-        String sourceFilepath;\r
-        String sourceFilename;\r
+        //\r
+        String sourceFilepath = "";\r
+        String sourceFilename = "";\r
+        String sourceFileext = "";\r
         if (sourceFile.getPath().endsWith("AutoGen.c")) {\r
             sourceFilepath = ".";\r
             sourceFilename = "AutoGen";\r
         if (sourceFile.getPath().endsWith("AutoGen.c")) {\r
             sourceFilepath = ".";\r
             sourceFilename = "AutoGen";\r
+            sourceFileext = ".c";\r
             filetype = "AUTOGEN";\r
         } else {\r
             // sourceFile.\r
             filetype = "AUTOGEN";\r
         } else {\r
             // sourceFile.\r
@@ -206,12 +247,14 @@ public class FileProcess {
             index = str.lastIndexOf('.');\r
             if (index > 0) {\r
                 sourceFilename = str.substring(0, index);\r
             index = str.lastIndexOf('.');\r
             if (index > 0) {\r
                 sourceFilename = str.substring(0, index);\r
+                sourceFileext = str.substring(index);\r
             }\r
         }\r
         // <Build_filetype FILEPATH="" FILENAME="" />\r
         Element ele = document.createElement("Build_" + filetype);\r
         ele.setAttribute("FILEPATH", sourceFilepath);\r
         ele.setAttribute("FILENAME", sourceFilename);\r
             }\r
         }\r
         // <Build_filetype FILEPATH="" FILENAME="" />\r
         Element ele = document.createElement("Build_" + filetype);\r
         ele.setAttribute("FILEPATH", sourceFilepath);\r
         ele.setAttribute("FILENAME", sourceFilename);\r
+        ele.setAttribute("FILEEXT", sourceFileext.substring(1));\r
         String[] includePaths = includes.toArray(new String[includes.size()]);\r
         Element includesEle = document.createElement("EXTRA.INC");\r
         for (int i = 0; i < includePaths.length; i++) {\r
         String[] includePaths = includes.toArray(new String[includes.size()]);\r
         Element includesEle = document.createElement("EXTRA.INC");\r
         for (int i = 0; i < includePaths.length; i++) {\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java
new file mode 100644 (file)
index 0000000..b9afc57
--- /dev/null
@@ -0,0 +1,210 @@
+package org.tianocore.build;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.InputStreamReader;\r
+import java.util.Iterator;\r
+import java.util.LinkedHashSet;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.Task;\r
+import org.tianocore.build.fpd.FpdParserTask;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.toolchain.ToolChainInfo;\r
+\r
+public class FrameworkBuildTask extends Task{\r
+\r
+    private Set<File> buildFiles = new LinkedHashSet<File>();\r
+    \r
+    private Set<File> fpdFiles = new LinkedHashSet<File>();\r
+    \r
+    private Set<File> msaFiles = new LinkedHashSet<File>();\r
+    \r
+    ///\r
+    /// there are three type: all (build), clean and cleanall\r
+    ///\r
+    private String type = "all";\r
+    \r
+    public void execute() throws BuildException {\r
+        //\r
+        // Seach build.xml -> .FPD -> .MSA file\r
+        //\r
+        try {\r
+            //\r
+            // Gen Current Working Directory\r
+            //\r
+            File dummyFile = new File(".");\r
+            File cwd = dummyFile.getCanonicalFile();\r
+            File[] files = cwd.listFiles();\r
+            for (int i = 0; i < files.length; i++) {\r
+                if (files[i].isFile()) {\r
+                    if (files[i].getName().equalsIgnoreCase("build.xml")) {\r
+                        //\r
+                        // First, search build.xml, if found, ANT call it\r
+                        //\r
+                        buildFiles.add(files[i]);\r
+\r
+                    } else if (files[i].getName().endsWith(".fpd")) {\r
+                        //\r
+                        // Second, search FPD file, if found, build it\r
+                        //\r
+                        fpdFiles.add(files[i]);\r
+                    } else if (files[i].getName().endsWith(".msa")) {\r
+                        //\r
+                        // Third, search MSA file, if found, build it\r
+                        //\r
+                        msaFiles.add(files[i]);\r
+                    }\r
+                }\r
+            }\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+        \r
+        //\r
+        // If there is no build files or FPD files or MSA files, stop build\r
+        //\r
+        if (fpdFiles.size() == 0 && msaFiles.size() == 0) {\r
+            throw new BuildException("Can't find any build.xml file or FPD files or MSA files in current directory. ");\r
+        }\r
+        \r
+        File buildFile = intercommuniteWithUser();\r
+        System.out.println("Start to build file [" + buildFile.getPath() + "] ..>> ");\r
+        \r
+        //\r
+        // Deal with all environment variable (Add them to properties)\r
+        //\r
+        backupSystemProperties();\r
+        \r
+        //\r
+        // Get ToolChain Info from environment\r
+        //\r
+        ToolChainInfo envToolChainInfo = new ToolChainInfo(); \r
+        envToolChainInfo.addTargets(getProject().getProperty("TARGET")); \r
+        envToolChainInfo.addTagnames(getProject().getProperty("TAGNAME")); \r
+        envToolChainInfo.addArchs(getProject().getProperty("ARCH")); \r
+        GlobalData.setToolChainEnvInfo(envToolChainInfo);\r
+        \r
+        //\r
+        // Global Data initialization\r
+        //\r
+        String toolsDefFilename = "tools_def.txt";\r
+        if (getProject().getProperty("TOOLS_DEF") != null) {\r
+            toolsDefFilename = getProject().getProperty("TOOLS_DEF");\r
+        }\r
+        \r
+        GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",\r
+                            getProject().getProperty("WORKSPACE_DIR"), toolsDefFilename);\r
+        \r
+        //\r
+        // Build every FPD files (PLATFORM build)\r
+        //\r
+        if (buildFile.getName().endsWith(".fpd")) {\r
+            FpdParserTask fpdParserTask = new FpdParserTask();\r
+            fpdParserTask.setType(type);\r
+            fpdParserTask.setProject(getProject());\r
+            fpdParserTask.setFpdFile(buildFile);\r
+            fpdParserTask.execute();\r
+        }\r
+        \r
+        //\r
+        // Build every MSA files (SINGLE MODULE BUILD)\r
+        //\r
+        else if (buildFile.getName().endsWith(".msa")) {\r
+            GenBuildTask genBuildTask = new GenBuildTask();\r
+            genBuildTask.setType(type);\r
+            genBuildTask.setProject(getProject());\r
+            genBuildTask.setMsaFile(buildFile);\r
+            genBuildTask.execute();\r
+        }\r
+    }\r
+    \r
+    /**\r
+      Transfer system environment variables to ANT properties. If system variable \r
+      already exiests in ANT properties, skip it.\r
+      \r
+    **/\r
+    private void backupSystemProperties() {\r
+        Map<String, String> sysProperties = System.getenv();\r
+        Set<String> keys = sysProperties.keySet();\r
+        Iterator<String> iter = keys.iterator();\r
+        while (iter.hasNext()) {\r
+            String name = iter.next();\r
+            \r
+            //\r
+            // If system environment variable is not in ANT properties, add it\r
+            //\r
+            if (getProject().getProperty(name) == null) {\r
+                getProject().setProperty(name, sysProperties.get(name));\r
+            }\r
+        }\r
+    }\r
+\r
+    private File intercommuniteWithUser(){\r
+        File file = null;\r
+        if (fpdFiles.size() + msaFiles.size() > 1) {\r
+            File[] allFiles = new File[fpdFiles.size() + msaFiles.size()];\r
+            int index = 0;\r
+            Iterator<File> iter = fpdFiles.iterator();\r
+            while (iter.hasNext()) {\r
+                allFiles[index] = iter.next();\r
+                index++;\r
+            }\r
+            iter = msaFiles.iterator();\r
+            while (iter.hasNext()) {\r
+                allFiles[index] = iter.next();\r
+                index++;\r
+            }\r
+            System.out.println("Find " + allFiles.length + " FPD and MSA files: ");\r
+            for (int i = 0; i < allFiles.length; i++) {\r
+                System.out.println("[" + (i + 1) + "]: " + allFiles[i].getName());\r
+            }\r
+            \r
+            boolean flag = true;\r
+            System.out.print("Please select one file to build:[1] ");\r
+            do{\r
+                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r
+                try {\r
+                     String str = br.readLine();\r
+                     if (str.trim().length() == 0) {\r
+                         file = allFiles[0];\r
+                         flag = false;\r
+                         continue ;\r
+                     }\r
+                     int indexSelect = Integer.parseInt(str);\r
+                     if (indexSelect <=0 || indexSelect > allFiles.length) {\r
+                         System.out.print("Please enter a number between [1.." + allFiles.length + "]:[1] ");\r
+                         continue ;\r
+                     } else {\r
+                         file = allFiles[indexSelect - 1];\r
+                         flag = false;\r
+                         continue ;\r
+                     }\r
+                } catch (Exception e) {\r
+                    System.out.print("Please enter a valid number:[1] ");\r
+                    flag = true;\r
+                }\r
+            } while (flag);\r
+        }\r
+        else if (fpdFiles.size() == 1) {\r
+            file = fpdFiles.toArray(new File[1])[0];\r
+        }\r
+        else if (msaFiles.size() == 1) {\r
+            file = msaFiles.toArray(new File[1])[0];\r
+        }\r
+        return file;\r
+    }\r
+    \r
+    \r
+    public void setType(String type) {\r
+        if (type.equalsIgnoreCase("clean") || type.equalsIgnoreCase("cleanall")) {\r
+            this.type = type.toLowerCase();\r
+        }\r
+        else {\r
+            this.type = "all";\r
+        }\r
+    }\r
+}\r
index 3127b8706dc3b1dd8a3344fb0089f6782a23cb55..0e807f8abbe07fc6c3bcc9671f24186413858bcd 100644 (file)
@@ -16,56 +16,42 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 package org.tianocore.build;\r
 \r
 import java.io.File;\r
 package org.tianocore.build;\r
 \r
 import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
+import java.util.Hashtable;\r
 import java.util.Iterator;\r
 import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.Iterator;\r
 import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
+import java.util.Stack;\r
 import java.util.Vector;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
 import java.util.Vector;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.transform.OutputKeys;\r
-import javax.xml.transform.Result;\r
-import javax.xml.transform.Source;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Project;\r
-import org.apache.tools.ant.Task;\r
 import org.apache.tools.ant.taskdefs.Ant;\r
 import org.apache.tools.ant.taskdefs.Ant;\r
+import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.xmlbeans.XmlObject;\r
-import org.w3c.dom.Comment;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-import org.w3c.dom.Node;\r
 \r
 \r
-import org.tianocore.build.autogen.AutoGen;\r
-import org.tianocore.build.autogen.CommonDefinition;\r
+import org.tianocore.build.exception.EdkException;\r
 import org.tianocore.build.fpd.FpdParserTask;\r
 import org.tianocore.build.fpd.FpdParserTask;\r
-import org.tianocore.build.global.GenBuildLogger;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.toolchain.ToolChainFactory;\r
-import org.tianocore.logger.EdkLog;\r
-import org.tianocore.FilenameDocument;\r
-import org.tianocore.MsaHeaderDocument;\r
-import org.tianocore.MsaLibHeaderDocument;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
+import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.tools.ModuleItem;\r
 \r
 /**\r
   <p>\r
   <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r
   system. The main function of this task is to parse module's surface area,\r
   then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r
 \r
 /**\r
   <p>\r
   <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r
   system. The main function of this task is to parse module's surface area,\r
   then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r
-  build script) and call this to build the module.\r
+  build script) and call this to build the module. The whole process including:\r
+  1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances; \r
+  3. build all source files inlcude AutoGen.c; 4. generate sections;\r
+  5. generate FFS file if it is driver module while LIB file if it is Library module. \r
   </p>\r
   \r
   <p>\r
   </p>\r
   \r
   <p>\r
@@ -73,11 +59,16 @@ import org.tianocore.MsaLibHeaderDocument;
   </p>\r
   \r
   <pre>\r
   </p>\r
   \r
   <pre>\r
-   &lt;GenBuild baseName=&quot;HelloWorld&quot; \r
-             mbdFilename=&quot;${MODULE_DIR}/HelloWorld.mbd&quot; \r
-             msaFilename=&quot;${MODULE_DIR}/HelloWorld.msa&quot;/&gt;\r
+   &lt;GenBuild  \r
+             msaFilename=&quot;HelloWorld.msa&quot;/&gt; \r
+             processTo=&quot;ALL&quot;/&gt;\r
   </pre>\r
   \r
   </pre>\r
   \r
+  <p><code>processTo</code> provides a way to customize the whole build process. \r
+  processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE. \r
+  Default is ALL, means whole \r
+  </p>\r
+  \r
   <p>\r
   This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r
   <em>AutoGen.h</em>. The task also parses the development environment\r
   <p>\r
   This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r
   <em>AutoGen.h</em>. The task also parses the development environment\r
@@ -88,85 +79,30 @@ import org.tianocore.MsaLibHeaderDocument;
   \r
   @since GenBuild 1.0\r
 **/\r
   \r
   @since GenBuild 1.0\r
 **/\r
-public class GenBuildTask extends Task {\r
-\r
+public class GenBuildTask extends Ant {\r
+    \r
     ///\r
     /// Module surface area file.\r
     ///\r
     ///\r
     /// Module surface area file.\r
     ///\r
-    File msaFilename;\r
-\r
-    ///\r
-    /// Module build description file.\r
-    ///\r
-    File mbdFilename;\r
-\r
-    ///\r
-    /// Module surface area information after overrided.\r
-    ///\r
-    public Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-\r
-    ///\r
-    /// Module's base name.\r
-    ///\r
-    private String baseName;\r
+    File msaFile;\r
 \r
     ///\r
 \r
     ///\r
-    /// Current build Arch, such as IA32, X64, IPF and so on.\r
-    ///\r
-    private String arch;\r
-\r
-    ///\r
-    /// Module's GUID (Globally Unique Identifier).\r
-    ///\r
-    private String guid;\r
-\r
-    ///\r
-    /// Module's component type, such as SEC, LIBRARY, BS_DRIVER and so on.\r
-    ///\r
-    private String componentType;\r
-\r
-    ///\r
-    /// This value is used in build time. Override module's component type. When\r
-    /// search FFS (Sections information) in common file, buildtype instead of\r
-    /// component type.\r
-    ///\r
-    private String buildType;\r
-\r
-    ///\r
-    /// List all required includes for current build module.\r
-    ///\r
-    public Set<String> includes = new LinkedHashSet<String>();\r
-\r
-    ///\r
-    /// List all libraries for current build module.\r
-    ///\r
-    public Set<String> libraries = new LinkedHashSet<String>();\r
-\r
-    ///\r
-    /// List all source files for current build module.\r
-    ///\r
-    public Set<String> sourceFiles = new LinkedHashSet<String>();\r
-\r
-    ///\r
-    /// Flag to identify what surface area files are specified. Current value is\r
-    /// <em>NO_SA</em>, <em>ONLY_MSA</em>, <em>ONLY_LIBMSA</em>,\r
-    /// <em>MSA_AND_MBD</em> or <em>LIBMSA_AND_LIBMBD</em>.\r
     /// \r
     /// \r
-    /// @see org.tianocore.build.global.GlobaData\r
     ///\r
     ///\r
-    private int flag = GlobalData.NO_SA;\r
-\r
+    private String type = "all"; // = "build";\r
+    \r
     ///\r
     ///\r
-    /// The information at the header of <em>build.xml</em>.\r
+    /// Module's Identification.\r
     ///\r
     ///\r
-    private String info = "====================================================================\n"\r
-                        + "DO NOT EDIT \n"\r
-                        + "File auto-generated by build utility\n"\r
-                        + "\n"\r
-                        + "Abstract:\n"\r
-                        + "Auto-generated ANT build file for building of EFI Modules/Platforms\n"\r
-                        + "=====================================================================";\r
+    private ModuleIdentification moduleId;\r
 \r
 \r
+    private Vector<Property> properties = new Vector<Property>();\r
+    \r
+    private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();\r
+    \r
+    \r
+    private static Hashtable backupProperties;\r
+    \r
     /**\r
       Public construct method. It is necessary for ANT task.\r
     **/\r
     /**\r
       Public construct method. It is necessary for ANT task.\r
     **/\r
@@ -174,945 +110,537 @@ public class GenBuildTask extends Task {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      ANT task's entry point, will be called after init(). The main steps is described\r
-      as following: \r
-      <ul>\r
-      <li> Judge current build mode (MODULE | PACKAGE | PLATFORM). This step will execute\r
-      only once in whole build process; </li>\r
-      <li> Initialize global information (Framework DB, SPD files and all MSA files \r
-      listed in SPD). This step will execute only once in whole build process; </li>\r
-      <li> Restore some important ANT property. If current build is single module \r
-      build, here will set many default values; </li>\r
-      <li> Get the current module's overridded surface area information from \r
-      global data; </li> \r
-      <li> Set up the output directories, including BIN_DIR, DEST_DIR_OUTPUT and\r
-      DEST_DIR_DEBUG; </li>\r
-      <li> Get module dependent library instances and include pathes; </li>\r
-      <li> Judge whether current module is built. If yes, skip it; </li>\r
-      <li> Call AutoGen and PCD to generate AutoGen.c & AutoGen.h </li>\r
-      <li> Set up the compile flags; </li>\r
-      <li> Generate BaseName_build.xml; </li>\r
-      <li> Call to BaseName_build.xml, and build the current module. </li>\r
-      </ul>\r
-      \r
-      <p>Build is dependent on BuildMacro.xml which define many macro. </p> \r
-      \r
+  \r
       @throws BuildException\r
               From module build, exception from module surface area invalid.\r
     **/\r
     public void execute() throws BuildException {\r
       @throws BuildException\r
               From module build, exception from module surface area invalid.\r
     **/\r
     public void execute() throws BuildException {\r
-        System.out.println("Module [" + baseName + "] start.");\r
-        //\r
-        // Inital GenBuild log  method \r
-        //\r
-        GenBuildLogger logger = new GenBuildLogger(getProject());\r
-        EdkLog.setLogger(logger);\r
-        EdkLog.setLogLevel(1);\r
-        \r
-        OutputManager.update(getProject());\r
-        GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",\r
-                            getProject().getProperty("WORKSPACE_DIR"));\r
-        recallFixedProperties();\r
-        arch = getProject().getProperty("ARCH");\r
-        arch = arch.toUpperCase();\r
-        map = GlobalData.getDoc(baseName);\r
-        //\r
-        // Initialize SurfaceAreaQuery\r
-        //\r
-        SurfaceAreaQuery.setDoc(map);\r
-        //\r
-        // Setup Output Management\r
-        //\r
-        String[] outdir = SurfaceAreaQuery.getOutputDirectory();\r
-        OutputManager.update(getProject(), outdir[1], outdir[0]);\r
-\r
-        updateIncludesAndLibraries();\r
-\r
-        if (GlobalData.isModuleBuilt(baseName, arch)) {\r
-            return;\r
-        } else {\r
-            GlobalData.registerBuiltModule(baseName, arch);\r
-        }\r
+        try{\r
+        pushProperties();\r
         //\r
         //\r
-        // Call AutoGen\r
+        // Enable all specified properties\r
         //\r
         //\r
-        AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), baseName, arch);\r
-        autogen.genAutogen();\r
-        //\r
-        // Update parameters\r
-        //\r
-        updateParameters();\r
-        //\r
-        // Update flags like CC_FLAGS, LIB_FLAGS etc.\r
-        //\r
-        flagsSetup();\r
-        GlobalData.addLibrary(baseName, arch, getProject().getProperty("BIN_DIR") + File.separatorChar + baseName + ".lib");\r
-        GlobalData.addModuleLibrary(baseName, arch, libraries);\r
-        //\r
-        // If ComponentType is USER_DEFINED,\r
-        // then call the exist BaseName_build.xml directly.\r
-        //\r
-        if (buildType.equalsIgnoreCase("CUSTOM_BUILD")) {\r
-            System.out.println("Call user-defined " + baseName + "_build.xml");\r
-            Ant ant = new Ant();\r
-            ant.setProject(getProject());\r
-            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + baseName + "_build.xml");\r
-            ant.setInheritAll(true);\r
-            ant.init();\r
-            ant.execute();\r
-            return;\r
+        Iterator<Property> iter = properties.iterator();\r
+        while (iter.hasNext()) {\r
+            Property item = iter.next();\r
+            getProject().setProperty(item.getName(), item.getValue());\r
         }\r
         }\r
+        \r
         //\r
         //\r
-        // Generate ${BASE_NAME}_build.xml file\r
+        // GenBuild should specify either msaFile or moduleGuid & packageGuid\r
         //\r
         //\r
-        System.out.println("Generate " + baseName + "_build.xml");\r
-        genBuildFile();\r
-        System.out.println("Call the " + baseName + "_build.xml");\r
-        Ant ant = new Ant();\r
-        ant.setProject(getProject());\r
-        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + baseName + "_build.xml");\r
-        ant.setInheritAll(true);\r
-        ant.init();\r
-        ant.execute();\r
-    }\r
-\r
-    /**\r
-      Return the name of the directory that corresponds to the architecture.\r
-      This is a translation from the XML Schema tag to a directory that\r
-      corresponds to our directory name coding convention.\r
-     \r
-    **/\r
-    private String archDir(String arch) {\r
-        return arch.replaceFirst("X64", "x64")\r
-                   .replaceFirst("IPF", "Ipf")\r
-                   .replaceFirst("IA32", "Ia32")\r
-                   .replaceFirst("ARM", "Arm")\r
-                   .replaceFirst("EBC", "Ebc");\r
-    }\r
-\r
-    /**\r
-      Get the dependent library instances and include package name from \r
-      surface area, and initialize module include pathes. \r
-     \r
-    **/\r
-    private void updateIncludesAndLibraries() {\r
-        List<String> rawIncludes = SurfaceAreaQuery.getIncludePackageName(arch);\r
-        if (rawIncludes != null) {\r
-            Iterator iter = rawIncludes.iterator();\r
-            while (iter.hasNext()) {\r
-                String packageName = (String) iter.next();\r
-                includes.add("${WORKSPACE_DIR}" + File.separatorChar + GlobalData.getPackagePath(packageName)\r
-                             + File.separatorChar + "Include");\r
-                includes.add("${WORKSPACE_DIR}" + File.separatorChar + GlobalData.getPackagePath(packageName)\r
-                             + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
+        if (msaFile == null ) {\r
+            String moduleGuid = getProject().getProperty("MODULE_GUID");\r
+            String moduleVersion = getProject().getProperty("MODULE_VERSION");\r
+            String packageGuid = getProject().getProperty("PACKAGE_GUID");\r
+            String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r
+            if (moduleGuid == null || packageGuid == null) {\r
+                throw new BuildException("GenBuild parameters error. ");\r
             }\r
             }\r
+            PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r
+            moduleId = new ModuleIdentification(moduleGuid, moduleVersion);\r
+            moduleId.setPackage(packageId);\r
+            Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r
+            SurfaceAreaQuery.setDoc(doc);\r
+            moduleId = SurfaceAreaQuery.getMsaHeader();\r
         }\r
         }\r
-        includes.add("${DEST_DIR_DEBUG}");\r
-        List<String> rawLibraries = SurfaceAreaQuery.getLibraryInstance(this.arch, CommonDefinition.AlwaysConsumed);\r
-        if (rawLibraries != null) {\r
-            Iterator iter = rawLibraries.iterator();\r
-            while (iter.hasNext()) {\r
-                libraries.add((String) iter.next());\r
-            }\r
+        else {\r
+            Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r
+            SurfaceAreaQuery.setDoc(doc);\r
+            moduleId = SurfaceAreaQuery.getMsaHeader();\r
         }\r
         }\r
-        normalize();\r
-    }\r
-\r
-    /**\r
-      Normalize all dependent library instance and include pathes' format. \r
-     \r
-    **/\r
-    private void normalize() {\r
-        String[] includesArray = includes.toArray(new String[includes.size()]);\r
-        includes.clear();\r
-        for (int i = 0; i < includesArray.length; i++) {\r
-            includes.add((new File(includesArray[i])).getPath());\r
+        String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");\r
+        if (producedLibraryClasses.length == 0) {\r
+            moduleId.setLibrary(false);\r
         }\r
         }\r
-        String[] librariesArray = libraries.toArray(new String[libraries.size()]);\r
-        libraries.clear();\r
-        for (int i = 0; i < librariesArray.length; i++) {\r
-            libraries.add((new File(librariesArray[i])).getPath());\r
+        else {\r
+            moduleId.setLibrary(true);\r
         }\r
         }\r
-    }\r
-\r
-    /**\r
-      Restore some important ANT property. If current build is single module \r
-      build, here will set many default values.\r
-      \r
-      <p> If current build is single module build, then the default <code>ARCH</code>\r
-      is <code>IA32</code>. Also set up the properties <code>PACKAGE</code>, \r
-      <code>PACKAGE_DIR</code>, <code>TARGET</code> and <code>MODULE_DIR</code></p>\r
-      \r
-      <p> Note that for package build, package name is stored in <code>PLATFORM</code>\r
-      and package directory is stored in <code>PLATFORM_DIR</code>. </p> \r
-     \r
-      @see org.tianocore.build.global.OutputManager\r
-    **/\r
-    private void recallFixedProperties() {\r
+        \r
         //\r
         //\r
-        // If build is for module build\r
+        // Judge whether it is single module build or not\r
         //\r
         //\r
-        if (getProject().getProperty("PACKAGE_DIR") == null) {\r
-            ToolChainFactory toolChainFactory = new ToolChainFactory(getProject());\r
-            toolChainFactory.setupToolChain();\r
+        if (getProject().getProperty("PLATFORM") == null) {\r
             //\r
             //\r
-            // PACKAGE PACKAGE_DIR ARCH (Default) COMMON_FILE BUILD_MACRO\r
+            // Single Module build\r
             //\r
             //\r
-            if (getProject().getProperty("ARCH") == null) {\r
-                getProject().setProperty("ARCH", "IA32");\r
-            }\r
-            String packageName = GlobalData.getPackageNameForModule(baseName);\r
-            getProject().setProperty("PACKAGE", packageName);\r
-            \r
-            String packageDir = GlobalData.getPackagePath(packageName);\r
-            getProject().setProperty("PACKAGE_DIR",\r
-                                     getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + packageDir);\r
-            \r
-            getProject().setProperty("TARGET", toolChainFactory.getCurrentTarget());\r
+            prepareSingleModuleBuild();\r
+        }\r
+        else {\r
+            //\r
+            // Platform build. Restore the platform related info\r
+            //\r
+            String platformName = getProject().getProperty("PLATFORM");\r
+            PlatformIdentification platformId = GlobalData.getPlatform(platformName);\r
+            getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+            getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
             \r
             \r
-            getProject().setProperty("MODULE_DIR",\r
-                                     getProject().replaceProperties(getProject().getProperty("MODULE_DIR")));\r
+            String packageGuid = getProject().getProperty("PACKAGE_GUID");\r
+            String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r
+            PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r
+            moduleId.setPackage(packageId);\r
         }\r
         }\r
-        if (OutputManager.PLATFORM != null) {\r
-            getProject().setProperty("PLATFORM", OutputManager.PLATFORM);\r
+        \r
+        //\r
+        // If single module : intersection MSA supported ARCHs and tools def!!\r
+        // else, get arch from pass down\r
+        //\r
+        String[] archList = new String[0];\r
+        if ( getProject().getProperty("ARCH") != null ) {\r
+            archList = getProject().getProperty("ARCH").split(" ");\r
         }\r
         }\r
-        if (OutputManager.PLATFORM_DIR != null) {\r
-            getProject().setProperty("PLATFORM_DIR", OutputManager.PLATFORM_DIR);\r
+        else {\r
+            archList = GlobalData.getToolChainInfo().getArchs();\r
         }\r
         }\r
-    }\r
-\r
-    /**\r
-      The whole BaseName_build.xml is composed of seven part. \r
-      <ul>\r
-      <li> ANT properties; </li>\r
-      <li> Dependent module (dependent library instances in most case); </li>\r
-      <li> Source files; </li>\r
-      <li> Sections if module is not library; </li>\r
-      <li> Output (different for library module and driver module); </li>\r
-      <li> Clean; </li>\r
-      <li> Clean all. </li>\r
-      </ul>\r
-      \r
-      @throws BuildException\r
-              Error throws during BaseName_build.xml generating. \r
-    **/\r
-    private void genBuildFile() throws BuildException {\r
-        FfsProcess fp = new FfsProcess();\r
-        DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
-        try {\r
-            DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
-            Document document = dombuilder.newDocument();\r
-            Comment rootComment = document.createComment(info);\r
-            //\r
-            // create root element and its attributes\r
-            //\r
-            Element root = document.createElement("project");\r
-            //\r
-            // root.setAttribute("name", base_name);\r
-            //\r
-            root.setAttribute("default", "main");\r
-            root.setAttribute("basedir", ".");\r
-            //\r
-            // element for External ANT tasks\r
-            //\r
-            root.appendChild(document.createComment("Apply external ANT tasks"));\r
-            Element ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "frameworktasks.tasks");\r
-            root.appendChild(ele);\r
-            ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "cpptasks.tasks");\r
-            root.appendChild(ele);\r
-            ele = document.createElement("typedef");\r
-            ele.setAttribute("resource", "cpptasks.types");\r
-            root.appendChild(ele);\r
-            ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "net/sf/antcontrib/antlib.xml");\r
-            root.appendChild(ele);\r
-            //\r
-            // elements for Properties\r
-            //\r
-            root.appendChild(document.createComment("All Properties"));\r
-            ele = document.createElement("property");\r
-            ele.setAttribute("name", "BASE_NAME");\r
-            ele.setAttribute("value", baseName);\r
-            root.appendChild(ele);\r
-            //\r
-            // Generate the default target,\r
-            // which depends on init, sections and output target\r
-            //\r
-            root.appendChild(document.createComment("Default target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "main");\r
-            ele.setAttribute("depends", "libraries, sourcefiles, sections, output");\r
-            root.appendChild(ele);\r
-            //\r
-            // compile all source files\r
-            //\r
-            root.appendChild(document.createComment("Compile all dependency Library instances."));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "libraries");\r
-            //\r
-            // Parse all sourfiles but files specified in sections\r
-            //\r
-            applyLibraryInstance(document, ele);\r
-            root.appendChild(ele);\r
-            //\r
-            // compile all source files\r
-            //\r
-            root.appendChild(document.createComment("sourcefiles target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "sourcefiles");\r
-            //\r
-            // Parse all sourfiles but files specified in sections\r
-            //\r
-            applyCompileElement(document, ele);\r
-            root.appendChild(ele);\r
-            //\r
-            // generate the init target\r
-            // main purpose is create all nessary pathes\r
-            // generate the sections target\r
-            //\r
-            root.appendChild(document.createComment("sections target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "sections");\r
-            applySectionsElement(document, ele, fp);\r
-            root.appendChild(ele);\r
-            //\r
-            // generate the output target\r
-            //\r
-            root.appendChild(document.createComment("output target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "output");\r
-            applyOutputElement(document, ele, fp);\r
-            root.appendChild(ele);\r
-            //\r
-            // generate the clean target\r
-            //\r
-            root.appendChild(document.createComment("clean target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "clean");\r
-            applyCleanElement(document, ele);\r
-            root.appendChild(ele);\r
-            //\r
-            // generate the Clean All target\r
-            //\r
-            root.appendChild(document.createComment("Clean All target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "cleanall");\r
-            applyDeepcleanElement(document, ele);\r
-            root.appendChild(ele);\r
-            //\r
-            // add the root element to the document\r
-            //\r
-            document.appendChild(rootComment);\r
-            document.appendChild(root);\r
-            //\r
-            // Prepare the DOM document for writing\r
-            //\r
-            Source source = new DOMSource(document);\r
-            //\r
-            // Prepare the output file\r
-            //\r
-            File file = new File(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + baseName\r
-                                 + "_build.xml");\r
-            //\r
-            // generate all directory path\r
-            //\r
-            (new File(file.getParent())).mkdirs();\r
-            Result result = new StreamResult(file);\r
-            //\r
-            // Write the DOM document to the file\r
-            //\r
-            Transformer xformer = TransformerFactory.newInstance().newTransformer();\r
-            xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
-            xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
-            xformer.transform(source, result);\r
-        } catch (Exception ex) {\r
-            throw new BuildException("Module [" + baseName + "] generating build file failed.\n" + ex.getMessage());\r
+        \r
+        \r
+        //\r
+        // Judge if arch is all supported by current module. If not, throw Exception.\r
+        //\r
+        List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();\r
+        if (moduleSupportedArchs != null) {\r
+            for (int k = 0; k < archList.length; k++) {\r
+                if ( ! moduleSupportedArchs.contains(archList[k])) {\r
+                    throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");\r
+                }\r
+            }\r
         }\r
         }\r
-    }\r
-\r
-    /**\r
-      Generate the clean elements for BaseName_build.xml. \r
-      \r
-      @param document current BaseName_build.xml XML document\r
-      @param root Root element for current\r
-    **/\r
-    private void applyCleanElement(Document document, Node root) {\r
-        String[] libinstances = libraries.toArray(new String[libraries.size()]);\r
-        for (int i = 0; i < libinstances.length; i++) {\r
-            File file = new File(GlobalData.getModulePath(libinstances[i]) + File.separatorChar + "build.xml");\r
-\r
-            Element ifEle = document.createElement("if");\r
-            Element availableEle = document.createElement("available");\r
-            availableEle.setAttribute("file", file.getPath());\r
-            ifEle.appendChild(availableEle);\r
-            Element elseEle = document.createElement("then");\r
-\r
-            Element ele = document.createElement("ant");\r
-            ele.setAttribute("antfile", file.getPath());\r
-            ele.setAttribute("inheritAll", "false");\r
-            ele.setAttribute("target", libinstances[i] + "_clean");\r
-            //\r
-            // Workspace_DIR\r
-            //\r
-            Element property = document.createElement("property");\r
-            property.setAttribute("name", "WORKSPACE_DIR");\r
-            property.setAttribute("value", "${WORKSPACE_DIR}");\r
-            ele.appendChild(property);\r
-            //\r
-            // Package Dir\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "PACKAGE_DIR");\r
-            property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
-                                           + GlobalData.getPackagePathForModule(libinstances[i]));\r
-            ele.appendChild(property);\r
-            //\r
-            // ARCH\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "ARCH");\r
-            property.setAttribute("value", "${ARCH}");\r
-            ele.appendChild(property);\r
-            //\r
-            // TARGET\r
+        \r
+        for (int k = 0; k < archList.length; k++) {\r
+            getProject().setProperty("ARCH", archList[k]);\r
+            \r
+            FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r
+            \r
             //\r
             //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "TARGET");\r
-            property.setAttribute("value", "${TARGET}");\r
-            ele.appendChild(property);\r
+            // Whether the module is built before\r
             //\r
             //\r
-            // PACKAGE\r
+            if (GlobalData.isModuleBuilt(fpdModuleId)) {\r
+                return ;\r
+            }\r
+            else {\r
+                GlobalData.registerBuiltModule(fpdModuleId);\r
+            }\r
+            \r
             //\r
             //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "PACKAGE");\r
-            property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i]));\r
-            ele.appendChild(property);\r
-\r
-            elseEle.appendChild(ele);\r
-            ifEle.appendChild(elseEle);\r
-            root.appendChild(ifEle);\r
+            // For Every TOOLCHAIN, TARGET\r
+            //\r
+            String[] targetList =  GlobalData.getToolChainInfo().getTargets();\r
+            for (int i = 0; i < targetList.length; i ++){\r
+                //\r
+                // Prepare for target related common properties\r
+                // TARGET\r
+                //\r
+                getProject().setProperty("TARGET", targetList[i]);\r
+                String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
+                for(int j = 0; j < toolchainList.length; j ++){\r
+                    //\r
+                    // Prepare for toolchain related common properties\r
+                    // TOOLCHAIN\r
+                    //\r
+                    getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r
+\r
+                    System.out.println("Build " + moduleId + " start >>>");\r
+                    System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);\r
+                    SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));\r
+                    \r
+                    //\r
+                    // Prepare for all other common properties\r
+                    // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
+                    // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r
+                    // MODULE_DIR, MODULE_RELATIVE_DIR\r
+                    // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r
+                    // LIBS, OBJECTS, SDB_FILES\r
+                    //\r
+                    setModuleCommonProperties(archList[k]);\r
+                    \r
+                    //\r
+                    // OutputManage prepare for \r
+                    // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r
+                    //\r
+                    OutputManager.getInstance().update(getProject());\r
+                    \r
+                    if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r
+                        applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r
+                    }\r
+                    else if (type.equalsIgnoreCase("clean")) {\r
+                        applyClean(fpdModuleId);\r
+                    }\r
+                    else if (type.equalsIgnoreCase("cleanall")) {\r
+                        applyCleanall(fpdModuleId);\r
+                    }\r
+                }\r
+            }\r
         }\r
         }\r
-    }\r
-\r
-    /**\r
-      Generate the cleanall elements for BaseName_build.xml. \r
-      \r
-      @param document current BaseName_build.xml XML document\r
-      @param root Root element for current\r
-    **/\r
-    private void applyDeepcleanElement(Document document, Node root) {\r
-        String[] libinstances = libraries.toArray(new String[libraries.size()]);\r
-        for (int i = 0; i < libinstances.length; i++) {\r
-            File file = new File(GlobalData.getModulePath(libinstances[i]) + File.separatorChar + "build.xml");\r
-\r
-            Element ifEle = document.createElement("if");\r
-            Element availableEle = document.createElement("available");\r
-            availableEle.setAttribute("file", file.getPath());\r
-            ifEle.appendChild(availableEle);\r
-            Element elseEle = document.createElement("then");\r
-\r
-            Element ele = document.createElement("ant");\r
-            ele.setAttribute("antfile", file.getPath());\r
-            ele.setAttribute("inheritAll", "false");\r
-            ele.setAttribute("target", libinstances[i] + "_cleanall");\r
-            //\r
-            // Workspace_DIR\r
-            //\r
-            Element property = document.createElement("property");\r
-            property.setAttribute("name", "WORKSPACE_DIR");\r
-            property.setAttribute("value", "${WORKSPACE_DIR}");\r
-            ele.appendChild(property);\r
-            //\r
-            // Package Dir\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "PACKAGE_DIR");\r
-            property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
-                                           + GlobalData.getPackagePathForModule(libinstances[i]));\r
-            ele.appendChild(property);\r
-            //\r
-            // ARCH\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "ARCH");\r
-            property.setAttribute("value", "${ARCH}");\r
-            ele.appendChild(property);\r
-            //\r
-            // TARGET\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "TARGET");\r
-            property.setAttribute("value", "${TARGET}");\r
-            ele.appendChild(property);\r
-            //\r
-            // PACKAGE\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "PACKAGE");\r
-            property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i]));\r
-            ele.appendChild(property);\r
-\r
-            elseEle.appendChild(ele);\r
-            ifEle.appendChild(elseEle);\r
-            root.appendChild(ifEle);\r
+        popProperties();\r
+        }catch (Exception e){\r
+            e.printStackTrace();\r
+            throw new BuildException(e.getMessage());\r
         }\r
     }\r
 \r
     /**\r
         }\r
     }\r
 \r
     /**\r
-      Generate the dependent library instances elements for BaseName_build.xml\r
+      This method is used to prepare Platform-related information\r
       \r
       \r
-      @param document current BaseName_build.xml XML document\r
-      @param root Root element for current\r
-    **/\r
-    private void applyLibraryInstance(Document document, Node root) {\r
-        String[] libinstances = libraries.toArray(new String[libraries.size()]);\r
-        for (int i = 0; i < libinstances.length; i++) {\r
-            Element ele = document.createElement("ant");\r
-            File file = new File(GlobalData.getModulePath(libinstances[i]) + File.separatorChar + "build.xml");\r
-            ele.setAttribute("antfile", file.getPath());\r
-            ele.setAttribute("inheritAll", "false");\r
-            ele.setAttribute("target", libinstances[i]);\r
-            //\r
-            // Workspace_DIR\r
-            //\r
-            Element property = document.createElement("property");\r
-            property.setAttribute("name", "WORKSPACE_DIR");\r
-            property.setAttribute("value", "${WORKSPACE_DIR}");\r
-            ele.appendChild(property);\r
-            //\r
-            // Package Dir\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "PACKAGE_DIR");\r
-            property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
-                                           + GlobalData.getPackagePathForModule(libinstances[i]));\r
-            ele.appendChild(property);\r
-            //\r
-            // ARCH\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "ARCH");\r
-            property.setAttribute("value", "${ARCH}");\r
-            ele.appendChild(property);\r
-            //\r
-            // TARGET\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "TARGET");\r
-            property.setAttribute("value", "${TARGET}");\r
-            ele.appendChild(property);\r
-            //\r
-            // PACKAGE\r
-            //\r
-            property = document.createElement("property");\r
-            property.setAttribute("name", "PACKAGE");\r
-            property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i]));\r
-            ele.appendChild(property);\r
-            root.appendChild(ele);\r
-        }\r
-        Element expand = document.createElement("Expand");\r
-        root.appendChild(expand);\r
-    }\r
-    \r
-    /**\r
-      Generate the build source files elements for BaseName_build.xml. \r
-      \r
-      @param document current BaseName_build.xml XML document\r
-      @param root Root element for current\r
+      <p>In Single Module Build mode, platform-related information is not ready.\r
+      The method read the system environment variable <code>ACTIVE_PLATFORM</code> \r
+      and search in the Framework Database. Note that platform name in the Framework\r
+      Database must be unique. </p>\r
+     \r
     **/\r
     **/\r
-    private void applyCompileElement(Document document, Node root) {\r
-        FileProcess fileProcess = new FileProcess();\r
-        fileProcess.init(getProject(), includes, sourceFiles, document);\r
-        Node[] files = this.getSourceFiles();\r
+    private void prepareSingleModuleBuild(){\r
         //\r
         //\r
-        // Parse all unicode files\r
+        // Find out the package which the module belongs to\r
+        // TBD: Enhance it!!!!\r
         //\r
         //\r
-        for (int i = 0; i < files.length; i++) {\r
-            String filetype = getFiletype(files[i]);\r
-            if (filetype != null) {\r
-                fileProcess.parseFile(getFilename(files[i]), filetype, root, true);\r
-            } else {\r
-                fileProcess.parseFile(getFilename(files[i]), root, true);\r
-            }\r
-        }\r
-        if (fileProcess.isUnicodeExist()) {\r
-            Element ele = document.createElement("Build_Unicode_Database");\r
-            ele.setAttribute("FILEPATH", ".");\r
-            ele.setAttribute("FILENAME", "${BASE_NAME}");\r
-            root.appendChild(ele);\r
-        }\r
-\r
+        PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r
+        \r
+        moduleId.setPackage(packageId);\r
+        \r
         //\r
         //\r
-        // Parse AutoGen.c & AutoGen.h\r
+        // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r
         //\r
         //\r
-        if (!baseName.equalsIgnoreCase("Shell")) {\r
-            fileProcess.parseFile(getProject().getProperty("DEST_DIR_DEBUG") + File.separatorChar + "AutoGen.c", root,\r
-                                  false);\r
+        String activePlatformName = getProject().getProperty("ACTIVE_PLATFORM");\r
+        \r
+        if (activePlatformName == null){\r
+            throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");\r
         }\r
         }\r
+        \r
+        PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);\r
+        \r
         //\r
         //\r
-        // Parse all source files\r
+        // Read FPD file\r
         //\r
         //\r
-        for (int i = 0; i < files.length; i++) {\r
-            String filetype = getFiletype(files[i]);\r
-            if (filetype != null) {\r
-                fileProcess.parseFile(getFilename(files[i]), filetype, root, false);\r
-            } else {\r
-                fileProcess.parseFile(getFilename(files[i]), root, false);\r
-            }\r
-        }\r
+        FpdParserTask fpdParser = new FpdParserTask();\r
+        fpdParser.setProject(getProject());\r
+        fpdParser.parseFpdFile(platformId.getFpdFile());\r
+        \r
         //\r
         //\r
-        // root.appendChild(parallelEle);\r
+        // Prepare for Platform related common properties\r
+        // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r
         //\r
         //\r
-        Iterator iter = sourceFiles.iterator();\r
-        String str = "";\r
-        while (iter.hasNext()) {\r
-            str += " " + (String) iter.next();\r
-        }\r
-        getProject().setProperty("SOURCE_FILES", str);\r
+        getProject().setProperty("PLATFORM", activePlatformName);\r
+        getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+        getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      Generate the section elements for BaseName_build.xml. Library module will\r
-      skip this process.  \r
-      \r
-      @param document current BaseName_build.xml XML document\r
-      @param root Root element for current\r
-    **/\r
-    private void applySectionsElement(Document document, Node root, FfsProcess fp) {\r
-        if (fp.initSections(buildType, getProject())) {\r
-            String targetFilename = guid + "-" + baseName + FpdParserTask.getSuffix(componentType);\r
-            String[] list = fp.getGenSectionElements(document, baseName, guid, targetFilename);\r
-\r
-            for (int i = 0; i < list.length; i++) {\r
-                Element ele = document.createElement(list[i]);\r
-                ele.setAttribute("FILEPATH", ".");\r
-                ele.setAttribute("FILENAME", "${BASE_NAME}");\r
-                root.appendChild(ele);\r
-            }\r
-        }\r
-    }\r
 \r
     /**\r
 \r
     /**\r
-      Generate the output elements for BaseName_build.xml. If module is library,\r
-      call the <em>LIB</em> command, else call the <em>GenFfs</em> command. \r
-      \r
-      @param document current BaseName_build.xml XML document\r
-      @param root Root element for current\r
+      Set Module-Related information to properties.\r
     **/\r
     **/\r
-    private void applyOutputElement(Document document, Node root, FfsProcess fp) {\r
-        if (flag == GlobalData.ONLY_LIBMSA || flag == GlobalData.LIBMSA_AND_LIBMBD) {\r
-            //\r
-            // call Lib command\r
-            //\r
-            Element cc = document.createElement("Build_Library");\r
-            cc.setAttribute("FILENAME", baseName);\r
-            root.appendChild(cc);\r
-        }\r
+    private void setModuleCommonProperties(String arch) {\r
         //\r
         //\r
-        // if it is a module but library\r
+        // Prepare for all other common properties\r
+        // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
         //\r
         //\r
+        PackageIdentification packageId = moduleId.getPackage();\r
+        getProject().setProperty("PACKAGE", packageId.getName());\r
+        getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r
+        getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r
+        getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r
+        getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r
+        \r
+        //\r
+        // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r
+        // MODULE_DIR, MODULE_RELATIVE_DIR\r
+        //\r
+        getProject().setProperty("MODULE", moduleId.getName());\r
+        String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
+        if (baseName == null) {\r
+            getProject().setProperty("BASE_NAME", moduleId.getName());\r
+        }\r
         else {\r
         else {\r
-            if (fp.getFfsNode() != null) {\r
-                root.appendChild(fp.getFfsNode());\r
+            getProject().setProperty("BASE_NAME", baseName);\r
+        }\r
+        getProject().setProperty("GUID", moduleId.getGuid());\r
+        getProject().setProperty("FILE_GUID", moduleId.getGuid());\r
+        getProject().setProperty("VERSION", moduleId.getVersion());\r
+        getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());\r
+        getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r
+        getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r
+        \r
+        //\r
+        // SUBSYSTEM\r
+        //\r
+        String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},\r
+                                    { "SEC", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "PEIM", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r
+                                    { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" }, \r
+                                    { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "TOOL", "EFI_BOOT_SERVICE_DRIVER" }, \r
+                                    { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
+                                    { "UEFI_APPLICATION", "EFI_APPLICATION" }, \r
+                                    { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} }; \r
+        \r
+        String subsystem = "EFI_BOOT_SERVICE_DRIVER";\r
+        for (int i = 0; i < subsystemMap.length; i++) {\r
+            if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {\r
+                subsystem = subsystemMap[i][1];\r
+                break ;\r
             }\r
         }\r
             }\r
         }\r
-    }\r
-\r
-    /**\r
-      Get file name from node. If some wrong, return string with zero length. \r
-      \r
-       @param node Filename node of MSA/MBD or specified in each Section\r
-       @return File name\r
-    **/\r
-    private String getFilename(Node node) {\r
-        String path = null;\r
-        String filename = "${MODULE_DIR}" + File.separatorChar;\r
-        String str = "";\r
-        try {\r
-            FilenameDocument file = (FilenameDocument) XmlObject.Factory.parse(node);\r
-            str = file.getFilename().getStringValue().trim();\r
-            path = file.getFilename().getPath();\r
-        } catch (Exception e) {\r
-            str = "";\r
-        }\r
-        if (path != null) {\r
-            filename += path + File.separatorChar + str;\r
-        } else {\r
-            filename += str;\r
-        }\r
-        return getProject().replaceProperties(filename);\r
-    }\r
-\r
-    /**\r
-      Get file type from node. If some wrong or not specified, return \r
-      <code>null</code>.  \r
-      \r
-      @param node Filename node of MSA/MBD or specified in each Section\r
-      @return File type\r
-    **/\r
-    private String getFiletype(Node node) {\r
-        String str = null;\r
-        try {\r
-            FilenameDocument file = (FilenameDocument) XmlObject.Factory.parse(node);\r
-            str = file.getFilename().getFileType();\r
-        } catch (Exception e) {\r
-            str = null;\r
-        }\r
-        return str;\r
-    }\r
-\r
-    /**\r
-      Return all source files but AutoGen.c.\r
-      \r
-      @return source files Node array\r
-    **/\r
-    public Node[] getSourceFiles() {\r
-        XmlObject[] files = SurfaceAreaQuery.getSourceFiles(arch);\r
-        if (files == null) {\r
-            return new Node[0];\r
+        getProject().setProperty("SUBSYSTEM", subsystem);\r
+        \r
+        //\r
+        // ENTRYPOINT\r
+        //\r
+        if (arch.equalsIgnoreCase("EBC")) {\r
+            getProject().setProperty("ENTRYPOINT", "EfiStart");\r
         }\r
         }\r
-        Vector<Node> vector = new Vector<Node>();\r
-        for (int i = 0; i < files.length; i++) {\r
-            vector.addElement(files[i].getDomNode());\r
+        else {\r
+            getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r
         }\r
         }\r
+        \r
         //\r
         //\r
-        // To be consider sourcefiles from Sections\r
+        // LIBS, OBJECTS, SDB_FILES\r
         //\r
         //\r
-        return vector.toArray(new Node[vector.size()]);\r
-    }\r
-\r
-    /**\r
-      Get current module's base name. \r
-      \r
-      @return base name\r
-    **/\r
-    public String getBaseName() {\r
-        return baseName;\r
-    }\r
-\r
-    /**\r
-      Set MBD surface area file. For ANT use.\r
-      \r
-      @param mbdFilename Surface Area file\r
-    **/\r
-    public void setMbdFilename(File mbdFilename) {\r
-        this.mbdFilename = mbdFilename;\r
-    }\r
-\r
-    /**\r
-      Set MSA surface area file. For ANT use.\r
-      \r
-      @param msaFilename Surface Area file\r
-    **/\r
-    public void setMsaFilename(File msaFilename) {\r
-        this.msaFilename = msaFilename;\r
+        getProject().setProperty("OBJECTS", "");\r
+        getProject().setProperty("SDB_FILES", "");\r
+        getProject().setProperty("LIBS", "");\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      Compile flags setup. \r
-      \r
-      <p> Take command <code>CC</code> and arch <code>IA32</code> for example, \r
-      Those flags are from <code>ToolChainFactory</code>: </p>\r
-      <ul>\r
-      <li> IA32_CC </li>\r
-      <li> IA32_CC_STD_FLAGS </li>\r
-      <li> IA32_CC_GLOBAL_FLAGS </li>\r
-      <li> IA32_CC_GLOBAL_ADD_FLAGS </li>\r
-      <li> IA32_CC_GLOBAL_SUB_FLAGS </li>\r
-      </ul>\r
-      Those flags can user-define: \r
-      <ul>\r
-      <li> IA32_CC_PROJ_FLAGS </li>\r
-      <li> IA32_CC_PROJ_ADD_FLAGS </li>\r
-      <li> IA32_CC_PROJ_SUB_FLAGS </li>\r
-      <li> CC_PROJ_FLAGS </li>\r
-      <li> CC_PROJ_ADD_FLAGS </li>\r
-      <li> CC_PROJ_SUB_FLAGS </li>\r
-      <li> CC_FLAGS </li>\r
-      <li> IA32_CC_FLAGS </li>\r
-      </ul>\r
-      \r
-      <p> The final flags is composed of STD, GLOBAL and PROJ. If CC_FLAGS or\r
-      IA32_CC_FLAGS is specified, STD, GLOBAL and PROJ will not affect. </p>\r
-      \r
-      Note that the <code>ToolChainFactory</code> executes only once \r
-      during whole build process. \r
-    **/\r
-    private void flagsSetup() {\r
-        Project project = getProject();\r
-        //\r
-        // If ToolChain has been set up before, do nothing.\r
-        //\r
-        ToolChainFactory toolChainFactory = new ToolChainFactory(project);\r
-        toolChainFactory.setupToolChain();\r
-\r
-        String[] cmd = ToolChainFactory.commandType;\r
-        Set<String> addSet = new HashSet<String>(40);\r
-        Set<String> subSet = new HashSet<String>(40);\r
-        for (int i = 0; i < cmd.length; i++) {\r
-            String str = ToolChainFactory.getValue(arch + "_" + cmd[i]);\r
+    private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {\r
+        String[] cmd = GlobalData.getToolChainInfo().getCommands();\r
+        for ( int m = 0; m < cmd.length; m++) {\r
             //\r
             //\r
-            // Command line path+command name\r
+            // Set cmd, like CC, DLINK\r
             //\r
             //\r
-            if (str != null) {\r
-                project.setProperty(cmd[i], str);\r
-            }\r
-            //\r
-            // ARCH_CMD_STD_FLAGS\r
-            //\r
-            str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_STD_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
-                project.setProperty(cmd[i] + "_STD_FLAGS", str);\r
-            }\r
-            //\r
-            // ARCH_CMD_GLOBAL_FLAGS\r
-            //\r
-            str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
-            }\r
-            //\r
-            // ARCH_CMD_GLOBAL_ADD_FLAGS\r
-            //\r
-            str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_ADD_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
-            }\r
-            //\r
-            // ARCH_CMD_GLOBAL_SUB_FLAGS\r
-            //\r
-            str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_SUB_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(subSet, str);\r
-            }\r
+            String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r
+            key[4] = "PATH";\r
+            String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r
+            key[4] = "NAME";\r
+            String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r
+            File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r
+//            GlobalData.log.info("PATH: " + cmdFile.getPath());\r
+            getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r
+            \r
             //\r
             //\r
-            // ARCH_CMD_PROJ_FLAGS\r
+            // set CC_FLAGS\r
             //\r
             //\r
-            str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
-            }\r
+            key[4] = "FLAGS";\r
+            String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r
+//            GlobalData.log.info("Flags: " + cmdFlags);\r
+            Set<String> addset = new LinkedHashSet<String>();\r
+            Set<String> subset = new LinkedHashSet<String>();\r
+            putFlagsToSet(addset, cmdFlags);\r
+            getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));\r
+            \r
             //\r
             //\r
-            // ARCH_CMD_PROG_FLAGS\r
+            // Set CC_EXT\r
             //\r
             //\r
-            str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_ADD_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
+            key[4] = "EXT";\r
+            String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r
+//            GlobalData.log.info("Ext: " + extName);\r
+            if ( extName != null && ! extName.equalsIgnoreCase("")) {\r
+                getProject().setProperty(cmd[m] + "_EXT", extName);\r
             }\r
             }\r
-            //\r
-            // ARCH_CMD_PROG_FLAGS\r
-            //\r
-            str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_SUB_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(subSet, str);\r
+            else {\r
+                getProject().setProperty(cmd[m] + "_EXT", "");\r
             }\r
             }\r
+            \r
             //\r
             //\r
-            // CMD_PROJ_FLAGS\r
+            // set CC_FAMILY\r
             //\r
             //\r
-            str = project.getProperty(cmd[i] + "_PROJ_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
+            key[4] = "FAMILY";\r
+            String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r
+//            GlobalData.log.info("FAMILY: " + toolChainFamily);\r
+            if (toolChainFamily != null) {\r
+                getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r
             }\r
             }\r
+            \r
             //\r
             //\r
-            // CMD_PROG_FLAGS\r
+            // set CC_SPATH\r
             //\r
             //\r
-            str = project.getProperty(cmd[i] + "_PROJ_ADD_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(addSet, str);\r
+            key[4] = "SPATH";\r
+            String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r
+//            GlobalData.log.info("SPATH: " + spath);\r
+            if (spath != null) {\r
+                getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r
             }\r
             }\r
-            //\r
-            // CMD_PROG_FLAGS\r
-            //\r
-            str = project.getProperty(cmd[i] + "_PROJ_SUB_FLAGS");\r
-            if (str != null) {\r
-                putFlagsToSet(subSet, str);\r
+            else {\r
+                getProject().setProperty(cmd[m] + "_SPATH", "");\r
             }\r
             }\r
+            \r
             //\r
             //\r
-            // If IA32_CC_FLAGS or IA32_LIB_FLAGS .. has defined in BuildOptions\r
+            // set CC_DPATH\r
             //\r
             //\r
-            if ((str = project.getProperty(arch + "_" + cmd[i] + "_FLAGS")) != null) {\r
-                project.setProperty(cmd[i] + "_FLAGS", getRawFlags(addSet, subSet));\r
-                addSet.clear();\r
-                subSet.clear();\r
-                putFlagsToSet(addSet, project.replaceProperties(str));\r
-                project.setProperty(cmd[i] + "_FLAGS", project.replaceProperties(getFlags(addSet, subSet)));\r
-                addSet.clear();\r
-                subSet.clear();\r
+            key[4] = "DPATH";\r
+            String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r
+//            GlobalData.log.info("DPATH: " + dpath);\r
+            if (dpath != null) {\r
+                getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r
             }\r
             }\r
-            //\r
-            // If CC_FLAGS or LIB_FLAGS .. has defined in BuildOptions\r
-            //\r
-            else if ((str = project.getProperty(cmd[i] + "_FLAGS")) != null) {\r
-                project.setProperty(cmd[i] + "_FLAGS", getRawFlags(addSet, subSet));\r
-                addSet.clear();\r
-                subSet.clear();\r
-                putFlagsToSet(addSet, project.replaceProperties(str));\r
-                project.setProperty(cmd[i] + "_FLAGS", project.replaceProperties(getFlags(addSet, subSet)));\r
-                addSet.clear();\r
-                subSet.clear();\r
-            } else {\r
-                project.setProperty(cmd[i] + "_FLAGS", getFlags(addSet, subSet));\r
-                addSet.clear();\r
-                subSet.clear();\r
+            else {\r
+                getProject().setProperty(cmd[m] + "_DPATH", "");\r
             }\r
         }\r
             }\r
         }\r
-        project.setProperty("C_FLAGS", project.getProperty("CC_FLAGS"));\r
+    }\r
+    \r
+    public void setMsaFile(File msaFile) {\r
+        this.msaFile = msaFile;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      Initialize some properties will be used in current module build, including\r
-      user-defined option from <em>Option</em> of <em>BuildOptions</em> in \r
-      surface area. \r
+      Method is for ANT to initialize MSA file. \r
+      \r
+      @param msaFilename MSA file name\r
     **/\r
     **/\r
-    private void updateParameters() {\r
-        getProject().setProperty("OBJECTS", "");\r
-        getProject().setProperty("SDB_FILES", "");\r
-        getProject().setProperty("BASE_NAME", baseName);\r
-        if (map.get("MsaHeader") != null) {\r
-            guid = SurfaceAreaQuery.getModuleGuid();//header.getGuid().getStringValue();\r
-            componentType = SurfaceAreaQuery.getComponentType();//header.getComponentType().toString();\r
-            if (!componentType.equalsIgnoreCase("LIBRARY")) {\r
-                flag = GlobalData.MSA_AND_MBD;\r
-            } else {\r
-                flag = GlobalData.LIBMSA_AND_LIBMBD;\r
-            }\r
-        } \r
+    public void setMsaFile(String msaFilename) {\r
+        String moduleDir = getProject().getProperty("MODULE_DIR");\r
         \r
         \r
-        else if (map.get("MsaLibHeader") != null) {\r
-            flag = GlobalData.LIBMSA_AND_LIBMBD;\r
-            MsaLibHeaderDocument.MsaLibHeader header = ((MsaLibHeaderDocument) map.get("MsaLibHeader"))\r
-                                                                                                       .getMsaLibHeader();\r
-            guid = header.getGuid().getStringValue();\r
-            componentType = header.getComponentType().toString();\r
+        //\r
+        // If is Single Module Build, then use the Base Dir defined in build.xml\r
+        //\r
+        if (moduleDir == null) {\r
+            moduleDir = getProject().getBaseDir().getPath();\r
         }\r
         }\r
+        msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r
+    }\r
+    \r
+    public void addConfiguredModuleItem(ModuleItem moduleItem) {\r
+        PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());\r
+        ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());\r
+        moduleId.setPackage(packageId);\r
+        this.moduleId = moduleId;\r
+    }\r
+    \r
+    /**\r
+      Add a property. \r
+    \r
+      @param p property\r
+    **/\r
+    public void addProperty(Property p) {\r
+        properties.addElement(p);\r
+    }\r
+\r
+    public void setType(String type) {\r
+        this.type = type;\r
+    }\r
+    \r
+    private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{\r
+        //\r
+        // AutoGen\r
+        //\r
+//        AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId);\r
+//        autogen.genAutogen();\r
+        \r
         \r
         \r
-        if (componentType != null) {\r
-            getProject().setProperty("COMPONENT_TYPE", componentType);\r
+        //\r
+        // Get compiler flags\r
+        //\r
+        getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r
+        \r
+        //\r
+        // Prepare LIBS\r
+        //\r
+        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
+        String propertyLibs = "";\r
+        for (int i = 0; i < libinstances.length; i++) {\r
+            propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";\r
         }\r
         }\r
-\r
-        if (guid != null) {\r
-            getProject().setProperty("FILE_GUID", guid);\r
+        getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
+        \r
+        //\r
+        // if it is CUSTOM_BUILD\r
+        // then call the exist BaseName_build.xml directly.\r
+        //\r
+        if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
+            GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
+            Ant ant = new Ant();\r
+            ant.setProject(getProject());\r
+            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
+            ant.setInheritAll(true);\r
+            ant.init();\r
+            ant.execute();\r
+            return ;\r
         }\r
         }\r
+        \r
         //\r
         //\r
-        // Get all options and set to properties\r
+        // Generate ${BASE_NAME}_build.xml\r
+        // TBD\r
         //\r
         //\r
-        String[][] options = SurfaceAreaQuery.getOptions(arch);\r
-        for (int i = 0; i < options.length; i++) {\r
-            if (options[i][0] != null && options[i][1] != null) {\r
-                getProject().setProperty(options[i][0], getProject().replaceProperties(options[i][1]));\r
-            }\r
+        String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();\r
+        ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);\r
+        String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+        fileGenerator.genBuildFile(buildFilename);\r
+        \r
+        //\r
+        // Ant call ${BASE_NAME}_build.xml\r
+        //\r
+        Ant ant = new Ant();\r
+        ant.setProject(getProject());\r
+        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
+        ant.setInheritAll(true);\r
+        ant.init();\r
+        ant.execute();\r
+    }\r
+    \r
+    private void applyClean(FpdModuleIdentification fpdModuleId){\r
+        //\r
+        // if it is CUSTOM_BUILD\r
+        // then call the exist BaseName_build.xml directly.\r
+        //\r
+        if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
+            GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
+            Ant ant = new Ant();\r
+            ant.setProject(getProject());\r
+            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
+            ant.setTarget("clean");\r
+            ant.setInheritAll(true);\r
+            ant.init();\r
+            ant.execute();\r
+            return ;\r
         }\r
         }\r
-\r
-        buildType = getProject().getProperty("BUILD_TYPE");\r
-        if (buildType == null) {\r
-            buildType = componentType;\r
+        \r
+        Ant ant = new Ant();\r
+        ant.setProject(getProject());\r
+        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
+        ant.setTarget("clean");\r
+        ant.setInheritAll(true);\r
+        ant.init();\r
+        ant.execute();\r
+        \r
+        //\r
+        // Delete current module's DEST_DIR_OUTPUT\r
+        // TBD\r
+    }\r
+    \r
+    private void applyCleanall(FpdModuleIdentification fpdModuleId){\r
+        //\r
+        // if it is CUSTOM_BUILD\r
+        // then call the exist BaseName_build.xml directly.\r
+        //\r
+        if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
+            GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
+            Ant ant = new Ant();\r
+            ant.setProject(getProject());\r
+            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
+            ant.setTarget("cleanall");\r
+            ant.setInheritAll(true);\r
+            ant.init();\r
+            ant.execute();\r
+            return ;\r
         }\r
         }\r
-\r
+        \r
+        Ant ant = new Ant();\r
+        ant.setProject(getProject());\r
+        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
+        ant.setTarget("cleanall");\r
+        ant.setInheritAll(true);\r
+        ant.init();\r
+        ant.execute();\r
+        \r
+        //\r
+        // Delete current module's DEST_DIR_OUTPUT\r
+        // TBD\r
     }\r
 \r
     }\r
 \r
+\r
+\r
+\r
     /**\r
       Separate the string and instore in set.\r
        \r
     /**\r
       Separate the string and instore in set.\r
        \r
@@ -1130,13 +658,15 @@ public class GenBuildTask extends Task {
       @param str string to separate\r
     **/\r
     private void putFlagsToSet(Set<String> set, String str) {\r
       @param str string to separate\r
     **/\r
     private void putFlagsToSet(Set<String> set, String str) {\r
+        if (str == null || str.length() == 0) {\r
+            return;\r
+        }\r
+\r
         Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");\r
         Matcher matcher = myPattern.matcher(str + " ");\r
         while (matcher.find()) {\r
             String item = str.substring(matcher.start(1), matcher.end(1));\r
         Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");\r
         Matcher matcher = myPattern.matcher(str + " ");\r
         while (matcher.find()) {\r
             String item = str.substring(matcher.start(1), matcher.end(1));\r
-            if (!set.contains(item)) {\r
-                set.add(item);\r
-            }\r
+            set.add(item);\r
         }\r
     }\r
     \r
         }\r
     }\r
     \r
@@ -1152,7 +682,7 @@ public class GenBuildTask extends Task {
         add.removeAll(sub);\r
         Iterator iter = add.iterator();\r
         while (iter.hasNext()) {\r
         add.removeAll(sub);\r
         Iterator iter = add.iterator();\r
         while (iter.hasNext()) {\r
-            String str = getProject().replaceProperties((String) iter.next());\r
+            String str = (String) iter.next();\r
             result += str.substring(1, str.length() - 1) + " ";\r
         }\r
         return result;\r
             result += str.substring(1, str.length() - 1) + " ";\r
         }\r
         return result;\r
@@ -1174,23 +704,55 @@ public class GenBuildTask extends Task {
       @return flags with original format\r
     **/\r
     private String getRawFlags(Set<String> add, Set<String> sub) {\r
       @return flags with original format\r
     **/\r
     private String getRawFlags(Set<String> add, Set<String> sub) {\r
-        String result = "";\r
+        String result = null;\r
         add.removeAll(sub);\r
         Iterator iter = add.iterator();\r
         while (iter.hasNext()) {\r
         add.removeAll(sub);\r
         Iterator iter = add.iterator();\r
         while (iter.hasNext()) {\r
-            String str = getProject().replaceProperties((String) iter.next());\r
+            String str = (String) iter.next();\r
             result += "\"" + str.substring(1, str.length() - 1) + "\", ";\r
         }\r
         return result;\r
     }\r
 \r
             result += "\"" + str.substring(1, str.length() - 1) + "\", ";\r
         }\r
         return result;\r
     }\r
 \r
-    /**\r
-      Set base name. For ANT use.\r
-      \r
-      @param baseName Base name\r
-    **/\r
-    public void setBaseName(String baseName) {\r
-        this.baseName = baseName;\r
-    }\r
+    private String parseOptionString(String optionString, Set<String> addSet, Set<String> subSet) {\r
+        boolean overrideOption = false;\r
+        Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]");\r
+        Matcher matcher = pattern.matcher(optionString);\r
+\r
+        while (matcher.find()) {\r
+            overrideOption = true;\r
+            String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r
+            putFlagsToSet(addSet, addOption);\r
+            \r
+        }\r
 \r
 \r
+        pattern = Pattern.compile("SUB\\.\\[(.+)\\]");\r
+        matcher = pattern.matcher(optionString);\r
+\r
+        while (matcher.find()) {\r
+            overrideOption = true;\r
+            String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r
+            putFlagsToSet(subSet, subOption);\r
+        }\r
+\r
+        if (overrideOption == true) {\r
+            return null;\r
+        }\r
+\r
+        return optionString;\r
+    }\r
+    \r
+    private void pushProperties() {\r
+        backupPropertiesStack.push(getProject().getProperties());\r
+    }\r
+    \r
+    private void popProperties() {\r
+        Hashtable backupProperties = backupPropertiesStack.pop();\r
+        Set keys = backupProperties.keySet();\r
+        Iterator iter = keys.iterator();\r
+        while (iter.hasNext()) {\r
+            String item = (String)iter.next();\r
+            getProject().setProperty(item, (String)backupProperties.get(item));\r
+        }\r
+    }\r
 }\r
 }\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java b/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java
new file mode 100644 (file)
index 0000000..4c6843e
--- /dev/null
@@ -0,0 +1,591 @@
+/** @file\r
\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ **/\r
+package org.tianocore.build;\r
+\r
+import java.io.File;\r
+import java.util.LinkedHashMap;\r
+import java.util.LinkedHashSet;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+import javax.xml.transform.OutputKeys;\r
+import javax.xml.transform.Result;\r
+import javax.xml.transform.Source;\r
+import javax.xml.transform.Transformer;\r
+import javax.xml.transform.TransformerFactory;\r
+import javax.xml.transform.dom.DOMSource;\r
+import javax.xml.transform.stream.StreamResult;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.Project;\r
+import org.tianocore.build.fpd.FpdParserTask;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
+import org.w3c.dom.Comment;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+\r
+public class ModuleBuildFileGenerator {\r
+\r
+    ///\r
+    /// Pass: TARGET, TOOLCHAIN, ARCH\r
+    /// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION\r
+    ///\r
+    String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM", "PACKAGE_GUID", "PACKAGE_VERSION"};\r
+\r
+    ///\r
+    /// The information at the header of <em>build.xml</em>.\r
+    ///\r
+    private String info = "DO NOT EDIT \n"\r
+                        + "File auto-generated by build utility\n"\r
+                        + "\n"\r
+                        + "Abstract:\n"\r
+                        + "Auto-generated ANT build file for building of EFI Modules/Platforms\n";\r
+\r
+    private FpdModuleIdentification fpdModuleId;\r
+    \r
+    private Project project;\r
+    \r
+    private String ffsKeyword;\r
+    \r
+    public ModuleBuildFileGenerator(Project project, String ffsKeyword, FpdModuleIdentification fpdModuleId) {\r
+        this.project = project;\r
+        this.fpdModuleId = fpdModuleId;\r
+        this.ffsKeyword = ffsKeyword;\r
+    }\r
+    \r
+    /**\r
+      The whole BaseName_build.xml is composed of seven part. \r
+      <ul>\r
+      <li> ANT properties; </li>\r
+      <li> Dependent module (dependent library instances in most case); </li>\r
+      <li> Source files; </li>\r
+      <li> Sections if module is not library; </li>\r
+      <li> Output (different for library module and driver module); </li>\r
+      <li> Clean; </li>\r
+      <li> Clean all. </li>\r
+      </ul>\r
+      \r
+      @throws BuildException\r
+              Error throws during BaseName_build.xml generating. \r
+    **/\r
+    public void genBuildFile(String buildFilename) throws BuildException {\r
+        FfsProcess fp = new FfsProcess();\r
+        DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
+        try {\r
+            DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
+            Document document = dombuilder.newDocument();\r
+            Comment rootComment = document.createComment(info);\r
+            \r
+            //\r
+            // create root element and its attributes\r
+            //\r
+            Element root = document.createElement("project");\r
+            root.setAttribute("name", fpdModuleId.getModule().getName());\r
+            root.setAttribute("default", "all");\r
+            root.setAttribute("basedir", ".");\r
+            \r
+            //\r
+            // element for External ANT tasks\r
+            //\r
+            root.appendChild(document.createComment("Apply external ANT tasks"));\r
+            Element ele = document.createElement("taskdef");\r
+            ele.setAttribute("resource", "frameworktasks.tasks");\r
+            root.appendChild(ele);\r
+            ele = document.createElement("taskdef");\r
+            ele.setAttribute("resource", "cpptasks.tasks");\r
+            root.appendChild(ele);\r
+            ele = document.createElement("typedef");\r
+            ele.setAttribute("resource", "cpptasks.types");\r
+            root.appendChild(ele);\r
+            ele = document.createElement("taskdef");\r
+            ele.setAttribute("resource", "net/sf/antcontrib/antlib.xml");\r
+            root.appendChild(ele);\r
+\r
+            //\r
+            // Generate the default target,\r
+            // which depends on init, sections and output target\r
+            //\r
+            root.appendChild(document.createComment("Default target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "all");\r
+            ele.setAttribute("depends", "libraries, sourcefiles, sections, output");\r
+            root.appendChild(ele);\r
+            \r
+            //\r
+            // compile all source files\r
+            //\r
+            root.appendChild(document.createComment("Compile all dependency Library instances."));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "libraries");\r
+\r
+            //\r
+            // Parse all sourfiles but files specified in sections\r
+            //\r
+            applyLibraryInstance(document, ele);\r
+            root.appendChild(ele);\r
+\r
+            //\r
+            // compile all source files\r
+            //\r
+            root.appendChild(document.createComment("sourcefiles target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "sourcefiles");\r
+            \r
+            //\r
+            // Parse all sourfiles but files specified in sections\r
+            //\r
+            applyCompileElement(document, ele);\r
+            root.appendChild(ele);\r
+\r
+            //\r
+            // generate the init target\r
+            // main purpose is create all nessary pathes\r
+            // generate the sections target\r
+            //\r
+            root.appendChild(document.createComment("sections target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "sections");\r
+            applySectionsElement(document, ele, fp);\r
+            root.appendChild(ele);\r
+\r
+            //\r
+            // generate the output target\r
+            //\r
+            root.appendChild(document.createComment("output target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "output");\r
+            applyOutputElement(document, ele, fp);\r
+            root.appendChild(ele);\r
+\r
+            \r
+            //\r
+            // generate the clean target\r
+            //\r
+            root.appendChild(document.createComment("clean target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "clean");\r
+            applyCleanElement(document, ele);\r
+            root.appendChild(ele);\r
+            \r
+            //\r
+            // generate the Clean All target\r
+            //\r
+            root.appendChild(document.createComment("Clean All target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "cleanall");\r
+            applyDeepcleanElement(document, ele);\r
+            root.appendChild(ele);\r
+            \r
+            //\r
+            // add the root element to the document\r
+            //\r
+            document.appendChild(rootComment);\r
+            document.appendChild(root);\r
+            //\r
+            // Prepare the DOM document for writing\r
+            //\r
+            Source source = new DOMSource(document);\r
+\r
+            //\r
+            // Prepare the output file\r
+            //\r
+            File file = new File(buildFilename);\r
+\r
+            //\r
+            // generate all directory path\r
+            //\r
+            (new File(file.getParent())).mkdirs();\r
+            Result result = new StreamResult(file);\r
+            \r
+            //\r
+            // Write the DOM document to the file\r
+            //\r
+            Transformer xformer = TransformerFactory.newInstance().newTransformer();\r
+            xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
+            xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
+            xformer.transform(source, result);\r
+        } catch (Exception ex) {\r
+            ex.printStackTrace();\r
+            throw new BuildException("Module [" + fpdModuleId.getModule().getName() + "] generating build file failed.\n" + ex.getMessage());\r
+        }\r
+    }\r
+\r
+    /**\r
+      Generate the clean elements for BaseName_build.xml. \r
+      \r
+      @param document current BaseName_build.xml XML document\r
+      @param root Root element for current\r
+    **/\r
+    private void applyCleanElement(Document document, Node root) {\r
+        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
+        for (int i = 0; i < libinstances.length; i++) {\r
+            //\r
+            // Put package file path to module identification\r
+            //\r
+            PackageIdentification packageId = libinstances[i].getPackage();\r
+            \r
+            //\r
+            // Generate ANT script to clean\r
+            //\r
+            Element ele = document.createElement("GenBuild");\r
+            ele.setAttribute("type", "clean");\r
+            \r
+            //\r
+            // Prepare pass down information\r
+            //\r
+            Map<String, String> passDownMap = new LinkedHashMap<String, String>();\r
+            for (int j = 0; j < inheritProperties.length; j ++){\r
+                passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}");\r
+            }\r
+            passDownMap.put("MODULE_GUID", libinstances[i].getGuid());\r
+            passDownMap.put("MODULE_VERSION", libinstances[i].getVersion());\r
+            \r
+            passDownMap.put("PACKAGE_GUID", packageId.getGuid());\r
+            passDownMap.put("PACKAGE_VERSION", packageId.getVersion());\r
+            \r
+            for (int j = 0; j < inheritProperties.length; j ++){\r
+                Element property = document.createElement("property");\r
+                property.setAttribute("name", inheritProperties[j]);\r
+                property.setAttribute("value", passDownMap.get(inheritProperties[j]));\r
+                ele.appendChild(property);\r
+            }\r
+\r
+            root.appendChild(ele);\r
+        }\r
+        //\r
+        // <delete includeemptydirs="true">\r
+        //   <fileset dir="${DEST_DIR_OUTPUT}" includes="" excludes="" />\r
+        // </delete>\r
+        //\r
+        Element deleteEle = document.createElement("delete");\r
+        deleteEle.setAttribute("includeemptydirs", "true");\r
+        Element filesetEle = document.createElement("fileset");\r
+        filesetEle.setAttribute("dir", "${DEST_DIR_OUTPUT}");\r
+        filesetEle.setAttribute("includes", "**/*");\r
+        filesetEle.setAttribute("excludes", "*.xml");\r
+        deleteEle.appendChild(filesetEle);\r
+        root.appendChild(deleteEle);\r
+    }\r
+\r
+    /**\r
+      Generate the cleanall elements for BaseName_build.xml. \r
+      \r
+      @param document current BaseName_build.xml XML document\r
+      @param root Root element for current\r
+    **/\r
+    private void applyDeepcleanElement(Document document, Node root) {\r
+        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
+        for (int i = 0; i < libinstances.length; i++) {\r
+            //\r
+            // Put package file path to module identification\r
+            //\r
+            PackageIdentification packageId = libinstances[i].getPackage();\r
+            \r
+            //\r
+            // Generate ANT script to clean\r
+            //\r
+            Element ele = document.createElement("GenBuild");\r
+            ele.setAttribute("type", "cleanall");\r
+            \r
+            //\r
+            // Prepare pass down information\r
+            //\r
+            Map<String, String> passDownMap = new LinkedHashMap<String, String>();\r
+            for (int j = 0; j < inheritProperties.length; j ++){\r
+                passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}");\r
+            }\r
+            \r
+            passDownMap.put("MODULE_GUID", libinstances[i].getGuid());\r
+            passDownMap.put("MODULE_VERSION", libinstances[i].getVersion());\r
+            \r
+            passDownMap.put("PACKAGE_GUID", packageId.getGuid());\r
+            passDownMap.put("PACKAGE_VERSION", packageId.getVersion());\r
+            \r
+            for (int j = 0; j < inheritProperties.length; j ++){\r
+                Element property = document.createElement("property");\r
+                property.setAttribute("name", inheritProperties[j]);\r
+                property.setAttribute("value", passDownMap.get(inheritProperties[j]));\r
+                ele.appendChild(property);\r
+            }\r
+\r
+            root.appendChild(ele);\r
+        }\r
+        //\r
+        // <delete includeemptydirs="true">\r
+        //   <fileset dir="${DEST_DIR_OUTPUT}" includes="" excludes="" />\r
+        // </delete>\r
+        //\r
+        Element deleteEle = document.createElement("delete");\r
+        deleteEle.setAttribute("includeemptydirs", "true");\r
+        Element filesetEle = document.createElement("fileset");\r
+        filesetEle.setAttribute("dir", "${DEST_DIR_OUTPUT}");\r
+        filesetEle.setAttribute("includes", "**/*");\r
+        filesetEle.setAttribute("excludes", "*.xml");\r
+        deleteEle.appendChild(filesetEle);\r
+        root.appendChild(deleteEle);\r
+        \r
+        //\r
+        // <delete includeemptydirs="true">\r
+        //   <fileset dir="${DEST_DIR_DEBUG}" includes="" />\r
+        // </delete>\r
+        //\r
+        deleteEle = document.createElement("delete");\r
+        deleteEle.setAttribute("includeemptydirs", "true");\r
+        filesetEle = document.createElement("fileset");\r
+        filesetEle.setAttribute("dir", "${DEST_DIR_DEBUG}");\r
+        filesetEle.setAttribute("includes", "**/*");\r
+        deleteEle.appendChild(filesetEle);\r
+        root.appendChild(deleteEle);\r
+    }\r
+\r
+    /**\r
+      Generate the dependent library instances elements for BaseName_build.xml. \r
+      \r
+      @param document current BaseName_build.xml XML document\r
+      @param root Root element for current\r
+    **/\r
+    private void applyLibraryInstance(Document document, Node root) {\r
+        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
+//        String propertyLibs = "";\r
+        for (int i = 0; i < libinstances.length; i++) {\r
+            //\r
+            // Put package file path to module identification\r
+            //\r
+            PackageIdentification packageId = libinstances[i].getPackage();\r
+            \r
+            //\r
+            // Generate ANT script to build library instances\r
+            //\r
+            Element ele = document.createElement("GenBuild");\r
+            ele.setAttribute("type", "build");\r
+//            ele.setAttribute("inheritAll", "false");\r
+            \r
+            //\r
+            // Prepare pass down information\r
+            //\r
+            Map<String, String> passDownMap = new LinkedHashMap<String, String>();\r
+            for (int j = 0; j < inheritProperties.length; j ++){\r
+                passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}");\r
+            }\r
+            \r
+            passDownMap.put("MODULE_GUID", libinstances[i].getGuid());\r
+            passDownMap.put("MODULE_VERSION", libinstances[i].getVersion());\r
+            \r
+            passDownMap.put("PACKAGE_GUID", packageId.getGuid());\r
+            passDownMap.put("PACKAGE_VERSION", packageId.getVersion());\r
+            \r
+            for (int j = 0; j < inheritProperties.length; j ++){\r
+                Element property = document.createElement("property");\r
+                property.setAttribute("name", inheritProperties[j]);\r
+                property.setAttribute("value", passDownMap.get(inheritProperties[j]));\r
+                ele.appendChild(property);\r
+            }\r
+            \r
+            root.appendChild(ele);\r
+//            propertyLibs += " " + project.getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";\r
+        }\r
+//        project.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
+    }\r
+    \r
+    /**\r
+      Generate the build source files elements for BaseName_build.xml. \r
+      \r
+      @param document current BaseName_build.xml XML document\r
+      @param root Root element for current\r
+    **/\r
+    private void applyCompileElement(Document document, Node root) {\r
+        //\r
+        // Prepare the includes: PackageDependencies and Output debug direactory\r
+        //\r
+        Set<String> includes = new LinkedHashSet<String>();\r
+        \r
+        //\r
+        // WORKSPACE\r
+        //\r
+        includes.add("${WORKSPACE_DIR}");\r
+        \r
+        //\r
+        // Module iteself\r
+        //\r
+        includes.add("${MODULE_DIR}");\r
+        includes.add("${MODULE_DIR}" + File.separatorChar + "${ARCH}");\r
+        \r
+        //\r
+        // Packages in PackageDenpendencies\r
+        //\r
+        PackageIdentification[] packageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch());\r
+        for (int i = 0; i < packageDependencies.length; i++) {\r
+            GlobalData.refreshPackageIdentification(packageDependencies[i]);\r
+            File packageFile = packageDependencies[i].getSpdFile();\r
+            includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
+            includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
+        }\r
+\r
+        //\r
+        // All Dependency Library Instance's PackageDependencies\r
+        //\r
+        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
+        for (int i = 0; i < libinstances.length; i++) {\r
+            SurfaceAreaQuery.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch()));\r
+            PackageIdentification[] libraryPackageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch());\r
+            for (int j = 0; j < libraryPackageDependencies.length; j++) {\r
+                GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);\r
+                File packageFile = libraryPackageDependencies[j].getSpdFile();\r
+                includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
+                includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
+            }\r
+            SurfaceAreaQuery.pop();\r
+        }\r
+        \r
+        \r
+        //\r
+        // The package which the module belongs to\r
+        // TBD\r
+        includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");\r
+        includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
+\r
+        //\r
+        // Debug files output directory\r
+        //\r
+        includes.add("${DEST_DIR_DEBUG}");\r
+        \r
+        //\r
+        // sourceFiles[][0] is FileType, [][1] is File name relative to Module_Dir\r
+        //\r
+        String[][] sourceFiles = SurfaceAreaQuery.getSourceFiles(fpdModuleId.getArch());\r
+\r
+        FileProcess fileProcess = new FileProcess();\r
+        fileProcess.init(project, includes, document);\r
+\r
+        String moduleDir = project.getProperty("MODULE_DIR");\r
+        //\r
+        // Parse all Unicode files\r
+        //\r
+        for (int i = 0; i < sourceFiles.length; i++) {\r
+            //\r
+            // Go through all source files. Add MODULE_DIR to preffix\r
+            //\r
+            File sourceFile =  new File(moduleDir + File.separatorChar + sourceFiles[i][1]);\r
+            sourceFiles[i][1] = sourceFile.getPath();\r
+            String filetype = sourceFiles[i][0];\r
+            if (filetype != null) {\r
+                fileProcess.parseFile(sourceFiles[i][1], filetype, root, true);\r
+            } else {\r
+                fileProcess.parseFile(sourceFiles[i][1], root, true);\r
+            }\r
+        }\r
+        \r
+        //\r
+        // If exist Unicode file\r
+        //\r
+        if (fileProcess.isUnicodeExist()) {\r
+            Element ele = document.createElement("Build_Unicode_Database");\r
+            ele.setAttribute("FILEPATH", ".");\r
+            ele.setAttribute("FILENAME", "${BASE_NAME}");\r
+            String[] includePaths = includes.toArray(new String[includes.size()]);\r
+            Element includesEle = document.createElement("EXTRA.INC");\r
+            for (int i = 0; i < includePaths.length; i++) {\r
+                Element includeEle = document.createElement("includepath");\r
+                includeEle.setAttribute("path", includePaths[i]);\r
+                includesEle.appendChild(includeEle);\r
+            }\r
+            ele.appendChild(includesEle);\r
+            root.appendChild(ele);\r
+        }\r
+\r
+        //\r
+        // Parse AutoGen.c & AutoGen.h\r
+        //\r
+        if ( ! fpdModuleId.getModule().getName().equalsIgnoreCase("Shell")) {\r
+            fileProcess.parseFile(project.getProperty("DEST_DIR_DEBUG") + File.separatorChar + "AutoGen.c", root, false);\r
+        }\r
+        \r
+        //\r
+        // Parse all source files but Unicode files\r
+        //\r
+        for (int i = 0; i < sourceFiles.length; i++) {\r
+            String filetype = sourceFiles[i][0];\r
+            if (filetype != null) {\r
+                fileProcess.parseFile(sourceFiles[i][1], filetype, root, false);\r
+            } else {\r
+                fileProcess.parseFile(sourceFiles[i][1], root, false);\r
+            }\r
+        }\r
+        \r
+        //\r
+        // Initialize SOURCE_FILES for dependcy check use\r
+        //\r
+        String str = "";\r
+        for (int i = 0; i < sourceFiles.length; i++) {\r
+            str += " " + sourceFiles[i][1];\r
+        }\r
+        project.setProperty("SOURCE_FILES", str.replaceAll("(\\\\)", "/"));\r
+    }\r
+\r
+    /**\r
+      Generate the section elements for BaseName_build.xml. Library module will\r
+      skip this process.  \r
+      \r
+      @param document current BaseName_build.xml XML document\r
+      @param root Root element for current\r
+    **/\r
+    private void applySectionsElement(Document document, Node root, FfsProcess fp) {\r
+        if (fpdModuleId.getModule().isLibrary()) {\r
+            return ;\r
+        }\r
+        if (fp.initSections(ffsKeyword, project, fpdModuleId)) {\r
+            String targetFilename = fpdModuleId.getModule().getGuid() + "-" + fpdModuleId.getModule().getName() + FpdParserTask.getSuffix(fpdModuleId.getModule().getModuleType());\r
+            String[] list = fp.getGenSectionElements(document, "${BASE_NAME}", fpdModuleId.getModule().getGuid(), targetFilename);\r
+\r
+            for (int i = 0; i < list.length; i++) {\r
+                Element ele = document.createElement(list[i]);\r
+                ele.setAttribute("FILEPATH", ".");\r
+                ele.setAttribute("FILENAME", "${BASE_NAME}");\r
+                root.appendChild(ele);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+      Generate the output elements for BaseName_build.xml. If module is library,\r
+      call the <em>LIB</em> command, else call the <em>GenFfs</em> command. \r
+      \r
+      @param document current BaseName_build.xml XML document\r
+      @param root Root element for current\r
+    **/\r
+    private void applyOutputElement(Document document, Node root, FfsProcess fp) {\r
+        if (fpdModuleId.getModule().isLibrary()) {\r
+            //\r
+            // call Lib command\r
+            //\r
+            Element cc = document.createElement("Build_Library");\r
+            cc.setAttribute("FILENAME", fpdModuleId.getModule().getName());\r
+            root.appendChild(cc);\r
+        }\r
+        //\r
+        // if it is a module but library\r
+        //\r
+        else {\r
+            if (fp.getFfsNode() != null) {\r
+                root.appendChild(fp.getFfsNode());\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/OutputDirSetup.java b/Tools/Source/GenBuild/org/tianocore/build/OutputDirSetup.java
new file mode 100644 (file)
index 0000000..6a53fa6
--- /dev/null
@@ -0,0 +1,271 @@
+package org.tianocore.build;\r
+\r
+import java.io.File;\r
+import java.util.Map;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.Task;\r
+import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.build.fpd.FpdParserTask;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.global.OutputManager;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
+import org.tianocore.build.id.PlatformIdentification;\r
+\r
+public class OutputDirSetup extends Task {\r
+    ///\r
+    /// Module surface area file.\r
+    ///\r
+    File msaFile;\r
+\r
+    ///\r
+    /// Module's Identification.\r
+    ///\r
+    private ModuleIdentification moduleId;\r
+    \r
+    ///\r
+    /// Module's component type, such as SEC, LIBRARY, BS_DRIVER and so on.\r
+    ///\r
+    private String componentType;\r
+    \r
+//    private ToolChainFactory toolChainFactory;\r
+    \r
+    /**\r
+      Public construct method. It is necessary for ANT task.\r
+    **/\r
+    public OutputDirSetup() {\r
+    }\r
+  \r
+    public void execute() throws BuildException {\r
+        //\r
+        // Global Data initialization\r
+        //\r
+//        GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",\r
+//                            getProject().getProperty("WORKSPACE_DIR"));\r
+      \r
+        //\r
+        // Parse MSA and get the basic information\r
+        // Including BaseName, GUID, Version, ComponentType and SupportedArchs\r
+        //\r
+        Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r
+        \r
+        SurfaceAreaQuery.setDoc(doc);\r
+      \r
+        //\r
+        // String[]: {BaseName, ModuleType, ComponentType, Guid, Version}\r
+        //\r
+        moduleId = SurfaceAreaQuery.getMsaHeader();\r
+        // REMOVE!!! TBD\r
+        componentType = "APPLICATION";\r
+      \r
+        //\r
+        // Judge whether it is single module build or not\r
+        //\r
+        if (getProject().getProperty("PLATFORM") == null) {\r
+            //\r
+            // Single Module build\r
+            //\r
+            prepareSingleModuleBuild();\r
+        }\r
+        else {\r
+            //\r
+            // Platform build\r
+            //\r
+            String platformName = getProject().getProperty("PLATFORM");\r
+            PlatformIdentification platformId = GlobalData.getPlatform(platformName);\r
+            getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+            getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
+          \r
+            String packageName = getProject().getProperty("PACKAGE");\r
+            String packageGuid = getProject().getProperty("PACKAGE_GUID");\r
+            String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r
+            PackageIdentification packageId = new PackageIdentification(packageName, packageGuid, packageVersion);\r
+            moduleId.setPackage(packageId);\r
+        }\r
+        \r
+        //\r
+        // Tools Definition file parse\r
+        //\r
+        parseToolsDefinitionFile();\r
+        \r
+        //\r
+        // For Every TOOLCHAIN, TARGET, ARCH\r
+        //\r
+//        String[] targetList = GlobalData.getTargets();\r
+//        for (int i = 0; i < targetList.length; i ++){\r
+//            //\r
+//            // Prepare for target related common properties\r
+//            // TARGET\r
+//            //\r
+//            getProject().setProperty("TARGET", targetList[i]);\r
+//            String[] toolchainList = GlobalData.getToolChains();\r
+//            for(int j = 0; j < toolchainList.length; j ++){\r
+//                //\r
+//                // Prepare for toolchain related common properties\r
+//                // TOOLCHAIN\r
+//                //\r
+//                getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r
+//                //\r
+//                // If single module : intersection MSA supported ARCHs and tools def!!\r
+//                // else, get arch from pass down\r
+//                //\r
+//                String[] archList = GlobalData.getArchs();\r
+//                for (int k = 0; k < archList.length; k++) {\r
+//                    \r
+//                    FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r
+//                    \r
+//                    SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));\r
+//                    \r
+//                    //\r
+//                    // Prepare for all other common properties\r
+//                    // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
+//                    // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, COMPONENT_TYPE\r
+//                    // MODULE_DIR, MODULE_RELATIVE_DIR\r
+//                    // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r
+//                    // LIBS, OBJECTS, SDB_FILES\r
+//                    //\r
+//                    getProject().setProperty("ARCH", archList[k]);\r
+//                    setModuleCommonProperties();\r
+//        \r
+//                    //\r
+//                    // String[0] is build mode. String[1] is user-defined output dir. \r
+//                    //\r
+//                    String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r
+//                    String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r
+//                    \r
+//                    //\r
+//                    // OutputManage prepare for \r
+//                    // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r
+//                    //\r
+//                    OutputManager.getInstance().update(getProject(), userDefinedOutputDir, buildMode);\r
+//                    \r
+//                }\r
+//            }\r
+//        }\r
+        \r
+    }\r
+    \r
+    private void prepareSingleModuleBuild(){\r
+        //\r
+        // Find out the package which the module belongs to\r
+        // TBD: Enhance it!!!!\r
+        //\r
+        PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r
+        \r
+        moduleId.setPackage(packageId);\r
+        \r
+        //\r
+        // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r
+        //\r
+        String activePlatformName = getProject().getProperty("env.ACTIVE_PLATFORM");\r
+        \r
+        PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);\r
+        \r
+        //\r
+        // Read FPD file\r
+        //\r
+        FpdParserTask fpdParser = new FpdParserTask();\r
+        fpdParser.parseFpdFile(platformId.getFpdFile());\r
+        \r
+        //\r
+        // Prepare for Platform related common properties\r
+        // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r
+        //\r
+        getProject().setProperty("PLATFORM", activePlatformName);\r
+        getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+        getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
+    }\r
+    \r
+\r
+\r
+    /**\r
+\r
+    **/\r
+    private void setModuleCommonProperties() {\r
+        //\r
+        // Prepare for all other common properties\r
+        // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
+        //\r
+        PackageIdentification packageId = moduleId.getPackage();\r
+        getProject().setProperty("PACKAGE", packageId.getName());\r
+        getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r
+        getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r
+        GlobalData.log.info("" + packageId);\r
+        getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r
+        getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r
+        \r
+        //\r
+        // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, COMPONENT_TYPE\r
+        // MODULE_DIR, MODULE_RELATIVE_DIR\r
+        //\r
+        getProject().setProperty("MODULE", moduleId.getName());\r
+        getProject().setProperty("BASE_NAME", moduleId.getName());\r
+        getProject().setProperty("GUID", moduleId.getGuid());\r
+        getProject().setProperty("FILE_GUID", moduleId.getGuid());\r
+        getProject().setProperty("VERSION", moduleId.getVersion());\r
+        getProject().setProperty("COMPONENT_TYPE", componentType);\r
+        getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r
+        getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r
+    }\r
+    \r
+\r
+    /**\r
+      Method is for ANT use to initialize MSA file.\r
+      \r
+      @param msaFilename MSA file name\r
+    **/\r
+    public void setMsaFile(String msaFilename) {\r
+        String moduleDir = getProject().getProperty("MODULE_DIR");\r
+        if (moduleDir == null) {\r
+            moduleDir = getProject().getBaseDir().getPath();\r
+        }\r
+        msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r
+    }\r
+\r
+    /**\r
+      Compile flags setup. \r
+      \r
+      <p> Take command <code>CC</code> and arch <code>IA32</code> for example, \r
+      Those flags are from <code>ToolChainFactory</code>: </p>\r
+      <ul>\r
+      <li> IA32_CC </li>\r
+      <li> IA32_CC_STD_FLAGS </li>\r
+      <li> IA32_CC_GLOBAL_FLAGS </li>\r
+      <li> IA32_CC_GLOBAL_ADD_FLAGS </li>\r
+      <li> IA32_CC_GLOBAL_SUB_FLAGS </li>\r
+      </ul>\r
+      Those flags can user-define: \r
+      <ul>\r
+      <li> IA32_CC_PROJ_FLAGS </li>\r
+      <li> IA32_CC_PROJ_ADD_FLAGS </li>\r
+      <li> IA32_CC_PROJ_SUB_FLAGS </li>\r
+      <li> CC_PROJ_FLAGS </li>\r
+      <li> CC_PROJ_ADD_FLAGS </li>\r
+      <li> CC_PROJ_SUB_FLAGS </li>\r
+      <li> CC_FLAGS </li>\r
+      <li> IA32_CC_FLAGS </li>\r
+      </ul>\r
+      \r
+      <p> The final flags is composed of STD, GLOBAL and PROJ. If CC_FLAGS or\r
+      IA32_CC_FLAGS is specified, STD, GLOBAL and PROJ will not affect. </p>\r
+      \r
+      Note that the <code>ToolChainFactory</code> executes only once \r
+      during whole build process. \r
+    **/\r
+    private void parseToolsDefinitionFile() {\r
+        //\r
+        // If ToolChain has been set up before, do nothing.\r
+        // CONF dir + tools definition file name\r
+        //\r
+        String confDir = GlobalData.getWorkspacePath() + File.separatorChar + "Tools" + File.separatorChar + "Conf";\r
+        String toolsDefFilename = "tools_def.txt";\r
+        if (getProject().getProperty("env.TOOLS_DEF") != null) {\r
+            toolsDefFilename = getProject().getProperty("env.TOOLS_DEF");\r
+        }\r
+//        toolChainFactory = new ToolChainFactory(confDir, toolsDefFilename);\r
+//        toolChainFactory.setupToolChain();\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/OutputDirSetupTask.java b/Tools/Source/GenBuild/org/tianocore/build/OutputDirSetupTask.java
deleted file mode 100644 (file)
index c2b7cc9..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/** @file\r
-  \r
-  This file is an ANT task OutputDirSetupTask. \r
-  \r
-  This task main purpose is to setup some necessary properties for Package,\r
-  Platform or Module clean. \r
\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-package org.tianocore.build;\r
-\r
-import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Task;\r
-import org.apache.xmlbeans.XmlObject;\r
-\r
-import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.OutputManager;\r
-import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.toolchain.ToolChainFactory;\r
-\r
-/**\r
-  <code>OutputDirSetupTask</code> is an ANT task that can be used in ANT build\r
-  system. The main function of this task is to initialize some basic information\r
-  for Package|Platform|Module clean or cleanall usage. \r
-  \r
-  <p>Here is an example: </p> \r
-  <pre>\r
-     &lt;OutputDirSetup baseName="HelloWorld" \r
-                     mbdFilename="${MODULE_DIR}\HelloWorld.mbd" \r
-                     msaFilename="${MODULE_DIR}\HelloWorld.msa" /&gt;\r
-  </pre>\r
-  \r
-  <p>Note that all this task doing is part of GenBuildTask. </p>\r
-  \r
-  @since GenBuild 1.0\r
-  @see org.tianocore.build.GenBuildTask\r
-**/\r
-public class OutputDirSetupTask extends Task {\r
-    \r
-    ///\r
-    /// Module surface area file.\r
-    ///\r
-    File msaFilename;\r
-\r
-    ///\r
-    /// Module build description file.\r
-    ///\r
-    File mbdFilename;\r
-    \r
-    ///\r
-    /// Module surface area information after overrided.\r
-    ///\r
-    public Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-    \r
-    ///\r
-    /// Module's base name.\r
-    ///\r
-    private String baseName;\r
-    \r
-    /**\r
-      Public construct method. It is necessary for ANT task.\r
-    **/\r
-    public OutputDirSetupTask () {\r
-    }\r
-    \r
-    /**\r
-      ANT task's entry point, will be called after init(). The main steps is described\r
-      as following: \r
-      <ul>\r
-      <li> Judge current build mode (MODULE | PACKAGE | PLATFORM). This step will execute\r
-      only once in whole build process; </li>\r
-      <li> Initialize global information (Framework DB, SPD files and all MSA files \r
-      listed in SPD). This step will execute only once in whole build process; </li>\r
-      <li> Restore some important ANT property. If current build is single module \r
-      build, here will set many default values; </li>\r
-      <li> Get the current module's overridded surface area information from \r
-      global data; </li> \r
-      <li> Set up the output directories, including BIN_DIR, DEST_DIR_OUTPUT and\r
-      DEST_DIR_DEBUG; </li>\r
-      </ul>\r
-      \r
-      @throws BuildException\r
-              From module build, exception from module surface area invalid.\r
-    **/\r
-    public void execute() throws BuildException {\r
-        System.out.println("Deleting module [" + baseName + "] start.");\r
-        OutputManager.update(getProject());\r
-        GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db", getProject()\r
-                        .getProperty("WORKSPACE_DIR"));\r
-        recallFixedProperties();\r
-        map = GlobalData.getDoc(baseName);\r
-        //\r
-        // Initialize SurfaceAreaQuery\r
-        //\r
-        SurfaceAreaQuery.setDoc(map);\r
-        //\r
-        // Setup Output Management\r
-        //\r
-        String[] outdir = SurfaceAreaQuery.getOutputDirectory();\r
-        OutputManager.update(getProject(), outdir[1], outdir[0]);\r
-    }\r
-    \r
-    /**\r
-      Get current module's base name. \r
-      \r
-      @return base name\r
-    **/\r
-    public String getBaseName() {\r
-        return baseName;\r
-    }\r
-\r
-    /**\r
-      Set base name. For ANT use.\r
-      \r
-      @param baseName Base name\r
-    **/\r
-    public void setBaseName(String baseName) {\r
-        this.baseName = baseName;\r
-    }\r
-\r
-    /**\r
-      Set MBD surface area file. For ANT use.\r
-      \r
-      @param mbdFilename Surface Area file\r
-    **/\r
-    public void setMbdFilename(File mbdFilename) {\r
-        this.mbdFilename = mbdFilename;\r
-    }\r
-\r
-    /**\r
-      Set MSA surface area file. For ANT use.\r
-      \r
-      @param msaFilename Surface Area file\r
-    **/\r
-    public void setMsaFilename(File msaFilename) {\r
-        this.msaFilename = msaFilename;\r
-    }\r
-    \r
-    /**\r
-      Restore some important ANT property. If current build is single module \r
-      build, here will set many default values.\r
-      \r
-      <p> If current build is single module build, then the default <code>ARCH</code>\r
-      is <code>IA32</code>. Also set up the properties <code>PACKAGE</code>, \r
-      <code>PACKAGE_DIR</code>, <code>TARGET</code> and <code>MODULE_DIR</code></p>\r
-      \r
-      <p> Note that for package build, package name is stored in <code>PLATFORM</code>\r
-      and package directory is stored in <code>PLATFORM_DIR</code>. </p> \r
-     \r
-      @see org.tianocore.build.global.OutputManager\r
-    **/\r
-    private void recallFixedProperties(){\r
-        //\r
-        // If build is for module build\r
-        //\r
-        if (getProject().getProperty("PACKAGE_DIR") == null) {\r
-            ToolChainFactory toolChainFactory = new ToolChainFactory(getProject());\r
-            toolChainFactory.setupToolChain();\r
-            //\r
-            // PACKAGE PACKAGE_DIR ARCH (Default) COMMON_FILE BUILD_MACRO\r
-            //\r
-            if (getProject().getProperty("ARCH") == null){\r
-                getProject().setProperty("ARCH", "IA32");\r
-            }\r
-            String packageName = GlobalData.getPackageNameForModule(baseName);\r
-            getProject().setProperty("PACKAGE", packageName);\r
-            String packageDir = GlobalData.getPackagePath(packageName);\r
-            getProject().setProperty("PACKAGE_DIR", getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + packageDir);\r
-            getProject().setProperty("TARGET", toolChainFactory.getCurrentTarget());\r
-            getProject().setProperty("MODULE_DIR", getProject().replaceProperties(getProject().getProperty("MODULE_DIR")));\r
-        }\r
-        if (OutputManager.PLATFORM != null) {\r
-            getProject().setProperty("PLATFORM", OutputManager.PLATFORM);\r
-        }\r
-        if (OutputManager.PLATFORM_DIR != null) {\r
-            getProject().setProperty("PLATFORM_DIR", OutputManager.PLATFORM_DIR);\r
-        }\r
-    }\r
-}\r
index 1b9c5a0e4a77de4f5a1dcb9731c3f1824edc7747..95875544b3592f9d5bb598dd771c5020fcc417b2 100644 (file)
@@ -20,12 +20,14 @@ package org.tianocore.build.autogen;
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.Spd;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.Spd;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.GuidsDocument;\r
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.ProtocolsDocument;\r
 import org.tianocore.GuidsDocument;\r
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.ProtocolsDocument;\r
-import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
-\r
+//import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
+import org.tianocore.build.exception.*;\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
@@ -33,78 +35,86 @@ import java.io.File;
 import java.io.FileReader;\r
 import java.io.FileWriter;\r
 import java.util.ArrayList;\r
 import java.io.FileReader;\r
 import java.io.FileWriter;\r
 import java.util.ArrayList;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.List;\r
 import java.util.Map;\r
+import java.util.Set;\r
 \r
 /**\r
 \r
 /**\r
-  This class is to generate Autogen.h and Autogen.c according to module surface\r
-  area or library surface area.\r
-**/\r
* This class is to generate Autogen.h and Autogen.c according to module surface\r
* area or library surface area.\r
+ */\r
 public class AutoGen {\r
 public class AutoGen {\r
-    ///\r
-    /// The output path of Autogen.h and Autogen.c\r
-    ///\r
+    // /\r
+    // / The output path of Autogen.h and Autogen.c\r
+    // /\r
     private String outputPath;\r
 \r
     private String outputPath;\r
 \r
-    ///\r
-    /// The base name of module or library.\r
-    ///\r
-    private String baseName;\r
+    // /\r
+    // / The base name of module or library.\r
+    // /\r
+    private ModuleIdentification moduleId;\r
 \r
 \r
-    ///\r
-    /// The build architecture\r
-    ///\r
+    // /\r
+    // / The build architecture\r
+    // /\r
     private String arch;\r
 \r
     private String arch;\r
 \r
-    ///\r
-    /// PcdAutogen instance which is used to manage how to generate the PCD\r
-    /// information.\r
-    ///\r
-    private PCDAutoGenAction myPcdAutogen;\r
-\r
-    ///\r
-    /// The protocl list which records in module or library surface area and\r
-    /// it's dependence on library instance surface area.\r
-    ///\r
-    private List<String> mProtocolList = new ArrayList<String>();\r
-\r
-    ///\r
-    /// The Ppi list which recorded in module or library surface area and its\r
-    /// dependency on library instance surface area.\r
-    ///\r
-    private List<String> mPpiList = new ArrayList<String>();\r
-\r
-    ///\r
-    /// The Guid list which recoreded in module or library surface are and it's\r
-    /// dependence on library instance surface area.\r
-    ///\r
-    private List<GuidsDocument.Guids.GuidEntry> mGuidList = new ArrayList<GuidsDocument.Guids.GuidEntry>();\r
+    // /\r
+    // / PcdAutogen instance which is used to manage how to generate the PCD\r
+    // / information.\r
+    // /\r
+//    private PCDAutoGenAction myPcdAutogen;\r
+\r
+    // /\r
+    // / The protocl list which records in module or library surface area and\r
+    // / it's dependence on library instance surface area.\r
+    // /\r
+    private Set<String> mProtocolList = new HashSet<String>();\r
+\r
+    // /\r
+    // / The Ppi list which recorded in module or library surface area and its\r
+    // / dependency on library instance surface area.\r
+    // /\r
+    private Set<String> mPpiList = new HashSet<String>();\r
+\r
+    // /\r
+    // / The Guid list which recoreded in module or library surface are and it's\r
+    // / dependence on library instance surface area.\r
+    // /\r
+    private Set<String> mGuidList = new HashSet<String>();\r
 \r
     /**\r
 \r
     /**\r
-      Construct function\r
-      \r
-      This function mainly initialize some member variable.\r
-      \r
-      @param outputPath    Output path of AutoGen file.\r
-      @param baseName      Module base name.\r
-      @param arch          Target architecture.\r
-    **/\r
-    public AutoGen(String outputPath, String baseName, String arch) {\r
+     * Construct function\r
+     * \r
+     * This function mainly initialize some member variable.\r
+     * \r
+     * @param outputPath\r
+     *            Output path of AutoGen file.\r
+     * @param baseName\r
+     *            Module base name.\r
+     * @param arch\r
+     *            Target architecture.\r
+     */\r
+    public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {\r
         this.outputPath = outputPath;\r
         this.outputPath = outputPath;\r
-        this.baseName = baseName;\r
+        this.moduleId = moduleId;\r
         this.arch = arch;\r
 \r
     }\r
 \r
     /**\r
         this.arch = arch;\r
 \r
     }\r
 \r
     /**\r
-      saveFile function\r
-      \r
-      This function save the content in stringBuffer to file.\r
-      \r
-      @param fileName      The name of file.\r
-      @param fileBuffer    The content of AutoGen file in buffer.\r
-      @return              "true" successful, "false" failed.\r
-    **/\r
+     * saveFile function\r
+     * \r
+     * This function save the content in stringBuffer to file.\r
+     * \r
+     * @param fileName\r
+     *            The name of file.\r
+     * @param fileBuffer\r
+     *            The content of AutoGen file in buffer.\r
+     * @return "true" successful, "false" failed.\r
+     */\r
     private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
         try {\r
             File autoGenH = new File(fileName);\r
     private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
         try {\r
             File autoGenH = new File(fileName);\r
@@ -136,13 +146,14 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      genAutogen function\r
-      \r
-      This function call libGenAutoGen or moduleGenAutogen function, which\r
-      dependence on generate library autogen or module autogen.\r
-      \r
-      @throws BuildException    Failed to creat AutoGen.c & AutoGen.h.\r
-    **/\r
+     * genAutogen function\r
+     * \r
+     * This function call libGenAutoGen or moduleGenAutogen function, which\r
+     * dependence on generate library autogen or module autogen.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to creat AutoGen.c & AutoGen.h.\r
+     */\r
     public void genAutogen() throws BuildException {\r
         try {\r
             //\r
     public void genAutogen() throws BuildException {\r
         try {\r
             //\r
@@ -155,8 +166,7 @@ public class AutoGen {
             // Check current is library or not, then call the corresponding\r
             // function.\r
             //\r
             // Check current is library or not, then call the corresponding\r
             // function.\r
             //\r
-            if (SurfaceAreaQuery.getComponentType().equalsIgnoreCase(\r
-                    CommonDefinition.LibraryStr)) {\r
+            if (this.moduleId.isLibrary()) {\r
                 libGenAutogen();\r
             } else {\r
                 moduleGenAutogen();\r
                 libGenAutogen();\r
             } else {\r
                 moduleGenAutogen();\r
@@ -169,13 +179,14 @@ public class AutoGen {
         }\r
     }\r
 \r
         }\r
     }\r
 \r
-    /** \r
-      moduleGenAutogen function\r
-    \r
-      This function generates AutoGen.c & AutoGen.h for module.\r
-     \r
-      @throws BuildException  Faile to create module AutoGen.c & AutoGen.h.\r
-    **/\r
+    /**\r
+     * moduleGenAutogen function\r
+     * \r
+     * This function generates AutoGen.c & AutoGen.h for module.\r
+     * \r
+     * @throws BuildException\r
+     *             Faile to create module AutoGen.c & AutoGen.h.\r
+     */\r
     void moduleGenAutogen() throws BuildException {\r
 \r
         try {\r
     void moduleGenAutogen() throws BuildException {\r
 \r
         try {\r
@@ -189,13 +200,13 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      libGenAutogen function\r
-      \r
-      This function generates AutoGen.c & AutoGen.h for library.\r
-      \r
-      @throws BuildException\r
-                  Faile to create library AutoGen.c & AutoGen.h\r
-    **/\r
+     * libGenAutogen function\r
+     * \r
+     * This function generates AutoGen.c & AutoGen.h for library.\r
+     * \r
+     * @throws BuildException\r
+     *             Faile to create library AutoGen.c & AutoGen.h\r
+     */\r
     void libGenAutogen() throws BuildException {\r
         try {\r
             libGenAutogenC();\r
     void libGenAutogen() throws BuildException {\r
         try {\r
             libGenAutogenC();\r
@@ -208,38 +219,42 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      moduleGenAutogenH\r
-     \r
-      This function generates AutoGen.h for module.\r
-      \r
-      @throws BuildException\r
-                  Failed to generate AutoGen.h.\r
-    **/\r
-    void moduleGenAutogenH() throws BuildException {\r
-\r
-        List<String> libClassIncludeH;\r
-        String moduleType;\r
-        List<String> headerFileList;\r
+     * moduleGenAutogenH\r
+     * \r
+     * This function generates AutoGen.h for module.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.h.\r
+     */\r
+    void moduleGenAutogenH() throws AutoGenException {\r
 \r
 \r
+        Set<String> libClassIncludeH;\r
+        String moduleType;\r
+        // List<String> headerFileList;\r
+        Set<String> headerFileList;\r
+        Iterator item;\r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
-        \r
+\r
         //\r
         //\r
-        // Write Autogen.h header notation \r
+        // Write Autogen.h header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenHNotation);\r
         //\r
         fileBuffer.append(CommonDefinition.autogenHNotation);\r
-        \r
+\r
         //\r
         //\r
-        // Add #ifndef  ${BaseName}_AUTOGENH\r
-        //     #def     ${BseeName}_AUTOGENH\r
+        // Add #ifndef ${BaseName}_AUTOGENH\r
+        // #def ${BseeName}_AUTOGENH\r
         //\r
         //\r
-        fileBuffer.append("#ifndef    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n");\r
-        fileBuffer.append("#define    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n\r\n");\r
-        \r
+        fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n");\r
+        fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n\r\n");\r
+\r
         //\r
         // Write the specification version and release version at the begine\r
         // of autogen.h file.\r
         // Note: the specification version and release version should\r
         //\r
         // Write the specification version and release version at the begine\r
         // of autogen.h file.\r
         // Note: the specification version and release version should\r
-        // be got from module surface area instead of hard code by it's moduleType.\r
+        // be got from module surface area instead of hard code by it's\r
+        // moduleType.\r
         //\r
         moduleType = SurfaceAreaQuery.getModuleType();\r
         switch (CommonDefinition.getModuleType(moduleType)) {\r
         //\r
         moduleType = SurfaceAreaQuery.getModuleType();\r
         switch (CommonDefinition.getModuleType(moduleType)) {\r
@@ -267,7 +282,7 @@ public class AutoGen {
         }\r
 \r
         //\r
         }\r
 \r
         //\r
-        // Add "extern int __make_me_compile_correctly;" at begin of \r
+        // Add "extern int __make_me_compile_correctly;" at begin of\r
         // AutoGen.h.\r
         //\r
         fileBuffer.append(CommonDefinition.autoGenHbegin);\r
         // AutoGen.h.\r
         //\r
         fileBuffer.append(CommonDefinition.autoGenHbegin);\r
@@ -275,49 +290,53 @@ public class AutoGen {
         //\r
         // Write consumed package's mdouleInfo related .h file to autogen.h\r
         //\r
         //\r
         // Write consumed package's mdouleInfo related .h file to autogen.h\r
         //\r
-        List<String> consumedPkgList = SurfaceAreaQuery\r
-                .getIncludePackageName(this.arch);\r
-        if (consumedPkgList != null) {\r
-            headerFileList = IncludesToAutogenH(consumedPkgList, moduleType);\r
-            for (int i = 0; i < headerFileList.size(); i++) {\r
-                fileBuffer.append(headerFileList.get(i));\r
+//        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
+//                .getDependencePkg(this.arch);\r
+        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery.getDependencePkg(null);\r
+        if (consumedPkgIdList != null) {\r
+            headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
+            item = headerFileList.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
 \r
         //\r
         // Write library class's related *.h file to autogen.h.\r
         //\r
             }\r
         }\r
 \r
         //\r
         // Write library class's related *.h file to autogen.h.\r
         //\r
-        LibraryClass[] libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
+        String[] libClassList = SurfaceAreaQuery\r
+                .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
 \r
         libClassList = SurfaceAreaQuery\r
             }\r
         }\r
 \r
         libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
+                .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
         fileBuffer.append("\r\n");\r
             }\r
         }\r
         fileBuffer.append("\r\n");\r
-        \r
+\r
         //\r
         // Write PCD autogen information to AutoGen.h.\r
         //\r
         //\r
         // Write PCD autogen information to AutoGen.h.\r
         //\r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputH());\r
-        }\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputH());\r
+//        }\r
 \r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
 \r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
-        \r
+\r
         //\r
         // Save string buffer content in AutoGen.h.\r
         //\r
         //\r
         // Save string buffer content in AutoGen.h.\r
         //\r
@@ -325,32 +344,40 @@ public class AutoGen {
             throw new BuildException("Failed to generate AutoGen.h !!!");\r
         }\r
     }\r
             throw new BuildException("Failed to generate AutoGen.h !!!");\r
         }\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-      moduleGenAutogenC\r
-   \r
-      This function generates AutoGen.c for module.\r
-    \r
-      @throws BuildException\r
-                Failed to generate AutoGen.c.\r
-    **/\r
-    void moduleGenAutogenC() throws BuildException {\r
+     * moduleGenAutogenC\r
+     * \r
+     * This function generates AutoGen.c for module.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void moduleGenAutogenC() throws AutoGenException {\r
 \r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
         //\r
 \r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
         //\r
-        // Write Autogen.c header notation \r
+        // Write Autogen.c header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenCNotation);\r
         //\r
         fileBuffer.append(CommonDefinition.autogenCNotation);\r
-        \r
+\r
         //\r
         // Write #include <AutoGen.h> at beginning of AutoGen.c\r
         //\r
         fileBuffer.append(CommonDefinition.includeAutogenH);\r
         //\r
         // Write #include <AutoGen.h> at beginning of AutoGen.c\r
         //\r
         fileBuffer.append(CommonDefinition.includeAutogenH);\r
-        \r
+\r
+        //\r
+        // Get the native MSA file infomation. Since before call autogen, \r
+        // the MSA native <Externs> information were overrided. So before \r
+        // process <Externs> it should be set the DOC as the Native MSA info.\r
+        //\r
+        Map<String, XmlObject> doc  = GlobalData.getNativeMsa(this.moduleId);\r
+        SurfaceAreaQuery.push(doc);\r
         //\r
         //\r
-        // Write DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
+        // Write <Extern> DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
         // to AutoGen.c\r
         //\r
         // to AutoGen.c\r
         //\r
+        \r
         ExternsDriverBindingToAutoGenC(fileBuffer);\r
 \r
         //\r
         ExternsDriverBindingToAutoGenC(fileBuffer);\r
 \r
         //\r
@@ -367,21 +394,29 @@ public class AutoGen {
             EntryPointToAutoGen(entryPointList, fileBuffer);\r
         }\r
 \r
             EntryPointToAutoGen(entryPointList, fileBuffer);\r
         }\r
 \r
+        //\r
+        // Restore the DOC which include the FPD module info. \r
+        //\r
+        SurfaceAreaQuery.pop();\r
+        \r
         //\r
         // Write Guid to autogen.c\r
         //\r
         //\r
         // Write Guid to autogen.c\r
         //\r
-        String guid = SurfaceAreaQuery.getModuleGuid();\r
+        String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery.getModuleGuid());\r
+        \r
         fileBuffer\r
                 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
         if (guid == null) {\r
         fileBuffer\r
                 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
         if (guid == null) {\r
-            throw new BuildException("Guid value must set!\n");\r
+            throw new AutoGenException("Guid value must set!\n");\r
         }\r
 \r
         //\r
         // Formate Guid as ANSI c form.Example:\r
         }\r
 \r
         //\r
         // Formate Guid as ANSI c form.Example:\r
-        // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24, 0xf0}}\r
+        // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
+        // 0xf0}}\r
         //\r
         //\r
-        fileBuffer.append(Spd.formatGuidName(guid));\r
+\r
+        fileBuffer.append(guid);\r
         fileBuffer.append("};\r\n");\r
 \r
         //\r
         fileBuffer.append("};\r\n");\r
 \r
         //\r
@@ -403,116 +438,119 @@ public class AutoGen {
         // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
         // isPcdEmulatedDriver as parameter. Library inherits PCD and module's\r
         // PCD information has been collected in FPDParser task by\r
         // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
         // isPcdEmulatedDriver as parameter. Library inherits PCD and module's\r
         // PCD information has been collected in FPDParser task by\r
-        // CollectPCDAction. \r
+        // CollectPCDAction.\r
         // Note : when PCD image tool ready,\r
         // isPCDEmulatedDriver parameter will be removed.\r
         //\r
         // Note : when PCD image tool ready,\r
         // isPCDEmulatedDriver parameter will be removed.\r
         //\r
-        try {\r
-            this.myPcdAutogen = new PCDAutoGenAction(baseName,\r
-                                                     null,\r
-                                                     null,\r
-                                                     null,\r
-                                                     this.arch,\r
-                                                     null,\r
-                                                     false,\r
-                                                     SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-            this.myPcdAutogen.execute();\r
-        } catch (Exception e) {\r
-            throw new BuildException("PCD Autogen for module failed:" + e.getMessage());\r
-        }\r
-\r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputC());\r
-        }\r
+//        try {\r
+//            this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),\r
+//                    moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));\r
+//            this.myPcdAutogen.execute();\r
+//        } catch (Exception e) {\r
+//            throw new BuildException("PCD Autogen failed:" + e.getMessage());\r
+//        }\r
+//\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputC());\r
+//        }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
             throw new BuildException("Failed to generate AutoGen.c !!!");\r
         }\r
 \r
     }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
             throw new BuildException("Failed to generate AutoGen.c !!!");\r
         }\r
 \r
     }\r
-    \r
+\r
     /**\r
     /**\r
-      libGenAutogenH\r
-   \r
-      This function generates AutoGen.h for library.\r
-    \r
-      @throws BuildException\r
-                Failed to generate AutoGen.c.\r
-    **/\r
-    void libGenAutogenH() throws BuildException {\r
-\r
-        List<String> libClassIncludeH;\r
+     * libGenAutogenH\r
+     * \r
+     * This function generates AutoGen.h for library.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void libGenAutogenH() throws AutoGenException {\r
+\r
+        Set<String> libClassIncludeH;\r
         String moduleType;\r
         String moduleType;\r
-        List<String> headerFileList;\r
+        Set<String> headerFileList;\r
+        Iterator item;\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
-        // Write Autogen.h header notation \r
+        // Write Autogen.h header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenHNotation);\r
         //\r
         fileBuffer.append(CommonDefinition.autogenHNotation);\r
-        \r
+\r
         //\r
         //\r
-        // Add #ifndef  ${BaseName}_AUTOGENH\r
-        //     #def     ${BseeName}_AUTOGENH\r
+        // Add #ifndef ${BaseName}_AUTOGENH\r
+        // #def ${BseeName}_AUTOGENH\r
         //\r
         //\r
-        fileBuffer.append("#ifndef    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n");\r
-        fileBuffer.append("#define    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n\r\n");\r
-        \r
+        fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n");\r
+        fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n\r\n");\r
+\r
         //\r
         //\r
-        // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION \r
+        // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
         // to autogen.h file.\r
         // Note: the specification version and release version should\r
         // be get from module surface area instead of hard code.\r
         //\r
         fileBuffer.append(CommonDefinition.autoGenHbegin);\r
         // to autogen.h file.\r
         // Note: the specification version and release version should\r
         // be get from module surface area instead of hard code.\r
         //\r
         fileBuffer.append(CommonDefinition.autoGenHbegin);\r
-        fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-        fileBuffer.append(CommonDefinition.autoGenHLine2);\r
+        String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
+        for (int i = 0; i < specList.length; i++){\r
+            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i] + "\r\n");\r
+        }\r
+//        fileBuffer.append(CommonDefinition.autoGenHLine1);\r
+//        fileBuffer.append(CommonDefinition.autoGenHLine2);\r
 \r
         //\r
         // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
         // \r
         moduleType = SurfaceAreaQuery.getModuleType();\r
 \r
         //\r
         // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
         // \r
         moduleType = SurfaceAreaQuery.getModuleType();\r
-        List<String> cosumedPkglist = SurfaceAreaQuery\r
-                .getIncludePackageName(this.arch);\r
-        headerFileList = IncludesToAutogenH(cosumedPkglist, moduleType);\r
-        for (int i = 0; i < headerFileList.size(); i++) {\r
-            fileBuffer.append(headerFileList.get(i));\r
+        PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
+                .getDependencePkg(this.arch);\r
+        headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
+        item = headerFileList.iterator();\r
+        while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
         }\r
         }\r
-\r
         //\r
         // Write library class's related *.h file to autogen.h\r
         //\r
         //\r
         // Write library class's related *.h file to autogen.h\r
         //\r
-        LibraryClass[] libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
+        String[] libClassList = SurfaceAreaQuery\r
+                .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
 \r
         libClassList = SurfaceAreaQuery\r
             }\r
         }\r
 \r
         libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
+                .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
         fileBuffer.append("\r\n");\r
             }\r
         }\r
         fileBuffer.append("\r\n");\r
-        \r
+\r
         //\r
         // Write PCD information to library AutoGen.h.\r
         //\r
         //\r
         // Write PCD information to library AutoGen.h.\r
         //\r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputH());\r
-        }\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputH());\r
+//        }\r
 \r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
 \r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
-        \r
+\r
         //\r
         // Save content of string buffer to AutoGen.h file.\r
         //\r
         //\r
         // Save content of string buffer to AutoGen.h file.\r
         //\r
@@ -522,21 +560,21 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      libGenAutogenC\r
-   \r
-      This function generates AutoGen.h for library.\r
-    \r
-      @throws BuildException\r
-                Failed to generate AutoGen.c.\r
-    **/\r
+     * libGenAutogenC\r
+     * \r
+     * This function generates AutoGen.h for library.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
     void libGenAutogenC() throws BuildException {\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
     void libGenAutogenC() throws BuildException {\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
-        // Write Autogen.c header notation \r
+        // Write Autogen.c header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenCNotation);\r
         //\r
         fileBuffer.append(CommonDefinition.autogenCNotation);\r
-        \r
+\r
         fileBuffer.append(CommonDefinition.autoGenCLine1);\r
         fileBuffer.append("\r\n");\r
 \r
         fileBuffer.append(CommonDefinition.autoGenCLine1);\r
         fileBuffer.append("\r\n");\r
 \r
@@ -544,27 +582,22 @@ public class AutoGen {
         // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
         // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
         // PCD information has been collected in FPDParser task by\r
         // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
         // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
         // PCD information has been collected in FPDParser task by\r
-        // CollectPCDAction. \r
+        // CollectPCDAction.\r
         // Note : when PCD image tool ready,\r
         // isPCDEmulatedDriver parameter will be removed.\r
         //\r
         try {\r
         // Note : when PCD image tool ready,\r
         // isPCDEmulatedDriver parameter will be removed.\r
         //\r
         try {\r
-            this.myPcdAutogen = new PCDAutoGenAction(baseName, \r
-                                                     null,\r
-                                                     null,\r
-                                                     null,\r
-                                                     this.arch,\r
-                                                     null,\r
-                                                     true,\r
-                                                     SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-            this.myPcdAutogen.execute();\r
+//            this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
+//                    this.moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));\r
+//            this.myPcdAutogen.execute();\r
+//             this.myPcdAutogen = new PCDAutoGenAction(this.moduleId,);\r
         } catch (Exception e) {\r
         } catch (Exception e) {\r
-            throw new BuildException("Pcd Autogen for library failed! " + e.getMessage());\r
+            throw new BuildException(e.getMessage());\r
         }\r
 \r
         }\r
 \r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputC());\r
-        }\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputC());\r
+//        }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
             throw new BuildException("Failed to generate AutoGen.c !!!");\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
             throw new BuildException("Failed to generate AutoGen.c !!!");\r
@@ -572,78 +605,97 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      LibraryClassToAutogenH\r
-      \r
-      This function returns *.h files declared by library classes which are \r
-      consumed or produced by current build module or library.\r
-      \r
-      @param   libClassList     List of library class which consumed or produce\r
-                                by current build module or library.\r
-      @return  includeStrList   List of *.h file.             \r
-    **/\r
-    List<String> LibraryClassToAutogenH(LibraryClass[] libClassList) {\r
-        List<String> includStrList = new ArrayList<String>();\r
-        String includerName;\r
+     * LibraryClassToAutogenH\r
+     * \r
+     * This function returns *.h files declared by library classes which are\r
+     * consumed or produced by current build module or library.\r
+     * \r
+     * @param libClassList\r
+     *            List of library class which consumed or produce by current\r
+     *            build module or library.\r
+     * @return includeStrList List of *.h file.\r
+     */\r
+    Set<String> LibraryClassToAutogenH(String[] libClassList) throws AutoGenException{\r
+        Set<String> includStrList = new HashSet<String>();\r
+        String includerName[];\r
         String str = "";\r
         String str = "";\r
-       \r
+\r
         //\r
         //\r
-        // Get include file from GlobalData's SPDTable according to \r
+        // Get include file from GlobalData's SPDTable according to\r
         // library class name.\r
         //\r
         // library class name.\r
         //\r
+\r
         for (int i = 0; i < libClassList.length; i++) {\r
         for (int i = 0; i < libClassList.length; i++) {\r
-            includerName = GlobalData.getLibClassIncluder(getStringValue((XmlObject)libClassList[i]));\r
-            if (includerName != null) {\r
-                str = CommonDefinition.include + " " + "<";\r
-                str = str + includerName + ">\r\n";\r
-                includStrList.add(str);\r
-                includerName = null;\r
+            includerName = GlobalData.getLibraryClassHeaderFiles(\r
+                    SurfaceAreaQuery.getDependencePkg(this.arch),\r
+                    libClassList[i]);\r
+            if (includerName == null){\r
+                throw new AutoGenException("Can not find library class [" + libClassList[i] + "] declaration in every packages. ");\r
+            }\r
+            for (int j = 0; j < includerName.length; j++) {\r
+                String includeNameStr = includerName[j];\r
+                if (includeNameStr != null) {\r
+                    str = CommonDefinition.include + " " + "<";\r
+                    str = str + includeNameStr + ">\r\n";\r
+                    includStrList.add(str);\r
+                    includeNameStr = null;\r
+                }\r
             }\r
         }\r
         return includStrList;\r
     }\r
 \r
     /**\r
             }\r
         }\r
         return includStrList;\r
     }\r
 \r
     /**\r
-      IncludesToAutogenH\r
-      \r
-      This function add include file in AutoGen.h file.\r
-      @param   packageNameList   List of module depended package.\r
-      @param   moduleType        Module type.\r
-      @return \r
-    **/\r
-    List<String> IncludesToAutogenH(List<String> packageNameList,\r
-            String moduleType) {\r
-\r
-        List<String> includeStrList = new ArrayList<String>();\r
-        String packageName = "";\r
+     * IncludesToAutogenH\r
+     * \r
+     * This function add include file in AutoGen.h file.\r
+     * \r
+     * @param packageNameList\r
+     *            List of module depended package.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @return\r
+     */\r
+    Set<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
+            String moduleType) throws AutoGenException{\r
+\r
+        Set<String> includeStrList = new HashSet<String>();\r
+        String pkgHeader;\r
         String includeStr = "";\r
 \r
         //\r
         // Get include file from moduleInfo file\r
         //\r
         String includeStr = "";\r
 \r
         //\r
         // Get include file from moduleInfo file\r
         //\r
-        for (int i = 0; i < packageNameList.size(); i++) {\r
-            packageName = packageNameList.get(i);\r
-            includeStr = GlobalData.getModuleInfoByPackageName(packageName,\r
-                    moduleType);\r
-            includeStrList.add(includeStr);\r
+        for (int i = 0; i < packageNameList.length; i++){\r
+//             pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i], moduleType);\r
+//            if (pkgHeader == null){\r
+//             throw new AutoGenException("Can not find package [" + packageNameList[i] + "] declaration in every packages. ");\r
+//            }else if (!pkgHeader.equalsIgnoreCase("")){\r
+//             includeStr = CommonDefinition.include + "<" + pkgHeader + ">\r\n";\r
+//                includeStrList.add(includeStr);\r
+//            }\r
         }\r
         }\r
+        \r
         return includeStrList;\r
     }\r
 \r
     /**\r
         return includeStrList;\r
     }\r
 \r
     /**\r
-      EntryPointToAutoGen \r
-      \r
-      This function convert <ModuleEntryPoint> & <ModuleUnloadImage> information\r
-      in mas to AutoGen.c\r
-      \r
-      @param  entryPointList    List of entry point.                            \r
-      @param  fileBuffer        String buffer fo AutoGen.c.\r
-      @throws Exception\r
-    **/\r
+     * EntryPointToAutoGen\r
+     * \r
+     * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
+     * information in mas to AutoGen.c\r
+     * \r
+     * @param entryPointList\r
+     *            List of entry point.\r
+     * @param fileBuffer\r
+     *            String buffer fo AutoGen.c.\r
+     * @throws Exception\r
+     */\r
     void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
             throws BuildException {\r
 \r
         String typeStr = SurfaceAreaQuery.getModuleType();\r
     void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
             throws BuildException {\r
 \r
         String typeStr = SurfaceAreaQuery.getModuleType();\r
-        \r
+\r
         //\r
         // The parameters and return value of entryPoint is difference\r
         // for difference module type.\r
         //\r
         // The parameters and return value of entryPoint is difference\r
         // for difference module type.\r
@@ -833,23 +885,7 @@ public class AutoGen {
             //\r
             entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             entryPointCount = 0;\r
             //\r
             entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             entryPointCount = 0;\r
-            if (entryPointList != null) {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("EFI_STATUS\r\n");\r
-                        fileBuffer.append("EFIAPI\r\n");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (\r\n");\r
-                        fileBuffer\r
-                                .append("  EFI_HANDLE        ImageHandle\r\n");\r
-                        fileBuffer.append("  );\r\n");\r
-                        entryPointCount++;\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-\r
+            \r
             fileBuffer\r
                     .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
             fileBuffer.append(Integer.toString(entryPointCount));\r
             fileBuffer\r
                     .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
             fileBuffer.append(Integer.toString(entryPointCount));\r
@@ -1078,198 +1114,170 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      PpiGuidToAutogenc \r
-    \r
-      This function gets GUIDs from SPD file accrodeing to <PPIs> information and \r
-      write those GUIDs to AutoGen.c.\r
-    \r
-      @param   fileBuffer         String Buffer for Autogen.c file.\r
-      @throws  BuildException     Guid must set value!\r
-    **/\r
-    void PpiGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+     * PpiGuidToAutogenc\r
+     * \r
+     * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
+     * and write those GUIDs to AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * @throws BuildException\r
+     *             Guid must set value!\r
+     */\r
+    void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
         String[] cNameGuid = null;\r
         String[] cNameGuid = null;\r
-        boolean isEqual = false;\r
-\r
-        PPIsDocument.PPIs.Ppi[] ppiList = SurfaceAreaQuery.getPpiArray(null);\r
-        if (ppiList != null) {\r
-            for (int i = 0; i < ppiList.length; i++) {\r
-                isEqual = false;\r
-                String ppiName = getStringValue((XmlObject)ppiList[i]);\r
-                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                    if (this.mPpiList.get(j).equalsIgnoreCase(ppiName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mPpiList.add(ppiName);\r
-                }\r
-            }\r
+\r
+        //\r
+        // Get the all PPI adn PPI Notify from MSA file,\r
+        // then add those PPI ,and PPI Notify name to list.\r
+        //\r
+        String[] ppiList = SurfaceAreaQuery.getPpiArray(null);\r
+        for (int i = 0; i < ppiList.length; i++) {\r
+            this.mPpiList.add(ppiList[i]);\r
         }\r
 \r
         }\r
 \r
-        PPIsDocument.PPIs.PpiNotify[] ppiNotifyList = SurfaceAreaQuery\r
-                .getPpiNotifyArray(null);\r
-        if (ppiNotifyList != null) {\r
-            for (int i = 0; i < ppiNotifyList.length; i++) {\r
-                isEqual = false;\r
-                String ppiNotifyName = getStringValue((XmlObject)ppiNotifyList[i]);\r
-                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                    if (this.mPpiList.get(j).equalsIgnoreCase(ppiNotifyName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mPpiList.add(ppiNotifyName);\r
-                }\r
-            }\r
+        String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(null);\r
+        for (int i = 0; i < ppiNotifyList.length; i++) {\r
+            this.mPpiList.add(ppiNotifyList[i]);\r
         }\r
 \r
         }\r
 \r
-        for (int i = 0; i < this.mPpiList.size(); i++) {\r
-            if (this.mPpiList.get(i) != null) {\r
-                cNameGuid = GlobalData.getPpiInfoGuid(this.mPpiList.get(i));\r
-                if (cNameGuid != null) {\r
-                    fileBuffer\r
-                            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                    fileBuffer.append(cNameGuid[0]);\r
-                    fileBuffer.append(" =     { ");\r
-                    fileBuffer.append(cNameGuid[1]);\r
-                    fileBuffer.append(" } ;");\r
-                }\r
+        //\r
+        // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
+        //\r
+        Iterator ppiIterator = this.mPpiList.iterator();\r
+        String ppiKeyWord = null;\r
+        while (ppiIterator.hasNext()) {\r
+               ppiKeyWord = ppiIterator.next().toString();\r
+            cNameGuid = GlobalData\r
+                    .getPpiGuid(SurfaceAreaQuery.getDependencePkg(this.arch),\r
+                            ppiKeyWord);\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(cNameGuid[1]);\r
+                fileBuffer.append(" } ;");\r
             } else {\r
             } else {\r
-                throw new BuildException("Guid must set value!");\r
+               //\r
+                // If can't find Ppi GUID declaration in every package\r
+                //\r
+                throw new AutoGenException("Can not find Ppi GUID [" + ppiKeyWord + "] declaration in every packages. ");\r
             }\r
         }\r
     }\r
 \r
     /**\r
             }\r
         }\r
     }\r
 \r
     /**\r
-      ProtocolGuidToAutogenc \r
-    \r
-      This function gets GUIDs from SPD file accrodeing to <Protocol> \r
-      information and write those GUIDs to AutoGen.c.\r
-    \r
-      @param   fileBuffer         String Buffer for Autogen.c file.\r
-      @throws  BuildException     Protocol name must set.\r
-    **/\r
+     * ProtocolGuidToAutogenc\r
+     * \r
+     * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
+     * information and write those GUIDs to AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * @throws BuildException\r
+     *             Protocol name must set.\r
+     */\r
     void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
         String[] cNameGuid = null;\r
     void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
         String[] cNameGuid = null;\r
-        boolean isEqual = false;\r
-\r
-        ProtocolsDocument.Protocols.Protocol[] protocolList = SurfaceAreaQuery\r
-                .getProtocolArray(null);\r
-        if (protocolList != null) {\r
-            for (int i = 0; i < protocolList.length; i++) {\r
-                isEqual = false;\r
-                String protocolName = getStringValue((XmlObject)protocolList[i]);\r
-                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                    if (this.mProtocolList.get(j).equalsIgnoreCase(protocolName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mProtocolList.add(protocolName);\r
 \r
 \r
-                }\r
-            }\r
+        String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
+\r
+        //\r
+        // Add result to Autogen global list.\r
+        //\r
+        for (int i = 0; i < protocolList.length; i++) {\r
+            this.mProtocolList.add(protocolList[i]);\r
         }\r
 \r
         }\r
 \r
-        ProtocolsDocument.Protocols.ProtocolNotify[] protocolNotifyList = SurfaceAreaQuery\r
-                .getProtocolNotifyArray(null);\r
-        if (protocolNotifyList != null) {\r
-            for (int i = 0; i < protocolNotifyList.length; i++) {\r
-                isEqual = false;\r
-                String protocolNotifyName = getStringValue((XmlObject)protocolNotifyList[i]);\r
-                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                    if (this.mProtocolList.get(j).equalsIgnoreCase(protocolNotifyName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mProtocolList.add(protocolNotifyName);\r
+        String[] protocolNotifyList = SurfaceAreaQuery\r
+                .getProtocolNotifyArray(this.arch);\r
 \r
 \r
-                }\r
-            }\r
+        for (int i = 0; i < protocolNotifyList.length; i++) {\r
+            this.mProtocolList.add(protocolNotifyList[i]);\r
         }\r
         }\r
-        if (this.mProtocolList.size() > 0) {\r
-            for (int i = 0; i < this.mProtocolList.size(); i++) {\r
-                if (this.mProtocolList.get(i) != null) {\r
-                    cNameGuid = GlobalData\r
-                            .getProtocolInfoGuid(this.mProtocolList.get(i));\r
-                    if (cNameGuid != null) {\r
-                        fileBuffer\r
-                                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                        fileBuffer.append(cNameGuid[0]);\r
-                        fileBuffer.append(" =     { ");\r
-                        fileBuffer.append(cNameGuid[1]);\r
-                        fileBuffer.append(" } ;");\r
-                    }\r
-                } else {\r
-                    throw new BuildException("Protocol name must set!");\r
-                }\r
+\r
+        //\r
+        // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
+        //\r
+        Iterator protocolIterator = this.mPpiList.iterator();\r
+        String protocolKeyWord = null;\r
+        while (protocolIterator.hasNext()) {\r
+               protocolKeyWord = protocolIterator.next().toString();\r
+            cNameGuid = GlobalData.getProtocolGuid(SurfaceAreaQuery\r
+                    .getDependencePkg(this.arch), protocolKeyWord);\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(cNameGuid[1]);\r
+                fileBuffer.append(" } ;");\r
+            } else {\r
+               //\r
+                // If can't find protocol GUID declaration in every package\r
+                //\r
+                throw new BuildException("Can not find protocol Guid [" + cNameGuid + "] declaration in every packages. ");\r
             }\r
         }\r
     }\r
 \r
     /**\r
             }\r
         }\r
     }\r
 \r
     /**\r
-      GuidGuidToAutogenc\r
-    \r
-      This function gets GUIDs from SPD file accrodeing to <Guids> information\r
-      and write those GUIDs to AutoGen.c.\r
-    \r
-      @param  fileBuffer       String Buffer for Autogen.c file.\r
-    \r
-    **/\r
-    void GuidGuidToAutogenC(StringBuffer fileBuffer) {\r
+     * GuidGuidToAutogenc\r
+     * \r
+     * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
+     * and write those GUIDs to AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * \r
+     */\r
+    void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
         String[] cNameGuid = null;\r
         String[] cNameGuid = null;\r
-        boolean isEqual = false;\r
-        GuidsDocument.Guids.GuidEntry[] guidList = SurfaceAreaQuery\r
-                .getGuidEntryArray(null);\r
-\r
-        if (guidList != null) {\r
-            for (int i = 0; i < guidList.length; i++) {\r
-                for (int j = 0; j < this.mGuidList.size(); j++) {\r
-                    isEqual = false;\r
-                    if (this.mGuidList.get(j).getCName().equalsIgnoreCase(\r
-                            guidList[i].getCName().toString())) {\r
-                        isEqual = true;\r
-                        break;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mGuidList.add(guidList[i]);\r
+        String   guidKeyWord = null;\r
 \r
 \r
-                }\r
+        String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
 \r
 \r
-            }\r
+        for (int i = 0; i < guidList.length; i++) {\r
+            this.mGuidList.add(guidList[i]);\r
         }\r
 \r
         }\r
 \r
-        for (int i = 0; i < this.mGuidList.size(); i++) {\r
-            if (this.mGuidList.get(i).getCName() != null) {\r
-                cNameGuid = GlobalData.getGuidInfoGuid(this.mGuidList.get(i)\r
-                        .getCName());\r
-                if (cNameGuid != null) {\r
-                    fileBuffer\r
-                            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                    fileBuffer.append(cNameGuid[0]);\r
-                    fileBuffer.append(" =     { ");\r
-                    fileBuffer.append(cNameGuid[1]);\r
-                    fileBuffer.append("} ;");\r
-                }\r
+        Iterator guidIterator = this.mGuidList.iterator();\r
+        while (guidIterator.hasNext()) {\r
+               guidKeyWord = guidIterator.next().toString();\r
+            cNameGuid = GlobalData.getGuid(SurfaceAreaQuery\r
+                    .getDependencePkg(this.arch), guidKeyWord);\r
+            \r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(cNameGuid[1]);\r
+                fileBuffer.append("} ;");\r
+            }else {\r
+               //\r
+                // If can't find GUID declaration in every package\r
+                //\r
+                throw new AutoGenException("Can not find Guid [" + guidKeyWord + "] declaration in every packages. ");\r
             }\r
             }\r
+\r
         }\r
     }\r
 \r
     /**\r
         }\r
     }\r
 \r
     /**\r
-      LibInstanceToAutogenC\r
-      \r
-      This function adds dependent library instance to autogen.c,which includeing \r
-      library's constructor, destructor, and library dependent ppi, protocol, guid,\r
-      pcd information.\r
-         \r
-      @param  fileBuffer              String buffer for AutoGen.c\r
-      @throws BuildException          \r
-    **/\r
+     * LibInstanceToAutogenC\r
+     * \r
+     * This function adds dependent library instance to autogen.c,which\r
+     * includeing library's constructor, destructor, and library dependent ppi,\r
+     * protocol, guid, pcd information.\r
+     * \r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws BuildException\r
+     */\r
     void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
         int index;\r
     void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
         int index;\r
-        boolean isEqual = false;\r
 \r
         String moduleType = SurfaceAreaQuery.getModuleType();\r
         List<String> libConstructList = new ArrayList<String>();\r
 \r
         String moduleType = SurfaceAreaQuery.getModuleType();\r
         List<String> libConstructList = new ArrayList<String>();\r
@@ -1277,144 +1285,83 @@ public class AutoGen {
 \r
         String libConstructName = null;\r
         String libDestructName = null;\r
 \r
         String libConstructName = null;\r
         String libDestructName = null;\r
-        List<String> libraryList = SurfaceAreaQuery.getLibraryInstance(\r
-                this.arch, CommonDefinition.AlwaysConsumed);\r
+        ModuleIdentification[] libraryIdList = SurfaceAreaQuery.getLibraryInstance(this.arch);\r
 \r
         try {\r
 \r
         try {\r
-            if (libraryList != null) {\r
+            if (libraryIdList != null) {\r
                 //\r
                 // Reorder library instance sequence.\r
                 //\r
                 //\r
                 // Reorder library instance sequence.\r
                 //\r
-                AutogenLibOrder libOrder = new AutogenLibOrder(libraryList);\r
-                List orderList = libOrder.orderLibInstance();\r
-                \r
+                AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, this.arch);\r
+                List<ModuleIdentification> orderList = libOrder.orderLibInstance();\r
+\r
                 if (orderList != null) {\r
                     //\r
                     // Process library instance one by one.\r
                     //\r
                     for (int i = 0; i < orderList.size(); i++) {\r
                 if (orderList != null) {\r
                     //\r
                     // Process library instance one by one.\r
                     //\r
                     for (int i = 0; i < orderList.size(); i++) {\r
-                        \r
+\r
                         //\r
                         // Get library instance basename.\r
                         //\r
                         //\r
                         // Get library instance basename.\r
                         //\r
-                        String libInstanceName = orderList.get(i).toString();\r
-                        \r
+                        ModuleIdentification libInstanceId = orderList.get(i);\r
+\r
                         //\r
                         // Get override map\r
                         //\r
                         Map<String, XmlObject> libDoc = GlobalData\r
                         //\r
                         // Get override map\r
                         //\r
                         Map<String, XmlObject> libDoc = GlobalData\r
-                                .getDoc(libInstanceName);\r
+                                .getDoc(libInstanceId, this.arch);\r
                         SurfaceAreaQuery.push(libDoc);\r
                         SurfaceAreaQuery.push(libDoc);\r
-                        \r
+\r
                         //\r
                         // Get <PPis>, <Protocols>, <Guids> list of this library\r
                         // instance.\r
                         //\r
                         //\r
                         // Get <PPis>, <Protocols>, <Guids> list of this library\r
                         // instance.\r
                         //\r
-                        PPIsDocument.PPIs.Ppi[] ppiList = SurfaceAreaQuery\r
+                        String[] ppiList = SurfaceAreaQuery\r
                                 .getPpiArray(null);\r
                                 .getPpiArray(null);\r
-                        PPIsDocument.PPIs.PpiNotify[] ppiNotifyList = SurfaceAreaQuery\r
+                        String[] ppiNotifyList = SurfaceAreaQuery\r
                                 .getPpiNotifyArray(null);\r
                                 .getPpiNotifyArray(null);\r
-                        ProtocolsDocument.Protocols.Protocol[] protocolList = SurfaceAreaQuery\r
+                        String[] protocolList = SurfaceAreaQuery\r
                                 .getProtocolArray(null);\r
                                 .getProtocolArray(null);\r
-                        ProtocolsDocument.Protocols.ProtocolNotify[] protocolNotifyList = SurfaceAreaQuery\r
+                        String[] protocolNotifyList = SurfaceAreaQuery\r
                                 .getProtocolNotifyArray(null);\r
                                 .getProtocolNotifyArray(null);\r
-                        GuidsDocument.Guids.GuidEntry[] guidList = SurfaceAreaQuery\r
+                        String[] guidList = SurfaceAreaQuery\r
                                 .getGuidEntryArray(null);\r
 \r
                         //\r
                                 .getGuidEntryArray(null);\r
 \r
                         //\r
-                        // Add those ppi, protocol, guid in global ppi, protocol, guid\r
+                        // Add those ppi, protocol, guid in global ppi,\r
+                        // protocol, guid\r
                         // list.\r
                         //\r
                         // list.\r
                         //\r
-                        if (ppiList != null) {\r
-                            for (index = 0; index < ppiList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)ppiList[index]);\r
-                                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                                    if (this.mPpiList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mPpiList.add(name);\r
-                                }\r
-                            }\r
+                        for (index = 0; index < ppiList.length; index++) {\r
+                            this.mPpiList.add(ppiList[index]);\r
                         }\r
                         }\r
-                        if (ppiNotifyList != null) {\r
-                            for (index = 0; index < ppiNotifyList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)ppiNotifyList[index]);\r
-                                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                                    if (this.mPpiList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mPpiList.add(name);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < ppiNotifyList.length; index++) {\r
+                            this.mPpiList.add(ppiNotifyList[index]);\r
                         }\r
                         }\r
-                        if (protocolList != null) {\r
-                            for (index = 0; index < protocolList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)protocolList[index]);\r
-                                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                                    if (this.mProtocolList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mProtocolList.add(name);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < protocolList.length; index++) {\r
+                            this.mProtocolList.add(protocolList[index]);\r
                         }\r
                         }\r
-                        if (protocolNotifyList != null) {\r
-                            for (index = 0; index < protocolNotifyList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)protocolNotifyList[index]);\r
-                                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                                    if (this.mProtocolList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mProtocolList.add(name);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < protocolNotifyList.length; index++) {\r
+                            this.mProtocolList.add(protocolNotifyList[index]);\r
                         }\r
                         }\r
-                        if (guidList != null) {\r
-                            for (index = 0; index < guidList.length; index++) {\r
-                                isEqual = false;\r
-                                for (int j = 0; j < this.mGuidList.size(); j++) {\r
-                                    if (this.mGuidList.get(j).getCName()\r
-                                            .equalsIgnoreCase(\r
-                                                    guidList[index].getCName())) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mGuidList.add(guidList[index]);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < guidList.length; index++) {\r
+                            this.mGuidList.add(guidList[index]);   \r
                         }\r
 \r
                         //\r
                         // If not yet parse this library instance's constructor\r
                         // element,parse it.\r
                         //\r
                         }\r
 \r
                         //\r
                         // If not yet parse this library instance's constructor\r
                         // element,parse it.\r
                         //\r
-                        if (!GlobalData.isHaveLibInstance(libInstanceName)) {\r
-                            libConstructName = SurfaceAreaQuery\r
+                        libConstructName = SurfaceAreaQuery\r
                                     .getLibConstructorName();\r
                                     .getLibConstructorName();\r
-                            libDestructName = SurfaceAreaQuery\r
+                        libDestructName = SurfaceAreaQuery\r
                                     .getLibDestructorName();\r
 \r
                                     .getLibDestructorName();\r
 \r
-                            GlobalData.setLibInstanceInfo(libInstanceName,\r
-                                    libConstructName, libDestructName);\r
-                        } else {\r
-                            libConstructName = GlobalData\r
-                                    .getLibInstanceConstructor(libInstanceName);\r
-                            libDestructName = GlobalData\r
-                                    .getLibInstanceDestructor(libInstanceName);\r
-                        }\r
                         SurfaceAreaQuery.pop();\r
                         //\r
                         // Add dependent library instance constructor function.\r
                         SurfaceAreaQuery.pop();\r
                         //\r
                         // Add dependent library instance constructor function.\r
@@ -1440,8 +1387,7 @@ public class AutoGen {
                 //\r
                 // Add library destructor to AutoGen.c\r
                 //\r
                 //\r
                 // Add library destructor to AutoGen.c\r
                 //\r
-                LibDestructorToAutogenC(libDestructList, moduleType,\r
-                        fileBuffer/* autogenC */);\r
+                LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
             }\r
 \r
         } catch (Exception e) {\r
             }\r
 \r
         } catch (Exception e) {\r
@@ -1449,24 +1395,26 @@ public class AutoGen {
         }\r
     }\r
 \r
         }\r
     }\r
 \r
\r
     /**\r
     /**\r
-      LibConstructorToAutogenc\r
-    \r
-      This function writes library constructor list to AutoGen.c. The library \r
-      constructor's parameter and return value depend on module type.\r
-    \r
-      @param  libInstanceList        List of library construct name.\r
-      @param  moduleType             Module type.\r
-      @param  fileBuffer             String buffer for AutoGen.c\r
-      @throws Exception              \r
-    **/\r
+     * LibConstructorToAutogenc\r
+     * \r
+     * This function writes library constructor list to AutoGen.c. The library\r
+     * constructor's parameter and return value depend on module type.\r
+     * \r
+     * @param libInstanceList\r
+     *            List of library construct name.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws Exception\r
+     */\r
     void LibConstructorToAutogenC(List<String> libInstanceList,\r
             String moduleType, StringBuffer fileBuffer) throws Exception {\r
         boolean isFirst = true;\r
 \r
         //\r
     void LibConstructorToAutogenC(List<String> libInstanceList,\r
             String moduleType, StringBuffer fileBuffer) throws Exception {\r
         boolean isFirst = true;\r
 \r
         //\r
-        // The library constructor's parameter and return value depend on \r
+        // The library constructor's parameter and return value depend on\r
         // module type.\r
         //\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
         // module type.\r
         //\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
@@ -1577,16 +1525,19 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      LibDestructorToAutogenc\r
-    \r
-      This function writes library destructor list to AutoGen.c. The library \r
-      destructor's parameter and return value depend on module type.\r
-    \r
-      @param  libInstanceList        List of library destructor name.\r
-      @param  moduleType             Module type.\r
-      @param  fileBuffer             String buffer for AutoGen.c\r
-      @throws Exception              \r
-    **/\r
+     * LibDestructorToAutogenc\r
+     * \r
+     * This function writes library destructor list to AutoGen.c. The library\r
+     * destructor's parameter and return value depend on module type.\r
+     * \r
+     * @param libInstanceList\r
+     *            List of library destructor name.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws Exception\r
+     */\r
     void LibDestructorToAutogenC(List<String> libInstanceList,\r
             String moduleType, StringBuffer fileBuffer) throws Exception {\r
         boolean isFirst = true;\r
     void LibDestructorToAutogenC(List<String> libInstanceList,\r
             String moduleType, StringBuffer fileBuffer) throws Exception {\r
         boolean isFirst = true;\r
@@ -1666,12 +1617,13 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      ExternsDriverBindingToAutoGenC\r
-      \r
-      This function is to write DRIVER_BINDING, COMPONENT_NAME, \r
-      DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
-      \r
-      @param  fileBuffer             String buffer for AutoGen.c\r
+     * ExternsDriverBindingToAutoGenC\r
+     * \r
+     * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
+     * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
      */\r
     void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
             throws BuildException {\r
      */\r
     void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
             throws BuildException {\r
@@ -1681,12 +1633,12 @@ public class AutoGen {
         // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
         // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
         //\r
         // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
         // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
         //\r
-        \r
+\r
         String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
         String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
-        \r
+\r
         //\r
         // If component name protocol,component configuration protocol,\r
         //\r
         // If component name protocol,component configuration protocol,\r
-        // component diagnostic protocol is not null or empty, check \r
+        // component diagnostic protocol is not null or empty, check\r
         // if every one have the same number of the driver binding protocol.\r
         //\r
         if (drvBindList == null || drvBindList.length == 0) {\r
         // if every one have the same number of the driver binding protocol.\r
         //\r
         if (drvBindList == null || drvBindList.length == 0) {\r
@@ -1819,14 +1771,15 @@ public class AutoGen {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      ExternCallBackToAutoGenC\r
-    \r
-      This function adds <SetVirtualAddressMapCallBack> and <ExitBootServicesCallBack>\r
-      infomation to AutoGen.c\r
-    \r
-      @param  fileBuffer           String buffer for AutoGen.c\r
-      @throws BuildException\r
-    **/\r
+     * ExternCallBackToAutoGenC\r
+     * \r
+     * This function adds <SetVirtualAddressMapCallBack> and\r
+     * <ExitBootServicesCallBack> infomation to AutoGen.c\r
+     * \r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws BuildException\r
+     */\r
     void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
             throws BuildException {\r
         String[] setVirtualList = SurfaceAreaQuery\r
     void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
             throws BuildException {\r
         String[] setVirtualList = SurfaceAreaQuery\r
@@ -2003,7 +1956,4 @@ public class AutoGen {
 \r
     }\r
 \r
 \r
     }\r
 \r
-    private String getStringValue(XmlObject xmlDoc) {\r
-        return xmlDoc.getDomNode().getFirstChild().getNodeValue();\r
-    }\r
-}\r
+}
\ No newline at end of file
index 50668b096bc88be1589d5a1e1ad152093d947a88..f08fec70e718266e404eaf5602d709cc88b028ca 100644 (file)
@@ -20,11 +20,13 @@ import java.util.ArrayList;
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
+\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 \r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 \r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.ModuleIdentification;\r
 \r
 /**\r
   This class This class is to reorder library instance sequence according to\r
 \r
 /**\r
   This class This class is to reorder library instance sequence according to\r
@@ -34,18 +36,18 @@ public class AutogenLibOrder {
     ///\r
     /// The map of library class and its library instance.\r
     ///\r
     ///\r
     /// The map of library class and its library instance.\r
     ///\r
-    private Map<String, String> libClassMap = new HashMap<String, String>();\r
+    private Map<String, ModuleIdentification> libClassMap = new HashMap<String, ModuleIdentification>();\r
 \r
     ///\r
 \r
     ///\r
-    /// The map of library instance and its implemet instance.\r
+    /// The map of library instance and its implemet libraryClass.\r
     ///\r
     ///\r
-    private Map<String, String[]> libInstanceMap = new HashMap<String, String[]>();\r
+    private Map<ModuleIdentification, String[]> libInstanceMap = new HashMap<ModuleIdentification, String[]>();\r
 \r
     ///\r
     /// List of library instance. It is String[3] list, String[0] is libraryName,\r
     /// String[1] is libraryConstructor name, String[2] is libDestructor name.\r
     ///\r
 \r
     ///\r
     /// List of library instance. It is String[3] list, String[0] is libraryName,\r
     /// String[1] is libraryConstructor name, String[2] is libDestructor name.\r
     ///\r
-    private List<String[]> libInstanceList = new ArrayList<String[]>();\r
+    private List<LibraryInstanceNode> libInstanceList = new ArrayList<LibraryInstanceNode>();\r
     \r
     /**\r
       Constructor function\r
     \r
     /**\r
       Constructor function\r
@@ -55,40 +57,37 @@ public class AutogenLibOrder {
       @param  libraryList   List of the library instance.\r
       @throws Exception\r
     **/\r
       @param  libraryList   List of the library instance.\r
       @throws Exception\r
     **/\r
-    AutogenLibOrder(List<String> libraryList) throws Exception {\r
-        String[]       libInstance = new String[3];\r
-        LibraryClass[] libClassDeclList = null;\r
-        LibraryClass[] libClassConsmList = null;\r
+    AutogenLibOrder(ModuleIdentification[] libraryList, String arch) throws Exception {\r
+        LibraryInstanceNode libInstanceNode;\r
+        String[]       libClassDeclList = null;\r
+        String[]       libClassConsmList = null;\r
         \r
         \r
-        for (int i = 0; i < libraryList.size(); i++) {\r
+        for (int i = 0; i < libraryList.length; i++) {\r
             //\r
             // Add libraryInstance in to libInstanceList.\r
             //\r
             // Add libraryInstance in to libInstanceList.\r
-            //\r
-            libInstance[0] = libraryList.get(i);\r
-            Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstance[0]);\r
+            // \r
+            Map<String, XmlObject> libDoc = GlobalData.getDoc(libraryList[i], arch);\r
             SurfaceAreaQuery.push(libDoc);\r
             SurfaceAreaQuery.push(libDoc);\r
-            libInstance[1] = SurfaceAreaQuery.getLibConstructorName();\r
-            libInstance[2] = SurfaceAreaQuery.getLibDestructorName();\r
-            libInstanceList.add(libInstance.clone());\r
+            libInstanceNode = new LibraryInstanceNode (libraryList[i],SurfaceAreaQuery.getLibConstructorName(), SurfaceAreaQuery.getLibDestructorName());\r
+            libInstanceList.add(libInstanceNode);\r
             \r
             //\r
             // Add library instance and consumed library class list to\r
             // libInstanceMap.\r
             //\r
             libClassConsmList = SurfaceAreaQuery\r
             \r
             //\r
             // Add library instance and consumed library class list to\r
             // libInstanceMap.\r
             //\r
             libClassConsmList = SurfaceAreaQuery\r
-                    .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
+                    .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
             if (libClassConsmList != null) {\r
                 String[] classStr = new String[libClassConsmList.length];\r
                 for (int k = 0; k < libClassConsmList.length; k++) {\r
             if (libClassConsmList != null) {\r
                 String[] classStr = new String[libClassConsmList.length];\r
                 for (int k = 0; k < libClassConsmList.length; k++) {\r
-                    //classStr[k] = libClassConsmList[k].getStringValue();\r
-                    classStr[k] = getStringValue((XmlObject)libClassConsmList[k]);\r
+                    classStr[k] = libClassConsmList[k];\r
                 }\r
                 }\r
-                if (this.libInstanceMap.containsKey(libInstance[0])) {\r
+                if (this.libInstanceMap.containsKey(libraryList[i])) {\r
                     throw new Exception(\r
                     throw new Exception(\r
-                            libInstance[0]\r
+                            libraryList[i].getName()\r
                                     + "this library instance is already exist, please check you library instance list!");\r
                 } else {\r
                                     + "this library instance is already exist, please check you library instance list!");\r
                 } else {\r
-                    this.libInstanceMap.put(libInstance[0], classStr);\r
+                    this.libInstanceMap.put(libraryList[i], classStr);\r
                 }\r
             }\r
 \r
                 }\r
             }\r
 \r
@@ -96,20 +95,17 @@ public class AutogenLibOrder {
             // Add library class and library instance map.\r
             //\r
             libClassDeclList = SurfaceAreaQuery\r
             // Add library class and library instance map.\r
             //\r
             libClassDeclList = SurfaceAreaQuery\r
-                    .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
+                    .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
             if (libClassDeclList != null) {\r
                 for (int j = 0; j < libClassDeclList.length; j++) {\r
             if (libClassDeclList != null) {\r
                 for (int j = 0; j < libClassDeclList.length; j++) {\r
-                    //if (this.libClassMap.containsKey(libClassDeclList[j]\r
-                    //        .getStringValue())) {\r
-                    String libClassName = getStringValue((XmlObject)libClassDeclList[j]);\r
-                    if (this.libClassMap.containsKey(libClassName)) {\r
-                        System.out.println(libClassName\r
+                    if (this.libClassMap.containsKey(libClassDeclList[j])) {\r
+                        System.out.println(libClassDeclList[j]\r
                                 + " class is already implement by "\r
                                 + " class is already implement by "\r
-                                + this.libClassMap.get(libClassName));\r
+                                + this.libClassMap.get(libClassDeclList[j]));\r
                         throw new Exception(libClassDeclList\r
                                 + " is already have library instance!");\r
                     } else {\r
                         throw new Exception(libClassDeclList\r
                                 + " is already have library instance!");\r
                     } else {\r
-                        this.libClassMap.put(libClassName, libInstance[0]);\r
+                        this.libClassMap.put(libClassDeclList[j], libraryList[i]);\r
                     }\r
                 }\r
             }\r
                     }\r
                 }\r
             }\r
@@ -149,15 +145,15 @@ public class AutogenLibOrder {
       \r
       @return     List which content the ordered library instance.\r
     **/\r
       \r
       @return     List which content the ordered library instance.\r
     **/\r
-    List orderLibInstance() {\r
-        List<String> orderList = new ArrayList<String>();\r
+    List<ModuleIdentification> orderLibInstance() {\r
+        List<ModuleIdentification> orderList = new ArrayList<ModuleIdentification>();\r
         //\r
         // Stack of node which track the library instance name ant its visiting\r
         // flag.\r
         //\r
         List<Node> stackList = new ArrayList<Node>();\r
         int stackSize = 0;\r
         //\r
         // Stack of node which track the library instance name ant its visiting\r
         // flag.\r
         //\r
         List<Node> stackList = new ArrayList<Node>();\r
         int stackSize = 0;\r
-        String libInstance = null;\r
+        ModuleIdentification libInstanceId = null;\r
         if (libInstanceList.size() < 0) {\r
             return null;\r
         }\r
         if (libInstanceList.size() < 0) {\r
             return null;\r
         }\r
@@ -169,11 +165,11 @@ public class AutogenLibOrder {
             //\r
             // If library instance is already in the order list skip it.\r
             //\r
             //\r
             // If library instance is already in the order list skip it.\r
             //\r
-            if (isInLibInstance(orderList, libInstanceList.get(i)[0])) {\r
+            if (isInLibInstance(orderList, libInstanceList.get(i).libId)) {\r
                 continue;\r
             }\r
             \r
                 continue;\r
             }\r
             \r
-            Node node = new Node(libInstanceList.get(i)[0], false);\r
+            Node node = new Node(libInstanceList.get(i).libId, false);\r
             //\r
             // Use stack to reorder library instance.\r
             // Push node to stack.\r
             //\r
             // Use stack to reorder library instance.\r
             // Push node to stack.\r
@@ -187,8 +183,8 @@ public class AutogenLibOrder {
                 //\r
                 if (stackList.get(stackSize).isVisit) {\r
                     if (!isInLibInstance(orderList,\r
                 //\r
                 if (stackList.get(stackSize).isVisit) {\r
                     if (!isInLibInstance(orderList,\r
-                            stackList.get(stackSize).nodeName)) {\r
-                        orderList.add(stackList.get(stackSize).nodeName);\r
+                            stackList.get(stackSize).nodeId)) {\r
+                        orderList.add(stackList.get(stackSize).nodeId);\r
                         stackList.remove(stackSize);\r
                     }\r
                     \r
                         stackList.remove(stackSize);\r
                     }\r
                     \r
@@ -198,15 +194,15 @@ public class AutogenLibOrder {
                     //\r
                     stackList.get(stackList.size() - 1).isVisit = true;\r
                     String[] libClassList = this.libInstanceMap.get(stackList\r
                     //\r
                     stackList.get(stackList.size() - 1).isVisit = true;\r
                     String[] libClassList = this.libInstanceMap.get(stackList\r
-                            .get(stackSize).nodeName);\r
+                            .get(stackSize).nodeId);\r
                     //\r
                     // Push the node dependence library instance to the stack.\r
                     //\r
                     if (libClassList != null) {\r
                         for (int j = 0; j < libClassList.length; j++) {\r
                     //\r
                     // Push the node dependence library instance to the stack.\r
                     //\r
                     if (libClassList != null) {\r
                         for (int j = 0; j < libClassList.length; j++) {\r
-                            libInstance = this.libClassMap.get(libClassList[j]);\r
-                            if (libInstance != null\r
-                                    && !isInLibInstance(orderList, libInstance)) {\r
+                            libInstanceId = this.libClassMap.get(libClassList[j]);\r
+                            if (libInstanceId != null\r
+                                    && !isInLibInstance(orderList, libInstanceId)) {\r
                                 //\r
                                 // If and only if the currently library instance\r
                                 // is not in stack and it have constructor or \r
                                 //\r
                                 // If and only if the currently library instance\r
                                 // is not in stack and it have constructor or \r
@@ -214,7 +210,7 @@ public class AutogenLibOrder {
                                 // instacne in stack.\r
                                 //\r
                                 if (!isInStackList(stackList, this.libClassMap\r
                                 // instacne in stack.\r
                                 //\r
                                 if (!isInStackList(stackList, this.libClassMap\r
-                                        .get(libClassList[j])) && isHaveConsDestructor(libInstance)) {\r
+                                        .get(libClassList[j])) && isHaveConsDestructor(libInstanceId)) {\r
                                     stackList.add(new Node(this.libClassMap\r
                                             .get(libClassList[j]), false));\r
                                 }\r
                                     stackList.add(new Node(this.libClassMap\r
                                             .get(libClassList[j]), false));\r
                                 }\r
@@ -237,9 +233,10 @@ public class AutogenLibOrder {
       @return                 "true" the library instance in list |\r
                               "false" the library instance is not in list.\r
     **/\r
       @return                 "true" the library instance in list |\r
                               "false" the library instance is not in list.\r
     **/\r
-    private boolean isInLibInstance(List list, String instanceName) {\r
+    private boolean isInLibInstance(List<ModuleIdentification> list, ModuleIdentification instanceId) {\r
         for (int i = 0; i < list.size(); i++) {\r
         for (int i = 0; i < list.size(); i++) {\r
-            if (instanceName.equalsIgnoreCase(list.get(i).toString())) {\r
+            \r
+            if (instanceId.equals(list.get(i))) {\r
                 return true;\r
             }\r
         }\r
                 return true;\r
             }\r
         }\r
@@ -256,9 +253,9 @@ public class AutogenLibOrder {
       @return            "true" if node have in stack |\r
                          "false" if node don't in stack.\r
     **/ \r
       @return            "true" if node have in stack |\r
                          "false" if node don't in stack.\r
     **/ \r
-    private boolean isInStackList(List<Node> list, String nodeName) {\r
+    private boolean isInStackList(List<Node> list, ModuleIdentification instanceId) {\r
         for (int i = 0; i < list.size(); i++) {\r
         for (int i = 0; i < list.size(); i++) {\r
-            if (nodeName.equalsIgnoreCase(list.get(i).nodeName)) {\r
+            if (instanceId.equals(list.get(i).nodeId)) {\r
                 return true;\r
             }\r
         }\r
                 return true;\r
             }\r
         }\r
@@ -276,20 +273,16 @@ public class AutogenLibOrder {
                          "false" if library don't have constructor \r
                          and desconstructor.\r
     **/\r
                          "false" if library don't have constructor \r
                          and desconstructor.\r
     **/\r
-    private boolean isHaveConsDestructor (String libName){\r
+    private boolean isHaveConsDestructor (ModuleIdentification libNode){\r
         for (int i = 0; i < libInstanceList.size(); i++){\r
         for (int i = 0; i < libInstanceList.size(); i++){\r
-            if (libInstanceList.get(i)[0].equalsIgnoreCase(libName)){\r
-                if (libInstanceList.get(i)[1] != null || libInstanceList.get(i)[2] != null){\r
+            if (libInstanceList.get(i).libId.equals(libNode)){\r
+                if (libInstanceList.get(i).constructorName != null || libInstanceList.get(i).deconstructorName != null){\r
                     return true;\r
                 }\r
             }\r
         }\r
         return false;\r
     }\r
                     return true;\r
                 }\r
             }\r
         }\r
         return false;\r
     }\r
-\r
-    private String getStringValue(XmlObject xmlDoc) {\r
-        return xmlDoc.getDomNode().getFirstChild().getNodeValue();\r
-    }\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -299,12 +292,29 @@ public class AutogenLibOrder {
  \r
  **/\r
 class Node {\r
  \r
  **/\r
 class Node {\r
-    String nodeName;\r
+    ModuleIdentification nodeId;\r
 \r
     boolean isVisit;\r
 \r
 \r
     boolean isVisit;\r
 \r
-    Node(String name, boolean isVisit) {\r
-        this.nodeName = name;\r
+    Node(ModuleIdentification nodeId, boolean isVisit) {\r
+        this.nodeId = nodeId;\r
         this.isVisit = false;\r
     }\r
         this.isVisit = false;\r
     }\r
-}
\ No newline at end of file
+}  \r
+/**\r
+  LibraryInstance Node   \r
+  \r
+  This class is used to store LibrayInstance and it's deconstructor and constructor\r
+**/\r
+    \r
+class LibraryInstanceNode {\r
+    ModuleIdentification libId;\r
+    String deconstructorName;\r
+    String constructorName;\r
+    \r
+    LibraryInstanceNode (ModuleIdentification libId, String deconstructor, String constructor){\r
+        this.libId = libId;\r
+        this.deconstructorName = deconstructor;\r
+        this.constructorName   = constructor;\r
+    }\r
+}\r
index 2da1c6b6f58b554b855adabd6a1e3264aa5f20ed..f449cb3a7c7310fa73818444b29ee65ecc5ffc53 100644 (file)
@@ -44,6 +44,7 @@ public class CommonDefinition {
     public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION        0x00000000\r\n";\r
 \r
     public final static String includeAutogenH        = "#include    <AutoGen.h>\r\n" ;\r
     public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION        0x00000000\r\n";\r
 \r
     public final static String includeAutogenH        = "#include    <AutoGen.h>\r\n" ;\r
+    public final static String marcDefineStr          = "#define ";\r
 \r
     public final static String gEfi = "gEfi";\r
     public final static String protocolGuid = "ProtocolGuid";\r
 \r
     public final static String gEfi = "gEfi";\r
     public final static String protocolGuid = "ProtocolGuid";\r
@@ -148,10 +149,10 @@ public class CommonDefinition {
                     new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
                     new MyEnum("PEIM", ModuleTypePeim),\r
                     new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
                     new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
                     new MyEnum("PEIM", ModuleTypePeim),\r
                     new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
-                    new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
+                    new MyEnum("DXE_DRIVER", ModuleTypeDxeRuntimeDriver),\r
                     new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
                     new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
-                    new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
                     new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
                     new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
+                    new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
                     new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
                     new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };\r
     \r
                     new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
                     new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };\r
     \r
@@ -254,29 +255,64 @@ public class CommonDefinition {
       }\r
       return false;\r
     }\r
       }\r
       return false;\r
     }\r
+    \r
+    /**\r
+     * formateGuidName\r
+     * \r
+     * This function is to formate GUID to ANSI c form.\r
+     * \r
+     * @param guidNameCon\r
+     *            String of GUID.\r
+     * @return Formated GUID.\r
+     */\r
+    public static String formatGuidName(String guidNameConv) {\r
+        String[] strList;\r
+        String guid = "";\r
+        int index = 0;\r
+        if (guidNameConv\r
+                .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r
+            strList = guidNameConv.split("-");\r
+            guid = "0x" + strList[0] + ", ";\r
+            guid = guid + "0x" + strList[1] + ", ";\r
+            guid = guid + "0x" + strList[2] + ", ";\r
+            guid = guid + "{";\r
+            guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
+            guid = guid + "0x" + strList[3].substring(2, 4);\r
 \r
 \r
-               static public boolean isPeiPhaseComponent (int componentType) {\r
-                       if (ComponentTypePe32Peim == componentType\r
-                                       || ComponentTypePicPeim == componentType\r
-                                       || ComponentTypeCombinedPeimDriver == componentType\r
-                                       || ComponentTypePeiCore == componentType) {\r
-                               return true;\r
-                       }\r
-                       return false;\r
-               }\r
+            while (index < strList[4].length()) {\r
+                guid = guid + ", ";\r
+                guid = guid + "0x" + strList[4].substring(index, index + 2);\r
+                index = index + 2;\r
+            }\r
+            guid = guid + "}";\r
+            return guid;\r
+        } else if (guidNameConv\r
+                .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r
+            strList = guidNameConv.split(",");\r
 \r
 \r
-               static public boolean isPe32PeimComponent (int componentType) {\r
-                       if (ComponentTypePe32Peim == componentType) {\r
-                               return true;\r
-                       }\r
-                       return false;\r
-               }\r
+            //\r
+            // chang Microsoft specific form to ANSI c form\r
+            //\r
+            for (int i = 0; i < 3; i++) {\r
+                guid = guid + strList[i] + ",";\r
+            }\r
+            guid = guid + "{";\r
 \r
 \r
-               static public boolean isBsDriverComponent (int componentType) {\r
-                       if (ComponentTypeBsDriver == componentType) {\r
-                               return true;\r
-                       }\r
-                       return false;\r
-               }\r
-               \r
-}\r
+            for (int i = 3; i < strList.length; i++) {\r
+                if (i == strList.length - 1) {\r
+                    guid = guid + strList[i];\r
+                } else {\r
+                    guid = guid + strList[i] + ",";\r
+                }\r
+            }\r
+            guid = guid + "}";\r
+            return guid;\r
+        } else {\r
+            System.out\r
+                    .println("Check GUID Value, it don't conform to the schema!!!");\r
+            return "0";\r
+\r
+        }\r
+    }\r
+    \r
+}
\ No newline at end of file
diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/AutoGenException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/AutoGenException.java
new file mode 100644 (file)
index 0000000..0faf6c7
--- /dev/null
@@ -0,0 +1,39 @@
+/** @file\r
+  AutoGenException class.\r
+\r
+  The class handle the exception throwed by entity class.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/   \r
+package org.tianocore.build.exception;\r
+\r
+\r
+/**\r
+  The class handle the exception throwed by entity class.\r
+**/\r
+public class AutoGenException extends GenBuildException {\r
+    //static final long serialVersionUID = -8034897190740066939L;\r
+    /**\r
+      Constructure function\r
+        \r
+      @param expStr exception message string.\r
+    **/\r
+    public AutoGenException(String expStr) {\r
+        super("[AutoGenException]:" + expStr);\r
+    }\r
+    \r
+    public AutoGenException() {\r
+        super();\r
+    }\r
+    public AutoGenException(Exception e, String messsge){\r
+        super(e, messsge);\r
+    }\r
+}
\ No newline at end of file
diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/EdkException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/EdkException.java
new file mode 100644 (file)
index 0000000..8be839b
--- /dev/null
@@ -0,0 +1,36 @@
+/** @file\r
+  EntityException class.\r
+\r
+  The class handle the exception throwed by entity class.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/   \r
+package org.tianocore.build.exception;\r
+\r
+/**\r
+  The class handle the exception throwed by entity class.\r
+**/\r
+public class EdkException extends Exception {\r
+    //static final long serialVersionUID = -8034897190740066939L;\r
+    /**\r
+      Constructure function\r
+        \r
+      @param expStr exception message string.\r
+    **/\r
+    public EdkException(String expStr) {\r
+        super("[EdkException]:" + expStr);\r
+    }\r
+    \r
+    public EdkException() {\r
+        super();\r
+    }\r
+}\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java
new file mode 100644 (file)
index 0000000..ac75ca8
--- /dev/null
@@ -0,0 +1,40 @@
+/** @file\r
+  GenBuildException class.\r
+\r
+  The class handle the exception throwed by entity class.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/   \r
+package org.tianocore.build.exception;\r
+\r
+import org.tianocore.build.exception.EdkException;\r
+\r
+/**\r
+  The class handle the exception throwed by entity class.\r
+**/\r
+public class GenBuildException extends EdkException {\r
+    //static final long serialVersionUID = -8034897190740066939L;\r
+    /**\r
+      Constructure function\r
+        \r
+      @param expStr exception message string.\r
+    **/\r
+    public GenBuildException(String expStr) {\r
+        super("[GenBuildException]:" + expStr);\r
+    }\r
+    \r
+    public GenBuildException() {\r
+        super();\r
+    }\r
+    public GenBuildException(Exception e, String message){\r
+//        super(e, message);\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java
new file mode 100644 (file)
index 0000000..49d5543
--- /dev/null
@@ -0,0 +1,35 @@
+/** @file\r
+  AutoGenException class.\r
+\r
+  The class handle the exception throwed by entity class.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/   \r
+package org.tianocore.build.exception;\r
+\r
+/**\r
+  The class handle the exception throwed by entity class.\r
+**/\r
+public class PcdAutogenException extends AutoGenException {\r
+    //static final long serialVersionUID = -8034897190740066939L;\r
+    /**\r
+      Constructure function\r
+        \r
+      @param expStr exception message string.\r
+    **/\r
+    public PcdAutogenException(String expStr) {\r
+        super("[PcdAutogenException]:" + expStr);\r
+    }\r
+    \r
+    public PcdAutogenException() {\r
+        super();\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java
new file mode 100644 (file)
index 0000000..3ab2fcf
--- /dev/null
@@ -0,0 +1,41 @@
+/** @file\r
+  TianoToolsException class.\r
+\r
+  The class handle the exception throwed by entity class.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/   \r
+package org.tianocore.build.exception;\r
+\r
+import org.tianocore.build.exception.EdkException;\r
+\r
+/**\r
+  The class handle the exception throwed by entity class.\r
+**/\r
+public class TianoToolsException extends EdkException {\r
+    //static final long serialVersionUID = -8034897190740066939L;\r
+    /**\r
+      Constructure function\r
+        \r
+      @param expStr exception message string.\r
+    **/\r
+    public TianoToolsException(String expStr) {\r
+        super("[TianoToolsException]:" + expStr);\r
+    }\r
+    \r
+    public TianoToolsException() {\r
+        super();\r
+    }\r
+    \r
+    public TianoToolsException (Exception e, String message){\r
+//        super(e, message);\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java
new file mode 100644 (file)
index 0000000..afa92f4
--- /dev/null
@@ -0,0 +1,35 @@
+/** @file\r
+  XmlParseException class.\r
+\r
+  The class handle the exception throwed by entity class.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/   \r
+package org.tianocore.build.exception;\r
+\r
+/**\r
+  The class handle the exception throwed by entity class.\r
+**/\r
+public class XmlParseException extends GenBuildException {\r
+    //static final long serialVersionUID = -8034897190740066939L;\r
+    /**\r
+      Constructure function\r
+        \r
+      @param expStr exception message string.\r
+    **/\r
+    public XmlParseException(String expStr) {\r
+        super("[XmlParseException]:" + expStr);\r
+    }\r
+    \r
+    public XmlParseException() {\r
+        super();\r
+    }\r
+}
\ No newline at end of file
diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdModuleIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdModuleIdentification.java
deleted file mode 100644 (file)
index 261cf58..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/** @file\r
-  Java class FpdModuleIdentification is used to present a module identification\r
-  from BaseName, GUID, Version, PackageName, and ARCH. \r
\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-package org.tianocore.build.fpd;\r
-\r
-/**\r
-  This class is used to identify a module with BaseName, GUID, Version, PackageName\r
-  and ARCH.\r
-  \r
-  @since GenBuild 1.0\r
- **/\r
-public class FpdModuleIdentification {\r
-    \r
-    private String arch;\r
-    \r
-    private String fvBinding;\r
-    \r
-    private String baseName;\r
-    \r
-    private String packageName;\r
-    \r
-    private String guid;\r
-    \r
-    private String version;\r
-    \r
-    private String sequence;\r
-    \r
-    /**\r
-      \r
-      @param baseName the base name of the module\r
-      @param guid the GUID of the module\r
-      @param arch the ARCH of the module\r
-    **/\r
-    public FpdModuleIdentification(String baseName, String guid, String arch){\r
-        this.baseName = baseName;\r
-        this.guid = guid;\r
-        this.arch = arch;\r
-    }\r
-    \r
-    /**\r
-      Override java.lang.Object#equals. \r
-      \r
-      <p>Currently, use BaseName and ARCH to identify a module. It will enhance\r
-      in the next version. </p>\r
-      \r
-      @see java.lang.Object#equals(java.lang.Object)\r
-    **/\r
-    public boolean equals(Object obj) {\r
-        if (obj instanceof FpdModuleIdentification) {\r
-            FpdModuleIdentification moduleIdObj = (FpdModuleIdentification)obj;\r
-            if ( baseName.equalsIgnoreCase(moduleIdObj.baseName) && arch.equalsIgnoreCase(moduleIdObj.arch)) {\r
-                return true;\r
-            }\r
-            // TBD\r
-            return false;\r
-        }\r
-        else {\r
-            return super.equals(obj);\r
-        }\r
-    }\r
-    \r
-    public void setArch(String arch) {\r
-        this.arch = arch;\r
-    }\r
-\r
-    public void setFvBinding(String fvBinding) {\r
-        this.fvBinding = fvBinding;\r
-    }\r
-\r
-    public void setSequence(String sequence) {\r
-        this.sequence = sequence;\r
-    }\r
-\r
-    public String toString(){\r
-        return arch + ":" + guid + "_" + baseName;\r
-    }\r
-\r
-    public void setBaseName(String baseName) {\r
-        this.baseName = baseName;\r
-    }\r
-\r
-    public void setGuid(String guid) {\r
-        this.guid = guid;\r
-    }\r
-\r
-    public void setPackageName(String packageName) {\r
-        this.packageName = packageName;\r
-    }\r
-\r
-    public void setVersion(String version) {\r
-        this.version = version;\r
-    }\r
-\r
-    public String getArch() {\r
-        return arch;\r
-    }\r
-\r
-    public String getBaseName() {\r
-        return baseName;\r
-    }\r
-\r
-    public String getFvBinding() {\r
-        return fvBinding;\r
-    }\r
-\r
-    public String getGuid() {\r
-        return guid;\r
-    }\r
-\r
-    public String getPackageName() {\r
-        return packageName;\r
-    }\r
-\r
-    public String getSequence() {\r
-        return sequence;\r
-    }\r
-\r
-    public String getVersion() {\r
-        return version;\r
-    }\r
-}\r
index 21197b5c626ffac05961204a01cba979a2361864..59bb47faa423f88b840c24218369a6c9ac661348 100644 (file)
@@ -1,18 +1,18 @@
 /** @file\r
 /** @file\r
 This file is ANT task FpdParserTask. \r
+ This file is ANT task FpdParserTask. \r
  \r
  \r
 FpdParserTask is used to parse FPD (Framework Platform Description) and generate\r
 build.out.xml. It is for Package or Platform build use. \r
+ FpdParserTask is used to parse FPD (Framework Platform Description) and generate\r
+ build.out.xml. It is for Package or Platform build use. \r
  \r
  \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ **/\r
 package org.tianocore.build.fpd;\r
 \r
 import java.io.BufferedWriter;\r
 package org.tianocore.build.fpd;\r
 \r
 import java.io.BufferedWriter;\r
@@ -25,67 +25,67 @@ import java.util.LinkedHashSet;
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.Vector;\r
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.Vector;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.transform.OutputKeys;\r
-import javax.xml.transform.Result;\r
-import javax.xml.transform.Source;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
+import java.util.TreeMap;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Task;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Task;\r
+import org.apache.tools.ant.taskdefs.Ant;\r
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
-import org.w3c.dom.Comment;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
 \r
 \r
+import org.tianocore.build.exception.EdkException;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
-import org.tianocore.build.global.OverrideProcess;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.pcd.action.CollectPCDAction;\r
-import org.tianocore.build.pcd.action.ActionMessage;\r
-import org.tianocore.BuildOptionsDocument;\r
-import org.tianocore.FrameworkPlatformDescriptionDocument;\r
-import org.tianocore.ModuleSADocument;\r
-\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.toolchain.ToolChainAttribute;\r
+import org.tianocore.build.toolchain.ToolChainElement;\r
+import org.tianocore.build.toolchain.ToolChainMap;\r
 \r
 /**\r
 \r
 /**\r
-  <code>FpdParserTask</code> is an ANT task. The main function is parsing FPD\r
-  XML file and generating its ANT build script for Platform or Package. \r
+  <code>FpdParserTask</code> is an ANT task. The main function is parsing Framework\r
+  Platform Descritpion (FPD) XML file and generating its ANT build script for \r
+  corresponding platform.  \r
+\r
+  <p>The task sets global properties PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r
+  and BUILD_DIR. </p>\r
   \r
   \r
-  <p>The usage is (take NT32 Platform for example):</p>\r
+  <p>The task generates ${PLATFORM}_build.xml file which will be called by top level\r
+  build.xml. The task also generate Fv.inf files (File is for Tool GenFvImage) \r
+  and flash definition file (File is for Tool FlashMap) if necessary. </p>\r
+  \r
+  <p>FpdParserTask task stores all FPD information to GlobalData. And parse\r
+  tools definition file to set up compiler options for different Target and\r
+  different ToolChainTag. </p>\r
+  \r
+  <p>The method parseFpdFile is also prepared for single module build. </p>\r
   \r
   \r
+  <p>The usage is (take NT32 Platform for example):</p>\r
+\r
   <pre>\r
   <pre>\r
-    &lt;FPDParser fpdfilename="Build\Nt32.fpd" /&gt;\r
+  &lt;FPDParser platformName="Nt32" /&gt;\r
   </pre>\r
   </pre>\r
-  \r
+\r
   <p>The task will initialize all information through parsing Framework Database, \r
   SPD, Tool chain configuration files. </p>\r
   <p>The task will initialize all information through parsing Framework Database, \r
   SPD, Tool chain configuration files. </p>\r
-  \r
+\r
   @since GenBuild 1.0\r
 **/\r
 public class FpdParserTask extends Task {\r
   @since GenBuild 1.0\r
 **/\r
 public class FpdParserTask extends Task {\r
+    \r
+    private String platformName;\r
 \r
 \r
+    private File fpdFile = null;\r
+    \r
+    private PlatformIdentification platformId;\r
+    \r
     ///\r
     ///\r
-    /// FV dir: ${PLATFORM_DIR}/Build/FV\r
-    ///\r
-    public static final String FV_OUTPUT_DIR = "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "FV";\r
-\r
-    private File fpdFilename;\r
-\r
-    private File guiddatabase;\r
-\r
-    ///\r
-    /// Keep platform buildoption information\r
+    /// \r
     ///\r
     ///\r
-    public static XmlObject platformBuildOptions = null;\r
-\r
+    private String type;\r
+    \r
     ///\r
     /// Mapping from modules identification to out put file name\r
     ///\r
     ///\r
     /// Mapping from modules identification to out put file name\r
     ///\r
@@ -94,102 +94,138 @@ public class FpdParserTask extends Task {
     ///\r
     /// Mapping from FV name to its modules\r
     ///\r
     ///\r
     /// Mapping from FV name to its modules\r
     ///\r
-    private Map<String, Set<FpdModuleIdentification> > fvs = new HashMap<String, Set<FpdModuleIdentification> >();\r
+    private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
 \r
     ///\r
 \r
     ///\r
-    /// Mapping from sequence number to its modules\r
+    /// Mapping from sequence number to FV names\r
     ///\r
     ///\r
-    private Map<String, Set<FpdModuleIdentification> > sequences = new HashMap<String, Set<FpdModuleIdentification> >();\r
+    private Map<String, Set<String>> sequences = new TreeMap<String, Set<String>>();\r
 \r
     ///\r
     /// FpdParserTask can specify some ANT properties. \r
     ///\r
     private Vector<Property> properties = new Vector<Property>();\r
 \r
     ///\r
     /// FpdParserTask can specify some ANT properties. \r
     ///\r
     private Vector<Property> properties = new Vector<Property>();\r
+    \r
+    private boolean isUnified = true;\r
 \r
 \r
-    private String info = "====================================================================\n"\r
-                    + "DO NOT EDIT \n"\r
-                    + "File auto-generated by build utility\n"\r
-                    + "\n"\r
-                    + "Abstract:\n"\r
-                    + "Auto-generated ANT build file for building of EFI Modules/Platforms\n"\r
-                    + "=====================================================================";\r
 \r
     /**\r
       Public construct method. It is necessary for ANT task.\r
     **/\r
 \r
     /**\r
       Public construct method. It is necessary for ANT task.\r
     **/\r
-    public FpdParserTask () {\r
+    public FpdParserTask() {\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      ANT task's entry method. The main steps is described as following: \r
-      \r
-      <ul>\r
-        <li>Initialize global information (Framework DB, SPD files and all MSA files \r
-        listed in SPD). This step will execute only once in whole build process;</li>\r
-        <li>Parse specified FPD file; </li>\r
-        <li>Generate FV.inf files; </li>\r
-        <li>Generate build.out.xml file for Flatform or Package build; </li>\r
-        <li>Collect PCD information. </li>\r
-      </ul>\r
-      \r
-      @throws BuildException\r
-                  Surface area is not valid. \r
+     ANT task's entry method. The main steps is described as following: \r
+     \r
+     <ul>\r
+     <li>Initialize global information (Framework DB, SPD files and all MSA files \r
+     listed in SPD). This step will execute only once in whole build process;</li>\r
+     <li>Parse specified FPD file; </li>\r
+     <li>Generate FV.inf files; </li>\r
+     <li>Generate PlatformName_build.xml file for Flatform build; </li>\r
+     <li>Collect PCD information. </li>\r
+     </ul>\r
+     \r
+     @throws BuildException\r
+     Surface area is not valid. \r
     **/\r
     public void execute() throws BuildException {\r
     **/\r
     public void execute() throws BuildException {\r
-        OutputManager.update(getProject());\r
-        //\r
-        // Parse DB and SPDs files. Initialize Global Data\r
-        //\r
-        GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db", getProject()\r
-                        .getProperty("WORKSPACE_DIR"));\r
+        // Remove !!\r
+        if ( fpdFile == null) {\r
+            if (platformName == null) {\r
+                throw new BuildException("FpdParserTask parameter error. Please specify platform name or FPD file. ");\r
+            }\r
+            platformId = GlobalData.getPlatform(platformName);\r
+            fpdFile = platformId.getFpdFile();\r
+        }\r
+        \r
         //\r
         // Parse FPD file\r
         //\r
         parseFpdFile();\r
         //\r
         // Parse FPD file\r
         //\r
         parseFpdFile();\r
+        \r
+        //\r
+        // Prepare BUILD_DIR\r
         //\r
         //\r
-        // Gen Fv.inf files\r
+        isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r
+        \r
         //\r
         //\r
-        genFvInfFiles();\r
+        // Generate FDF (Flash Definition File) file\r
+        //\r
+\r
+        //\r
+        // For every Target and ToolChain\r
+        //\r
+        String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
+        for (int i = 0; i < targetList.length; i++){\r
+            String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
+            for(int j = 0; j < toolchainList.length; j++){\r
+                //\r
+                // Prepare FV_DIR\r
+                //\r
+                String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar \r
+                                + targetList[i] + File.separatorChar \r
+                                + toolchainList[j];\r
+                File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
+                fvDir.mkdirs();\r
+                getProject().setProperty("FV_DIR", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
+                \r
+                //\r
+                // Gen Fv.inf files\r
+                //\r
+                genFvInfFiles(ffsCommonDir);\r
+            }\r
+        }\r
+\r
         //\r
         // Gen build.xml\r
         //\r
         //\r
         // Gen build.xml\r
         //\r
-        genBuildFile();\r
+        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, sequences, isUnified);\r
+        fileGenerator.genBuildFile();\r
+        \r
+        //\r
+        // Ant call ${PLATFORM}_build.xml\r
         //\r
         //\r
-        // Collect PCD information \r
-        // \r
-        collectPCDInformation (); \r
+        Ant ant = new Ant();\r
+        ant.setProject(getProject());\r
+        ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r
+        ant.setTarget(type);\r
+        ant.setInheritAll(true);\r
+        ant.init();\r
+        ant.execute();\r
+        \r
+//        GlobalData.log.info("Fpd build end. ");\r
     }\r
     }\r
-    \r
+\r
     /**\r
       Generate Fv.inf files. The Fv.inf file is composed with four \r
       parts: Options, Attributes, Components and Files. The Fv.inf files \r
     /**\r
       Generate Fv.inf files. The Fv.inf file is composed with four \r
       parts: Options, Attributes, Components and Files. The Fv.inf files \r
-      will be under ${PLATFOMR_DIR}\Build\Fv.\r
-      \r
+      will be under FV_DIR.\r
+     \r
       @throws BuildException\r
       @throws BuildException\r
-              File write FV.inf files error. \r
+                  File write FV.inf files error. \r
     **/\r
     **/\r
-    private void genFvInfFiles() throws BuildException{\r
+    private void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
         String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
         for (int i = 0; i < validFv.length; i++) {\r
         String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
         for (int i = 0; i < validFv.length; i++) {\r
-            getProject().setProperty("FV_FILENAME", validFv[i].toUpperCase());\r
             //\r
             // Get all global variables from FPD and set them to properties\r
             //\r
             //\r
             // Get all global variables from FPD and set them to properties\r
             //\r
-            String[][] globalVariables = SurfaceAreaQuery\r
-                            .getFpdGlobalVariable();\r
+            String[][] globalVariables = SurfaceAreaQuery.getFpdGlobalVariable();\r
             for (int j = 0; j < globalVariables.length; j++) {\r
             for (int j = 0; j < globalVariables.length; j++) {\r
-                getProject().setProperty(globalVariables[j][0],\r
-                                globalVariables[j][1]);\r
+                getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);\r
             }\r
 \r
             }\r
 \r
-            File fvFile = new File(getProject().replaceProperties(\r
-                            FV_OUTPUT_DIR + File.separatorChar + validFv[i].toUpperCase()\r
-                                            + ".inf"));\r
+            getProject().setProperty("FV_FILENAME", validFv[i].toUpperCase());\r
+            \r
+            File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i].toUpperCase() + ".inf"));\r
             fvFile.getParentFile().mkdirs();\r
 \r
             try {\r
                 FileWriter fw = new FileWriter(fvFile);\r
                 BufferedWriter bw = new BufferedWriter(fw);\r
             fvFile.getParentFile().mkdirs();\r
 \r
             try {\r
                 FileWriter fw = new FileWriter(fvFile);\r
                 BufferedWriter bw = new BufferedWriter(fw);\r
+                \r
                 //\r
                 // Options\r
                 //\r
                 //\r
                 // Options\r
                 //\r
@@ -210,11 +246,11 @@ public class FpdParserTask extends Task {
                     }\r
                     bw.newLine();\r
                 }\r
                     }\r
                     bw.newLine();\r
                 }\r
+                \r
                 //\r
                 // Attributes;\r
                 //\r
                 //\r
                 // Attributes;\r
                 //\r
-                String[][] attributes = SurfaceAreaQuery\r
-                                .getFpdAttributes(validFv[i]);\r
+                String[][] attributes = SurfaceAreaQuery.getFpdAttributes(validFv[i]);\r
                 if (attributes.length > 0) {\r
                     bw.write("[attributes]");\r
                     bw.newLine();\r
                 if (attributes.length > 0) {\r
                     bw.write("[attributes]");\r
                     bw.newLine();\r
@@ -226,18 +262,16 @@ public class FpdParserTask extends Task {
                         }\r
                         str.append("=  ");\r
                         str.append(attributes[j][1]);\r
                         }\r
                         str.append("=  ");\r
                         str.append(attributes[j][1]);\r
-                        bw\r
-                                        .write(getProject().replaceProperties(\r
-                                                        str.toString()));\r
+                        bw.write(getProject().replaceProperties(str.toString()));\r
                         bw.newLine();\r
                     }\r
                     bw.newLine();\r
                 }\r
                         bw.newLine();\r
                     }\r
                     bw.newLine();\r
                 }\r
+                \r
                 //\r
                 // Components\r
                 //\r
                 //\r
                 // Components\r
                 //\r
-                String[][] components = SurfaceAreaQuery\r
-                                .getFpdComponents(validFv[i]);\r
+                String[][] components = SurfaceAreaQuery.getFpdComponents(validFv[i]);\r
                 if (components.length > 0) {\r
                     bw.write("[components]");\r
                     bw.newLine();\r
                 if (components.length > 0) {\r
                     bw.write("[components]");\r
                     bw.newLine();\r
@@ -249,26 +283,23 @@ public class FpdParserTask extends Task {
                         }\r
                         str.append("=  ");\r
                         str.append(components[j][1]);\r
                         }\r
                         str.append("=  ");\r
                         str.append(components[j][1]);\r
-                        bw\r
-                                        .write(getProject().replaceProperties(\r
-                                                        str.toString()));\r
+                        bw.write(getProject().replaceProperties(str.toString()));\r
                         bw.newLine();\r
                     }\r
                     bw.newLine();\r
                 }\r
                         bw.newLine();\r
                     }\r
                     bw.newLine();\r
                 }\r
+                \r
                 //\r
                 // Files\r
                 //\r
                 Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i].toUpperCase());\r
                 if (filesSet != null) {\r
                 //\r
                 // Files\r
                 //\r
                 Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i].toUpperCase());\r
                 if (filesSet != null) {\r
-                    FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet\r
-                                    .size()]);\r
+                    FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet.size()]);\r
                     bw.write("[files]");\r
                     bw.newLine();\r
                     for (int j = 0; j < files.length; j++) {\r
                     bw.write("[files]");\r
                     bw.newLine();\r
                     for (int j = 0; j < files.length; j++) {\r
-                        String str = outfiles.get(files[j]);\r
-                        bw.write(getProject().replaceProperties(\r
-                                        "EFI_FILE_NAME = " + str));\r
+                        String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);\r
+                        bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r
                         bw.newLine();\r
                     }\r
                 }\r
                         bw.newLine();\r
                     }\r
                 }\r
@@ -276,537 +307,286 @@ public class FpdParserTask extends Task {
                 bw.close();\r
                 fw.close();\r
             } catch (Exception e) {\r
                 bw.close();\r
                 fw.close();\r
             } catch (Exception e) {\r
-                throw new BuildException("Generate Fv.inf file failed. \n" + e.getMessage());\r
+                e.printStackTrace();\r
+                throw new BuildException("Generate FV file [" + fvFile.getPath() + "] failed. \n" + e.getMessage());\r
             }\r
         }\r
     }\r
             }\r
         }\r
     }\r
+    /**\r
+      This method is used for Single Module Build.\r
+      \r
+      \r
+      @throws BuildException\r
+                  FPD file is not valid. \r
+    **/\r
+    public void parseFpdFile(File fpdFile) throws BuildException {\r
+        this.fpdFile = fpdFile;\r
+        parseFpdFile();\r
+    }\r
 \r
     /**\r
       Parse FPD file. \r
 \r
     /**\r
       Parse FPD file. \r
-    \r
+     \r
       @throws BuildException\r
       @throws BuildException\r
-              FPD file is not valid. \r
-    **/\r
+                  FPD file is not valid. \r
+     **/\r
     private void parseFpdFile() throws BuildException {\r
         try {\r
     private void parseFpdFile() throws BuildException {\r
         try {\r
-            FrameworkPlatformDescriptionDocument doc = (FrameworkPlatformDescriptionDocument) XmlObject.Factory\r
-                            .parse(fpdFilename);\r
-            if ( ! doc.validate() ){\r
-                throw new BuildException("FPD file is invalid.");\r
+            XmlObject doc = XmlObject.Factory.parse(fpdFile);\r
+            \r
+            if (!doc.validate()) {\r
+                throw new BuildException("Platform Surface Area file [" + fpdFile.getPath() + "] is invalid.");\r
             }\r
             }\r
-            platformBuildOptions = doc.getFrameworkPlatformDescription()\r
-                            .getBuildOptions();\r
-            HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-            map.put("FrameworkPlatformDescription", doc);\r
+            \r
+            Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
+            map.put("PlatformSurfaceArea", doc);\r
             SurfaceAreaQuery.setDoc(map);\r
             SurfaceAreaQuery.setDoc(map);\r
+            \r
+            //\r
+            // Initialize\r
+            //\r
+            platformId = SurfaceAreaQuery.getFpdHeader();\r
+            platformId.setFpdFile(fpdFile);\r
+            getProject().setProperty("PLATFORM", platformId.getName());\r
+            getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+            getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
+\r
+            //\r
+            // Build mode. User-defined output dir. \r
+            //\r
+            String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r
+            String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r
+\r
+            OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);\r
+\r
+            //\r
+            // TBD. Deal PCD and BuildOption related Info\r
+            //\r
+            GlobalData.setFpdBuildOptions(SurfaceAreaQuery.getFpdBuildOptions());\r
+            \r
+            GlobalData.setToolChainPlatformInfo(SurfaceAreaQuery.getFpdToolChainInfo());\r
+            \r
             //\r
             // Parse all list modules SA\r
             //\r
             parseModuleSAFiles();\r
             //\r
             // Parse all list modules SA\r
             //\r
             parseModuleSAFiles();\r
+\r
+            //\r
+            // TBD. Deal PCD and BuildOption related Info\r
+            //\r
+            parseToolChainFamilyOptions();\r
+            parseToolChainOptions();\r
+\r
             SurfaceAreaQuery.setDoc(map);\r
         } catch (Exception e) {\r
             SurfaceAreaQuery.setDoc(map);\r
         } catch (Exception e) {\r
-            throw new BuildException("Load FPD file [" + fpdFilename.getPath()\r
-                            + "] error. \n" + e.getMessage());\r
+            e.printStackTrace();\r
+            throw new BuildException("Load FPD file [" + fpdFile.getPath() + "] error. \n" + e.getMessage());\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
+\r
+    \r
     /**\r
       Parse all modules listed in FPD file. \r
     **/\r
     /**\r
       Parse all modules listed in FPD file. \r
     **/\r
-    private void parseModuleSAFiles() {\r
-        ModuleSADocument.ModuleSA[] moduleSAs = SurfaceAreaQuery\r
-                        .getFpdModules();\r
+    private void parseModuleSAFiles() throws EdkException{\r
+        Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
+        System.out.println("Nubmer: ##" + moduleSAs.size());\r
         //\r
         // For every Module lists in FPD file.\r
         //\r
         //\r
         // For every Module lists in FPD file.\r
         //\r
-        for (int i = 0; i < moduleSAs.length; i++) {\r
-            String defaultFv = "NULL";\r
-            String defaultArch = "IA32";\r
-            String baseName = moduleSAs[i].getModuleName();\r
-            if (baseName == null) {\r
-                System.out.println("Warning: Module Name is not specified.");\r
-                continue;\r
-            }\r
-            String fvBinding = moduleSAs[i].getFvBinding();\r
-            //\r
-            // If the module do not specify any FvBinding, use the default value.\r
-            // Else update the default FvBinding value to this value.\r
+        Set<FpdModuleIdentification> keys = moduleSAs.keySet();\r
+        Iterator iter = keys.iterator();\r
+        while (iter.hasNext()) {\r
+            FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
+            \r
             //\r
             //\r
-            if (fvBinding == null) {\r
-                fvBinding = defaultFv;\r
-            }\r
-            else {\r
-                defaultFv = fvBinding;\r
-            }\r
-            String arch;\r
+            // Judge if Module is existed? \r
+            // TBD\r
+            \r
+            GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r
+\r
             //\r
             //\r
-            // If the module do not specify any Arch, use the default value.\r
-            // Else update the default Arch value to this value.\r
+            // Put fpdModuleId to the corresponding FV\r
             //\r
             //\r
-            if (moduleSAs[i].getArch() == null ){\r
-                arch = defaultArch;\r
-            }\r
-            else {\r
-                arch = moduleSAs[i].getArch().toString();\r
-                defaultArch = arch;\r
-            }\r
-            Map<String, XmlObject> msaMap = GlobalData.getNativeMsa(baseName);\r
-            Map<String, XmlObject> mbdMap = GlobalData.getNativeMbd(baseName);\r
-            Map<String, XmlObject> fpdMap = new HashMap<String, XmlObject>();\r
-            Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
+            SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
+            String fvBinding = SurfaceAreaQuery.getModuleFvBindingKeyword();\r
+            SurfaceAreaQuery.pop();\r
+\r
+            fpdModuleId.setFvBinding(fvBinding);\r
+            String fvSequence = fpdModuleId.getSequence();\r
+            updateFvs(fvSequence, fvBinding, fpdModuleId);\r
+            \r
             //\r
             //\r
-            // Whether the Module SA has parsed before or not\r
+            // Prepare for out put file name\r
             //\r
             //\r
-            if (!GlobalData.isModuleParsed(baseName)) {\r
-                OverrideProcess op = new OverrideProcess();\r
-                //\r
-                // using overriding rules\r
-                // Here we can also put platform Build override\r
-                //\r
-                map = op.override(mbdMap, msaMap);\r
-                fpdMap = getPlatformOverrideInfo(moduleSAs[i]);\r
-                XmlObject buildOption = (XmlObject)fpdMap.get("BuildOptions");\r
-                buildOption = (XmlObject)fpdMap.get("PackageDependencies");\r
-                buildOption = (XmlObject)fpdMap.get("BuildOptions");\r
-                buildOption = op.override(buildOption, platformBuildOptions);\r
-                fpdMap.put("BuildOptions", ((BuildOptionsDocument)buildOption).getBuildOptions());\r
-                Map<String, XmlObject> overrideMap = op.override(fpdMap, OverrideProcess.deal(map));\r
-                GlobalData.registerModule(baseName, overrideMap);\r
-            } else {\r
-                map = GlobalData.getDoc(baseName);\r
+            ModuleIdentification moduleId = fpdModuleId.getModule();\r
+            SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
+            String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
+            SurfaceAreaQuery.pop();\r
+            if (baseName == null) {\r
+                baseName = moduleId.getName();\r
             }\r
             }\r
-            SurfaceAreaQuery.setDoc(map);\r
-            String guid = SurfaceAreaQuery.getModuleGuid();\r
-            String componentType = SurfaceAreaQuery.getComponentType();\r
-            FpdModuleIdentification moduleId = new FpdModuleIdentification(baseName, guid, arch);\r
-            updateFvs(fvBinding, moduleId);\r
-            outfiles.put(moduleId, "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar \r
-                            + "${TARGET}" + File.separatorChar + arch\r
-                            + File.separatorChar + guid + "-" + baseName\r
-                            + getSuffix(componentType));\r
+            outfiles.put(fpdModuleId, fpdModuleId.getArch() + File.separatorChar \r
+                         + moduleId.getGuid() + "-" + baseName \r
+                         + getSuffix(moduleId.getModuleType()));\r
+\r
+            //\r
+            // parse module build options, if any\r
+            // \r
+            SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
+            GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r
+            GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r
+            SurfaceAreaQuery.pop();\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
-    /**\r
-      Add the current module to corresponding FV. \r
-    \r
-      @param fvName current FV name\r
-      @param moduleName current module identification\r
-    **/\r
-    private void updateFvs(String fvName, FpdModuleIdentification moduleName) {\r
-        String upcaseFvName = fvName.toUpperCase();\r
-        if (fvs.containsKey(upcaseFvName)) {\r
-            Set<FpdModuleIdentification> set = fvs.get(upcaseFvName);\r
-            set.add(moduleName);\r
-        } else {\r
-            Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
-            set.add(moduleName);\r
-            fvs.put(upcaseFvName, set);\r
+    private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
+        String[][] options = SurfaceAreaQuery.getModuleBuildOptions(toolChainFamilyFlag);\r
+        if (options == null || options.length == 0) {\r
+            return null;\r
         }\r
         }\r
+        return parseOptions(options);\r
     }\r
     }\r
-\r
-    /**\r
-      Get the suffix based on component type. Current relationship are listed:  \r
-      \r
-      <pre>\r
-        <b>ComponentType</b>   <b>Suffix</b>\r
-           APPLICATION          .APP\r
-           SEC                  .SEC\r
-           PEI_CORE             .PEI\r
-           PE32_PEIM            .PEI\r
-           RELOCATABLE_PEIM     .PEI\r
-           PIC_PEIM             .PEI\r
-           COMBINED_PEIM_DRIVER .PEI\r
-           TE_PEIM              .PEI\r
-           LOGO                 .FFS\r
-           others               .DXE\r
-      </pre>\r
     \r
     \r
-      @param componentType component type\r
-      @return\r
-      @throws BuildException\r
-              If component type is null\r
-    **/\r
-    public static String getSuffix(String componentType) throws BuildException{\r
-        if (componentType == null) {\r
-            throw new BuildException("Component type is not specified.");\r
+    private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
+        String[][] options = SurfaceAreaQuery.getPlatformBuildOptions(toolChainFamilyFlag);\r
+        if (options == null || options.length == 0) {\r
+            return null;\r
         }\r
         }\r
-        String str = ".DXE";\r
-        if (componentType.equalsIgnoreCase("APPLICATION")) {\r
-            str = ".APP";\r
-        } else if (componentType.equalsIgnoreCase("SEC")) {\r
-            str = ".SEC";\r
-        } else if (componentType.equalsIgnoreCase("PEI_CORE")) {\r
-            str = ".PEI";\r
-        } else if (componentType.equalsIgnoreCase("PE32_PEIM")) {\r
-            str = ".PEI";\r
-        } else if (componentType.equalsIgnoreCase("RELOCATABLE_PEIM")) {\r
-            str = ".PEI";\r
-        } else if (componentType.equalsIgnoreCase("PIC_PEIM")) {\r
-            str = ".PEI";\r
-        } else if (componentType.equalsIgnoreCase("COMBINED_PEIM_DRIVER")) {\r
-            str = ".PEI";\r
-        } else if (componentType.equalsIgnoreCase("TE_PEIM")) {\r
-            str = ".PEI";\r
-        } else if (componentType.equalsIgnoreCase("LOGO")) {\r
-            str = ".FFS";\r
-        }\r
-        return str;\r
+        return parseOptions(options);\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      Parse module surface are info described in FPD file and put them into map. \r
-      \r
-      @param sa module surface area info descibed in FPD file\r
-      @return map list with top level elements\r
-    **/\r
-    private Map<String, XmlObject> getPlatformOverrideInfo(\r
-                    ModuleSADocument.ModuleSA sa) {\r
-        Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-        map.put("SourceFiles", sa.getSourceFiles());\r
-        map.put("Includes", sa.getIncludes());\r
-        map.put("PackageDependencies", null);\r
-        map.put("Libraries", sa.getLibraries());\r
-        map.put("Protocols", sa.getProtocols());\r
-        map.put("Events", sa.getEvents());\r
-        map.put("Hobs", sa.getHobs());\r
-        map.put("PPIs", sa.getPPIs());\r
-        map.put("Variables", sa.getVariables());\r
-        map.put("BootModes", sa.getBootModes());\r
-        map.put("SystemTables", sa.getSystemTables());\r
-        map.put("DataHubs", sa.getDataHubs());\r
-        map.put("Formsets", sa.getFormsets());\r
-        map.put("Guids", sa.getGuids());\r
-        map.put("Externs", sa.getExterns());\r
-        map.put("BuildOptions", sa.getBuildOptions());//platformBuildOptions);\r
+    private ToolChainMap parseOptions(String[][] options) throws EdkException {\r
+        ToolChainMap map = new ToolChainMap();\r
+        int flagIndex = ToolChainElement.ATTRIBUTE.value;\r
+\r
+        for (int i = 0; i < options.length; ++i) {\r
+            String flagString = options[i][flagIndex];\r
+            if (flagString == null) {\r
+                flagString = "";\r
+            }\r
+            options[i][flagIndex] = ToolChainAttribute.FLAGS + "";\r
+            map.put(options[i], flagString.trim());\r
+        }\r
+\r
         return map;\r
     }\r
         return map;\r
     }\r
+    \r
+    private void parseToolChainFamilyOptions() throws EdkException {\r
+        GlobalData.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));\r
+    }\r
+\r
+    private void parseToolChainOptions() throws EdkException {\r
+        GlobalData.setPlatformToolChainOption(parsePlatformBuildOptions(false));\r
+    }\r
 \r
     /**\r
 \r
     /**\r
-      Generate build.out.xml file.\r
-      \r
-      @throws BuildException\r
-              build.out.xml XML document create error\r
+      Add the current module to corresponding FV. \r
+     \r
+      @param fvName current FV name\r
+      @param moduleName current module identification\r
     **/\r
     **/\r
-    private void genBuildFile() throws BuildException {\r
-        DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
-        try {\r
-            DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
-            Document document = dombuilder.newDocument();\r
-            Comment rootComment = document.createComment(info);\r
-            //\r
-            // create root element and its attributes\r
-            //\r
-            Element root = document.createElement("project");\r
-            root.setAttribute("name", getProject().getProperty("PLATFORM"));\r
-            root.setAttribute("default", "main");\r
-            root.setAttribute("basedir", ".");\r
-            //\r
-            // element for External ANT tasks\r
-            //\r
-            root.appendChild(document.createComment("Apply external ANT tasks"));\r
-            Element ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "GenBuild.tasks");\r
-            root.appendChild(ele);\r
-\r
-            ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "frameworktasks.tasks");\r
-            root.appendChild(ele);\r
-\r
-            ele = document.createElement("property");\r
-            ele.setAttribute("environment", "env");\r
-            root.appendChild(ele);\r
-            //\r
-            // Default Target\r
-            //\r
-            root.appendChild(document.createComment("Default target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "main");\r
-            ele.setAttribute("depends", "modules, fvs");\r
-            root.appendChild(ele);\r
-            //\r
-            // Modules Target\r
-            //\r
-            root.appendChild(document.createComment("Modules target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "modules");\r
-\r
-            Set set = outfiles.keySet();\r
-            Iterator iter = set.iterator();\r
-            while (iter.hasNext()) {\r
-                FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
-                String baseName = moduleId.getBaseName();\r
-                Element moduleEle = document.createElement("ant");\r
-                moduleEle.setAttribute("antfile", GlobalData\r
-                                .getModulePath(baseName)\r
-                                + File.separatorChar + "build.xml");\r
-                moduleEle.setAttribute("target", baseName);\r
-                //\r
-                // ARCH\r
-                //\r
-                Element property = document.createElement("property");\r
-                property.setAttribute("name", "ARCH");\r
-                property.setAttribute("value", moduleId.getArch());\r
-                moduleEle.appendChild(property);\r
-                //\r
-                // PACKAGE_DIR\r
-                //\r
-                property = document.createElement("property");\r
-                property.setAttribute("name", "PACKAGE_DIR");\r
-                property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
-                                + GlobalData.getPackagePathForModule(baseName));\r
-                moduleEle.appendChild(property);\r
-                //\r
-                // PACKAGE\r
-                //\r
-                property = document.createElement("property");\r
-                property.setAttribute("name", "PACKAGE");\r
-                property.setAttribute("value", GlobalData\r
-                                .getPackageNameForModule(baseName));\r
-                moduleEle.appendChild(property);\r
-                ele.appendChild(moduleEle);\r
-            }\r
-            root.appendChild(ele);\r
-            //\r
-            // FVS Target\r
-            //\r
-            root.appendChild(document.createComment("FVs target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "fvs");\r
-\r
-            String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
-            for (int i = 0; i < validFv.length; i++) {\r
-                String inputFile = FV_OUTPUT_DIR + "" + File.separatorChar\r
-                                + validFv[i].toUpperCase() + ".inf";\r
-                Element fvEle = document.createElement("genfvimage");\r
-                fvEle.setAttribute("infFile", inputFile);\r
-                ele.appendChild(fvEle);\r
-                Element moveEle = document.createElement("move");\r
-                moveEle.setAttribute("file", validFv[i].toUpperCase() + ".fv");\r
-                moveEle.setAttribute("todir", FV_OUTPUT_DIR);\r
-                ele.appendChild(moveEle);\r
-            }\r
-            root.appendChild(ele);\r
-            \r
-            boolean isUnified = false;\r
-            BuildOptionsDocument.BuildOptions buildOptions = (BuildOptionsDocument.BuildOptions)platformBuildOptions;\r
-            if (buildOptions.getOutputDirectory() != null){\r
-                if (buildOptions.getOutputDirectory().getIntermediateDirectories() != null){\r
-                    if (buildOptions.getOutputDirectory().getIntermediateDirectories().toString().equalsIgnoreCase("UNIFIED")){\r
-                        isUnified = true;\r
-                    }\r
-                }\r
-            }\r
+    private void updateFvs(String fvSequence, String fvName, FpdModuleIdentification fpdModuleId) {\r
+        String upcaseFvName = fvName.toUpperCase();\r
+        String[] fvNameArray = upcaseFvName.split("[, \t]+");\r
+        for (int i = 0; i < fvNameArray.length; i++) {\r
             //\r
             //\r
-            // Clean Target\r
+            // Put module to corresponding fvName\r
             //\r
             //\r
-            root.appendChild(document.createComment("Clean target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "clean");\r
-            \r
-            if (isUnified) {\r
-                Element cleanEle = document.createElement("delete");\r
-                cleanEle.setAttribute("includeemptydirs", "true");\r
-                Element filesetEle = document.createElement("fileset");\r
-                filesetEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r
-                filesetEle.setAttribute("includes", "**/OUTPUT/**");\r
-                cleanEle.appendChild(filesetEle);\r
-                ele.appendChild(cleanEle);\r
+            if (fvs.containsKey(fvNameArray[i])) {\r
+                Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);\r
+                set.add(fpdModuleId);\r
             }\r
             else {\r
             }\r
             else {\r
-                set = outfiles.keySet();\r
-                iter = set.iterator();\r
-                while (iter.hasNext()) {\r
-                    FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
-                    String baseName = moduleId.getBaseName();\r
-    \r
-                    Element ifEle = document.createElement("if");\r
-                    Element availableEle = document.createElement("available");\r
-                    availableEle.setAttribute("file", GlobalData\r
-                                    .getModulePath(baseName)\r
-                                    + File.separatorChar + "build.xml");\r
-                    ifEle.appendChild(availableEle);\r
-                    Element elseEle = document.createElement("then");\r
-    \r
-                    Element moduleEle = document.createElement("ant");\r
-                    moduleEle.setAttribute("antfile", GlobalData\r
-                                    .getModulePath(baseName)\r
-                                    + File.separatorChar + "build.xml");\r
-                    moduleEle.setAttribute("target", baseName + "_clean");\r
-                    //\r
-                    // ARCH\r
-                    //\r
-                    Element property = document.createElement("property");\r
-                    property.setAttribute("name", "ARCH");\r
-                    property.setAttribute("value", moduleId.getArch());\r
-                    moduleEle.appendChild(property);\r
-                    //\r
-                    // PACKAGE_DIR\r
-                    //\r
-                    property = document.createElement("property");\r
-                    property.setAttribute("name", "PACKAGE_DIR");\r
-                    property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
-                                    + GlobalData.getPackagePathForModule(baseName));\r
-                    moduleEle.appendChild(property);\r
-                    //\r
-                    // PACKAGE\r
-                    //\r
-                    property = document.createElement("property");\r
-                    property.setAttribute("name", "PACKAGE");\r
-                    property.setAttribute("value", GlobalData\r
-                                    .getPackageNameForModule(baseName));\r
-                    moduleEle.appendChild(property);\r
-                    elseEle.appendChild(moduleEle);\r
-                    ifEle.appendChild(elseEle);\r
-                    ele.appendChild(ifEle);\r
-                }\r
+                Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
+                set.add(fpdModuleId);\r
+                fvs.put(fvNameArray[i], set);\r
             }\r
             }\r
-            root.appendChild(ele);\r
+            \r
             //\r
             //\r
-            // Deep Clean Target\r
+            // Put fvName to corresponding fvSequence\r
             //\r
             //\r
-            root.appendChild(document.createComment("Clean All target"));\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "cleanall");\r
-\r
-            if (isUnified) {\r
-                Element cleanAllEle = document.createElement("delete");\r
-                cleanAllEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r
-                ele.appendChild(cleanAllEle);\r
+            if (sequences.containsKey(fvSequence)) {\r
+                Set<String> set = sequences.get(fvSequence);\r
+                set.add(fvNameArray[i]);\r
             }\r
             else {\r
             }\r
             else {\r
-                set = outfiles.keySet();\r
-                iter = set.iterator();\r
-                while (iter.hasNext()) {\r
-                    FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
-                    String baseName = moduleId.getBaseName();\r
-    \r
-                    Element ifEle = document.createElement("if");\r
-                    Element availableEle = document.createElement("available");\r
-                    availableEle.setAttribute("file", GlobalData\r
-                                    .getModulePath(baseName)\r
-                                    + File.separatorChar + "build.xml");\r
-                    ifEle.appendChild(availableEle);\r
-                    Element elseEle = document.createElement("then");\r
-    \r
-                    Element moduleEle = document.createElement("ant");\r
-                    moduleEle.setAttribute("antfile", GlobalData\r
-                                    .getModulePath(baseName)\r
-                                    + File.separatorChar + "build.xml");\r
-                    moduleEle.setAttribute("target", baseName + "_cleanall");\r
-                    //\r
-                    // ARCH\r
-                    //\r
-                    Element property = document.createElement("property");\r
-                    property.setAttribute("name", "ARCH");\r
-                    property.setAttribute("value", moduleId.getArch());\r
-                    moduleEle.appendChild(property);\r
-                    //\r
-                    // PACKAGE_DIR\r
-                    //\r
-                    property = document.createElement("property");\r
-                    property.setAttribute("name", "PACKAGE_DIR");\r
-                    property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
-                                    + GlobalData.getPackagePathForModule(baseName));\r
-                    moduleEle.appendChild(property);\r
-                    //\r
-                    // PACKAGE\r
-                    //\r
-                    property = document.createElement("property");\r
-                    property.setAttribute("name", "PACKAGE");\r
-                    property.setAttribute("value", GlobalData\r
-                                    .getPackageNameForModule(baseName));\r
-                    moduleEle.appendChild(property);\r
-                    elseEle.appendChild(moduleEle);\r
-                    ifEle.appendChild(elseEle);\r
-                    ele.appendChild(ifEle);\r
-                }\r
+                Set<String> set = new LinkedHashSet<String>();\r
+                set.add(fvNameArray[i]);\r
+                sequences.put(fvSequence, set);\r
             }\r
             }\r
-            root.appendChild(ele);\r
-            \r
-            document.appendChild(rootComment);\r
-            document.appendChild(root);\r
-            //\r
-            // Prepare the DOM document for writing\r
-            //\r
-            Source source = new DOMSource(document);\r
-            //\r
-            // Prepare the output file\r
-            //\r
-            File file = new File(getProject().getProperty("PLATFORM_DIR")\r
-                            + File.separatorChar + "build.out.xml");\r
-            //\r
-            // generate all directory path\r
-            //\r
-            (new File(file.getParent())).mkdirs();\r
-            Result result = new StreamResult(file);\r
-            //\r
-            // Write the DOM document to the file\r
-            //\r
-            Transformer xformer = TransformerFactory.newInstance()\r
-                            .newTransformer();\r
-            xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
-            xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
-            xformer.transform(source, result);\r
-        } catch (Exception ex) {\r
-            throw new BuildException("Generate build.out.xml failed. \n" + ex.getMessage());\r
         }\r
     }\r
 \r
     /**\r
         }\r
     }\r
 \r
     /**\r
-      Add a property. \r
+      Get the suffix based on module type. Current relationship are listed:  \r
       \r
       \r
-      @param p property\r
+      <pre>\r
+      <b>ModuleType</b>     <b>Suffix</b>\r
+      BASE                 .FFS\r
+      SEC                  .SEC\r
+      PEI_CORE             .PEI\r
+      PEIM                 .PEI\r
+      DXE_CORE             .DXE\r
+      DXE_DRIVER           .DXE\r
+      DXE_RUNTIME_DRIVER   .DXE\r
+      DXE_SAL_DRIVER       .DXE\r
+      DXE_SMM_DRIVER       .DXE\r
+      TOOL                 .FFS\r
+      UEFI_DRIVER          .DXE\r
+      UEFI_APPLICATION     .APP\r
+      USER_DEFINED         .FFS\r
+      </pre>\r
+     \r
+      @param moduleType module type\r
+      @return\r
+      @throws BuildException\r
+      If module type is null\r
     **/\r
     **/\r
-    public void addProperty(Property p) {\r
-        properties.addElement(p);\r
-    }\r
+    public static String getSuffix(String moduleType) throws BuildException {\r
+        if (moduleType == null) {\r
+            throw new BuildException("Module type is not specified.");\r
+        }\r
 \r
 \r
-    /**\r
-      Get FPD file name.\r
-       \r
-      @return FPD file name.\r
-    **/\r
-    public File getFpdFilename() {\r
-        return fpdFilename;\r
+        String[][] suffix = { { "BASE", ".FFS"},\r
+                              { "SEC", ".SEC" }, { "PEI_CORE", ".PEI" }, \r
+                              { "PEIM", ".PEI" }, { "DXE_CORE", ".DXE" },\r
+                              { "DXE_DRIVER", ".DXE" }, { "DXE_RUNTIME_DRIVER", ".DXE" }, \r
+                              { "DXE_SAL_DRIVER", ".DXE" }, { "DXE_SMM_DRIVER", ".DXE" }, \r
+                              { "TOOL", ".FFS" }, { "UEFI_DRIVER", ".DXE" },\r
+                              { "UEFI_APPLICATION", ".APP" }, { "USER_DEFINED", ".FFS" } };\r
+        \r
+        for (int i = 0; i < suffix.length; i++) {\r
+            if (suffix[i][0].equalsIgnoreCase(moduleType)) {\r
+                return suffix[i][1];\r
+            }\r
+        }\r
+        //\r
+        // Default is '.FFS'\r
+        //\r
+        return ".FFS";\r
     }\r
     }\r
-\r
     /**\r
     /**\r
-      Set FPD file name.\r
-      \r
-      @param fpdFilename FPD file name\r
-    **/\r
-    public void setFpdFilename(File fpdFilename) {\r
-        this.fpdFilename = fpdFilename;\r
+     Add a property. \r
+     \r
+     @param p property\r
+     **/\r
+    public void addProperty(Property p) {\r
+        properties.addElement(p);\r
     }\r
 \r
     }\r
 \r
-    public File getGuiddatabase() {\r
-        return guiddatabase;\r
+    public void setPlatformName(String platformName) {\r
+        this.platformName = platformName;\r
     }\r
 \r
     }\r
 \r
-    public void setGuiddatabase(File guiddatabase) {\r
-        this.guiddatabase = guiddatabase;\r
+    public void setFpdFile(File fpdFile) {\r
+        this.fpdFile = fpdFile;\r
     }\r
 \r
     }\r
 \r
-    public void collectPCDInformation() {\r
-        String           exceptionString = null;\r
-        CollectPCDAction collectAction   = new CollectPCDAction ();\r
-        //\r
-        // Collect all PCD information from FPD to MSA, and get help information from SPD.\r
-        // These all information will be stored into memory database for future usage such \r
-        // as autogen.\r
-        //\r
-        try {\r
-            collectAction.perform (getProject().getProperty("WORKSPACE_DIR"),\r
-                                   fpdFilename.getPath(),\r
-                                   ActionMessage.MAX_MESSAGE_LEVEL\r
-                                   );\r
-        } catch (Exception exp) {\r
-            exceptionString = exp.getMessage();\r
-            if (exceptionString == null) {\r
-                exceptionString = "[Internal Error]Pcd tools catch a internel errors, Please report this bug into TianoCore or send email to Wang, scott or Lu, ken!";\r
-            }\r
-            throw new BuildException (String.format("Fail to do PCD preprocess from FPD file: %s", exceptionString));\r
-        }\r
+    public void setType(String type) {\r
+        this.type = type;\r
     }\r
     }\r
+    \r
+\r
 }\r
 }\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java
new file mode 100644 (file)
index 0000000..b41ea21
--- /dev/null
@@ -0,0 +1,479 @@
+/** @file\r
\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ **/\r
+package org.tianocore.build.fpd;\r
+\r
+import java.io.File;\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+import javax.xml.transform.OutputKeys;\r
+import javax.xml.transform.Result;\r
+import javax.xml.transform.Source;\r
+import javax.xml.transform.Transformer;\r
+import javax.xml.transform.TransformerFactory;\r
+import javax.xml.transform.dom.DOMSource;\r
+import javax.xml.transform.stream.StreamResult;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.Project;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.w3c.dom.Comment;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+\r
+public class PlatformBuildFileGenerator {\r
+\r
+    private String platformName;\r
+    \r
+    ///\r
+    /// Mapping from modules identification to out put file name\r
+    ///\r
+    private Map<FpdModuleIdentification, String> outfiles;\r
+\r
+    ///\r
+    /// Mapping from FV name to its modules\r
+    ///\r
+    private Map<String, Set<FpdModuleIdentification>> fvs;\r
+\r
+    ///\r
+    /// Mapping from sequence number to FV names\r
+    ///\r
+    private Map<String, Set<String>> sequences;\r
+    \r
+    private boolean isUnified = true;\r
+    \r
+    private Project project;\r
+    \r
+    private String info = "DO NOT EDIT \n" \r
+        + "File auto-generated by build utility\n" \r
+        + "\n" \r
+        + "Abstract:\n"\r
+        + "Auto-generated ANT build file for building of EFI Modules/Platforms\n";\r
+\r
+    public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, Map<String, Set<String>> sequences, boolean isUnified){\r
+        this.project = project;\r
+        this.outfiles = outfiles;\r
+        this.fvs = fvs;\r
+        this.sequences = sequences;\r
+        this.isUnified = isUnified;\r
+        this.platformName = project.getProperty("PLATFORM");\r
+    }\r
+    \r
+    /**\r
+      Generate build.out.xml file.\r
+     \r
+      @throws BuildException\r
+                  build.out.xml XML document create error\r
+    **/\r
+    public void genBuildFile() throws BuildException {\r
+        DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
+        try {\r
+            DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
+            Document document = dombuilder.newDocument();\r
+            Comment rootComment = document.createComment(info);\r
+            //\r
+            // create root element and its attributes\r
+            //\r
+            Element root = document.createElement("project");\r
+            root.setAttribute("name", project.getProperty("PLATFORM"));\r
+            root.setAttribute("default", "all");\r
+            root.setAttribute("basedir", ".");\r
+            \r
+            //\r
+            // element for External ANT tasks\r
+            //\r
+            root.appendChild(document.createComment("Apply external ANT tasks"));\r
+            Element ele = document.createElement("taskdef");\r
+            ele.setAttribute("resource", "GenBuild.tasks");\r
+            root.appendChild(ele);\r
+\r
+            ele = document.createElement("taskdef");\r
+            ele.setAttribute("resource", "frameworktasks.tasks");\r
+            root.appendChild(ele);\r
+\r
+            ele = document.createElement("property");\r
+            ele.setAttribute("environment", "env");\r
+            root.appendChild(ele);\r
+            \r
+            Set<String> sequenceKeys = sequences.keySet();\r
+            Iterator sequenceIter = sequenceKeys.iterator();\r
+            String dependsStr = "";\r
+            while (sequenceIter.hasNext()) {\r
+                String num = (String)sequenceIter.next();\r
+                if (dependsStr.length() > 0) {\r
+                    dependsStr += " , ";\r
+                }\r
+                dependsStr += "modules" + num + ", fvs" + num;\r
+            }\r
+            \r
+            //\r
+            // Default Target\r
+            //\r
+            root.appendChild(document.createComment("Default target"));\r
+            ele = document.createElement("target");\r
+            ele.setAttribute("name", "all");\r
+            ele.setAttribute("depends", dependsStr + ", userextensions");\r
+            root.appendChild(ele);\r
+            \r
+            //\r
+            // Modules and Fvs Target\r
+            //\r
+            sequenceIter = sequenceKeys.iterator();\r
+            while (sequenceIter.hasNext()) {\r
+                String num = (String)sequenceIter.next();\r
+                applyModules(document, root, num);\r
+                applyFvs(document, root, num);\r
+            }\r
+\r
+            //\r
+            // Clean Target\r
+            //\r
+            applyClean(document, root);\r
+            \r
+            //\r
+            // Deep Clean Target\r
+            //\r
+            applyCleanall(document, root);\r
+            \r
+            //\r
+            // User Extension\r
+            //\r
+            applyUserExtensions(document, root);\r
+            \r
+            document.appendChild(rootComment);\r
+            document.appendChild(root);\r
+            //\r
+            // Prepare the DOM document for writing\r
+            //\r
+            Source source = new DOMSource(document);\r
+            //\r
+            // Prepare the output file\r
+            //\r
+            File file = new File(project.getProperty("PLATFORM_DIR") + File.separatorChar + platformName + "_build.xml");\r
+            //\r
+            // generate all directory path\r
+            //\r
+            (new File(file.getParent())).mkdirs();\r
+            Result result = new StreamResult(file);\r
+            //\r
+            // Write the DOM document to the file\r
+            //\r
+            Transformer xformer = TransformerFactory.newInstance().newTransformer();\r
+            xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
+            xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
+            xformer.transform(source, result);\r
+        } catch (Exception ex) {\r
+            ex.printStackTrace();\r
+            throw new BuildException("Generate " + platformName + "_build.xml failed. \n" + ex.getMessage());\r
+        }\r
+    }\r
+    private void applyModules(Document document, Node root, String num) {\r
+        root.appendChild(document.createComment("Modules target"));\r
+        Element ele = document.createElement("target");\r
+        ele.setAttribute("name", "modules" + num);\r
+        \r
+        Set<String> fvNameSet = sequences.get(num);\r
+\r
+        Iterator fvNameIter = fvNameSet.iterator();\r
+        while (fvNameIter.hasNext()) {\r
+            String fvName = (String)fvNameIter.next();\r
+            Set<FpdModuleIdentification> set = fvs.get(fvName);\r
+            Iterator iter = set.iterator();\r
+            while (iter.hasNext()) {\r
+                FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
+                ModuleIdentification moduleId = fpdModuleId.getModule();\r
+                Element moduleEle = document.createElement("GenBuild");\r
+                moduleEle.setAttribute("type", "build");\r
+                //\r
+                // Inherit Properties.\r
+                //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
+                //\r
+                \r
+                //\r
+                // ARCH\r
+                //\r
+                Element property = document.createElement("property");\r
+                property.setAttribute("name", "ARCH");\r
+                property.setAttribute("value", fpdModuleId.getArch());\r
+                moduleEle.appendChild(property);\r
+\r
+                //\r
+                // MODULE_GUID\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "MODULE_GUID");\r
+                property.setAttribute("value", moduleId.getGuid());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // MODULE_VERSION\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "MODULE_VERSION");\r
+                property.setAttribute("value", moduleId.getVersion());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // PACKAGE_GUID\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE_GUID");\r
+                property.setAttribute("value", moduleId.getPackage().getGuid());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // PACKAGE_VERSION\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE_VERSION");\r
+                property.setAttribute("value", moduleId.getPackage().getVersion());\r
+                moduleEle.appendChild(property);\r
+                \r
+                ele.appendChild(moduleEle);\r
+            }\r
+        }\r
+        root.appendChild(ele);\r
+    }\r
+    \r
+    private void applyFvs(Document document, Node root, String num) {\r
+        Set<String> fvNameSet = sequences.get(num);\r
+        //\r
+        // FVS Target\r
+        //\r
+        root.appendChild(document.createComment("FVs target"));\r
+        Element ele = document.createElement("target");\r
+        ele.setAttribute("name", "fvs" + num);\r
+\r
+        //\r
+        // For every Target and ToolChain\r
+        //\r
+        String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
+        for (int i = 0; i < targetList.length; i++){\r
+            String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
+            for(int j = 0; j < toolchainList.length; j++){\r
+                String fvOutputDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
+                                        + targetList[i] + File.separatorChar \r
+                                        + toolchainList[i] + File.separatorChar + "FV";\r
+                String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
+                for (int k = 0; k < validFv.length; k++) {\r
+                    if (fvNameSet.contains(validFv[k]) || ! isListInSequence(validFv[k])) {\r
+                        String inputFile = fvOutputDir + "" + File.separatorChar + validFv[k].toUpperCase() + ".inf";\r
+                        Element fvEle = document.createElement("genfvimage");\r
+                        fvEle.setAttribute("infFile", inputFile);\r
+                        fvEle.setAttribute("outputDir", fvOutputDir);\r
+                        ele.appendChild(fvEle);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        root.appendChild(ele);\r
+    }\r
+    \r
+    private void applyClean(Document document, Node root) {\r
+        //\r
+        // Clean Target\r
+        //\r
+        root.appendChild(document.createComment("Clean target"));\r
+        Element ele = document.createElement("target");\r
+        ele.setAttribute("name", "clean");\r
+\r
+        if (isUnified) {\r
+            Element cleanEle = document.createElement("delete");\r
+            cleanEle.setAttribute("includeemptydirs", "true");\r
+            Element filesetEle = document.createElement("fileset");\r
+            filesetEle.setAttribute("dir", project.getProperty("BUILD_DIR"));\r
+            filesetEle.setAttribute("includes", "**\\OUTPUT\\**");\r
+            cleanEle.appendChild(filesetEle);\r
+            ele.appendChild(cleanEle);\r
+        } else {\r
+            Set set = outfiles.keySet();\r
+            Iterator iter = set.iterator();\r
+            while (iter.hasNext()) {\r
+                FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
+                ModuleIdentification moduleId = fpdModuleId.getModule();\r
+\r
+                Element ifEle = document.createElement("if");\r
+                Element availableEle = document.createElement("available");\r
+                availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
+                                                  + "build.xml");\r
+                ifEle.appendChild(availableEle);\r
+                Element elseEle = document.createElement("then");\r
+\r
+                Element moduleEle = document.createElement("ant");\r
+                moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
+                                                  + "build.xml");\r
+                moduleEle.setAttribute("target", "clean");\r
+                //\r
+                // Inherit Properties.\r
+                //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
+                //\r
+                \r
+                //\r
+                // ARCH\r
+                //\r
+                Element property = document.createElement("property");\r
+                property.setAttribute("name", "ARCH");\r
+                property.setAttribute("value", fpdModuleId.getArch());\r
+                moduleEle.appendChild(property);\r
+\r
+                //\r
+                // PACKAGE\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE");\r
+                property.setAttribute("value", moduleId.getPackage().getName());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // PACKAGE_GUID\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE_GUID");\r
+                property.setAttribute("value", moduleId.getPackage().getGuid());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // PACKAGE_VERSION\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE_VERSION");\r
+                property.setAttribute("value", moduleId.getPackage().getVersion());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // MODULE_DIR\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "MODULE_DIR");\r
+                property.setAttribute("value", moduleId.getMsaFile().getParent());\r
+                moduleEle.appendChild(property);\r
+                elseEle.appendChild(moduleEle);\r
+                ifEle.appendChild(elseEle);\r
+                ele.appendChild(ifEle);\r
+            }\r
+        }\r
+        root.appendChild(ele);\r
+    }\r
+    \r
+    private void applyCleanall(Document document, Node root) {\r
+        //\r
+        // Deep Clean Target\r
+        //\r
+        root.appendChild(document.createComment("Clean All target"));\r
+        Element ele = document.createElement("target");\r
+        ele.setAttribute("name", "cleanall");\r
+\r
+        if (isUnified) {\r
+            Element cleanAllEle = document.createElement("delete");\r
+            cleanAllEle.setAttribute("dir", project.getProperty("BUILD_DIR"));\r
+            ele.appendChild(cleanAllEle);\r
+        } else {\r
+            Set set = outfiles.keySet();\r
+            Iterator iter = set.iterator();\r
+            while (iter.hasNext()) {\r
+                FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
+                ModuleIdentification moduleId = fpdModuleId.getModule();\r
+\r
+                Element ifEle = document.createElement("if");\r
+                Element availableEle = document.createElement("available");\r
+                availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
+                                                  + "build.xml");\r
+                ifEle.appendChild(availableEle);\r
+                Element elseEle = document.createElement("then");\r
+\r
+                Element moduleEle = document.createElement("ant");\r
+                moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
+                                                  + "build.xml");\r
+                moduleEle.setAttribute("target", "cleanall");\r
+                //\r
+                // Inherit Properties.\r
+                //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
+                //\r
+                \r
+                //\r
+                // ARCH\r
+                //\r
+                Element property = document.createElement("property");\r
+                property.setAttribute("name", "ARCH");\r
+                property.setAttribute("value", fpdModuleId.getArch());\r
+                moduleEle.appendChild(property);\r
+\r
+                //\r
+                // PACKAGE\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE");\r
+                property.setAttribute("value", moduleId.getPackage().getName());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // PACKAGE_GUID\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE_GUID");\r
+                property.setAttribute("value", moduleId.getPackage().getGuid());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // PACKAGE_VERSION\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "PACKAGE_VERSION");\r
+                property.setAttribute("value", moduleId.getPackage().getVersion());\r
+                moduleEle.appendChild(property);\r
+                \r
+                //\r
+                // MODULE_DIR\r
+                //\r
+                property = document.createElement("property");\r
+                property.setAttribute("name", "MODULE_DIR");\r
+                property.setAttribute("value", moduleId.getMsaFile().getParent());\r
+                moduleEle.appendChild(property);\r
+                elseEle.appendChild(moduleEle);\r
+                ifEle.appendChild(elseEle);\r
+                ele.appendChild(ifEle);\r
+            }\r
+        }\r
+        root.appendChild(ele);\r
+    }\r
+    \r
+    private void applyUserExtensions(Document document, Node root) {\r
+        //\r
+        // User Extensions\r
+        //\r
+        root.appendChild(document.createComment("User Extensions"));\r
+        Element ele = document.createElement("target");\r
+        ele.setAttribute("name", "userextensions");\r
+        \r
+        root.appendChild(ele);\r
+    }\r
+    \r
+    \r
+    private boolean isListInSequence(String fvName) {\r
+        Set<String> numbers = sequences.keySet();\r
+        Iterator<String> iter = numbers.iterator();\r
+        while (iter.hasNext()) {\r
+            Set<String> fvNameSet = sequences.get(iter.next());\r
+            if (fvNameSet.contains(fvName)) {\r
+                return true;\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+}\r
index 97096f6b4f32b156907f70fa359e50c169bd416a..99cccc364cc3211317f79f2894155cffa89a2d40 100644 (file)
@@ -16,29 +16,34 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.global;\r
 \r
 **/\r
 package org.tianocore.build.global;\r
 \r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.DbPathAndFilename;\r
+import org.tianocore.FrameworkDatabaseDocument;\r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
+import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
+import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.toolchain.ToolChainAttribute;\r
+import org.tianocore.build.toolchain.ToolChainConfig;\r
+import org.tianocore.build.toolchain.ToolChainElement;\r
+import org.tianocore.build.toolchain.ToolChainInfo;\r
+import org.tianocore.build.toolchain.ToolChainKey;\r
+import org.tianocore.build.toolchain.ToolChainMap;\r
+//import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
+//import org.tianocore.logger.EdkLog;\r
+\r
 import java.io.File;\r
 import java.io.File;\r
-import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.FilenameDocument;\r
-import org.tianocore.FilenameDocument.Filename;\r
-import org.tianocore.FrameworkDatabaseDocument;\r
-import org.tianocore.MsaFilesDocument;\r
-import org.tianocore.MsaFilesDocument.MsaFiles.MsaFile;\r
-import org.tianocore.MsaHeaderDocument.MsaHeader;\r
-import org.tianocore.MsaLibHeaderDocument.MsaLibHeader;\r
-import org.tianocore.PackageListDocument;\r
-import org.tianocore.PackageSurfaceAreaDocument;\r
-import org.tianocore.build.autogen.CommonDefinition;\r
-import org.tianocore.build.fpd.FpdParserTask;\r
-import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
+import java.util.logging.Logger;\r
 \r
 /**\r
   GlobalData provide initializing, instoring, querying and update global data.\r
 \r
 /**\r
   GlobalData provide initializing, instoring, querying and update global data.\r
@@ -46,408 +51,321 @@ import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
   PCD and so on. \r
   \r
   <p>Note that all global information are initialized incrementally. All data will \r
   PCD and so on. \r
   \r
   <p>Note that all global information are initialized incrementally. All data will \r
-  parse and record only it is necessary during build time. </p>\r
+  parse and record only of necessary during build time. </p>\r
   \r
   @since GenBuild 1.0\r
 **/\r
 public class GlobalData {\r
 \r
   \r
   @since GenBuild 1.0\r
 **/\r
 public class GlobalData {\r
 \r
-    ///\r
-    /// means no surface area information for module\r
-    ///\r
-    public static final int NO_SA = 0;\r
-\r
-    ///\r
-    /// means only MSA\r
-    ///\r
-    public static final int ONLY_MSA = 1;\r
-\r
-    ///\r
-    /// means only Library MSA\r
-    ///\r
-    public static final int ONLY_LIBMSA = 2;\r
-\r
-    ///\r
-    /// means both MSA and MBD\r
-    ///\r
-    public static final int MSA_AND_MBD = 3;\r
-\r
-    ///\r
-    /// means both Library MSA and Library MBD\r
-    ///\r
-    public static final int LIBMSA_AND_LIBMBD = 4;\r
-\r
-    ///\r
-    /// Be used to ensure Global data will be initialized only once.\r
-    ///\r
-    public static boolean globalFlag = false;\r
-\r
+    public static Logger log = Logger.getAnonymousLogger();\r
+    \r
     ///\r
     /// Record current WORKSPACE Directory\r
     ///\r
     private static String workspaceDir = "";\r
     ///\r
     /// Record current WORKSPACE Directory\r
     ///\r
     private static String workspaceDir = "";\r
-\r
+    \r
     ///\r
     ///\r
-    /// Two columns: Package Name (Key), Package Path(ralative to WORKSPACE)\r
+    /// Be used to ensure Global data will be initialized only once.\r
     ///\r
     ///\r
-    private static final Map<String, String> packageInfo = new HashMap<String, String>();\r
-\r
+    private static boolean globalFlag = false;\r
+    \r
     ///\r
     ///\r
-    /// spdTable\r
-    /// Key: Package Name, Value: SPD detail info\r
+    /// Framework Database information: package list and platform list\r
     ///\r
     ///\r
-    private static final Map<String, Spd> spdTable = new HashMap<String, Spd>();\r
+    private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();  \r
 \r
 \r
-    ///\r
-    /// Three columns:\r
-    /// 1. Module Name | BaseName (Key)\r
-    /// 2. Module Path + Msa file name (relative to Package)\r
-    /// 3. Package Name (This module belong to which package)\r
-    ///\r
-    private static final Map<String, String[]> moduleInfo = new HashMap<String, String[]>();\r
+    private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();\r
 \r
     ///\r
 \r
     ///\r
-    /// List all libraries for current build module\r
-    /// Key: Library BaseName, Value: output library path+name\r
+    /// Every detail SPD informations: Module list, Library class definition,\r
+    ///   Package header file, GUID/PPI/Protocol definitions\r
     ///\r
     ///\r
-    private static final Map<String, String> libraries = new HashMap<String, String>();\r
+    private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();\r
 \r
     ///\r
 \r
     ///\r
-    /// Store every module's relative library instances BaseName\r
-    /// Key: Module BaseName, Value: All library instances module depends on.\r
+    /// Build informations are divided into three parts:\r
+    /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA\r
     ///\r
     ///\r
-    private static final Map<String, Set<String> > moduleLibraryMap = new HashMap<String, Set<String> >();\r
+    private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();\r
 \r
 \r
-    ///\r
-    /// Key: Module BaseName, Value: original MSA info\r
-    ///\r
-    private static final Map<String, Map<String, XmlObject> > nativeMsa = new HashMap<String, Map<String, XmlObject> >();\r
+    private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
 \r
 \r
-    ///\r
-    /// Key: Module BaseName, Value: original MBD info\r
-    ///\r
-    private static final Map<String, Map<String, XmlObject> > nativeMbd = new HashMap<String, Map<String, XmlObject> >();\r
+    private static XmlObject fpdBuildOptions;\r
 \r
 \r
+    private static XmlObject fpdDynamicPcds;\r
+    \r
     ///\r
     ///\r
-    /// Two columns: Module Name or Base Name as Key\r
-    /// Value is a HashMap with overridden data from MSA/MBD or/and Platform\r
+    /// Parsed modules list\r
     ///\r
     ///\r
-    private static final Map<String, Map<String, XmlObject> > parsedModules = new HashMap<String, Map<String, XmlObject> >();\r
-\r
+    private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
+    \r
     ///\r
     ///\r
-    /// List all built Module; Value is Module BaseName + Arch. TBD\r
+    /// built modules list with ARCH, TARGET, TOOLCHAIN\r
     ///\r
     ///\r
-    private static final Set<String> builtModules = new HashSet<String>();\r
-\r
+    private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r
+    \r
     ///\r
     ///\r
-    /// Library instance information table which recored the library and it's\r
-    /// constructor and distructor function\r
+    /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r
     ///\r
     ///\r
-    private static final Map<String, String[]> libInstanceInfo = new HashMap<String, String[]>();\r
+//    private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
 \r
     ///\r
 \r
     ///\r
-    /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r
+    /// build target + tool chain family/tag name + arch + command types + command options\r
     ///\r
     ///\r
-    private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
-\r
-    /**\r
-      Query the module's absolute path with module base name. \r
-      \r
-      @param moduleName the base name of the module\r
-      @return the absolute module path\r
-    **/\r
-    public synchronized static String getModulePath(String moduleName) {\r
-        String[] info = moduleInfo.get(moduleName);\r
-        String packagePath = (String) packageInfo.get(info[1]);\r
-        File convertFile = new File(workspaceDir + File.separatorChar + packagePath + File.separatorChar + info[0]);\r
-        return convertFile.getParent();\r
-    }\r
-\r
-    /**\r
-      Query the module's absolute MSA file path with module base name. \r
-    \r
-      @param moduleName the base name of the module\r
-      @return the absolute MSA file name\r
-      @throws BuildException\r
-              Base name is not registered in any SPD files\r
-    **/\r
-    private synchronized static String getMsaFilename(String moduleName) throws BuildException {\r
-        String[] info = moduleInfo.get(moduleName);\r
-        if (info == null) {\r
-            throw new BuildException("Module base name [" + moduleName + "] can't found in all SPD.");\r
-        }\r
-        String packagePath = (String) packageInfo.get(info[1]);\r
-        File convertFile = new File(workspaceDir + File.separatorChar + packagePath + File.separatorChar + info[0]);\r
-        return convertFile.getPath();\r
-    }\r
+    ///\r
+    /// Tool Chain Data\r
+    /// toolsDef - build tool program information\r
+    /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r
+    /// moduleSaBuildOption - build options for a specific module\r
+    /// \r
+    private static ToolChainConfig toolsDef;\r
 \r
 \r
-    /**\r
-      Query the module's absolute MBD file path with module base name. \r
-    \r
-      @param moduleName the base name of the module\r
-      @return the absolute MBD file name\r
-      @throws BuildException\r
-              Base name is not registered in any SPD files\r
-    **/\r
-    private synchronized static String getMbdFilename(String moduleName) throws BuildException {\r
-        String[] info = moduleInfo.get(moduleName);\r
-        if (info == null) {\r
-            throw new BuildException("Info: Module base name [" + moduleName + "] can't found in all SPD.");\r
-        }\r
-        String packagePath = (String) packageInfo.get(info[1]);\r
-        File convertFile = new File(workspaceDir + File.separatorChar + packagePath + File.separatorChar + info[0]);\r
-        return convertFile.getPath().substring(0, convertFile.getPath().length() - 4) + ".mbd";\r
-    }\r
+    private static ToolChainInfo toolChainInfo;\r
+    private static ToolChainInfo toolChainEnvInfo;\r
+    private static ToolChainInfo toolChainPlatformInfo;\r
 \r
 \r
-    /**\r
-      Get the current WORKSPACE Directory. \r
-      @return current workspace directory\r
-    **/\r
-    public synchronized static String getWorkspacePath() {\r
-        return workspaceDir;\r
-    }\r
+    private static ToolChainMap platformToolChainOption;\r
+    private static ToolChainMap platformToolChainFamilyOption;\r
 \r
 \r
-    /**\r
-      Query package relative path to WORKSPACE_DIR with package name. \r
-      \r
-      @param packageName the name of the package\r
-      @return the path relative to WORKSPACE_DIR \r
-    **/\r
-    public synchronized static String getPackagePath(String packageName) {\r
-        return (String) packageInfo.get(packageName);\r
-    }\r
+    private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
+    private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
 \r
 \r
-    /**\r
-      Query package (which the module belongs to) relative path to WORSPACE_DIR.  \r
-    \r
-      @param moduleName the base name of the module\r
-      @return the relative path to WORKSPACE_DIR of the package which the module belongs to\r
-    **/\r
-    public synchronized static String getPackagePathForModule(String moduleName) {\r
-        String[] info = moduleInfo.get(moduleName);\r
-        String packagePath = (String) packageInfo.get(info[1]);\r
-        return packagePath;\r
-    }\r
+//    private static final MemoryDatabasseManager pcdDbManager = new MemoryDatabaseManager();\r
 \r
 \r
-    /**\r
-      Query the package name which the module belongs to with the module's base name.\r
     \r
     \r
-      @param moduleName the base name of the module\r
-      @return the package name which the module belongs to\r
-    **/\r
-    public synchronized static String getPackageNameForModule(String moduleName) {\r
-        return moduleInfo.get(moduleName)[1];\r
-    }\r
 \r
     /**\r
       Parse framework database (DB) and all SPD files listed in DB to initialize\r
       the environment for next build. This method will only be executed only once\r
       in the whole build process.  \r
 \r
     /**\r
       Parse framework database (DB) and all SPD files listed in DB to initialize\r
       the environment for next build. This method will only be executed only once\r
       in the whole build process.  \r
-      \r
+    \r
       @param workspaceDatabaseFile the file name of framework database\r
       @param workspaceDir current workspace directory path\r
       @throws BuildException\r
       @param workspaceDatabaseFile the file name of framework database\r
       @param workspaceDir current workspace directory path\r
       @throws BuildException\r
-              Framework Dababase or SPD or MSA file is not valid\r
+            Framework Dababase or SPD or MSA file is not valid\r
     **/\r
     **/\r
-    public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir) throws BuildException {\r
+    public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename) throws BuildException {\r
+        //\r
+        // ensure this method will be revoked only once\r
+        //\r
         if (globalFlag) {\r
             return;\r
         }\r
         globalFlag = true;\r
         if (globalFlag) {\r
             return;\r
         }\r
         globalFlag = true;\r
-        GlobalData.workspaceDir = workspaceDir;\r
+        \r
+        //\r
+        // Backup workspace directory. It will be used by other method\r
+        //\r
+        GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r
+        \r
+        //\r
+        // Parse tools definition file\r
+        //\r
+        //\r
+        // If ToolChain has been set up before, do nothing.\r
+        // CONF dir + tools definition file name\r
+        //\r
+        String confDir = GlobalData.workspaceDir + File.separatorChar + "Tools" + File.separatorChar + "Conf";\r
+        File toolsDefFile = new File(confDir + File.separatorChar + toolsDefFilename);\r
+        System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");\r
+        toolsDef = new ToolChainConfig(toolsDefFile);\r
+        \r
+        //\r
+        // Parse Framework Database\r
+        //\r
         File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r
         try {\r
             FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r
         File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r
         try {\r
             FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r
-            List<PackageListDocument.PackageList.Package> packages = db.getFrameworkDatabase().getPackageList()\r
-                                                                       .getPackageList();\r
-            Iterator iter = packages.iterator();\r
-            while (iter.hasNext()) {\r
-                PackageListDocument.PackageList.Package packageItem = (PackageListDocument.PackageList.Package) iter\r
-                                                                                                                    .next();\r
-                String name = packageItem.getPackageNameArray(0).getStringValue();\r
-                String path = packageItem.getPathArray(0).getStringValue();\r
-                packageInfo.put(name, path);\r
-                File spdFile = new File(workspaceDir + File.separatorChar + path + File.separatorChar + name + ".spd");\r
-                initPackageInfo(spdFile.getPath(), name);\r
-                // \r
-                // SPD Parse.\r
-                //\r
-                PackageSurfaceAreaDocument spdDoc = (PackageSurfaceAreaDocument) XmlObject.Factory.parse(spdFile);\r
-                Spd spd = new Spd(spdDoc, path);\r
-                spdTable.put(name, spd);\r
-\r
+            //\r
+            // validate FrameworkDatabaseFile\r
+            //\r
+            if (! db.validate()) {\r
+                throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid.");\r
             }\r
             }\r
-        } catch (Exception e) {\r
-            throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());\r
-        }\r
-    }\r
-\r
-    /**\r
-      Parse every MSA files, get base name from MSA Header. And record those\r
-      values to ModuleInfo.\r
-      \r
-      @param packageFilename the file name of the package\r
-      @param packageName the name of the package\r
-      @throws BuildException\r
-              SPD or MSA file is not valid\r
-    **/\r
-    private synchronized static void initPackageInfo(String packageFilename, String packageName) throws BuildException {\r
-        File packageFile = new File(packageFilename);\r
-        try {\r
-            PackageSurfaceAreaDocument spd = (PackageSurfaceAreaDocument) XmlObject.Factory.parse(packageFile);\r
-            List<String> msaFilenameList;\r
-\r
-            List<MsaFilesDocument.MsaFiles.MsaFile> msasList = spd.getPackageSurfaceArea().getMsaFiles()\r
-                                                                  .getMsaFileList();\r
-            if (msasList.size() == 0) {\r
-                msaFilenameList = spd.getPackageSurfaceArea().getMsaFiles().getFilenameList();\r
-            } else {\r
-                msaFilenameList = new ArrayList<String>(msasList.size());\r
-                Iterator msasIter = msasList.iterator();\r
-                while (msasIter.hasNext()) {\r
-                    MsaFilesDocument.MsaFiles.MsaFile msaFile = (MsaFilesDocument.MsaFiles.MsaFile)msasIter.next();\r
-                    msaFilenameList.add(msaFile.getFilename().getStringValue());\r
+            //\r
+            // Get package list\r
+            //\r
+            if (db.getFrameworkDatabase().getPackageList() != null ) {\r
+                List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();\r
+                Iterator<DbPathAndFilename> iter = packages.iterator();\r
+                while (iter.hasNext()) {\r
+                    String fileName = iter.next().getStringValue();\r
+                    Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r
+                    packageList.add(spd.getPackageId());\r
+                    spdTable.put(spd.getPackageId(), spd);\r
                 }\r
             }\r
 \r
                 }\r
             }\r
 \r
-            Iterator msaFilenameIter = msaFilenameList.iterator();\r
-            while (msaFilenameIter.hasNext()) {\r
-                String filename = (String)msaFilenameIter.next();\r
-                File msaFile = new File(workspaceDir + File.separatorChar + GlobalData.getPackagePath(packageName)\r
-                                        + File.separatorChar + filename);\r
-                SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();\r
-                Map<String, XmlObject> map = surfaceAreaParser.parseFile(msaFile);\r
-                String baseName = "";\r
-                XmlObject header = null;\r
-                if ((header = map.get("MsaHeader")) != null) {\r
-                    if (((MsaHeader) header).isSetBaseName()) {\r
-                        baseName = ((MsaHeader) header).getBaseName().getStringValue();\r
-                    } else {\r
-                        baseName = ((MsaHeader) header).getModuleName();\r
+            //\r
+            // Get platform list\r
+            //\r
+            if (db.getFrameworkDatabase().getPlatformList() != null) {\r
+                List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r
+                Iterator<DbPathAndFilename> iter = platforms.iterator();\r
+                while (iter.hasNext()) {\r
+                    String fileName = iter.next().getStringValue();\r
+                    File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r
+                    if ( ! fpdFile.exists() ) {\r
+                        throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r
                     }\r
                     }\r
-                } else if ((header = map.get("MsaLibHeader")) != null) {\r
-                    baseName = ((MsaLibHeader) header).getBaseName().getStringValue();\r
-                } else {\r
-                    continue;\r
+                    XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r
+                    //\r
+                    // Verify FPD file, if is invalid, throw Exception\r
+                    //\r
+                    if (! fpdDoc.validate()) {\r
+                        throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] is invalid. ");\r
+                    }\r
+                    //\r
+                    // We can change Map to XmlObject\r
+                    //\r
+                    //\r
+                    // TBD check SPD or FPD is existed in FS\r
+                    //\r
+                    Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r
+                    fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r
+                    SurfaceAreaQuery.setDoc(fpdDocMap);\r
+                    PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader();\r
+                    platformId.setFpdFile(fpdFile);\r
+                    platformList.add(platformId);\r
                 }\r
                 }\r
-                nativeMsa.put(baseName, map);\r
-                String[] info = { filename, packageName };\r
-                moduleInfo.put(baseName, info);\r
             }\r
         } catch (Exception e) {\r
             }\r
         } catch (Exception e) {\r
-            throw new BuildException("Parse package description file [" + packageFile.getPath() + "] Error.\n"\r
-                                     + e.getMessage());\r
+            e.printStackTrace();\r
+            throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());\r
         }\r
     }\r
         }\r
     }\r
-\r
-    /**\r
-      Query the libraries which the module depends on.\r
     \r
     \r
-      @param moduleName the base name of the module\r
-      @return the libraries which the module depends on\r
-    **/\r
-    public synchronized static String[] getModuleLibrary(String moduleName, String arch) {\r
-        Set<String> set = moduleLibraryMap.get(moduleName + "-" + arch);\r
-        return set.toArray(new String[set.size()]);\r
-    }\r
-\r
     /**\r
     /**\r
-      Register module's library list which it depends on for later use\r
+      Get the current WORKSPACE Directory\r
       \r
       \r
-      @param moduleName the base name of the module\r
-      @param libraryList the libraries which the module depends on\r
+      @return current workspace directory\r
     **/\r
     **/\r
-    public synchronized static void addModuleLibrary(String moduleName, String arch, Set<String> libraryList) {\r
-        moduleLibraryMap.put(moduleName + "-" + arch, libraryList);\r
+    public synchronized static String getWorkspacePath() {\r
+        return workspaceDir;\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      Query the library absolute file name with library name. \r
-      \r
-      @param library the base name of the library\r
-      @return the library absolute file name\r
-    **/\r
-    public synchronized static String getLibrary(String library, String arch) {\r
-        return libraries.get(library + "-" + arch);\r
-    }\r
 \r
     /**\r
 \r
     /**\r
-      Register library absolute file name for later use.\r
-      \r
-      @param library the base name of the library\r
-      @param resultPath the library absolute file name\r
-    **/\r
-    public synchronized static void addLibrary(String library, String arch, String resultPath) {\r
-        libraries.put(library + "-" + arch, resultPath);\r
+      Get the MSA file name with absolute path\r
+     */\r
+    public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {\r
+        File msaFile = null;\r
+        //\r
+        // TBD. Do only when package is null. \r
+        //\r
+        Iterator iter = packageList.iterator();\r
+        while (iter.hasNext()) {\r
+            PackageIdentification packageId = (PackageIdentification)iter.next();\r
+            Spd spd = spdTable.get(packageId);\r
+            msaFile = spd.getModuleFile(moduleId);\r
+            if (msaFile != null ) {\r
+                break ;\r
+            }\r
+        }\r
+        if (msaFile == null){\r
+            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r
+        }\r
+        else {\r
+            return msaFile;\r
+        }\r
     }\r
 \r
     }\r
 \r
+    public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) {\r
+        //\r
+        // If package already defined in module\r
+        //\r
+        if (moduleId.getPackage() != null) {\r
+            return moduleId.getPackage();\r
+        }\r
+        \r
+        PackageIdentification packageId = null;\r
+        Iterator iter = packageList.iterator();\r
+        while (iter.hasNext()) {\r
+            packageId = (PackageIdentification)iter.next();\r
+            moduleId.setPackage(packageId);\r
+            Spd spd = spdTable.get(packageId);\r
+            if (spd.getModuleFile(moduleId) != null ) {\r
+                break ;\r
+            }\r
+        }\r
+        if (packageId == null){\r
+            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r
+        }\r
+        else {\r
+            return packageId;\r
+        }\r
+    }\r
+    \r
     /**\r
     /**\r
-      Whether the module with ARCH has built in the previous build. \r
-      \r
-      @param moduleName the base name of the module\r
-      @param arch current build ARCH\r
-      @return true if the module has built in previous, otherwise return false\r
+      Difference between build and parse: ToolChain and Target\r
     **/\r
     **/\r
-    public synchronized static boolean isModuleBuilt(String moduleName, String arch) {\r
-        return builtModules.contains(moduleName + "-" + arch);\r
+    public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r
+        return builtModules.contains(moduleId);\r
     }\r
     }\r
-\r
-    /**\r
-      Register the module with ARCH has built. \r
     \r
     \r
-      @param moduleName the base name of the module\r
-      @param arch current build ARCH\r
-    **/\r
-    public synchronized static void registerBuiltModule(String moduleName, String arch) {\r
-        builtModules.add(moduleName + "-" + arch);\r
+    public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r
+        builtModules.add(fpdModuleId);\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      Whether the module's surface area has parsed in the previous build.\r
-      \r
-      @param moduleName the base name of the module\r
-      @return true if the module's surface area has parsed in previous, otherwise\r
-      return false\r
-    **/\r
-    public synchronized static boolean isModuleParsed(String moduleName) {\r
-        return parsedModules.containsKey(moduleName);\r
+    \r
+    public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {\r
+        Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r
+        Set keySet = doc.keySet();\r
+        Iterator iter = keySet.iterator();\r
+        while (iter.hasNext()){\r
+            String key = (String)iter.next();\r
+            XmlObject item = cloneXmlObject(doc.get(key), true);\r
+            result.put(key, item);\r
+        }\r
+        fpdModuleSA.put(fpdModuleId, result);\r
     }\r
     }\r
-\r
+    \r
     /**\r
       Query overrided module surface area information. If current is Package\r
       or Platform build, also include the information from FPD file. \r
       \r
       <p>Note that surface area parsing is incremental. That means the method will \r
     /**\r
       Query overrided module surface area information. If current is Package\r
       or Platform build, also include the information from FPD file. \r
       \r
       <p>Note that surface area parsing is incremental. That means the method will \r
-      only to parse the MSA and MBD files when never parsed before. </p>\r
+      only parse the MSA and MBD files if necessary. </p>\r
     \r
       @param moduleName the base name of the module\r
       @return the overrided module surface area information\r
       @throws BuildException\r
               MSA or MBD is not valid\r
     **/\r
     \r
       @param moduleName the base name of the module\r
       @return the overrided module surface area information\r
       @throws BuildException\r
               MSA or MBD is not valid\r
     **/\r
-    public synchronized static Map<String, XmlObject> getDoc(String moduleName) throws BuildException {\r
-        if (parsedModules.containsKey(moduleName)) {\r
-            return parsedModules.get(moduleName);\r
-        }\r
-        Map<String, XmlObject> msaMap = getNativeMsa(moduleName);\r
-        Map<String, XmlObject> mbdMap = getNativeMbd(moduleName);\r
-        OverrideProcess op = new OverrideProcess();\r
-        Map<String, XmlObject> map = op.override(mbdMap, msaMap);\r
+    public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {\r
+        if (parsedModules.containsKey(fpdModuleId)) {\r
+            return parsedModules.get(fpdModuleId);\r
+        }\r
+        Map<String, XmlObject> doc = new HashMap<String, XmlObject>();\r
+        ModuleIdentification moduleId = fpdModuleId.getModule();\r
         //\r
         //\r
-        // IF IT IS A PALTFORM BUILD, OVERRIDE FROM PLATFORM\r
+        // First part: get the MSA files info\r
         //\r
         //\r
-        if (FpdParserTask.platformBuildOptions != null) {\r
-            Map<String, XmlObject> platformMap = new HashMap<String, XmlObject>();\r
-            platformMap.put("BuildOptions", FpdParserTask.platformBuildOptions);\r
-            Map<String, XmlObject> overrideMap = op.override(platformMap, OverrideProcess.deal(map));\r
-            GlobalData.registerModule(moduleName, overrideMap);\r
-            return overrideMap;\r
-        } else {\r
-            parsedModules.put(moduleName, map);\r
-            return map;\r
+        doc = getNativeMsa(moduleId);\r
+        \r
+        //\r
+        // Second part: put build options\r
+        //\r
+        doc.put("BuildOptions", fpdBuildOptions);\r
+        \r
+        //\r
+        // Third part: get Module info from FPD, such as Library instances, PCDs\r
+        //\r
+        if (fpdModuleSA.containsKey(fpdModuleId)){\r
+            //\r
+            // merge module info in FPD to final Doc\r
+            // For Library Module, do nothing here\r
+            //\r
+            doc.putAll(fpdModuleSA.get(fpdModuleId));\r
         }\r
         }\r
+        parsedModules.put(fpdModuleId, doc);\r
+        return doc;\r
     }\r
 \r
     }\r
 \r
+    public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {\r
+        FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r
+        return getDoc(fpdModuleId);\r
+    }\r
     /**\r
       Query the native MSA information with module base name. \r
       \r
     /**\r
       Query the native MSA information with module base name. \r
       \r
@@ -459,200 +377,425 @@ public class GlobalData {
       @throws BuildException\r
               MSA file is not valid\r
     **/\r
       @throws BuildException\r
               MSA file is not valid\r
     **/\r
-    public synchronized static Map<String, XmlObject> getNativeMsa(String moduleName) throws BuildException {\r
-        if (nativeMsa.containsKey(moduleName)) {\r
-            return nativeMsa.get(moduleName);\r
-        }\r
-        String msaFilename = getMsaFilename(moduleName);\r
-        File msaFile = new File(msaFilename);\r
-        if (!msaFile.exists()) {\r
-            throw new BuildException("Info: Surface Area file [" + msaFile.getPath() + "] can't found.");\r
-        }\r
-        SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();\r
-        Map<String, XmlObject> map = surfaceAreaParser.parseFile(msaFile);\r
-        nativeMsa.put(moduleName, map);\r
+    public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {\r
+        if (nativeMsa.containsKey(moduleId)) {\r
+            return nativeMsa.get(moduleId);\r
+        }\r
+        File msaFile = getMsaFile(moduleId);\r
+        Map<String, XmlObject> msaMap = getNativeMsa(msaFile);\r
+        nativeMsa.put(moduleId, msaMap);\r
+        return msaMap;\r
+    }\r
+    \r
+    public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {\r
+        if (! msaFile.exists()) {\r
+            throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found.");\r
+        }\r
+        try {\r
+            ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r
+            //\r
+            // Validate File if they accord with XML Schema\r
+            //\r
+            if ( ! doc.validate()){\r
+                throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");\r
+            }\r
+            //\r
+            // parse MSA file\r
+            //\r
+            ModuleSurfaceArea msa= doc.getModuleSurfaceArea();\r
+            Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();\r
+            msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));\r
+            msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));\r
+            msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));\r
+            msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));\r
+            msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));\r
+            msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));\r
+            msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r
+            msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r
+            msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r
+            return msaMap;\r
+        }\r
+        catch (Exception ex){\r
+            throw new BuildException(ex.getMessage());\r
+        }\r
+    }\r
+    \r
+    public static Map<String, XmlObject> getFpdBuildOptions() {\r
+        Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
+        map.put("BuildOptions", fpdBuildOptions);\r
         return map;\r
     }\r
     \r
         return map;\r
     }\r
     \r
-    /**\r
-      Query the native MBD information with module base name. \r
-      \r
-      <p>Note that MBD parsing is incremental. That means the method will \r
-      only to parse the MBD files when never parsed before. </p>\r
+    public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {\r
+        GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r
+    }\r
+\r
+    public static XmlObject getFpdDynamicPcds() {\r
+        return fpdDynamicPcds;\r
+    }\r
+\r
+    public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {\r
+        GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r
+    }\r
+\r
+    //////////////////////////////////////////////\r
+    //////////////////////////////////////////////\r
     \r
     \r
-      @param moduleName the base name of the module\r
-      @return the native MBD information\r
-      @throws BuildException\r
-              MBD file is not valid\r
-    **/\r
-    public synchronized static Map<String, XmlObject> getNativeMbd(String moduleName) throws BuildException {\r
-        if (nativeMbd.containsKey(moduleName)) {\r
-            return nativeMbd.get(moduleName);\r
+    public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r
+        Spd spd = spdTable.get(packageId);\r
+        if (spd == null ) {\r
+            Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r
+            return dummy;\r
         }\r
         }\r
-        String mbdFilename = getMbdFilename(moduleName);\r
-        File mbdFile = new File(mbdFilename);\r
-        if (!mbdFile.exists()) {\r
-            return null;\r
-            //throw new BuildException("Info: Surface Area file [" + mbdFile.getPath() + "] can't found.");\r
+        else {\r
+            return spd.getModules();\r
         }\r
         }\r
-        SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();\r
-        Map<String, XmlObject> map = surfaceAreaParser.parseFile(mbdFile);\r
-        nativeMbd.put(moduleName, map);\r
-        return map;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      Register module overrided surface area information. If has existed, then update.\r
-      \r
-      @param moduleName the base name of the module\r
-      @param map the overrided surface area information\r
-    **/\r
-    public synchronized static void registerModule(String moduleName, Map<String, XmlObject> map) {\r
-        parsedModules.put(moduleName, map);\r
+     * The header file path is relative to workspace dir\r
+     */\r
+    public static String[] getLibraryClassHeaderFiles(\r
+            PackageIdentification[] packages, String name)\r
+            throws BuildException {\r
+        if (packages == null) {\r
+            // throw Exception or not????\r
+            return new String[0];\r
+        }\r
+        String[] result = null;\r
+        for (int i = 0; i < packages.length; i++) {\r
+            Spd spd = spdTable.get(packages[i]);\r
+            //\r
+            // If find one package defined the library class\r
+            //\r
+            if ((result = spd.getLibClassIncluder(name)) != null) {\r
+                return result;\r
+            }\r
+        }\r
+        //\r
+        // If can't find library class declaration in every package\r
+        //\r
+        throw new BuildException("Can not find library class [" + name\r
+                + "] declaration in every packages. ");\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     * \r
-     * @param protocolName\r
-     * @return\r
+     * The header file path is relative to workspace dir\r
      */\r
      */\r
-    public synchronized static String[] getProtocolInfoGuid(String protocolName) {\r
-        Set set = spdTable.keySet();\r
-        Iterator iter = set.iterator();\r
-        String[] cNameGuid = null;\r
-\r
-        while (iter.hasNext()) {\r
-            Spd spd = (Spd) spdTable.get(iter.next());\r
-            cNameGuid = spd.getProtocolNameGuidArray(protocolName);\r
-            if (cNameGuid != null) {\r
-                break;\r
+    public static String getPackageHeaderFiles(PackageIdentification packages,\r
+            String moduleType) throws BuildException {\r
+        if (packages == null) {\r
+            return new String("");\r
+        }\r
+        Spd spd = spdTable.get(packages);\r
+        //\r
+        // If can't find package header file, skip it\r
+        //\r
+        String temp = null;\r
+        if (spd != null) {\r
+            if ((temp = spd.getPackageIncluder(moduleType)) != null) {\r
+                return temp;\r
+            } else {\r
+                temp = "";\r
+                return temp;\r
             }\r
             }\r
+        } else {\r
+            return null;\r
         }\r
         }\r
-        return cNameGuid;\r
     }\r
 \r
     }\r
 \r
-    public synchronized static String[] getPpiInfoGuid(String ppiName) {\r
-        Set set = spdTable.keySet();\r
-        Iterator iter = set.iterator();\r
-        String[] cNameGuid = null;\r
-\r
-        while (iter.hasNext()) {\r
-            Spd spd = (Spd) spdTable.get(iter.next());\r
-            cNameGuid = spd.getPpiCnameGuidArray(ppiName);\r
-\r
-            if (cNameGuid != null) {\r
-                break;\r
+    /**\r
+     * return two values: {cName, GuidValue}\r
+     */\r
+    public static String[] getGuid(PackageIdentification[] packages, String name)\r
+            throws BuildException {\r
+        if (packages == null) {\r
+            // throw Exception or not????\r
+            return new String[0];\r
+        }\r
+        String[] result = null;\r
+        for (int i = 0; i < packages.length; i++) {\r
+            Spd spd = spdTable.get(packages[i]);\r
+            //\r
+            // If find one package defined the GUID\r
+            //\r
+            if ((result = spd.getGuid(name)) != null) {\r
+                return result;\r
             }\r
         }\r
             }\r
         }\r
-        return cNameGuid;\r
+        return null;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     * \r
-     * @param guidName\r
-     * @return\r
+     * return two values: {cName, GuidValue}\r
      */\r
      */\r
-    public synchronized static String[] getGuidInfoGuid(String guidName) {\r
-        String[] cNameGuid = null;\r
-        Set set = spdTable.keySet();\r
-        Iterator iter = set.iterator();\r
-\r
-        while (iter.hasNext()) {\r
-            Spd spd = (Spd) spdTable.get(iter.next());\r
-            cNameGuid = spd.getGuidNameArray(guidName);\r
-            if (cNameGuid != null) {\r
-                break;\r
+    public static String[] getPpiGuid(PackageIdentification[] packages,\r
+            String name) throws BuildException {\r
+        if (packages == null) {\r
+            return new String[0];\r
+        }\r
+        String[] result = null;\r
+        for (int i = 0; i < packages.length; i++) {\r
+            Spd spd = spdTable.get(packages[i]);\r
+            //\r
+            // If find one package defined the Ppi GUID\r
+            //\r
+            if ((result = spd.getPpi(name)) != null) {\r
+                return result;\r
             }\r
         }\r
             }\r
         }\r
-        return cNameGuid;\r
+        return null;\r
+\r
     }\r
 \r
     }\r
 \r
-    public synchronized static String getLibClassIncluder(String libName) {\r
-        String libIncluder = null;\r
-        Set set = spdTable.keySet();\r
-        Iterator iter = set.iterator();\r
+    /**\r
+     * return two values: {cName, GuidValue}\r
+     */\r
+    public static String[] getProtocolGuid(PackageIdentification[] packages,\r
+            String name) throws BuildException {\r
+        if (packages == null) {\r
+            return new String[0];\r
+        }\r
+        String[] result = null;\r
+        for (int i = 0; i < packages.length; i++) {\r
+            Spd spd = spdTable.get(packages[i]);\r
+            //\r
+            // If find one package defined the protocol GUID\r
+            //\r
+            if ((result = spd.getProtocol(name)) != null) {\r
+                return result;\r
+            }\r
+        }\r
+        return null;\r
 \r
 \r
-        while (iter.hasNext()) {\r
-            String packageName = (String) iter.next();\r
-            Spd spd = (Spd) spdTable.get(packageName);\r
-            libIncluder = spd.getLibClassIncluder(libName);\r
-            String packagePath = spd.packagePath;\r
-            if (packagePath != null) {\r
-                packagePath = packagePath.replace('\\', File.separatorChar);\r
-                packagePath = packagePath.replace('/', File.separatorChar);\r
-            } else {\r
-                packagePath = packageName;\r
+    }\r
+    \r
+    /////////////////////////// Update!! Update!! Update!!\r
+//    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
+//        return pcdDbManager;\r
+//    }\r
+    ///////////////////////////\r
+    public synchronized static PlatformIdentification getPlatform(String name) throws BuildException {\r
+        Iterator iter = platformList.iterator();\r
+        while(iter.hasNext()){\r
+            PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
+            if (platformId.getName().equalsIgnoreCase(name)) {\r
+//                GlobalData.log.info("Platform: " + platformId + platformId.getFpdFile());\r
+                return platformId;\r
             }\r
             }\r
-            if (libIncluder != null) {\r
-                libIncluder = libIncluder.replace('\\', File.separatorChar);\r
-                libIncluder = libIncluder.replace('/', File.separatorChar);\r
-                libIncluder = packageName + File.separatorChar + libIncluder;\r
-                break;\r
+        }\r
+        throw new BuildException("Can't find platform [" + name + "] in current workspace. ");\r
+    }\r
+    \r
+    public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r
+        Iterator iter = packageList.iterator();\r
+        while(iter.hasNext()){\r
+            PackageIdentification packageItem = (PackageIdentification)iter.next();\r
+            if (packageItem.equals(packageId)) {\r
+                packageId.setName(packageItem.getName());\r
+                packageId.setSpdFile(packageItem.getSpdFile());\r
+                return packageId;\r
             }\r
         }\r
             }\r
         }\r
-        return libIncluder;\r
+        throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r
+    }\r
+    \r
+    public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r
+//        System.out.println("1");\r
+//        System.out.println("##" + moduleId.getGuid());\r
+        PackageIdentification packageId = getPackageForModule(moduleId);\r
+//        System.out.println("" + packageId.getGuid());\r
+        moduleId.setPackage(packageId);\r
+        Spd spd = spdTable.get(packageId);\r
+        if (spd == null) {\r
+            throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r
+        }\r
+        Set<ModuleIdentification> modules = spd.getModules();\r
+        Iterator<ModuleIdentification> iter = modules.iterator();\r
+        while (iter.hasNext()) {\r
+            ModuleIdentification item = iter.next();\r
+            if (item.equals(moduleId)) {\r
+                moduleId.setName(item.getName());\r
+                moduleId.setModuleType(item.getModuleType());\r
+                moduleId.setMsaFile(item.getMsaFile());\r
+                return moduleId;\r
+            }\r
+        }\r
+        throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");\r
+    }\r
+    \r
+    public synchronized static Set<PackageIdentification> getPackageList(){\r
+        return packageList;\r
+    }\r
+    ///// remove!!\r
+    private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r
+        if ( object == null) {\r
+            return null;\r
+        }\r
+        XmlObject result = null;\r
+        try {\r
+            result = XmlObject.Factory.parse(object.getDomNode()\r
+                            .cloneNode(deep));\r
+        } catch (Exception ex) {\r
+            throw new BuildException(ex.getMessage());\r
+        }\r
+        return result;\r
     }\r
 \r
     }\r
 \r
-    public synchronized static String getModuleInfoByPackageName(String packageName, String moduleType) {\r
-        Spd spd;\r
-        String includeFile = null;\r
-        String includeStr = "";\r
-        String cleanPath = "";\r
-\r
-        spd = (Spd) spdTable.get(packageName);\r
-        includeFile = spd.getModuleTypeIncluder(moduleType);\r
-        if (includeFile != null) {\r
-            includeFile = includeFile.replace('\\', File.separatorChar);\r
-            includeFile = includeFile.replace('/', File.separatorChar);\r
-            includeStr = CommonDefinition.include + " <" + includeStr;\r
-            cleanPath = spd.packagePath;\r
-            cleanPath = cleanPath.replace('\\', File.separatorChar);\r
-            cleanPath = cleanPath.replace('/', File.separatorChar);\r
+    ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r
 \r
 \r
-            if (cleanPath.charAt(spd.packagePath.length() - 1) != File.separatorChar) {\r
-                cleanPath = cleanPath + File.separatorChar;\r
+    public static ToolChainInfo getToolChainInfo() {\r
+//        GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);\r
+        if (toolChainInfo == null) {\r
+            toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r
+            if (toolChainPlatformInfo != null) {\r
+                toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r
             }\r
             }\r
-            includeStr = includeStr + cleanPath;\r
-            includeStr = includeStr + includeFile;\r
-            includeStr = includeStr + ">\r\n";\r
+            toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r
+            toolChainInfo.normalize();\r
+            GlobalData.log.info(toolChainInfo + "");\r
         }\r
         }\r
+        return toolChainInfo;\r
+    }\r
+\r
+\r
 \r
 \r
-        return includeStr;\r
+    public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r
+        platformToolChainFamilyOption = map;\r
     }\r
 \r
     }\r
 \r
-    public synchronized static void setLibInstanceInfo(String libName, String libConstructor, String libDesturctor) {\r
-        String[] libConsDes = new String[2];\r
-        libConsDes[0] = libConstructor;\r
-        libConsDes[1] = libDesturctor;\r
+    public static void setPlatformToolChainOption(ToolChainMap map) {\r
+        platformToolChainOption = map;\r
+    }\r
 \r
 \r
-        libInstanceInfo.put(libName, libConsDes);\r
+    public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r
+        ToolChainMap toolChainOption) {\r
+        moduleToolChainOption.put(fpdModuleId, toolChainOption);\r
     }\r
 \r
     }\r
 \r
-    public synchronized static boolean isHaveLibInstance(String libName) {\r
-        return libInstanceInfo.containsKey(libName);\r
+    public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r
+        ToolChainMap toolChainOption) {\r
+        moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r
     }\r
 \r
     }\r
 \r
-    public synchronized static String getLibInstanceConstructor(String libName) {\r
-        String[] libInstanceValue;\r
-        libInstanceValue = libInstanceInfo.get(libName);\r
-        if (libInstanceValue != null) {\r
-            return libInstanceValue[0];\r
-        } else {\r
-            return null;\r
+    public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
+        ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r
+        ToolChainMap toolChainConfig = toolsDef.getConfig(); \r
+        String setting = null;\r
+\r
+        if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r
+            setting = toolChainConfig.get(toolChainKey);\r
+            if (setting == null) {\r
+                setting = "";\r
+            }\r
+            return setting;\r
         }\r
         }\r
-    }\r
 \r
 \r
-    public synchronized static String getLibInstanceDestructor(String libName) {\r
-        String[] libInstanceValue;\r
-        libInstanceValue = libInstanceInfo.get(libName);\r
-        if (libInstanceValue != null) {\r
-            return libInstanceValue[1];\r
-        } else {\r
-            return null;\r
+        //\r
+        // get module specific options, if any\r
+        //\r
+        // tool tag first\r
+        ToolChainMap option = moduleToolChainOption.get(fpdModuleId);\r
+        ToolChainKey toolChainFamilyKey = null;\r
+\r
+        if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {\r
+            //\r
+            // then tool chain family\r
+            //\r
+            toolChainFamilyKey = new ToolChainKey(commandDescription);\r
+            toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r
+            String family = toolChainConfig.get(toolChainFamilyKey);\r
+            toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r
+            toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r
+\r
+            option = moduleToolChainFamilyOption.get(fpdModuleId);\r
+            if (option != null) {                \r
+                setting = option.get(toolChainFamilyKey);\r
+            }\r
         }\r
         }\r
-    }\r
 \r
 \r
-    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
-        return pcdDbManager;\r
+        //\r
+        // get platform options, if any\r
+        //\r
+        if (setting == null) {\r
+            // tool tag first\r
+            if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {\r
+                // then tool chain family\r
+                if (toolChainFamilyKey == null) {\r
+                    toolChainFamilyKey = new ToolChainKey(commandDescription);\r
+                    toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r
+                    String family = toolChainConfig.get(toolChainFamilyKey);\r
+                    toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r
+                    toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r
+                }\r
+\r
+                setting = platformToolChainFamilyOption.get(toolChainFamilyKey);\r
+            }\r
+        }\r
+\r
+        if (setting == null) {\r
+            setting = "";\r
+        }\r
+\r
+        return setting;\r
+    }\r
+    \r
+    public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r
+        toolChainEnvInfo = envInfo;\r
+    }\r
+    public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r
+        toolChainPlatformInfo = platformInfo;\r
     }\r
     }\r
+\r
+    //\r
+    // for PCD\r
+    //\r
+//    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
+//        return pcdDbManager;\r
+//    }\r
+\r
+    //\r
+    // For PCD\r
+    //\r
+    /**\r
+     * \r
+     * @param guidName\r
+     * @return\r
+     */\r
+//    public synchronized static String[] getGuidInfoGuid(String guidName) {\r
+//        String[] cNameGuid = null;\r
+//        Set set = spdTable.keySet();\r
+//        Iterator iter = set.iterator();\r
+//\r
+//        while (iter.hasNext()) {\r
+//            Spd spd = (Spd) spdTable.get(iter.next());\r
+//            cNameGuid = spd.getGuidNameArray(guidName);\r
+//            if (cNameGuid != null) {\r
+//                break;\r
+//            }\r
+//        }\r
+//        return cNameGuid;\r
+//    }\r
+\r
+    //\r
+    // For PCD\r
+    //\r
+//    public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r
+//            String xmlObjectName) {\r
+//        Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
+//        Iterator item = fpdModuleSASet.iterator();\r
+//\r
+//        Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r
+//        Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r
+//        FpdModuleIdentification moduleId;\r
+//        while (item.hasNext()) {\r
+//            moduleId = (FpdModuleIdentification) item.next();\r
+//            SANode = fpdModuleSA.get(item.next());\r
+//            SAPcdBuildDef.put(moduleId,\r
+//                    (PcdBuildDefinitionDocument.PcdBuildDefinition) SANode\r
+//                            .get(xmlObjectName));\r
+//        }\r
+//        return SAPcdBuildDef;\r
+//    }\r
 }\r
 }\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalShare.java b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalShare.java
deleted file mode 100644 (file)
index 5912127..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/*++\r
-\r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution.  The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- Module Name:\r
- ShareObject.java\r
-\r
- Abstract:\r
-\r
- --*/\r
-package org.tianocore.build.global;\r
-\r
-import java.util.*;\r
-\r
-import org.apache.tools.ant.*;\r
-import org.apache.tools.ant.types.DataType;\r
-\r
-public class GlobalShare extends DataType implements DynamicConfigurator {\r
-    private static final HashMap<String, Object> objStorage = new HashMap<String, Object>();\r
-\r
-    private DataObjectOp op;\r
-\r
-    private String objName;\r
-\r
-    private Object objInst;\r
-\r
-    private String objClassPackage = "org.tianocore";\r
-\r
-    public GlobalShare () {\r
-\r
-    }\r
-\r
-    public GlobalShare (String objName) {\r
-        this.objName = objName;\r
-        this.objInst = objStorage.get(this.objName);\r
-    }\r
-\r
-    public GlobalShare (String objName, Object obj) {\r
-        this.objName = objName;\r
-        this.objInst = obj;\r
-        objStorage.put(this.objName, this.objInst);\r
-    }\r
-\r
-    public Object createDynamicElement(String name) throws BuildException {\r
-        String className = objClassPackage + "." + name;\r
-        log("GlobalShare.createDynamicElement(" + name + ")",\r
-                        Project.MSG_VERBOSE);\r
-        try {\r
-            objInst = Class.forName(className).newInstance();\r
-        } catch (ClassNotFoundException e) {\r
-            throw new BuildException("class name is not found");\r
-        } catch (InstantiationException e) {\r
-            throw new BuildException("the class cannnot be instantiated");\r
-        } catch (IllegalAccessException e) {\r
-            throw new BuildException("cannot access the class");\r
-        }\r
-\r
-        return objInst;\r
-    }\r
-\r
-    public void setDynamicAttribute(String name, String value)\r
-                    throws BuildException {\r
-        log("name = " + name + " value = " + value, Project.MSG_VERBOSE);\r
-        throw new BuildException();\r
-    }\r
-\r
-    public void setName(String name) {\r
-        this.objName = name;\r
-        if (this.op != null) {\r
-            issueOperation();\r
-        }\r
-    }\r
-\r
-    public String getName() {\r
-        return this.objName;\r
-    }\r
-\r
-    public void setPackage(String name) {\r
-        log("ShareObject.setPackage(" + name + ")", Project.MSG_VERBOSE);\r
-        this.objClassPackage = name;\r
-    }\r
-\r
-    public String getPackage() {\r
-        return this.objClassPackage;\r
-    }\r
-\r
-    public void setOperation(String opName) {\r
-        log("ShareObject.setOperation(" + opName + ")", Project.MSG_VERBOSE);\r
-        this.op = DataObjectOp.formString(opName);\r
-\r
-        if (this.objName != null) {\r
-            issueOperation();\r
-        }\r
-    }\r
-\r
-    public String getOperation() {\r
-        return this.op.toString();\r
-    }\r
-\r
-    public void issueOperation() {\r
-        if (this.op == DataObjectOp.ADD) {\r
-\r
-            log("ShareObject: adding ... " + this.objName, Project.MSG_VERBOSE);\r
-            objStorage.put(this.objName, this.objInst);\r
-\r
-        } else if (this.op == DataObjectOp.GET) {\r
-\r
-            log("ShareObject: fetching ... " + this.objName,\r
-                            Project.MSG_VERBOSE);\r
-            objInst = objStorage.get(objName);\r
-\r
-        } else if (this.op == DataObjectOp.DEL) {\r
-\r
-            log("ShareObject: removing ... " + this.objName,\r
-                            Project.MSG_VERBOSE);\r
-            objInst = objStorage.remove(objName);\r
-\r
-        } else {\r
-            throw new BuildException("not supported operation");\r
-        }\r
-    }\r
-\r
-    public Object get() {\r
-        return this.objInst;\r
-    }\r
-\r
-    public static int getObjectNum() {\r
-        return objStorage.size();\r
-    }\r
-\r
-    public static Object add(String objName, Object obj) {\r
-        return objStorage.put(objName, obj);\r
-    }\r
-\r
-    public static Object retrieve(String objName) {\r
-        return objStorage.get(objName);\r
-    }\r
-\r
-    public static Object remove(String objName) {\r
-        return objStorage.remove(objName);\r
-    }\r
-\r
-    public static void empty() {\r
-        objStorage.clear();\r
-    }\r
-}\r
-\r
-class DataObjectOp {\r
-    private static final HashMap<String, DataObjectOp> opMap = new HashMap<String, DataObjectOp>();\r
-\r
-    private final String opName;\r
-\r
-    private DataObjectOp (String name) {\r
-        this.opName = name;\r
-        opMap.put(this.opName, this);\r
-    }\r
-\r
-    public String toString() {\r
-        return opName;\r
-    }\r
-\r
-    public static DataObjectOp formString(String opName) {\r
-        return opMap.get(opName);\r
-    }\r
-\r
-    public static final DataObjectOp ADD = new DataObjectOp("ADD");\r
-\r
-    public static final DataObjectOp GET = new DataObjectOp("GET");\r
-\r
-    public static final DataObjectOp DEL = new DataObjectOp("DEL");\r
-}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/LibBuildFileGenerator.java b/Tools/Source/GenBuild/org/tianocore/build/global/LibBuildFileGenerator.java
deleted file mode 100644 (file)
index 4d7e870..0000000
+++ /dev/null
@@ -1,412 +0,0 @@
-/** @file\r
-  This file is an ANT task.\r
-  \r
-  LibBuildFileGenerator task is used to generate module's build.xml file.\r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-package org.tianocore.build.global;\r
-\r
-import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.Vector;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.transform.OutputKeys;\r
-import javax.xml.transform.Result;\r
-import javax.xml.transform.Source;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Task;\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.MsaHeaderDocument.MsaHeader;\r
-import org.tianocore.MsaLibHeaderDocument.MsaLibHeader;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
-\r
-/**\r
-  This class <code>LibBuildFileGenerator</code> is an ANT task to generate \r
-  build.xml for each module. Here are two usages. \r
-  \r
-  <ul>\r
-    <li>\r
-      For one module (<b>bf</b> is LibBuildFileGenerator task name):\r
-      <pre>\r
-        &lt;bf buildFile="Application\HelloWorld\HelloWorld.msa" /&gt;\r
-      </pre>\r
-    </li>\r
-    <li>\r
-      For one package:\r
-      <pre>\r
-        &lt;bf recursive="true" /&gt;\r
-      </pre>\r
-    </li>\r
-  </ul>\r
-  \r
-  @since GenBuild 1.0\r
-**/\r
-public class LibBuildFileGenerator extends Task {\r
-\r
-    private File buildFile;\r
-\r
-    private boolean recursive = false;\r
-    \r
-    private String license = " Copyright (c) 2006, Intel Corporation \n"\r
-                    + "All rights reserved. This program and the accompanying materials \n"\r
-                    + "are licensed and made available under the terms and conditions of the BSD License \n"\r
-                    + "which accompanies this distribution.  The full text of the license may be found at  \n"\r
-                    + "http://opensource.org/licenses/bsd-license.php \n"\r
-                    + "\n"\r
-                    + "THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS, \n"\r
-                    + "WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.";\r
-\r
-    private String base_name;\r
-    \r
-    private String module_relative_path;\r
-    \r
-    private File base_file = new File(".");\r
-    \r
-    /**\r
-      Public construct method. It is necessary for ANT task.\r
-    **/\r
-    public LibBuildFileGenerator () {\r
-    }\r
-\r
-    /**\r
-      ANT task's entry point, will be called after init(). \r
-      \r
-      @throws BuildException\r
-              buildFile do not specify while recursive set to false\r
-    **/\r
-    public void execute() throws BuildException {\r
-        if(recursive){\r
-            searchMsa(new File("."));\r
-        }\r
-        else {\r
-            Map<String,File> map = new HashMap<String,File>();\r
-            String basename = buildFile.getName();\r
-            int k = basename.lastIndexOf('.');\r
-            base_name = basename.substring(0, k);\r
-            map.put(base_name, buildFile);\r
-            genBuildFile(map);\r
-        }\r
-    }\r
-    \r
-    /**\r
-      Recursivly find all MSA files and record all modules. \r
-      \r
-      @param path Package path\r
-    **/\r
-    private void searchMsa(File path){\r
-        File[] files = path.listFiles();\r
-        Vector<File> vec = new Vector<File>();\r
-        for(int i=0; i < files.length; i ++){\r
-            if (files[i].isFile()){\r
-                if(files[i].getName().endsWith(".msa")){\r
-                    System.out.println("#" + files[i].getPath());\r
-                    vec.add(files[i]);\r
-                }\r
-            }\r
-        }\r
-        Map<String,File> mapBasename = new HashMap<String,File>();\r
-        if (vec.size() > 0){\r
-            base_name = null;\r
-            for ( int j = 0 ; j < vec.size(); j++){\r
-                if ( vec.size() > 1){\r
-                  System.out.println("##" + vec.get(0));\r
-                }\r
-                File f = (File)vec.get(j);\r
-                SurfaceAreaParser surfaceAreaParser = new SurfaceAreaParser();\r
-                Map<String, XmlObject> map = surfaceAreaParser.parseFile(f);\r
-                String baseName = "";\r
-                XmlObject header = null;\r
-                if ( (header = map.get("MsaHeader")) != null ){\r
-                    baseName = ((MsaHeader)header).getBaseName().getStringValue();\r
-                }\r
-                else if ( (header = map.get("MsaLibHeader")) != null){\r
-                    baseName = ((MsaLibHeader)header).getBaseName().getStringValue();\r
-                } else {\r
-                    continue ;\r
-                }\r
-                if ( base_name == null || base_name.length() > baseName.length()){\r
-                    base_name = baseName;\r
-                    buildFile = f;\r
-                    try {\r
-                    module_relative_path = buildFile.getParent().substring(base_file.getPath().length() + 1);\r
-                    }\r
-                    catch(Exception e){\r
-                        module_relative_path = ".";\r
-                    }\r
-                }\r
-                mapBasename.put(baseName, f);\r
-            }\r
-            genBuildFile(mapBasename);\r
-        }\r
-\r
-        for(int i=0; i < files.length; i ++){\r
-            if (files[i].isDirectory()){\r
-                searchMsa(files[i]);\r
-            }\r
-        }\r
-    }\r
-    \r
-    /**\r
-      Generate build.xml.\r
-      \r
-      @param map All base name under one module directory\r
-    **/\r
-    private void genBuildFile(Map map) {\r
-        DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
-        try {\r
-            DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
-            Document document = dombuilder.newDocument();\r
-            //\r
-            // create root element and its attributes\r
-            //\r
-            document.appendChild(document.createComment(license));\r
-            Element root = document.createElement("project");\r
-            root.setAttribute("default", base_name);\r
-            root.setAttribute("basedir", ".");\r
-            //\r
-            // element for External ANT tasks\r
-            //\r
-            root.appendChild(document.createComment("Apply external ANT tasks"));\r
-            Element ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "GenBuild.tasks");\r
-            root.appendChild(ele);\r
-            //\r
-            // <taskdef resource="net/sf/antcontrib/antlib.xml" />\r
-            //\r
-            ele = document.createElement("taskdef");\r
-            ele.setAttribute("resource", "net/sf/antcontrib/antlib.xml");\r
-            root.appendChild(ele);\r
-            \r
-            ele = document.createElement("property");\r
-            ele.setAttribute("environment", "env");\r
-            root.appendChild(ele);\r
-\r
-            ele = document.createElement("property");\r
-            ele.setAttribute("name", "WORKSPACE_DIR");\r
-            ele.setAttribute("value", "${env.WORKSPACE}");\r
-            root.appendChild(ele);\r
-            \r
-            ele = document.createElement("import");\r
-            ele.setAttribute("file", "${WORKSPACE_DIR}"+File.separatorChar+"Tools"+File.separatorChar+"Conf"+File.separatorChar+"BuildMacro.xml");\r
-            root.appendChild(ele);\r
-            \r
-            root.appendChild(document.createComment("MODULE_RELATIVE PATH is relative to PACKAGE_DIR"));\r
-            ele = document.createElement("property");\r
-            ele.setAttribute("name", "MODULE_RELATIVE_PATH");\r
-            ele.setAttribute("value", module_relative_path);\r
-            root.appendChild(ele);\r
-\r
-            ele = document.createElement("property");\r
-            ele.setAttribute("name", "MODULE_DIR");\r
-            ele.setAttribute("value", "${PACKAGE_DIR}" + File.separatorChar + "${MODULE_RELATIVE_PATH}");\r
-            root.appendChild(ele);\r
-\r
-            ele = document.createElement("property");\r
-            ele.setAttribute("name", "COMMON_FILE");\r
-            ele.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar + "Tools"\r
-                            + File.separatorChar + "Conf" + File.separatorChar + "Common.xml");\r
-            root.appendChild(ele);\r
-            \r
-            //\r
-            // generate the buildfmd target\r
-            //\r
-            Set set = map.keySet();\r
-            Iterator iter = set.iterator();\r
-            while (iter.hasNext()){\r
-                String bName = (String)iter.next();\r
-                File msaFile = (File)map.get(bName);\r
-                String msaFilename = "${MODULE_DIR}" + File.separatorChar + msaFile.getName();\r
-                String mbdFilename = msaFilename.substring(0 , msaFilename.length() - 4) + ".mbd";\r
-                ele = document.createElement("target");\r
-                ele.setAttribute("name", bName);\r
-                Element target = document.createElement("GenBuild");\r
-                target.setAttribute("msaFilename", msaFilename);\r
-                target.setAttribute("mbdFilename", mbdFilename);\r
-                target.setAttribute("baseName", bName);\r
-                ele.appendChild(target);\r
-                root.appendChild(ele);\r
-            }\r
-\r
-            root.appendChild(ele);\r
-            //\r
-            // Default clean\r
-            //\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "clean");\r
-            ele.setAttribute("depends", base_name + "_clean");\r
-            root.appendChild(ele);\r
-            //\r
-            // Default Clean ALl\r
-            //\r
-            ele = document.createElement("target");\r
-            ele.setAttribute("name", "cleanall");\r
-            ele.setAttribute("depends", base_name + "_cleanall");\r
-            root.appendChild(ele);\r
-            //\r
-            // Every clean target for each BaseName\r
-            //\r
-            set = map.keySet();\r
-            iter = set.iterator();\r
-            while (iter.hasNext()){\r
-                String bName = (String)iter.next();\r
-                File msaFile = (File)map.get(bName);\r
-                String msaFilename = "${MODULE_DIR}" + File.separatorChar + msaFile.getName();\r
-                String mbdFilename = msaFilename.substring(0 , msaFilename.length() - 4) + ".mbd";\r
-                \r
-                ele = document.createElement("target");\r
-                ele.setAttribute("name", bName + "_clean");\r
-                //\r
-                // Output Dir\r
-                //\r
-                Element target = document.createElement("OutputDirSetup");\r
-                target.setAttribute("msaFilename", msaFilename);\r
-                target.setAttribute("mbdFilename", mbdFilename);\r
-                target.setAttribute("baseName", bName);\r
-                ele.appendChild(target);\r
-                //\r
-                // Call BaseName_build.xml clean\r
-                //\r
-                Element ifEle = document.createElement("if");\r
-                Element availableEle = document.createElement("available");\r
-                availableEle.setAttribute("file", "${DEST_DIR_OUTPUT}" + File.separatorChar + bName + "_build.xml");\r
-                ifEle.appendChild(availableEle);\r
-                Element elseEle = document.createElement("then");\r
-                \r
-                Element moduleEle = document.createElement("ant");\r
-                moduleEle.setAttribute("antfile", "${DEST_DIR_OUTPUT}" + File.separatorChar + bName + "_build.xml");\r
-                moduleEle.setAttribute("target", "clean");\r
-                \r
-                elseEle.appendChild(moduleEle);\r
-                ifEle.appendChild(elseEle);\r
-                ele.appendChild(ifEle);\r
-                //\r
-                // just delete\r
-                //\r
-                Element clean = document.createElement("delete");\r
-                clean.setAttribute("dir", "${DEST_DIR_OUTPUT}");\r
-                clean.setAttribute("excludes", "*.xml");\r
-                ele.appendChild(clean);\r
-                \r
-                root.appendChild(ele);\r
-            }\r
-            //\r
-            // Every Clean ALl target for each BaseName\r
-            //\r
-            set = map.keySet();\r
-            iter = set.iterator();\r
-            while (iter.hasNext()){\r
-                String bName = (String)iter.next();\r
-                File msaFile = (File)map.get(bName);\r
-                String msaFilename = "${MODULE_DIR}" + File.separatorChar + msaFile.getName();\r
-                String mbdFilename = msaFilename.substring(0 , msaFilename.length() - 4) + ".mbd";\r
-                \r
-                ele = document.createElement("target");\r
-                ele.setAttribute("name", bName + "_cleanall");\r
-                //\r
-                // Output Dir\r
-                //\r
-                Element target = document.createElement("OutputDirSetup");\r
-                target.setAttribute("msaFilename", msaFilename);\r
-                target.setAttribute("mbdFilename", mbdFilename);\r
-                target.setAttribute("baseName", bName);\r
-                ele.appendChild(target);\r
-                //\r
-                // Call BaseName_build.xml clean\r
-                //\r
-                Element ifEle = document.createElement("if");\r
-                Element availableEle = document.createElement("available");\r
-                availableEle.setAttribute("file", "${DEST_DIR_OUTPUT}" + File.separatorChar + bName + "_build.xml");\r
-                ifEle.appendChild(availableEle);\r
-                Element elseEle = document.createElement("then");\r
-                \r
-                Element moduleEle = document.createElement("ant");\r
-                moduleEle.setAttribute("antfile", "${DEST_DIR_OUTPUT}" + File.separatorChar + bName + "_build.xml");\r
-                moduleEle.setAttribute("target", "cleanall");\r
-                \r
-                elseEle.appendChild(moduleEle);\r
-                ifEle.appendChild(elseEle);\r
-                ele.appendChild(ifEle);\r
-                //\r
-                // just delete\r
-                //\r
-                Element clean = document.createElement("delete");\r
-                clean.setAttribute("dir", "${DEST_DIR_OUTPUT}");\r
-                ele.appendChild(clean);\r
-                \r
-                clean = document.createElement("delete");\r
-                clean.setAttribute("dir", "${DEST_DIR_DEBUG}");\r
-                ele.appendChild(clean);\r
-                \r
-                clean = document.createElement("delete");\r
-                Element fileset = document.createElement("fileset");\r
-                fileset.setAttribute("dir", "${BIN_DIR}");\r
-                fileset.setAttribute("includes", "**" + bName + "*");\r
-                clean.appendChild(fileset);\r
-                ele.appendChild(clean);\r
-                \r
-                root.appendChild(ele);\r
-            }\r
-            document.appendChild(root);\r
-            //\r
-            // Prepare the DOM document for writing\r
-            //\r
-            Source source = new DOMSource(document);\r
-            //\r
-            // Prepare the output file\r
-            //\r
-            String filename = buildFile.getParent() + File.separatorChar + "build.xml";\r
-            File file = new File(getProject().replaceProperties(filename));\r
-            //\r
-            // generate all directory path\r
-            //\r
-            Result result = new StreamResult(file);\r
-            //\r
-            // Write the DOM document to the file\r
-            //\r
-            Transformer xformer = TransformerFactory.newInstance()\r
-                            .newTransformer();\r
-            xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
-            xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
-            xformer.transform(source, result);\r
-        } catch (Exception ex) {\r
-            System.out.println("##" + ex);\r
-        }\r
-    }\r
-    \r
-    \r
-    public File getBuildFile() {\r
-        return buildFile;\r
-    }\r
-\r
-    public void setBuildFile(File buildFile) {\r
-        this.buildFile = buildFile;\r
-    }\r
-\r
-    public boolean isRecursive() {\r
-        return recursive;\r
-    }\r
-\r
-    public void setRecursive(boolean recursive) {\r
-        this.recursive = recursive;\r
-    }\r
-}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/ModuleIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/global/ModuleIdentification.java
deleted file mode 100644 (file)
index 74311d4..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.tianocore.build.global;\r
-\r
-public class ModuleIdentification {\r
-\r
-    private String baseName;\r
-    \r
-    private String packageName;\r
-    \r
-    private String guid;\r
-    \r
-    private String version;\r
-    \r
-    public ModuleIdentification(String baseName, String packageName, String guid, String version){\r
-        this.baseName = baseName;\r
-        this.packageName = packageName;\r
-        this.guid = guid;\r
-        this.version = version;\r
-    }\r
-    \r
-    public boolean equals(Object obj) {\r
-        if (obj instanceof ModuleIdentification) {\r
-            ModuleIdentification moduleIdObj = (ModuleIdentification)obj;\r
-            if ( baseName.equalsIgnoreCase(moduleIdObj.baseName)) {\r
-                return true;\r
-            }\r
-            // TBD\r
-            return false;\r
-        }\r
-        else {\r
-            return super.equals(obj);\r
-        }\r
-    }\r
-    \r
-    public String toString(){\r
-        return packageName + ":" + guid + "_" + baseName + "_" + version;\r
-    }\r
-\r
-    public void setBaseName(String baseName) {\r
-        this.baseName = baseName;\r
-    }\r
-\r
-    public void setGuid(String guid) {\r
-        this.guid = guid;\r
-    }\r
-\r
-    public void setPackageName(String packageName) {\r
-        this.packageName = packageName;\r
-    }\r
-\r
-    public void setVersion(String version) {\r
-        this.version = version;\r
-    }\r
-    \r
-    \r
-}\r
index 01e24e653f1ed915c33a6e74fc10082a5bdd39c2..773fe3e94922b395e06c1fade0e6712af65704b7 100644 (file)
@@ -19,158 +19,180 @@ import java.io.File;
 \r
 /**\r
   OutputManager class is used to setup output directories (BIN_DIR, DEST_DIR_OUTPUT, \r
 \r
 /**\r
   OutputManager class is used to setup output directories (BIN_DIR, DEST_DIR_OUTPUT, \r
-  DEST_DIR_DEBUG) according to BUILD_MODE\r
+  DEST_DIR_DEBUG). \r
   \r
   @since GenBuild 1.0\r
 **/\r
 public class OutputManager {\r
   \r
   @since GenBuild 1.0\r
 **/\r
 public class OutputManager {\r
-    \r
-    ///\r
-    /// Single Module build\r
-    ///\r
-    public static final String MODULE_BUILD = "MODULE";\r
-\r
-    ///\r
-    /// Package build\r
-    ///\r
-    public static final String PACKAGE_BUILD = "PACKAGE";\r
 \r
     ///\r
 \r
     ///\r
-    /// Platform build\r
+    /// means intermediate files will put under Module's dir\r
     ///\r
     ///\r
-    public static final String PLATFORM_BUILD = "PLATFORM";\r
-    \r
-    public static String buildMode = MODULE_BUILD;\r
+    private String MODULE = "MODULE";\r
     \r
     ///\r
     \r
     ///\r
-    /// For Package build, PLATFORM represent PACKAGE\r
+    /// mean intermediate files will put under a unify dir\r
     ///\r
     ///\r
-    public static String PLATFORM;\r
+    private String UNIFIED = "UNIFIED";\r
     \r
     \r
-    ///\r
-    /// For Platform build, PLATFORM_DIR represent PACKAGE_DIR\r
-    ///\r
-    public static String PLATFORM_DIR;\r
     \r
     \r
-    ///\r
-    /// means intermediate files will put under Module's dir\r
-    ///\r
-    public static final String MODULE = "MODULE";\r
+    private String userdir;\r
     \r
     \r
+    private String type;\r
     ///\r
     ///\r
-    /// mean intermediate files will put under a unify dir\r
+    /// Singleton Design Pattern\r
     ///\r
     ///\r
-    public static final String UNIFIED = "UNIFIED";\r
+    private static OutputManager object;\r
     \r
     \r
-    ///\r
-    /// Flag to ensure the function <code>update</code> will be called only one in the whole build.\r
-    ///\r
-    private static boolean flag = true;\r
+    public synchronized static OutputManager getInstance() {\r
+        if ( object == null ) {\r
+            object = new OutputManager();\r
+        }\r
+        return object;\r
+    }\r
+    \r
+    public void setup(String userdir, String type) {\r
+        this.userdir = userdir;\r
+        this.type = type;\r
+    }\r
     \r
     /**\r
     \r
     /**\r
-      If BUILD_MODE is PLATFORM or PACKAGE, record PLATFORM and PLARFORM_DIR.\r
-      Reminder that for PACKAGE build, here set value PACKAGE to PLATFORM and\r
-      PACKAGE_DIR to PLARFORM_DIR, and also update the ant properties. \r
+      Setup BIN_DIR, DEST_DIR_OUTPUT and DEST_DIR_OUTPUT, following are the rules:\r
+      \r
+      <p>Divide all output files into two types: one is final files, such as FFS \r
+      file for driver module while LIB file for library module; another is \r
+      intermediate files, such AutoGen.c, OBJ files, Section files and so on. \r
+      \r
+      <p>In FPD, OutputDirectory element is used to specify where to put the output \r
+      files to. There are two mode (MODULE | UNIFIED). MODULE mode means that all \r
+      output files will put to the module directory while UNIFIED mode means that \r
+      all output files will put together. Default is UNIFIED mode. \r
+      \r
+      <p>BUILD_DIR is the base directory for current module build. By default, \r
+      BUILD_DIR is PLATFORM_DIR/Build in UNIFIED mode while is MODULE_DIR/Build \r
+      in MODULE mode. Of course, user can customize BUILD_DIR. If user-defined \r
+      BUILD_DIR is relative path, then look as related to WORKSPACE_DIR. \r
       \r
       \r
-      <p>Note that this function will be called only once in the whole build.</p> \r
+      <p>Then, BIN_DIR is BUILD_DIR/TARGET/TOOLCHAIN/ARCH;\r
+      \r
+      <p>FV_DIR is BUILD_DIR/TARGET/TOOLCHAIN/FV;\r
+      \r
+      <p>DEST_DIR_DEBUG | DEST_DIR_OUTPUT is: \r
+      BIN_DIR/PACKAGE_RELATIVE_DIR/MODULE_RELATIVE_DIR/DEBUG | OUTPUT\r
+\r
       \r
       @param project current ANT build Project\r
       \r
       @param project current ANT build Project\r
+      @param userdir user-defined directory\r
+      @param type the module build type (MODULE or UNIFIED)\r
     **/\r
     **/\r
-    public synchronized static void update(Project project) {\r
-        if (flag){\r
-            flag = false;\r
-            String str = project.getProperty("BUILD_MODE");\r
-            if (str != null){\r
-                if (str.equals(PLATFORM_BUILD)) {\r
-                    buildMode = PLATFORM_BUILD;\r
-                    PLATFORM = project.getProperty("PLATFORM");\r
-                    PLATFORM_DIR = project.getProperty("PLATFORM_DIR");\r
-                }\r
-                else if (str.equals(PACKAGE_BUILD)) {\r
-                    buildMode = PACKAGE_BUILD;\r
-                    PLATFORM = project.getProperty("PACKAGE");\r
-                    PLATFORM_DIR = project.getProperty("PACKAGE_DIR");\r
-                    project.setProperty("PLATFORM", PLATFORM);\r
-                    project.setProperty("PLATFORM_DIR", PLATFORM_DIR);\r
-                }\r
+    public void update(Project project) {\r
+//        GlobalData.log.info("" + userdir + ":" + type);\r
+        //\r
+        // Default mode is UNIFIED. \r
+        //\r
+        if (type != null && type.equalsIgnoreCase(MODULE)) {\r
+            type = MODULE;\r
+        }\r
+        else {\r
+            type = UNIFIED;\r
+        }\r
+        \r
+        //\r
+        // default BUILD_DIR value\r
+        //\r
+        String buildDir;\r
+        if(type.equals(MODULE)){\r
+            buildDir = project.getProperty("MODULE_DIR") + File.separatorChar + "Build";\r
+        }\r
+        else {\r
+            buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";\r
+        }\r
+        \r
+        //\r
+        // If user define BUILD_DIR\r
+        //\r
+        if (userdir != null && ! userdir.equals("")) {\r
+            File buildFile = new File(userdir);\r
+            if (buildFile.isAbsolute()){\r
+                buildDir = userdir;\r
+            }\r
+            //\r
+            // If path is not absolute, then look as related to WORKSPACE_DIR\r
+            //\r
+            else {\r
+                buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;\r
             }\r
         }\r
             }\r
         }\r
-    }\r
-    \r
-    /**\r
-      Setup BIN_DIR, DEST_DIR_OUTPUT and DEST_DIR_OUTPUT, following are the rules:\r
-      \r
-      <pre>\r
-        Those three variables are defined as following\r
-        DEST_DIR_OUTPUT (intermediate files)\r
-        DEST_DIR_DEBUG (intermediate debug files)\r
-        BIN_DIR (final files)\r
         \r
         \r
-        Output Dir (MODULE or UNIFIED):\r
-        For <b>Module</b> build: \r
-        All intermediate files are at ${MODULE_DIR}/Build/${TARGET}/${ARCH}/DEBUG|OUTPUT\r
-        All final files are at ${MODULE_DIR}/Build/${TARGET}/${ARCH}\r
+        //\r
+        // Define BIN_DIR and FV_DIR\r
+        //\r
+        String binDir = buildDir + File.separatorChar + project.getProperty("TARGET")\r
+                                 + File.separatorChar + project.getProperty("TOOLCHAIN") \r
+                                 + File.separatorChar + project.getProperty("ARCH") ;\r
         \r
         \r
-        For <b>Platform</b> build:\r
-        If specified with MODULE\r
-        Intermediate files->${MODULE_DIR}/Build/${PLATFORM}/${TARGET}/${ARCH}/DEBUG|OUTPUT\r
-        Final files -> ${PLARFORM_DIR}/Build/${TARGET}/${ARCH}\r
+        String fvDir = buildDir + File.separatorChar + project.getProperty("TARGET")\r
+                                + File.separatorChar + project.getProperty("TOOLCHAIN") \r
+                                + File.separatorChar + "FV";\r
         \r
         \r
-        Else if specified with UNIFIED\r
-        Intermediate files->${PLARFORM_DIR}/Build/${TARGET}/${ARCH}/${PACKAGE}/${SOURCE_RELATIVE_PATH}/DEBUG|OUTPUT\r
-        Final files -> ${PLARFORM_DIR}/Build/${TARGET}/${ARCH}\r
+        //\r
+        // Define DEST_DIR_OUTPUT and DEST_DIR_DEBUG\r
+        //\r
+        String destDir = binDir + File.separatorChar + project.getProperty("PACKAGE_RELATIVE_DIR")\r
+                                + File.separatorChar + project.getProperty("MODULE_RELATIVE_DIR");\r
         \r
         \r
-        For <b>Package</b> build:\r
-        If specified with MODULE\r
-        Intermediate files->${MODULE_DIR}/Build/${PACKAGE}/${TARGET}/${ARCH}/DEBUG|OUTPUT\r
-        Final files -> ${PACKAGE_DIR}/Build/${TARGET}/${ARCH}\r
+        //\r
+        // Set properties\r
+        //\r
+        project.setProperty("BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));\r
+        project.setProperty("FV_DIR", fvDir.replaceAll("(\\\\)", "/"));\r
+        project.setProperty("BIN_DIR", binDir.replaceAll("(\\\\)", "/"));\r
+        project.setProperty("DEST_DIR_DEBUG", (destDir + File.separatorChar + "DEBUG").replaceAll("(\\\\)", "/"));\r
+        project.setProperty("DEST_DIR_OUTPUT", (destDir + File.separatorChar + "OUTPUT").replaceAll("(\\\\)", "/"));\r
         \r
         \r
-        Else if specified with UNIFIED\r
-        Intermediate files->${PACKAGE_DIR}/Build/${TARGET}/${ARCH}/${PACKAGE}/${SOURCE_RELATIVE_PATH}/DEBUG|OUTPUT\r
-        Final files -> ${PACKAGE_DIR}/Build/${TARGET}/${ARCH}\r
-      </pre>\r
-      \r
-      @param project current ANT build Project\r
-      @param userdir user-defined directory\r
-      @param type the module build type (MODULE or UNIFIED)\r
-    **/\r
-    public synchronized static void update(Project project, String userdir, String type) {\r
-        //\r
-        // userdir TBD\r
-        //\r
-       if(  type == null || ! type.equals(MODULE)){\r
-           type = UNIFIED;\r
-       }\r
-       if (buildMode.equals(MODULE_BUILD)){\r
-           project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${MODULE_DIR}"\r
-                        + File.separatorChar + "Build" + File.separatorChar + "${TARGET}"\r
-                        + File.separatorChar + "${ARCH}" + File.separatorChar + "OUTPUT"));\r
-           project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "DEBUG"));\r
-           project.setProperty("BIN_DIR", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));\r
-       }\r
-       else if (buildMode.equals(PLATFORM_BUILD)) {\r
-           if (type.equals(MODULE)) {\r
-               project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "OUTPUT"));\r
-               project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "DEBUG"));\r
-               project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));\r
-           }\r
-           else if (type.equals(UNIFIED)){\r
-               project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "OUTPUT"));\r
-               project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "DEBUG"));\r
-               project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));\r
-           }\r
-       }\r
-       else if (buildMode.equals(PACKAGE_BUILD)) {\r
-           if (type.equals(MODULE)) {\r
-               project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "OUTPUT"));\r
-               project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "DEBUG"));\r
-               project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));\r
-           }\r
-           else if (type.equals(UNIFIED)){\r
-               project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "OUTPUT"));\r
-               project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "DEBUG"));\r
-               project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));\r
-           }\r
-       }\r
+        //\r
+        // Create all directory if necessary\r
+        //\r
+        (new File(buildDir)).mkdirs();\r
+        (new File(fvDir)).mkdirs();\r
+        (new File(binDir)).mkdirs();\r
+        (new File(destDir + File.separatorChar + "DEBUG")).mkdirs();\r
+        (new File(destDir + File.separatorChar + "OUTPUT")).mkdirs();\r
     }\r
     }\r
-}\r
+    \r
+    public boolean prepareBuildDir(Project project){\r
+        boolean isUnified = true;\r
+        \r
+        if (type.equalsIgnoreCase("MODULE")) {\r
+            isUnified = false;\r
+        }\r
+        \r
+        String buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";\r
+        //\r
+        // If user define BUILD_DIR\r
+        //\r
+        if (userdir != null && ! userdir.equals("")) {\r
+            File buildFile = new File(userdir);\r
+            if (buildFile.isAbsolute()){\r
+                buildDir = userdir;\r
+            }\r
+            //\r
+            // If path is not absolute, then look as related to WORKSPACE_DIR\r
+            //\r
+            else {\r
+                buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;\r
+            }\r
+        }\r
+        //\r
+        // Set to property\r
+        //\r
+        project.setProperty("BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));\r
+        \r
+        //\r
+        // Create all directory if necessary\r
+        //\r
+        (new File(buildDir)).mkdirs();\r
+        return isUnified;\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/OverrideProcess.java b/Tools/Source/GenBuild/org/tianocore/build/global/OverrideProcess.java
deleted file mode 100644 (file)
index 60f430f..0000000
+++ /dev/null
@@ -1,361 +0,0 @@
-/** @file\r
-  OverrideProcess class.\r
-  \r
-  OverrideProcess class is used to override surface area information. \r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-package org.tianocore.build.global;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import javax.xml.namespace.QName;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.xmlbeans.XmlCursor;\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.BootModesDocument;\r
-import org.tianocore.BuildOptionsDocument;\r
-import org.tianocore.DataHubsDocument;\r
-import org.tianocore.EventsDocument;\r
-import org.tianocore.ExternsDocument;\r
-import org.tianocore.FormsetsDocument;\r
-import org.tianocore.GuidsDocument;\r
-import org.tianocore.HobsDocument;\r
-import org.tianocore.IncludesDocument;\r
-import org.tianocore.LibrariesDocument;\r
-import org.tianocore.LibraryClassDefinitionsDocument;\r
-import org.tianocore.MsaHeaderDocument;\r
-import org.tianocore.MsaLibHeaderDocument;\r
-import org.tianocore.PcdCodedDocument;\r
-import org.tianocore.PPIsDocument;\r
-import org.tianocore.ProtocolsDocument;\r
-import org.tianocore.SourceFilesDocument;\r
-import org.tianocore.SystemTablesDocument;\r
-import org.tianocore.VariablesDocument;\r
-import org.tianocore.PackageDependenciesDocument;\r
-\r
-/**\r
-  This class is used to override surface area information. For example, MBD can\r
-  overried MSA, Platform can override all information of the module. \r
-  \r
-  <p>Override will take effect if two element satisfy one of following two condition: </p>\r
-  <ul>\r
-    <li>Element name and its attribute OverrideID equal each other. </li>\r
-    <li>Element is defined as exclusive which mean such element can be\r
-    only appeared in the surface area. </li>\r
-  </ul>\r
-  \r
-  <p>For example, here OutputDirectory element is exclusive: </p>\r
-  \r
-  <pre>\r
-  Low priority Xml Document fragment:\r
-     &lt;Libraries&gt;\r
-       &lt;Arch ArchType="IA32"&gt;\r
-         &lt;Library OverrideID="8888"&gt;EdkPeCoffLoaderLib&lt;/Library&gt;\r
-         &lt;Library OverrideID="8888"&gt;BasePeCoffLib&lt;/Library&gt;\r
-       &lt;/Arch&gt;\r
-     &lt;/Libraries&gt; \r
-     &lt;BuildOptions&gt;\r
-       &lt;OutputDirectory IntermediateDirectories="MODULE"/&gt;\r
-       &lt;Option&gt;CC_FLAGS = "/NOLOGO", "/C"&lt;/Option&gt;\r
-     &lt;BuildOptions&gt;\r
\r
-  High priority Xml Document fragment:\r
-     &lt;Libraries&gt;\r
-       &lt;Arch ArchType="IA32"&gt;\r
-         &lt;Library OverrideID="8888">Nt32PeCoffLoaderLib&lt;/Library&gt;\r
-       &lt;/Arch&gt;\r
-     &lt;/Libraries&gt;\r
-     &lt;BuildOptions&gt;\r
-       &lt;OutputDirectory IntermediateDirectories="UNIFIED"/&gt;\r
-       &lt;Option&gt;LIB_FLAGS = "/NOLOGO"&lt;/Option&gt;\r
-     &lt;BuildOptions&gt;\r
-     \r
-   The result is: \r
-     &lt;Libraries&gt;\r
-       &lt;Arch ArchType="IA32"&gt;\r
-         &lt;Library OverrideID="8888"&gt;Nt32PeCoffLoaderLib&lt;/Library&gt;\r
-       &lt;/Arch&gt;\r
-     &lt;/Libraries&gt;\r
-     &lt;BuildOptions&gt;\r
-       &lt;OutputDirectory IntermediateDirectories="UNIFIED"/&gt;\r
-       &lt;Option&gt;CC_FLAGS = "/NOLOGO", "/C"&lt;/Option&gt;\r
-       &lt;Option&gt;LIB_FLAGS = "/NOLOGO"&lt;/Option&gt;\r
-     &lt;BuildOptions&gt;\r
-   \r
-  </pre>\r
-  \r
-  <p>Note that using XmlBeans to walk through the whole XML document tree.</p> \r
-  \r
-  @since GenBuild 1.0\r
-  @see org.apache.xmlbeans.XmlBeans\r
-**/\r
-public class OverrideProcess {\r
-\r
-    ///\r
-    /// URI, the namespace of current XML schema\r
-    ///\r
-    public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";\r
-\r
-    ///\r
-    /// list of top elements of surface area\r
-    ///\r
-    public static String[] topElements = { "LibraryClassDefinitions",\r
-                    "SourceFiles", "Includes", "PackageDependencies", "Libraries", "Protocols",\r
-                    "Events", "Hobs", "PPIs", "Variables", "BootModes",\r
-                    "SystemTables", "DataHubs", "Formsets", "Guids", "Externs",\r
-                    "PcdCoded", "BuildOptions" };\r
-\r
-    ///\r
-    /// list of exclusive elements\r
-    ///\r
-    public static String[] exclusiveElements = {"OutputDirectory"};\r
-    \r
-    /**\r
-      Recursively find out all elements specified with OverrideId attribute\r
-      and exclusive elements in current XML object. \r
-      \r
-      @param o curent parsing XML object\r
-      @param map Map to list elements specified OverrideID attribute\r
-      @param execlusiveMap Map to list exclusive elements appeared in current XMl object\r
-      @param level the depth in XML document tree\r
-    **/\r
-    private void listOverrideID(XmlObject o, Map<String,Object> map, Map<String,Object> execlusiveMap, int level) {\r
-        XmlCursor cursor = o.newCursor();\r
-        String name = cursor.getName().getLocalPart();\r
-        for (int i = 0 ; i < exclusiveElements.length; i++){\r
-            if (name.equalsIgnoreCase(exclusiveElements[i])){\r
-                execlusiveMap.put(exclusiveElements[i], cursor.getObject());\r
-            }\r
-        }\r
-        String overrideID = cursor.getAttributeText(new QName("OverrideID"));\r
-        if (overrideID != null) {\r
-            map.put(name + ":" + overrideID, cursor.getObject());\r
-        }\r
-        if (cursor.toFirstChild()) {\r
-            do {\r
-                listOverrideID(cursor.getObject(), map, execlusiveMap, level + 1);\r
-            } while (cursor.toNextSibling());\r
-        }\r
-    }\r
-\r
-    /**\r
-      This function is used to prepare for overriding with changing data. \r
-      \r
-      @param map original surface area information \r
-      @return after normalize surface area information\r
-    **/\r
-    public synchronized static Map<String, XmlObject> deal(Map<String, XmlObject> map) {\r
-        Map<String, XmlObject> newMap = new HashMap<String, XmlObject>();\r
-        if (map.get("MsaHeader") != null) {\r
-            newMap.put("MsaHeader", ((MsaHeaderDocument) map.get("MsaHeader"))\r
-                            .getMsaHeader());\r
-        }\r
-        if (map.get("MsaLibHeader") != null) {\r
-            newMap.put("MsaLibHeader", ((MsaLibHeaderDocument) map\r
-                            .get("MsaLibHeader")).getMsaLibHeader());\r
-        }\r
-        if (map.get("LibraryClassDefinitions") != null) {\r
-            newMap.put("LibraryClassDefinitions",\r
-                            ((LibraryClassDefinitionsDocument) map\r
-                                            .get("LibraryClassDefinitions"))\r
-                                            .getLibraryClassDefinitions());\r
-        }\r
-        if (map.get("SourceFiles") != null) {\r
-            newMap.put("SourceFiles", ((SourceFilesDocument) map\r
-                            .get("SourceFiles")).getSourceFiles());\r
-        }\r
-        if (map.get("Includes") != null) {\r
-            newMap.put("Includes", ((IncludesDocument) map.get("Includes"))\r
-                            .getIncludes());\r
-        }\r
-        if (map.get("PackageDependencies") != null) {\r
-            newMap.put("PackageDependencies", ((PackageDependenciesDocument) map.get("PackageDependencies"))\r
-                            .getPackageDependencies());\r
-        }\r
-        if (map.get("Libraries") != null) {\r
-            newMap.put("Libraries", ((LibrariesDocument) map.get("Libraries"))\r
-                            .getLibraries());\r
-        }\r
-        if (map.get("Protocols") != null) {\r
-            newMap.put("Protocols", ((ProtocolsDocument) map.get("Protocols"))\r
-                            .getProtocols());\r
-        }\r
-        if (map.get("Events") != null) {\r
-            newMap.put("Events", ((EventsDocument) map.get("Events"))\r
-                            .getEvents());\r
-        }\r
-        if (map.get("Hobs") != null) {\r
-            newMap.put("Hobs", ((HobsDocument) map.get("Hobs")).getHobs());\r
-        }\r
-        if (map.get("PPIs") != null) {\r
-            newMap.put("PPIs", ((PPIsDocument) map.get("PPIs")).getPPIs());\r
-        }\r
-        if (map.get("Variables") != null) {\r
-            newMap.put("Variables", ((VariablesDocument) map.get("Variables"))\r
-                            .getVariables());\r
-        }\r
-        if (map.get("BootModes") != null) {\r
-            newMap.put("BootModes", ((BootModesDocument) map.get("BootModes"))\r
-                            .getBootModes());\r
-        }\r
-        if (map.get("SystemTables") != null) {\r
-            newMap.put("SystemTables", ((SystemTablesDocument) map\r
-                            .get("SystemTables")).getSystemTables());\r
-        }\r
-        if (map.get("DataHubs") != null) {\r
-            newMap.put("DataHubs", ((DataHubsDocument) map.get("DataHubs"))\r
-                            .getDataHubs());\r
-        }\r
-        if (map.get("Formsets") != null) {\r
-            newMap.put("Formsets", ((FormsetsDocument) map.get("Formsets"))\r
-                            .getFormsets());\r
-        }\r
-        if (map.get("Guids") != null) {\r
-            newMap.put("Guids", ((GuidsDocument) map.get("Guids")).getGuids());\r
-        }\r
-        if (map.get("Externs") != null) {\r
-            newMap.put("Externs", ((ExternsDocument) map.get("Externs"))\r
-                            .getExterns());\r
-        }\r
-        if (map.get("PcdCoded") != null) {\r
-            newMap.put("PcdCoded", ((PcdCodedDocument) map.get("PcdCoded")).getPcdCoded());\r
-        }\r
-        if (map.get("BuildOptions") != null) {\r
-            newMap.put("BuildOptions", ((BuildOptionsDocument) map\r
-                            .get("BuildOptions")).getBuildOptions());\r
-        }\r
-        return newMap;\r
-    }\r
-\r
-    /**\r
-      Recursively remove all subelement in Xml Object l (with low priority) \r
-      based on OverrideID or exclusive elements. \r
-    \r
-      @param l the XML object to process\r
-      @param map list of elements with OverrideID in high priority XML object\r
-      @param execusiveMap  list of exclusive elements in high priority XML object\r
-    **/\r
-    private void cut(XmlCursor l, Map map, Map execusiveMap) {\r
-        String name = l.getName().getLocalPart();\r
-        if (execusiveMap.containsKey(name)){\r
-            l.removeXml();\r
-            return;\r
-        }\r
-        String overrideID = l.getAttributeText(new QName("OverrideID"));\r
-        if (overrideID != null) {\r
-            if (map.containsKey(name + ":" + overrideID)) {\r
-                l.removeXml();\r
-                return;\r
-            }\r
-        }\r
-        if (l.toFirstChild()) {\r
-            do {\r
-                cut(l, map, execusiveMap);\r
-            } while (l.toNextSibling());\r
-        }\r
-    }\r
-\r
-    private XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r
-        XmlObject result = null;\r
-        try {\r
-            result = XmlObject.Factory.parse(object.getDomNode()\r
-                            .cloneNode(deep));\r
-        } catch (Exception ex) {\r
-            throw new BuildException(ex.getMessage());\r
-        }\r
-        return result;\r
-    }\r
-\r
-    /**\r
-      Process every item list in h and l.\r
-    \r
-      @param h surface area info with high priority\r
-      @param l surface area info with low priority\r
-      @return surface area after override\r
-    **/\r
-    public Map<String, XmlObject> override(Map<String, XmlObject> h,\r
-                    Map<String, XmlObject> l) {\r
-        Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r
-        result.put("MsaHeader", override(l.get("MsaHeader"), null));\r
-        result.put("MsaLibHeader", override(l.get("MsaLibHeader"), null));\r
-        for (int i = 0; i < topElements.length; i++) {\r
-            if (h != null) {\r
-                result.put(topElements[i], override(h.get(topElements[i]), l.get(topElements[i])));\r
-            } else {\r
-                result.put(topElements[i], override(l.get(topElements[i]), null));\r
-            }\r
-        }\r
-        return result;\r
-    }\r
-\r
-    /**\r
-      Recursively override two Xml Objects.\r
-      \r
-      @param h Xml Object info with high priority\r
-      @param l Xml Object info with low priority\r
-      @return Xml Object after area\r
-    **/\r
-    public XmlObject override(XmlObject h, XmlObject l) {\r
-        if (l == null && h == null) {\r
-            return null;\r
-        }\r
-        if (h == null) {\r
-            return cloneXmlObject(l, true);\r
-        }\r
-        if (l == null) {\r
-            return cloneXmlObject(h, true);\r
-        }\r
-        XmlCursor hc = h.newCursor();\r
-        if (h.getClass() != l.getClass()) {\r
-            System.out.println("Error: Two XmlObject does not with compliant format.");\r
-            return null;\r
-        }\r
-        if (!hc.toFirstChild()) {\r
-            return cloneXmlObject(l, true);\r
-        }\r
-\r
-        XmlCursor result = cloneXmlObject(h, true).newCursor();\r
-        XmlCursor lcursor = cloneXmlObject(l, true).newCursor();\r
-        result.push();\r
-        result.toNextToken();\r
-        result.insertNamespace("", prefix);\r
-        result.toFirstChild();\r
-        //\r
-        // found out all element specified a OverrideID\r
-        //\r
-        Map<String,Object> hmap = new HashMap<String,Object>();\r
-        Map<String,Object> execlusiveMap = new HashMap<String,Object>();\r
-        listOverrideID(h, hmap, execlusiveMap, 0);\r
-        lcursor.toNextToken();\r
-        lcursor.push();\r
-        //\r
-        // for every direct subelement of l, cut all element satisfied with\r
-        // override rule\r
-        //\r
-        if (lcursor.toFirstChild()) {\r
-            do {\r
-                cut(lcursor, hmap, execlusiveMap);\r
-            } while (lcursor.toNextSibling());\r
-        }\r
-        lcursor.pop();\r
-        if (lcursor.toFirstChild()) {\r
-            do {\r
-                lcursor.copyXml(result);\r
-                result.insertChars("\n");\r
-            } while (lcursor.toNextSibling());\r
-        }\r
-        result.pop();\r
-        return result.getObject();\r
-    }\r
-}
\ No newline at end of file
index 72efa7eba778b64c163b77b940e4a693e80c0037..ddc851dc70fce6a11aff4716550c31ef719c4dc0 100644 (file)
 \r
  **/\r
 package org.tianocore.build.global;\r
 \r
  **/\r
 package org.tianocore.build.global;\r
+\r
+import java.io.File;\r
 import java.util.HashMap;\r
 import java.util.HashMap;\r
-import java.util.List;\r
+import java.util.Iterator;\r
 import java.util.Map;\r
 import java.util.Map;\r
+import java.util.Set;\r
 \r
 \r
-import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;\r
-import org.tianocore.IncludeHeaderDocument.IncludeHeader;\r
-import org.tianocore.LibraryClassDeclarationDocument.LibraryClassDeclaration;\r
-import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;\r
-import org.tianocore.PackageHeadersDocument.PackageHeaders;\r
-import org.tianocore.PackageSurfaceAreaDocument;\r
-import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
-import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;\r
-import org.tianocore.PpiDeclarationsDocument.PpiDeclarations.Entry;\r
-import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
 \r
 /**\r
  \r
 \r
 /**\r
  \r
 This class is to generate a global table for the content of spd file.\r
-  \r
-**/\r
+ This class is to generate a global table for the content of spd file.\r
\r
+ **/\r
 public class Spd {\r
     ///\r
 public class Spd {\r
     ///\r
-    /// Map of module name and package it belongs to.\r
-    /// Key : Module BaseName\r
-    /// Value: Relative Path to Package\r
     ///\r
     ///\r
-    Map<String, String[]> msaInfo = new HashMap<String, String[]>();\r
+    ///\r
+    Map<ModuleIdentification, File> msaInfo = new HashMap<ModuleIdentification, File>();\r
 \r
     ///\r
     /// Map of module info. \r
     /// Key : moduletype\r
     /// Value: moduletype related include file\r
     ///\r
 \r
     ///\r
     /// Map of module info. \r
     /// Key : moduletype\r
     /// Value: moduletype related include file\r
     ///\r
-    Map<String, String> moduleInfo = new HashMap<String, String>();\r
+    Map<String, String> packageHeaderInfo = new HashMap<String, String>();\r
 \r
     ///\r
     /// Map of PPI info.\r
 \r
     ///\r
     /// Map of PPI info.\r
@@ -70,366 +65,198 @@ public class Spd {
     ///\r
     Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
 \r
     ///\r
     Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
 \r
-\r
     ///\r
     /// Map of library class and its exposed header file.\r
     /// Key : library class name\r
     /// value : library class corresponding header file\r
     ///\r
     ///\r
     /// Map of library class and its exposed header file.\r
     /// Key : library class name\r
     /// value : library class corresponding header file\r
     ///\r
-    Map<String, String> libClassHeaderList = new HashMap<String, String>();\r
+    Map<String, String[]> libClassHeaderList = new HashMap<String, String[]>();\r
 \r
     ///\r
     /// Package path.\r
     ///\r
 \r
     ///\r
     /// Package path.\r
     ///\r
-    String packagePath = null;\r
-\r
-    /**\r
-      Constructor function\r
-      \r
-      This function mainly initialize some member variables. \r
-   \r
-      @param spdDoc      Handle of spd document.\r
-      @param spdPath     Path of spd file.\r
-     **/\r
-    Spd (PackageSurfaceAreaDocument spdDoc, String spdPath) {\r
-\r
-        PackageSurfaceArea spd = spdDoc.getPackageSurfaceArea();\r
-        this.packagePath = spdPath;\r
-\r
-        GuidDeclarations spdGuidInfo = spd.getGuidDeclarations();\r
-        genGuidInfoList(spdGuidInfo);\r
-\r
-        PpiDeclarations spdPpiInfo = spd.getPpiDeclarations();\r
-        genPpiInfoList(spdPpiInfo);\r
-\r
-        ProtocolDeclarations spdProtocolInfo = spd.getProtocolDeclarations();\r
-        genProtocolInfoList(spdProtocolInfo);\r
-\r
-        LibraryClassDeclarations spdLibClassDeclare = spd\r
-                        .getLibraryClassDeclarations();\r
-        genLibClassDeclare(spdLibClassDeclare);\r
-\r
-        PackageHeaders spdPackageHeaderInfo = spd.getPackageHeaders();\r
-        genModuleInfoList(spdPackageHeaderInfo);\r
-\r
-    }\r
+    PackageIdentification packageId;\r
 \r
     /**\r
 \r
     /**\r
-      genModuleInfoList\r
-      \r
-      This function is to generate Module info map.\r
-      \r
-      @param packageHeader   The information of packageHeader which descripted\r
-                             in spd file.    \r
+     Constructor function\r
+     \r
+     This function mainly initialize some member variables. \r
     **/\r
     **/\r
-    public void genModuleInfoList(PackageHeaders packageHeader) {\r
-\r
-        if (packageHeader != null) {\r
-            List<IncludeHeader> headerList = packageHeader.getIncludeHeaderList();\r
-            IncludeHeader       header;\r
-\r
-            for (int i = 0; i < headerList.size(); i++) {\r
-                header = (IncludeHeader)headerList.get(i);\r
-                try {\r
-                    this.moduleInfo.put(header.getModuleType().toString(), header.getStringValue());\r
-                } catch (Exception e) {\r
-                    System.out.print("can't find ModuleHeaders ModuleType & includeHeader!\n");\r
-                }\r
-            }\r
+    Spd(File packageFile) throws BuildException {\r
+        //\r
+        // If specified package file not exists\r
+        //\r
+        if ( ! packageFile.exists()) {\r
+            throw new BuildException("Package file [" + packageFile.getPath() + "] not exists. ");\r
         }\r
         }\r
-    }\r
-\r
-  /**\r
-    genPpiInfoList\r
-    \r
-    This function is to generate Ppi info map.\r
-    \r
-    @param  ppiInfo           The information of PpiDeclarations which descripted\r
-                              in spd file.    \r
-  **/\r
-    public void genPpiInfoList(PpiDeclarations ppiInfo) {\r
-        String[] cNameGuid = new String[2];\r
-        String   guidString;\r
-\r
-        if (ppiInfo != null) {\r
-            List<PpiDeclarations.Entry> ppiEntryList = ppiInfo.getEntryList();\r
-            PpiDeclarations.Entry       ppiEntry;\r
-\r
-            for (int i = 0; i < ppiEntryList.size(); i++) {\r
-                ppiEntry = (PpiDeclarations.Entry)ppiEntryList.get(i);\r
-                try {\r
-                    if (ppiEntry.isSetGuidValue()) {\r
-                        guidString = ppiEntry.getGuidValue();\r
-                    } else {\r
-                        guidString = ppiEntry.getGuid().getStringValue();\r
-                    }\r
-\r
-                    cNameGuid[0] = ppiEntry.getCName();\r
-                    cNameGuid[1] = formatGuidName(guidString);\r
-                    this.ppiInfo.put(ppiEntry.getName(), new String[] { cNameGuid[0], cNameGuid[1] });\r
-                } catch (Exception e) {\r
-                    System.out.print("can't find GuidDeclarations C_Name & Guid!\n");\r
-                }\r
+        try {\r
+            XmlObject spdDoc = XmlObject.Factory.parse(packageFile);\r
+            //\r
+            // Verify SPD file, if is invalid, throw Exception\r
+            //\r
+            if (! spdDoc.validate()) {\r
+                throw new BuildException("Package Surface Area file [" + packageFile.getPath() + "] is invalid. ");\r
             }\r
             }\r
-        }\r
-    }\r
-\r
-    /**\r
-      genProtocolInfoList \r
-      \r
-      This function is to generate Protocol info map.\r
-      \r
-      @param   proInfo    The information of ProtocolDeclarations which \r
-                          descripted in spd file.\r
-    **/\r
-    public void genProtocolInfoList(ProtocolDeclarations proInfo) {\r
-        String[] cNameGuid = new String[2];\r
-        String   guidString;\r
-\r
-        if (proInfo != null) {\r
-            List<ProtocolDeclarations.Entry> protocolEntryList = proInfo.getEntryList();\r
-            ProtocolDeclarations.Entry       protocolEntry;\r
-            for (int i = 0; i < protocolEntryList.size(); i++) {\r
-                protocolEntry = (ProtocolDeclarations.Entry)protocolEntryList.get(i);\r
-                try {\r
-                    if (protocolEntry.isSetGuidValue()) {\r
-                        guidString = protocolEntry.getGuidValue();\r
-                    } else {\r
-                        guidString = protocolEntry.getGuid().getStringValue();\r
-                    }\r
-                    cNameGuid[0] = protocolEntry.getCName();\r
-                    cNameGuid[1] = formatGuidName(guidString);\r
-\r
-                    String temp = new String(protocolEntry.getName());\r
-                    this.protocolInfo.put(temp, new String[] { cNameGuid[0], cNameGuid[1] });\r
-                } catch (Exception e) {\r
-                    System.out.print("can't find ProtocolDeclarations C_Name & Guid!\n");\r
+            // We can change Map to XmlObject\r
+            Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();\r
+            spdDocMap.put("PackageSurfaceArea", spdDoc);\r
+            SurfaceAreaQuery.setDoc(spdDocMap);\r
+            //\r
+            //\r
+            //\r
+            packageId = SurfaceAreaQuery.getSpdHeader();\r
+            packageId.setSpdFile(packageFile);\r
+            \r
+            //\r
+            // initialize Msa Files\r
+            // MSA file is absolute file path\r
+            //\r
+            String[] msaFilenames = SurfaceAreaQuery.getSpdMsaFile();\r
+            for (int i = 0; i < msaFilenames.length; i++){\r
+                File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]);\r
+                Map<String, XmlObject> msaDoc = GlobalData.getNativeMsa( msaFile );\r
+                SurfaceAreaQuery.push(msaDoc);\r
+                ModuleIdentification moduleId = SurfaceAreaQuery.getMsaHeader();\r
+                SurfaceAreaQuery.pop();\r
+                moduleId.setPackage(packageId);\r
+                moduleId.setMsaFile(msaFile);\r
+                if (msaInfo.containsKey(moduleId)) {\r
+                    throw new BuildException("Find two modules with the same GUID and Version in " + packageId + ". They are [" + msaInfo.get(moduleId) + "] and [" + msaFile + "] ");\r
                 }\r
                 }\r
+                msaInfo.put(moduleId, msaFile);\r
             }\r
             }\r
-        }\r
-    }\r
-\r
-    /**\r
-      genGuidInfoList\r
-      \r
-      This function is to generate GUID inf map.\r
-      \r
-      @param guidInfo     The information of GuidDeclarations which descripted\r
-                          in spd file.\r
-      \r
-    **/\r
-    public void genGuidInfoList(GuidDeclarations guidInfo) {\r
-        String[] cNameGuid = new String[2];\r
-        String   guidString;\r
-\r
-        if (guidInfo != null) {\r
             \r
             \r
-            List<GuidDeclarations.Entry>    guidEntryList = guidInfo.getEntryList();\r
-            GuidDeclarations.Entry          guidEntry;\r
-            for (int i = 0; i < guidEntryList.size(); i++) {\r
-                guidEntry = (GuidDeclarations.Entry)guidEntryList.get(i);\r
-                if (guidEntry.isSetGuidValue()) {\r
-                    guidString = guidEntry.getGuidValue();\r
-                } else {\r
-                    guidString = guidEntry.getGuid().getStringValue();\r
-                }\r
-                    \r
-                cNameGuid[0] = guidEntry.getCName();\r
-                cNameGuid[1] = formatGuidName(guidString);\r
-                this.guidInfo.put(guidEntry.getName(), new String[] {cNameGuid[0], cNameGuid[1] });\r
+            //\r
+            // initialize Package header files\r
+            //\r
+            Map<String, String> packageHeaders = SurfaceAreaQuery.getSpdPackageHeaderFiles();\r
+            Set keys = packageHeaders.keySet();\r
+            Iterator iter = keys.iterator();\r
+            while (iter.hasNext()){\r
+                String moduleType = (String)iter.next();\r
+                String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType);\r
+                \r
+                //\r
+                // Change path seperator to system-dependent path separator\r
+                //\r
+                File file = new File (header);\r
+                header = file.getParent();\r
+                packageHeaderInfo.put(moduleType, header);\r
             }\r
             }\r
-        }\r
-    }\r
-\r
-    /**\r
-      genLibClassDeclare\r
-      \r
-      This function is to generate the libClassHeader list.\r
-      \r
-      @param libClassDeclares  The information of LibraryClassDeclarations which\r
-                               descripted in spd file.\r
-    **/\r
-    public void genLibClassDeclare(LibraryClassDeclarations libClassDeclares) {\r
-        if (libClassDeclares != null && libClassDeclares.getLibraryClassDeclarationList() != null) {\r
-            if (libClassDeclares.getLibraryClassDeclarationList().size() > 0) {\r
-                List<LibraryClassDeclaration> libDeclareList = libClassDeclares.getLibraryClassDeclarationList();\r
-                for (int i = 0; i < libDeclareList.size(); i++) {\r
-                    libClassHeaderList.put(libDeclareList.get(i).getLibraryClass()\r
-                                    .getStringValue(), libDeclareList.get(i)\r
-                                    .getIncludeHeader().getStringValue());\r
+            \r
+            //\r
+            // initialize Guid Info\r
+            //\r
+            guidInfo.putAll(SurfaceAreaQuery.getSpdGuid());\r
+            \r
+            //\r
+            // initialize PPI info\r
+            //\r
+            ppiInfo.putAll(SurfaceAreaQuery.getSpdPpi());\r
+            \r
+            //\r
+            // initialize Protocol info\r
+            //\r
+            protocolInfo.putAll(SurfaceAreaQuery.getSpdProtocol());\r
+            \r
+            //\r
+            // initialize library class declaration\r
+            //\r
+            Map<String, String[]> libraryClassHeaders = SurfaceAreaQuery.getSpdLibraryClasses();\r
+            keys = libraryClassHeaders.keySet();\r
+            iter = keys.iterator();\r
+            while (iter.hasNext()){\r
+                String libraryClassName = (String)iter.next();\r
+                String[] headerFiles = libraryClassHeaders.get(libraryClassName);\r
+                for (int i = 0; i < headerFiles.length; i++){\r
+                    headerFiles[i] = packageId.getPackageRelativeDir() + File.separatorChar + headerFiles[i];\r
+                    \r
+                    //\r
+                    // Change path separator to system system-dependent path separator. \r
+                    //\r
+                    File file = new File (headerFiles[i]);\r
+                    headerFiles[i] = file.getPath();\r
                 }\r
                 }\r
+                libClassHeaderList.put(libraryClassName, headerFiles);\r
             }\r
         }\r
             }\r
         }\r
-    }\r
-\r
-    /**\r
-      getPpiGuid\r
-      \r
-      This function is to get ppi GUID according ppi name.\r
-    \r
-      @param   ppiStr    Name of ppi.\r
-      @return            PPi's GUID.\r
-    **/\r
-    public String getPpiGuid(String ppiStr) {\r
-        if (ppiInfo.get(ppiStr) != null) {\r
-            return ppiInfo.get(ppiStr)[1];\r
-        } else {\r
-            return null;\r
+        catch (Exception e) {\r
+            e.setStackTrace(e.getStackTrace());\r
+            throw new BuildException("Parse package description file [" + packageId.getSpdFile() + "] Error.\n"\r
+                                     + e.getMessage());\r
         }\r
         }\r
-\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      getPpiCnameGuidArray\r
-      \r
-      This function is to get the ppi CName and it's GUID according to ppi name.\r
-      \r
-      @param   ppiName      Name of ppi.\r
-      @return               Ppi CName and it's GUID.\r
-    **/\r
-    public String[] getPpiCnameGuidArray(String ppiName) {\r
-        return this.ppiInfo.get(ppiName);\r
+    public PackageIdentification getPackageId() {\r
+        return packageId;\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      getProtocolGuid\r
-      \r
-      This function is to get the protocol GUID according to protocol's name.\r
-      \r
-      @param   protocolStr    Name of protocol.\r
-      @return                 Protocol's GUID.\r
-    **/\r
-    public String getProtocolGuid(String protocolStr) {\r
-        if (protocolInfo.get(protocolStr) != null) {\r
-            return this.protocolInfo.get(protocolStr)[0];\r
-        } else {\r
-            return null;\r
-        }\r
+    public File getModuleFile(ModuleIdentification moduleId) {\r
+        return msaInfo.get(moduleId);\r
+    }\r
+    \r
+    public Set<ModuleIdentification> getModules(){\r
+        return msaInfo.keySet();\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      getProtocolNameGuidArray\r
-      \r
-      This function is to get the protocol's CName ant it's GUID according to\r
-      protocol's namej.\r
-      \r
-      @param  protocolName   Name of protocl.\r
-      @return                Protocol's CName and it's GUID.\r
-    **/\r
-    public String[] getProtocolNameGuidArray(String protocolName) {\r
-        return this.protocolInfo.get(protocolName);\r
+       return two value {CName, Guid}. If not found, return null.\r
+     **/\r
+    public String[] getPpi(String ppiName) {\r
+        return ppiInfo.get(ppiName);\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      getGUIDGuid\r
-      \r
-      This function is to get the GUID according to GUID's name\r
-      \r
-      @param  guidStr        Name of GUID\r
-      @return                GUID.\r
+        return two value {CName, Guid}. If not found, return null.\r
     **/\r
     **/\r
-    public String getGUIDGuid(String guidStr) {\r
-        if (guidInfo.get(guidStr) != null) {\r
-            return guidInfo.get(guidStr)[1];\r
-        } else {\r
-            return null;\r
-        }\r
-\r
+    public String[] getProtocol(String protocolName) {\r
+        return protocolInfo.get(protocolName);\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      getGuidNameArray\r
-      \r
-      This function is to get the GUID's CName and it's GUID according to \r
-      GUID's name\r
-      \r
-      @param   guidName     Name of GUID\r
-      @return               CName and GUID.\r
+      return two value {CName, Guid}. If not found, return null.\r
     **/\r
     **/\r
-    public String[] getGuidNameArray(String guidName) {\r
-        return this.guidInfo.get(guidName);\r
+    public String[] getGuid(String guidName) {\r
+        return guidInfo.get(guidName);\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      getLibClassInclude \r
-      \r
-      This function is to get the library exposed header file name according \r
-      library class name.\r
-      \r
-      @param     libName    Name of library class   \r
-      @return               Name of header file\r
+     getLibClassInclude \r
+     \r
+     This function is to get the library exposed header file name according \r
+     library class name.\r
+     \r
+     @param     libName    Name of library class   \r
+     @return               Name of header file\r
     **/\r
     **/\r
-    String getLibClassIncluder(String libName) {\r
+    String[] getLibClassIncluder(String libName) {\r
         return libClassHeaderList.get(libName);\r
     }\r
 \r
     /**\r
       getModuleTypeIncluder\r
         return libClassHeaderList.get(libName);\r
     }\r
 \r
     /**\r
       getModuleTypeIncluder\r
-      \r
+    \r
       This function is to get the header file name from module info map \r
       according to module type.\r
       This function is to get the header file name from module info map \r
       according to module type.\r
-     \r
+    \r
       @param   moduleType    Module type.\r
       @return                Name of header file.\r
     **/\r
       @param   moduleType    Module type.\r
       @return                Name of header file.\r
     **/\r
-    String getModuleTypeIncluder(String moduleType) {\r
-        return moduleInfo.get(moduleType);\r
+    String getPackageIncluder(String moduleType) {\r
+        return packageHeaderInfo.get(moduleType);\r
     }\r
     }\r
-\r
+    \r
     /**\r
     /**\r
-      formateGuidName\r
-      \r
-      This function is to formate GUID to ANSI c form.\r
-     \r
-      @param  guidNameCon      String of GUID.\r
-      @return                  Formated GUID.\r
-    **/\r
-    public static String formatGuidName (String guidNameConv) {\r
-        String[] strList;\r
-        String guid = "";\r
-        int index = 0;\r
-        if (guidNameConv\r
-                        .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r
-            strList = guidNameConv.split("-");\r
-            guid = "0x" + strList[0] + ", ";\r
-            guid = guid + "0x" + strList[1] + ", ";\r
-            guid = guid + "0x" + strList[2] + ", ";\r
-            guid = guid + "{";\r
-            guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
-            guid = guid + "0x" + strList[3].substring(2, 4);\r
-\r
-            while (index < strList[4].length()) {\r
-                guid = guid + ", ";\r
-                guid = guid + "0x" + strList[4].substring(index, index + 2);\r
-                index = index + 2;\r
-            }\r
-            guid = guid + "}";\r
-            return guid;\r
-        } else if (guidNameConv\r
-                        .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r
-            strList = guidNameConv.split(",");\r
-            \r
-            //\r
-            // chang Microsoft specific form to ANSI c form\r
-            //\r
-            for (int i = 0; i < 3; i++){\r
-                guid = guid + strList[i] + ",";\r
-            }\r
-            guid = guid + "{";\r
-            \r
-            for (int i = 3; i < strList.length; i++){\r
-                if (i == strList.length - 1){\r
-                    guid = guid + strList[i];\r
-                } else {\r
-                    guid = guid + strList[i] + ",";\r
-                }\r
-            }\r
-            guid = guid + "}";            \r
-            return guid;\r
-        } else {\r
-            System.out.println("Check GUID Value, it don't conform to the schema!!!");\r
-            return "0";\r
+           getGuidNameArray\r
+    \r
+           This function is to get the GUID's CName and it's GUID according to\r
+           GUID's name\r
+    \r
+           @param   guidName     Name of GUID\r
+           @return               CName and GUID.\r
+         **/\r
+         public String[] getGuidNameArray(String guidName) {\r
+             return this.guidInfo.get(guidName);\r
+         }\r
 \r
 \r
-        }\r
-    }\r
 }\r
 }\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaParser.java b/Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaParser.java
deleted file mode 100644 (file)
index 229e169..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-/** @file\r
-  SurfaceAreaParser class.\r
-  \r
-  SurfaceAreaParser class is used to parse module surface area include both \r
-  driver and library. \r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-package org.tianocore.build.global;\r
-\r
-import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.LibraryModuleBuildDescriptionDocument;\r
-import org.tianocore.LibraryModuleSurfaceAreaDocument;\r
-import org.tianocore.ModuleBuildDescriptionDocument;\r
-import org.tianocore.ModuleSurfaceAreaDocument;\r
-\r
-/**\r
-  This class is used to parse module surface area (MSA & MBD) include both \r
-  driver and library. \r
-\r
-  @since GenBuild 1.0\r
-**/\r
-public class SurfaceAreaParser {\r
-\r
-    /**\r
-      Using XmlBeans to parse and valid surface area file. \r
-    \r
-      @param surfaceAreaFile the surface area file to parse\r
-      @return top level elements and its value mapping information\r
-      @throws BuildException\r
-              If surface area is not well-formed or invalid\r
-    **/\r
-    public Map<String, XmlObject> parseFile(File surfaceAreaFile) throws BuildException {\r
-        Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-        try {\r
-            XmlObject sadoc = XmlObject.Factory.parse(surfaceAreaFile);\r
-            // Validate File if they obey XML Schema\r
-            \r
-            if ( ! sadoc.validate()){\r
-                throw new BuildException("Surface Area file [" + surfaceAreaFile.getPath() + "] is invalid.");\r
-            }\r
-            if (sadoc instanceof ModuleSurfaceAreaDocument){\r
-                parseFile((ModuleSurfaceAreaDocument) sadoc, map);\r
-            }\r
-            else if(sadoc instanceof ModuleBuildDescriptionDocument){\r
-                parseFile((ModuleBuildDescriptionDocument) sadoc, map);\r
-            }\r
-            else if(sadoc instanceof LibraryModuleSurfaceAreaDocument){\r
-                parseFile((LibraryModuleSurfaceAreaDocument) sadoc, map);\r
-            }\r
-            else if(sadoc instanceof LibraryModuleBuildDescriptionDocument){\r
-                parseFile((LibraryModuleBuildDescriptionDocument) sadoc, map);\r
-            }\r
-        }\r
-        catch (Exception ex){\r
-            throw new BuildException(ex.getMessage());\r
-        }\r
-        return map;\r
-    }\r
-    \r
-    \r
-    /**\r
-      Parse MSA.\r
-    \r
-      @param doc top level surface area XML document\r
-      @param msaMap the map to store the result\r
-    **/\r
-    private void parseFile(ModuleSurfaceAreaDocument doc, Map<String, XmlObject> msaMap) {\r
-        msaMap.put("MsaHeader", doc.getModuleSurfaceArea().getMsaHeader());\r
-        msaMap.put("LibraryClassDefinitions", doc.getModuleSurfaceArea()\r
-                        .getLibraryClassDefinitions());\r
-        msaMap.put("SourceFiles", doc.getModuleSurfaceArea().getSourceFiles());\r
-        msaMap.put("Includes", doc.getModuleSurfaceArea().getIncludes());\r
-        msaMap.put("PackageDependencies", doc.getModuleSurfaceArea().getPackageDependencies());\r
-        msaMap.put("Protocols", doc.getModuleSurfaceArea().getProtocols());\r
-\r
-        msaMap.put("Events", doc.getModuleSurfaceArea().getEvents());\r
-        msaMap.put("Hobs", doc.getModuleSurfaceArea().getHobs());\r
-        msaMap.put("PPIs", doc.getModuleSurfaceArea().getPPIs());\r
-        msaMap.put("Variables", doc.getModuleSurfaceArea().getVariables());\r
-        msaMap.put("BootModes", doc.getModuleSurfaceArea().getBootModes());\r
-\r
-        msaMap.put("SystemTables", doc.getModuleSurfaceArea().getSystemTables());\r
-        msaMap.put("DataHubs", doc.getModuleSurfaceArea().getDataHubs());\r
-        msaMap.put("Formsets", doc.getModuleSurfaceArea().getFormsets());\r
-        msaMap.put("Guids", doc.getModuleSurfaceArea().getGuids());\r
-        msaMap.put("Externs", doc.getModuleSurfaceArea().getExterns());\r
-\r
-        msaMap.put("PcdCoded", doc.getModuleSurfaceArea().getPcdCoded());\r
-        msaMap.put("BuildOptions", doc.getModuleSurfaceArea().getBuildOptions());\r
-    }\r
-\r
-    /**\r
-      Parse MBD.\r
-  \r
-      @param doc top level surface area XML document\r
-      @param msaMap the map to store the result\r
-    **/\r
-    private void parseFile(ModuleBuildDescriptionDocument doc, Map<String, XmlObject> mbdMap) {\r
-        mbdMap.put("MbdHeader", doc.getModuleBuildDescription().getMbdHeader());\r
-        mbdMap.put("Libraries", doc.getModuleBuildDescription().getLibraries());\r
-        mbdMap.put("SourceFiles", doc.getModuleBuildDescription()\r
-                        .getSourceFiles());\r
-        mbdMap.put("Includes", doc.getModuleBuildDescription().getIncludes());\r
-        mbdMap.put("Protocols", doc.getModuleBuildDescription().getProtocols());\r
-\r
-        mbdMap.put("Events", doc.getModuleBuildDescription().getEvents());\r
-        mbdMap.put("Hobs", doc.getModuleBuildDescription().getHobs());\r
-        mbdMap.put("PPIs", doc.getModuleBuildDescription().getPPIs());\r
-        mbdMap.put("Variables", doc.getModuleBuildDescription().getVariables());\r
-        mbdMap.put("BootModes", doc.getModuleBuildDescription().getBootModes());\r
-\r
-        mbdMap.put("SystemTables", doc.getModuleBuildDescription()\r
-                        .getSystemTables());\r
-        mbdMap.put("DataHubs", doc.getModuleBuildDescription().getDataHubs());\r
-        mbdMap.put("Formsets", doc.getModuleBuildDescription().getFormsets());\r
-        mbdMap.put("Guids", doc.getModuleBuildDescription().getGuids());\r
-        mbdMap.put("Externs", doc.getModuleBuildDescription().getExterns());\r
-\r
-        mbdMap.put("BuildOptions", doc.getModuleBuildDescription()\r
-                        .getBuildOptions());\r
-    }\r
-    /**\r
-      Parse Library MSA.\r
-\r
-      @param doc top level surface area XML document\r
-      @param msaMap the map to store the result\r
-    **/\r
-    private void parseFile(LibraryModuleSurfaceAreaDocument doc, Map<String, XmlObject> msaMap) {\r
-        msaMap.put("MsaLibHeader", doc.getLibraryModuleSurfaceArea()\r
-                        .getMsaLibHeader());\r
-        msaMap.put("LibraryClassDefinitions", doc.getLibraryModuleSurfaceArea()\r
-                        .getLibraryClassDefinitions());\r
-        msaMap.put("SourceFiles", doc.getLibraryModuleSurfaceArea()\r
-                        .getSourceFiles());\r
-        msaMap.put("Includes", doc.getLibraryModuleSurfaceArea().getIncludes());\r
-        msaMap.put("Protocols", doc.getLibraryModuleSurfaceArea()\r
-                        .getProtocols());\r
-\r
-        msaMap.put("Events", doc.getLibraryModuleSurfaceArea().getEvents());\r
-        msaMap.put("Hobs", doc.getLibraryModuleSurfaceArea().getHobs());\r
-        msaMap.put("PPIs", doc.getLibraryModuleSurfaceArea().getPPIs());\r
-        msaMap.put("Variables", doc.getLibraryModuleSurfaceArea()\r
-                        .getVariables());\r
-        msaMap.put("BootModes", doc.getLibraryModuleSurfaceArea()\r
-                        .getBootModes());\r
-\r
-        msaMap.put("SystemTables", doc.getLibraryModuleSurfaceArea()\r
-                        .getSystemTables());\r
-        msaMap.put("DataHubs", doc.getLibraryModuleSurfaceArea().getDataHubs());\r
-        msaMap.put("Formsets", doc.getLibraryModuleSurfaceArea().getFormsets());\r
-        msaMap.put("Guids", doc.getLibraryModuleSurfaceArea().getGuids());\r
-        msaMap.put("Externs", doc.getLibraryModuleSurfaceArea().getExterns());\r
-\r
-        msaMap.put("PcdCoded", doc.getLibraryModuleSurfaceArea().getPcdCoded());\r
-        msaMap.put("BuildOptions", doc.getLibraryModuleSurfaceArea()\r
-                        .getBuildOptions());\r
-    }\r
-\r
-    /**\r
-      Parse Library MBD.\r
-\r
-      @param doc top level surface area XML document\r
-      @param msaMap the map to store the result\r
-    **/\r
-    private void parseFile(LibraryModuleBuildDescriptionDocument doc, Map<String, XmlObject> mbdMap) {\r
-        mbdMap.put("MbdLibHeader", doc.getLibraryModuleBuildDescription()\r
-                        .getMbdLibHeader());\r
-        mbdMap.put("Libraries", doc.getLibraryModuleBuildDescription()\r
-                        .getLibraries());\r
-        mbdMap.put("SourceFiles", doc.getLibraryModuleBuildDescription()\r
-                        .getSourceFiles());\r
-        mbdMap.put("Includes", doc.getLibraryModuleBuildDescription()\r
-                        .getIncludes());\r
-        mbdMap.put("Protocols", doc.getLibraryModuleBuildDescription()\r
-                        .getProtocols());\r
-\r
-        mbdMap\r
-                        .put("Events", doc.getLibraryModuleBuildDescription()\r
-                                        .getEvents());\r
-        mbdMap.put("Hobs", doc.getLibraryModuleBuildDescription().getHobs());\r
-        mbdMap.put("PPIs", doc.getLibraryModuleBuildDescription().getPPIs());\r
-        mbdMap.put("Variables", doc.getLibraryModuleBuildDescription()\r
-                        .getVariables());\r
-        mbdMap.put("BootModes", doc.getLibraryModuleBuildDescription()\r
-                        .getBootModes());\r
-\r
-        mbdMap.put("SystemTables", doc.getLibraryModuleBuildDescription()\r
-                        .getSystemTables());\r
-        mbdMap.put("DataHubs", doc.getLibraryModuleBuildDescription()\r
-                        .getDataHubs());\r
-        mbdMap.put("Formsets", doc.getLibraryModuleBuildDescription()\r
-                        .getFormsets());\r
-        mbdMap.put("Guids", doc.getLibraryModuleBuildDescription().getGuids());\r
-        mbdMap.put("Externs", doc.getLibraryModuleBuildDescription()\r
-                        .getExterns());\r
-\r
-        mbdMap.put("BuildOptions", doc.getLibraryModuleBuildDescription()\r
-                        .getBuildOptions());\r
-    }\r
-}\r
index 35fd77833a284ccd76ec201ddb30fc5704259da9..5eb14d4a4521d1c701c05b4efb515b03b0084671 100644 (file)
@@ -14,7 +14,9 @@
 package org.tianocore.build.global;\r
 \r
 import java.util.ArrayList;\r
 package org.tianocore.build.global;\r
 \r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.Iterator;\r
 import java.util.Iterator;\r
+import java.util.LinkedHashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Stack;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Stack;\r
@@ -25,99 +27,122 @@ import org.apache.xmlbeans.XmlNormalizedString;
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.xmlbeans.XmlString;\r
 import org.tianocore.BuildOptionsDocument;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.xmlbeans.XmlString;\r
 import org.tianocore.BuildOptionsDocument;\r
-import org.tianocore.CName;\r
+import org.tianocore.DataIdDocument;\r
 import org.tianocore.ExternsDocument;\r
 import org.tianocore.ExternsDocument;\r
-import org.tianocore.FfsDocument;\r
 import org.tianocore.FileNameConvention;\r
 import org.tianocore.FileNameConvention;\r
-import org.tianocore.FrameworkComponentTypes;\r
-import org.tianocore.FvImageOptionsDocument;\r
-import org.tianocore.GuidDocument;\r
+import org.tianocore.FvAttributeDocument;\r
+import org.tianocore.FvImagesDocument;\r
+import org.tianocore.FvOptionDocument;\r
+import org.tianocore.GuidDeclarationsDocument;\r
 import org.tianocore.GuidsDocument;\r
 import org.tianocore.LibrariesDocument;\r
 import org.tianocore.GuidsDocument;\r
 import org.tianocore.LibrariesDocument;\r
+import org.tianocore.LibraryClassDeclarationsDocument;\r
 import org.tianocore.LibraryClassDocument;\r
 import org.tianocore.LibraryClassDocument;\r
-import org.tianocore.LibraryUsage;\r
+import org.tianocore.ModuleDefinitionsDocument;\r
 import org.tianocore.ModuleSADocument;\r
 import org.tianocore.ModuleSADocument;\r
+import org.tianocore.ModuleSaBuildOptionsDocument;\r
 import org.tianocore.ModuleTypeDef;\r
 import org.tianocore.ModuleTypeDef;\r
-import org.tianocore.NameValueDocument;\r
-import org.tianocore.OutputDirectoryDocument;\r
-import org.tianocore.PPIsDocument;\r
-import org.tianocore.PackageNameDocument;\r
-import org.tianocore.ProtocolsDocument;\r
-import org.tianocore.PcdCodedDocument.PcdCoded;\r
+import org.tianocore.MsaFilesDocument;\r
 import org.tianocore.MsaHeaderDocument;\r
 import org.tianocore.MsaHeaderDocument;\r
+import org.tianocore.OptionDocument;\r
+import org.tianocore.PPIsDocument;\r
+import org.tianocore.PackageDependenciesDocument;\r
+import org.tianocore.PackageHeadersDocument;\r
+import org.tianocore.PlatformDefinitionsDocument;\r
+import org.tianocore.PpiDeclarationsDocument;\r
+import org.tianocore.ProtocolDeclarationsDocument;\r
+import org.tianocore.SpdHeaderDocument;\r
+import org.tianocore.SupportedArchitectures;\r
+import org.tianocore.FilenameDocument.Filename;\r
 import org.tianocore.MsaHeaderDocument.MsaHeader;\r
 import org.tianocore.MsaHeaderDocument.MsaHeader;\r
+import org.tianocore.ProtocolsDocument.Protocols.Protocol;\r
+import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;\r
+import org.tianocore.PlatformHeaderDocument;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
+import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.toolchain.ToolChainInfo;\r
 \r
 /**\r
 \r
 /**\r
 SurfaceAreaQuery class is used to query Surface Area information from msa, mbd,\r
-  spd and fpd files. \r
-  \r
-  This class should not instantiated. All the public interfaces is static.\r
-  \r
-  @since GenBuild 1.0\r
- **/\r
* SurfaceAreaQuery class is used to query Surface Area information from msa,\r
+ * mbd, spd and fpd files.\r
+ * \r
* This class should not instantiated. All the public interfaces is static.\r
+ * \r
* @since GenBuild 1.0\r
+ */\r
 public class SurfaceAreaQuery {\r
 public class SurfaceAreaQuery {\r
-    /// \r
-    /// Contains name/value pairs of Surface Area document object. The name is\r
-    /// always the top level element name.\r
-    ///  \r
+\r
+    public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";\r
+\r
+    // /\r
+    // / Contains name/value pairs of Surface Area document object. The name is\r
+    // / always the top level element name.\r
+    // /\r
     private static Map<String, XmlObject> map = null;\r
     private static Map<String, XmlObject> map = null;\r
-    \r
-    ///\r
-    /// mapStack is used to do nested query\r
-    ///\r
-    private static Stack< Map<String, XmlObject> > mapStack = new Stack< Map<String, XmlObject> >();\r
-    \r
-    //\r
-    /// prefix of name space\r
-    //\r
+\r
+    // /\r
+    // / mapStack is used to do nested query\r
+    // /\r
+    private static Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();\r
+\r
+    // /\r
+    // / prefix of name space\r
+    // /\r
     private static String nsPrefix = "sans";\r
     private static String nsPrefix = "sans";\r
-    \r
-    ///\r
-    /// xmlbeans needs a name space for each Xpath element \r
-    ///\r
+\r
+    // /\r
+    // / xmlbeans needs a name space for each Xpath element\r
+    // /\r
     private static String ns = null;\r
     private static String ns = null;\r
-    \r
-    ///\r
-    /// keep the namep declaration for xmlbeans Xpath query\r
-    ///\r
+\r
+    // /\r
+    // / keep the namep declaration for xmlbeans Xpath query\r
+    // /\r
     private static String queryDeclaration = null;\r
 \r
     /**\r
     private static String queryDeclaration = null;\r
 \r
     /**\r
-     Set a Surface Area document for query later\r
-     \r
-     @param     map     A Surface Area document in TopLevelElementName/XmlObject format.\r
-     **/\r
+     * Set a Surface Area document for query later\r
+     * \r
+     * @param map\r
+     *            A Surface Area document in TopLevelElementName/XmlObject\r
+     *            format.\r
+     */\r
     public static void setDoc(Map<String, XmlObject> map) {\r
     public static void setDoc(Map<String, XmlObject> map) {\r
-        ns = OverrideProcess.prefix;\r
+        ns = prefix;\r
         queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";\r
         SurfaceAreaQuery.map = map;\r
     }\r
 \r
     /**\r
         queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";\r
         SurfaceAreaQuery.map = map;\r
     }\r
 \r
     /**\r
-     Push current used Surface Area document into query stack. The given new \r
-     document  will be used for any immediately followed getXXX() callings, \r
-     untill pop() is called.\r
-     \r
-     @param     newMap  The TopLevelElementName/XmlObject format of a Surface Area document.\r
-     **/\r
+     * Push current used Surface Area document into query stack. The given new\r
+     * document will be used for any immediately followed getXXX() callings,\r
+     * untill pop() is called.\r
+     * \r
+     * @param newMap\r
+     *            The TopLevelElementName/XmlObject format of a Surface Area\r
+     *            document.\r
+     */\r
     public static void push(Map<String, XmlObject> newMap) {\r
         mapStack.push(SurfaceAreaQuery.map);\r
         SurfaceAreaQuery.map = newMap;\r
     }\r
     public static void push(Map<String, XmlObject> newMap) {\r
         mapStack.push(SurfaceAreaQuery.map);\r
         SurfaceAreaQuery.map = newMap;\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-     Discard current used Surface Area document and use the top document in stack\r
-     instead.\r
-     **/\r
+     * Discard current used Surface Area document and use the top document in\r
+     * stack instead.\r
+     */\r
     public static void pop() {\r
         SurfaceAreaQuery.map = mapStack.pop();\r
     }\r
     public static void pop() {\r
         SurfaceAreaQuery.map = mapStack.pop();\r
     }\r
-    \r
-    ///\r
-    /// Convert xPath to be namespace qualified, which is necessary for XmlBeans\r
-    /// selectPath(). For example, converting /MsaHeader/ModuleType to\r
-    /// /ns:MsaHeader/ns:ModuleType\r
-    ///     \r
+\r
+    // /\r
+    // / Convert xPath to be namespace qualified, which is necessary for\r
+    // XmlBeans\r
+    // / selectPath(). For example, converting /MsaHeader/ModuleType to\r
+    // / /ns:MsaHeader/ns:ModuleType\r
+    // /\r
     private static String normalizeQueryString(String[] exp, String from) {\r
         StringBuffer normQueryString = new StringBuffer(4096);\r
 \r
     private static String normalizeQueryString(String[] exp, String from) {\r
         StringBuffer normQueryString = new StringBuffer(4096);\r
 \r
@@ -128,10 +153,13 @@ public class SurfaceAreaQuery {
             Matcher matcher = pattern.matcher(newExp);\r
 \r
             while (matcher.find()) {\r
             Matcher matcher = pattern.matcher(newExp);\r
 \r
             while (matcher.find()) {\r
-                String starter = newExp.substring(matcher.start(1), matcher.end(1));\r
-                String seperator = newExp.substring(matcher.start(2), matcher.end(2));\r
-                String token = newExp.substring(matcher.start(3), matcher.end(3));\r
-                \r
+                String starter = newExp.substring(matcher.start(1), matcher\r
+                        .end(1));\r
+                String seperator = newExp.substring(matcher.start(2), matcher\r
+                        .end(2));\r
+                String token = newExp.substring(matcher.start(3), matcher\r
+                        .end(3));\r
+\r
                 normQueryString.append(starter);\r
                 normQueryString.append(seperator);\r
                 normQueryString.append(nsPrefix);\r
                 normQueryString.append(starter);\r
                 normQueryString.append(seperator);\r
                 normQueryString.append(nsPrefix);\r
@@ -149,243 +177,363 @@ public class SurfaceAreaQuery {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-      Search all XML documents stored in "map" for the specified xPath, using\r
-      relative path (starting with '$this')\r
-     \r
-     @param     xPath   xpath query string array\r
-     @returns   An array of XmlObject   if elements are found at the specified xpath\r
-     @returns   NULL                    if nothing is at the specified xpath\r
-     **/\r
-    public static XmlObject[] get(String[] xPath) {\r
+     * Search all XML documents stored in "map" for the specified xPath, using\r
+     * relative path (starting with '$this')\r
+     * \r
+     * @param xPath\r
+     *            xpath query string array\r
+     * @returns An array of XmlObject if elements are found at the specified\r
+     *          xpath\r
+     * @returns NULL if nothing is at the specified xpath\r
+     */\r
+    public static Object[] get(String[] xPath) {\r
         if (map == null) {\r
             return null;\r
         }\r
         if (map == null) {\r
             return null;\r
         }\r
-        \r
+\r
         String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);\r
         String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);\r
-        List<XmlObject> result = new ArrayList<XmlObject>();\r
+        List<Object> result = new ArrayList<Object>();\r
         for (int i = 0; i < keys.length; ++i) {\r
             XmlObject rootNode = (XmlObject) map.get(keys[i]);\r
             if (rootNode == null) {\r
                 continue;\r
             }\r
         for (int i = 0; i < keys.length; ++i) {\r
             XmlObject rootNode = (XmlObject) map.get(keys[i]);\r
             if (rootNode == null) {\r
                 continue;\r
             }\r
-            \r
-            String query = queryDeclaration + normalizeQueryString(xPath, "$this/" + keys[i]);\r
+\r
+            String query = queryDeclaration\r
+                    + normalizeQueryString(xPath, "$this/" + keys[i]);\r
             XmlObject[] tmp = rootNode.selectPath(query);\r
             for (int j = 0; j < tmp.length; ++j) {\r
             XmlObject[] tmp = rootNode.selectPath(query);\r
             for (int j = 0; j < tmp.length; ++j) {\r
-                result.add(tmp[j]);\r
+                result.add((Object)tmp[j]);\r
             }\r
         }\r
             }\r
         }\r
-        \r
+\r
         int size = result.size();\r
         if (size <= 0) {\r
             return null;\r
         }\r
         int size = result.size();\r
         if (size <= 0) {\r
             return null;\r
         }\r
-        \r
-        return (XmlObject[]) result.toArray(new XmlObject[size]);\r
+\r
+        return (Object[]) result.toArray(new Object[size]);\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Search XML documents named by "rootName" for the given xPath, using\r
-     relative path (starting with '$this')\r
-     \r
-     @param     rootName    The top level element name \r
-     @param     xPath       The xpath query string array\r
-     @returns   An array of XmlObject   if elements are found at the given xpath\r
-     @returns   NULL                    if nothing is found at the given xpath\r
-     **/\r
-    public static XmlObject[] get(String rootName, String[] xPath) {\r
+     * Search XML documents named by "rootName" for the given xPath, using\r
+     * relative path (starting with '$this')\r
+     * \r
+     * @param rootName\r
+     *            The top level element name\r
+     * @param xPath\r
+     *            The xpath query string array\r
+     * @returns An array of XmlObject if elements are found at the given xpath\r
+     * @returns NULL if nothing is found at the given xpath\r
+     */\r
+    public static Object[] get(String rootName, String[] xPath) {\r
         if (map == null) {\r
             return null;\r
         }\r
         if (map == null) {\r
             return null;\r
         }\r
-        \r
+\r
         XmlObject root = (XmlObject) map.get(rootName);\r
         if (root == null) {\r
             return null;\r
         }\r
 \r
         XmlObject root = (XmlObject) map.get(rootName);\r
         if (root == null) {\r
             return null;\r
         }\r
 \r
-        String query = queryDeclaration + normalizeQueryString(xPath, "$this/" + rootName);\r
+        String query = queryDeclaration\r
+                + normalizeQueryString(xPath, "$this/" + rootName);\r
         XmlObject[] result = root.selectPath(query);\r
         if (result.length > 0) {\r
         XmlObject[] result = root.selectPath(query);\r
         if (result.length > 0) {\r
-            return result;\r
+            return (Object[])result;\r
         }\r
 \r
         query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);\r
         result = root.selectPath(query);\r
         if (result.length > 0) {\r
         }\r
 \r
         query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);\r
         result = root.selectPath(query);\r
         if (result.length > 0) {\r
-            return result;\r
+            return (Object[])result;\r
         }\r
 \r
         return null;\r
     }\r
 \r
     /**\r
         }\r
 \r
         return null;\r
     }\r
 \r
     /**\r
-     Retrieve SourceFiles/Filename for specified ARCH type\r
-      \r
-     @param     arch        architecture name\r
-     @returns   An array of XmlObject   if elements are found at the known xpath\r
-     @returns   NULL                    if nothing is found at the known xpath\r
-     **/\r
-    public static XmlObject[] getSourceFiles(String arch) {\r
+     * Retrieve SourceFiles/Filename for specified ARCH type\r
+     * \r
+     * @param arch\r
+     *            architecture name\r
+     * @returns An 2 dimension string array if elements are found at the known\r
+     *          xpath\r
+     * @returns NULL if nothing is found at the known xpath\r
+     */\r
+    public static String[][] getSourceFiles(String arch) {\r
         String[] xPath;\r
         String[] xPath;\r
+        Object[] returns;\r
 \r
         if (arch == null || arch.equals("")) {\r
 \r
         if (arch == null || arch.equals("")) {\r
-            xPath = new String[] {\r
-                "/Filename",\r
-                "/Arch/Filename"\r
-                };\r
+            xPath = new String[] { "/Filename" };\r
         } else {\r
         } else {\r
-            xPath = new String[] {\r
-                "/Filename[not(@SupArchList) and not(@ArchType) or @SupArchList='ALL' or @SupArchList='" + arch + "' or @ArchType='ALL' or @ArchType='" + arch + "']",\r
-                "/Filename[not(@SupArchList) and not(@ArchType) or @ArchType='ALL' or @ArchType='" + arch + "']",\r
-                "/Arch[@ArchType='ALL' or @ArchType='" + arch + "']/Filename"\r
-                };\r
+            xPath = new String[] { "/Filename[not(@SupArchList) or @SupArchList='"\r
+                    + arch + "']" };\r
         }\r
 \r
         }\r
 \r
-        return get("SourceFiles", xPath);\r
-    }\r
-\r
-    /**\r
-     Retrieve BuildOptions/Ffs\r
-\r
-     @returns   FfsDocument.Ffs object  if elements are found at the known xpath\r
-     @returns   NULL                    if nothing is found at the known xpath\r
-     **/\r
-    public static FfsDocument.Ffs getFfs() {\r
-        String[] xPath = new String[] { "/Ffs" };\r
+        returns = get("SourceFiles", xPath);\r
 \r
 \r
-        XmlObject[] returns = get("BuildOptions", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (FfsDocument.Ffs) returns[0];\r
+        if (returns == null || returns.length == 0) {\r
+            return new String[0][0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        Filename[] sourceFileNames = (Filename[]) returns;\r
+        String[][] outputString = new String[sourceFileNames.length][2];\r
+        for (int i = 0; i < sourceFileNames.length; i++) {\r
+            outputString[i][0] = sourceFileNames[i].getToolCode();\r
+            outputString[i][1] = sourceFileNames[i].getStringValue();\r
+        }\r
+        return outputString;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve BuildOptions/OutputDirectory\r
+     * Retrieve /PlatformDefinitions/OutputDirectory from FPD\r
+     * \r
+     * @returns Directory names array if elements are found at the known xpath\r
+     * @returns Empty if nothing is found at the known xpath\r
+     */\r
+    public static String getFpdOutputDirectory() {\r
+        String[] xPath = new String[] { "/PlatformDefinitions" };\r
+\r
+        Object[] returns = get("PlatformSurfaceArea", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+        PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];\r
+        return item.getOutputDirectory();\r
+    }\r
 \r
 \r
-     @returns   Directory names array   if elements are found at the known xpath\r
-     @returns   Empty                   if nothing is found at the known xpath\r
-     **/\r
-    public static String[] getOutputDirectory() {\r
-        String[] xPath = new String[] { "/OutputDirectory" };\r
+    public static String getFpdIntermediateDirectories() {\r
+        String[] xPath = new String[] { "/PlatformDefinitions" };\r
 \r
 \r
-        XmlObject[] returns = get("BuildOptions", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            String[] dirString = new String[2];\r
+        Object[] returns = get("PlatformSurfaceArea", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return "UNIFIED";\r
+        }\r
+        PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];\r
+        if(item.getIntermediateDirectories() == null) {\r
+            return null;     \r
+        }\r
+        else {\r
+            return item.getIntermediateDirectories().toString();\r
+        }\r
+    }\r
 \r
 \r
-            OutputDirectoryDocument.OutputDirectory[] dir = (OutputDirectoryDocument.OutputDirectory[]) returns;\r
-            dirString[0] = dir[0].getIntermediateDirectories().toString();\r
-            dirString[1] = dir[0].getStringValue();\r
+    public static String getModuleFfsKeyword() {\r
+        String[] xPath = new String[] { "/" };\r
 \r
 \r
-            return dirString;\r
+        Object[] returns = get("ModuleSaBuildOptions", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
         }\r
         }\r
+        ModuleSaBuildOptionsDocument.ModuleSaBuildOptions item = (ModuleSaBuildOptionsDocument.ModuleSaBuildOptions)returns[0];\r
+        return item.getFfsFormatKey();\r
+    }\r
+    \r
+    public static String getModuleFvBindingKeyword() {\r
+        String[] xPath = new String[] { "/" };\r
 \r
 \r
-        return new String[] { "UNIFIED", null };\r
+        Object[] returns = get("ModuleSaBuildOptions", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+        ModuleSaBuildOptionsDocument.ModuleSaBuildOptions item = (ModuleSaBuildOptionsDocument.ModuleSaBuildOptions)returns[0];\r
+        return item.getFvBinding();\r
+    }\r
+    \r
+    public static List getModuleSupportedArchs() {\r
+        String[] xPath = new String[] { "/" };\r
+\r
+        Object[] returns = get("ModuleDefinitions", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+        ModuleDefinitionsDocument.ModuleDefinitions item = (ModuleDefinitionsDocument.ModuleDefinitions)returns[0];\r
+        return item.getSupportedArchitectures();\r
+    }\r
+    \r
+    public static BuildOptionsDocument.BuildOptions.Ffs[] getFpdFfs() {\r
+        String[] xPath = new String[] {"/Ffs"};\r
+        \r
+        Object[] returns = get("BuildOptions", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return new BuildOptionsDocument.BuildOptions.Ffs[0];\r
+        }\r
+        return (BuildOptionsDocument.BuildOptions.Ffs[])returns;\r
     }\r
     }\r
+    \r
+    public static String getModuleOutputFileBasename() {\r
+        String[] xPath = new String[] { "/" };\r
 \r
 \r
+        Object[] returns = get("ModuleDefinitions", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+        ModuleDefinitionsDocument.ModuleDefinitions item = (ModuleDefinitionsDocument.ModuleDefinitions)returns[0];\r
+        return item.getOutputFileBasename();\r
+    }\r
+    \r
     /**\r
     /**\r
-     Retrieve BuildOptions/Option or Arch/Option\r
+     * Retrieve BuildOptions/Option or Arch/Option\r
+     * \r
+     * @param toolChainFamilyFlag\r
+     *            if true, retrieve options for toolchain family; otherwise for\r
+     *            toolchain\r
+     * \r
+     * @returns String[][5] name, target, toolchain, arch, coommand of options\r
+     *          if elements are found at the known xpath. String[0][] if dont\r
+     *          find element.\r
+     * \r
+     * @returns Empty array if nothing is there\r
+     */\r
+    public static String[][] getOptions(String from, String[] xPath, boolean toolChainFamilyFlag) {\r
+        String target = null;\r
+        String toolchain = null;\r
+        String toolchainFamily = null;\r
+        List<String> archList = null;\r
+        String cmd = null;\r
+        String targetName = null;\r
+        String optionName = null;\r
+\r
+        Object[] returns = get(from, xPath);\r
+        if (returns == null) {\r
+            return new String[0][5];\r
+        }\r
 \r
 \r
-     @param     arch    architecture name\r
+        List<String[]> optionList = new ArrayList<String[]>();\r
+        OptionDocument.Option option;\r
 \r
 \r
-     @returns   name/value pairs of options if elements are found at the known xpath\r
-     @returns   Empty array                 if nothing is there\r
-     **/\r
-    public static String[][] getOptions(String arch){\r
-        String[] xPath;\r
+        for (int i = 0; i < returns.length; i++) {\r
+            option = (OptionDocument.Option) returns[i];\r
 \r
 \r
-        if (arch == null || arch.equals("")) {\r
-            xPath = new String[] {\r
-                "/Option",\r
-                "/Arch/Option"\r
-                };\r
-        } else {\r
-            xPath = new String[] {\r
-                "/Option",\r
-                "/Option[@SupArchList='ALL' or @SupArchList='" + arch + "']",\r
-                "/Arch[@ArchType='ALL' or @ArchType='" + arch + "']/Option"\r
-                };\r
-        }\r
+            //\r
+            // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,\r
+            // then\r
+            // put to result[][5] array in above order.\r
+            //\r
+            String[] targetList;\r
+            if (option.getBuildTargets() == null) {\r
+                target = null;\r
+            }\r
+            else {\r
+                target = option.getBuildTargets().toString();\r
+            }\r
+            if (target != null) {\r
+                targetList = target.split(" ");\r
+            } else {\r
+                targetList = new String[1];\r
+                targetList[0] = null;\r
+            }\r
 \r
 \r
-        XmlObject[] returns = get("BuildOptions", xPath);\r
-        if (returns == null){\r
-            return new String[0][2];\r
-        }\r
-        \r
-        String[][] result = new String[returns.length][2];\r
-        for (int i = 0; i < returns.length; i ++){\r
-            String str;\r
-            String name = null;\r
-            String value = null;\r
-\r
-            if (returns[i] instanceof BuildOptionsDocument.BuildOptions.Option) {\r
-                BuildOptionsDocument.BuildOptions.Option option = (BuildOptionsDocument.BuildOptions.Option)returns[i];\r
-                str = option.getStringValue();\r
-            } else if (returns[i] instanceof BuildOptionsDocument.BuildOptions.Arch.Option) {\r
-                BuildOptionsDocument.BuildOptions.Arch.Option archOption = (BuildOptionsDocument.BuildOptions.Arch.Option)returns[i];\r
-                str = archOption.getStringValue();\r
+            if (toolChainFamilyFlag) {\r
+                toolchainFamily = option.getToolChainFamily();\r
+                if (toolchainFamily != null) {\r
+                    toolchain = toolchainFamily.toString();\r
+                } else {\r
+                    toolchain = null;\r
+                }\r
             } else {\r
             } else {\r
-                continue;\r
+                toolchain = option.getTagName();\r
             }\r
             }\r
-            \r
-            int equalIndex = str.indexOf('=');\r
-            if ( equalIndex > 0) {\r
-                name = str.substring(0, equalIndex).trim();\r
-                value = str.substring(equalIndex + 1).trim();\r
-                // TBD remove some forbidden name: BASE_NAME, ARCH and so on\r
-                if (name.length() == 0){\r
-                    name = null;\r
+\r
+            archList = new ArrayList<String>();\r
+            List<String> archEnumList = option.getSupArchList();            \r
+            if (archEnumList == null) {\r
+                archList.add(null);\r
+            } else {\r
+                archList.addAll(archEnumList);\r
+                /*\r
+                Iterator it = archEnumList.iterator();\r
+                while (it.hasNext()) {\r
+                    System.out.println(it.next().getClass().getName());\r
+                    SupportedArchitectures.Enum archType = it.next();\r
+                    archList.add(archType.toString());\r
+                }\r
+                */\r
+            }\r
+\r
+            cmd = option.getToolCode();\r
+\r
+            optionName = option.getStringValue();\r
+            for (int t = 0; t < targetList.length; t++) {\r
+                for (int j = 0; j < archList.size(); j++) {\r
+                    optionList.add(new String[] { targetList[t],\r
+                            toolchain, archList.get(j), cmd, optionName});\r
                 }\r
             }\r
                 }\r
             }\r
-            result[i][0] = name;\r
-            result[i][1] = value;\r
         }\r
 \r
         }\r
 \r
+        String[][] result = new String[optionList.size()][5];\r
+        for (int i = 0; i < optionList.size(); i++) {\r
+            result[i][0] = optionList.get(i)[0];\r
+            result[i][1] = optionList.get(i)[1];\r
+            result[i][2] = optionList.get(i)[2];\r
+            result[i][3] = optionList.get(i)[3];\r
+            result[i][4] = optionList.get(i)[4];\r
+        }\r
         return result;\r
     }\r
         return result;\r
     }\r
+\r
+    public static String[][] getModuleBuildOptions(boolean toolChainFamilyFlag) {\r
+        String[] xPath;\r
+        \r
+        if (toolChainFamilyFlag == true) {\r
+            xPath = new String[] {\r
+                    "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
+                    "/Options/Option[@ToolChainFamily]", };\r
+        } else {\r
+            xPath = new String[] {\r
+                    "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
+                    "/Options/Option[@TagName]", };\r
+        }\r
+        return getOptions("ModuleSaBuildOptions", xPath, toolChainFamilyFlag);\r
+    }   \r
     \r
     \r
-    public static String getModuleName() {\r
-        String[] xPath = new String[] { "/ModuleName", "/BaseName" };\r
+    public static String[][] getPlatformBuildOptions(boolean toolChainFamilyFlag) {\r
+        String[] xPath;\r
 \r
 \r
-        XmlObject[] returns = get(xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return returns[0].toString();\r
+        if (toolChainFamilyFlag == true) {\r
+            xPath = new String[] {\r
+                    "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
+                    "/BuildOptions/Options/Option[@ToolChainFamily]", };\r
+        } else {\r
+            xPath = new String[] {\r
+                    "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
+                    "/BuildOptions/Options/Option[@TagName]", };\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        return getOptions("PlatformSurfaceArea", xPath, toolChainFamilyFlag);\r
     }\r
 \r
     }\r
 \r
-    /**\r
-     Retrieve <xxxHeader>/ModuleType\r
-\r
-     @returns   The module type name    if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static String getModuleType() {\r
-        String[] xPath = new String[] { "/ModuleType" };\r
+    public static ToolChainInfo getFpdToolChainInfo() {\r
+        String[] xPath = new String[] { "/PlatformDefinitions" };\r
 \r
 \r
-        XmlObject[] returns = get(xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            ModuleTypeDef type = (ModuleTypeDef) returns[0];\r
-            return type.enumValue().toString();\r
+        Object[] returns = get("PlatformSurfaceArea", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
         }\r
         }\r
-\r
-        return null;\r
+        \r
+        PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];\r
+        ToolChainInfo toolChainInfo = new ToolChainInfo();\r
+        toolChainInfo.addTargets(item.getBuildTargets().toString());\r
+        toolChainInfo.addArchs(item.getSupportedArchitectures().toString());\r
+        toolChainInfo.addTagnames((String)null);\r
+        return toolChainInfo;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve <xxxHeader>/ComponentType\r
-     \r
-     @returns   The component type name if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static String getComponentType() {\r
-        String[] xPath = new String[] { "/ComponentType" };\r
-\r
-        XmlObject[] returns = get(xPath);\r
+     * Retrieve <xxxHeader>/ModuleType\r
+     * \r
+     * @returns The module type name if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String getModuleType() {\r
+        String[] xPath = new String[] { "/ModuleType" };\r
+\r
+        Object[] returns = get(xPath);\r
         if (returns != null && returns.length > 0) {\r
         if (returns != null && returns.length > 0) {\r
-            FrameworkComponentTypes type = (FrameworkComponentTypes) returns[0];\r
+            ModuleTypeDef type = (ModuleTypeDef) returns[0];\r
             return type.enumValue().toString();\r
         }\r
 \r
             return type.enumValue().toString();\r
         }\r
 \r
@@ -393,89 +541,91 @@ public class SurfaceAreaQuery {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve Includes/PackageName\r
-\r
-     @param     arch    Architecture name\r
-\r
-     @returns   package name list       if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static List<String> getIncludePackageName(String arch) {\r
+     * Retrieve PackageDependencies/Package\r
+     * \r
+     * @param arch\r
+     *            Architecture name\r
+     * \r
+     * @returns package name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static PackageIdentification[] getDependencePkg(String arch) {\r
         String[] xPath;\r
         String[] xPath;\r
+        String packageGuid = null;\r
+        String packageVersion = null;\r
 \r
         if (arch == null || arch.equals("")) {\r
 \r
         if (arch == null || arch.equals("")) {\r
-            xPath = new String[] {\r
-                "/PackageName",\r
-                "/Arch/PackageName"\r
-                };\r
+            xPath = new String[] { "/Package" };\r
         } else {\r
         } else {\r
-            xPath = new String[] {\r
-                "/PackageName",\r
-                "/PackageName[@SupArchList='ALL' or @SupArchList='" + arch + "']",\r
-                "/PackageName[@Arch='ALL' or @Arch='" + arch + "']",\r
-                "/Arch[@ArchType='ALL' or @ArchType='" + arch + "']/PackageName"\r
-                };\r
-        }\r
-        \r
-        XmlObject[] returns = get("Includes", xPath);\r
-        if (returns == null || returns.length == 0) {\r
-            returns = get("PackageDependencies", xPath);\r
-            if (returns == null || returns.length == 0) {\r
-                return null;\r
-            }\r
+            xPath = new String[] { "/Package[not(@SupArchList) or @SupArchList='"\r
+                    + arch + "']" };\r
         }\r
 \r
         }\r
 \r
-        List<String> packageNames = new ArrayList<String>();\r
-        PackageNameDocument.PackageName[] nameObj = (PackageNameDocument.PackageName[])returns;\r
-        for (int i = 0; i < returns.length; ++i) {\r
-            packageNames.add(nameObj[i].getStringValue());\r
+        Object[] returns = get("PackageDependencies", xPath);\r
+        if (returns == null) {\r
+            return new PackageIdentification[0];\r
         }\r
         }\r
-        \r
-        return packageNames;\r
+        PackageIdentification[] packageIdList = new PackageIdentification[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];\r
+            packageGuid = item.getPackageGuid();\r
+            packageVersion = item.getPackageVersion();\r
+            packageIdList[i] = (new PackageIdentification(null, packageGuid,\r
+                    packageVersion));\r
+        }\r
+        return packageIdList;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve LibraryClassDefinitions/LibraryClass for specified usage\r
-\r
-     @param     usage   Library class usage\r
-\r
-     @returns   LibraryClass objects list   if elements are found at the known xpath\r
-     @returns   null                        if nothing is there\r
-     **/\r
-    public static LibraryClassDocument.LibraryClass[] getLibraryClassArray(String usage) {\r
+     * Retrieve LibraryClassDefinitions/LibraryClass for specified usage\r
+     * \r
+     * @param usage\r
+     *            Library class usage\r
+     * \r
+     * @returns LibraryClass objects list if elements are found at the known\r
+     *          xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String[] getLibraryClasses(String usage) {\r
         String[] xPath;\r
 \r
         if (usage == null || usage.equals("")) {\r
         String[] xPath;\r
 \r
         if (usage == null || usage.equals("")) {\r
-            xPath = new String[] {"/LibraryClass"};\r
+            xPath = new String[] { "/LibraryClass" };\r
         } else {\r
         } else {\r
-            xPath = new String[] {"/LibraryClass[@Usage='" + usage + "']"};\r
+            xPath = new String[] { "/LibraryClass[@Usage='" + usage + "']" };\r
         }\r
 \r
         }\r
 \r
-        XmlObject[] returns = get("LibraryClassDefinitions", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (LibraryClassDocument.LibraryClass[]) returns;\r
+        Object[] returns = get("LibraryClassDefinitions", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        LibraryClassDocument.LibraryClass[] libraryClassList = (LibraryClassDocument.LibraryClass[]) returns;\r
+        String[] libraryClassName = new String[libraryClassList.length];\r
+        for (int i = 0; i < libraryClassList.length; i++) {\r
+            libraryClassName[i] = libraryClassList[i].getKeyword();\r
+        }\r
+        return libraryClassName;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve ModuleEntryPoint names\r
-\r
-     @returns   ModuleEntryPoint name list  if elements are found at the known xpath\r
-     @returns   null                        if nothing is there\r
-     **/\r
+     * Retrieve ModuleEntryPoint names\r
+     * \r
+     * @returns ModuleEntryPoint name list if elements are found at the known\r
+     *          xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getModuleEntryPointArray() {\r
         String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };\r
 \r
     public static String[] getModuleEntryPointArray() {\r
         String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };\r
 \r
-        XmlObject[] returns = get("Externs", xPath);\r
+        Object[] returns = get("Externs", xPath);\r
 \r
         if (returns != null && returns.length > 0) {\r
             String[] entryPoints = new String[returns.length];\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
                 entryPoints[i] = ((XmlNormalizedString) returns[i])\r
 \r
         if (returns != null && returns.length > 0) {\r
             String[] entryPoints = new String[returns.length];\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
                 entryPoints[i] = ((XmlNormalizedString) returns[i])\r
-                                .getStringValue();\r
+                        .getStringValue();\r
             }\r
 \r
             return entryPoints;\r
             }\r
 \r
             return entryPoints;\r
@@ -485,108 +635,162 @@ public class SurfaceAreaQuery {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve module Guid string\r
\r
-     @returns   GUILD string            if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static String getModuleGuid() {\r
-        String[] xPath = new String[] { "" };\r
+     * retrieve Protocol for specified usage\r
+     * \r
+     * @param usage\r
+     *            Protocol usage arch Architecture\r
+     * \r
+     * @returns Protocol String list if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getProtocolArray(String arch, String usage) {\r
+        String[] xPath;\r
+        String usageXpath = "";\r
+        String archXpath = "";\r
 \r
 \r
-        XmlObject[] returns = get("MsaHeader", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            MsaHeaderDocument.MsaHeader moduleHeader = (MsaHeaderDocument.MsaHeader) returns[0];\r
-            if (moduleHeader.isSetGuid()) {\r
-                return moduleHeader.getGuid().getStringValue();\r
-            } else if (moduleHeader.isSetGuidValue()) {\r
-                return moduleHeader.getGuidValue();\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
+        } else {\r
+            archXpath = "/Protocol[@SupArchList='" + arch + "']";\r
+            if (usage != null && !usage.equals("")) {\r
+                usageXpath = "/Protocol[@Usage='" + usage + "']";\r
+                xPath = new String[] { usageXpath, archXpath };\r
+            } else {\r
+                return getProtocolArray(arch);\r
             }\r
             }\r
+\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        Object[] returns = get("Protocols", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
+        }\r
+        Protocol[] protocolList = (Protocol[]) returns;\r
+\r
+        String[] protocolArray = new String[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            protocolArray[i] = protocolList[i].getProtocolCName();\r
+        }\r
+        return protocolArray;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve module Guid string\r
\r
-     @returns   GUILD string            if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static String getModuleGuidValue() {\r
-        String[] xPath = new String[] { "" };\r
+     * retrieve Protocol for specified usage\r
+     * \r
+     * @param arch\r
+     *            Architecture\r
+     * \r
+     * @returns Protocol String list if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getProtocolArray(String arch) {\r
+        String[] xPath;\r
+\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
+        } else {\r
+            xPath = new String[] { "/Protocol[@SupArchList='" + arch + "']" };\r
+        }\r
 \r
 \r
-        XmlObject[] returns = get("MsaHeader", xPath);\r
-        if (returns != null && returns.length > 0) {            \r
-            MsaHeaderDocument.MsaHeader moduleHeader = (MsaHeaderDocument.MsaHeader) returns[0];\r
-            return moduleHeader.getGuidValue();\r
+        Object[] returns = get("Protocols", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
         }\r
+        Protocol[] protocolList = (Protocol[]) returns;\r
 \r
 \r
-        return null;\r
+        String[] protocolArray = new String[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            protocolArray[i] = protocolList[i].getProtocolCName();\r
+        }\r
+        return protocolArray;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     retrieve Protocol for specified usage\r
-\r
-     @param     usage   Protocol usage\r
-\r
-     @returns   Protocol objects list   if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static ProtocolsDocument.Protocols.Protocol[] getProtocolArray(String usage) {\r
+     * Retrieve ProtocolNotify for specified usage\r
+     * \r
+     * @param usage\r
+     *            ProtocolNotify usage\r
+     * \r
+     * @returns String[] if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getProtocolNotifyArray(String arch) {\r
         String[] xPath;\r
 \r
         String[] xPath;\r
 \r
-        if (usage == null || usage.equals("")) {\r
-            xPath = new String[] {"/Protocol"};\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
         } else {\r
         } else {\r
-            xPath = new String[] {"/Protocol[@Usage='" + usage + "']"};\r
+            xPath = new String[] { "/ProtocolNotify[@SupArchList='" + arch\r
+                    + "']" };\r
         }\r
 \r
         }\r
 \r
-        XmlObject[] returns = get("Protocols", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (ProtocolsDocument.Protocols.Protocol[]) returns;\r
+        Object[] returns = get("Protocols", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        String[] protocolNotifyList = new String[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();\r
+        }\r
+\r
+        return protocolNotifyList;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve ProtocolNotify for specified usage\r
-    \r
-     @param     usage   ProtocolNotify usage\r
+     * Retrieve ProtocolNotify for specified usage\r
+     * \r
+     * @param usage\r
+     *            ProtocolNotify usage\r
+     * \r
+     * @returns String[] if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getProtocolNotifyArray(String arch, String usage) {\r
 \r
 \r
-     @returns   ProtocolNotify objects list     if elements are found at the known xpath\r
-     @returns   null                            if nothing is there\r
-     **/\r
-    public static ProtocolsDocument.Protocols.ProtocolNotify[] getProtocolNotifyArray(String usage) {\r
         String[] xPath;\r
         String[] xPath;\r
+        String usageXpath;\r
+        String archXpath;\r
 \r
 \r
-        if (usage == null || usage.equals("")) {\r
-            xPath = new String[] {"/ProtocolNotify"};\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
         } else {\r
         } else {\r
-            xPath = new String[] {"/ProtocolNotify[@Usage='" + usage + "']"};\r
+            archXpath = "/ProtocolNotify[@SupArchList='" + arch + "']";\r
+            if (usage != null && !usage.equals("")) {\r
+                usageXpath = "/ProtocolNotify[@Usage='" + arch + "']";\r
+                xPath = new String[] { archXpath, usageXpath };\r
+            } else {\r
+                return getProtocolNotifyArray(arch);\r
+            }\r
         }\r
 \r
         }\r
 \r
-        XmlObject[] returns = get("Protocols", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (ProtocolsDocument.Protocols.ProtocolNotify[]) returns;\r
+        Object[] returns = get("Protocols", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        String[] protocolNotifyList = new String[returns.length];\r
+\r
+        for (int i = 0; i < returns.length; i++) {\r
+            protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();\r
+        }\r
+        return protocolNotifyList;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve ModuleUnloadImage names\r
-\r
-     @returns   ModuleUnloadImage name list     if elements are found at the known xpath\r
-     @returns   null                            if nothing is there\r
-     **/\r
+     * Retrieve ModuleUnloadImage names\r
+     * \r
+     * @returns ModuleUnloadImage name list if elements are found at the known\r
+     *          xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getModuleUnloadImageArray() {\r
         String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };\r
 \r
     public static String[] getModuleUnloadImageArray() {\r
         String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };\r
 \r
-        XmlObject[] returns = get("Externs", xPath);\r
+        Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
             String[] stringArray = new String[returns.length];\r
         if (returns != null && returns.length > 0) {\r
             String[] stringArray = new String[returns.length];\r
-            XmlNormalizedString[] doc = (XmlNormalizedString[])returns;\r
+            XmlNormalizedString[] doc = (XmlNormalizedString[]) returns;\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
                 stringArray[i] = doc[i].getStringValue();\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
                 stringArray[i] = doc[i].getStringValue();\r
@@ -599,15 +803,15 @@ public class SurfaceAreaQuery {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve Extern\r
-\r
-     @returns   Extern objects list     if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+     Retrieve Extern\r
+     * \r
+     * @returns Extern objects list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static ExternsDocument.Externs.Extern[] getExternArray() {\r
         String[] xPath = new String[] { "/Extern" };\r
 \r
     public static ExternsDocument.Externs.Extern[] getExternArray() {\r
         String[] xPath = new String[] { "/Extern" };\r
 \r
-        XmlObject[] returns = get("Externs", xPath);\r
+        Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
             return (ExternsDocument.Externs.Extern[]) returns;\r
         }\r
         if (returns != null && returns.length > 0) {\r
             return (ExternsDocument.Externs.Extern[]) returns;\r
         }\r
@@ -616,504 +820,1069 @@ public class SurfaceAreaQuery {
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve Ppi information\r
-\r
-     @param     usage   Ppi usage\r
-\r
-     @returns   Ppi objects list        if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static PPIsDocument.PPIs.Ppi[] getPpiArray(String usage) {\r
+     * Retrieve PpiNotify for specified arch\r
+     * \r
+     * @param arch\r
+     *            PpiNotify arch\r
+     * \r
+     * @returns String[] if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getPpiNotifyArray(String arch) {\r
         String[] xPath;\r
 \r
         String[] xPath;\r
 \r
-        if (usage == null || usage.equals("")) {\r
-            xPath = new String[] { "/Ppi" };\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
         } else {\r
         } else {\r
-            xPath = new String[] { "/Ppi[@Usage='" + usage + "']" };\r
+            xPath = new String[] { "/PpiNotify[@SupArchList='" + arch + "']" };\r
         }\r
 \r
         }\r
 \r
-        XmlObject[] returns = get("PPIs", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (PPIsDocument.PPIs.Ppi[])returns;\r
+        Object[] returns = get("PPIs", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        String[] ppiNotifyList = new String[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();\r
+        }\r
+\r
+        return ppiNotifyList;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrive PpiNotify information\r
-    \r
-     @param usage\r
+     * Retrieve PpiNotify for specified usage and arch\r
+     * \r
+     * @param arch\r
+     *            PpiNotify arch usage PpiNotify usage\r
+     * \r
+     * \r
+     * @returns String[] if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getPpiNotifyArray(String arch, String usage) {\r
 \r
 \r
-     @returns   PpiNotify objects list  if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static PPIsDocument.PPIs.PpiNotify[] getPpiNotifyArray(String usage) {\r
         String[] xPath;\r
         String[] xPath;\r
+        String usageXpath;\r
+        String archXpath;\r
 \r
 \r
-        if (usage == null || usage.equals("")) {\r
-            xPath = new String[] { "/PpiNotify" };\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
         } else {\r
         } else {\r
-            xPath = new String[] { "/PpiNotify[@Usage='" + usage + "']" };\r
+            archXpath = "/PpiNotify[@SupArchList='" + arch + "']";\r
+            if (usage != null && !usage.equals("")) {\r
+                usageXpath = "/PpiNotify[@Usage='" + arch + "']";\r
+                xPath = new String[] { archXpath, usageXpath };\r
+            } else {\r
+                return getProtocolNotifyArray(arch);\r
+            }\r
         }\r
 \r
         }\r
 \r
-        XmlObject[] returns = get("PPIs", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (PPIsDocument.PPIs.PpiNotify[])returns;\r
+        Object[] returns = get("PPIs", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        String[] ppiNotifyList = new String[returns.length];\r
+\r
+        for (int i = 0; i < returns.length; i++) {\r
+            ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();\r
+        }\r
+        return ppiNotifyList;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve GuidEntry information for specified usage\r
+     * Retrieve Ppi for specified arch\r
+     * \r
+     * @param arch\r
+     *            Ppi arch\r
+     * \r
+     * @returns String[] if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getPpiArray(String arch) {\r
+        String[] xPath;\r
+\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
+        } else {\r
+            xPath = new String[] { "/Ppi[@SupArchList='" + arch + "']" };\r
+        }\r
+\r
+        Object[] returns = get("PPIs", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
+        }\r
+\r
+        String[] ppiList = new String[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();\r
+        }\r
+        return ppiList;\r
+    }\r
 \r
 \r
-     @param     usage   GuidEntry usage\r
+    /**\r
+     * Retrieve PpiNotify for specified usage and arch\r
+     * \r
+     * @param arch\r
+     *            PpiNotify arch usage PpiNotify usage\r
+     * \r
+     * \r
+     * @returns String[] if elements are found at the known xpath\r
+     * @returns String[0] if nothing is there\r
+     */\r
+    public static String[] getPpiArray(String arch, String usage) {\r
 \r
 \r
-     @returns   GuidEntry objects list  if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static GuidsDocument.Guids.GuidEntry[] getGuidEntryArray(String usage) {\r
         String[] xPath;\r
         String[] xPath;\r
+        String usageXpath;\r
+        String archXpath;\r
 \r
 \r
-        if (usage == null || usage.equals("")) {\r
-            xPath = new String[] { "/GuidEntry" };\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
         } else {\r
         } else {\r
-            xPath = new String[] { "/GuidEntry[@Usage='" + usage + "']" };\r
+            archXpath = "/Ppi[@SupArchList='" + arch + "']";\r
+            if (usage != null && !usage.equals("")) {\r
+                usageXpath = "/Ppi[@Usage='" + arch + "']";\r
+                xPath = new String[] { archXpath, usageXpath };\r
+            } else {\r
+                return getProtocolNotifyArray(arch);\r
+            }\r
         }\r
 \r
         }\r
 \r
-        XmlObject[] returns = get("Guids", xPath);\r
-        if (returns != null && returns.length > 0) {\r
-            return (GuidsDocument.Guids.GuidEntry[])returns;\r
+        Object[] returns = get("PPIs", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        return null;\r
+        String[] ppiList = new String[returns.length];\r
+\r
+        for (int i = 0; i < returns.length; i++) {\r
+            ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();\r
+        }\r
+        return ppiList;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve Library instance information\r
+     * Retrieve GuidEntry information for specified usage\r
+     * \r
+     * @param arch\r
+     *            GuidEntry arch\r
+     * \r
+     * @returns GuidEntry objects list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String[] getGuidEntryArray(String arch) {\r
+        String[] xPath;\r
+\r
+        if (arch == null || arch.equals("")) {\r
+            xPath = new String[] { "/GuidName" };\r
+        } else {\r
+            xPath = new String[] { "/GuidName[@SupArchList='" + arch + "']" };\r
+        }\r
+\r
+        Object[] returns = get("Guids", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
+        }\r
+        String[] guidList = new String[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();\r
+        }\r
+        return guidList;\r
 \r
 \r
-     @param     arch    Architecture name\r
-     @param     usage   Library instance usage\r
+    }\r
 \r
 \r
-     @returns   library instance name list  if elements are found at the known xpath\r
-     @returns   null                        if nothing is there\r
-     **/\r
-    public static List<String> getLibraryInstance(String arch, String usage) {\r
+    /**\r
+     * Retrieve GuidEntry information for specified usage\r
+     * \r
+     * @param arch\r
+     *            GuidEntry arch usage GuidEntry usage\r
+     * \r
+     * @returns GuidEntry objects list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String[] getGuidEntryArray(String arch, String usage) {\r
         String[] xPath;\r
         String[] xPath;\r
-        String   archAttribute = "";\r
-        String   usageAttribute = "";\r
+        String archXpath;\r
+        String usageXpath;\r
 \r
 \r
-        if ((arch != null) || (!arch.equals(""))) {\r
-            archAttribute = "[@ArchType='ALL' or @ArchType='" + arch + "']";\r
-        }\r
-        \r
-        if ((usage != null) || (!usage.equals(""))) {\r
-            // if no Usage attribute specified, default to ALWAYS_CONSUMED\r
-            if (usage.equals(LibraryUsage.ALWAYS_CONSUMED.toString())) {\r
-                usageAttribute = "[not(@Usage) or @Usage='" + usage + "']";\r
+        if (arch == null || arch.equals("")) {\r
+            return new String[0];\r
+        } else {\r
+            archXpath = "/GuidEntry[@SupArchList='" + arch + "']";\r
+            if (usage != null && !usage.equals("")) {\r
+                usageXpath = "/GuidEntry[@Usage='" + arch + "']";\r
+                xPath = new String[] { archXpath, usageXpath };\r
             } else {\r
             } else {\r
-                usageAttribute = "[@Usage='" + usage + "']";\r
+                return getProtocolNotifyArray(arch);\r
             }\r
         }\r
             }\r
         }\r
-        \r
-        xPath = new String[] {\r
-                "/Library" + archAttribute, //usageAttribute,\r
-                "/Library[not(@SupArchList) or @SupArchList='" + arch + "']",\r
-                "/Arch" + archAttribute + "/Library" + usageAttribute\r
-                };\r
 \r
 \r
-        XmlObject[] returns = get("Libraries", xPath);\r
-        if (returns == null || returns.length == 0) {\r
-            return null;\r
+        Object[] returns = get("Guids", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
         }\r
         }\r
-        \r
-        List<String> instances = new ArrayList<String>();\r
-        for (int i = 0; i < returns.length; ++i) {\r
-            if (returns[i] instanceof LibrariesDocument.Libraries.Library) {\r
-                LibrariesDocument.Libraries.Library lib = (LibrariesDocument.Libraries.Library)returns[i];\r
-                instances.add(lib.getStringValue());\r
-            } else if (returns[i] instanceof LibrariesDocument.Libraries.Arch.Library) {\r
-                LibrariesDocument.Libraries.Arch.Library lib = (LibrariesDocument.Libraries.Arch.Library)returns[i];\r
-                instances.add(lib.getStringValue());\r
-            }\r
+\r
+        String[] guidList = new String[returns.length];\r
+\r
+        for (int i = 0; i < returns.length; i++) {\r
+            guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();\r
+        }\r
+        return guidList;\r
+    }\r
+\r
+    /**\r
+     * Retrieve Library instance information\r
+     * \r
+     * @param arch\r
+     *            Architecture name\r
+     * @param usage\r
+     *            Library instance usage\r
+     * \r
+     * @returns library instance name list if elements are found at the known\r
+     *          xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static ModuleIdentification[] getLibraryInstance(String arch) {\r
+        String[] xPath;\r
+        String saGuid = null;\r
+        String saVersion = null;\r
+        String pkgGuid = null;\r
+        String pkgVersion = null;\r
+\r
+        if (arch == null || arch.equalsIgnoreCase("")) {\r
+            xPath = new String[] { "/Instance" };\r
+        } else {\r
+            xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"\r
+                    + arch + "']" };\r
         }\r
 \r
         }\r
 \r
-        return instances;\r
+        Object[] returns = get("Libraries", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return new ModuleIdentification[0];\r
+        }\r
+\r
+        ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];\r
+            saGuid = library.getModuleGuid();\r
+            saVersion = library.getModuleVersion();\r
+\r
+            pkgGuid = library.getPackageGuid();\r
+            pkgVersion = library.getPackageVersion();\r
+\r
+            ModuleIdentification saId = new ModuleIdentification(null, saGuid,\r
+                    saVersion);\r
+            PackageIdentification pkgId = new PackageIdentification(null,\r
+                    pkgGuid, pkgVersion);\r
+            saId.setPackage(pkgId);\r
+\r
+            saIdList[i] = saId;\r
+\r
+        }\r
+        return saIdList;\r
     }\r
 \r
     }\r
 \r
-    ///\r
-    /// This method is used for retrieving the elements information which has \r
-    /// CName sub-element\r
-    ///\r
+    // /\r
+    // / This method is used for retrieving the elements information which has\r
+    // / CName sub-element\r
+    // /\r
     private static String[] getCNames(String from, String xPath[]) {\r
     private static String[] getCNames(String from, String xPath[]) {\r
-        XmlObject[] returns = get(from, xPath);\r
+        Object[] returns = get(from, xPath);\r
         if (returns == null || returns.length == 0) {\r
             return null;\r
         }\r
         if (returns == null || returns.length == 0) {\r
             return null;\r
         }\r
-        \r
+\r
         String[] strings = new String[returns.length];\r
         for (int i = 0; i < returns.length; ++i) {\r
         String[] strings = new String[returns.length];\r
         for (int i = 0; i < returns.length; ++i) {\r
-            strings[i] = ((CName)returns[i]).getStringValue(); \r
+            // TBD\r
+            // strings[i] = ((CName) returns[i]).getStringValue();\r
         }\r
         }\r
-        \r
-        return strings;            \r
+\r
+        return strings;\r
     }\r
     }\r
-    \r
-    /**\r
-     Retrive library's constructor name\r
 \r
 \r
-     @returns   constructor name list   if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+    /**\r
+     * Retrive library's constructor name\r
+     * \r
+     * @returns constructor name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String getLibConstructorName() {\r
     public static String getLibConstructorName() {\r
-        String[] xPath = new String[] {"/Extern/Constructor"};\r
+        String[] xPath = new String[] { "/Extern/Constructor" };\r
 \r
 \r
-        XmlObject[] returns = get("Externs", xPath);\r
+        Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
         if (returns != null && returns.length > 0) {\r
-            CName constructor = (CName)returns[0]; \r
-            return constructor.getStringValue();            \r
+            // CName constructor = (CName) returns[0];\r
+            // return constructor.getStringValue();\r
         }\r
 \r
         return null;\r
     }\r
 \r
     /**\r
         }\r
 \r
         return null;\r
     }\r
 \r
     /**\r
-     Retrive library's destructor name\r
-\r
-     @returns   destructor name list    if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+     Retrive library's destructor name\r
+     * \r
+     * @returns destructor name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String getLibDestructorName() {\r
     public static String getLibDestructorName() {\r
-        String[] xPath = new String[] {"/Extern/Destructor"};\r
+        String[] xPath = new String[] { "/Extern/Destructor" };\r
 \r
 \r
-        XmlObject[] returns = get("Externs", xPath);\r
+        Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
         if (returns != null && returns.length > 0) {\r
-            CName destructor = (CName)returns[0]; \r
-            return destructor.getStringValue();            \r
+            // CName destructor = (CName) returns[0];\r
+            // return destructor.getStringValue();\r
         }\r
 \r
         return null;\r
     }\r
         }\r
 \r
         return null;\r
     }\r
-    \r
-    /**\r
-     Retrive DriverBinding names\r
 \r
 \r
-     @returns   DriverBinding name list if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+    /**\r
+     * Retrive DriverBinding names\r
+     * \r
+     * @returns DriverBinding name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getDriverBindingArray() {\r
     public static String[] getDriverBindingArray() {\r
-        String[] xPath = new String[] {"/Extern/DriverBinding"};\r
+        String[] xPath = new String[] { "/Extern/DriverBinding" };\r
         return getCNames("Externs", xPath);\r
     }\r
         return getCNames("Externs", xPath);\r
     }\r
-    \r
-    /**\r
-     Retrive ComponentName names\r
 \r
 \r
-     @returns   ComponentName name list if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+    /**\r
+     * Retrive ComponentName names\r
+     * \r
+     * @returns ComponentName name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getComponentNameArray() {\r
     public static String[] getComponentNameArray() {\r
-        String[] xPath = new String[] {"/Extern/ComponentName"};\r
+        String[] xPath = new String[] { "/Extern/ComponentName" };\r
         return getCNames("Externs", xPath);\r
     }\r
         return getCNames("Externs", xPath);\r
     }\r
-    \r
-    /**\r
-     Retrive DriverConfig names\r
 \r
 \r
-     @returns   DriverConfig name list  if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+    /**\r
+     * Retrive DriverConfig names\r
+     * \r
+     * @returns DriverConfig name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getDriverConfigArray() {\r
     public static String[] getDriverConfigArray() {\r
-        String[] xPath = new String[] {"/Extern/DriverConfig"};\r
+        String[] xPath = new String[] { "/Extern/DriverConfig" };\r
         return getCNames("Externs", xPath);\r
     }\r
         return getCNames("Externs", xPath);\r
     }\r
-    \r
-    /**\r
-     Retrive DriverDiag names\r
 \r
 \r
-     @returns   DriverDiag name list    if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+    /**\r
+     * Retrive DriverDiag names\r
+     * \r
+     * @returns DriverDiag name list if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getDriverDiagArray() {\r
     public static String[] getDriverDiagArray() {\r
-        String[] xPath = new String[] {"/Extern/DriverDiag"};\r
+        String[] xPath = new String[] { "/Extern/DriverDiag" };\r
         return getCNames("Externs", xPath);\r
     }\r
 \r
     /**\r
         return getCNames("Externs", xPath);\r
     }\r
 \r
     /**\r
-     Retrive SetVirtualAddressMapCallBack names\r
-\r
-     @returns   SetVirtualAddressMapCallBack name list  \r
-                                        if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+     Retrive SetVirtualAddressMapCallBack names\r
+     * \r
+     * @returns SetVirtualAddressMapCallBack name list if elements are found at\r
+     *          the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getSetVirtualAddressMapCallBackArray() {\r
     public static String[] getSetVirtualAddressMapCallBackArray() {\r
-        String[] xPath = new String[] {"/Extern/SetVirtualAddressMapCallBack"};\r
+        String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };\r
         return getCNames("Externs", xPath);\r
     }\r
         return getCNames("Externs", xPath);\r
     }\r
-    \r
-    /**\r
-     Retrive ExitBootServicesCallBack names\r
 \r
 \r
-     @returns   ExitBootServicesCallBack name list  \r
-                                        if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
+    /**\r
+     * Retrive ExitBootServicesCallBack names\r
+     * \r
+     * @returns ExitBootServicesCallBack name list if elements are found at the\r
+     *          known xpath\r
+     * @returns null if nothing is there\r
+     */\r
     public static String[] getExitBootServicesCallBackArray() {\r
     public static String[] getExitBootServicesCallBackArray() {\r
-        String[] xPath = new String[] {"/Extern/ExitBootServicesCallBack"};\r
+        String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };\r
         return getCNames("Externs", xPath);\r
     }\r
 \r
     /**\r
         return getCNames("Externs", xPath);\r
     }\r
 \r
     /**\r
-     Retrieve module surface area file information\r
-\r
-     @returns   ModuleSA objects list   if elements are found at the known xpath\r
-     @returns   Empty ModuleSA list     if nothing is there\r
-     **/\r
-    public static ModuleSADocument.ModuleSA[] getFpdModules() {\r
-        String[] xPath = new String[] { "/TianoImage/*/ModuleSA" };\r
+     * Retrieve module surface area file information\r
+     * \r
+     * @returns ModuleSA objects list if elements are found at the known xpath\r
+     * @returns Empty ModuleSA list if nothing is there\r
+     */\r
+    public static Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() {\r
+        String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };\r
+        Object[] result = get("PlatformSurfaceArea", xPath);\r
+        String arch = null;\r
+        String fvBinding = null;\r
+        String saGuid = null;\r
+        String saVersion = null;\r
+        String pkgGuid = null;\r
+        String pkgVersion = null;\r
+\r
+        Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
 \r
 \r
-        XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
         if (result == null) {\r
         if (result == null) {\r
-            xPath = new String[] { "/FrameworkModules/*/ModuleSA" };\r
-            result = get("FrameworkPlatformDescription", xPath);\r
-            if (result != null) {\r
-                return (ModuleSADocument.ModuleSA[]) result;\r
+            return fpdModuleMap;\r
+        }\r
+\r
+        for (int i = 0; i < result.length; i++) {\r
+            //\r
+            // Get Fpd SA Module element node and add to ObjectMap.\r
+            //\r
+            Map<String, XmlObject> ObjectMap = new HashMap<String, XmlObject>();\r
+            ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];\r
+            if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {\r
+                ObjectMap.put("Libraries", moduleSA.getLibraries());\r
+            }\r
+            if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {\r
+                ObjectMap.put("PcdBuildDefinition", moduleSA\r
+                        .getPcdBuildDefinition());\r
+            }\r
+            if (((ModuleSADocument.ModuleSA) result[i])\r
+                    .getModuleSaBuildOptions() != null) {\r
+                ObjectMap.put("ModuleSaBuildOptions", moduleSA\r
+                        .getModuleSaBuildOptions());\r
+            }\r
+\r
+            //\r
+            // Get Fpd SA Module attribute and create FpdMoudleIdentification.\r
+            //\r
+            arch = moduleSA.getSupArchList().toString();\r
+\r
+            // TBD\r
+            fvBinding = null;\r
+            saVersion = ((ModuleSADocument.ModuleSA) result[i])\r
+                    .getModuleVersion();\r
+\r
+            saGuid = moduleSA.getModuleGuid();\r
+            pkgGuid = moduleSA.getPackageGuid();\r
+            pkgVersion = moduleSA.getPackageVersion();\r
+\r
+            //\r
+            // Create Module Identification which have class member of package\r
+            // identification.\r
+            //\r
+            PackageIdentification pkgId = new PackageIdentification(null,\r
+                    pkgGuid, pkgVersion);\r
+            ModuleIdentification saId = new ModuleIdentification(null, saGuid,\r
+                    saVersion);\r
+\r
+            saId.setPackage(pkgId);\r
+\r
+            //\r
+            // Create FpdModule Identification which have class member of module\r
+            // identification\r
+            //\r
+            if (arch != null) {\r
+                String[] archList = arch.split(" ");\r
+                for (int j = 0; j < archList.length; j++) {\r
+                    FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId,    archList[j]);\r
+        \r
+                    if (fvBinding != null) {\r
+                        fpdSaId.setFvBinding(fvBinding);\r
+                    }\r
+        \r
+                    //\r
+                    // Put element to Map<FpdModuleIdentification, Map<String,\r
+                    // Object>>.\r
+                    //\r
+                    fpdModuleMap.put(fpdSaId, ObjectMap);\r
+                }\r
             }\r
             }\r
-            return new ModuleSADocument.ModuleSA[0];\r
         }\r
         }\r
+        return fpdModuleMap;\r
+    }\r
 \r
 \r
-        return (ModuleSADocument.ModuleSA[]) result;\r
+    /**\r
+     * Retrieve valid image names\r
+     * \r
+     * @returns valid iamges name list if elements are found at the known xpath\r
+     * @returns empty list if nothing is there\r
+     */\r
+    public static String[] getFpdValidImageNames() {\r
+        String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };\r
+\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
+        if (queryResult == null) {\r
+            return new String[0];\r
+        }\r
+\r
+        String[] result = new String[queryResult.length];\r
+        for (int i = 0; i < queryResult.length; i++) {\r
+            result[i] = ((XmlString) queryResult[i]).getStringValue();\r
+        }\r
+\r
+        return result;\r
+    }\r
+    \r
+    public static XmlObject getFpdUserExtension() {\r
+        String[] xPath = new String[] { "" };\r
+\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
+        if (queryResult == null) {\r
+            return null;\r
+        }\r
+        return null;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve all <ModuleSA> documents from FPD file.\r
+     * Retrieve FV image option information\r
+     * \r
+     * @param fvName\r
+     *            FV image name\r
+     * \r
+     * @returns option name/value list if elements are found at the known xpath\r
+     * @returns empty list if nothing is there\r
+     */\r
+    public static String[][] getFpdOptions(String fvName) {\r
+           String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"\r
+                      + fvName.toUpperCase() + "']/FvImageOptions" };\r
+           Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
+           if (queryResult == null) {\r
+                 return new String[0][];\r
+           }\r
+           ArrayList<String[]> list = new ArrayList<String[]>();\r
+           for (int i = 0; i < queryResult.length; i++) {\r
+               FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];\r
+               List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item\r
+               .getNameValueList();\r
+               Iterator iter = namevalues.iterator();\r
+               while (iter.hasNext()) {\r
+                   FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter\r
+                   .next();\r
+                   list.add(new String[] { nvItem.getName(), nvItem.getValue() });\r
+               }\r
+           }\r
+          String[][] result = new String[list.size()][2];\r
+          for (int i = 0; i < list.size(); i++) {\r
+              result[i][0] = list.get(i)[0];\r
+              result[i][1] = list.get(i)[1];\r
+          }\r
+          return result;\r
 \r
 \r
-     @returns   ModuleSA objects list   if elements are found at the known xpath\r
-     @returns   Empty ModuleSA list     if nothing is there\r
-     **/\r
-    public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {\r
-        String[] xPath = new String[] { "/FrameworkModules/*/ModuleSA" };\r
+    }\r
 \r
 \r
-        XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
-        if (result != null) {\r
-            return (ModuleSADocument.ModuleSA[]) result;\r
+    public static XmlObject getFpdBuildOptions() {\r
+        String[] xPath = new String[] { "/BuildOptions" };\r
+\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
+\r
+        if (queryResult == null || queryResult.length == 0) {\r
+            return null;\r
         }\r
         }\r
-        return new ModuleSADocument.ModuleSA[0];\r
+        return (XmlObject)queryResult[0];\r
+    }\r
+\r
+    public static PlatformIdentification getFpdHeader() {\r
+        String[] xPath = new String[] { "/PlatformHeader" };\r
+\r
+        Object[] returns = get("PlatformSurfaceArea", xPath);\r
+\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+        PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];\r
+\r
+        String name = header.getPlatformName();\r
+\r
+        String guid = header.getGuidValue();\r
+\r
+        String version = header.getVersion();\r
+\r
+        return new PlatformIdentification(name, guid, version);\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve variables for FV images\r
+     * Retrieve FV image attributes information\r
+     * \r
+     * @param fvName\r
+     *            FV image name\r
+     * \r
+     * @returns attribute name/value list if elements are found at the known\r
+     *          xpath\r
+     * @returns empty list if nothing is there\r
+     */\r
+    public static String[][] getFpdAttributes(String fvName) {\r
+        String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"\r
+                         + fvName.toUpperCase() + "']/FvImageOptions" };\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
+        if (queryResult == null) {\r
+             return new String[0][];\r
+        }\r
+        ArrayList<String[]> list = new ArrayList<String[]>();\r
+        for (int i = 0; i < queryResult.length; i++) {\r
+            \r
+            FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];\r
+            List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();\r
+            Iterator iter = namevalues.iterator();\r
+            while (iter.hasNext()) {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter\r
+                 .next();\r
+                 list.add(new String[] { nvItem.getName(), nvItem.getValue() });\r
+            }\r
+        }\r
+       String[][] result = new String[list.size()][2];\r
+       for (int i = 0; i < list.size(); i++) {\r
+             result[i][0] = list.get(i)[0];\r
+             result[i][1] = list.get(i)[1];\r
+       }\r
+       return result;\r
+    }\r
+\r
+    /**\r
+     * Retrieve flash definition file name\r
+     * \r
+     * @returns file name if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String getFlashDefinitionFile() {\r
+        String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };\r
+\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
+        if (queryResult == null || queryResult.length == 0) {\r
+            return null;\r
+        }\r
+\r
+        FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];\r
+        return filename.getStringValue();\r
+    }\r
 \r
 \r
-     @returns   name/value list        if elements are found at the known xpath\r
-     @returns   empty list             if nothing is there\r
-     **/\r
     public static String[][] getFpdGlobalVariable() {\r
         String[] xPath = new String[] { "/Flash/FvImages/NameValue" };\r
     public static String[][] getFpdGlobalVariable() {\r
         String[] xPath = new String[] { "/Flash/FvImages/NameValue" };\r
-\r
-        XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
         if (queryResult == null) {\r
             return new String[0][];\r
         }\r
 \r
         String[][] result = new String[queryResult.length][2];\r
         if (queryResult == null) {\r
             return new String[0][];\r
         }\r
 \r
         String[][] result = new String[queryResult.length][2];\r
-        for (int i = 0; i < queryResult.length; i++){\r
-            result[i][0] = ((NameValueDocument.NameValue)queryResult[i]).getName();\r
-            result[i][1] = ((NameValueDocument.NameValue)queryResult[i]).getValue();\r
+        \r
+        for (int i = 0; i < queryResult.length; i++) {\r
+            FvImagesDocument.FvImages.NameValue item = (FvImagesDocument.FvImages.NameValue)queryResult[i];\r
+            result[i][0] = item.getName();\r
+            result[i][1] = item.getValue();\r
         }\r
         }\r
-\r
-        return result;\r
+        return result;   \r
     }\r
     \r
     /**\r
     }\r
     \r
     /**\r
-     Retrieve valid image names\r
-\r
-     @returns   valid iamges name list  if elements are found at the known xpath\r
-     @returns   empty list              if nothing is there\r
-     **/\r
-    public static String[] getFpdValidImageNames(){\r
-        String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };\r
-\r
-        XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
+     * Retrieve FV image component options\r
+     * \r
+     * @param fvName\r
+     *            FV image name\r
+     * \r
+     * @returns name/value pairs list if elements are found at the known xpath\r
+     * @returns empty list if nothing is there\r
+     */\r
+    public static String[][] getFpdComponents(String fvName) {\r
+        String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName.toUpperCase() + "']/FvImageOptions" };\r
+        Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
         if (queryResult == null) {\r
         if (queryResult == null) {\r
-            return new String[0];\r
+            return new String[0][];\r
         }\r
 \r
         }\r
 \r
-        String[] result = new String[queryResult.length];\r
-        for (int i = 0; i < queryResult.length; i++){\r
-            result[i] = ((XmlString)queryResult[i]).getStringValue();\r
+        ArrayList<String[]> list = new ArrayList<String[]>();\r
+        for (int i = 0; i < queryResult.length; i++) {\r
+        FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];\r
+        List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();\r
+        Iterator iter = namevalues.iterator();\r
+        while (iter.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter\r
+                        .next();\r
+                   list.add(new String[] { nvItem.getName(), nvItem.getValue() });\r
+                 }\r
+                }\r
+         String[][] result = new String[list.size()][2];\r
+                for (int i = 0; i < list.size(); i++) {\r
+               result[i][0] = list.get(i)[0];\r
+             result[i][1] = list.get(i)[1];\r
         }\r
         }\r
+            return result;  \r
+    }\r
 \r
 \r
-        return result;\r
+    /**\r
+     * Retrieve PCD tokens\r
+     * \r
+     * @returns CName/ItemType pairs list if elements are found at the known\r
+     *          xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String[][] getPcdTokenArray() {\r
+        String[] xPath = new String[] { "/PcdData" };\r
+\r
+        Object[] returns = get("PCDs", xPath);\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+\r
+        // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;\r
+        // String[][] result = new String[pcds.length][2];\r
+        // for (int i = 0; i < returns.length; ++i) {\r
+        // if (pcds[i].getItemType() != null) {\r
+        // result[i][1] = pcds[i].getItemType().toString();\r
+        // } else {\r
+        // result[i][1] = null;\r
+        // }\r
+        // result[i][0] = pcds[i].getCName();\r
+        // }\r
+\r
+        return null;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
-     Retrieve FV image option information\r
+     * Get the PcdToken array from module's surface area document. The array\r
+     * should contains following data:\r
+     * <p>\r
+     * -------------------------------------------------------------------\r
+     * </p>\r
+     * <p>\r
+     * CName | ItemType | TokenspaceName | DefaultValue | Usage | HelpText\r
+     * </p>\r
+     * <p>\r
+     * -------------------------------------------------------------------\r
+     * </p>\r
+     * <p>\r
+     * Note: Until new schema applying, now we can only get CName, ItemType,\r
+     * </p>\r
+     * \r
+     * @return 2-array table contains all information of PCD token retrieved\r
+     *         from MSA.\r
+     */\r
+    public static Object[][] etModulePCDTokenArray() {\r
+        return null;\r
+        // int index;\r
+        // Object[][] result;\r
+        // PCDs.PcdData[] pcds;\r
+        // String[] xPath = new String[] { "/PcdData" };\r
+        // Object[] returns = get("PCDs", xPath);\r
+        //\r
+        // if ((returns == null) || (returns.length == 0)) {\r
+        // return null;\r
+        // }\r
+        //\r
+        // pcds = (PCDs.PcdData[]) returns;\r
+        // result = new Object[pcds.length][6];\r
+        // for (index = 0; index < pcds.length; index++) {\r
+        // //\r
+        // // Get CName\r
+        // //\r
+        // result[index][0] = pcds[index].getCName();\r
+        // //\r
+        // // Get ItemType: FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODLE,\r
+        // // DYNAMIC, DYNAMIC_EX\r
+        // //\r
+        // if (pcds[index].getItemType() != null) {\r
+        // result[index][1] = pcds[index].getItemType().toString();\r
+        // } else {\r
+        // result[index][1] = null;\r
+        // }\r
+        //\r
+        // //\r
+        // // BUGBUG: following field can *not* be got from current MSA until\r
+        // // schema changed.\r
+        // //\r
+        // // result [index][2] = pcds[index].getTokenSpaceName();\r
+        // result[index][2] = null;\r
+        // result[index][3] = pcds[index].getDefaultValue();\r
+        // // result [index][4] = pcds[index].getUsage ();\r
+        // result[index][4] = null;\r
+        // // result [index][5] = pcds[index].getHelpText ();\r
+        // result[index][5] = null;\r
+        // }\r
+        // return result;\r
+    }\r
+\r
+    /**\r
+     * Retrieve MAS header\r
+     * \r
+     * @return\r
+     * @return\r
+     */\r
+    public static ModuleIdentification getMsaHeader() {\r
+        String[] xPath = new String[] { "/" };\r
+        Object[] returns = get("MsaHeader", xPath);\r
+\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
+        }\r
+\r
+        MsaHeader msaHeader = (MsaHeader) returns[0];\r
+        //\r
+        // Get BaseName, ModuleType, GuidValue, Version\r
+        // which in MsaHeader.\r
+        //\r
+        String name = msaHeader.getModuleName();\r
+        String moduleType = msaHeader.getModuleType().toString();\r
+        String guid = msaHeader.getGuidValue();\r
+        String version = msaHeader.getVersion();\r
 \r
 \r
-     @param fvName  FV image name\r
+        ModuleIdentification moduleId = new ModuleIdentification(name, guid,\r
+                version);\r
 \r
 \r
-     @returns   option name/value list if elements are found at the known xpath\r
-     @returns   empty list             if nothing is there\r
-     **/\r
-    public static String[][] getFpdOptions(String fvName){\r
-        String[] xPath = new String[] {"/Flash/FvImages/FvImageName[@Name='" + fvName.toUpperCase() + "']/FvImageOptions/NameValue" };\r
+        moduleId.setModuleType(moduleType);\r
+\r
+        return moduleId;\r
+    }\r
 \r
 \r
-        XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
+    /**\r
+     * Retrieve Extern Specification\r
+     * \r
+     * @param\r
+     * \r
+     * @return String[] If have specification element in the <extern> String[0]\r
+     *         If no specification element in the <extern>\r
+     * \r
+     */\r
+\r
+    public static String[] getExternSpecificaiton() {\r
+        String[] xPath = new String[] { "/Specification" };\r
+\r
+        Object[] queryResult = get("Externs", xPath);\r
         if (queryResult == null) {\r
         if (queryResult == null) {\r
-            return new String[0][];\r
+            return new String[0];\r
         }\r
 \r
         }\r
 \r
-        String[][] result = new String[queryResult.length][2];\r
-        for (int i = 0; i < queryResult.length; i++){\r
-            result[i][0] = ((NameValueDocument.NameValue)queryResult[i]).getName();\r
-            result[i][1] = ((NameValueDocument.NameValue)queryResult[i]).getValue();\r
+        String[] specificationList = new String[queryResult.length];\r
+        for (int i = 0; i < queryResult.length; i++) {\r
+            // specificationList[i] = ((SpecificationDocument.Specification)\r
+            // queryResult[i])\r
+            // .getStringValue();\r
         }\r
         }\r
+        return specificationList;\r
+    }\r
 \r
 \r
-        return result;\r
+    /**\r
+     * Retreive MsaFile which in SPD\r
+     * \r
+     * @param\r
+     * @return String[][3] The string sequence is ModuleName, ModuleGuid,\r
+     *         ModuleVersion, MsaFile String[0][] If no msafile in SPD\r
+     */\r
+    public static String[] getSpdMsaFile() {\r
+        String[] xPath = new String[] { "/MsaFiles" };\r
+\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
+        if (returns == null) {\r
+            return new String[0];\r
+        }\r
+\r
+        List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])\r
+                .getFilenameList();\r
+        return filenameList.toArray(new String[filenameList.size()]);\r
     }\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-     Retrieve FV image attributes information\r
+     * Reteive\r
+     */\r
+    public static Map<String, String[]> getSpdLibraryClasses() {\r
+        String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };\r
 \r
 \r
-     @param     fvName  FV image name\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
 \r
 \r
-     @returns   attribute name/value list   if elements are found at the known xpath\r
-     @returns   empty list                  if nothing is there\r
-     **/\r
-    public static String[][] getFpdAttributes(String fvName){\r
-        String[] xPath = new String[] {"/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='" + fvName.toUpperCase() + "']/FvImageOptions" };\r
+        //\r
+        // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.\r
+        //\r
+        Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();\r
 \r
 \r
-        XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
-        if (queryResult == null) {\r
-            return new String[0][];\r
+        if (returns == null) {\r
+            return libClassHeaderMap;\r
         }\r
 \r
         }\r
 \r
-        ArrayList<String[]> list = new ArrayList<String[]>();\r
-        for (int i = 0 ; i < queryResult.length; i++){\r
-            FvImageOptionsDocument.FvImageOptions item = (FvImageOptionsDocument.FvImageOptions)queryResult[i];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];\r
+            libClassHeaderMap.put(library.getName(), new String[] { library\r
+                    .getIncludeHeader() });\r
+        }\r
+        return libClassHeaderMap;\r
+    }\r
 \r
 \r
-            List<NameValueDocument.NameValue> namevalues = item.getNameValueList();\r
-            Iterator iter = namevalues.iterator();\r
-            while (iter.hasNext()) {\r
-                NameValueDocument.NameValue nvItem = (NameValueDocument.NameValue)iter.next();\r
-                list.add(new String[]{nvItem.getName(), nvItem.getValue()});\r
-            }\r
+    /**\r
+     * Reteive\r
+     */\r
+    public static Map<String, String> getSpdPackageHeaderFiles() {\r
+        String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };\r
 \r
 \r
-            List<String> enables = item.getEnableList();\r
-            iter = enables.iterator();\r
-            while (iter.hasNext()) {\r
-                String enableItem = (String)iter.next();\r
-                list.add(new String[]{enableItem, "TRUE"});\r
-            }\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
 \r
 \r
-            List<String> disables = item.getDisableList();\r
-            iter = disables.iterator();\r
-            while (iter.hasNext()) {\r
-                String disableItem = (String)iter.next();\r
-                list.add(new String[]{disableItem, "FALSE"});\r
-            }\r
+        //\r
+        // Create Map, Key - ModuleType, String - PackageInclude Header file.\r
+        //\r
+        Map<String, String> packageIncludeMap = new HashMap<String, String>();\r
+\r
+        if (returns == null) {\r
+            return packageIncludeMap;\r
         }\r
         }\r
+//        GlobalData.log.info("" + returns[0].getClass().getName());\r
+        for (int i = 0; i < returns.length; i++) {\r
+            PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];\r
+            packageIncludeMap.put(includeHeader.getModuleType().toString(),\r
+                    includeHeader.getStringValue());\r
+        }\r
+        return packageIncludeMap;\r
+    }\r
 \r
 \r
-        String[][] result = new String[list.size()][2];\r
-        for (int i = 0; i < list.size(); i++){\r
-            result[i][0] = list.get(i)[0];\r
-            result[i][1] = list.get(i)[1];\r
+    public static PackageIdentification getSpdHeader() {\r
+        String[] xPath = new String[] { "/SpdHeader" };\r
+\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
+\r
+        if (returns == null || returns.length == 0) {\r
+            return null;\r
         }\r
 \r
         }\r
 \r
-        return result;\r
+        SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];\r
+\r
+        String name = header.getPackageName();\r
+\r
+        String guid = header.getGuidValue();\r
+\r
+        String version = header.getVersion();\r
+\r
+        return new PackageIdentification(name, guid, version);\r
     }\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-     Retrieve flash definition file name\r
+     * Reteive\r
+     */\r
+    public static Map<String, String[]> getSpdGuid() {\r
+        String[] xPath = new String[] { "/GuidDeclarations/Entry" };\r
 \r
 \r
-     @returns   file name               if elements are found at the known xpath\r
-     @returns   null                    if nothing is there\r
-     **/\r
-    public static String getFlashDefinitionFile(){\r
-        String[] xPath = new String[] {"/Flash/FlashDefinitionFile" };\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
 \r
 \r
-        XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
-        if (queryResult == null || queryResult.length == 0) {\r
-            return null;\r
+        //\r
+        // Create Map, Key - GuidName, String[] - C_NAME & GUID value.\r
+        //\r
+        Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();\r
+        if (returns == null) {\r
+            return guidDeclMap;\r
         }\r
 \r
         }\r
 \r
-        FileNameConvention filename = (FileNameConvention)queryResult[queryResult.length - 1];\r
-        return filename.getStringValue();\r
+        for (int i = 0; i < returns.length; i++) {\r
+            GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];\r
+            String[] guidPair = new String[2];\r
+            guidPair[0] = entry.getCName();\r
+            guidPair[1] = entry.getGuidValue();\r
+            guidDeclMap.put(entry.getName(), guidPair);\r
+        }\r
+        return guidDeclMap;\r
     }\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-     Retrieve FV image component options\r
+     * Reteive\r
+     */\r
+    public static Map<String, String[]> getSpdProtocol() {\r
+        String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };\r
 \r
 \r
-     @param     fvName  FV image name\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
 \r
 \r
-     @returns   name/value pairs list   if elements are found at the known xpath\r
-     @returns   empty list              if nothing is there\r
-     **/\r
-    public static String[][] getFpdComponents(String fvName){\r
-        String[] xPath = new String[] {"/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='" + fvName.toUpperCase() + "']/FvImageOptions" };\r
+        //\r
+        // Create Map, Key - protocolName, String[] - C_NAME & GUID value.\r
+        //\r
+        Map<String, String[]> protoclMap = new HashMap<String, String[]>();\r
 \r
 \r
-        XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
-        if (queryResult == null) {\r
-            return new String[0][];\r
+        if (returns == null) {\r
+            return protoclMap;\r
         }\r
 \r
         }\r
 \r
-        ArrayList<String[]> list = new ArrayList<String[]>();\r
-        for (int i = 0 ; i < queryResult.length; i++){\r
-            FvImageOptionsDocument.FvImageOptions item = (FvImageOptionsDocument.FvImageOptions)queryResult[i];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];\r
+            String[] protocolPair = new String[2];\r
 \r
 \r
-            List<NameValueDocument.NameValue> namevalues = item.getNameValueList();\r
-            Iterator iter = namevalues.iterator();\r
-            while (iter.hasNext()) {\r
-                NameValueDocument.NameValue nvItem = (NameValueDocument.NameValue)iter.next();\r
-                list.add(new String[]{nvItem.getName(), nvItem.getValue()});\r
-            }\r
+            protocolPair[0] = entry.getCName();\r
+            protocolPair[1] = entry.getGuidValue();\r
+            protoclMap.put(entry.getName(), protocolPair);\r
+        }\r
+        return protoclMap;\r
+    }\r
 \r
 \r
-            List<String> enables = item.getEnableList();\r
-            iter = enables.iterator();\r
-            while (iter.hasNext()) {\r
-                String enableItem = (String)iter.next();\r
-                list.add(new String[]{enableItem, "TRUE"});\r
-            }\r
+    /**\r
+     * getSpdPpi() Retrieve the SPD PPI Entry\r
+     * \r
+     * @param\r
+     * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI\r
+     *         Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI\r
+     *         entry in SPD.\r
+     */\r
+    public static Map<String, String[]> getSpdPpi() {\r
+        String[] xPath = new String[] { "/PpiDeclarations/Entry" };\r
+\r
+        Object[] returns = get("PackageSurfaceArea", xPath);\r
+\r
+        //\r
+        // Create Map, Key - protocolName, String[] - C_NAME & GUID value.\r
+        //\r
+        Map<String, String[]> ppiMap = new HashMap<String, String[]>();\r
 \r
 \r
-            List<String> disables = item.getDisableList();\r
-            iter = disables.iterator();\r
-            while (iter.hasNext()) {\r
-                String disableItem = (String)iter.next();\r
-                list.add(new String[]{disableItem, "FALSE"});\r
-            }\r
+        if (returns == null) {\r
+            return ppiMap;\r
         }\r
 \r
         }\r
 \r
-        String[][] result = new String[list.size()][2];\r
-        for (int i = 0; i < list.size(); i++){\r
-            result[i][0] = list.get(i)[0];\r
-            result[i][1] = list.get(i)[1];\r
+        for (int i = 0; i < returns.length; i++) {\r
+            PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];\r
+            String[] ppiPair = new String[2];\r
+            ppiPair[0] = entry.getCName();\r
+            ppiPair[1] = entry.getGuidValue();\r
+            ppiMap.put(entry.getName(), ppiPair);\r
         }\r
         }\r
-\r
-        return result;\r
+        return ppiMap;\r
     }\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-       Get name array of PCD in a module. In one module, token space\r
-       is same, and token name should not be conflicted.\r
-       \r
-       @return String[]\r
-    **/\r
-    public static String[] getModulePcdEntryNameArray() {\r
-        PcdCoded.PcdEntry[] pcdEntries  = null;\r
-        String[]            results;\r
-        int                 index;\r
-        String[]            xPath       = new String[] {"/PcdEntry"};\r
-        XmlObject[]         returns     = get ("PcdCoded", xPath);\r
-        if (returns == null) {\r
+     * getToolChainFamily\r
+     * \r
+     * This function is to retrieve ToolChainFamily attribute of FPD\r
+     * <BuildOptions>\r
+     * \r
+     * @param\r
+     * @return toolChainFamily If find toolChainFamily attribute in\r
+     *         <BuildOptions> Null If don't have toolChainFamily in\r
+     *         <BuildOptions>.\r
+     */\r
+    public String getToolChainFamily() {\r
+        String toolChainFamily;\r
+        String[] xPath = new String[] { "/BuildOptions" };\r
+\r
+        Object[] result = get("PlatformSurfaceArea", xPath);\r
+        if (result == null) {\r
             return null;\r
         }\r
             return null;\r
         }\r
+        // toolChainFamily =\r
+        // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();\r
+        // return toolChainFamily;\r
+        return null;\r
+    }\r
 \r
 \r
-        pcdEntries = (PcdCoded.PcdEntry[])returns;\r
-        results    = new String[pcdEntries.length];\r
-        \r
-        for (index = 0; index < pcdEntries.length; index ++) {\r
-            results[index] = pcdEntries[index].getCName();\r
+    /**\r
+     * Retrieve module Guid string\r
+     * \r
+     * @returns GUILD string if elements are found at the known xpath\r
+     * @returns null if nothing is there\r
+     */\r
+    public static String getModuleGuid() {\r
+        String[] xPath = new String[] { "" };\r
+\r
+        Object[] returns = get("MsaHeader", xPath);\r
+        if (returns != null && returns.length > 0) {\r
+            String guid = ((MsaHeaderDocument.MsaHeader) returns[0])\r
+                    .getGuidValue();\r
+            return guid;\r
         }\r
         }\r
-        return results;\r
+\r
+        return null;\r
+    }\r
+\r
+    //\r
+    // For new Pcd\r
+    //\r
+    public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {\r
+        String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };\r
+        Object[] result = get("PlatformSurfaceArea", xPath);\r
+        if (result != null) {\r
+            return (ModuleSADocument.ModuleSA[]) result;\r
+        }\r
+        return new ModuleSADocument.ModuleSA[0];\r
+\r
     }\r
 }\r
     }\r
 }\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/FpdModuleIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/id/FpdModuleIdentification.java
new file mode 100644 (file)
index 0000000..add968f
--- /dev/null
@@ -0,0 +1,108 @@
+/** @file\r
+  Java class FpdModuleIdentification is used to present a module identification\r
+  from BaseName, GUID, Version, PackageName, and ARCH. \r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+package org.tianocore.build.id;\r
+\r
+\r
+/**\r
+  This class is used to identify a module with BaseName, GUID, Version, PackageName\r
+  and ARCH.\r
+  \r
+  @since GenBuild 1.0\r
+ **/\r
+public class FpdModuleIdentification {\r
+    \r
+    private String arch;\r
+    \r
+    private String fvBinding = "NULL"; // Optional\r
+    \r
+    private String sequence = "0"; // Optional\r
+    \r
+    private ModuleIdentification module;\r
+    \r
+    private String target; // Optional\r
+    \r
+    private String toolchain; // Optional\r
+    \r
+    public FpdModuleIdentification(String arch, String fvBinding, String sequence, ModuleIdentification module){\r
+        this.arch = arch;\r
+        this.fvBinding = fvBinding;\r
+        this.sequence = sequence;\r
+        this.module = module;\r
+    }\r
+    \r
+    public FpdModuleIdentification(ModuleIdentification module, String arch){\r
+        this.arch = arch;\r
+        this.module = module;\r
+    }\r
+    /**\r
+      Override java.lang.Object#equals. \r
+      \r
+      <p>Currently, use BaseName and ARCH to identify a module. It will enhance\r
+      in the next version. </p>\r
+      \r
+      @see java.lang.Object#equals(java.lang.Object)\r
+    **/\r
+    public boolean equals(Object obj) {\r
+        if (obj instanceof FpdModuleIdentification) {\r
+            FpdModuleIdentification moduleIdObj = (FpdModuleIdentification)obj;\r
+            if ( module.equals(moduleIdObj.module) && arch.equalsIgnoreCase(moduleIdObj.arch)) {\r
+                return true;\r
+            }\r
+            return false;\r
+        }\r
+        else {\r
+            return false;\r
+        }\r
+    }\r
+\r
+    public void setFvBinding(String fvBinding) {\r
+        this.fvBinding = fvBinding;\r
+    }\r
+\r
+    public void setSequence(String sequence) {\r
+        this.sequence = sequence;\r
+    }\r
+\r
+    public String toString(){\r
+        return arch + ":" + module;\r
+    }\r
+\r
+    public String getFvBinding() {\r
+        return fvBinding;\r
+    }\r
+\r
+    public String getSequence() {\r
+        return sequence;\r
+    }\r
+\r
+    public ModuleIdentification getModule() {\r
+        return module;\r
+    }\r
+\r
+    public void setModule(ModuleIdentification module) {\r
+        this.module = module;\r
+    }\r
+\r
+    public String getArch() {\r
+        return arch;\r
+    }\r
+\r
+    public void setArch(String arch) {\r
+        this.arch = arch;\r
+    }\r
+    \r
+    public int hashCode(){\r
+        return module.hashCode();\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/Identification.java b/Tools/Source/GenBuild/org/tianocore/build/id/Identification.java
new file mode 100644 (file)
index 0000000..abf5c1b
--- /dev/null
@@ -0,0 +1,74 @@
+package org.tianocore.build.id;\r
+\r
+import org.tianocore.build.global.GlobalData;\r
+\r
+public class Identification {\r
+\r
+    String name;\r
+    \r
+    String guid;\r
+    \r
+    String version;\r
+    \r
+    String type; // Optional\r
+    \r
+    Identification(String name, String guid, String version){\r
+        this.name = name;\r
+        this.guid = guid;\r
+        this.version = version;\r
+    }\r
+    \r
+    Identification(String guid, String version){\r
+        this.guid = guid;\r
+        this.version = version;\r
+    }\r
+    \r
+    public boolean equals(Object obj) {\r
+        if (obj instanceof Identification) {\r
+            Identification id = (Identification)obj;\r
+            if ( guid.equalsIgnoreCase(id.guid)) {\r
+                if (version == null || id.version == null) {\r
+                    return true;\r
+                }\r
+                else if (version.trim().equalsIgnoreCase("") || id.version.trim().equalsIgnoreCase("")){\r
+                    return true;\r
+                }\r
+                else if (version.equalsIgnoreCase(id.version)) {\r
+                    return true;\r
+                }\r
+            }\r
+            return false;\r
+        }\r
+        else {\r
+            return super.equals(obj);\r
+        }\r
+    }\r
+    \r
+    public void setName(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public void setGuid(String guid) {\r
+        this.guid = guid;\r
+    }\r
+\r
+    public void setVersion(String version) {\r
+        this.version = version;\r
+    }\r
+\r
+    public String getGuid() {\r
+        return guid;\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    public String getVersion() {\r
+        return version;\r
+    }\r
+    \r
+    public int hashCode(){\r
+        return guid.toLowerCase().hashCode();\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java
new file mode 100644 (file)
index 0000000..5681251
--- /dev/null
@@ -0,0 +1,124 @@
+package org.tianocore.build.id;\r
+\r
+import java.io.File;\r
+\r
+import org.tianocore.build.global.GlobalData;\r
+\r
+public class ModuleIdentification extends Identification {\r
+    \r
+    private PackageIdentification packageId;\r
+    \r
+    private File msaFile;\r
+    \r
+    private String moduleType;\r
+    \r
+    private boolean isLibrary = false;\r
+\r
+    public ModuleIdentification(String guid, String version){\r
+        super(guid, version);\r
+    }\r
+    \r
+    public ModuleIdentification(String guid, String version, PackageIdentification packageId){\r
+        super(guid, version);\r
+        this.packageId = packageId;\r
+    }\r
+    \r
+    public ModuleIdentification(String name, String guid, String version){\r
+        super(name, guid, version);\r
+    }\r
+    \r
+    public ModuleIdentification(String name, String guid, String version, PackageIdentification packageId){\r
+        super(name, guid, version);\r
+        this.packageId = packageId;\r
+    }\r
+    \r
+    public boolean isLibrary() {\r
+        return isLibrary;\r
+    }\r
+\r
+    public void setLibrary(boolean isLibrary) {\r
+        this.isLibrary = isLibrary;\r
+    }\r
+\r
+    public File getMsaFile() {\r
+        prepareMsaFile();\r
+        return msaFile;\r
+    }\r
+    \r
+    public String getModuleRelativePath() {\r
+        prepareMsaFile();\r
+        if (msaFile.getParent().length() == packageId.getPackageDir().length()) {\r
+            return ".";\r
+        }\r
+        return msaFile.getParent().substring(packageId.getPackageDir().length() + 1);\r
+    }\r
+\r
+    private void prepareMsaFile(){\r
+        if (msaFile == null) {\r
+            GlobalData.refreshModuleIdentification(this);\r
+        }\r
+    }\r
+\r
+    public void setMsaFile(File msaFile) {\r
+        this.msaFile = msaFile;\r
+    }\r
+   \r
+    public boolean equals(Object obj) {\r
+        if (obj instanceof ModuleIdentification) {\r
+            ModuleIdentification id = (ModuleIdentification)obj;\r
+            if (guid.equalsIgnoreCase(id.getGuid()) && packageId.equals(id.getPackage())) {\r
+                if (version == null || id.version == null) {\r
+                    return true;\r
+                }\r
+                else if (version.trim().equalsIgnoreCase("") || id.version.trim().equalsIgnoreCase("")){\r
+                    return true;\r
+                }\r
+                else if (version.equalsIgnoreCase(id.version)) {\r
+                    return true;\r
+                }\r
+            }\r
+            return false;\r
+        }\r
+        else {\r
+            return super.equals(obj);\r
+        }\r
+    }\r
+    \r
+    public String toString(){\r
+        if (name == null) {\r
+            GlobalData.refreshModuleIdentification(this);\r
+        }\r
+        if (version == null || version.trim().equalsIgnoreCase("")) {\r
+            return "Module [" + name + "] in " + packageId;\r
+        }\r
+        else {\r
+            return "Module [" + name + " " + version + "] in " + packageId; \r
+        }\r
+    }\r
+\r
+    public void setPackage(PackageIdentification packageId) {\r
+        this.packageId = packageId;\r
+    }\r
+\r
+    public PackageIdentification getPackage() {\r
+        return packageId;\r
+    }\r
+\r
+    public String getModuleType() {\r
+        if (moduleType == null) {\r
+            GlobalData.refreshModuleIdentification(this);\r
+        }\r
+        return moduleType;\r
+    }\r
+\r
+    public void setModuleType(String moduleType) {\r
+        this.moduleType = moduleType;\r
+    }\r
+    \r
+    public String getName() {\r
+        if (name == null) {\r
+            GlobalData.refreshModuleIdentification(this);\r
+        }\r
+        return name;\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java
new file mode 100644 (file)
index 0000000..8d4994d
--- /dev/null
@@ -0,0 +1,73 @@
+package org.tianocore.build.id;\r
+import java.io.File;\r
+\r
+import org.tianocore.build.global.GlobalData;\r
+\r
+public class PackageIdentification extends Identification{\r
+    \r
+    //\r
+    // It is optional\r
+    //\r
+    private File spdFile;\r
+    \r
+    public PackageIdentification(String guid, String version){\r
+        super(guid, version);\r
+    }\r
+    \r
+    public PackageIdentification(String name, String guid, String version){\r
+        super(name, guid, version);\r
+    }\r
+    \r
+    public PackageIdentification(String name, String guid, String version, String spdFilename){\r
+        super(name, guid, version);\r
+        this.spdFile = new File(spdFilename);\r
+    }\r
+    \r
+    public PackageIdentification(String name, String guid, String version, File spdFile){\r
+        super(name, guid, version);\r
+        this.spdFile = spdFile;\r
+    }\r
+    \r
+    public void setSpdFile(File spdFile) {\r
+        this.spdFile = spdFile;\r
+    }\r
+\r
+    public File getSpdFile() {\r
+        return spdFile;\r
+    }\r
+\r
+    public String toString(){\r
+        if (name == null) {\r
+            GlobalData.refreshPackageIdentification(this);\r
+        }\r
+        if (version == null || version.trim().equalsIgnoreCase("")) {\r
+            return "package [" + name + "]";\r
+        }\r
+        else {\r
+            return "package [" + name + " " + version + "]";\r
+        }\r
+    }\r
+    \r
+    public String getPackageDir(){\r
+        prepareSpdFile();\r
+        return spdFile.getParent();\r
+    }\r
+    \r
+    public String getPackageRelativeDir(){\r
+        prepareSpdFile();\r
+        return spdFile.getParent().substring(GlobalData.getWorkspacePath().length() + 1);\r
+    }\r
+    \r
+    private void prepareSpdFile(){\r
+        if (spdFile == null) {\r
+            GlobalData.refreshPackageIdentification(this);\r
+        }\r
+    }\r
+    \r
+    public String getName() {\r
+        if (name == null) {\r
+            GlobalData.refreshPackageIdentification(this);\r
+        }\r
+        return name;\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/PlatformIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/id/PlatformIdentification.java
new file mode 100644 (file)
index 0000000..8ee6cf0
--- /dev/null
@@ -0,0 +1,43 @@
+package org.tianocore.build.id;\r
+import java.io.File;\r
+\r
+import org.tianocore.build.global.GlobalData;\r
+\r
+public class PlatformIdentification extends Identification{\r
+    \r
+    private File fpdFile;\r
+    \r
+    public PlatformIdentification(String guid, String version){\r
+        super(guid, version);\r
+    }\r
+    \r
+    public PlatformIdentification(String name, String guid, String version){\r
+        super(name, guid, version);\r
+    }\r
+    \r
+    public PlatformIdentification(String name, String guid, String version, String fpdFilename){\r
+        super(name, guid, version);\r
+        this.fpdFile = new File(fpdFilename);\r
+    }\r
+    \r
+    public PlatformIdentification(String name, String guid, String version, File fpdFile){\r
+        super(name, guid, version);\r
+        this.fpdFile = fpdFile;\r
+    }\r
+    \r
+    public String toString(){\r
+        return "Platform " + name + "["+guid+"]";\r
+    }\r
+\r
+    public void setFpdFile(File fpdFile) {\r
+        this.fpdFile = fpdFile;\r
+    }\r
+\r
+    public File getFpdFile() {\r
+        return fpdFile;\r
+    }\r
+    \r
+    public String getPlatformRelativeDir(){\r
+        return fpdFile.getParent().substring(GlobalData.getWorkspacePath().length());\r
+    }\r
+}
\ No newline at end of file
index f48735966e80c609ad8bf848cf6c4b5636ff5fcc..0472265d399f0194b103a2745521ee8cee9100b2 100644 (file)
@@ -14,16 +14,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.toolchain;\r
 \r
 **/\r
 package org.tianocore.build.toolchain;\r
 \r
+import org.tianocore.build.exception.EdkException;\r
+\r
 import java.io.BufferedReader;\r
 import java.io.File;\r
 import java.io.FileReader;\r
 import java.io.BufferedReader;\r
 import java.io.File;\r
 import java.io.FileReader;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.Vector;\r
-\r
-import org.apache.tools.ant.BuildException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
 \r
 /**\r
   \r
 \r
 /**\r
   \r
@@ -36,6 +33,7 @@ public class ConfigReader {
 \r
     private static String confPath = ".";\r
 \r
 \r
     private static String confPath = ".";\r
 \r
+\r
     /**\r
       Public construct method. \r
     **/\r
     /**\r
       Public construct method. \r
     **/\r
@@ -48,7 +46,7 @@ public class ConfigReader {
       @param filename the config file name like "target.txt"\r
       @return the variables defined in file\r
     **/\r
       @param filename the config file name like "target.txt"\r
       @return the variables defined in file\r
     **/\r
-    public static synchronized String[][] parse(String filename) {\r
+    public static synchronized String[][] parse(String filename) throws EdkException {\r
         return parse(confPath, filename);\r
     }\r
 \r
         return parse(confPath, filename);\r
     }\r
 \r
@@ -62,157 +60,77 @@ public class ConfigReader {
       @throws BuildException\r
               Config file's format is not valid\r
     **/\r
       @throws BuildException\r
               Config file's format is not valid\r
     **/\r
-    public static synchronized String[][] parse(String confPath, String filename) throws BuildException {\r
+    public static synchronized String[][] parse(String confPath, String filename) throws EdkException {\r
+        //Map<String, String> map = new TreeMap<String,String>(comparator);\r
+        List<String> keyList = new ArrayList<String>(256);\r
+        List<String> valueList = new ArrayList<String>(256);\r
+\r
         try {\r
         try {\r
-            Map<String, String> map = new HashMap<String, String>(20);\r
             File file = new File(confPath + File.separatorChar + filename);\r
             FileReader reader = new FileReader(file);\r
             BufferedReader in = new BufferedReader(reader);\r
             String str;\r
             File file = new File(confPath + File.separatorChar + filename);\r
             FileReader reader = new FileReader(file);\r
             BufferedReader in = new BufferedReader(reader);\r
             String str;\r
+\r
             while ((str = in.readLine()) != null) {\r
                 str = str.trim();\r
                 //\r
             while ((str = in.readLine()) != null) {\r
                 str = str.trim();\r
                 //\r
-                // if str is empty line or comments (start with '#')\r
+                // if str is empty line, comments (start with '#'),\r
+                // without '=', or start with '='\r
                 //\r
                 //\r
-                if (str.equalsIgnoreCase("") || str.startsWith("#")) {\r
-                    continue;\r
-                }\r
-                //\r
-                // if str without '=' or start with '='\r
-                //\r
-                if (str.indexOf('=') <= 0) {\r
+                int index;\r
+                if (str.length() == 0 || str.startsWith("#") || \r
+                    (index = str.indexOf('=')) <= 0) {\r
                     continue;\r
                 }\r
                 //\r
                 // look as line "A = B"\r
                 //\r
                     continue;\r
                 }\r
                 //\r
                 // look as line "A = B"\r
                 //\r
-                int index = str.indexOf('=');\r
-                String key = str.substring(0, index).trim();\r
-                String value = str.substring(index + 1).trim();\r
-                //\r
-                // if key is existed, then update\r
-                //\r
-                if (map.containsKey(key)) {\r
-                    map.remove(key);\r
-                }\r
-                map.put(key, value);\r
+                keyList.add(str.substring(0, index).trim());\r
+                valueList.add(str.substring(index + 1).trim());\r
             }\r
             }\r
-            Set keyset = map.keySet();\r
-            Iterator iter = keyset.iterator();\r
-            String[][] result = new String[map.size()][2];\r
-            int i = 0;\r
-            while (iter.hasNext()) {\r
-                String key = (String) iter.next();\r
-                result[i][0] = key;\r
-                result[i++][1] = (String) map.get(key);\r
-            }\r
-            return result;\r
         } catch (Exception e) {\r
         } catch (Exception e) {\r
-            throw new BuildException("Processor file [" + filename + "] error. \n" + e.getMessage());\r
+            throw new EdkException("Process file [" + filename + "] error. \n" + e.getMessage());\r
         }\r
         }\r
+\r
+        String[][] definitions = new String[2][keyList.size()];\r
+        definitions[0] = (String[])keyList.toArray(definitions[0]);\r
+        definitions[1] = (String[])valueList.toArray(definitions[1]);\r
+\r
+        return definitions;\r
     }\r
 \r
     }\r
 \r
-    /**\r
-      Parse global flags table. The format is like such(global flag name, value, \r
-      vendor_arch_cmd, [add flags], [sub flags]): \r
-      \r
-      <pre>\r
-        # EFI_DEBUG\r
-        EFI_DEBUG YES MSFT_IA32_ASM    ADD.["/Zi", "/DEBUG"]\r
-        EFI_DEBUG YES MSFT_IA32_CC     ADD.["/Zi", "/Gm", "/D EFI_DEBUG"] SUB.["/nologo", "/WX"]\r
-        EFI_DEBUG YES MSFT_IA32_LINK   ADD.["/DEBUG"]\r
-        EFI_DEBUG YES MSFT_NT32_CC     ADD.["/DEBUG"]\r
-      </pre>\r
-     \r
-      @param confPath the file path of config file\r
-      @param filename the file name of config file\r
-      @return the value list\r
-      @throws BuildException\r
-              Config file is not valid\r
-    **/\r
-    public static synchronized String[][] parseTable(String confPath,\r
-                    String filename) throws BuildException {\r
+    public static synchronized ToolChainMap parseToolChainConfig(File ConfigFile) throws EdkException {\r
+        ToolChainMap map = new ToolChainMap();\r
+    \r
         try {\r
         try {\r
-            Vector<String[]> vector = new Vector<String[]>(20);\r
-            File file = new File(confPath + File.separatorChar + filename);\r
-            FileReader reader = new FileReader(file);\r
+            FileReader reader = new FileReader(ConfigFile);\r
             BufferedReader in = new BufferedReader(reader);\r
             String str;\r
             BufferedReader in = new BufferedReader(reader);\r
             String str;\r
+\r
             while ((str = in.readLine()) != null) {\r
                 str = str.trim();\r
                 //\r
             while ((str = in.readLine()) != null) {\r
                 str = str.trim();\r
                 //\r
-                // if str is empty line or comments (start with '#')\r
+                // if str is empty line, comments (start with '#'),\r
+                // without '=', or start with '='\r
                 //\r
                 //\r
-                if (str.equalsIgnoreCase("") || str.startsWith("#")) {\r
+                int index;\r
+                if (str.length() == 0 || str.startsWith("#") || \r
+                    (index = str.indexOf('=')) <= 0) {\r
                     continue;\r
                 }\r
                     continue;\r
                 }\r
-                String[] item = new String[5];\r
-                for(int i=0; i < item.length; i++){\r
-                    item[i] = "";\r
-                }\r
-                //\r
-                // EFI_DEBUG YES MSFT_IA32_ASM    ADD.["/Zi", "/DEBUG"]\r
-                // FLAGS: EFI_DEBUG\r
-                //\r
-                int index = str.indexOf(" ");\r
-                item[0] = str.substring(0, index);\r
-                str = str.substring(index + 1).trim();\r
-                //\r
-                // Setting: YES\r
                 //\r
                 //\r
-                index = str.indexOf(" ");\r
-                item[1] = str.substring(0, index);\r
-                str = str.substring(index + 1).trim();\r
-                //\r
-                // Vendor_Arch_Commandtype: MSFT_IA32_ASM\r
-                //\r
-                index = str.indexOf(" ");\r
-                item[2] = str.substring(0, index);\r
-                str = str.substring(index + 1).trim();\r
-                //\r
-                // Add or/and Sub\r
+                // look as line "A = B"\r
                 //\r
                 //\r
-                if (str.startsWith("ADD.")) {\r
-                    index = str.indexOf("]");\r
-                    if ( index > 0){\r
-                        item[3] = str.substring(5, index);\r
-                        str = str.substring(index + 1).trim();\r
-                    }\r
-                }\r
-                else if(str.startsWith("SUB.")){\r
-                    index = str.indexOf("]");\r
-                    if ( index > 0){\r
-                        item[4] = str.substring(5, index);\r
-                        str = str.substring(index + 1).trim();\r
-                    }\r
-                }\r
-                else {\r
-                    throw new BuildException("File [" + filename + "] never conform to Global Flags Table format.");\r
-                }\r
-                \r
-                if (str.startsWith("ADD.")) {\r
-                    index = str.indexOf("]");\r
-                    if ( index > 0){\r
-                        item[3] = str.substring(5, index);\r
-                        str = str.substring(index + 1).trim();\r
-                    }\r
-                }\r
-                else if(str.startsWith("SUB.")){\r
-                    index = str.indexOf("]");\r
-                    if ( index > 0){\r
-                        item[4] = str.substring(5, index);\r
-                        str = str.substring(index + 1).trim();\r
-                    }\r
-                }\r
-                vector.addElement(item);\r
-            }\r
-            String[][] result = new String[vector.size()][5];\r
-            for(int i=0; i < vector.size(); i++){\r
-                result[i] = (String[])vector.get(i);\r
+                String key = str.substring(0, index).trim().toUpperCase();\r
+                String value = str.substring(index + 1).trim();\r
+                map.put(key, value);\r
             }\r
             }\r
-            return result;\r
         } catch (Exception e) {\r
         } catch (Exception e) {\r
-            throw new BuildException("Processor file [" + filename + "] error. \n" + e.getMessage());\r
+            throw new EdkException("Process file [" + ConfigFile.getAbsolutePath() + "] error. \n" + e.getMessage());\r
         }\r
         }\r
+\r
+        return map;\r
     }\r
 }\r
     }\r
 }\r
+\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainAttribute.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainAttribute.java
new file mode 100644 (file)
index 0000000..7fa0bb3
--- /dev/null
@@ -0,0 +1,37 @@
+package org.tianocore.build.toolchain;\r
+/**\r
+* TODO: Add class description\r
+* \r
+* @author   jwang36\r
+*/\r
+public class ToolChainAttribute {\r
+    private static int nextValue = 0;\r
+\r
+    //"NAME", "PATH", "DPATH", "SPATH", "EXT", "FAMILY", "FLAGS"\r
+    public final static ToolChainAttribute NAME = new ToolChainAttribute("NAME");\r
+    public final static ToolChainAttribute PATH = new ToolChainAttribute("PATH");\r
+    public final static ToolChainAttribute DPATH = new ToolChainAttribute("DPATH");\r
+    public final static ToolChainAttribute SPATH = new ToolChainAttribute("SPATH");\r
+    public final static ToolChainAttribute EXT = new ToolChainAttribute("EXT");\r
+    public final static ToolChainAttribute FAMILY = new ToolChainAttribute("FAMILY");\r
+    public final static ToolChainAttribute FLAGS = new ToolChainAttribute("FLAGS");\r
+\r
+    private final String name;\r
+    public final int value = nextValue++;\r
+\r
+    /**\r
+     * Default constructor\r
+     */\r
+    private ToolChainAttribute(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public String toString() {\r
+        return name;\r
+    }\r
+}\r
+\r
+\r
+\r
+\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java
new file mode 100644 (file)
index 0000000..05d2124
--- /dev/null
@@ -0,0 +1,142 @@
+/** @file\r
+  ToolChainFactory class.\r
+  \r
+  ToolChainFactory class parse all config files and get STD_FLAGS, GLOBAL_FLAGS,\r
+  and also command path + name.\r
+  \r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+package org.tianocore.build.toolchain;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.build.toolchain.ToolChainKey;\r
+import org.tianocore.build.toolchain.ToolChainMap;\r
+\r
+import java.io.File;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
+\r
+\r
+/**\r
+  This class parse all config files and get STD_FLAGS, GLOBAL_FLAGS, and also \r
+  command path + name.\r
+  \r
+  @since GenBuild 1.0\r
+**/\r
+public class ToolChainConfig {\r
+    ///\r
+    /// list of attributes\r
+    ///\r
+    private final static String[] attributes = {"NAME", "PATH", "DPATH", "SPATH", "EXT", "FAMILY", "FLAGS"};\r
+    ///\r
+    /// elements which are used to define one type of tool\r
+    ///\r
+    private final static String[] elements = {"TARGET", "TOOLCHAIN", "ARCH", "CMD", "ATTRIBUTE" };\r
+\r
+    ///\r
+    /// tool chain definitions\r
+    ///\r
+    private ToolChainMap config = null;\r
+    private ToolChainInfo info = new ToolChainInfo();\r
+\r
+    /**\r
+      Public construct method.\r
+    **/\r
+    public ToolChainConfig () {\r
+    }\r
+\r
+    /**\r
+      Public construct method.\r
+      \r
+      @param confPath the path of config files\r
+      @param toolChainTag TOOL_CHAIN name\r
+    **/\r
+    public ToolChainConfig (File toolChainFile) {\r
+        try {\r
+            config = ConfigReader.parseToolChainConfig(toolChainFile);\r
+            parseToolChainDefKey(config.keySet());\r
+        }\r
+        catch (EdkException ex) {\r
+            throw new BuildException(ex.getMessage());\r
+        }\r
+    }\r
+\r
+    /// \r
+    /// \r
+    /// \r
+    public void parseToolChainDefKey (Set<ToolChainKey> toolChainDefKey) {\r
+        Iterator it = toolChainDefKey.iterator();\r
+        while (it.hasNext()) {\r
+            ToolChainKey key = (ToolChainKey)it.next();\r
+            String[] keySet = key.getKeySet();\r
+            info.addTargets(keySet[0]);\r
+            info.addTagnames(keySet[1]);\r
+            info.addArchs(keySet[2]);\r
+            info.addCommands(keySet[1], keySet[3]);\r
+        }\r
+    }\r
+\r
+/**\r
+     public Set<String> getTargets() {\r
+         return info.getTargets();\r
+     }\r
+\r
+     public Set<String> getTagnames() {\r
+         return info.getTagnames();\r
+     }\r
+\r
+     public Set<String> getArchs() {\r
+         return info.getArchs();\r
+     }\r
+\r
+     public Set<String> getCommands() {\r
+         return info.getCommands();\r
+     }\r
+\r
+     public String getValue(String key) {\r
+         return config.get(key);\r
+     }\r
+\r
+     public String getValue(String[] keySet) {\r
+         return config.get(keySet);\r
+     }\r
+\r
+     public String getValue(ToolChainKey key) {\r
+         return config.get(key);\r
+     }\r
+ **/\r
+\r
+    public ToolChainMap getConfig() {\r
+        return config;\r
+    }\r
+\r
+    public ToolChainInfo getConfigInfo() {\r
+        return info;\r
+    }\r
+\r
+    ///\r
+    /// override toString()\r
+    /// \r
+    public String toString() {\r
+        StringBuffer ts = new StringBuffer(10240);\r
+\r
+        Iterator it = config.keySet().iterator();\r
+        while (it.hasNext()) {\r
+            ToolChainKey key = (ToolChainKey)it.next();\r
+            ts.append(key.toString() + " = ");\r
+//            ts.append(config.get(key) + "\n");\r
+        }\r
+\r
+        return ts.toString();\r
+    }\r
+}\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainElement.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainElement.java
new file mode 100644 (file)
index 0000000..a383cc8
--- /dev/null
@@ -0,0 +1,35 @@
+package org.tianocore.build.toolchain;\r
+/**\r
+* TODO: Add class description\r
+* \r
+* @author   jwang36\r
+*/\r
+public class ToolChainElement {\r
+    private static int nextValue = 0;\r
+\r
+    //"NAME", "PATH", "DPATH", "SPATH", "EXT", "FAMILY", "FLAGS"\r
+    public final static ToolChainElement TARGET = new ToolChainElement("TARGET");\r
+    public final static ToolChainElement TOOLCHAIN = new ToolChainElement("TOOLCHAIN");\r
+    public final static ToolChainElement ARCH = new ToolChainElement("ARCH");\r
+    public final static ToolChainElement TOOLCODE = new ToolChainElement("TOOLCODE");\r
+    public final static ToolChainElement ATTRIBUTE = new ToolChainElement("ATTRIBUTE");\r
+\r
+    private final String name;\r
+    public final int value = nextValue++;\r
+\r
+    /**\r
+     * Default constructor\r
+     */\r
+    private ToolChainElement(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public String toString() {\r
+        return name;\r
+    }\r
+}\r
+\r
+\r
+\r
+\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainFactory.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainFactory.java
deleted file mode 100644 (file)
index ce8e93f..0000000
+++ /dev/null
@@ -1,529 +0,0 @@
-/** @file\r
-  ToolChainFactory class.\r
-  \r
-  ToolChainFactory class parse all config files and get STD_FLAGS, GLOBAL_FLAGS,\r
-  and also command path + name.\r
-  \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-package org.tianocore.build.toolchain;\r
-\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.StringTokenizer;\r
-import java.io.File;\r
-\r
-import org.apache.tools.ant.Project;\r
-\r
-\r
-/**\r
-  This class parse all config files and get STD_FLAGS, GLOBAL_FLAGS, and also \r
-  command path + name.\r
-  \r
-  @since GenBuild 1.0\r
-**/\r
-public class ToolChainFactory {\r
-    ///\r
-    /// list of Arch: EBC, ARM, IA32, X64, IPF, PPC\r
-    ///\r
-    public final static String[] arch = { "EBC", "ARM", "IA32", "X64", "IPF",\r
-                    "PPC"};\r
-\r
-    ///\r
-    /// list of OS: Linux, Windows\r
-    ///\r
-    public final static String[] os = { "WINDOWS", "LINUX" };\r
-\r
-    ///\r
-    /// list of Command Type: CC, LIB, LINK, ASL, ASM, ASMLINK, PP\r
-    ///\r
-    public final static String[] commandType = { "CC", "LIB", "LINK", "ASL",\r
-                    "ASM", "ASMLINK", "PP" };\r
-\r
-    ///\r
-    /// default command name for every command\r
-    ///\r
-    public final static String[][] defaultCmdName = { { "CC", "cl" },\r
-                    { "LIB", "lib" }, { "LINK", "link" }, { "ASL", "iasl" },\r
-                    { "ASM", "ml" }, { "ASMLINK", "link" }, { "PP", "cl" } };\r
-\r
-    private String confPath = ".";\r
-    \r
-    private String toolChainName = "MSFT";\r
-\r
-    private String sTargetFilename = "target.txt";\r
-\r
-    private String sToolsdefFilename = "tools_def.txt";\r
-\r
-    private String sWorkspaceTarget = "WORKSPACE_TARGET";\r
-\r
-    private String sTargetArch = "TARGET_ARCH";\r
-\r
-    private HashMap<String,String[][]> filesMap = new HashMap<String,String[][]>();\r
-    \r
-    private HashMap<String,String> globalFlagsMap = new HashMap<String,String>();\r
-    \r
-    private String[][] globalFlagTable;\r
-    \r
-    private String currentTarget = "RELEASE";\r
-\r
-    ///\r
-    /// toolchain array list all results by parsing config files\r
-    ///\r
-    public static String[][] toolchain = null;\r
-    \r
-    /**\r
-      Public construct method.\r
-    **/\r
-    public ToolChainFactory () {\r
-    }\r
-\r
-    /**\r
-      Public construct method.\r
-      \r
-      @param project current ANT Project.\r
-    **/\r
-    public ToolChainFactory (Project project) {\r
-        this.confPath = project.replaceProperties("${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "Conf");\r
-    }\r
-    \r
-    /**\r
-      Public construct method.\r
-      \r
-      @param confPath the path of config files\r
-      @param toolChainName TOOL_CHAIN name\r
-    **/\r
-    public ToolChainFactory (String confPath, String toolChainName) {\r
-        this.confPath = confPath;\r
-        //\r
-        // If set tool used the set one, otherwise use default one.\r
-        // toolChain used to define open tools define txt file.\r
-        //\r
-        if (toolChainName != null && toolChainName.length() > 0){\r
-            this.toolChainName = toolChainName;\r
-        }\r
-    }\r
-\r
-    /**\r
-      Parse all config files, following are the detail steps:\r
-      \r
-      <ul>\r
-        <li>Parse target.txt file. This file define the current build TARGET \r
-        and supported ARCH list. </li>\r
-        <li>Parse tools_def.txt file. This file define every command name, path\r
-        and vendor. </li>\r
-        <li>For every supported ARCH and Command Type, find out STD_FLAGS, \r
-        GLOBAL_ADD_FLAGS, GLOBAL_SUB_FLAGS. </li>\r
-      </ul>\r
-      \r
-      <p>Note that this method will be called only once during the whole build\r
-      process. </p>\r
-    **/\r
-    public void setupToolChain() {\r
-        if (toolchain != null) {\r
-            return ;\r
-        }\r
-        Map<String, String> map = new HashMap<String, String>(40);\r
-        //\r
-        // parse target.txt\r
-        //\r
-        String[][] target = ConfigReader.parse(confPath, sTargetFilename);\r
-        //\r
-        // get workspace_target and initialize global flags setting\r
-        //\r
-        currentTarget = getValue(sWorkspaceTarget, target);\r
-        parseGlobalSetting(currentTarget);\r
-        String[] archList = getArchs(getValue(sTargetArch, target));\r
-        \r
-        //\r
-        // If user write the ${toolChain}_Tools_Def.txt use this one,\r
-        // otherwise used "tools_def.txt" file.\r
-        //\r
-        File tempFile = new File (confPath + File.separator + toolChainName.toLowerCase() + "_tools_def.txt");\r
-        if (tempFile.exists()){\r
-            sToolsdefFilename = toolChainName.toLowerCase() + "_tools_def.txt";\r
-        }\r
-        \r
-        System.out.println("Tools definition file is: " + sToolsdefFilename);\r
-        //\r
-        // parse tools_def.txt\r
-        //\r
-        String[][] tools_def = ConfigReader.parse(confPath, sToolsdefFilename);\r
-        //\r
-        // for each arch find all command's path&name and flags\r
-        //\r
-        for (int i = 0; i < archList.length; i++) {\r
-            for (int j = 0; j < commandType.length; j++) {\r
-                //\r
-                // Path & Name\r
-                //\r
-                map.put(archList[i] + "_" + commandType[j], getAbsoluteCmdPath(\r
-                                archList[i], commandType[j], tools_def));\r
-                //\r
-                // Flags: CMD_STD_FLAGS + CMD_GLOBAL_FLAGS + CMD_PROJ_FLAGS\r
-                // ARCH_CMD_STD_FLAGS\r
-                //\r
-                map.put(archList[i] + "_" + commandType[j] + "_STD_FLAGS",\r
-                                getStdFlags(archList[i], commandType[j],\r
-                                                tools_def));\r
-                //\r
-                // Flags:ARCH_CMD_VENDOR or ARCH_VENDOR\r
-                //\r
-                map.put(archList[i]+ "_"+commandType[j]+"_VENDOR", getVendorFlag(archList[i],\r
-                        commandType[j], tools_def));\r
-                //\r
-                // ARCH_CMD_GLOBAL_FLAGS\r
-                //\r
-                String[] globalFlags = getGlobalFlags(archList[i], commandType[j],\r
-                                tools_def);\r
-                map.put(archList[i] + "_" + commandType[j] + "_GLOBAL_ADD_FLAGS",\r
-                                globalFlags[0]);\r
-                map.put(archList[i] + "_" + commandType[j] + "_GLOBAL_SUB_FLAGS",\r
-                                globalFlags[1]);\r
-                //\r
-                // ARCH_CMD_GLOBAL_FLAGS, default is "".\r
-                //\r
-                map.put(archList[i] + "_" + commandType[j] + "_PROJ_FLAGS", "");\r
-            }\r
-            map.put(archList[i]+"_VENDOR", getVendorFlag(archList[i], null, tools_def));\r
-        }\r
-        Set keyset = map.keySet();\r
-        Iterator iter = keyset.iterator();\r
-        String[][] result = new String[map.size()][2];\r
-        int i = 0;\r
-        while (iter.hasNext()) {\r
-            String key = (String) iter.next();\r
-            result[i][0] = key;\r
-            result[i++][1] = (String) map.get(key);\r
-        }\r
-        toolchain = result;\r
-    }\r
-\r
-    /**\r
-      Get the standard flags (STD_FLAGS) for specified arch and command type. \r
-      \r
-      <ul>\r
-        <li>Find out Vendor that cmd Command Type with arch ARCH used. The \r
-        search sequence is ARCH_CMD_VENDOR -> ARCH_VENDOR -> "MSFT". Here\r
-        we suppose default Vendor is MSFT.</li>\r
-        <li>Search ${Vendor}_tools.txt file, and get the corrsponding flags. \r
-        </li>\r
-      </ul>\r
-      \r
-      @param arch the ARCH\r
-      @param cmd the command type\r
-      @param map detail flags information of tools_def.txt\r
-      @return the standard flags of arch ARCH and cmd Command Type \r
-    **/\r
-    private String getStdFlags(String arch, String cmd, String[][] map) {\r
-        //\r
-        // first is to find out its Vendor in map\r
-        // ARCH_CMD_VENDOR -> ARCH_VENDOR -> "MSFT"\r
-        // Here we suppose default Vendor is MSFT.\r
-        //\r
-        String vendor = "MSFT";\r
-        String str;\r
-        if ((str = getValue(arch + "_" + cmd + "_VENDOR", map)) != null) {\r
-            vendor = str;\r
-        } else if ((str = getValue(arch + "_VENDOR", map)) != null) {\r
-            vendor = str;\r
-        }\r
-        //\r
-        // change to low letter\r
-        //\r
-        vendor = vendor.toLowerCase();\r
-        //\r
-        // parse the corresponding file and get arch_cmd value\r
-        //\r
-        String filename = vendor + "_tools.txt";\r
-        String[][] flagsMap;\r
-        if (filesMap.containsKey(filename)) {\r
-            flagsMap = (String[][]) filesMap.get(filename);\r
-        } else {\r
-            //\r
-            // read file and store in filesMap\r
-            //\r
-            flagsMap = ConfigReader.parse(confPath, vendor + "_tools.txt");\r
-            filesMap.put(filename, flagsMap);\r
-        }\r
-        if ((str = getValue(arch + "_" + cmd, flagsMap)) != null) {\r
-            return str;\r
-        }\r
-        return "";\r
-    }\r
-\r
-    /**\r
-      Get the global flags (GLOBAL_ADD_FLAGS & GLOBAL_SUB_FLAGS) for specified \r
-      arch and command type. \r
-      \r
-      <ul>\r
-        <li>Find out Vendor that cmd Command Type with arch ARCH used. The \r
-        search sequence is ARCH_CMD_VENDOR -> ARCH_VENDOR -> "MSFT". Here\r
-        we suppose default Vendor is MSFT.</li>\r
-        <li>Search efi_flags_table.txt file, and get the corrsponding flags. \r
-        </li>\r
-      </ul>\r
-      \r
-      @param arch the ARCH\r
-      @param cmd the command type\r
-      @param map detail flags information of tools_def.txt\r
-      @return two values, first is GLOBAL_ADD_FLAGS and another value is \r
-      GLOBAL_SUB_FLAGS\r
-    **/\r
-    private String[] getGlobalFlags(String arch, String cmd, String[][] map) {\r
-        String addStr = "";\r
-        String subStr = "";\r
-        //\r
-        // first is to find out its Vendor in map\r
-        // ARCH_CMD_VENDOR -> ARCH_VENDOR -> "MSFT"\r
-        // Here we suppose default Vendor is MSFT.\r
-        //\r
-        String vendor = "MSFT";\r
-        String str;\r
-        if ((str = getValue(arch + "_" + cmd + "_VENDOR", map)) != null) {\r
-            vendor = str;\r
-        } else if ((str = getValue(arch + "_VENDOR", map)) != null) {\r
-            vendor = str;\r
-        }\r
-        //\r
-        // parse global flags table\r
-        //\r
-        if (globalFlagTable == null) {\r
-            globalFlagTable =  ConfigReader.parseTable(confPath, "efi_flags_table.txt");\r
-        }\r
-        for (int i=0; i < globalFlagTable.length; i++){\r
-            String[] item = globalFlagTable[i];\r
-            if (item[2].equalsIgnoreCase(vendor + "_" + arch + "_" + cmd)){\r
-                //\r
-                // if item[0] == item[1] is existed in globalFlagsMap\r
-                //\r
-                if (globalFlagsMap.containsKey(item[0])){\r
-                    if( item[1].equalsIgnoreCase((String)globalFlagsMap.get(item[0]))){\r
-                        addStr += item[3] + " ";\r
-                        subStr += item[4] + " ";\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        \r
-        return new String[]{addStr, subStr};\r
-    }\r
-\r
-    /**\r
-      Find out command path and command name. \r
-      \r
-      <pre>\r
-        Command path searching sequence in tools_def.txt file:\r
-        Path: ARCH_CMD_PATH -> ARCH_PATH -> Set to "".\r
-        \r
-        Command name searching sequence in tools_def.txt file:\r
-        Name: ARCH_CMD_NAME -> CMD_NAME -> Default Value.\r
-      </pre>\r
-      \r
-      @param arch the ARCH\r
-      @param cmd the Command Type\r
-      @param map detail flags information of tools_def.txt\r
-      @return the absolute command path and name\r
-    **/\r
-    private String getAbsoluteCmdPath(String arch, String cmd, String[][] map) {\r
-        String path = "";\r
-        String name = "";\r
-        String str;\r
-        //\r
-        // find Path\r
-        //\r
-        if ((str = getValue(arch + "_" + cmd + "_PATH", map)) != null) {\r
-            path = str;\r
-        } else if ((str = getValue(arch + "_PATH", map)) != null) {\r
-            path = str;\r
-        }\r
-        //\r
-        // find Name\r
-        //\r
-        if ((str = getValue(arch + "_" + cmd + "_NAME", map)) != null) {\r
-            name = str;\r
-        } else if ((str = getValue(cmd + "_NAME", map)) != null) {\r
-            name = str;\r
-        } else {\r
-            name = getValue(cmd, defaultCmdName);\r
-        }\r
-        if (path.equalsIgnoreCase("")) {\r
-            return name;\r
-        }\r
-        return path + File.separatorChar + name;\r
-    }\r
-\r
-    /**\r
-      Find out all global flags value, such as EFI_DEBUG equal YES or NO. Here \r
-      are three type files: global_efi_flags.txt, ${TARGET}_efi_flags.txt, \r
-      my_efi_flags.txt. global_efi_flags.txt with the highest priority while \r
-      my_efi_flags.txt with the lowest priority. \r
-      \r
-      <p>All global flags value will store in <code>globalFlagsMap</code> for \r
-      getGlobalFlags using. </p> \r
-      \r
-      @param target current build TARGET value\r
-    **/\r
-    private void parseGlobalSetting(String target){\r
-        //\r
-        // parse global_efi_flags -> ${TARGET}_efi_flags -> my_efi_flags\r
-        // parse global_efi_flags\r
-        //\r
-        String[][] map = ConfigReader.parse(confPath, "global_efi_flags.txt");\r
-        for (int i = 0; i < map.length; i++){\r
-            if(globalFlagsMap.containsKey(map[i][0])){\r
-                globalFlagsMap.remove(map[i][0]);\r
-            }\r
-            globalFlagsMap.put(map[i][0], map[i][1]);\r
-        }\r
-        //\r
-        // parse ${TARGET}_efi_flags\r
-        //\r
-        map = ConfigReader.parse(confPath, target.toLowerCase() + "_efi_flags.txt");\r
-        for (int i = 0; i < map.length; i++){\r
-            if(globalFlagsMap.containsKey(map[i][0])){\r
-                globalFlagsMap.remove(map[i][0]);\r
-            }\r
-            globalFlagsMap.put(map[i][0], map[i][1]);\r
-        }\r
-        //\r
-        // parse my_efi_flags.txt\r
-        //\r
-        map = ConfigReader.parse(confPath, "my_efi_flags.txt");\r
-        for (int i = 0; i < map.length; i++){\r
-            if(globalFlagsMap.containsKey(map[i][0])){\r
-                globalFlagsMap.remove(map[i][0]);\r
-            }\r
-            globalFlagsMap.put(map[i][0], map[i][1]);\r
-        }\r
-    }\r
-    \r
-    /**\r
-      Find value with key from map. If not found, return null. \r
-      \r
-      <p>Note that default is case-insensitive</p>\r
-      \r
-      @param key key value\r
-      @param map mapping information\r
-      @return the related value of key\r
-    **/\r
-    private String getValue(String key, String[][] map) {\r
-        return getValue(key, map, false);\r
-    }\r
-\r
-    /**\r
-      Find value with key from map. If not found, return null. \r
-      \r
-      @param key key value\r
-      @param map mapping information\r
-      @param caseSensitive whether case sesitive or not\r
-      @return the related value of key\r
-    **/\r
-    private String getValue(String key, String[][] map, boolean caseSensitive) {\r
-        for (int i = 0; i < map.length; i++) {\r
-            if (caseSensitive) {\r
-                if (key.compareTo(map[i][0]) == 0) {\r
-                    return map[i][1];\r
-                }\r
-            } else {\r
-                if (key.compareToIgnoreCase(map[i][0]) == 0) {\r
-                    return map[i][1];\r
-                }\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-    /**\r
-      Find value with key from <code>toolchain</code>. If not found, return null. \r
-    \r
-      @param key key value\r
-      @return the related value of key\r
-    **/\r
-    public static String getValue(String key){\r
-        for (int i = 0; i < toolchain.length; i++) {\r
-            if (key.compareToIgnoreCase(toolchain[i][0]) == 0) {\r
-                return toolchain[i][1];\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-    \r
-    /**\r
-      Get Arch list from a string separated with comma. \r
-      \r
-      <pre>\r
-        For example:\r
-          If the arch string is "IA32, X64, EBC".\r
-          Then the result is {"IA32", "X64", "EBC"}. \r
-      </pre>\r
-    \r
-      @param arch string separated with comma\r
-      @return Arch list\r
-    **/\r
-    public String[] getArchs(String arch) {\r
-        if (arch == null) {\r
-            return new String[0];\r
-        }\r
-        StringTokenizer st = new StringTokenizer(arch, " \t,");\r
-        String[] archs = new String[st.countTokens()];\r
-        int i = 0;\r
-        while (st.hasMoreTokens()) {\r
-            archs[i++] = st.nextToken().toUpperCase();\r
-        }\r
-        return archs;\r
-    }\r
-\r
-    /**\r
-      Get current target value.\r
-    \r
-      @return current target value\r
-    **/\r
-    public String getCurrentTarget() {\r
-        return currentTarget;\r
-    }\r
-\r
-    /**\r
-      Find out Vendor that cmd Command Type with arch ARCH used. The \r
-      search sequence is ARCH_CMD_VENDOR -> ARCH_VENDOR -> "MSFT". Here\r
-      we suppose default Vendor is MSFT.\r
-      \r
-      @param arch the ARCH\r
-      @param cmd the Command Type\r
-      @param map detail flags information of tools_def.txt\r
-      @return the related vendor name\r
-    **/\r
-    public String getVendorFlag (String arch, String cmdType, String[][] map){\r
-        //\r
-        // ARCH_CMD_VENDOR -> ARCH_VENDOR -> "MSFT"\r
-        // Here we suppose default Vendor is MSFT.\r
-        //\r
-        String str;\r
-        String vendor = "";\r
-        if (cmdType != null){\r
-            if ((str = getValue(arch + "_" + cmdType + "_VENDOR", map)) != null) {\r
-                vendor = str; \r
-            }else {\r
-                vendor = "";\r
-            }\r
-        }else if (arch != null){\r
-            if ((str = getValue(arch + "_VENDOR", map)) != null) {\r
-                vendor = str; \r
-            }else {\r
-                vendor = "";\r
-            }\r
-        }\r
-        return vendor;\r
-    }\r
-    \r
-}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java
new file mode 100644 (file)
index 0000000..146f6e5
--- /dev/null
@@ -0,0 +1,219 @@
+package org.tianocore.build.toolchain;\r
+\r
+import java.util.HashMap;\r
+import java.util.LinkedHashSet;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+public class ToolChainInfo {\r
+\r
+    private Set<String> targets = new LinkedHashSet<String>();\r
+    \r
+    private Set<String> tagnames = new LinkedHashSet<String>();\r
+    \r
+    private Set<String> archs = new LinkedHashSet<String>();\r
+    \r
+    private Set<String> commands = new LinkedHashSet<String>();\r
+\r
+    private Map<String, Set<String>> commandMap = new HashMap<String, Set<String>>();\r
+    \r
+    public void addTargets(String targetList) {\r
+        //\r
+        // targetList some targets separated by space " "\r
+        //\r
+        if (targetList == null) {\r
+            targets.add("*");\r
+            return ;\r
+        }\r
+        addTargets(targetList.split(" "));\r
+    }\r
+    \r
+    public void addTargets(String[] targetArray) {\r
+        if (targetArray == null ) {\r
+            return ;\r
+        }\r
+        for (int i = 0; i < targetArray.length; i++) {\r
+            targets.add(targetArray[i]);\r
+        }\r
+    }\r
+    \r
+    public void addTargets(Set<String> targetSet) {\r
+        targets.addAll(targetSet);\r
+    }\r
+    \r
+    public void addTagnames(String tagnameList) {\r
+        //\r
+        // tagnameList some tagnames separated by space " "\r
+        //\r
+        if (tagnameList == null) {\r
+            tagnames.add("*");\r
+            return ;\r
+        }\r
+        addTagnames(tagnameList.split(" "));\r
+    }\r
+    \r
+    public void addTagnames(String[] tagnameArray) {\r
+        if (tagnameArray == null ) {\r
+            return ;\r
+        }\r
+        for (int i = 0; i < tagnameArray.length; i++) {\r
+            tagnames.add(tagnameArray[i]);\r
+        }\r
+    }\r
+    \r
+    public void addTagnames(Set<String> tagnameSet) {\r
+        tagnames.addAll(tagnameSet);\r
+    }\r
+    \r
+    public void addArchs(String archList) {\r
+        //\r
+        // archList some archs separated by space " "\r
+        //\r
+        if (archList == null) {\r
+            archs.add("*");\r
+            return ;\r
+        }\r
+        addArchs(archList.split(" "));\r
+    }\r
+    \r
+    public void addArchs(String[] archArray) {\r
+        if (archArray == null ) {\r
+            return ;\r
+        }\r
+        for (int i = 0; i < archArray.length; i++) {\r
+            archs.add(archArray[i]);\r
+        }\r
+    }\r
+    \r
+    public void addArchs(Set<String> archSet) {\r
+        archs.addAll(archSet);\r
+    }\r
+    \r
+    public void addCommands(String toolChain, String commandList) {\r
+        //\r
+        // archList some archs separated by space " "\r
+        //\r
+        if (commandList == null || commandList.length() == 0) {\r
+            return ;\r
+        }\r
+        addCommands(commandList.split(" "));\r
+    }\r
+    \r
+    public void addCommands(String[] commandArray) {\r
+        if (commandArray == null ) {\r
+            return ;\r
+        }\r
+        for (int i = 0; i < commandArray.length; i++) {\r
+            commands.add(commandArray[i]);\r
+        }\r
+    }\r
+    \r
+    public void addCommands(String toolChain, String[] commandArray) {\r
+        if (commandArray == null) {\r
+            return ;\r
+        }\r
+\r
+        Set<String> toolChainCommandSet = commandMap.get(toolChain);\r
+        if (toolChainCommandSet == null) {\r
+            toolChainCommandSet = new LinkedHashSet<String>();\r
+            commandMap.put(toolChain, toolChainCommandSet);\r
+        }\r
+        for (int i = 0; i < commandArray.length; i++) {\r
+            commands.add(commandArray[i]);\r
+            toolChainCommandSet.add(commandArray[i]);\r
+        }\r
+    }\r
+    \r
+    public void addCommands(String toolChain, Set<String> commandSet) {\r
+        if (commandSet == null) {\r
+            return;\r
+        }\r
+        Set<String> toolChainCommandSet = commandMap.get(toolChain);\r
+        if (toolChainCommandSet == null) {\r
+            toolChainCommandSet = new LinkedHashSet<String>();\r
+            commandMap.put(toolChain, toolChainCommandSet);\r
+        }\r
+        commands.addAll(commandSet);\r
+        toolChainCommandSet.addAll(commandSet);\r
+    }\r
+    \r
+    public ToolChainInfo union(ToolChainInfo info) {\r
+        ToolChainInfo result = new ToolChainInfo();\r
+        result.addTargets(union(this.targets, info.targets));\r
+        result.addTagnames(union(this.tagnames, info.tagnames));\r
+        result.addArchs(union(this.archs, info.archs));\r
+        //result.addCommands(union(this.getCommands(), info.getCommands()));\r
+        return result;\r
+    }\r
+    \r
+    public ToolChainInfo intersection(ToolChainInfo info) {\r
+//        System.out.println(this + "\n" + info);\r
+        ToolChainInfo result = new ToolChainInfo();\r
+        result.addTargets(intersection(this.targets, info.targets));\r
+        result.addTagnames(intersection(this.tagnames, info.tagnames));\r
+        result.addArchs(intersection(this.archs, info.archs));\r
+        // result.addCommands(union(this.commands, info.commands));\r
+//        System.out.println("result: " + result);\r
+        return result;\r
+    }\r
+    \r
+    private Set<String> union(Set<String> set1, Set<String> set2) {\r
+        Set<String> result = new LinkedHashSet<String>();\r
+        result.addAll(set1);\r
+        result.addAll(set2);\r
+        result.remove("*");\r
+        return result;\r
+    }\r
+    \r
+    private Set<String> intersection(Set<String> set1, Set<String> set2) {\r
+        Set<String> result = new LinkedHashSet<String>();\r
+        boolean set1HasWildcard = set1.contains("*");\r
+        boolean set2HasWildcard = set2.contains("*");\r
+\r
+        if (set1HasWildcard && set2HasWildcard) {\r
+            result.addAll(set1);\r
+            result.addAll(set2);\r
+        } else if (set1HasWildcard) {\r
+            result.addAll(set2);\r
+        } else if (set2HasWildcard) {\r
+            result.addAll(set1);\r
+        } else {\r
+            result.addAll(set1);\r
+            result.retainAll(set2);\r
+        }\r
+\r
+//        result.remove("*");\r
+        return result;\r
+    }\r
+    \r
+    public String[] getTargets() {\r
+        return (String[])targets.toArray(new String[targets.size()]);\r
+    }\r
+    \r
+    public String[] getTagnames() {\r
+        return (String[])tagnames.toArray(new String[tagnames.size()]);\r
+    }\r
+    \r
+    public String[] getArchs() {\r
+        return (String[])archs.toArray(new String[archs.size()]);\r
+    }\r
+\r
+    public String[] getCommands() {\r
+        return (String[])commands.toArray(new String[commands.size()]);\r
+    }\r
+\r
+    public Set<String> getCommands(String toolChain) {\r
+        return commandMap.get(toolChain);\r
+    }\r
+    \r
+    public String toString() {\r
+        return targets + "\n" + tagnames + "\n" + archs + "\n" + commands;\r
+    }\r
+    \r
+    public void normalize() {\r
+        targets.remove("*");\r
+        tagnames.remove("*");\r
+        archs.remove("*");\r
+        commands.remove("*");\r
+    }\r
+}\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainKey.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainKey.java
new file mode 100644 (file)
index 0000000..4804f15
--- /dev/null
@@ -0,0 +1,177 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  ToolChainKey.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+package org.tianocore.build.toolchain;\r
+\r
+import java.io.Serializable;\r
+import java.util.AbstractMap;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+\r
+import org.tianocore.build.exception.EdkException;\r
+\r
+public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {\r
+\r
+    private String delimiter = "_";\r
+\r
+    public final static int keyLength = 5;\r
+\r
+    private String[] keySet = null;\r
+\r
+    private String keyString = null;\r
+\r
+    private int hashValue = 0;\r
+\r
+    public ToolChainKey(String keyString, String delimiter) throws Exception {\r
+        setKey(keyString, delimiter);\r
+    }\r
+\r
+    public ToolChainKey(String keyString) throws EdkException {\r
+        setKey(keyString);\r
+    }\r
+\r
+    public ToolChainKey(String[] keySet) throws EdkException {\r
+        setKey(keySet);\r
+    }\r
+\r
+    public int hashCode() {\r
+        if (hashValue != 0) {\r
+            return hashValue;\r
+        }\r
+\r
+        for (int i = 0; i < keySet.length; ++i) {\r
+            char[] keyStringValue = new char[keySet[i].length()];\r
+            this.keySet[i].getChars(0, keyStringValue.length, keyStringValue, 0);\r
+\r
+            for (int j = 0; j < keyStringValue.length; ++j) {\r
+                hashValue = keyStringValue[j] + hashValue * 31;\r
+            }\r
+        }\r
+\r
+        return hashValue;\r
+    }\r
+\r
+    public int compareTo(ToolChainKey dstKey) {\r
+        String[] dstKeySet = dstKey.getKeySet();\r
+        int result = 0;\r
+        for (int i = 0; i < this.keyLength; ++i) {\r
+            result = this.keySet[i].compareToIgnoreCase(dstKeySet[i]);\r
+            if (result != 0) {\r
+                break;\r
+            }\r
+        }\r
+\r
+        return result;\r
+    }\r
+\r
+    public boolean equals(Object o) {\r
+        ToolChainKey dstKey = (ToolChainKey)o;\r
+        String[] dstKeySet = dstKey.getKeySet();\r
+\r
+        if (this == dstKey) {\r
+            return true;\r
+        }\r
+\r
+        if (dstKeySet.length != this.keyLength) {\r
+            return false;\r
+        }\r
+\r
+        for (int i = 0; i < this.keyLength; ++i) {\r
+            if (!this.keySet[i].equalsIgnoreCase(dstKeySet[i])) {\r
+                return false;\r
+            }\r
+        }\r
+\r
+        return true;\r
+    }\r
+\r
+    public void setKey(String[] keySet) throws EdkException {\r
+        if (keySet.length != this.keyLength) {\r
+            throw new EdkException("Invalid ToolChain key");\r
+        }\r
+\r
+        this.keySet = new String[this.keyLength];\r
+        System.arraycopy(keySet, 0, this.keySet, 0, this.keyLength);\r
+        for (int i = 0; i < this.keyLength; ++i) {\r
+            if (this.keySet[i] == null || this.keySet[i].length() == 0) {\r
+                this.keySet[i] = "*";\r
+            }\r
+        }\r
+        this.keyString = null;\r
+        this.hashValue = 0;\r
+    }\r
+\r
+    public void setKey(String keySetString, int index) throws EdkException {\r
+        if (index >= this.keyLength) {\r
+            throw new EdkException("Invalid ToolChain key index");\r
+        }\r
+\r
+        if (keySetString == null || keySetString.length() == 0) {\r
+            keySetString = "*";\r
+        }\r
+        this.keySet[index] = keySetString;\r
+        this.keyString = null;\r
+        this.hashValue = 0;\r
+    }\r
+\r
+    public void setKey(String keyString) throws EdkException {\r
+        this.keySet = keyString.split(this.delimiter);\r
+\r
+        if (this.keySet.length != this.keyLength) {\r
+            throw new EdkException("Invalid ToolChain key");\r
+        }\r
+\r
+        this.keyString = keyString;\r
+        this.hashValue = 0;\r
+    }\r
+\r
+    public void setKey(String keyString, String delimiter) throws Exception {\r
+        this.keySet = keyString.split(delimiter);\r
+\r
+        if (this.keySet.length != this.keyLength) {\r
+            throw new Exception("Invalid ToolChain key");\r
+        }\r
+\r
+        this.keyString = keyString;\r
+        this.delimiter = delimiter;\r
+        this.hashValue = 0;\r
+    }\r
+\r
+    public String[] getKeySet() {\r
+        return keySet;\r
+    }\r
+\r
+    public String toString() {\r
+        if (this.keyString == null) {\r
+            StringBuffer keyStringBuf = new StringBuffer(64);\r
+            int i = 0;\r
+\r
+            keyStringBuf.append(this.keySet[i++]);\r
+            for (; i < this.keyLength; ++i) {\r
+                keyStringBuf.append(this.delimiter);\r
+                keyStringBuf.append(this.keySet[i]);\r
+            }\r
+\r
+            this.keyString = keyStringBuf.toString();\r
+        }\r
+\r
+        return this.keyString;\r
+    }\r
+}\r
+\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java
new file mode 100644 (file)
index 0000000..da34e7e
--- /dev/null
@@ -0,0 +1,165 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  ToolChainMap.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+package org.tianocore.build.toolchain;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.tianocore.build.exception.EdkException;\r
+\r
+public class ToolChainMap {\r
+\r
+    private int matchLevel = ToolChainKey.keyLength - 2;\r
+\r
+    private Map<ToolChainKey, String> map = null;\r
+\r
+    public ToolChainMap() {\r
+        //this.map = new TreeMap<ToolChainKey, String>();\r
+        this.map = new HashMap<ToolChainKey, String>();\r
+    }\r
+\r
+    public String put(String key, String delimiter, String value)throws EdkException {\r
+        ToolChainKey toolChainKey;\r
+\r
+        try {\r
+            toolChainKey = new ToolChainKey(key, delimiter);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+        return (String)map.put(toolChainKey, value);\r
+    }\r
+\r
+    public String put(String key, String value) throws EdkException {\r
+        ToolChainKey toolChainKey;\r
+\r
+        try {\r
+            toolChainKey = new ToolChainKey(key);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+        return (String)map.put(toolChainKey, value);\r
+    }\r
+\r
+    public String put(String[] key, String value) throws EdkException {\r
+        ToolChainKey toolChainKey;\r
+\r
+        try {\r
+            toolChainKey = new ToolChainKey(key);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+        return (String)map.put(toolChainKey, value);\r
+    }\r
+\r
+    public String put(ToolChainKey key, String value) {\r
+        return (String)map.put(key, value);\r
+    }\r
+\r
+    public String get(String key) throws EdkException {\r
+        ToolChainKey toolChainKey;\r
+\r
+        try {\r
+            toolChainKey = new ToolChainKey(key);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+        return get(toolChainKey);\r
+    }\r
+\r
+    public String get(String key, String delimiter) throws EdkException {\r
+        ToolChainKey toolChainKey;\r
+\r
+        try {\r
+            toolChainKey = new ToolChainKey(key, delimiter);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+        return get(toolChainKey);\r
+    }\r
+\r
+    public String get(String[] key)  throws EdkException {\r
+        ToolChainKey toolChainKey;\r
+\r
+        try {\r
+            toolChainKey = new ToolChainKey(key);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+        return get(toolChainKey);\r
+    }\r
+\r
+    public String get(ToolChainKey key)  throws EdkException {\r
+        String result = map.get(key);\r
+        if (result != null || map.containsKey(key)) {\r
+            return result;\r
+        }\r
+\r
+        String[] keySet = key.getKeySet();\r
+        ToolChainKey tmpKey;\r
+        try {\r
+            tmpKey = new ToolChainKey(keySet);\r
+        } catch (Exception e) {\r
+            throw new EdkException(e.getMessage());\r
+        }\r
+\r
+        int level = matchLevel;\r
+        while (level >= 0) {\r
+            int tmpLevel = level;\r
+            while (tmpLevel >= level) {\r
+                String[] tmpKeySet = tmpKey.getKeySet();\r
+                try {\r
+                    if (!tmpKeySet[tmpLevel].equals("*")) {\r
+                        tmpKey.setKey("*", tmpLevel);\r
+                        tmpLevel = matchLevel;\r
+                    } else {\r
+                        tmpKey.setKey(keySet[tmpLevel], tmpLevel);\r
+                        --tmpLevel;\r
+                        continue;\r
+                    }\r
+                } catch (Exception e) {\r
+                    throw new EdkException(e.getMessage());\r
+                }\r
+\r
+                result = map.get(tmpKey);\r
+                if (result != null) {\r
+                    map.put(key, result);\r
+                    return result;\r
+                }\r
+            }\r
+            --level;\r
+        }\r
+\r
+        map.put(key, result);\r
+        return result;\r
+    }\r
+\r
+    public int size() {\r
+        return map.size();\r
+    }\r
+\r
+    public Set<ToolChainKey> keySet() {\r
+        return (Set<ToolChainKey>)map.keySet();\r
+    }\r
+    \r
+//    public String toString() {\r
+//        return map.toString();\r
+//    }\r
+}\r
+\r
index 04dab1c3e37be35c88651ee66700d9d7f0de888e..4b0577bea3aa0302b1b59fcecd34c0372bfdd722 100644 (file)
@@ -15,6 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.toolchain;\r
 \r
 **/\r
 package org.tianocore.build.toolchain;\r
 \r
+import java.io.File;\r
+\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Task;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Task;\r
 \r
@@ -25,7 +27,13 @@ import org.apache.tools.ant.Task;
   @since GenBuild 1.0\r
 **/\r
 public class ToolChainTask extends Task{\r
   @since GenBuild 1.0\r
 **/\r
 public class ToolChainTask extends Task{\r
-\r
+    ///\r
+    /// environment variable name of toolchain\r
+    ///\r
+    static private String toolsEnv = "env.TOOLS_DEF";\r
+    ///\r
+    /// configuration file path\r
+    ///\r
     private String confPath = ".";\r
     \r
     /**\r
     private String confPath = ".";\r
     \r
     /**\r
@@ -43,10 +51,9 @@ public class ToolChainTask extends Task{
               Config files are invalid.\r
     **/\r
     public void execute() throws BuildException {\r
               Config files are invalid.\r
     **/\r
     public void execute() throws BuildException {\r
-        String toolChain = getProject().getProperty("env.TOOL_CHAIN");\r
-        ToolChainFactory toolchain = new ToolChainFactory(confPath, toolChain);\r
-        toolchain.setupToolChain();\r
-        getProject().setProperty("TARGET", toolchain.getCurrentTarget());\r
+        String toolChain = getProject().getProperty(toolsEnv);\r
+//        ToolChainConfig toolchain = new ToolChainConfig(new File(confPath + File.separatorChar + toolChain));\r
+        //getProject().setProperty("TARGET", toolchain.getCurrentTarget());\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r