X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FToolDefClassObject.py;h=73ebdaf6b1793646fffcfc3fe06e1835c510fe99;hp=549f76cee98ca7741cca1e2f49a392914952ba31;hb=1563349a967d7e02c43492ba853babb9c660a083;hpb=40d841f6a8f84e75409178e19e69b95e01bada0f
diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseTools/Source/Python/Common/ToolDefClassObject.py
index 549f76cee9..73ebdaf6b1 100644
--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
@@ -1,7 +1,7 @@
## @file
# This file is used to define each component of tools_def.txt file
#
-# Copyright (c) 2007, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -14,21 +14,30 @@
##
# Import Modules
#
-import os
+import Common.LongFilePathOs as os
import re
import EdkLogger
-from Dictionary import *
from BuildToolError import *
from TargetTxtClassObject import *
+from Common.LongFilePathSupport import OpenLongFilePath as open
+from Common.Misc import PathClass
+from Common.String import NormPath
+import Common.GlobalData as GlobalData
+from Common import GlobalData
+from Common.MultipleWorkspace import MultipleWorkspace as mws
+from DataType import TAB_TOD_DEFINES_TARGET,TAB_TOD_DEFINES_TOOL_CHAIN_TAG,\
+ TAB_TOD_DEFINES_TARGET_ARCH,TAB_TOD_DEFINES_COMMAND_TYPE\
+ ,TAB_TOD_DEFINES_FAMILY,TAB_TOD_DEFINES_BUILDRULEFAMILY
+
##
-# Static vailabes used for pattern
+# Static variables used for pattern
#
gMacroRefPattern = re.compile('(DEF\([^\(\)]+\))')
gEnvRefPattern = re.compile('(ENV\([^\(\)]+\))')
gMacroDefPattern = re.compile("DEFINE\s+([^\s]+)")
-gDefaultToolsDefFile = "Conf/tools_def.txt"
+gDefaultToolsDefFile = "tools_def.txt"
## ToolDefClassObject
#
@@ -41,43 +50,121 @@ gDefaultToolsDefFile = "Conf/tools_def.txt"
# @var MacroDictionary: To store keys and values defined in DEFINE statement
#
class ToolDefClassObject(object):
- def __init__(self, FileName = None):
+ def __init__(self, FileName=None):
self.ToolsDefTxtDictionary = {}
self.MacroDictionary = {}
for Env in os.environ:
self.MacroDictionary["ENV(%s)" % Env] = os.environ[Env]
- if FileName != None:
+ if FileName is not None:
self.LoadToolDefFile(FileName)
## LoadToolDefFile
#
- # Load target.txt file and parse it, return a set structure to store keys and values
+ # Load target.txt file and parse it
#
# @param Filename: Input value for full path of tools_def.txt
#
def LoadToolDefFile(self, FileName):
+ # set multiple workspace
+ PackagesPath = os.getenv("PACKAGES_PATH")
+ mws.setWs(GlobalData.gWorkspace, PackagesPath)
+
+ self.ToolsDefTxtDatabase = {
+ TAB_TOD_DEFINES_TARGET : [],
+ TAB_TOD_DEFINES_TOOL_CHAIN_TAG : [],
+ TAB_TOD_DEFINES_TARGET_ARCH : [],
+ TAB_TOD_DEFINES_COMMAND_TYPE : []
+ }
+
+ self.IncludeToolDefFile(FileName)
+
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]))
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]))
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]))
+
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]))
+
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort()
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort()
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort()
+ self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort()
+
+ KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE]
+ for Index in range(3, -1, -1):
+ for Key in dict(self.ToolsDefTxtDictionary):
+ List = Key.split('_')
+ if List[Index] == '*':
+ for String in self.ToolsDefTxtDatabase[KeyList[Index]]:
+ List[Index] = String
+ NewKey = '%s_%s_%s_%s_%s' % tuple(List)
+ if NewKey not in self.ToolsDefTxtDictionary:
+ self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key]
+ continue
+ del self.ToolsDefTxtDictionary[Key]
+ elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:
+ del self.ToolsDefTxtDictionary[Key]
+
+
+ ## IncludeToolDefFile
+ #
+ # Load target.txt file and parse it as if it's contents were inside the main file
+ #
+ # @param Filename: Input value for full path of tools_def.txt
+ #
+ def IncludeToolDefFile(self, FileName):
FileContent = []
if os.path.isfile(FileName):
try:
- F = open(FileName,'r')
+ F = open(FileName, 'r')
FileContent = F.readlines()
except:
EdkLogger.error("tools_def.txt parser", FILE_OPEN_FAILURE, ExtraData=FileName)
else:
EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=FileName)
- self.ToolsDefTxtDatabase = {
- TAB_TOD_DEFINES_TARGET : [],
- TAB_TOD_DEFINES_TOOL_CHAIN_TAG : [],
- TAB_TOD_DEFINES_TARGET_ARCH : [],
- TAB_TOD_DEFINES_COMMAND_TYPE : []
- }
-
for Index in range(len(FileContent)):
Line = FileContent[Index].strip()
if Line == "" or Line[0] == '#':
continue
+
+ if Line.startswith("!include"):
+ IncFile = Line[8:].strip()
+ Done, IncFile = self.ExpandMacros(IncFile)
+ if not Done:
+ EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
+ "Macro or Environment has not been defined",
+ ExtraData=IncFile[4:-1], File=FileName, Line=Index+1)
+ IncFile = NormPath(IncFile)
+
+ if not os.path.isabs(IncFile):
+ #
+ # try WORKSPACE
+ #
+ IncFileTmp = PathClass(IncFile, GlobalData.gWorkspace)
+ ErrorCode = IncFileTmp.Validate()[0]
+ if ErrorCode != 0:
+ #
+ # try PACKAGES_PATH
+ #
+ IncFileTmp = mws.join(GlobalData.gWorkspace, IncFile)
+ if not os.path.exists(IncFileTmp):
+ #
+ # try directory of current file
+ #
+ IncFileTmp = PathClass(IncFile, os.path.dirname(FileName))
+ ErrorCode = IncFileTmp.Validate()[0]
+ if ErrorCode != 0:
+ EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=IncFile)
+
+ if type(IncFileTmp) is PathClass:
+ IncFile = IncFileTmp.Path
+ else:
+ IncFile = IncFileTmp
+
+ self.IncludeToolDefFile(IncFile)
+ continue
+
NameValuePair = Line.split("=", 1)
if len(NameValuePair) != 2:
EdkLogger.warn("tools_def.txt parser", "Line %d: not correct assignment statement, skipped" % (Index + 1))
@@ -143,31 +230,6 @@ class ToolDefClassObject(object):
EdkLogger.verbose("Line %d: The family is not specified, but BuildRuleFamily is specified for the tool chain: %s" % ((Index + 1), Name))
self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]))
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]))
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]))
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]))
-
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort()
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort()
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort()
- self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort()
-
- KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE]
- for Index in range(3,-1,-1):
- for Key in dict(self.ToolsDefTxtDictionary):
- List = Key.split('_')
- if List[Index] == '*':
- for String in self.ToolsDefTxtDatabase[KeyList[Index]]:
- List[Index] = String
- NewKey = '%s_%s_%s_%s_%s' % tuple(List)
- if NewKey not in self.ToolsDefTxtDictionary:
- self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key]
- continue
- del self.ToolsDefTxtDictionary[Key]
- elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:
- del self.ToolsDefTxtDictionary[Key]
-
## ExpandMacros
#
# Replace defined macros with real value
@@ -177,12 +239,16 @@ class ToolDefClassObject(object):
# @retval Value: The string which has been replaced with real value
#
def ExpandMacros(self, Value):
+ # os.environ contains all environment variables uppercase on Windows which cause the key in the self.MacroDictionary is uppercase, but Ref may not
EnvReference = gEnvRefPattern.findall(Value)
for Ref in EnvReference:
- if Ref not in self.MacroDictionary:
- return False, Ref
- Value = Value.replace(Ref, self.MacroDictionary[Ref])
-
+ if Ref not in self.MacroDictionary and Ref.upper() not in self.MacroDictionary:
+ Value = Value.replace(Ref, "")
+ else:
+ if Ref in self.MacroDictionary:
+ Value = Value.replace(Ref, self.MacroDictionary[Ref])
+ else:
+ Value = Value.replace(Ref, self.MacroDictionary[Ref.upper()])
MacroReference = gMacroRefPattern.findall(Value)
for Ref in MacroReference:
if Ref not in self.MacroDictionary:
@@ -193,18 +259,23 @@ class ToolDefClassObject(object):
## ToolDefDict
#
-# Load tools_def.txt in input workspace dir
+# Load tools_def.txt in input Conf dir
#
-# @param WorkSpace: Workspace dir
+# @param ConfDir: Conf dir
#
# @retval ToolDef An instance of ToolDefClassObject() with loaded tools_def.txt
#
-def ToolDefDict(WorkSpace):
- Target = TargetTxtDict(WorkSpace)
+def ToolDefDict(ConfDir):
+ Target = TargetTxtDict(ConfDir)
ToolDef = ToolDefClassObject()
if DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary:
- gDefaultToolsDefFile = Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
- ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(WorkSpace, gDefaultToolsDefFile)))
+ ToolsDefFile = Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
+ if ToolsDefFile:
+ ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
+ else:
+ ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))
+ else:
+ ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))
return ToolDef
##