]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Change to new XML Schema.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / Spd.java
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