BaseTools: Fix bug for GUIDED tool path override by DSC [BuildOptions]
authorYonghong Zhu <yonghong.zhu@intel.com>
Wed, 15 Feb 2017 06:47:47 +0000 (14:47 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 17 Feb 2017 01:37:12 +0000 (09:37 +0800)
Current the GUIDED tool path can't be override to the different path in
the [BuildOptions] of DSC file. This patch fix the bug.

Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=283
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/GenFds/GenFds.py

index c35f0b2..06e674a 100644 (file)
@@ -1718,7 +1718,10 @@ class PlatformAutoGen(AutoGen):
                         if self.BuildOption[Tool][Attr].startswith('='):\r
                             Value = self.BuildOption[Tool][Attr][1:]\r
                         else:\r
-                            Value += " " + self.BuildOption[Tool][Attr]\r
+                            if Attr != 'PATH':\r
+                                Value += " " + self.BuildOption[Tool][Attr]\r
+                            else:\r
+                                Value = self.BuildOption[Tool][Attr]\r
 \r
                     if Attr == "PATH":\r
                         # Don't put MAKE definition in the file\r
@@ -2381,8 +2384,11 @@ class PlatformAutoGen(AutoGen):
                         if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
                             BuildOptions[Tool][Attr] = Options[Key]\r
                         else:\r
-                            # append options for the same tool\r
-                            BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            # append options for the same tool except PATH\r
+                            if Attr != 'PATH':\r
+                                BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            else:\r
+                                BuildOptions[Tool][Attr] = Options[Key]\r
         # Build Option Family has been checked, which need't to be checked again for family.\r
         if FamilyMatch or FamilyIsNull:\r
             return BuildOptions\r
@@ -2413,8 +2419,11 @@ class PlatformAutoGen(AutoGen):
                         if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
                             BuildOptions[Tool][Attr] = Options[Key]\r
                         else:\r
-                            # append options for the same tool\r
-                            BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            # append options for the same tool except PATH\r
+                            if Attr != 'PATH':\r
+                                BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            else:\r
+                                BuildOptions[Tool][Attr] = Options[Key]\r
         return BuildOptions\r
 \r
     ## Append build options in platform to a module\r
@@ -2473,7 +2482,10 @@ class PlatformAutoGen(AutoGen):
                         BuildOptions[Tool][Attr] = ToolPath\r
                     else:\r
                         Value = mws.handleWsMacro(Value)\r
-                        BuildOptions[Tool][Attr] += " " + Value\r
+                        if Attr != 'PATH':\r
+                            BuildOptions[Tool][Attr] += " " + Value\r
+                        else:\r
+                            BuildOptions[Tool][Attr] = Value\r
         if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
             #\r
             # Override UNI flag only for EDK module.\r
index c2e9418..a8a68da 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # generate flash image\r
 #\r
-#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -30,7 +30,7 @@ from EfiSection import EfiSection
 import StringIO\r
 import Common.TargetTxtClassObject as TargetTxtClassObject\r
 import Common.ToolDefClassObject as ToolDefClassObject\r
-import Common.DataType\r
+from Common.DataType import *\r
 import Common.GlobalData as GlobalData\r
 from Common import EdkLogger\r
 from Common.String import *\r
@@ -45,7 +45,7 @@ from Common.MultipleWorkspace import MultipleWorkspace as mws
 ## Version and Copyright\r
 versionNumber = "1.0" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + versionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2016, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation  All rights reserved."\r
 \r
 ## Tool entrance method\r
 #\r
@@ -424,11 +424,11 @@ def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Val
 #  @param  NameGuid         The Guid name\r
 #\r
 def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
+    ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
     # if user not specify filter, try to deduce it from global data.\r
     if KeyStringList == None or KeyStringList == []:\r
         Target = GenFdsGlobalVariable.TargetName\r
         ToolChain = GenFdsGlobalVariable.ToolChainTag\r
-        ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase\r
         if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:\r
             EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)\r
         KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]\r
@@ -443,6 +443,9 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
     ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
     ToolPathTmp = None\r
     ToolOption = None\r
+    ToolPathKey = None\r
+    ToolOptionKey = None\r
+    KeyList = None\r
     for ToolDef in ToolDefinition.items():\r
         if NameGuid == ToolDef[1]:\r
             KeyList = ToolDef[0].split('_')\r
@@ -452,24 +455,55 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
                   '_' + \\r
                   KeyList[2]\r
             if Key in KeyStringList and KeyList[4] == 'GUID':\r
-\r
-                ToolPath = ToolDefinition.get(Key + \\r
-                                               '_' + \\r
-                                               KeyList[3] + \\r
-                                               '_' + \\r
-                                               'PATH')\r
-\r
-                ToolOption = ToolDefinition.get(Key + \\r
-                                                '_' + \\r
-                                                KeyList[3] + \\r
-                                                '_' + \\r
-                                                'FLAGS')\r
+                ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
+                ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+                ToolPath = ToolDefinition.get(ToolPathKey)\r
+                ToolOption = ToolDefinition.get(ToolOptionKey)\r
                 if ToolPathTmp == None:\r
                     ToolPathTmp = ToolPath\r
                 else:\r
                     if ToolPathTmp != ToolPath:\r
                         EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))\r
 \r
+    BuildOption = {}\r
+    for Arch in CurrentArchList:\r
+        Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]\r
+        # key is (ToolChainFamily, ToolChain, CodeBase)\r
+        for item in Platform.BuildOptions:\r
+            if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:\r
+                if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):\r
+                    if item[1] not in BuildOption:\r
+                        BuildOption[item[1]] = Platform.BuildOptions[item]\r
+        if BuildOption:\r
+            ToolList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH]\r
+            for Index in range(2, -1, -1):\r
+                for Key in dict(BuildOption):\r
+                    List = Key.split('_')\r
+                    if List[Index] == '*':\r
+                        for String in ToolDb[ToolList[Index]]:\r
+                            if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:\r
+                                List[Index] = String\r
+                                NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
+                                if NewKey not in BuildOption:\r
+                                    BuildOption[NewKey] = BuildOption[Key]\r
+                                    continue\r
+                                del BuildOption[Key]\r
+                    elif List[Index] not in ToolDb[ToolList[Index]]:\r
+                        del BuildOption[Key]\r
+    if BuildOption:\r
+        if not KeyList:\r
+            for Op in BuildOption:\r
+                if NameGuid == BuildOption[Op]:\r
+                    KeyList = Op.split('_')\r
+                    Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]\r
+                    if Key in KeyStringList and KeyList[4] == 'GUID':\r
+                        ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
+                        ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
+        if ToolPathKey in BuildOption.keys():\r
+            ToolPathTmp = BuildOption.get(ToolPathKey)\r
+        if ToolOptionKey in BuildOption.keys():\r
+            ToolOption = BuildOption.get(ToolOptionKey)\r
+\r
     GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
     return ToolPathTmp, ToolOption\r
 \r