|
From: <qh...@us...> - 2010-10-08 00:46:24
|
Revision: 2064
http://edk2-buildtools.svn.sourceforge.net/edk2-buildtools/?rev=2064&view=rev
Author: qhuang8
Date: 2010-10-08 00:46:18 +0000 (Fri, 08 Oct 2010)
Log Message:
-----------
Update Trim tool to support the search of the ASL source directory plus the extra include path list to find the included file specified in the ASL source.
Modified Paths:
--------------
trunk/BaseTools/Conf/build_rule.template
trunk/BaseTools/Source/Python/Trim/Trim.py
Modified: trunk/BaseTools/Conf/build_rule.template
===================================================================
--- trunk/BaseTools/Conf/build_rule.template 2010-10-05 23:35:51 UTC (rev 2063)
+++ trunk/BaseTools/Conf/build_rule.template 2010-10-08 00:46:18 UTC (rev 2064)
@@ -343,13 +343,13 @@
$(MAKE_FILE)
<Command.MSFT, Command.INTEL>
- Trim --asl-file -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i ${src}
+ Trim --asl-file -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
"$(ASLPP)" $(ASLPP_FLAGS) $(INC) /I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
<Command.GCC>
- Trim --asl-file -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i ${src}
+ Trim --asl-file -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
"$(ASLPP)" $(ASLPP_FLAGS) $(INC) -I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Modified: trunk/BaseTools/Source/Python/Trim/Trim.py
===================================================================
--- trunk/BaseTools/Source/Python/Trim/Trim.py 2010-10-05 23:35:51 UTC (rev 2063)
+++ trunk/BaseTools/Source/Python/Trim/Trim.py 2010-10-08 00:46:18 UTC (rev 2064)
@@ -270,23 +270,33 @@
## Read the content ASL file, including ASL included, recursively
#
-# @param Source File to be read
-# @param Indent Spaces before the Include() statement
+# @param Source File to be read
+# @param Indent Spaces before the Include() statement
+# @param IncludePathList The list of external include file
#
-def DoInclude(Source, Indent=''):
+def DoInclude(Source, Indent='', IncludePathList=[]):
NewFileContent = []
- # avoid A "include" B and B "include" A
- if Source in gIncludedAslFile:
- EdkLogger.warn("Trim", "Circular include",
- ExtraData= "%s -> %s" % (" -> ".join(gIncludedAslFile), Source))
- return []
- gIncludedAslFile.append(Source)
try:
- F = open(Source,'r')
+ for IncludePath in IncludePathList:
+ IncludeFile = os.path.join(IncludePath, Source)
+ if os.path.isfile(IncludeFile):
+ F = open(IncludeFile, "r")
+ break
+ else:
+ EdkLogger.error("Trim", "Failed to find include file %s" % Source)
except:
EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
+
+ # avoid A "include" B and B "include" A
+ IncludeFile = os.path.abspath(os.path.normpath(IncludeFile))
+ if IncludeFile in gIncludedAslFile:
+ EdkLogger.warn("Trim", "Circular include",
+ ExtraData= "%s -> %s" % (" -> ".join(gIncludedAslFile), IncludeFile))
+ return []
+ gIncludedAslFile.append(IncludeFile)
+
for Line in F:
Result = gAslIncludePattern.findall(Line)
if len(Result) == 0:
@@ -296,7 +306,7 @@
continue
CurrentIndent = Indent + Result[0][0]
IncludedFile = Result[0][1]
- NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent))
+ NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, IncludePathList))
NewFileContent.append("\n")
gIncludedAslFile.pop()
@@ -309,20 +319,40 @@
#
# Replace ASL include statement with the content the included file
#
-# @param Source File to be trimmed
-# @param Target File to store the trimmed content
+# @param Source File to be trimmed
+# @param Target File to store the trimmed content
+# @param IncludePathFile The file to log the external include path
#
-def TrimAslFile(Source, Target):
+def TrimAslFile(Source, Target, IncludePathFile):
CreateDirectory(os.path.dirname(Target))
- Cwd = os.getcwd()
SourceDir = os.path.dirname(Source)
if SourceDir == '':
SourceDir = '.'
- os.chdir(SourceDir)
- Lines = DoInclude(Source)
- os.chdir(Cwd)
+
+ #
+ # Add source directory as the first search directory
+ #
+ IncludePathList = [SourceDir]
+
+ #
+ # If additional include path file is specified, append them all
+ # to the search directory list.
+ #
+ if IncludePathFile:
+ try:
+ LineNum = 0
+ for Line in open(IncludePathFile,'r'):
+ LineNum += 1
+ if Line.startswith("/I") or Line.startswith ("-I"):
+ IncludePathList.append(Line[2:].strip())
+ else:
+ EdkLogger.warn("Trim", "Invalid include line in include list file.", IncludePathFile, LineNum)
+ except:
+ EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=IncludePathFile)
+ Lines = DoInclude(Source, '', IncludePathList)
+
#
# Undef MIN and MAX to avoid collision in ASL source code
#
@@ -452,7 +482,8 @@
make_option("-l", "--trim-long", dest="TrimLong", action="store_true",
help="Remove postfix of long number"),
-
+ make_option("-i", "--include-path-file", dest="IncludePathFile",
+ help="The input file is include path list to search for ASL include file"),
make_option("-o", "--output", dest="OutputFile",
help="File to store the trimmed content"),
make_option("-v", "--verbose", dest="LogLevel", action="store_const", const=EdkLogger.VERBOSE,
@@ -465,7 +496,7 @@
]
# use clearer usage to override default usage message
- UsageString = "%prog [-s|-r|-a] [-c] [-v|-d <debug_level>|-q] [-o <output_file>] <input_file>"
+ UsageString = "%prog [-s|-r|-a] [-c] [-v|-d <debug_level>|-q] [-i <include_path_file>] [-o <output_file>] <input_file>"
Parser = OptionParser(description=__copyright__, version=__version__, option_list=OptionList, usage=UsageString)
Parser.set_defaults(FileType="Vfr")
@@ -511,7 +542,7 @@
elif CommandOptions.FileType == "Asl":
if CommandOptions.OutputFile == None:
CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
- TrimAslFile(InputFile, CommandOptions.OutputFile)
+ TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptions.IncludePathFile)
elif CommandOptions.FileType == "R8SourceCode":
TrimR8Sources(InputFile, CommandOptions.OutputFile)
else :
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|