From nobody Sun Feb 8 14:53:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+50925+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+50925+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1574218743; cv=none; d=zoho.com; s=zohoarc; b=M6SQPssZCwBOZxS1zeekYzYbCx4IT9OWYmvk8NtqrlRTt9sppcwKp81GDibuR25ghwTshgmEPXp+qz4d5C7UlYTxV00RzIyRoxsmFudW37wfhSQqV9j3CjzWDFsDeeZno9PyQQXKrtwoNGviOOYeBXDTjTMtL5lVdWILEdd7UZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574218743; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=W6NID13hn5nD7Q0JA///Or1t5p5YnpX3yo5ZHljB7To=; b=iW24n0OYvHJ3RYxXjDTcp0e54dWc4XBetMOg39AIPZ/ldbPAM7/QULwN2p8FyY1NmP7tIaAtRAazcqAyHq5O3ZR8qzDWZHdV9syGoRsLUOySwgseHCE5zXuFOhej4esvi8xXsTkD6ecKgWPhYQCRbRBP9TQ8hrjvFB0cHxAn+q0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+50925+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1574218743517884.8043440383957; Tue, 19 Nov 2019 18:59:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id KkfxYY1788612xxLKkcXnbCR; Tue, 19 Nov 2019 18:59:00 -0800 X-Received: from mga09.intel.com (mga09.intel.com []) by mx.groups.io with SMTP id smtpd.web12.1911.1574218737222119877 for ; Tue, 19 Nov 2019 18:59:00 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2019 18:58:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,220,1571727600"; d="scan'208";a="209611507" X-Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.47]) by orsmga006.jf.intel.com with ESMTP; 19 Nov 2019 18:58:58 -0800 From: "Bob Feng" To: devel@edk2.groups.io Cc: "Feng, Bob C" , Liming Gao , Steven Shi Subject: [edk2-devel] [Patch 2/4] BaseTools: Generate dependent files for ASL and ASM files Date: Wed, 20 Nov 2019 10:58:28 +0800 Message-Id: <20191120025830.2788-3-bob.c.feng@intel.com> In-Reply-To: <20191120025830.2788-1-bob.c.feng@intel.com> References: <20191120025830.2788-1-bob.c.feng@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,bob.c.feng@intel.com X-Gm-Message-State: qHuwW3ld2DA2k4oafxKbWbSdx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574218740; bh=tdRj/VtxMVa+mTBPoKPm4Fk9XFMNKNFeSeoqsjyudaE=; h=Cc:Date:From:Reply-To:Subject:To; b=PW5lqPX8pRm36XV/ewPbAvdPk5EL/Wr240o59ExeseiDulJX1MbOI8BOiRGhQ4pnxJn rR336tedoZnX5qhYZzmvPU4GHP+CYiQIBlmpDkxD2VG7M+XHP55iV3jSHSMUez3mGBaj3 sEtoAClhM/LJGoyZ8qntdgNsjB36zJaFs14= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: "Feng, Bob C" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2311 Implement the function in Trim tool to get the included file list for ASL and ASM file. Cc: Liming Gao Cc: Steven Shi Signed-off-by: Bob Feng --- BaseTools/Source/Python/Trim/Trim.py | 115 ++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 20 deletions(-) diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python= /Trim/Trim.py index 24c3fafa76f9..c5638376e41a 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -54,10 +54,14 @@ gLongNumberPattern =3D re.compile("(?<=3D[^a-zA-Z0-9_])= (0[xX][0-9a-fA-F]+|[0-9]+)U?L gAslIncludePattern =3D re.compile("^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\= )", re.MULTILINE) ## Regular expression for matching C style #include "XXX.asl" in asl file gAslCIncludePattern =3D re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\= s*([>"])', re.MULTILINE) ## Patterns used to convert EDK conventions to EDK2 ECP conventions =20 +## Regular expression for finding header file inclusions +gIncludePattern =3D re.compile(r"^[ \t]*[%]?[ \t]*include(?:[ \t]*(?:\\(?:= \r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?= )", re.MULTILINE | re.UNICODE | re.IGNORECASE) + + ## file cache to avoid circular include in ASL file gIncludedAslFile =3D [] =20 ## Trim preprocessed source code # @@ -251,13 +255,14 @@ def TrimPreprocessedVfr(Source, Target): # @param IncludePathList The list of external include file # @param LocalSearchPath If LocalSearchPath is specified, this path wil= l be searched # first for the included file; otherwise, only t= he path specified # in the IncludePathList will be searched. # -def DoInclude(Source, Indent=3D'', IncludePathList=3D[], LocalSearchPath= =3DNone): +def DoInclude(Source, Indent=3D'', IncludePathList=3D[], LocalSearchPath= =3DNone, IncludeFileList =3D None, filetype=3DNone): NewFileContent =3D [] - + if IncludeFileList is None: + IncludeFileList =3D [] try: # # Search LocalSearchPath first if it is specified. # if LocalSearchPath: @@ -286,28 +291,41 @@ def DoInclude(Source, Indent=3D'', IncludePathList=3D= [], LocalSearchPath=3DNone): if IncludeFile in gIncludedAslFile: EdkLogger.warn("Trim", "Circular include", ExtraData=3D "%s -> %s" % (" -> ".join(gIncludedAsl= File), IncludeFile)) return [] gIncludedAslFile.append(IncludeFile) - + IncludeFileList.append(IncludeFile.strip()) for Line in F: LocalSearchPath =3D None - Result =3D gAslIncludePattern.findall(Line) - if len(Result) =3D=3D 0: - Result =3D gAslCIncludePattern.findall(Line) - if len(Result) =3D=3D 0 or os.path.splitext(Result[0][1])[1].l= ower() not in [".asl", ".asi"]: + if filetype =3D=3D "ASL": + Result =3D gAslIncludePattern.findall(Line) + if len(Result) =3D=3D 0: + Result =3D gAslCIncludePattern.findall(Line) + if len(Result) =3D=3D 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 fi= le are using pattern #include "XXX" + # + if Result[0][2] =3D=3D '"': + LocalSearchPath =3D os.path.dirname(IncludeFile) + CurrentIndent =3D Indent + Result[0][0] + IncludedFile =3D Result[0][1] + NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, I= ncludePathList, LocalSearchPath,IncludeFileList,filetype)) + NewFileContent.append("\n") + elif filetype =3D=3D "ASM": + Result =3D gIncludePattern.findall(Line) + if len(Result) =3D=3D 0: NewFileContent.append("%s%s" % (Indent, Line)) continue - # - # We should first search the local directory if current file a= re using pattern #include "XXX" - # - if Result[0][2] =3D=3D '"': - LocalSearchPath =3D os.path.dirname(IncludeFile) - CurrentIndent =3D Indent + Result[0][0] - IncludedFile =3D Result[0][1] - NewFileContent.extend(DoInclude(IncludedFile, CurrentIndent, Inclu= dePathList, LocalSearchPath)) - NewFileContent.append("\n") + + IncludedFile =3D Result[0] + + IncludedFile =3D IncludedFile.strip() + IncludedFile =3D os.path.normpath(IncludedFile) + NewFileContent.extend(DoInclude(IncludedFile, '', IncludePathL= ist, LocalSearchPath,IncludeFileList,filetype)) + NewFileContent.append("\n") =20 gIncludedAslFile.pop() =20 return NewFileContent =20 @@ -318,11 +336,11 @@ def DoInclude(Source, Indent=3D'', IncludePathList=3D= [], LocalSearchPath=3DNone): # # @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, IncludePathFile): +def TrimAslFile(Source, Target, IncludePathFile,AslDeps =3D False): CreateDirectory(os.path.dirname(Target)) =20 SourceDir =3D os.path.dirname(Source) if SourceDir =3D=3D '': SourceDir =3D '.' @@ -347,12 +365,15 @@ def TrimAslFile(Source, Target, IncludePathFile): IncludePathList.append(Line[2:].strip()) else: EdkLogger.warn("Trim", "Invalid include line in includ= e list file.", IncludePathFile, LineNum) except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=3DInclude= PathFile) - - Lines =3D DoInclude(Source, '', IncludePathList) + AslIncludes =3D [] + Lines =3D DoInclude(Source, '', IncludePathList,IncludeFileList=3DAslI= ncludes,filetype=3D'ASL') + AslIncludes =3D [item for item in AslIncludes if item !=3DSource] + if AslDeps and AslIncludes: + SaveFileOnChange(os.path.join(os.path.dirname(Target),os.path.base= name(Source))+".trim.deps", " \\\n".join([Source+":"] +AslIncludes),False) =20 # # Undef MIN and MAX to avoid collision in ASL source code # Lines.insert(0, "#undef MIN\n#undef MAX\n") @@ -362,10 +383,58 @@ def TrimAslFile(Source, Target, IncludePathFile): with open(Target, 'w') as File: File.writelines(Lines) except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=3DTarget) =20 +## Trim ASM file +# +# Output ASM include statement with the content the included file +# +# @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 TrimAsmFile(Source, Target, IncludePathFile): + CreateDirectory(os.path.dirname(Target)) + + SourceDir =3D os.path.dirname(Source) + if SourceDir =3D=3D '': + SourceDir =3D '.' + + # + # Add source directory as the first search directory + # + IncludePathList =3D [SourceDir] + # + # If additional include path file is specified, append them all + # to the search directory list. + # + if IncludePathFile: + try: + LineNum =3D 0 + with open(IncludePathFile, 'r') as File: + FileLines =3D File.readlines() + for Line in FileLines: + LineNum +=3D 1 + if Line.startswith("/I") or Line.startswith ("-I"): + IncludePathList.append(Line[2:].strip()) + else: + EdkLogger.warn("Trim", "Invalid include line in includ= e list file.", IncludePathFile, LineNum) + except: + EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=3DInclude= PathFile) + AsmIncludes =3D [] + Lines =3D DoInclude(Source, '', IncludePathList,IncludeFileList=3DAsmI= ncludes,filetype=3D'ASM') + AsmIncludes =3D [item for item in AsmIncludes if item !=3D Source] + if AsmIncludes: + SaveFileOnChange(os.path.join(os.path.dirname(Target),os.path.base= name(Source))+".trim.deps", " \\\n".join([Source+":"] +AsmIncludes),False) + # save all lines trimmed + try: + with open(Target, 'w') as File: + File.writelines(Lines) + except: + EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=3DTarget) + def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): VfrNameList =3D [] if os.path.isdir(DebugDir): for CurrentDir, Dirs, Files in os.walk(DebugDir): for FileName in Files: @@ -438,12 +507,16 @@ def Options(): help=3D"The input file is preprocessed source co= de, including C or assembly code"), make_option("-r", "--vfr-file", dest=3D"FileType", const=3D"Vfr", = action=3D"store_const", help=3D"The input file is preprocessed VFR file"= ), make_option("--Vfr-Uni-Offset", dest=3D"FileType", const=3D"VfrOff= setBin", action=3D"store_const", help=3D"The input file is EFI image"), + make_option("--asl-deps", dest=3D"AslDeps", const=3D"True", action= =3D"store_const", + help=3D"Generate Asl dependent files."), make_option("-a", "--asl-file", dest=3D"FileType", const=3D"Asl", = action=3D"store_const", help=3D"The input file is ASL file"), + make_option( "--asm-file", dest=3D"FileType", const=3D"Asm", actio= n=3D"store_const", + help=3D"The input file is asm file"), make_option("-c", "--convert-hex", dest=3D"ConvertHex", action=3D"= store_true", help=3D"Convert standard hex format (0xabcd) to = MASM format (abcdh)"), =20 make_option("-l", "--trim-long", dest=3D"TrimLong", action=3D"stor= e_true", help=3D"Remove postfix of long number"), @@ -513,13 +586,15 @@ def Main(): CommandOptions.OutputFile =3D os.path.splitext(InputFile)[= 0] + '.iii' TrimPreprocessedVfr(InputFile, CommandOptions.OutputFile) elif CommandOptions.FileType =3D=3D "Asl": if CommandOptions.OutputFile is None: CommandOptions.OutputFile =3D os.path.splitext(InputFile)[= 0] + '.iii' - TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptio= ns.IncludePathFile) + TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptio= ns.IncludePathFile,CommandOptions.AslDeps) elif CommandOptions.FileType =3D=3D "VfrOffsetBin": GenerateVfrBinSec(CommandOptions.ModuleName, CommandOptions.De= bugDir, CommandOptions.OutputFile) + elif CommandOptions.FileType =3D=3D "Asm": + TrimAsmFile(InputFile, CommandOptions.OutputFile, CommandOptio= ns.IncludePathFile) else : if CommandOptions.OutputFile is None: CommandOptions.OutputFile =3D os.path.splitext(InputFile)[= 0] + '.iii' TrimPreprocessedFile(InputFile, CommandOptions.OutputFile, Com= mandOptions.ConvertHex, CommandOptions.TrimLong) except FatalError as X: --=20 2.20.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#50925): https://edk2.groups.io/g/devel/message/50925 Mute This Topic: https://groups.io/mt/60738065/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-