Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. Enhanced the format of build_rule.txt to allow module type and arc…
…h information.

2. Enhanced Trim to convert ASL style of include to C style of include
3. Enhanced Trim to convert some EDK coding convention to EDK2 ECP convention
4. Added warning message when encountering unrecognized content in DSC/DEC/INF File


git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1300 7335b38e-4728-0410-8992-fb3ffe349368
  • Loading branch information
jwang36 committed Aug 12, 2008
1 parent 392b60d commit 8a5eb10
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 258 deletions.
13 changes: 9 additions & 4 deletions Source/Python/AutoGen/AutoGen.py
Expand Up @@ -1240,6 +1240,10 @@ def _GetModuleType(self):
def _GetComponentType(self):
return self.Module.ComponentType

## Return the build type
def _GetBuildType(self):
return self.Module.BuildType

## Return the PCD_IS_DRIVER setting
def _GetPcdIsDriver(self):
return self.Module.PcdIsDriver
Expand Down Expand Up @@ -1405,17 +1409,17 @@ def _GetSourceFileList(self):
Base, Ext = path.splitext(SourceFile)

# skip file which needs a tool having no matching toolchain family
FileType, RuleObject = BuildRule.Get(Ext, ToolChainFamily)
FileType, RuleObject = BuildRule[Ext, self.BuildType, self.Arch, ToolChainFamily]
# unicode must be processed by AutoGen
if FileType == "Unicode-Text-File":
if FileType == "UNICODE-TEXT-FILE":
self._UnicodeFileList.append(os.path.join(self.WorkspaceDir, self.SourceDir, SourceFile))

# if there's dxs file, don't use content in [depex] section to generate .depex file
if FileType == "Dependency-Expression-File":
if FileType == "DEPENDENCY-EXPRESSION-FILE":
self._DepexList = []

# no command, no build
if RuleObject != None and RuleObject.CommandList == []:
if RuleObject != None and len(RuleObject.CommandList) == 0:
RuleObject = None
if [SourceFile, FileType, RuleObject] not in self._SourceFileList:
self._SourceFileList.append([SourceFile, FileType, RuleObject])
Expand Down Expand Up @@ -1668,6 +1672,7 @@ def _GetBuildCommand(self):
Version = property(_GetVersion)
ModuleType = property(_GetModuleType)
ComponentType = property(_GetComponentType)
BuildType = property(_GetBuildType)
PcdIsDriver = property(_GetPcdIsDriver)
AutoGenVersion = property(_GetAutoGenVersion)
Macro = property(_GetMacroList)
Expand Down
401 changes: 174 additions & 227 deletions Source/Python/AutoGen/BuildEngine.py

Large diffs are not rendered by default.

39 changes: 20 additions & 19 deletions Source/Python/AutoGen/GenMake.py
Expand Up @@ -469,11 +469,11 @@ def _CreateTemplateDict(self):
ExtraData="[%s]" % str(self._AutoGenObject))

if self._AutoGenObject.IsLibrary:
if "Static-Library-File" in self.DestFileDatabase:
self.ResultFileList = self.DestFileDatabase["Static-Library-File"]
if "STATIC-LIBRARY-FILE" in self.DestFileDatabase:
self.ResultFileList = self.DestFileDatabase["STATIC-LIBRARY-FILE"]
elif self._AutoGenObject.ModuleType == "USER_DEFINED":
if "Dynamic-Library-File" in self.DestFileDatabase:
self.ResultFileList = self.DestFileDatabase["Dynamic-Library-File"]
if "DYNAMIC-LIBRARY-FILE" in self.DestFileDatabase:
self.ResultFileList = self.DestFileDatabase["DYNAMIC-LIBRARY-FILE"]
if len(self.ResultFileList) == 0:
EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",
ExtraData="[%s]" % str(self._AutoGenObject))
Expand Down Expand Up @@ -580,6 +580,8 @@ def ProcessSourceFileList(self):
ExtraData="[%s]" % str(self._AutoGenObject))
Family = self.PlatformInfo.ToolChainFamily["CC"]
BuildRule = self.PlatformInfo.BuildRule
Arch = self._AutoGenObject.Arch
BuildType = self._AutoGenObject.BuildType

CCodeFlag = False
FileList = self._AutoGenObject.SourceFileList
Expand All @@ -589,7 +591,7 @@ def ProcessSourceFileList(self):
# no rule, no build
if SrcFileBuildRule == None:
continue
if SrcFileType == "C-Code-File":
if SrcFileType == "C-CODE-FILE":
CCodeFlag = True
SrcFileName = path.basename(F)
SrcFileBase, SrcFileExt = path.splitext(SrcFileName)
Expand All @@ -615,9 +617,9 @@ def ProcessSourceFileList(self):

while True:
# next target
DstFileType, DstFileBuildRule = BuildRule.Get(SrcFileBuildRule.DestFileExt, Family)
DstFileType, DstFileBuildRule = BuildRule[SrcFileBuildRule.DestFileExt, BuildType, Arch, Family]
if DstFileType == None:
DstFileType = "Unknown-Type-File"
DstFileType = "UNKNOWN-TYPE-FILE"

if DstFileType in self.SourceFileDatabase:
self.SourceFileDatabase[DstFileType].append(DstFile)
Expand All @@ -630,7 +632,7 @@ def ProcessSourceFileList(self):
if DstFileBuildRule not in self.PendingBuildTargetList:
self.PendingBuildTargetList.append(DstFileBuildRule)
break
elif DstFileBuildRule == None or DstFileBuildRule.CommandList == []:
elif DstFileBuildRule == None or len(DstFileBuildRule.CommandList) == 0:
self.ResultFileList.append(DstFile)
break

Expand Down Expand Up @@ -661,11 +663,11 @@ def ProcessSourceFileList(self):

# try to find next target
while True:
DstFileType, DstFileBuildRule = BuildRule.Get(SrcFileBuildRule.DestFileExt, Family)
DstFileType, DstFileBuildRule = BuildRule[SrcFileBuildRule.DestFileExt, BuildType, Arch, Family]
if DstFileType == None:
DstFileType = "Unknown-Type-File"
DstFileType = "UNKNOWN-TYPE-FILE"

if DstFileType in self.SourceFileDatabase:
if DstFileType in self.SourceFileDatabase:
self.SourceFileDatabase[DstFileType].append(DstFile)
else:
if DstFileType not in self.DestFileDatabase:
Expand All @@ -675,7 +677,7 @@ def ProcessSourceFileList(self):
if DstFileBuildRule != None and DstFileBuildRule.IsMultipleInput:
TempBuildTargetList.append(DstFileBuildRule)
break
elif DstFileBuildRule == None or DstFileBuildRule.CommandList == []:
elif DstFileBuildRule == None or len(DstFileBuildRule.CommandList) == 0:
self.ResultFileList.append(DstFile)
break

Expand Down Expand Up @@ -703,10 +705,10 @@ def ProcessSourceFileList(self):

SrcFileRelativePath = os.path.join(self._AutoGenObject.DebugDir, F)

SrcFileType, SrcFileBuildRule = BuildRule.Get(SrcFileExt, Family)
if SrcFileType != None and SrcFileType == "C-Header-File":
SrcFileType, SrcFileBuildRule = BuildRule[SrcFileExt, BuildType, Arch, Family]
if SrcFileType != None and SrcFileType == "C-HEADER-FILE":
ForceIncludedFile.append(SrcFileRelativePath)
if SrcFileBuildRule == None or SrcFileBuildRule.CommandList == []:
if SrcFileBuildRule == None or len(SrcFileBuildRule.CommandList) == 0:
continue

SrcFile, ExtraSrcFileList, DstFile, CommandList = SrcFileBuildRule.Apply(F, self._AutoGenObject.DebugDir, Separator)
Expand All @@ -723,9 +725,9 @@ def ProcessSourceFileList(self):

while True:
# next target
DstFileType, DstFileBuildRule = BuildRule.Get(SrcFileBuildRule.DestFileExt, Family)
DstFileType, DstFileBuildRule = BuildRule[SrcFileBuildRule.DestFileExt, BuildType, Arch, Family]
if DstFileType == None:
DstFileType = "Unknown-Type-File"
DstFileType = "UNKNOWN-TYPE-FILE"

if DstFileType in self.SourceFileDatabase:
self.SourceFileDatabase[DstFileType].append(DstFile)
Expand All @@ -738,7 +740,7 @@ def ProcessSourceFileList(self):
if DstFileBuildRule not in self.PendingBuildTargetList:
self.PendingBuildTargetList.append(DstFileBuildRule)
break
elif DstFileBuildRule == None or DstFileBuildRule.CommandList == []:
elif DstFileBuildRule == None or len(DstFileBuildRule.CommandList) == 0:
self.ResultFileList.append(DstFile)
break

Expand Down Expand Up @@ -789,7 +791,6 @@ def ProcessSourceFileList(self):
Template.Append(TargetTemplate, {"deps" : self.FileDependency[File]})
self.BuildTargetList.append(str(Template))


## Process binary files to generate makefile targets and dependencies
#
# All binary files are just copied to $(OUTPUT_DIR)
Expand Down
2 changes: 1 addition & 1 deletion Source/Python/Common/Misc.py
Expand Up @@ -602,7 +602,7 @@ class tdict:
_ListType = type([])
_TupleType = type(())
_Wildcard = 'COMMON'
_ValidWildcardList = ['COMMON', 'DEFAULT', 'ALL', '', '*', 'PLATFORM']
_ValidWildcardList = ['COMMON', 'DEFAULT', 'ALL', '*', 'PLATFORM']

def __init__(self, _Single_=False, _Level_=2):
self._Level_ = _Level_
Expand Down
150 changes: 144 additions & 6 deletions Source/Python/Trim/Trim.py
Expand Up @@ -21,13 +21,14 @@
from optparse import OptionParser
from optparse import make_option
from Common.BuildToolError import *
from Common.Misc import *

import Common.EdkLogger as EdkLogger

# Version and Copyright
__version_number__ = "0.02"
__version_number__ = "0.04"
__version__ = "%prog Version " + __version_number__
__copyright__ = "Copyright (c) 2007, Intel Corporation. All rights reserved."
__copyright__ = "Copyright (c) 2007-2008, Intel Corporation. All rights reserved."

## Regular expression for matching Line Control directive like "#line xxx"
gLineControlDirective = re.compile('^\s*(#line|#)\s+([0-9]+)\s+"*([^"]*)"*')
Expand All @@ -39,6 +40,57 @@
gHexNumberPattern = re.compile("0[xX]([0-9a-fA-F]+)", re.MULTILINE)
## Regular expression for matching "Include ()" in asl file
gAslIncludePattern = re.compile("^\s*Include\s*\(([^\(\)]+)\)\s*$", re.MULTILINE)
## Patterns used to convert EDK conventions to EDK2 ECP conventions
gImportCodePatterns = [
[
re.compile('^(\s*)\(\*\*PeiServices\)\.PciCfg\s*=\s*([^;\s]+);', re.MULTILINE),
'''\\1{
\\1 STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
\\1 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
\\1 &gEcpPeiPciCfgPpiGuid,
\\1 \\2
\\1 };
\\1 (**PeiServices).InstallPpi (PeiServices, gEcpPeiPciCfgPpiList);
\\1}'''
],

[
re.compile('^(\s*)\(\*PeiServices\)->PciCfg\s*=\s*([^;\s]+);', re.MULTILINE),
'''\\1{
\\1 STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
\\1 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
\\1 &gEcpPeiPciCfgPpiGuid,
\\1 \\2
\\1 };
\\1 (**PeiServices).InstallPpi (PeiServices, gEcpPeiPciCfgPpiList);
\\1}'''
],

[
re.compile("(\s*).+->Modify[\s\n]*\(", re.MULTILINE),
'\\1PeiLibPciCfgModify ('
],

[
re.compile("(\W*)gRT->ReportStatusCode[\s\n]*\(", re.MULTILINE),
'\\1EfiLibReportStatusCode ('
],

[
re.compile('#include\s+["<]LoadFile\.h[">]', re.MULTILINE),
'#include <FvLoadFile.h>'
],

[
re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_READY_TO_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
'\\1EfiCreateEventReadyToBoot (\\2\\3;'
],

[
re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_LEGACY_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
'\\1EfiCreateEventLegacyBoot (\\2\\3;'
]
]

## Trim preprocessed source code
#
Expand Down Expand Up @@ -198,6 +250,85 @@ def TrimAslFile(Source, Target):
f.write(Lines)
f.close()

## Trim EDK source code file(s)
#
#
# @param Source File or directory to be trimmed
# @param Target File or directory to store the trimmed content
#
def TrimR8Sources(Source, Target):
if os.path.isdir(Source):
for CurrentDir, Dirs, Files in os.walk(Source):
if '.svn' in Dirs:
Dirs.remove('.svn')
elif "CVS" in Dirs:
Dirs.remove("CVS")

for FileName in Files:
Dummy, Ext = os.path.splitext(FileName)
if Ext.upper() not in ['.C', '.H']: continue
if Target == None or Target == '':
TrimR8SourceCode(
os.path.join(CurrentDir, FileName),
os.path.join(CurrentDir, FileName)
)
else:
TrimR8SourceCode(
os.path.join(CurrentDir, FileName),
os.path.join(Target, CurrentDir[len(Source)+1:], FileName)
)
else:
TrimR8SourceCode(Source, Target)

## Trim one EDK source code file
#
# Do following replacement:
#
# (**PeiServices\).PciCfg = <*>;
# => {
# STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
# (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
# &gEcpPeiPciCfgPpiGuid,
# <*>
# };
# (**PeiServices).InstallPpi (PeiServices, gEcpPeiPciCfgPpiList);
#
# <*>Modify(<*>)
# => PeiLibPciCfgModify (<*>)
#
# gRT->ReportStatusCode (<*>)
# => EfiLibReportStatusCode (<*>)
#
# #include <LoadFile\.h>
# => #include <FvLoadFile.h>
#
# CreateEvent (EFI_EVENT_SIGNAL_READY_TO_BOOT, <*>)
# => EfiCreateEventReadyToBoot (<*>)
#
# CreateEvent (EFI_EVENT_SIGNAL_LEGACY_BOOT, <*>)
# => EfiCreateEventLegacyBoot (<*>)
#
# @param Source File to be trimmed
# @param Target File to store the trimmed content
#
def TrimR8SourceCode(Source, Target):
EdkLogger.verbose("\t%s -> %s" % (Source, Target))
CreateDirectory(os.path.dirname(Target))

f = open (Source,'r')
# read whole file
Lines = f.read()
f.close()

for Re,Repl in gImportCodePatterns:
Lines = Re.sub(Repl, Lines)

# save all lines trimmed
f = open (Target,'w')
f.write(Lines)
f.close()


## Parse command line options
#
# Using standard Python module optparse to parse command line option of this tool.
Expand All @@ -213,6 +344,8 @@ def Options():
help="The input file is preprocessed VFR file"),
make_option("-a", "--asl-file", dest="FileType", const="Asl", action="store_const",
help="The input file is ASL file"),
make_option("-8", "--r8-source-code", dest="FileType", const="R8SourceCode", action="store_const",
help="The input file is source code for R8 to be trimmed for ECP"),

make_option("-c", "--convert-hex", dest="ConvertHex", action="store_true",
help="Convert standard hex format (0xabcd) to MASM format (abcdh)"),
Expand All @@ -229,7 +362,7 @@ def Options():
]

# use clearer usage to override default usage message
UsageString = "%prog [-s|-r] [-c] [-v|-d <debug_level>|-q] [-o <output_file>] <input_file>"
UsageString = "%prog [-s|-r|-a] [-c] [-v|-d <debug_level>|-q] [-o <output_file>] <input_file>"

Parser = OptionParser(description=__copyright__, version=__version__, option_list=OptionList, usage=UsageString)
Parser.set_defaults(FileType="Vfr")
Expand All @@ -245,9 +378,6 @@ def Options():
EdkLogger.error("Trim", OPTION_NOT_SUPPORTED, ExtraData=Parser.get_usage())

InputFile = Args[0]
if Options.OutputFile == None:
Options.OutputFile = os.path.splitext(InputFile)[0] + '.iii'

return Options, InputFile

## Entrance method
Expand All @@ -269,10 +399,18 @@ def Main():
EdkLogger.SetLevel(CommandOptions.LogLevel)

if CommandOptions.FileType == "Vfr":
if CommandOptions.OutputFile == None:
CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
TrimPreprocessedVfr(InputFile, CommandOptions.OutputFile)
elif CommandOptions.FileType == "Asl":
if CommandOptions.OutputFile == None:
CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
TrimAslFile(InputFile, CommandOptions.OutputFile)
elif CommandOptions.FileType == "R8SourceCode":
TrimR8Sources(InputFile, CommandOptions.OutputFile)
else :
if CommandOptions.OutputFile == None:
CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
TrimPreprocessedFile(InputFile, CommandOptions.OutputFile, CommandOptions.ConvertHex)
except Exception, e:
print e
Expand Down
2 changes: 2 additions & 0 deletions Source/Python/Workspace/MetaFileParser.py
Expand Up @@ -145,6 +145,8 @@ def _PathParser(self):

## Skip unsupported data
def _Skip(self):
EdkLogger.warn("Parser", "Unrecognized content", File=self._FilePath,
Line=self._LineIndex+1, ExtraData=self._CurrentLine);
self._ValueList[0:1] = [self._CurrentLine]

## Section header parser
Expand Down

0 comments on commit 8a5eb10

Please sign in to comment.