]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Fixed EDKT147, which will fail the single module build when a module is just defined...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index 3147a245389169fe68761915beac6b1d9a5c3b07..366e0ac59d98de60400444fce8d63ceff549e82a 100644 (file)
 \r
 package org.tianocore.build.autogen;\r
 \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.build.pcd.action.PCDAutoGenAction;\r
-import org.tianocore.build.exception.*;\r
-import org.tianocore.logger.EdkLog;\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.xmlbeans.XmlObject;\r
-\r
 import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\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.LinkedHashSet;\r
 import java.util.LinkedList;\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.GuidsDocument;\r
+import org.tianocore.LibraryClassDocument.LibraryClass;\r
+import org.tianocore.PPIsDocument;\r
+import org.tianocore.ProtocolsDocument;\r
+import org.tianocore.build.exception.*;\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.build.pcd.action.PCDAutoGenAction;\r
+import org.tianocore.logger.EdkLog;\r
+\r
 /**\r
  * This class is to generate Autogen.h and Autogen.c according to module surface\r
  * area or library surface area.\r
@@ -52,7 +55,10 @@ public class AutoGen {
        // / The output path of Autogen.h and Autogen.c\r
        // /\r
        private String outputPath;\r
-\r
+    /// \r
+    /// The name of FV directory \r
+    /// \r
+    private String fvDir;\r
        // /\r
        // / The base name of module or library.\r
        // /\r
@@ -104,10 +110,11 @@ public class AutoGen {
         * @param arch\r
         *            Target architecture.\r
         */\r
-       public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {\r
+       public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch) {\r
                this.outputPath = outputPath;\r
                this.moduleId = moduleId;\r
                this.arch = arch;\r
+        this.fvDir = fvDir;\r
 \r
        }\r
 \r
@@ -251,10 +258,8 @@ public class AutoGen {
                // Add #ifndef ${BaseName}_AUTOGENH\r
                // #def ${BseeName}_AUTOGENH\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
+               fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n");\r
+               fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n\r\n");\r
 \r
                //\r
                // Write the specification version and release version at the begine\r
@@ -264,29 +269,6 @@ public class AutoGen {
                // moduleType.\r
                //\r
                moduleType = SurfaceAreaQuery.getModuleType();\r
-//             switch (CommonDefinition.getModuleType(moduleType)) {\r
-//             case CommonDefinition.ModuleTypeDxeCore:\r
-//             case CommonDefinition.ModuleTypeDxeDriver:\r
-//             case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-//             case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-//             case CommonDefinition.ModuleTypeDxeSalDriver:\r
-//             case CommonDefinition.ModuleTypeUefiDriver:\r
-//             case CommonDefinition.ModuleTypeUefiApplication:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-//                     break;\r
-//             default:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHVersionDefault);\r
-//                     break;\r
-//             }\r
-//             switch (CommonDefinition.getModuleType(moduleType)) {\r
-//             case CommonDefinition.ModuleTypeUefiDriver:\r
-//             case CommonDefinition.ModuleTypeUefiApplication:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHReleaseDefault);\r
-//                     break;\r
-//             default:\r
-//                     fileBuffer.append(CommonDefinition.autoGenHLine2);\r
-//                     break;\r
-//             }\r
 \r
                //\r
                // Add "extern int __make_me_compile_correctly;" at begin of\r
@@ -308,7 +290,7 @@ public class AutoGen {
                // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
                // .getDependencePkg(this.arch);\r
                PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
-                               .getDependencePkg(null);\r
+                               .getDependencePkg(this.arch);\r
                if (consumedPkgIdList != null) {\r
                        headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
                        item = headerFileList.iterator();\r
@@ -321,7 +303,7 @@ public class AutoGen {
                // Write library class's related *.h file to autogen.h.\r
                //\r
                String[] libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysConsumed,this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -331,7 +313,7 @@ public class AutoGen {
                }\r
 \r
                libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -341,7 +323,17 @@ public class AutoGen {
                }\r
                fileBuffer.append("\r\n");\r
 \r
-               //\r
+        //\r
+        //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to \r
+        // {DEST_DIR_DRBUG}/FlashMap.h\r
+        // \r
+        if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) {\r
+            fileBuffer.append(CommonDefinition.include);\r
+            fileBuffer.append("  <");\r
+            fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n");\r
+            copyFlashMapHToDebugDir();\r
+        }\r
+\r
                // Write PCD autogen information to AutoGen.h.\r
                //\r
                if (this.myPcdAutogen != null) {\r
@@ -516,10 +508,8 @@ public class AutoGen {
                // Add #ifndef ${BaseName}_AUTOGENH\r
                // #def ${BseeName}_AUTOGENH\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
+               fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n");\r
+               fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n\r\n");\r
 \r
                //\r
                // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
@@ -551,7 +541,7 @@ public class AutoGen {
                // Write library class's related *.h file to autogen.h\r
                //\r
                String[] libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysConsumed, this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -561,7 +551,7 @@ public class AutoGen {
                }\r
 \r
                libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
+                               .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
                if (libClassList != null) {\r
                        libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
                        item = libClassIncludeH.iterator();\r
@@ -571,6 +561,17 @@ public class AutoGen {
                }\r
                fileBuffer.append("\r\n");\r
 \r
+        //\r
+        //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to \r
+        // {DEST_DIR_DRBUG}/FlashMap.h\r
+        // \r
+        if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) {\r
+            fileBuffer.append(CommonDefinition.include);\r
+            fileBuffer.append("  <");\r
+            fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n");\r
+            copyFlashMapHToDebugDir();\r
+        }\r
+\r
                //\r
                // Write PCD information to library AutoGen.h.\r
                //\r
@@ -659,7 +660,7 @@ public class AutoGen {
         */\r
        Set<String> LibraryClassToAutogenH(String[] libClassList)\r
                        throws AutoGenException {\r
-               Set<String> includStrList = new HashSet<String>();\r
+               Set<String> includStrList = new LinkedHashSet<String>();\r
                String includerName[];\r
                String str = "";\r
 \r
@@ -891,21 +892,17 @@ public class AutoGen {
                                fileBuffer.append("{\r\n");\r
                                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
                                fileBuffer.append("}\r\n\r\n");\r
-                               break;\r
+\r
                        } else {\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.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                        fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                        fileBuffer.append("  );\r\n");\r
-                        entryPointCount++;\r
-                    } else {\r
-                        break;\r
-                    }\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.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                    fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
                 }\r
                 fileBuffer\r
                         .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
@@ -962,27 +959,24 @@ public class AutoGen {
             entryPointList = CommonDefinition.remDupString(entryPointList);\r
                        entryPointCount = 0;\r
 \r
-                       fileBuffer\r
-                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-                       fileBuffer.append(Integer.toString(entryPointCount));\r
-                       fileBuffer.append(";\r\n\r\n");\r
-\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("  IN EFI_HANDLE        ImageHandle\r\n");\r
-                                               fileBuffer.append("  );\r\n");\r
-                                       } else {\r
-                                               break;\r
-                                       }\r
-                               }\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("  IN EFI_HANDLE        ImageHandle\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
+                }\r
                        }\r
 \r
+            fileBuffer\r
+                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
+                       fileBuffer.append(Integer.toString(entryPointCount));\r
+                       fileBuffer.append(";\r\n\r\n");\r
+\r
                        fileBuffer.append("EFI_STATUS\r\n");\r
                        fileBuffer.append("EFIAPI\r\n");\r
                        fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
@@ -1135,18 +1129,14 @@ public class AutoGen {
                        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("  IN EFI_HANDLE        ImageHandle\r\n");\r
-                                               fileBuffer.append("  );\r\n");\r
-                                               entryPointCount++;\r
-                                       } else {\r
-                                               break;\r
-                                       }\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("  IN EFI_HANDLE        ImageHandle\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
                                }\r
                        }\r
 \r
@@ -1155,22 +1145,6 @@ public class AutoGen {
                        fileBuffer.append(Integer.toString(entryPointCount));\r
                        fileBuffer.append(";\r\n\r\n");\r
 \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("  IN EFI_HANDLE        ImageHandle\r\n");\r
-                                               fileBuffer.append("  );\r\n");\r
-                                       } else {\r
-                                               break;\r
-                                       }\r
-                               }\r
-                       }\r
-\r
                        fileBuffer.append("EFI_STATUS\n");\r
                        fileBuffer.append("EFIAPI\r\n");\r
                        fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
@@ -1531,6 +1505,7 @@ public class AutoGen {
                        switch (CommonDefinition.getModuleType(moduleType)) {\r
                        case CommonDefinition.ModuleTypeBase:\r
                                fileBuffer.append("RETURN_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  VOID\r\n");\r
@@ -1540,6 +1515,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypePeiCore:\r
                        case CommonDefinition.ModuleTypePeim:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer\r
@@ -1557,6 +1533,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypeUefiDriver:\r
                        case CommonDefinition.ModuleTypeUefiApplication:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1570,6 +1547,7 @@ public class AutoGen {
                // Add ProcessLibraryConstructorList in AutoGen.c\r
                //\r
                fileBuffer.append("VOID\r\n");\r
+               fileBuffer.append("EFIAPI\r\n");\r
                fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
                switch (CommonDefinition.getModuleType(moduleType)) {\r
                case CommonDefinition.ModuleTypeBase:\r
@@ -1662,7 +1640,8 @@ public class AutoGen {
                for (int i = 0; i < libInstanceList.size(); i++) {\r
                        switch (CommonDefinition.getModuleType(moduleType)) {\r
                        case CommonDefinition.ModuleTypeBase:\r
-                               fileBuffer.append("RETURN_STATUS\n");\r
+                               fileBuffer.append("RETURN_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  VOID\r\n");\r
@@ -1671,6 +1650,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypePeiCore:\r
                        case CommonDefinition.ModuleTypePeim:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer\r
@@ -1687,6 +1667,7 @@ public class AutoGen {
                        case CommonDefinition.ModuleTypeUefiDriver:\r
                        case CommonDefinition.ModuleTypeUefiApplication:\r
                                fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
                                fileBuffer.append(libInstanceList.get(i));\r
                                fileBuffer.append(" (\r\n");\r
                                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1712,6 +1693,7 @@ public class AutoGen {
                case CommonDefinition.ModuleTypeUefiDriver:\r
                case CommonDefinition.ModuleTypeUefiApplication:\r
                        fileBuffer.append("VOID\r\n");\r
+                       fileBuffer.append("EFIAPI\r\n");\r
                        fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
                        fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
                        fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
@@ -1822,7 +1804,7 @@ public class AutoGen {
                if (compDiagList != null && compDiagList.length != 0) {\r
                        if (drvBindList.length != compDiagList.length) {\r
                                throw new BuildException(\r
-                                               "Different number of Driver Binding and Driver Configuration protocols!");\r
+                                               "Different number of Driver Binding and Driver Diagnosis protocols!");\r
                        }\r
 \r
                        BitMask |= 0x04;\r
@@ -2017,14 +1999,12 @@ public class AutoGen {
                        //\r
                        Count = 0;\r
                        if (exitBootList != null) {\r
-                               if (setVirtualList != null) {\r
-                                       for (i = 0; i < exitBootList.length; i++) {\r
-                                               if (exitBootList[i].equalsIgnoreCase("")) {\r
-                                                       break;\r
-                                               }\r
+                               for (i = 0; i < exitBootList.length; i++) {\r
+                                       if (exitBootList[i].equalsIgnoreCase("")) {\r
+                                               break;\r
                                        }\r
-                                       Count = i;\r
                                }\r
+                               Count = i;\r
                        }\r
                        fileBuffer.append(Integer.toString(Count));\r
                        fileBuffer.append(";\r\n\r\n");\r
@@ -2083,4 +2063,31 @@ public class AutoGen {
 \r
        }\r
 \r
+    private void copyFlashMapHToDebugDir() throws  AutoGenException{\r
+        \r
+        File inFile = new File(fvDir + File.separatorChar + CommonDefinition.flashMapH);\r
+        int size = (int)inFile.length();\r
+        byte[] buffer = new byte[size];\r
+        File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.tianoR8FlashMapH);\r
+               //\r
+               //  If TianoR8FlashMap.h existed and the flashMap.h don't change, \r
+               //  do nothing.\r
+               // \r
+        if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r
+                   try{\r
+                if (inFile.exists()) {\r
+                    FileInputStream fis = new FileInputStream (inFile);\r
+                    fis.read(buffer);\r
+                    FileOutputStream fos = new FileOutputStream(outFile);\r
+                    fos.write(buffer);\r
+                    fis.close();\r
+                    fos.close();\r
+                }else {\r
+                    throw new AutoGenException("The flashMap.h file don't exist!!");\r
+                }\r
+            } catch (Exception e){\r
+                throw new AutoGenException(e.getMessage());\r
+            }\r
+               }\r
+    }\r
 }
\ No newline at end of file