From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 46B8F211B6C0E for ; Wed, 16 Jan 2019 23:50:12 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 23:50:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="311148953" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga006.fm.intel.com with ESMTP; 16 Jan 2019 23:50:08 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 16 Jan 2019 23:50:01 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 16 Jan 2019 23:50:01 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.196]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.160]) with mapi id 14.03.0415.000; Thu, 17 Jan 2019 15:47:10 +0800 From: "Feng, Bob C" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: [Patch v1 4/5] BaseTools/AutoGen: move functions Thread-Index: AQHUqRPjWQ6OVzjRZkip1LwzF+p3U6WzH4CQ Date: Thu, 17 Jan 2019 07:47:10 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D16005CFA5@SHSMSX101.ccr.corp.intel.com> References: <698297b59eec9259911953079ae568af9400de05.1547145461.git.jaben.carsey@intel.com> In-Reply-To: <698297b59eec9259911953079ae568af9400de05.1547145461.git.jaben.carsey@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v1 4/5] BaseTools/AutoGen: move functions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2019 07:50:12 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Carsey, Jaben=20 Sent: Friday, January 11, 2019 2:40 AM To: edk2-devel@lists.01.org Cc: Feng, Bob C ; Gao, Liming Subject: [Patch v1 4/5] BaseTools/AutoGen: move functions Move SplitOption and ConvertStringToByteArray from Common.Misc to this file= . There were no other consumers of the functions. Cc: Bob Feng Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/AutoGen.py | 77 ++++++++++++++++++-- BaseTools/Source/Python/Common/Misc.py | 68 ----------------- 2 files changed, 72 insertions(+), 73 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/= Python/AutoGen/AutoGen.py index acd34692b6c2..f68166403edf 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -30,7 +30,7 @@ from io import BytesIO =20 from .StrGather import * from .BuildEngine import BuildRule - +import shutil from Common.LongFilePathSupport import CopyLongFilePath from Common.Build= ToolError import * from Common.DataType import * @@ -170,6 +170,73 @@ ${ta= il_comments} ## @AsBuilt${BEGIN} ## ${flags_item}${END} """) +## Split command line option string to list # # subprocess.Popen needs=20 +the args to be a sequence. Otherwise there's problem # in non-windows=20 +platform to launch command # def _SplitOption(OptionString): + OptionList =3D [] + LastChar =3D " " + OptionStart =3D 0 + QuotationMark =3D "" + for Index in range(0, len(OptionString)): + CurrentChar =3D OptionString[Index] + if CurrentChar in ['"', "'"]: + if QuotationMark =3D=3D CurrentChar: + QuotationMark =3D "" + elif QuotationMark =3D=3D "": + QuotationMark =3D CurrentChar + continue + elif QuotationMark: + continue + + if CurrentChar in ["/", "-"] and LastChar in [" ", "\t", "\r", "\n= "]: + if Index > OptionStart: + OptionList.append(OptionString[OptionStart:Index - 1]) + OptionStart =3D Index + LastChar =3D CurrentChar + OptionList.append(OptionString[OptionStart:]) + return OptionList + +# +# Convert string to C format array +# +def _ConvertStringToByteArray(Value): + Value =3D Value.strip() + if not Value: + return None + if Value[0] =3D=3D '{': + if not Value.endswith('}'): + return None + Value =3D Value.replace(' ', '').replace('{', '').replace('}', '') + ValFields =3D Value.split(',') + try: + for Index in range(len(ValFields)): + ValFields[Index] =3D str(int(ValFields[Index], 0)) + except ValueError: + return None + Value =3D '{' + ','.join(ValFields) + '}' + return Value + + Unicode =3D False + if Value.startswith('L"'): + if not Value.endswith('"'): + return None + Value =3D Value[1:] + Unicode =3D True + elif not Value.startswith('"') or not Value.endswith('"'): + return None + + Value =3D eval(Value) # translate escape character + NewValue =3D '{' + for Index in range(0, len(Value)): + if Unicode: + NewValue =3D NewValue + str(ord(Value[Index]) % 0x10000) + ',' + else: + NewValue =3D NewValue + str(ord(Value[Index]) % 0x100) + ',' + Value =3D NewValue + '0}' + return Value =20 ## Base class for AutoGen # @@ -1719,11 +1786,11 @@ class PlatformAutoGen(AutoGen): def BuildCommand(self): RetVal =3D [] if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition= ["MAKE"]: - RetVal +=3D SplitOption(self.ToolDefinition["MAKE"]["PATH"]) + RetVal +=3D _SplitOption(self.ToolDefinition["MAKE"]["PATH"]) if "FLAGS" in self.ToolDefinition["MAKE"]: NewOption =3D self.ToolDefinition["MAKE"]["FLAGS"].strip() if NewOption !=3D '': - RetVal +=3D SplitOption(NewOption) + RetVal +=3D _SplitOption(NewOption) if "MAKE" in self.EdkIIBuildOption: if "FLAGS" in self.EdkIIBuildOption["MAKE"]: Flags =3D self.EdkIIBuildOption["MAKE"]["FLAGS"] @@ -3425,7 +3492,7 @@ class ModuleAutoGen(AutoGen): Guid =3D gEfiVarStoreGuidPattern.search(Content, Pos) if not Guid: break - NameArray =3D ConvertStringToByteArray('L"' + Name.group(1= ) + '"') + NameArray =3D _ConvertStringToByteArray('L"' +=20 + Name.group(1) + '"') NameGuids.add((NameArray, GuidStructureStringToGuidString(= Guid.group(1)))) Pos =3D Content.find('efivarstore', Name.end()) if not NameGuids: @@ -3438,7 +3505,7 @@ class ModuleAutoGen(AutoGen): Value =3D GuidValue(SkuInfo.VariableGuid, self.PlatformInf= o.PackageList, self.MetaFile.Path) if not Value: continue - Name =3D ConvertStringToByteArray(SkuInfo.VariableName) + Name =3D _ConvertStringToByteArray(SkuInfo.VariableName) Guid =3D GuidStructureStringToGuidString(Value) if (Name, Guid) in NameGuids and Pcd not in HiiExPcds: HiiExPcds.append(Pcd) diff --git a/BaseTools/Source/Py= thon/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 7e8077558da5..5968a3de4e1f 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1514,35 +1514,6 @@ def CheckPcdDatum(Type, Value): =20 return True, "" =20 -## Split command line option string to list -# -# subprocess.Popen needs t= he args to be a sequence. Otherwise there's problem -# in non-windows platf= orm to launch command -# -def SplitOption(OptionString): - OptionList =3D [] - LastChar =3D " " - OptionStart =3D 0 - QuotationMark =3D "" - for Index in range(0, len(OptionString)): - CurrentChar =3D OptionString[Index] - if CurrentChar in ['"', "'"]: - if QuotationMark =3D=3D CurrentChar: - QuotationMark =3D "" - elif QuotationMark =3D=3D "": - QuotationMark =3D CurrentChar - continue - elif QuotationMark: - continue - - if CurrentChar in ["/", "-"] and LastChar in [" ", "\t", "\r", "\n= "]: - if Index > OptionStart: - OptionList.append(OptionString[OptionStart:Index - 1]) - OptionStart =3D Index - LastChar =3D CurrentChar - OptionList.append(OptionString[OptionStart:]) - return OptionList - def CommonPath(PathList): P1 =3D min(PathList).split(os.path.sep) P2 =3D max(PathList).split(os.path.sep) @@ -1551,45 +1522,6 @@ def Com= monPath(PathList): return os.path.sep.join(P1[:Index]) return os.path.sep.join(P1) =20 -# -# Convert string to C format array -# -def ConvertStringToByteArray(Value): - Value =3D Value.strip() - if not Value: - return None - if Value[0] =3D=3D '{': - if not Value.endswith('}'): - return None - Value =3D Value.replace(' ', '').replace('{', '').replace('}', '') - ValFields =3D Value.split(',') - try: - for Index in range(len(ValFields)): - ValFields[Index] =3D str(int(ValFields[Index], 0)) - except ValueError: - return None - Value =3D '{' + ','.join(ValFields) + '}' - return Value - - Unicode =3D False - if Value.startswith('L"'): - if not Value.endswith('"'): - return None - Value =3D Value[1:] - Unicode =3D True - elif not Value.startswith('"') or not Value.endswith('"'): - return None - - Value =3D eval(Value) # translate escape character - NewValue =3D '{' - for Index in range(0, len(Value)): - if Unicode: - NewValue =3D NewValue + str(ord(Value[Index]) % 0x10000) + ',' - else: - NewValue =3D NewValue + str(ord(Value[Index]) % 0x100) + ',' - Value =3D NewValue + '0}' - return Value - class PathClass(object): def __init__(self, File=3D'', Root=3D'', AlterRoot=3D'', Type=3D'', Is= Binary=3DFalse, Arch=3D'COMMON', ToolChainFamily=3D'', Target=3D'', TagNa= me=3D'', ToolCode=3D''): -- 2.16.2.windows.1