summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python/Trim
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2010-10-14 06:30:37 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2010-10-14 06:30:37 +0000
commita72526804846e44773174a7b4800168e889d831a (patch)
tree507ba239c8cf71c4060a6b488d975c2ab819de48 /BaseTools/Source/Python/Trim
parent5b7183efb1e24f3d32f97c9a619ae69f61f4c0a1 (diff)
downloadedk2-platforms-a72526804846e44773174a7b4800168e889d831a.tar.xz
Sync EDKII BaseTools to BaseTools project r2068.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10937 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/Trim')
-rw-r--r--BaseTools/Source/Python/Trim/Trim.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py
index b3ad16715a..bfa2b7b590 100644
--- a/BaseTools/Source/Python/Trim/Trim.py
+++ b/BaseTools/Source/Python/Trim/Trim.py
@@ -41,7 +41,7 @@ gHexNumberPattern = re.compile("0[xX]([0-9a-fA-F]+)")
## Regular expression for matching "Include ()" in asl file
gAslIncludePattern = re.compile("^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.MULTILINE)
## Regular expression for matching C style #include "XXX.asl" in asl file
-gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*[>"]', re.MULTILINE)
+gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE)
## Regular expression for matching constant with 'ULL' and 'UL', 'LL', 'L' postfix
gLongNumberPattern = re.compile("(0[xX][0-9a-fA-F]+|[0-9]+)U?LL", re.MULTILINE)
## Patterns used to convert EDK conventions to EDK2 ECP conventions
@@ -273,12 +273,23 @@ def TrimPreprocessedVfr(Source, Target):
# @param Source File to be read
# @param Indent Spaces before the Include() statement
# @param IncludePathList The list of external include file
+# @param LocalSearchPath If LocalSearchPath is specified, this path will be searched
+# first for the included file; otherwise, only the path specified
+# in the IncludePathList will be searched.
#
-def DoInclude(Source, Indent='', IncludePathList=[]):
+def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None):
NewFileContent = []
try:
- for IncludePath in IncludePathList:
+ #
+ # Search LocalSearchPath first if it is specified.
+ #
+ if LocalSearchPath:
+ SearchPathList = [LocalSearchPath] + IncludePathList
+ else:
+ SearchPathList = IncludePathList
+
+ for IncludePath in SearchPathList:
IncludeFile = os.path.join(IncludePath, Source)
if os.path.isfile(IncludeFile):
F = open(IncludeFile, "r")
@@ -298,15 +309,21 @@ def DoInclude(Source, Indent='', IncludePathList=[]):
gIncludedAslFile.append(IncludeFile)
for Line in F:
+ LocalSearchPath = None
Result = gAslIncludePattern.findall(Line)
if len(Result) == 0:
Result = gAslCIncludePattern.findall(Line)
if len(Result) == 0 or os.path.splitext(Result[0][1])[1].lower() not in [".asl", ".asi"]:
NewFileContent.append("%s%s" % (Indent, Line))
continue
+ #
+ # We should first search the local directory if current file are using pattern #include "XXX"
+ #
+ if Result[0][2] == '"':
+ LocalSearchPath = os.path.dirname(IncludeFile)
CurrentIndent = Indent + Result[0][0]
IncludedFile = Result[0][1]
- NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, IncludePathList))
+ NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, IncludePathList, LocalSearchPath))
NewFileContent.append("\n")
gIncludedAslFile.pop()