public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch 1/4] BaseTools: Fixed the pcd value override issue.
@ 2018-02-28  5:59 BobCF
  2018-02-28  5:59 ` [Patch 2/4] BaseTools: Improve build performance BobCF
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: BobCF @ 2018-02-28  5:59 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

1. the issue in the overriding value from command line.
2. dec fully value < dec field assign value <
   dsc fully value < dsc field assign value

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/AutoGen/GenMake.py         | 39 +++++++++++-----------
 .../Source/Python/Workspace/BuildClassObject.py    |  4 +++
 BaseTools/Source/Python/Workspace/DecBuildData.py  |  1 +
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 24 ++++++++++---
 4 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 4b924d21e0..1b0cf17e25 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -1549,30 +1549,29 @@ class TopLevelMakefile(BuildFile):
         if GlobalData.gEnableGenfdsMultiThread:
             ExtraOption += " --genfds-multi-thread"
         if GlobalData.gIgnoreSource:
             ExtraOption += " --ignore-sources"
 
-        if GlobalData.BuildOptionPcd:
-            for index, option in enumerate(GlobalData.gCommand):
-                if "--pcd" == option and GlobalData.gCommand[index+1]:
-                    pcdName, pcdValue = GlobalData.gCommand[index+1].split('=')
-                    for Item in GlobalData.BuildOptionPcd:
-                        if '.'.join(Item[0:2]) == pcdName:
-                            pcdValue = Item[2]
-                            if pcdValue.startswith('L') or pcdValue.startswith('"'):
-                                pcdValue, Size = ParseFieldValue(pcdValue)
-                                NewVal = '{'
-                                for S in range(Size):
-                                    NewVal = NewVal + '0x%02X' % ((pcdValue >> S * 8) & 0xff)
-                                    NewVal += ','
-                                pcdValue =  NewVal[:-1] + '}'
-                            break
-                    if pcdValue.startswith('{'):
-                        pcdValue = 'H' + '"' + pcdValue + '"'
-                        ExtraOption += " --pcd " + pcdName + '=' + pcdValue
-                    else:
-                        ExtraOption += " --pcd " + GlobalData.gCommand[index+1]
+        for index, option in enumerate(GlobalData.gCommand):
+            if "--pcd" == option and GlobalData.gCommand[index+1]:
+                pcdName, pcdValue = GlobalData.gCommand[index+1].split('=')
+                for Item in GlobalData.BuildOptionPcd:
+                    if '.'.join(Item[0:2]) == pcdName:
+                        pcdValue = Item[2]
+                        if pcdValue.startswith('L') or pcdValue.startswith('"'):
+                            pcdValue, Size = ParseFieldValue(pcdValue)
+                            NewVal = '{'
+                            for S in range(Size):
+                                NewVal = NewVal + '0x%02X' % ((pcdValue >> S * 8) & 0xff)
+                                NewVal += ','
+                            pcdValue =  NewVal[:-1] + '}'
+                        break
+                if pcdValue.startswith('{'):
+                    pcdValue = 'H' + '"' + pcdValue + '"'
+                    ExtraOption += " --pcd " + pcdName + '=' + pcdValue
+                else:
+                    ExtraOption += " --pcd " + GlobalData.gCommand[index+1]
 
         MakefileName = self._FILE_NAME_[self._FileType]
         SubBuildCommandList = []
         for A in PlatformInfo.ArchList:
             Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index f499cbd58b..05a83e84ac 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -124,19 +124,22 @@ class StructurePcd(PcdClassObject):
         self.SkuOverrideValues = collections.OrderedDict({})
         self.FlexibleFieldName = None
         self.StructName = None
         self.PcdDefineLineNo = 0
         self.PkgPath = ""
+        self.DefaultValueFromDec = ""
     def __repr__(self):
         return self.TypeName
 
     def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
         if FieldName in self.DefaultValues:
             del self.DefaultValues[FieldName]
         self.DefaultValues[FieldName] = [Value.strip(), FileName, LineNo]
         return self.DefaultValues[FieldName]
 
+    def SetDecDefaultValue(self,DefaultValue):
+        self.DefaultValueFromDec = DefaultValue
     def AddOverrideValue (self, FieldName, Value, SkuName, DefaultStoreName, FileName="", LineNo=0):
         if SkuName not in self.SkuOverrideValues:
             self.SkuOverrideValues[SkuName] = collections.OrderedDict({})
         if DefaultStoreName not in self.SkuOverrideValues[SkuName]:
             self.SkuOverrideValues[SkuName][DefaultStoreName] = collections.OrderedDict({})
@@ -173,10 +176,11 @@ class StructurePcd(PcdClassObject):
             self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile
             self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs
             self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
             self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
             self.DefaultFromDSC=None
+            self.DefaultValueFromDec = PcdObject.DefaultValueFromDec if PcdObject.DefaultValueFromDec else self.DefaultValueFromDec
             self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
             self.FlexibleFieldName = PcdObject.FlexibleFieldName if PcdObject.FlexibleFieldName else self.FlexibleFieldName
             self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName
             self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo
             self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else self.PkgPath
diff --git a/BaseTools/Source/Python/Workspace/DecBuildData.py b/BaseTools/Source/Python/Workspace/DecBuildData.py
index 99c3bf14f1..61f15086d0 100644
--- a/BaseTools/Source/Python/Workspace/DecBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DecBuildData.py
@@ -383,10 +383,11 @@ class DecBuildData(PackageBuildClassObject):
                     struct_pcd.copy(item)
                     struct_pcd.TokenValue = struct_pcd.TokenValue.strip("{").strip()
                     struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName = pcdname.split(".")
                     struct_pcd.PcdDefineLineNo = LineNo
                     struct_pcd.PkgPath = self.MetaFile.File
+                    struct_pcd.SetDecDefaultValue(item.DefaultValue)
                 else:
                     struct_pcd.AddDefaultValue(item.TokenCName, item.DefaultValue,self.MetaFile.File,LineNo)
 
             struct_pcd.PackageDecs = dep_pkgs
             if not struct_pcd.StructuredPcdIncludeFile:
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index ea8d1847f7..393ad0265f 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -892,16 +892,15 @@ class DscBuildData(PlatformBuildClassObject):
         if GlobalData.BuildOptionPcd:
             for pcd in GlobalData.BuildOptionPcd:
                 if pcd[2] == "":
                     pcdset.append((pcd[0],pcd[1],pcd[3]))
                 else:
-                    pcdobj = self._Pcds.get((pcd[1],pcd[0]))
-                    if pcdobj:
-                        pcdset.append((pcd[0],pcd[1], pcdobj.DefaultValue))
-                    else:
+                    if (pcd[1],pcd[0]) not in self._Pcds:
                         pcdvalue = pcd[3] if len(pcd) == 4 else pcd[2]
                         pcdset.append((pcd[0],pcd[1],pcdvalue))
+                    #else:
+                        # remove the settings from command line since it has been handled.
         GlobalData.BuildOptionPcd = pcdset
     def GetFieldValueFromComm(self,ValueStr,TokenSpaceGuidCName, TokenCName, FieldName):
         PredictedFieldType = "VOID*"
         if ValueStr.startswith('L'):
             if not ValueStr[1]:
@@ -1674,10 +1673,27 @@ class DscBuildData(PlatformBuildClassObject):
 
             #
             # Assign field values in PCD
             #
             CApp = CApp + "// Default value in Dec \n"
+            DefaultValueFromDec = Pcd.DefaultValueFromDec
+            IsArray = self.IsFieldValueAnArray(Pcd.DefaultValueFromDec)
+            if IsArray:
+                try:
+                    DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, "VOID*")(True)
+                except BadExpression:
+                    EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %
+                                    (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))
+            Value, ValueSize = ParseFieldValue (DefaultValueFromDec)
+            if isinstance(Value, str):
+                CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)
+            elif IsArray:
+            #
+            # Use memcpy() to copy value into field
+            #
+                CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
+                CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
             for FieldList in [Pcd.DefaultValues]:
                 if not FieldList:
                     continue
                 for FieldName in FieldList:
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
-- 
2.14.3.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Patch 2/4] BaseTools: Improve build performance
  2018-02-28  5:59 [Patch 1/4] BaseTools: Fixed the pcd value override issue BobCF
@ 2018-02-28  5:59 ` BobCF
  2018-02-28  5:59 ` [Patch 3/4] BaseTool: GUID assignment fail BobCF
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: BobCF @ 2018-02-28  5:59 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

Add cache for building PcdValueInit.c.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/GenFds/GenFds.py          |   1 +
 BaseTools/Source/Python/Workspace/DecBuildData.py |  12 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 172 +++++++++++-----------
 3 files changed, 101 insertions(+), 84 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py
index dcba9f24cb..cd705630a3 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -324,10 +324,11 @@ def main():
                                         EdkLogger.error("GenFds", FORMAT_INVALID, "The FV %s's region is specified in multiple FD with different value." %FvObj.UiFvName)
                                 else:
                                     FvObj.FvRegionInFD = RegionObj.Size
                                     RegionObj.BlockInfoOfRegion(FdObj.BlockSizeList, FvObj)
 
+        GlobalData.BuildOptionPcd     = Options.OptionPcd if Options.OptionPcd else {}
         """Call GenFds"""
         GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)
 
         """Generate GUID cross reference file"""
         GenFds.GenerateGuidXRefFile(BuildWorkSpace, ArchList, FdfParserObj)
diff --git a/BaseTools/Source/Python/Workspace/DecBuildData.py b/BaseTools/Source/Python/Workspace/DecBuildData.py
index 61f15086d0..18101a0add 100644
--- a/BaseTools/Source/Python/Workspace/DecBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DecBuildData.py
@@ -93,10 +93,11 @@ class DecBuildData(PackageBuildClassObject):
         self._PkgUniFile        = None
         self._Protocols         = None
         self._Ppis              = None
         self._Guids             = None
         self._Includes          = None
+        self._CommonIncludes    = None
         self._LibraryClasses    = None
         self._Pcds              = None
         self.__Macros           = None
         self._PrivateProtocols  = None
         self._PrivatePpis       = None
@@ -294,11 +295,12 @@ class DecBuildData(PackageBuildClassObject):
                 self._PrivateGuids[Name] = PrivateGuidDict[self._Arch, Name]
         return self._Guids
 
     ## Retrieve public include paths declared in this package
     def _GetInclude(self):
-        if self._Includes == None:
+        if self._Includes == None or self._CommonIncludes is None:
+            self._CommonIncludes = []
             self._Includes = []
             self._PrivateIncludes = []
             PublicInclues = []
             RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]
             Macros = self._Macros
@@ -322,11 +324,12 @@ class DecBuildData(PackageBuildClassObject):
                 else:
                     if File not in PublicInclues:
                         PublicInclues.append(File)
                     if File in self._PrivateIncludes:
                         EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % File, File=self.MetaFile, Line=LineNo)
-
+                if Record[3] == "COMMON":
+                    self._CommonIncludes.append(File)
         return self._Includes
 
     ## Retrieve library class declarations (not used in build at present)
     def _GetLibraryClass(self):
         if self._LibraryClasses == None:
@@ -450,10 +453,15 @@ class DecBuildData(PackageBuildClassObject):
         StructurePcds = self.ProcessStructurePcd(StrPcdSet)
         for pcd in StructurePcds:
             Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd
 
         return Pcds
+    @property
+    def CommonIncludes(self):
+        if self._CommonIncludes is None:
+            self.Includes
+        return self._CommonIncludes
 
 
     _Macros = property(_GetMacros)
     Arch = property(_GetArch, _SetArch)
     PackageName = property(_GetPackageName)
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 393ad0265f..59bfd9c8e0 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -35,10 +35,11 @@ from Common.Misc import ProcessDuplicatedInf
 import re
 from Common.Parsing import IsValidWord
 from Common.VariableAttributes import VariableAttributes
 import Common.GlobalData as GlobalData
 import subprocess
+from Common.Misc import SaveFileOnChange
 from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
 
 #
 # Treat CHAR16 as a synonym for UINT16.  CHAR16 support is required for VFR C structs
 #
@@ -87,11 +88,10 @@ LIBS = $(LIB_PATH)\Common.lib
 
 !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
 '''
 
 PcdGccMakefile = '''
-ARCH ?= IA32
 MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
 LIBS = -lCommon
 '''
 
 class DscBuildData(PlatformBuildClassObject):
@@ -154,16 +154,19 @@ class DscBuildData(PlatformBuildClassObject):
         self._Target = Target
         self._Toolchain = Toolchain
         self._ToolChainFamily = None
         self._Clear()
         self._HandleOverridePath()
-        if os.getenv("WORKSPACE"):
-            self.OutputPath = os.path.join(os.getenv("WORKSPACE"), 'Build', PcdValueInitName)
-        else:
-            self.OutputPath = os.path.dirname(self.DscFile)
+        self.WorkspaceDir = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") else ""
         self.DefaultStores = None
         self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)
+    @property
+    def OutputPath(self):
+        if os.getenv("WORKSPACE"):
+            return os.path.join(os.getenv("WORKSPACE"), self.OutputDirectory, self._Target + "_" + self._Toolchain,PcdValueInitName)
+        else:
+            return os.path.dirname(self.DscFile)
 
     ## XXX[key] = value
     def __setitem__(self, key, value):
         self.__dict__[self._PROPERTY_[key]] = value
 
@@ -1297,11 +1300,11 @@ class DscBuildData(PlatformBuildClassObject):
                     str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                 else:
                     str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                 for str_pcd_data in StrPcdSet[str_pcd]:
                     if str_pcd_data[3] in SkuIds:
-                        str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File,LineNo=str_pcd_data[5])
+                        str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:],LineNo=str_pcd_data[5])
                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
             else:
                 EdkLogger.error('build', PARSER_ERROR,
                             "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
                             File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
@@ -1806,14 +1809,14 @@ class DscBuildData(PlatformBuildClassObject):
             for IncludeFile in Pcd.StructuredPcdIncludeFile:
                 if IncludeFile not in Includes:
                     Includes[IncludeFile] = True
                     CApp = CApp + '#include <%s>\n' % (IncludeFile)
         CApp = CApp + '\n'
-
         for PcdName in StructuredPcds:
             Pcd = StructuredPcds[PcdName]
-            if not Pcd.SkuOverrideValues:
+            if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
+                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
                 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
                     if SkuName not in Pcd.SkuOverrideValues:
                         continue
@@ -1825,11 +1828,11 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + 'PcdEntryPoint(\n'
         CApp = CApp + '  VOID\n'
         CApp = CApp + '  )\n'
         CApp = CApp + '{\n'
         for Pcd in StructuredPcds.values():
-            if not Pcd.SkuOverrideValues:
+            if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
                 CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
                     if SkuName not in Pcd.SkuOverrideValues:
                         continue
@@ -1840,17 +1843,15 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + PcdMainCEntry + '\n'
 
         if not os.path.exists(self.OutputPath):
             os.makedirs(self.OutputPath)
         CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
-        File = open (CAppBaseFileName + '.c', 'w')
-        File.write(CApp)
-        File.close()
+        SaveFileOnChange(CAppBaseFileName + '.c', CApp, False)
 
         MakeApp = PcdMakefileHeader
         if sys.platform == "win32":
-            MakeApp = MakeApp + 'ARCH = IA32\nAPPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj\n' % (self.OutputPath, PcdValueInitName) + 'INC = '
+            MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj\n' % (self.OutputPath, PcdValueInitName) + 'INC = '
         else:
             MakeApp = MakeApp + PcdGccMakefile
             MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o\n' % (self.OutputPath, PcdValueInitName) + \
                       'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
 
@@ -1858,11 +1859,11 @@ class DscBuildData(PlatformBuildClassObject):
         for Cache in self._Bdb._CACHE_.values():
             if Cache.MetaFile.Ext.lower() != '.dec':
                 continue
             if Cache.Includes:
                 if str(Cache.MetaFile.Path) not in PlatformInc:
-                    PlatformInc[str(Cache.MetaFile.Path)] = Cache.Includes
+                    PlatformInc[str(Cache.MetaFile.Path)] = Cache.CommonIncludes
 
         PcdDependDEC = []
         for Pcd in StructuredPcds.values():
             for PackageDec in Pcd.PackageDecs:
                 Package = os.path.normpath(mws.join(GlobalData.gWorkspace, PackageDec))
@@ -1922,94 +1923,101 @@ class DscBuildData(PlatformBuildClassObject):
         MakeApp += CC_FLAGS
 
         if sys.platform == "win32":
             MakeApp = MakeApp + PcdMakefileEnd
         MakeFileName = os.path.join(self.OutputPath, 'Makefile')
-        File = open (MakeFileName, 'w')
-        File.write(MakeApp)
-        File.close()
+        SaveFileOnChange(MakeFileName, MakeApp, False)
 
         InputValueFile = os.path.join(self.OutputPath, 'Input.txt')
         OutputValueFile = os.path.join(self.OutputPath, 'Output.txt')
-        File = open (InputValueFile, 'w')
-        File.write(InitByteValue)
-        File.close()
-
-        Messages = ''
-        if sys.platform == "win32":
-            MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
-            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
-            Messages = StdOut
-        else:
-            MakeCommand = 'make clean & make -f %s' % (MakeFileName)
-            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
-            Messages = StdErr
-        Messages = Messages.split('\n')
-        MessageGroup = []
-        if returncode <>0:
-            CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
-            File = open (CAppBaseFileName + '.c', 'r')
-            FileData = File.readlines()
-            File.close()
-            for Message in Messages:
-                if " error" in Message or "warning" in Message:
-                    FileInfo = Message.strip().split('(')
-                    if len (FileInfo) > 1:
-                        FileName = FileInfo [0]
-                        FileLine = FileInfo [1].split (')')[0]
-                    else:
-                        FileInfo = Message.strip().split(':')
-                        FileName = FileInfo [0]
-                        FileLine = FileInfo [1]
-                    if FileLine.isdigit():
-                        error_line = FileData[int (FileLine) - 1]
-                        if r"//" in error_line:
-                            c_line,dsc_line = error_line.split(r"//")
-                        else:
-                            dsc_line = error_line
-                        message_itmes = Message.split(":")
-                        Index = 0
-                        if "PcdValueInit.c" not in Message:
-                            if not MessageGroup:
-                                MessageGroup.append(Message)
-                            break
-                        else:
-                            for item in message_itmes:
-                                if "PcdValueInit.c" in item:
-                                    Index = message_itmes.index(item)
-                                    message_itmes[Index] = dsc_line.strip()
-                                    break
-                            MessageGroup.append(":".join(message_itmes[Index:]).strip())
-                            continue
-                    else:
-                        MessageGroup.append(Message)
-            if MessageGroup:
-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )
-            else:
-                EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)
+        SaveFileOnChange(InputValueFile, InitByteValue, False)
 
         PcdValueInitExe = PcdValueInitName
         if not sys.platform == "win32":
             PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName)
-
-        Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)
-        returncode, StdOut, StdErr = self.ExecuteCommand (Command)
-        if returncode <> 0:
-            EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)
-            FileBuffer = []
         else:
-            File = open (OutputValueFile, 'r')
-            FileBuffer = File.readlines()
-            File.close()
+            PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName) +".exe"
+        if not os.path.exists(PcdValueInitExe) or self.NeedUpdateOutput(OutputValueFile, CAppBaseFileName + '.c',MakeFileName,InputValueFile):
+            Messages = ''
+            if sys.platform == "win32":
+                MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
+                returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
+                Messages = StdOut
+            else:
+                MakeCommand = 'make clean & make -f %s' % (MakeFileName)
+                returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
+                Messages = StdErr
+            Messages = Messages.split('\n')
+            MessageGroup = []
+            if returncode <>0:
+                CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
+                File = open (CAppBaseFileName + '.c', 'r')
+                FileData = File.readlines()
+                File.close()
+                for Message in Messages:
+                    if " error" in Message or "warning" in Message:
+                        FileInfo = Message.strip().split('(')
+                        if len (FileInfo) > 1:
+                            FileName = FileInfo [0]
+                            FileLine = FileInfo [1].split (')')[0]
+                        else:
+                            FileInfo = Message.strip().split(':')
+                            FileName = FileInfo [0]
+                            FileLine = FileInfo [1]
+                        if FileLine.isdigit():
+                            error_line = FileData[int (FileLine) - 1]
+                            if r"//" in error_line:
+                                c_line,dsc_line = error_line.split(r"//")
+                            else:
+                                dsc_line = error_line
+                            message_itmes = Message.split(":")
+                            Index = 0
+                            if "PcdValueInit.c" not in Message:
+                                if not MessageGroup:
+                                    MessageGroup.append(Message)
+                                break
+                            else:
+                                for item in message_itmes:
+                                    if "PcdValueInit.c" in item:
+                                        Index = message_itmes.index(item)
+                                        message_itmes[Index] = dsc_line.strip()
+                                        break
+                                MessageGroup.append(":".join(message_itmes[Index:]).strip())
+                                continue
+                        else:
+                            MessageGroup.append(Message)
+                if MessageGroup:
+                    EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )
+                else:
+                    EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)
+            Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)
+            returncode, StdOut, StdErr = self.ExecuteCommand (Command)
+            if returncode <> 0:
+                EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)
+
+        File = open (OutputValueFile, 'r')
+        FileBuffer = File.readlines()
+        File.close()
 
         StructurePcdSet = []
         for Pcd in FileBuffer:
             PcdValue = Pcd.split ('|')
             PcdInfo = PcdValue[0].split ('.')
             StructurePcdSet.append((PcdInfo[0],PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))
         return StructurePcdSet
 
+    def NeedUpdateOutput(self,OutputFile, ValueCFile, MakeFile, StructureInput):
+        if not os.path.exists(OutputFile):
+            return True
+        if os.stat(OutputFile).st_mtime <= os.stat(ValueCFile).st_mtime:
+            return True
+        if os.stat(OutputFile).st_mtime <= os.stat(MakeFile).st_mtime:
+            return True
+        if os.stat(OutputFile).st_mtime <= os.stat(StructureInput).st_mtime:
+            return True
+        return False
+
     ## Retrieve dynamic PCD settings
     #
     #   @param  Type    PCD type
     #
     #   @retval a dict object contains settings of given PCD type
-- 
2.14.3.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Patch 3/4] BaseTool: GUID assignment fail.
  2018-02-28  5:59 [Patch 1/4] BaseTools: Fixed the pcd value override issue BobCF
  2018-02-28  5:59 ` [Patch 2/4] BaseTools: Improve build performance BobCF
@ 2018-02-28  5:59 ` BobCF
  2018-02-28  5:59 ` [Patch 4/4] BaseTools: Improve build performance BobCF
  2018-02-28  6:46 ` [Patch 1/4] BaseTools: Fixed the pcd value override issue Gao, Liming
  3 siblings, 0 replies; 5+ messages in thread
From: BobCF @ 2018-02-28  5:59 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

Structure PCD GUID assignment fail.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/Workspace/DecBuildData.py |   3 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 289 ++++++++++++++--------
 2 files changed, 182 insertions(+), 110 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DecBuildData.py b/BaseTools/Source/Python/Workspace/DecBuildData.py
index 18101a0add..ee00ec0719 100644
--- a/BaseTools/Source/Python/Workspace/DecBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DecBuildData.py
@@ -13,10 +13,11 @@
 #
 from Common.String import *
 from Common.DataType import *
 from Common.Misc import *
 from types import *
+from collections import OrderedDict
 
 from Workspace.BuildClassObject import PackageBuildClassObject, StructurePcd, PcdClassObject
 
 ## Platform build information from DEC file
 #
@@ -365,11 +366,11 @@ class DecBuildData(PackageBuildClassObject):
             self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
         return self._Pcds
 
 
     def ProcessStructurePcd(self, StructurePcdRawDataSet):
-        s_pcd_set = dict()
+        s_pcd_set = OrderedDict()
         for s_pcd,LineNo in StructurePcdRawDataSet:
             if s_pcd.TokenSpaceGuidCName not in s_pcd_set:
                 s_pcd_set[s_pcd.TokenSpaceGuidCName] = []
             s_pcd_set[s_pcd.TokenSpaceGuidCName].append((s_pcd,LineNo))
 
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 59bfd9c8e0..29c43e751f 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -37,10 +37,11 @@ from Common.Parsing import IsValidWord
 from Common.VariableAttributes import VariableAttributes
 import Common.GlobalData as GlobalData
 import subprocess
 from Common.Misc import SaveFileOnChange
 from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
+from collections import OrderedDict
 
 #
 # Treat CHAR16 as a synonym for UINT16.  CHAR16 support is required for VFR C structs
 #
 PcdValueInitName = 'PcdValueInit'
@@ -1281,11 +1282,11 @@ class DscBuildData(PlatformBuildClassObject):
             if SkuName in SkuIds and "." in TokenSpaceGuid:
                 S_PcdSet.append([ TokenSpaceGuid.split(".")[0],TokenSpaceGuid.split(".")[1], PcdCName,SkuName, default_store,Dummy5, AnalyzePcdExpression(Setting)[0]])
 
         # handle pcd value override
         StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)
-        S_pcd_set = {}
+        S_pcd_set = OrderedDict()
         for str_pcd in StrPcdSet:
             str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
             str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
             if not isinstance (str_pcd_dec, StructurePcd):
                 EdkLogger.error('build', PARSER_ERROR,
@@ -1559,10 +1560,181 @@ class DscBuildData(PlatformBuildClassObject):
                 Result = Result + '\\x%02x' % (Value & 0xff)
                 Value = Value >> 8
         Result = Result + '"'
         return Result
 
+    def GenerateSizeFunction(self,Pcd):
+        CApp = "// Default Value in Dec \n"
+        CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+        for FieldList in [Pcd.DefaultValues]:
+            if not FieldList:
+                continue
+            for FieldName in FieldList:
+                FieldName = "." + FieldName
+                IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
+                if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):
+                    try:
+                        Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)
+                    except BadExpression:
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
+                                        (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
+                    Value, ValueSize = ParseFieldValue(Value)
+                    CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
+                else:
+                    NewFieldName = ''
+                    FieldName_ori = FieldName.strip('.')
+                    while '[' in  FieldName:
+                        NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
+                        ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])
+                        FieldName = FieldName.split(']', 1)[1]
+                    FieldName = NewFieldName + FieldName
+                    while '[' in FieldName:
+                        FieldName = FieldName.rsplit('[', 1)[0]
+                        CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
+        for skuname in Pcd.SkuOverrideValues:
+            if skuname == "COMMON":
+                continue
+            for defaultstorenameitem in Pcd.SkuOverrideValues[skuname]:
+                CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
+                for FieldList in [Pcd.SkuOverrideValues[skuname].get(defaultstorenameitem)]:
+                    if not FieldList:
+                        continue
+                    for FieldName in FieldList:
+                        FieldName = "." + FieldName
+                        IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
+                        if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):
+                            try:
+                                Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)
+                            except BadExpression:
+                                EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
+                                                (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
+                            Value, ValueSize = ParseFieldValue(Value)
+                            CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
+                        else:
+                            NewFieldName = ''
+                            FieldName_ori = FieldName.strip('.')
+                            while '[' in  FieldName:
+                                NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
+                                ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])
+                                FieldName = FieldName.split(']', 1)[1]
+                            FieldName = NewFieldName + FieldName
+                            while '[' in FieldName:
+                                FieldName = FieldName.rsplit('[', 1)[0]
+                                CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
+        CApp = CApp + "}\n"
+        return CApp
+    def GenerateSizeStatments(self,Pcd):
+        CApp = '  Size = sizeof(%s);\n' % (Pcd.DatumType)
+        CApp = CApp + '  Cal_%s_%s_Size(&Size);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+        return CApp
+    def GenerateDefaultValueAssignFunction(self,Pcd):
+        CApp = "// Default value in Dec \n"
+        CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType)
+        CApp = CApp + '  UINT32  FieldSize;\n'
+        CApp = CApp + '  CHAR8   *Value;\n'
+        DefaultValueFromDec = Pcd.DefaultValueFromDec
+        IsArray = self.IsFieldValueAnArray(Pcd.DefaultValueFromDec)
+        if IsArray:
+            try:
+                DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, "VOID*")(True)
+            except BadExpression:
+                EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %
+                                (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))
+        Value, ValueSize = ParseFieldValue (DefaultValueFromDec)
+        if isinstance(Value, str):
+            CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)
+        elif IsArray:
+        #
+        # Use memcpy() to copy value into field
+        #
+            CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
+            CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
+        for FieldList in [Pcd.DefaultValues]:
+            if not FieldList:
+                continue
+            for FieldName in FieldList:
+                IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
+                if IsArray:
+                    try:
+                        FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
+                    except BadExpression:
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
+                                        (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1],FieldList[FieldName][2]))
+
+                try:
+                    Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
+                except Exception:
+                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
+                if isinstance(Value, str):
+                    CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                elif IsArray:
+                    #
+                    # Use memcpy() to copy value into field
+                    #
+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
+                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
+                else:
+                    if ValueSize > 4:
+                        CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    else:
+                        CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+        CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % ('DEFAULT', 'STANDARD')
+        inherit_OverrideValues = Pcd.SkuOverrideValues['DEFAULT']
+        pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
+        for FieldList in [pcddefaultvalue,inherit_OverrideValues.get('STANDARD')]:
+            if not FieldList:
+                continue
+            if pcddefaultvalue and FieldList == pcddefaultvalue:
+                IsArray = self.IsFieldValueAnArray(FieldList)
+                if IsArray:
+                    try:
+                        FieldList = ValueExpressionEx(FieldList, "VOID*")(True)
+                    except BadExpression:
+                        EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %
+                                        (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))
+                Value, ValueSize = ParseFieldValue (FieldList)
+                if isinstance(Value, str):
+                    CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                elif IsArray:
+                #
+                # Use memcpy() to copy value into field
+                #
+                    CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                    CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
+                continue
+            for FieldName in FieldList:
+                IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
+                if IsArray:
+                    try:
+                        FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
+                    except BadExpression:
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
+                                        (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))
+                try:
+                    Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
+                except Exception:
+                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
+                if isinstance(Value, str):
+                    CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                elif IsArray:
+                #
+                # Use memcpy() to copy value into field
+                #
+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
+                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
+                else:
+                    if ValueSize > 4:
+                        CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    else:
+                        CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+        CApp = CApp + "}\n"
+        return CApp
+    def GenerateDefaultValueAssignStatement(self,Pcd):
+        CApp = '  Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+        return CApp
     def GenerateInitializeFunc(self, SkuName, DefaultStoreName, Pcd, InitByteValue, CApp):
         OverrideValues = {DefaultStoreName:""}
         if Pcd.SkuOverrideValues:
             OverrideValues = Pcd.SkuOverrideValues[SkuName]
         for DefaultStoreName in OverrideValues.keys():
@@ -1598,69 +1770,11 @@ class DscBuildData(PlatformBuildClassObject):
             # array member is detected, and the size is based on the highest index used with
             # the flexible array member.  The flexible array member must be the last field
             # in a structure.  The size formula for this case is:
             # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
             #
-            CApp = CApp + '  Size = sizeof(%s);\n' % (Pcd.DatumType)
-            CApp = CApp + "// Default Value in Dec \n"
-            for FieldList in [Pcd.DefaultValues]:
-                if not FieldList:
-                    continue
-                for FieldName in FieldList:
-                    FieldName = "." + FieldName
-                    IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
-                    if IsArray:
-                        try:
-                            Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)
-                        except BadExpression:
-                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
-                                            (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
-                        Value, ValueSize = ParseFieldValue(Value)
-                        CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
-                    else:
-                        NewFieldName = ''
-                        FieldName_ori = FieldName.strip('.')
-                        while '[' in  FieldName:
-                            NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
-                            ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])
-                            FieldName = FieldName.split(']', 1)[1]
-                        FieldName = NewFieldName + FieldName
-                        while '[' in FieldName:
-                            FieldName = FieldName.rsplit('[', 1)[0]
-                            CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
-            for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
-                inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]
-                storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName]
-                for defaultstorenameitem in storeset:
-                    CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
-                    for FieldList in [inherit_OverrideValues.get(defaultstorenameitem)]:
-                        if not FieldList:
-                            continue
-                        for FieldName in FieldList:
-                            FieldName = "." + FieldName
-                            IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
-                            if IsArray:
-                                try:
-                                    Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)
-                                except BadExpression:
-                                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
-                                                    (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
-                                Value, ValueSize = ParseFieldValue(Value)
-                                CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
-                            else:
-                                NewFieldName = ''
-                                FieldName_ori = FieldName.strip('.')
-                                while '[' in  FieldName:
-                                    NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'
-                                    ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])
-                                    FieldName = FieldName.split(']', 1)[1]
-                                FieldName = NewFieldName + FieldName
-                                while '[' in FieldName:
-                                    FieldName = FieldName.rsplit('[', 1)[0]
-                                    CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
-                if skuname == SkuName:
-                    break
+            CApp = CApp + self.GenerateSizeStatments(Pcd)
 
             #
             # Allocate and zero buffer for the PCD
             # Must handle cases where current value is smaller, larger, or same size
             # Always keep that larger one as the current size
@@ -1675,59 +1789,14 @@ class DscBuildData(PlatformBuildClassObject):
             CApp = CApp + '  memcpy (Pcd, OriginalPcd, OriginalSize);\n'
 
             #
             # Assign field values in PCD
             #
-            CApp = CApp + "// Default value in Dec \n"
-            DefaultValueFromDec = Pcd.DefaultValueFromDec
-            IsArray = self.IsFieldValueAnArray(Pcd.DefaultValueFromDec)
-            if IsArray:
-                try:
-                    DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, "VOID*")(True)
-                except BadExpression:
-                    EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %
-                                    (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))
-            Value, ValueSize = ParseFieldValue (DefaultValueFromDec)
-            if isinstance(Value, str):
-                CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)
-            elif IsArray:
-            #
-            # Use memcpy() to copy value into field
-            #
-                CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
-                CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
-            for FieldList in [Pcd.DefaultValues]:
-                if not FieldList:
-                    continue
-                for FieldName in FieldList:
-                    IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
-                    if IsArray:
-                        try:
-                            FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
-                        except BadExpression:
-                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
-                                            (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1],FieldList[FieldName][2]))
-
-                    try:
-                        Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
-                    except Exception:
-                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
-                    if isinstance(Value, str):
-                        CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                    elif IsArray:
-                        #
-                        # Use memcpy() to copy value into field
-                        #
-                        CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
-                        CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                        CApp = CApp + '  memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
-                    else:
-                        if ValueSize > 4:
-                            CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                        else:
-                            CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+            CApp = CApp + self.GenerateDefaultValueAssignStatement(Pcd)
             for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
+                if skuname == "DEFAULT":
+                    continue
                 inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]
                 storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName]
                 for defaultstorenameitem in storeset:
                     CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
                     pcddefaultvalue = Pcd.DefaultFromDSC.get(skuname,{}).get(defaultstorenameitem, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
@@ -1770,11 +1839,11 @@ class DscBuildData(PlatformBuildClassObject):
                             #
                             # Use memcpy() to copy value into field
                             #
                                 CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
                                 CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                                CApp = CApp + '  memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
+                                CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                             else:
                                 if ValueSize > 4:
                                     CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                                 else:
                                     CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
@@ -1811,10 +1880,12 @@ class DscBuildData(PlatformBuildClassObject):
                     Includes[IncludeFile] = True
                     CApp = CApp + '#include <%s>\n' % (IncludeFile)
         CApp = CApp + '\n'
         for PcdName in StructuredPcds:
             Pcd = StructuredPcds[PcdName]
+            CApp = CApp + self.GenerateSizeFunction(Pcd)
+            CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)
             if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
                 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
-- 
2.14.3.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Patch 4/4] BaseTools: Improve build performance
  2018-02-28  5:59 [Patch 1/4] BaseTools: Fixed the pcd value override issue BobCF
  2018-02-28  5:59 ` [Patch 2/4] BaseTools: Improve build performance BobCF
  2018-02-28  5:59 ` [Patch 3/4] BaseTool: GUID assignment fail BobCF
@ 2018-02-28  5:59 ` BobCF
  2018-02-28  6:46 ` [Patch 1/4] BaseTools: Fixed the pcd value override issue Gao, Liming
  3 siblings, 0 replies; 5+ messages in thread
From: BobCF @ 2018-02-28  5:59 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

Optimized the PcdValueInit.c size.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 .../Source/Python/Workspace/BuildClassObject.py    |   4 +
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 211 +++++++++++----------
 2 files changed, 112 insertions(+), 103 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 05a83e84ac..edf2bdf4b9 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -63,10 +63,11 @@ class PcdClassObject(object):
         self.IsFromDsc = False
         self.validateranges = validateranges
         self.validlists = validlists
         self.expressions = expressions
         self.DscDefaultValue = None
+        self.DscRawValue = None
         if IsDsc:
             self.DscDefaultValue = Value
 
     ## Convert the class to a string
     #
@@ -125,10 +126,11 @@ class StructurePcd(PcdClassObject):
         self.FlexibleFieldName = None
         self.StructName = None
         self.PcdDefineLineNo = 0
         self.PkgPath = ""
         self.DefaultValueFromDec = ""
+        self.ValueChain = dict()
     def __repr__(self):
         return self.TypeName
 
     def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
         if FieldName in self.DefaultValues:
@@ -170,10 +172,11 @@ class StructurePcd(PcdClassObject):
         self.IsFromBinaryInf = PcdObject.IsFromBinaryInf if PcdObject.IsFromBinaryInf else self.IsFromBinaryInf
         self.IsFromDsc = PcdObject.IsFromDsc if PcdObject.IsFromDsc else self.IsFromDsc
         self.validateranges = PcdObject.validateranges if PcdObject.validateranges else self.validateranges
         self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists
         self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions
+        self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue
         if type(PcdObject) is StructurePcd:
             self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile
             self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs
             self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
             self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
@@ -182,10 +185,11 @@ class StructurePcd(PcdClassObject):
             self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
             self.FlexibleFieldName = PcdObject.FlexibleFieldName if PcdObject.FlexibleFieldName else self.FlexibleFieldName
             self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName
             self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo
             self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else self.PkgPath
+            self.ValueChain = PcdObject.ValueChain if PcdObject.ValueChain else self.ValueChain
 
 ## LibraryClassObject
 #
 # This Class defines LibraryClassObject used in BuildDatabase
 #
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 29c43e751f..580fcdefc2 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1329,16 +1329,19 @@ class DscBuildData(PlatformBuildClassObject):
             for skuid in SkuIds:
                 if skuid in stru_pcd.SkuOverrideValues:
                     continue
                 nextskuid = self.SkuIdMgr.GetNextSkuId(skuid)
                 NoDefault = False
-                while nextskuid not in stru_pcd.SkuOverrideValues:
-                    if nextskuid == "DEFAULT":
-                        NoDefault = True
-                        break
-                    nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
-                stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {'STANDARD':stru_pcd.DefaultValues})
+                if skuid not in stru_pcd.SkuOverrideValues:
+                    while nextskuid not in stru_pcd.SkuOverrideValues:
+                        if nextskuid == "DEFAULT":
+                            NoDefault = True
+                            break
+                        nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
+                    stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {'STANDARD':stru_pcd.DefaultValues})
+                    if not NoDefault:
+                        stru_pcd.ValueChain[(skuid,'')]= (nextskuid,'')
             if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
                 for skuid in SkuIds:
                     nextskuid = skuid
                     NoDefault = False
                     if skuid not in stru_pcd.SkuOverrideValues:
@@ -1353,10 +1356,11 @@ class DscBuildData(PlatformBuildClassObject):
                     mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)
 
                     for defaultstoreid in DefaultStores:
                         if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:
                             stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])
+                            stru_pcd.ValueChain[(skuid,defaultstoreid)]= (nextskuid,mindefaultstorename)
         S_pcd_set = self.OverrideByFdfComm(S_pcd_set)
         Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)
         if Str_Pcd_Values:
             for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values:
                 str_pcd_obj = S_pcd_set.get((PcdName, PcdGuid))
@@ -1676,14 +1680,28 @@ class DscBuildData(PlatformBuildClassObject):
                 else:
                     if ValueSize > 4:
                         CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     else:
                         CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+        CApp = CApp + "}\n"
+        return CApp
+    def GenerateDefaultValueAssignStatement(self,Pcd):
+        CApp = '  Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+        return CApp
+    def GenerateInitValueFunction(self,Pcd,SkuName,DefaultStoreName):
+        CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName,DefaultStoreName)
+        CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,DefaultStoreName,Pcd.DatumType)
+        CApp = CApp + '  UINT32  FieldSize;\n'
+        CApp = CApp + '  CHAR8   *Value;\n'
+
         CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % ('DEFAULT', 'STANDARD')
-        inherit_OverrideValues = Pcd.SkuOverrideValues['DEFAULT']
-        pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
-        for FieldList in [pcddefaultvalue,inherit_OverrideValues.get('STANDARD')]:
+        inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]
+        if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'):
+            pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
+        else:
+            pcddefaultvalue = Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName)
+        for FieldList in [pcddefaultvalue,inherit_OverrideValues.get(DefaultStoreName)]:
             if not FieldList:
                 continue
             if pcddefaultvalue and FieldList == pcddefaultvalue:
                 IsArray = self.IsFieldValueAnArray(FieldList)
                 if IsArray:
@@ -1691,52 +1709,64 @@ class DscBuildData(PlatformBuildClassObject):
                         FieldList = ValueExpressionEx(FieldList, "VOID*")(True)
                     except BadExpression:
                         EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %
                                         (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))
                 Value, ValueSize = ParseFieldValue (FieldList)
-                if isinstance(Value, str):
-                    CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
-                elif IsArray:
-                #
-                # Use memcpy() to copy value into field
-                #
-                    CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
-                    CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
+
+                if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'):
+                    if isinstance(Value, str):
+                        CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                    elif IsArray:
+                    #
+                    # Use memcpy() to copy value into field
+                    #
+                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                        CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
+                else:
+                    if isinstance(Value, str):
+                        CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName))
+                    elif IsArray:
+                    #
+                    # Use memcpy() to copy value into field
+                    #
+                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName))
+                        CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
                 continue
-            for FieldName in FieldList:
-                IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
-                if IsArray:
+            if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD') or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )):
+                for FieldName in FieldList:
+                    IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
+                    if IsArray:
+                        try:
+                            FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
+                        except BadExpression:
+                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
+                                            (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))
                     try:
-                        FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
-                    except BadExpression:
-                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
-                                        (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))
-                try:
-                    Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
-                except Exception:
-                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
-                if isinstance(Value, str):
-                    CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                elif IsArray:
-                #
-                # Use memcpy() to copy value into field
-                #
-                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
-                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
-                else:
-                    if ValueSize > 4:
-                        CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                        Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
+                    except Exception:
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
+                    if isinstance(Value, str):
+                        CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    elif IsArray:
+                    #
+                    # Use memcpy() to copy value into field
+                    #
+                        CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
+                        CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                        CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                     else:
-                        CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                        if ValueSize > 4:
+                            CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                        else:
+                            CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
         CApp = CApp + "}\n"
         return CApp
-    def GenerateDefaultValueAssignStatement(self,Pcd):
-        CApp = '  Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+    def GenerateInitValueStatement(self,Pcd,SkuName,DefaultStoreName):
+        CApp = '  Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,DefaultStoreName)
         return CApp
-    def GenerateInitializeFunc(self, SkuName, DefaultStoreName, Pcd, InitByteValue, CApp):
-        OverrideValues = {DefaultStoreName:""}
+    def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteValue, CApp):
+        OverrideValues = {DefaultStore:""}
         if Pcd.SkuOverrideValues:
             OverrideValues = Pcd.SkuOverrideValues[SkuName]
         for DefaultStoreName in OverrideValues.keys():
             CApp = CApp + 'void\n'
             CApp = CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
@@ -1750,11 +1780,11 @@ class DscBuildData(PlatformBuildClassObject):
             CApp = CApp + '  VOID    *OriginalPcd;\n'
             CApp = CApp + '  %s      *Pcd;  // From %s Line %d \n' % (Pcd.DatumType, Pcd.PkgPath, Pcd.PcdDefineLineNo)
             CApp = CApp + '\n'
 
             if SkuName in Pcd.SkuInfoList:
-                DefaultValue = Pcd.SkuInfoList[SkuName].DefaultStoreDict.get(DefaultStoreName,Pcd.SkuInfoList[SkuName].HiiDefaultValue) if Pcd.SkuInfoList[SkuName].HiiDefaultValue  else Pcd.SkuInfoList[SkuName].DefaultValue
+                DefaultValue = Pcd.SkuInfoList[SkuName].DefaultStoreDict.get(DefaultStoreName,Pcd.SkuInfoList[SkuName].HiiDefaultValue if Pcd.SkuInfoList[SkuName].HiiDefaultValue  else Pcd.SkuInfoList[SkuName].DefaultValue)
             else:
                 DefaultValue = Pcd.DefaultValue
             PcdDefaultValue = StringToArray(DefaultValue.strip())
 
             InitByteValue += '%s.%s.%s.%s|%s|%s\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DatumType, PcdDefaultValue)
@@ -1790,67 +1820,22 @@ class DscBuildData(PlatformBuildClassObject):
 
             #
             # Assign field values in PCD
             #
             CApp = CApp + self.GenerateDefaultValueAssignStatement(Pcd)
-            for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
-                if skuname == "DEFAULT":
-                    continue
-                inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]
-                storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName]
-                for defaultstorenameitem in storeset:
-                    CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
-                    pcddefaultvalue = Pcd.DefaultFromDSC.get(skuname,{}).get(defaultstorenameitem, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
-                    for FieldList in [pcddefaultvalue,inherit_OverrideValues.get(defaultstorenameitem)]:
-                        if not FieldList:
-                            continue
-                        if pcddefaultvalue and FieldList == pcddefaultvalue:
-                            IsArray = self.IsFieldValueAnArray(FieldList)
-                            if IsArray:
-                                try:
-                                    FieldList = ValueExpressionEx(FieldList, "VOID*")(True)
-                                except BadExpression:
-                                    EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %
-                                                    (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))
-                            Value, ValueSize = ParseFieldValue (FieldList)
-                            if isinstance(Value, str):
-                                CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get(skuname,{}).get(defaultstorenameitem, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
-                            elif IsArray:
-                            #
-                            # Use memcpy() to copy value into field
-                            #
-                                CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get(skuname,{}).get(defaultstorenameitem, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
-                                CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
-                            continue
-                        for FieldName in FieldList:
-                            IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
-                            if IsArray:
-                                try:
-                                    FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)
-                                except BadExpression:
-                                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
-                                                    (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))
-                            try:
-                                Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
-                            except Exception:
-                                EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
-                            if isinstance(Value, str):
-                                CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                            elif IsArray:
-                            #
-                            # Use memcpy() to copy value into field
-                            #
-                                CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
-                                CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                                CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
-                            else:
-                                if ValueSize > 4:
-                                    CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                                else:
-                                    CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
-                if skuname == SkuName:
-                    break
+            if Pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
+                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
+                for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
+                    storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName]
+                    for defaultstorenameitem in storeset:
+                        CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
+                        CApp = CApp + self.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem)
+                    if skuname == SkuName:
+                        break
+            else:
+                CApp = CApp + "// SkuName: DEFAULT,  DefaultStoreName: STANDARD \n"
+                CApp = CApp + self.GenerateInitValueStatement(Pcd,"DEFAULT","STANDARD")
             #
             # Set new PCD value and size
             #
             CApp = CApp + '  PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 *)Pcd);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
 
@@ -1882,10 +1867,19 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + '\n'
         for PcdName in StructuredPcds:
             Pcd = StructuredPcds[PcdName]
             CApp = CApp + self.GenerateSizeFunction(Pcd)
             CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)
+            if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
+                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
+                CApp = CApp + self.GenerateInitValueFunction(Pcd,self.SkuIdMgr.SystemSkuId, 'STANDARD')
+            else:
+                for SkuName in self.SkuIdMgr.SkuOverrideOrder():
+                    if SkuName not in Pcd.SkuOverrideValues:
+                        continue
+                    for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:
+                        CApp = CApp + self.GenerateInitValueFunction(Pcd,SkuName,DefaultStoreName)
             if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
                 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
@@ -2198,10 +2192,20 @@ class DscBuildData(PlatformBuildClassObject):
         Attr2Set = set(Attr2s)
         if Attr2Set == Attr1Set:
             return True
         else:
             return False
+    def CopyDscRawValue(self,Pcd):
+        if Pcd.DscRawValue is None:
+            Pcd.DscRawValue = dict()
+        for skuname in Pcd.SkuInfoList:
+            Pcd.DscRawValue[skuname] = {}
+            if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
+                for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict:
+                    Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore]
+            else:
+                Pcd.DscRawValue[skuname]['STANDARD'] = Pcd.SkuInfoList[skuname].DefaultValue
     def CompletePcdValues(self,PcdSet):
         Pcds = {}
         DefaultStoreObj = DefaultStore(self._GetDefaultStores())
         SkuIds = {skuname:skuid for skuname,skuid in self.SkuIdMgr.AvailableSkuIdSet.items() if skuname !='COMMON'}
         DefaultStores = set([storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict.keys()])
@@ -2213,10 +2217,11 @@ class DscBuildData(PlatformBuildClassObject):
                         self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],
                         self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],
                         self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]:
                 Pcds[PcdCName, TokenSpaceGuid]= PcdObj
                 continue
+            self.CopyDscRawValue(PcdObj)
             PcdType = PcdObj.Type
             if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
                 for skuid in PcdObj.SkuInfoList:
                     skuobj = PcdObj.SkuInfoList[skuid]
                     mindefaultstorename = DefaultStoreObj.GetMin(set([defaultstorename  for defaultstorename in skuobj.DefaultStoreDict]))
-- 
2.14.3.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch 1/4] BaseTools: Fixed the pcd value override issue.
  2018-02-28  5:59 [Patch 1/4] BaseTools: Fixed the pcd value override issue BobCF
                   ` (2 preceding siblings ...)
  2018-02-28  5:59 ` [Patch 4/4] BaseTools: Improve build performance BobCF
@ 2018-02-28  6:46 ` Gao, Liming
  3 siblings, 0 replies; 5+ messages in thread
From: Gao, Liming @ 2018-02-28  6:46 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Feng, Bob C
> Sent: Wednesday, February 28, 2018 1:59 PM
> To: edk2-devel@lists.01.org
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [Patch 1/4] BaseTools: Fixed the pcd value override issue.
> 
> 1. the issue in the overriding value from command line.
> 2. dec fully value < dec field assign value <
>    dsc fully value < dsc field assign value
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  BaseTools/Source/Python/AutoGen/GenMake.py         | 39 +++++++++++-----------
>  .../Source/Python/Workspace/BuildClassObject.py    |  4 +++
>  BaseTools/Source/Python/Workspace/DecBuildData.py  |  1 +
>  BaseTools/Source/Python/Workspace/DscBuildData.py  | 24 ++++++++++---
>  4 files changed, 44 insertions(+), 24 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
> index 4b924d21e0..1b0cf17e25 100644
> --- a/BaseTools/Source/Python/AutoGen/GenMake.py
> +++ b/BaseTools/Source/Python/AutoGen/GenMake.py
> @@ -1549,30 +1549,29 @@ class TopLevelMakefile(BuildFile):
>          if GlobalData.gEnableGenfdsMultiThread:
>              ExtraOption += " --genfds-multi-thread"
>          if GlobalData.gIgnoreSource:
>              ExtraOption += " --ignore-sources"
> 
> -        if GlobalData.BuildOptionPcd:
> -            for index, option in enumerate(GlobalData.gCommand):
> -                if "--pcd" == option and GlobalData.gCommand[index+1]:
> -                    pcdName, pcdValue = GlobalData.gCommand[index+1].split('=')
> -                    for Item in GlobalData.BuildOptionPcd:
> -                        if '.'.join(Item[0:2]) == pcdName:
> -                            pcdValue = Item[2]
> -                            if pcdValue.startswith('L') or pcdValue.startswith('"'):
> -                                pcdValue, Size = ParseFieldValue(pcdValue)
> -                                NewVal = '{'
> -                                for S in range(Size):
> -                                    NewVal = NewVal + '0x%02X' % ((pcdValue >> S * 8) & 0xff)
> -                                    NewVal += ','
> -                                pcdValue =  NewVal[:-1] + '}'
> -                            break
> -                    if pcdValue.startswith('{'):
> -                        pcdValue = 'H' + '"' + pcdValue + '"'
> -                        ExtraOption += " --pcd " + pcdName + '=' + pcdValue
> -                    else:
> -                        ExtraOption += " --pcd " + GlobalData.gCommand[index+1]
> +        for index, option in enumerate(GlobalData.gCommand):
> +            if "--pcd" == option and GlobalData.gCommand[index+1]:
> +                pcdName, pcdValue = GlobalData.gCommand[index+1].split('=')
> +                for Item in GlobalData.BuildOptionPcd:
> +                    if '.'.join(Item[0:2]) == pcdName:
> +                        pcdValue = Item[2]
> +                        if pcdValue.startswith('L') or pcdValue.startswith('"'):
> +                            pcdValue, Size = ParseFieldValue(pcdValue)
> +                            NewVal = '{'
> +                            for S in range(Size):
> +                                NewVal = NewVal + '0x%02X' % ((pcdValue >> S * 8) & 0xff)
> +                                NewVal += ','
> +                            pcdValue =  NewVal[:-1] + '}'
> +                        break
> +                if pcdValue.startswith('{'):
> +                    pcdValue = 'H' + '"' + pcdValue + '"'
> +                    ExtraOption += " --pcd " + pcdName + '=' + pcdValue
> +                else:
> +                    ExtraOption += " --pcd " + GlobalData.gCommand[index+1]
> 
>          MakefileName = self._FILE_NAME_[self._FileType]
>          SubBuildCommandList = []
>          for A in PlatformInfo.ArchList:
>              Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}
> diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
> index f499cbd58b..05a83e84ac 100644
> --- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
> +++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
> @@ -124,19 +124,22 @@ class StructurePcd(PcdClassObject):
>          self.SkuOverrideValues = collections.OrderedDict({})
>          self.FlexibleFieldName = None
>          self.StructName = None
>          self.PcdDefineLineNo = 0
>          self.PkgPath = ""
> +        self.DefaultValueFromDec = ""
>      def __repr__(self):
>          return self.TypeName
> 
>      def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
>          if FieldName in self.DefaultValues:
>              del self.DefaultValues[FieldName]
>          self.DefaultValues[FieldName] = [Value.strip(), FileName, LineNo]
>          return self.DefaultValues[FieldName]
> 
> +    def SetDecDefaultValue(self,DefaultValue):
> +        self.DefaultValueFromDec = DefaultValue
>      def AddOverrideValue (self, FieldName, Value, SkuName, DefaultStoreName, FileName="", LineNo=0):
>          if SkuName not in self.SkuOverrideValues:
>              self.SkuOverrideValues[SkuName] = collections.OrderedDict({})
>          if DefaultStoreName not in self.SkuOverrideValues[SkuName]:
>              self.SkuOverrideValues[SkuName][DefaultStoreName] = collections.OrderedDict({})
> @@ -173,10 +176,11 @@ class StructurePcd(PcdClassObject):
>              self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else
> self.StructuredPcdIncludeFile
>              self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs
>              self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
>              self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
>              self.DefaultFromDSC=None
> +            self.DefaultValueFromDec = PcdObject.DefaultValueFromDec if PcdObject.DefaultValueFromDec else
> self.DefaultValueFromDec
>              self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
>              self.FlexibleFieldName = PcdObject.FlexibleFieldName if PcdObject.FlexibleFieldName else self.FlexibleFieldName
>              self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName
>              self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo
>              self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else self.PkgPath
> diff --git a/BaseTools/Source/Python/Workspace/DecBuildData.py b/BaseTools/Source/Python/Workspace/DecBuildData.py
> index 99c3bf14f1..61f15086d0 100644
> --- a/BaseTools/Source/Python/Workspace/DecBuildData.py
> +++ b/BaseTools/Source/Python/Workspace/DecBuildData.py
> @@ -383,10 +383,11 @@ class DecBuildData(PackageBuildClassObject):
>                      struct_pcd.copy(item)
>                      struct_pcd.TokenValue = struct_pcd.TokenValue.strip("{").strip()
>                      struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName = pcdname.split(".")
>                      struct_pcd.PcdDefineLineNo = LineNo
>                      struct_pcd.PkgPath = self.MetaFile.File
> +                    struct_pcd.SetDecDefaultValue(item.DefaultValue)
>                  else:
>                      struct_pcd.AddDefaultValue(item.TokenCName, item.DefaultValue,self.MetaFile.File,LineNo)
> 
>              struct_pcd.PackageDecs = dep_pkgs
>              if not struct_pcd.StructuredPcdIncludeFile:
> diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
> index ea8d1847f7..393ad0265f 100644
> --- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> @@ -892,16 +892,15 @@ class DscBuildData(PlatformBuildClassObject):
>          if GlobalData.BuildOptionPcd:
>              for pcd in GlobalData.BuildOptionPcd:
>                  if pcd[2] == "":
>                      pcdset.append((pcd[0],pcd[1],pcd[3]))
>                  else:
> -                    pcdobj = self._Pcds.get((pcd[1],pcd[0]))
> -                    if pcdobj:
> -                        pcdset.append((pcd[0],pcd[1], pcdobj.DefaultValue))
> -                    else:
> +                    if (pcd[1],pcd[0]) not in self._Pcds:
>                          pcdvalue = pcd[3] if len(pcd) == 4 else pcd[2]
>                          pcdset.append((pcd[0],pcd[1],pcdvalue))
> +                    #else:
> +                        # remove the settings from command line since it has been handled.
>          GlobalData.BuildOptionPcd = pcdset
>      def GetFieldValueFromComm(self,ValueStr,TokenSpaceGuidCName, TokenCName, FieldName):
>          PredictedFieldType = "VOID*"
>          if ValueStr.startswith('L'):
>              if not ValueStr[1]:
> @@ -1674,10 +1673,27 @@ class DscBuildData(PlatformBuildClassObject):
> 
>              #
>              # Assign field values in PCD
>              #
>              CApp = CApp + "// Default value in Dec \n"
> +            DefaultValueFromDec = Pcd.DefaultValueFromDec
> +            IsArray = self.IsFieldValueAnArray(Pcd.DefaultValueFromDec)
> +            if IsArray:
> +                try:
> +                    DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, "VOID*")(True)
> +                except BadExpression:
> +                    EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %
> +                                    (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))
> +            Value, ValueSize = ParseFieldValue (DefaultValueFromDec)
> +            if isinstance(Value, str):
> +                CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)
> +            elif IsArray:
> +            #
> +            # Use memcpy() to copy value into field
> +            #
> +                CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (self.IntToCString(Value, ValueSize),
> Pcd.DefaultValueFromDec)
> +                CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
>              for FieldList in [Pcd.DefaultValues]:
>                  if not FieldList:
>                      continue
>                  for FieldName in FieldList:
>                      IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
> --
> 2.14.3.windows.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-02-28  6:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-28  5:59 [Patch 1/4] BaseTools: Fixed the pcd value override issue BobCF
2018-02-28  5:59 ` [Patch 2/4] BaseTools: Improve build performance BobCF
2018-02-28  5:59 ` [Patch 3/4] BaseTool: GUID assignment fail BobCF
2018-02-28  5:59 ` [Patch 4/4] BaseTools: Improve build performance BobCF
2018-02-28  6:46 ` [Patch 1/4] BaseTools: Fixed the pcd value override issue Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox