public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Remove EDKI related logic from Trim tool
@ 2019-03-15 15:22 Feng, Bob C
  2019-03-19  7:24 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Feng, Bob C @ 2019-03-15 15:22 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1350

Remove EDKI related logic from Trim tool.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/Trim/Trim.py | 160 ---------------------------
 1 file changed, 160 deletions(-)

diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py
index 825ed3e5d5..228779b5a9 100644
--- a/BaseTools/Source/Python/Trim/Trim.py
+++ b/BaseTools/Source/Python/Trim/Trim.py
@@ -59,74 +59,10 @@ gLongNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?L
 ## 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)
 ## Patterns used to convert EDK conventions to EDK2 ECP conventions
-gImportCodePatterns = [
-    [
-        re.compile('^(\s*)\(\*\*PeiServices\)\.PciCfg\s*=\s*([^;\s]+);', re.MULTILINE),
-        '''\\1{
-\\1  STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
-\\1    (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
-\\1    &gEcpPeiPciCfgPpiGuid,
-\\1    \\2
-\\1  };
-\\1  (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
-\\1}'''
-    ],
-
-    [
-        re.compile('^(\s*)\(\*PeiServices\)->PciCfg\s*=\s*([^;\s]+);', re.MULTILINE),
-        '''\\1{
-\\1  STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
-\\1    (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
-\\1    &gEcpPeiPciCfgPpiGuid,
-\\1    \\2
-\\1  };
-\\1  (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
-\\1}'''
-    ],
-
-    [
-        re.compile("(\s*).+->Modify[\s\n]*\(", re.MULTILINE),
-        '\\1PeiLibPciCfgModify ('
-    ],
-
-    [
-        re.compile("(\W*)gRT->ReportStatusCode[\s\n]*\(", re.MULTILINE),
-        '\\1EfiLibReportStatusCode ('
-    ],
-
-    [
-        re.compile('#include\s+EFI_GUID_DEFINITION\s*\(FirmwareFileSystem\)', re.MULTILINE),
-        '#include EFI_GUID_DEFINITION (FirmwareFileSystem)\n#include EFI_GUID_DEFINITION (FirmwareFileSystem2)'
-    ],
-
-    [
-        re.compile('gEfiFirmwareFileSystemGuid', re.MULTILINE),
-        'gEfiFirmwareFileSystem2Guid'
-    ],
-
-    [
-        re.compile('EFI_FVH_REVISION', re.MULTILINE),
-        'EFI_FVH_PI_REVISION'
-    ],
-
-    [
-        re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_READY_TO_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
-        '\\1EfiCreateEventReadyToBoot (\\2\\3;'
-    ],
-
-    [
-        re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_LEGACY_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
-        '\\1EfiCreateEventLegacyBoot (\\2\\3;'
-    ],
-#    [
-#        re.compile("(\W)(PEI_PCI_CFG_PPI)(\W)", re.MULTILINE),
-#        '\\1ECP_\\2\\3'
-#    ]
-]
 
 ## file cache to avoid circular include in ASL file
 gIncludedAslFile = []
 
 ## Trim preprocessed source code
@@ -492,101 +428,10 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
         EdkLogger.error("Trim", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %OutputFile, None)
 
     fStringIO.close ()
     fInputfile.close ()
 
-## Trim EDK source code file(s)
-#
-#
-# @param  Source    File or directory to be trimmed
-# @param  Target    File or directory to store the trimmed content
-#
-def TrimEdkSources(Source, Target):
-    if os.path.isdir(Source):
-        for CurrentDir, Dirs, Files in os.walk(Source):
-            if '.svn' in Dirs:
-                Dirs.remove('.svn')
-            elif "CVS" in Dirs:
-                Dirs.remove("CVS")
-
-            for FileName in Files:
-                Dummy, Ext = os.path.splitext(FileName)
-                if Ext.upper() not in ['.C', '.H']: continue
-                if Target is None or Target == '':
-                    TrimEdkSourceCode(
-                        os.path.join(CurrentDir, FileName),
-                        os.path.join(CurrentDir, FileName)
-                        )
-                else:
-                    TrimEdkSourceCode(
-                        os.path.join(CurrentDir, FileName),
-                        os.path.join(Target, CurrentDir[len(Source)+1:], FileName)
-                        )
-    else:
-        TrimEdkSourceCode(Source, Target)
-
-## Trim one EDK source code file
-#
-# Do following replacement:
-#
-#   (**PeiServices\).PciCfg = <*>;
-#   =>  {
-#         STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
-#         (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
-#         &gEcpPeiPciCfgPpiGuid,
-#         <*>
-#       };
-#       (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
-#
-#   <*>Modify(<*>)
-#   =>  PeiLibPciCfgModify (<*>)
-#
-#   gRT->ReportStatusCode (<*>)
-#   => EfiLibReportStatusCode (<*>)
-#
-#   #include <LoadFile\.h>
-#   =>  #include <FvLoadFile.h>
-#
-#   CreateEvent (EFI_EVENT_SIGNAL_READY_TO_BOOT, <*>)
-#   => EfiCreateEventReadyToBoot (<*>)
-#
-#   CreateEvent (EFI_EVENT_SIGNAL_LEGACY_BOOT, <*>)
-#   =>  EfiCreateEventLegacyBoot (<*>)
-#
-# @param  Source    File to be trimmed
-# @param  Target    File to store the trimmed content
-#
-def TrimEdkSourceCode(Source, Target):
-    EdkLogger.verbose("\t%s -> %s" % (Source, Target))
-    CreateDirectory(os.path.dirname(Target))
-
-    try:
-        f = open (Source, 'r')
-    except:
-        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
-    # read whole file
-    Lines = f.read()
-    f.close()
-
-    NewLines = None
-    for Re, Repl in gImportCodePatterns:
-        if NewLines is None:
-            NewLines = Re.sub(Repl, Lines)
-        else:
-            NewLines = Re.sub(Repl, NewLines)
-
-    # save all lines if trimmed
-    if Source == Target and NewLines == Lines:
-        return
-
-    try:
-        f = open (Target, 'w')
-    except:
-        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
-    f.write(NewLines)
-    f.close()
-
 
 ## Parse command line options
 #
 # Using standard Python module optparse to parse command line option of this tool.
 #
@@ -601,13 +446,10 @@ def Options():
                           help="The input file is preprocessed VFR file"),
         make_option("--Vfr-Uni-Offset", dest="FileType", const="VfrOffsetBin", action="store_const",
                           help="The input file is EFI image"),
         make_option("-a", "--asl-file", dest="FileType", const="Asl", action="store_const",
                           help="The input file is ASL file"),
-        make_option("-8", "--Edk-source-code", dest="FileType", const="EdkSourceCode", action="store_const",
-                          help="The input file is source code for Edk to be trimmed for ECP"),
-
         make_option("-c", "--convert-hex", dest="ConvertHex", action="store_true",
                           help="Convert standard hex format (0xabcd) to MASM format (abcdh)"),
 
         make_option("-l", "--trim-long", dest="TrimLong", action="store_true",
                           help="Remove postfix of long number"),
@@ -678,12 +520,10 @@ def Main():
             TrimPreprocessedVfr(InputFile, CommandOptions.OutputFile)
         elif CommandOptions.FileType == "Asl":
             if CommandOptions.OutputFile is None:
                 CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
             TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptions.IncludePathFile)
-        elif CommandOptions.FileType == "EdkSourceCode":
-            TrimEdkSources(InputFile, CommandOptions.OutputFile)
         elif CommandOptions.FileType == "VfrOffsetBin":
             GenerateVfrBinSec(CommandOptions.ModuleName, CommandOptions.DebugDir, CommandOptions.OutputFile)
         else :
             if CommandOptions.OutputFile is None:
                 CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch] BaseTools: Remove EDKI related logic from Trim tool
  2019-03-15 15:22 [Patch] BaseTools: Remove EDKI related logic from Trim tool Feng, Bob C
@ 2019-03-19  7:24 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2019-03-19  7:24 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: Feng, Bob C
>Sent: Friday, March 15, 2019 11:22 PM
>To: edk2-devel@lists.01.org
>Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
>Subject: [Patch] BaseTools: Remove EDKI related logic from Trim tool
>
>BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1350
>
>Remove EDKI related logic from Trim tool.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Bob Feng <bob.c.feng@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>---
> BaseTools/Source/Python/Trim/Trim.py | 160 ---------------------------
> 1 file changed, 160 deletions(-)
>
>diff --git a/BaseTools/Source/Python/Trim/Trim.py
>b/BaseTools/Source/Python/Trim/Trim.py
>index 825ed3e5d5..228779b5a9 100644
>--- a/BaseTools/Source/Python/Trim/Trim.py
>+++ b/BaseTools/Source/Python/Trim/Trim.py
>@@ -59,74 +59,10 @@ gLongNumberPattern = re.compile("(?<=[^a-zA-Z0-
>9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?L
> ## 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)
> ## Patterns used to convert EDK conventions to EDK2 ECP conventions
>-gImportCodePatterns = [
>-    [
>-        re.compile('^(\s*)\(\*\*PeiServices\)\.PciCfg\s*=\s*([^;\s]+);',
>re.MULTILINE),
>-        '''\\1{
>-\\1  STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
>-\\1    (EFI_PEI_PPI_DESCRIPTOR_PPI |
>EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
>-\\1    &gEcpPeiPciCfgPpiGuid,
>-\\1    \\2
>-\\1  };
>-\\1  (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
>-\\1}'''
>-    ],
>-
>-    [
>-        re.compile('^(\s*)\(\*PeiServices\)->PciCfg\s*=\s*([^;\s]+);',
>re.MULTILINE),
>-        '''\\1{
>-\\1  STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
>-\\1    (EFI_PEI_PPI_DESCRIPTOR_PPI |
>EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
>-\\1    &gEcpPeiPciCfgPpiGuid,
>-\\1    \\2
>-\\1  };
>-\\1  (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
>-\\1}'''
>-    ],
>-
>-    [
>-        re.compile("(\s*).+->Modify[\s\n]*\(", re.MULTILINE),
>-        '\\1PeiLibPciCfgModify ('
>-    ],
>-
>-    [
>-        re.compile("(\W*)gRT->ReportStatusCode[\s\n]*\(", re.MULTILINE),
>-        '\\1EfiLibReportStatusCode ('
>-    ],
>-
>-    [
>-
>re.compile('#include\s+EFI_GUID_DEFINITION\s*\(FirmwareFileSystem\)',
>re.MULTILINE),
>-        '#include EFI_GUID_DEFINITION (FirmwareFileSystem)\n#include
>EFI_GUID_DEFINITION (FirmwareFileSystem2)'
>-    ],
>-
>-    [
>-        re.compile('gEfiFirmwareFileSystemGuid', re.MULTILINE),
>-        'gEfiFirmwareFileSystem2Guid'
>-    ],
>-
>-    [
>-        re.compile('EFI_FVH_REVISION', re.MULTILINE),
>-        'EFI_FVH_PI_REVISION'
>-    ],
>-
>-    [
>-
>re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_READY_TO
>_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
>-        '\\1EfiCreateEventReadyToBoot (\\2\\3;'
>-    ],
>-
>-    [
>-
>re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_LEGACY_B
>OOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
>-        '\\1EfiCreateEventLegacyBoot (\\2\\3;'
>-    ],
>-#    [
>-#        re.compile("(\W)(PEI_PCI_CFG_PPI)(\W)", re.MULTILINE),
>-#        '\\1ECP_\\2\\3'
>-#    ]
>-]
>
> ## file cache to avoid circular include in ASL file
> gIncludedAslFile = []
>
> ## Trim preprocessed source code
>@@ -492,101 +428,10 @@ def GenerateVfrBinSec(ModuleName, DebugDir,
>OutputFile):
>         EdkLogger.error("Trim", FILE_WRITE_FAILURE, "Write data to file %s
>failed, please check whether the file been locked or using by other
>applications." %OutputFile, None)
>
>     fStringIO.close ()
>     fInputfile.close ()
>
>-## Trim EDK source code file(s)
>-#
>-#
>-# @param  Source    File or directory to be trimmed
>-# @param  Target    File or directory to store the trimmed content
>-#
>-def TrimEdkSources(Source, Target):
>-    if os.path.isdir(Source):
>-        for CurrentDir, Dirs, Files in os.walk(Source):
>-            if '.svn' in Dirs:
>-                Dirs.remove('.svn')
>-            elif "CVS" in Dirs:
>-                Dirs.remove("CVS")
>-
>-            for FileName in Files:
>-                Dummy, Ext = os.path.splitext(FileName)
>-                if Ext.upper() not in ['.C', '.H']: continue
>-                if Target is None or Target == '':
>-                    TrimEdkSourceCode(
>-                        os.path.join(CurrentDir, FileName),
>-                        os.path.join(CurrentDir, FileName)
>-                        )
>-                else:
>-                    TrimEdkSourceCode(
>-                        os.path.join(CurrentDir, FileName),
>-                        os.path.join(Target, CurrentDir[len(Source)+1:], FileName)
>-                        )
>-    else:
>-        TrimEdkSourceCode(Source, Target)
>-
>-## Trim one EDK source code file
>-#
>-# Do following replacement:
>-#
>-#   (**PeiServices\).PciCfg = <*>;
>-#   =>  {
>-#         STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
>-#         (EFI_PEI_PPI_DESCRIPTOR_PPI |
>EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
>-#         &gEcpPeiPciCfgPpiGuid,
>-#         <*>
>-#       };
>-#       (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
>-#
>-#   <*>Modify(<*>)
>-#   =>  PeiLibPciCfgModify (<*>)
>-#
>-#   gRT->ReportStatusCode (<*>)
>-#   => EfiLibReportStatusCode (<*>)
>-#
>-#   #include <LoadFile\.h>
>-#   =>  #include <FvLoadFile.h>
>-#
>-#   CreateEvent (EFI_EVENT_SIGNAL_READY_TO_BOOT, <*>)
>-#   => EfiCreateEventReadyToBoot (<*>)
>-#
>-#   CreateEvent (EFI_EVENT_SIGNAL_LEGACY_BOOT, <*>)
>-#   =>  EfiCreateEventLegacyBoot (<*>)
>-#
>-# @param  Source    File to be trimmed
>-# @param  Target    File to store the trimmed content
>-#
>-def TrimEdkSourceCode(Source, Target):
>-    EdkLogger.verbose("\t%s -> %s" % (Source, Target))
>-    CreateDirectory(os.path.dirname(Target))
>-
>-    try:
>-        f = open (Source, 'r')
>-    except:
>-        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
>-    # read whole file
>-    Lines = f.read()
>-    f.close()
>-
>-    NewLines = None
>-    for Re, Repl in gImportCodePatterns:
>-        if NewLines is None:
>-            NewLines = Re.sub(Repl, Lines)
>-        else:
>-            NewLines = Re.sub(Repl, NewLines)
>-
>-    # save all lines if trimmed
>-    if Source == Target and NewLines == Lines:
>-        return
>-
>-    try:
>-        f = open (Target, 'w')
>-    except:
>-        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
>-    f.write(NewLines)
>-    f.close()
>-
>
> ## Parse command line options
> #
> # Using standard Python module optparse to parse command line option of
>this tool.
> #
>@@ -601,13 +446,10 @@ def Options():
>                           help="The input file is preprocessed VFR file"),
>         make_option("--Vfr-Uni-Offset", dest="FileType", const="VfrOffsetBin",
>action="store_const",
>                           help="The input file is EFI image"),
>         make_option("-a", "--asl-file", dest="FileType", const="Asl",
>action="store_const",
>                           help="The input file is ASL file"),
>-        make_option("-8", "--Edk-source-code", dest="FileType",
>const="EdkSourceCode", action="store_const",
>-                          help="The input file is source code for Edk to be trimmed for
>ECP"),
>-
>         make_option("-c", "--convert-hex", dest="ConvertHex",
>action="store_true",
>                           help="Convert standard hex format (0xabcd) to MASM format
>(abcdh)"),
>
>         make_option("-l", "--trim-long", dest="TrimLong", action="store_true",
>                           help="Remove postfix of long number"),
>@@ -678,12 +520,10 @@ def Main():
>             TrimPreprocessedVfr(InputFile, CommandOptions.OutputFile)
>         elif CommandOptions.FileType == "Asl":
>             if CommandOptions.OutputFile is None:
>                 CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
>             TrimAslFile(InputFile, CommandOptions.OutputFile,
>CommandOptions.IncludePathFile)
>-        elif CommandOptions.FileType == "EdkSourceCode":
>-            TrimEdkSources(InputFile, CommandOptions.OutputFile)
>         elif CommandOptions.FileType == "VfrOffsetBin":
>             GenerateVfrBinSec(CommandOptions.ModuleName,
>CommandOptions.DebugDir, CommandOptions.OutputFile)
>         else :
>             if CommandOptions.OutputFile is None:
>                 CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
>--
>2.18.0.windows.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-19  7:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-15 15:22 [Patch] BaseTools: Remove EDKI related logic from Trim tool Feng, Bob C
2019-03-19  7:24 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox