## @file\r
# The engine for building files\r
#\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
# which accompanies this distribution. The full text of the license may be found at\r
\r
# Check input files\r
self.IsMultipleInput = False\r
- self.SourceFileExtList = []\r
+ self.SourceFileExtList = set()\r
for File in Input:\r
Base, Ext = os.path.splitext(File)\r
if Base.find("*") >= 0:\r
# There's no "*" and "?" in file name\r
self.ExtraSourceFileList.append(File)\r
continue\r
- if Ext not in self.SourceFileExtList:\r
- self.SourceFileExtList.append(Ext)\r
+ self.SourceFileExtList.add(Ext)\r
\r
# Check output files\r
self.DestFileList = []\r
CommandString = "\n\t".join(self.CommandList)\r
return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)\r
\r
- ## Check if given file extension is supported by this rule\r
- #\r
- # @param FileExt The extension of a file\r
- #\r
- # @retval True If the extension is supported\r
- # @retval False If the extension is not supported\r
- #\r
- def IsSupported(self, FileExt):\r
- return FileExt in self.SourceFileExtList\r
-\r
def Instantiate(self, Macros={}):\r
NewRuleObject = copy.copy(self)\r
NewRuleObject.BuildTargets = {}\r
def __init__(self, File=None, Content=None, LineIndex=0, SupportedFamily=["MSFT", "INTEL", "GCC", "RVCT"]):\r
self.RuleFile = File\r
# Read build rules from file if it's not none\r
- if File != None:\r
+ if File is not None:\r
try:\r
self.RuleContent = open(File, 'r').readlines()\r
except:\r
EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r
- elif Content != None:\r
+ elif Content is not None:\r
self.RuleContent = Content\r
else:\r
EdkLogger.error("build", PARAMETER_MISSING, ExtraData="No rule file or string given")\r
self._State = ""\r
self._RuleInfo = tdict(True, 2) # {toolchain family : {"InputFile": {}, "OutputFile" : [], "Command" : []}}\r
self._FileType = ''\r
- self._BuildTypeList = []\r
- self._ArchList = []\r
+ self._BuildTypeList = set()\r
+ self._ArchList = set()\r
self._FamilyList = []\r
self._TotalToolChainFamilySet = set()\r
self._RuleObjectList = [] # FileBuildRule object list\r
self.Parse()\r
\r
# some intrinsic rules\r
- self.RuleDatabase[TAB_DEFAULT_BINARY_FILE, "COMMON", "COMMON", "COMMON"] = self._BinaryFileRule\r
+ self.RuleDatabase[TAB_DEFAULT_BINARY_FILE, TAB_COMMON, TAB_COMMON, TAB_COMMON] = self._BinaryFileRule\r
self.FileTypeList.add(TAB_DEFAULT_BINARY_FILE)\r
\r
## Parse the build rule strings\r
\r
# find the build_rule_version\r
if Line and Line[0] == "#" and Line.find(TAB_BUILD_RULE_VERSION) <> -1:\r
- if Line.find("=") <> -1 and Line.find("=") < (len(Line)-1) and (Line[(Line.find("=") + 1):]).split():\r
+ if Line.find("=") <> -1 and Line.find("=") < (len(Line) - 1) and (Line[(Line.find("=") + 1):]).split():\r
self._FileVersion = (Line[(Line.find("=") + 1):]).split()[0]\r
# skip empty or comment line\r
if Line == "" or Line[0] == "#":\r
def EndOfSection(self):\r
Database = self.RuleDatabase\r
# if there's specific toochain family, 'COMMON' doesn't make sense any more\r
- if len(self._TotalToolChainFamilySet) > 1 and 'COMMON' in self._TotalToolChainFamilySet:\r
- self._TotalToolChainFamilySet.remove('COMMON')\r
+ if len(self._TotalToolChainFamilySet) > 1 and TAB_COMMON in self._TotalToolChainFamilySet:\r
+ self._TotalToolChainFamilySet.remove(TAB_COMMON)\r
for Family in self._TotalToolChainFamilySet:\r
Input = self._RuleInfo[Family, self._InputFile]\r
Output = self._RuleInfo[Family, self._OutputFile]\r
#\r
def ParseSectionHeader(self, LineIndex):\r
self._RuleInfo = tdict(True, 2)\r
- self._BuildTypeList = []\r
- self._ArchList = []\r
+ self._BuildTypeList = set()\r
+ self._ArchList = set()\r
self._FamilyList = []\r
self._TotalToolChainFamilySet = set()\r
FileType = ''\r
RuleNameList = self.RuleContent[LineIndex][1:-1].split(',')\r
for RuleName in RuleNameList:\r
- Arch = 'COMMON'\r
- BuildType = 'COMMON'\r
+ Arch = TAB_COMMON\r
+ BuildType = TAB_COMMON\r
TokenList = [Token.strip().upper() for Token in RuleName.split('.')]\r
# old format: Build.File-Type\r
if TokenList[0] == "BUILD":\r
if len(TokenList) == 1:\r
EdkLogger.error("build", FORMAT_INVALID, "Invalid rule section",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
\r
FileType = TokenList[1]\r
if FileType == '':\r
EdkLogger.error("build", FORMAT_INVALID, "No file type given",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
- if self._FileTypePattern.match(FileType) == None:\r
- EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1,\r
+ if self._FileTypePattern.match(FileType) is None:\r
+ EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData="Only character, number (non-first character), '_' and '-' are allowed in file type")\r
# new format: File-Type.Build-Type.Arch\r
else:\r
elif FileType != TokenList[0]:\r
EdkLogger.error("build", FORMAT_INVALID,\r
"Different file types are not allowed in the same rule section",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
if len(TokenList) > 1:\r
BuildType = TokenList[1]\r
if len(TokenList) > 2:\r
Arch = TokenList[2]\r
- if BuildType not in self._BuildTypeList:\r
- self._BuildTypeList.append(BuildType)\r
- if Arch not in self._ArchList:\r
- self._ArchList.append(Arch)\r
+ self._BuildTypeList.add(BuildType)\r
+ self._ArchList.add(Arch)\r
\r
- if 'COMMON' in self._BuildTypeList and len(self._BuildTypeList) > 1:\r
+ if TAB_COMMON in self._BuildTypeList and len(self._BuildTypeList) > 1:\r
EdkLogger.error("build", FORMAT_INVALID,\r
"Specific build types must not be mixed with common one",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
- if 'COMMON' in self._ArchList and len(self._ArchList) > 1:\r
+ if TAB_COMMON in self._ArchList and len(self._ArchList) > 1:\r
EdkLogger.error("build", FORMAT_INVALID,\r
"Specific ARCH must not be mixed with common one",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
\r
self._FileType = FileType\r
elif SectionType != Type:\r
EdkLogger.error("build", FORMAT_INVALID,\r
"Two different section types are not allowed in the same sub-section",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
\r
if len(TokenList) > 1:\r
Family = TokenList[1].strip().upper()\r
else:\r
- Family = "COMMON"\r
+ Family = TAB_COMMON\r
\r
if Family not in FamilyList:\r
FamilyList.append(Family)\r
self._FamilyList = FamilyList\r
self._TotalToolChainFamilySet.update(FamilyList)\r
self._State = SectionType.upper()\r
- if 'COMMON' in FamilyList and len(FamilyList) > 1:\r
+ if TAB_COMMON in FamilyList and len(FamilyList) > 1:\r
EdkLogger.error("build", FORMAT_INVALID,\r
"Specific tool chain family should not be mixed with general one",\r
- File=self.RuleFile, Line=LineIndex+1,\r
+ File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData=self.RuleContent[LineIndex])\r
if self._State not in self._StateHandler:\r
- EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1,\r
+ EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex + 1,\r
ExtraData="Unknown subsection: %s" % self.RuleContent[LineIndex])\r
## Parse <InputFile> sub-section\r
#\r
FileList = [File.strip() for File in self.RuleContent[LineIndex].split(",")]\r
for ToolChainFamily in self._FamilyList:\r
InputFiles = self._RuleInfo[ToolChainFamily, self._State]\r
- if InputFiles == None:\r
+ if InputFiles is None:\r
InputFiles = []\r
self._RuleInfo[ToolChainFamily, self._State] = InputFiles\r
InputFiles.extend(FileList)\r
def ParseCommon(self, LineIndex):\r
for ToolChainFamily in self._FamilyList:\r
Items = self._RuleInfo[ToolChainFamily, self._State]\r
- if Items == None:\r
+ if Items is None:\r
Items = []\r
self._RuleInfo[ToolChainFamily, self._State] = Items\r
Items.append(self.RuleContent[LineIndex])\r