diff options
author | Joey Vagedes <joey.vagedes@gmail.com> | 2024-06-27 11:22:29 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-08-31 04:58:54 +0000 |
commit | 95ee7f3ef7a34773e0528410fd0178aecfdd89b5 (patch) | |
tree | a968a4a163ee203ef498dc1c3065f35503ba8f39 /BaseTools/Source/Python | |
parent | 90d861f63d0fe467cec9659703f02d3d32969dc3 (diff) | |
download | edk2-95ee7f3ef7a34773e0528410fd0178aecfdd89b5.tar.gz edk2-95ee7f3ef7a34773e0528410fd0178aecfdd89b5.tar.bz2 edk2-95ee7f3ef7a34773e0528410fd0178aecfdd89b5.zip |
BaseTools: Trim: Add header/footer for ASL include
When including one ASL file in another, add a header / footer to the
included file to easily tell where the included file starts and ends.
Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
Diffstat (limited to 'BaseTools/Source/Python')
-rw-r--r-- | BaseTools/Source/Python/Trim/Trim.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py index 6d7bc05510..ea9d1a06d5 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -248,6 +248,23 @@ def TrimPreprocessedVfr(Source, Target): except:
EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
+# Create a banner to indicate the start and
+# end of the included ASL file. Banner looks like:-
+#
+# /*************************************
+# * @param *
+# *************************************/
+#
+# @param Pathname File pathname to be included in the banner
+#
+def AddIncludeHeader(Pathname):
+ StartLine = "/*" + '*' * (len(Pathname) + 4)
+ EndLine = '*' * (len(Pathname) + 4) + "*/"
+ Banner = '\n' + StartLine
+ Banner += '\n' + ('{0} {1} {0}'.format('*', Pathname))
+ Banner += '\n' + EndLine + '\n'
+ return Banner
+
## Read the content ASL file, including ASL included, recursively
#
# @param Source File to be read
@@ -276,16 +293,18 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None, Inclu try:
with open(IncludeFile, "r") as File:
F = File.readlines()
- except:
+ except Exception:
with codecs.open(IncludeFile, "r", encoding='utf-8') as File:
F = File.readlines()
break
else:
- EdkLogger.error("Trim", "Failed to find include file %s" % Source)
+ EdkLogger.error("Trim", FILE_NOT_FOUND, ExtraData="Failed to find include file %s" % Source)
return []
- except:
- EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
- return []
+ except Exception as e:
+ if str(e) == str(FILE_NOT_FOUND):
+ raise
+ else:
+ EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
# avoid A "include" B and B "include" A
@@ -312,7 +331,9 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None, Inclu LocalSearchPath = os.path.dirname(IncludeFile)
CurrentIndent = Indent + Result[0][0]
IncludedFile = Result[0][1]
+ NewFileContent.append(AddIncludeHeader(IncludedFile+" --START"))
NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, IncludePathList, LocalSearchPath,IncludeFileList,filetype))
+ NewFileContent.append(AddIncludeHeader(IncludedFile+" --END"))
NewFileContent.append("\n")
elif filetype == "ASM":
Result = gIncludePattern.findall(Line)
@@ -324,7 +345,9 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None, Inclu IncludedFile = IncludedFile.strip()
IncludedFile = os.path.normpath(IncludedFile)
+ NewFileContent.append(AddIncludeHeader(IncludedFile+" --START"))
NewFileContent.extend(DoInclude(IncludedFile, '', IncludePathList, LocalSearchPath,IncludeFileList,filetype))
+ NewFileContent.append(AddIncludeHeader(IncludedFile+" --END"))
NewFileContent.append("\n")
gIncludedAslFile.pop()
|