(Source, Indent='', IncludePathList=[], LocalSearchPath=None)
| 254 | # in the IncludePathList will be searched. |
| 255 | # |
| 256 | def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None): |
| 257 | NewFileContent = [] |
| 258 | |
| 259 | try: |
| 260 | # |
| 261 | # Search LocalSearchPath first if it is specified. |
| 262 | # |
| 263 | if LocalSearchPath: |
| 264 | SearchPathList = [LocalSearchPath] + IncludePathList |
| 265 | else: |
| 266 | SearchPathList = IncludePathList |
| 267 | |
| 268 | for IncludePath in SearchPathList: |
| 269 | IncludeFile = os.path.join(IncludePath, Source) |
| 270 | if os.path.isfile(IncludeFile): |
| 271 | try: |
| 272 | with open(IncludeFile, "r") as File: |
| 273 | F = File.readlines() |
| 274 | except: |
| 275 | with codecs.open(IncludeFile, "r", encoding='utf-8') as File: |
| 276 | F = File.readlines() |
| 277 | break |
| 278 | else: |
| 279 | EdkLogger.error("Trim", "Failed to find include file %s" % Source) |
| 280 | except: |
| 281 | EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source) |
| 282 | |
| 283 | |
| 284 | # avoid A "include" B and B "include" A |
| 285 | IncludeFile = os.path.abspath(os.path.normpath(IncludeFile)) |
| 286 | if IncludeFile in gIncludedAslFile: |
| 287 | EdkLogger.warn("Trim", "Circular include", |
| 288 | ExtraData= "%s -> %s" % (" -> ".join(gIncludedAslFile), IncludeFile)) |
| 289 | return [] |
| 290 | gIncludedAslFile.append(IncludeFile) |
| 291 | |
| 292 | for Line in F: |
| 293 | LocalSearchPath = None |
| 294 | Result = gAslIncludePattern.findall(Line) |
| 295 | if len(Result) == 0: |
| 296 | Result = gAslCIncludePattern.findall(Line) |
| 297 | if len(Result) == 0 or os.path.splitext(Result[0][1])[1].lower() not in [".asl", ".asi"]: |
| 298 | NewFileContent.append("%s%s" % (Indent, Line)) |
| 299 | continue |
| 300 | # |
| 301 | # We should first search the local directory if current file are using pattern #include "XXX" |
| 302 | # |
| 303 | if Result[0][2] == '"': |
| 304 | LocalSearchPath = os.path.dirname(IncludeFile) |
| 305 | CurrentIndent = Indent + Result[0][0] |
| 306 | IncludedFile = Result[0][1] |
| 307 | NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, IncludePathList, LocalSearchPath)) |
| 308 | NewFileContent.append("\n") |
| 309 | |
| 310 | gIncludedAslFile.pop() |
| 311 | |
| 312 | return NewFileContent |
| 313 |
no test coverage detected