Fixed R8 modules build issues
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 2 Apr 2008 09:34:59 +0000 (09:34 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 2 Apr 2008 09:34:59 +0000 (09:34 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1105 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Workspace/MetaFileParser.py
Source/Python/Workspace/WorkspaceDatabase.py
Source/Python/build/build.py

index 5927846..9869f35 100644 (file)
@@ -156,14 +156,13 @@ class InfParser(MetaFileParser):
             if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:\r
                 self._SectionHeaderParser()\r
                 continue\r
-            elif Line.startswith('DEFINE '):\r
+            elif Line.upper().startswith('DEFINE '):\r
                 self._MacroParser()\r
                 continue\r
 \r
             # section content\r
             self._ValueList = ['','','']\r
             self._SectionParser[self._SectionType](self)\r
-            EdkLogger.debug(EdkLogger.DEBUG_8, "Define: %s" % self._ValueList)\r
 \r
             # \r
             # Model, Value1, Value2, Value3, Value4, Value5, Arch, Platform, BelongsToFile=-1, \r
@@ -186,13 +185,6 @@ class InfParser(MetaFileParser):
                             )\r
         self._Done()\r
             \r
-    #def _DefineParser(self):\r
-    #    TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r
-    #    self._ValueList[0] = TokenList[0]\r
-    #    if len(TokenList) == 2:\r
-    #        MoreValues = GetSplitValueList(TokenList[1], TAB_VALUE_SPLIT)\r
-    #        self._ValueList[1:1+len(MoreValues)] = MoreValues\r
-\r
     def _BuildOptionParser(self):\r
         TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r
         TokenList2 = GetSplitValueList(TokenList[0], ':', 1)\r
@@ -201,16 +193,13 @@ class InfParser(MetaFileParser):
             self._ValueList[1] = TokenList2[1]\r
         else:\r
             self._ValueList[1] = TokenList[0]\r
-        self._ValueList[2] = TokenList[1]\r
+        self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros)\r
 \r
     def _NmakeParser(self):\r
-        TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)\r
-        if len(TokenList) == 2:\r
-            self._ValueList[0] = TokenList[0]\r
-            TokenList = GetSplitValueList(TokenList[1], TAB_EQUAL_SPLIT, 1)\r
-        else:\r
-            TokenList = GetSplitValueList(TokenList[0], TAB_EQUAL_SPLIT, 1)\r
-        self._ValueList[1:1+len(TokenList)] = TokenList\r
+        TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r
+        self._ValueList[0:len(TokenList)] = TokenList\r
+        # remove self-reference in macro setting\r
+        self._ValueList[1] = ReplaceMacro(self._ValueList[1], {self._ValueList[0]:''})\r
 \r
     def _PcdParser(self):\r
         TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)\r
@@ -225,11 +214,11 @@ class InfParser(MetaFileParser):
         MODEL_UNKNOWN                   :   MetaFileParser._Skip,\r
         MODEL_META_DATA_HEADER          :   MetaFileParser._DefineParser,\r
         MODEL_META_DATA_BUILD_OPTION    :   _BuildOptionParser,\r
-        MODEL_EFI_INCLUDE               :   MetaFileParser._PathParser,\r
-        MODEL_EFI_LIBRARY_INSTANCE      :   MetaFileParser._PathParser,\r
+        MODEL_EFI_INCLUDE               :   MetaFileParser._PathParser,     # for R8.x modules\r
+        MODEL_EFI_LIBRARY_INSTANCE      :   MetaFileParser._CommonParser,   # for R8.x modules\r
         MODEL_EFI_LIBRARY_CLASS         :   MetaFileParser._PathParser,\r
         MODEL_META_DATA_PACKAGE         :   MetaFileParser._PathParser,\r
-        MODEL_META_DATA_NMAKE           :   _NmakeParser,\r
+        MODEL_META_DATA_NMAKE           :   _NmakeParser,                   # for R8.x modules\r
         MODEL_PCD_FIXED_AT_BUILD        :   _PcdParser,\r
         MODEL_PCD_PATCHABLE_IN_MODULE   :   _PcdParser,\r
         MODEL_PCD_FEATURE_FLAG          :   _PcdParser,\r
@@ -321,7 +310,7 @@ class DscParser(MetaFileParser):
             elif Line[0] == '!':\r
                 self._DirectiveParser()\r
                 continue\r
-            elif Line.startswith('DEFINE '):\r
+            elif Line.upper().startswith('DEFINE '):\r
                 self._MacroParser()\r
                 continue\r
 \r
@@ -382,7 +371,6 @@ class DscParser(MetaFileParser):
         self._ValueList = ['','','']\r
         TokenList = GetSplitValueList(self._CurrentLine, ' ', 1)\r
         self._ValueList[0:len(TokenList)] = TokenList\r
-        print self._ValueList\r
         DirectiveName = self._ValueList[0].upper()\r
         self._LastItem = self._Store(\r
             self._DataType[DirectiveName],\r
@@ -425,7 +413,7 @@ class DscParser(MetaFileParser):
             self._ValueList[1] = TokenList2[1]\r
         else:\r
             self._ValueList[1] = TokenList[0]\r
-        self._ValueList[2] = TokenList[1]\r
+        self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros)\r
 \r
     def _PcdParser(self):\r
         TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)\r
index 206829a..82778cf 100644 (file)
@@ -288,7 +288,10 @@ class DscBuildData(PlatformBuildClassObject):
                 Module = self._Db.BuildObject[ModuleFile, MODEL_FILE_INF, self._Arch]\r
                 # only merge library classes and PCD for non-library module\r
                 if Module.LibraryClass == None or Module.LibraryClass == []:\r
-                    self._MergeModuleInfo(Module, ModuleId)\r
+                    if Module.AutoGenVersion < 0x00010005:\r
+                        self._ResolveLibraryReference(Module)\r
+                    else:\r
+                        self._MergeModuleInfo(Module, ModuleId)\r
                 self._UpdateModulePcd(Module, ModuleId)\r
                 self._MergeModuleBuildOption(Module, ModuleId)\r
                 self._Modules.append(Module)\r
@@ -482,6 +485,30 @@ class DscBuildData(PlatformBuildClassObject):
                 if CName not in Module.Ppis:\r
                     Module.Ppis.append(CName)\r
 \r
+    ##\r
+    # for R8.x modules\r
+    # \r
+    def _ResolveLibraryReference(self, Module):\r
+        EdkLogger.verbose("")\r
+        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self._Arch))\r
+        LibraryConsumerList = [Module]\r
+\r
+        # "CompilerStub" is a must for R8 modules\r
+        Module.Libraries.append("CompilerStub")\r
+        while len(LibraryConsumerList) > 0:\r
+            M = LibraryConsumerList.pop()\r
+            for LibraryName in M.Libraries:\r
+                if LibraryName not in self.Libraries:\r
+                    EdkLogger.warn("AutoGen", "Library [%s] is not found" % LibraryName,\r
+                                    ExtraData="\t%s [%s]" % (str(Module), Arch))\r
+                    continue\r
+\r
+                Library = self.Libraries[LibraryName]\r
+                if (LibraryName, Module.ModuleType) not in Module.LibraryClasses:\r
+                    Module.LibraryClasses[LibraryName, Module.ModuleType] = Library\r
+                    LibraryConsumerList.append(Library)\r
+                    EdkLogger.verbose("\t" + LibraryName + " : " + str(Library))\r
+\r
     def _UpdateModulePcd(self, Module, ModuleId):\r
         for Name,Guid in Module.Pcds:\r
             PcdInModule = Module.Pcds[Name,Guid]\r
@@ -608,7 +635,7 @@ class DscBuildData(PlatformBuildClassObject):
 \r
     def _GetLibraries(self):\r
         if self._Libraries == None:\r
-            self._Libraries = []\r
+            self._Libraries = sdict()\r
             RecordList = self._Table.Query(MODEL_EFI_LIBRARY_INSTANCE, Scope1=self.Arch)\r
             for Record in RecordList:\r
                 File = NormPath(Record[0], self._Macros)\r
@@ -616,7 +643,8 @@ class DscBuildData(PlatformBuildClassObject):
                 if not ValidFile(File):\r
                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
                                     File=self.DescFilePath, Line=LineNo)\r
-                self._Libraries.append(File)\r
+                Library = self._Db.BuildObject[File, MODEL_FILE_INF, self._Arch]\r
+                self._Libraries[Library.BaseName] = Library\r
         return self._Libraries\r
 \r
     def _GetPcds(self):\r
@@ -1057,6 +1085,7 @@ class InfBuildData(ModuleBuildClassObject):
         TAB_INF_DEFINES_INF_VERSION                 : "_AutoGenVersion",\r
         TAB_INF_DEFINES_COMPONENT_TYPE              : "_ComponentType",\r
         TAB_INF_DEFINES_MAKEFILE_NAME               : "_CustomMakefile",\r
+        TAB_INF_DEFINES_CUSTOM_MAKEFILE             : "_CustomMakefile",\r
         TAB_INF_DEFINES_VERSION_NUMBER              : "_Version",\r
         TAB_INF_DEFINES_VERSION_STRING              : "_Version",\r
         TAB_INF_DEFINES_VERSION                     : "_Version",\r
@@ -1065,6 +1094,31 @@ class InfBuildData(ModuleBuildClassObject):
         TAB_INF_DEFINES_CUSTOM_MAKEFILE             : "_CustomMakefile",\r
     }\r
 \r
+    _MODULE_TYPE_ = {\r
+        "LIBRARY"               :   "BASE",\r
+        "SECURITY_CORE"         :   "SEC",\r
+        "PEI_CORE"              :   "PEI_CORE",\r
+        "COMBINED_PEIM_DRIVER"  :   "PEIM",\r
+        "PIC_PEIM"              :   "PEIM",\r
+        "RELOCATABLE_PEIM"      :   "PEIM",\r
+        "PE32_PEIM"             :   "PEIM",\r
+        "BS_DRIVER"             :   "DXE_DRIVER",\r
+        "RT_DRIVER"             :   "DXE_RUNTIME_DRIVER",\r
+        "SAL_RT_DRIVER"         :   "DXE_SAL_DRIVER",\r
+    #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",\r
+    #    "BS_DRIVER"             :   "UEFI_DRIVER",\r
+        "APPLICATION"           :   "UEFI_APPLICATION",\r
+        "LOGO"                  :   "BASE",\r
+    }\r
+    \r
+    _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
+    _TOOL_CODE_ = {\r
+        "C"         :   "CC",\r
+        "LIB"       :   "SLINK",\r
+        "LINK"      :   "DLINK",\r
+    }\r
+    \r
+\r
     def __init__(self, FilePath, Table, Db, Arch='COMMON', Macros={}):\r
         self.DescFilePath = FilePath\r
         self._ModuleDir = os.path.dirname(FilePath)\r
@@ -1237,6 +1291,49 @@ class InfBuildData(ModuleBuildClassObject):
                 if Record[1] == '':\r
                     continue\r
                 self._DestructorList.append(Record[1])\r
+\r
+        # \r
+        # R8.x modules\r
+        # \r
+        if self._AutoGenVersion < 0x00010005:\r
+            if self._ComponentType in self._MODULE_TYPE_:\r
+                self._ModuleType = self._MODULE_TYPE_[self._ComponentType]\r
+            if self._ComponentType == 'LIBRARY':\r
+                self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]\r
+            # make use some [nmake] section macros\r
+            RecordList = self._Table.Query(MODEL_META_DATA_NMAKE, Arch=self._Arch, Platform=self._Platform)\r
+            for Name,Value,Dummy,Arch,Platform,ID,LineNo in RecordList:\r
+                if Name == "IMAGE_ENTRY_POINT":\r
+                    if self._ModuleEntryPointList == None:\r
+                        self._ModuleEntryPointList = []\r
+                    self._ModuleEntryPointList.append(Value)\r
+                elif Name == "DPX_SOURCE":\r
+                    File = NormPath(Value, self._Macros)\r
+                    if not ValidFile(Source, self._ModuleDir):\r
+                        EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
+                                        File=self.DescFilePath, Line=LineNo)\r
+                    self._Sources.append(ModuleSourceFileClass(File, "", "", "", ""))\r
+                else:\r
+                    ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)\r
+                    if len(ToolList) == 0 or len(ToolList) != 1:\r
+                        EdkLogger.warn("\nbuild", "Don't know how to do with MACRO: %s" % Name, \r
+                                       ExtraData=ContainerFile)\r
+                    else:\r
+                        if self._BuildOptions == None:\r
+                            self._BuildOptions = sdict()\r
+\r
+                        if ToolList[0] in self._TOOL_CODE_:\r
+                            Tool = self._TOOL_CODE_[ToolList[0]]\r
+                        else:\r
+                            Tool = ToolList[0]\r
+                        ToolChain = "*_*_*_%s_FLAGS" % Tool\r
+                        ToolChainFamily = 'MSFT'    # R8.x only support MSFT tool chain\r
+                        if (ToolChainFamily, ToolChain) not in self._BuildOptions:\r
+                            self._BuildOptions[ToolChainFamily, ToolChain] = Value\r
+                        else:\r
+                            OptionString = self._BuildOptions[ToolChainFamily, ToolChain]\r
+                            self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value\r
+\r
         self._Header_ = 'DUMMY'\r
 \r
     def _GetInfVersion(self):\r
@@ -1448,9 +1545,14 @@ class InfBuildData(ModuleBuildClassObject):
             for Record in RecordList:\r
                 File = NormPath(Record[0], self._Macros)\r
                 LineNo = Record[-1]\r
-                if not ValidFile(File, self._ModuleDir):\r
-                    EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
-                                    File=self.DescFilePath, Line=LineNo)\r
+                #if File[0] == '.':\r
+                #    if not ValidFile(File, self._ModuleDir):\r
+                #        EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
+                #                        File=self.DescFilePath, Line=LineNo)\r
+                #else:\r
+                #    if not ValidFile(File):\r
+                #        EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
+                #                        File=self.DescFilePath, Line=LineNo)\r
                 self._Includes.append(File)\r
         return self._Includes\r
 \r
index 1f7d6e4..43f710b 100644 (file)
@@ -688,7 +688,7 @@ class Build():
             EdkLogger.verbose('%-24s = %s' % ("Max Thread Number", self.ThreadNumber))\r
 \r
         # establish build database, INF/DEC files will be parsed in this stage\r
-        self.Progress.Start("\nParsing meta-files")\r
+        self.Progress.Start("\nParsing meta-data")\r
         try:\r
             if self.Fdf != None and self.Fdf != "":\r
                 FdfFile = os.path.join(self.WorkspaceDir, self.Fdf)\r