BaseTools: fix imports

1 - Some of these imports are cascaded from another file. Import them locally.
2 - Some of these imports are not used. Remove them.
3 - Some of these were missing the namespace used to import them.

These changes facilitate optimization of BaseTools:
https://bugzilla.tianocore.org/show_bug.cgi?id=42

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Carsey, Jaben 2019-01-10 03:00:41 +08:00 committed by BobCF
parent a53a888de8
commit 938cf4c33a
14 changed files with 38 additions and 32 deletions

View File

@ -1,7 +1,7 @@
## @file ## @file
# Generate AutoGen.h, AutoGen.c and *.depex files # Generate AutoGen.h, AutoGen.c and *.depex files
# #
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR> # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
# #
# This program and the accompanying materials # This program and the accompanying materials
@ -52,6 +52,7 @@ from .GenVar import VariableMgr, var_info
from collections import OrderedDict from collections import OrderedDict
from collections import defaultdict from collections import defaultdict
from Workspace.WorkspaceCommon import OrderedListDict from Workspace.WorkspaceCommon import OrderedListDict
from Common.ToolDefClassObject import gDefaultToolsDefFile
from Common.caching import cached_property, cached_class_function from Common.caching import cached_property, cached_class_function
@ -85,9 +86,6 @@ gMakeTypeMap = {TAB_COMPILER_MSFT:"nmake", "GCC":"gmake"}
## Build rule configuration file ## Build rule configuration file
gDefaultBuildRuleFile = 'build_rule.txt' gDefaultBuildRuleFile = 'build_rule.txt'
## Tools definition configuration file
gDefaultToolsDefFile = 'tools_def.txt'
## Build rule default version ## Build rule default version
AutoGenReqBuildRuleVerNum = "0.1" AutoGenReqBuildRuleVerNum = "0.1"

View File

@ -18,7 +18,7 @@ import string
import collections import collections
import struct import struct
from Common import EdkLogger from Common import EdkLogger
from Common import GlobalData
from Common.BuildToolError import * from Common.BuildToolError import *
from Common.DataType import * from Common.DataType import *
from Common.Misc import * from Common.Misc import *

View File

@ -22,6 +22,9 @@ from Common.VariableAttributes import VariableAttributes
import copy import copy
from struct import unpack from struct import unpack
from Common.DataType import * from Common.DataType import *
from Common import GlobalData
from Common import EdkLogger
import Common.LongFilePathOs as os
DATABASE_VERSION = 7 DATABASE_VERSION = 7

View File

@ -19,6 +19,7 @@ from CommonDataClass.Exceptions import WrnExpression
import uuid import uuid
from Common.Expression import PcdPattern, BaseExpression from Common.Expression import PcdPattern, BaseExpression
from Common.DataType import * from Common.DataType import *
from re import compile
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].' ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].' ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
@ -202,7 +203,7 @@ class RangeExpression(BaseExpression):
NonLetterOpLst = ['+', '-', '&', '|', '^', '!', '=', '>', '<'] NonLetterOpLst = ['+', '-', '&', '|', '^', '!', '=', '>', '<']
RangePattern = re.compile(r'[0-9]+ - [0-9]+') RangePattern = compile(r'[0-9]+ - [0-9]+')
def preProcessRangeExpr(self, expr): def preProcessRangeExpr(self, expr):
# convert hex to int # convert hex to int

View File

@ -1,7 +1,7 @@
## @file ## @file
# This file is used to define each component of tools_def.txt file # This file is used to define each component of tools_def.txt file
# #
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # 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 # which accompanies this distribution. The full text of the license may be found at
@ -20,7 +20,7 @@ import re
from . import EdkLogger from . import EdkLogger
from .BuildToolError import * from .BuildToolError import *
from .TargetTxtClassObject import * from Common.TargetTxtClassObject import TargetTxtDict
from Common.LongFilePathSupport import OpenLongFilePath as open from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.Misc import PathClass from Common.Misc import PathClass
from Common.StringUtils import NormPath from Common.StringUtils import NormPath

View File

@ -40,7 +40,7 @@ from Common.LongFilePathSupport import CodecOpenLongFilePath
## A decorator used to parse macro definition ## A decorator used to parse macro definition
def ParseMacro(Parser): def ParseMacro(Parser):
def MacroParser(self): def MacroParser(self):
Match = gMacroDefPattern.match(self._CurrentLine) Match = GlobalData.gMacroDefPattern.match(self._CurrentLine)
if not Match: if not Match:
# Not 'DEFINE/EDK_GLOBAL' statement, call decorated method # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method
Parser(self) Parser(self)
@ -61,7 +61,7 @@ def ParseMacro(Parser):
EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name, EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name,
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
# Only upper case letters, digit and '_' are allowed # Only upper case letters, digit and '_' are allowed
if not gMacroNamePattern.match(Name): if not GlobalData.gMacroNamePattern.match(Name):
EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*", EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)

View File

@ -1101,7 +1101,7 @@ class FdfParser:
def _GetNextGuid(self): def _GetNextGuid(self):
if not self._GetNextToken(): if not self._GetNextToken():
return False return False
if gGuidPattern.match(self._Token) is not None: if GlobalData.gGuidPattern.match(self._Token) is not None:
return True return True
else: else:
self._UndoToken() self._UndoToken()
@ -1169,7 +1169,7 @@ class FdfParser:
def _GetNextHexNumber(self): def _GetNextHexNumber(self):
if not self._GetNextToken(): if not self._GetNextToken():
return False return False
if gHexPatternAll.match(self._Token): if GlobalData.gHexPatternAll.match(self._Token):
return True return True
else: else:
self._UndoToken() self._UndoToken()

View File

@ -30,6 +30,7 @@ from . import RuleSimpleFile
from . import RuleComplexFile from . import RuleComplexFile
from CommonDataClass.FdfClass import FfsInfStatementClassObject from CommonDataClass.FdfClass import FfsInfStatementClassObject
from Common.MultipleWorkspace import MultipleWorkspace as mws from Common.MultipleWorkspace import MultipleWorkspace as mws
from Common.DataType import SUP_MODULE_USER_DEFINED
from Common.StringUtils import * from Common.StringUtils import *
from Common.Misc import PathClass from Common.Misc import PathClass
from Common.Misc import GuidStructureByteArrayToGuidString from Common.Misc import GuidStructureByteArrayToGuidString
@ -94,7 +95,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
ModuleType = self.InfModule.ModuleType ModuleType = self.InfModule.ModuleType
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if ModuleType != DataType.SUP_MODULE_USER_DEFINED: if ModuleType != SUP_MODULE_USER_DEFINED:
for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys(): for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys():
if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]: if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:
self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType] self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]

View File

@ -1,7 +1,7 @@
## @file ## @file
# generate flash image # generate flash image
# #
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
# #
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # are licensed and made available under the terms and conditions of the BSD License

View File

@ -24,7 +24,6 @@ import Common.LongFilePathOs as os
from .GenFdsGlobalVariable import GenFdsGlobalVariable from .GenFdsGlobalVariable import GenFdsGlobalVariable
from .GenFdsGlobalVariable import FindExtendTool from .GenFdsGlobalVariable import FindExtendTool
from CommonDataClass.FdfClass import GuidSectionClassObject from CommonDataClass.FdfClass import GuidSectionClassObject
from Common import ToolDefClassObject
import sys import sys
from Common import EdkLogger from Common import EdkLogger
from Common.BuildToolError import * from Common.BuildToolError import *

View File

@ -16,8 +16,10 @@ from Common.DataType import *
from Common.Misc import * from Common.Misc import *
from types import * from types import *
from collections import OrderedDict from collections import OrderedDict
from CommonDataClass.DataClass import *
from Workspace.BuildClassObject import PackageBuildClassObject, StructurePcd, PcdClassObject from Workspace.BuildClassObject import PackageBuildClassObject, StructurePcd, PcdClassObject
from Common.GlobalData import gGlobalDefines, gEcpSource
from re import compile
## Platform build information from DEC file ## Platform build information from DEC file
# #
@ -109,7 +111,7 @@ class DecBuildData(PackageBuildClassObject):
@property @property
def _Macros(self): def _Macros(self):
if self._MacroDict is None: if self._MacroDict is None:
self._MacroDict = dict(GlobalData.gGlobalDefines) self._MacroDict = dict(gGlobalDefines)
return self._MacroDict return self._MacroDict
## Get architecture ## Get architecture
@ -298,7 +300,7 @@ class DecBuildData(PackageBuildClassObject):
PublicInclues = [] PublicInclues = []
RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch] RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]
Macros = self._Macros Macros = self._Macros
Macros["EDK_SOURCE"] = GlobalData.gEcpSource Macros["EDK_SOURCE"] = gEcpSource
for Record in RecordList: for Record in RecordList:
File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch) File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch)
LineNo = Record[-1] LineNo = Record[-1]
@ -464,6 +466,7 @@ class DecBuildData(PackageBuildClassObject):
StructurePcds = self.ProcessStructurePcd(StrPcdSet) StructurePcds = self.ProcessStructurePcd(StrPcdSet)
for pcd in StructurePcds: for pcd in StructurePcds:
Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd
StructPattern = compile(r'[_a-zA-Z][0-9A-Za-z_]*$')
for pcd in Pcds.values(): for pcd in Pcds.values():
if pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: if pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:
if not pcd.IsAggregateDatumType(): if not pcd.IsAggregateDatumType():

View File

@ -25,8 +25,8 @@ from Common.Misc import *
from types import * from types import *
from Common.Expression import * from Common.Expression import *
from CommonDataClass.CommonClass import SkuInfoClass from CommonDataClass.CommonClass import SkuInfoClass
from Common.TargetTxtClassObject import * from Common.TargetTxtClassObject import TargetTxtClassObject
from Common.ToolDefClassObject import * from Common.ToolDefClassObject import ToolDefClassObject
from .MetaDataTable import * from .MetaDataTable import *
from .MetaFileTable import * from .MetaFileTable import *
from .MetaFileParser import * from .MetaFileParser import *

View File

@ -36,6 +36,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
from collections import defaultdict from collections import defaultdict
from .MetaFileTable import MetaFileStorage from .MetaFileTable import MetaFileStorage
from .MetaFileCommentParser import CheckInfComment from .MetaFileCommentParser import CheckInfComment
from Common.DataType import TAB_COMMENT_EDK_START, TAB_COMMENT_EDK_END
## RegEx for finding file versions ## RegEx for finding file versions
hexVersionPattern = re.compile(r'0[xX][\da-f-A-F]{5,8}') hexVersionPattern = re.compile(r'0[xX][\da-f-A-F]{5,8}')
@ -45,7 +46,7 @@ CODEPattern = re.compile(r"{CODE\([a-fA-F0-9Xx\{\},\s]*\)}")
## A decorator used to parse macro definition ## A decorator used to parse macro definition
def ParseMacro(Parser): def ParseMacro(Parser):
def MacroParser(self): def MacroParser(self):
Match = gMacroDefPattern.match(self._CurrentLine) Match = GlobalData.gMacroDefPattern.match(self._CurrentLine)
if not Match: if not Match:
# Not 'DEFINE/EDK_GLOBAL' statement, call decorated method # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method
Parser(self) Parser(self)
@ -66,7 +67,7 @@ def ParseMacro(Parser):
EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name, EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name,
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1) ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
# Only upper case letters, digit and '_' are allowed # Only upper case letters, digit and '_' are allowed
if not gMacroNamePattern.match(Name): if not GlobalData.gMacroNamePattern.match(Name):
EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*", EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1) ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
@ -562,10 +563,10 @@ class InfParser(MetaFileParser):
SectionComments.extend(Comments) SectionComments.extend(Comments)
Comments = [] Comments = []
continue continue
if Line.find(DataType.TAB_COMMENT_EDK_START) > -1: if Line.find(TAB_COMMENT_EDK_START) > -1:
IsFindBlockComment = True IsFindBlockComment = True
continue continue
if Line.find(DataType.TAB_COMMENT_EDK_END) > -1: if Line.find(TAB_COMMENT_EDK_END) > -1:
IsFindBlockComment = False IsFindBlockComment = False
continue continue
if IsFindBlockComment: if IsFindBlockComment:

View File

@ -37,8 +37,8 @@ from subprocess import *
from Common import Misc as Utils from Common import Misc as Utils
from Common.LongFilePathSupport import OpenLongFilePath as open from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.TargetTxtClassObject import * from Common.TargetTxtClassObject import TargetTxtClassObject
from Common.ToolDefClassObject import * from Common.ToolDefClassObject import ToolDefClassObject
from Common.DataType import * from Common.DataType import *
from Common.BuildVersion import gBUILD_VERSION from Common.BuildVersion import gBUILD_VERSION
from AutoGen.AutoGen import * from AutoGen.AutoGen import *
@ -884,7 +884,7 @@ class Build():
if os.path.isfile(BuildConfigurationFile) == True: if os.path.isfile(BuildConfigurationFile) == True:
StatusCode = self.TargetTxt.LoadTargetTxtFile(BuildConfigurationFile) StatusCode = self.TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF] ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolDefinitionFile == '': if ToolDefinitionFile == '':
ToolDefinitionFile = gToolsDefinition ToolDefinitionFile = gToolsDefinition
ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile)) ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))
@ -897,16 +897,16 @@ class Build():
# if no ARCH given in command line, get it from target.txt # if no ARCH given in command line, get it from target.txt
if not self.ArchList: if not self.ArchList:
self.ArchList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET_ARCH] self.ArchList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
self.ArchList = tuple(self.ArchList) self.ArchList = tuple(self.ArchList)
# if no build target given in command line, get it from target.txt # if no build target given in command line, get it from target.txt
if not self.BuildTargetList: if not self.BuildTargetList:
self.BuildTargetList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET] self.BuildTargetList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET]
# if no tool chain given in command line, get it from target.txt # if no tool chain given in command line, get it from target.txt
if not self.ToolChainList: if not self.ToolChainList:
self.ToolChainList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG] self.ToolChainList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_TAG]
if self.ToolChainList is None or len(self.ToolChainList) == 0: if self.ToolChainList is None or len(self.ToolChainList) == 0:
EdkLogger.error("build", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.\n") EdkLogger.error("build", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.\n")
@ -936,7 +936,7 @@ class Build():
self.ToolChainFamily = ToolChainFamily self.ToolChainFamily = ToolChainFamily
if self.ThreadNumber is None: if self.ThreadNumber is None:
self.ThreadNumber = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER] self.ThreadNumber = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]
if self.ThreadNumber == '': if self.ThreadNumber == '':
self.ThreadNumber = 0 self.ThreadNumber = 0
else: else:
@ -949,7 +949,7 @@ class Build():
self.ThreadNumber = 1 self.ThreadNumber = 1
if not self.PlatformFile: if not self.PlatformFile:
PlatformFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM] PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM]
if not PlatformFile: if not PlatformFile:
# Try to find one in current directory # Try to find one in current directory
WorkingDirectory = os.getcwd() WorkingDirectory = os.getcwd()