From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ml01.01.org (Postfix) with ESMTP id 21E8A1A1E24 for ; Mon, 1 Aug 2016 21:04:19 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 01 Aug 2016 21:04:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,458,1464678000"; d="scan'208";a="1033365048" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga002.fm.intel.com with ESMTP; 01 Aug 2016 21:04:18 -0700 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 1 Aug 2016 21:04:18 -0700 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.248.2; Mon, 1 Aug 2016 21:04:18 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.181]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.150]) with mapi id 14.03.0248.002; Tue, 2 Aug 2016 12:04:16 +0800 From: "Zhu, Yonghong" To: "Chen, Hesheng" , "edk2-devel@lists.01.org" Thread-Topic: [patch] BaseTool/Upt: Avoid UNI file name conflict Thread-Index: AQHR6V++tgquNCoAnkm4euKOBzf2OaA1Ev5A Date: Tue, 2 Aug 2016 04:04:15 +0000 Message-ID: References: <1469772540-215688-1-git-send-email-hesheng.chen@intel.com> In-Reply-To: <1469772540-215688-1-git-send-email-hesheng.chen@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [patch] BaseTool/Upt: Avoid UNI file name conflict X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2016 04:04:19 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: Chen, Hesheng=20 Sent: Friday, July 29, 2016 2:09 PM To: edk2-devel@lists.01.org Cc: Zhu, Yonghong Subject: [patch] BaseTool/Upt: Avoid UNI file name conflict When creating a UNI file if there is a name conflict, add an index from 0 t= o the file name Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: hesschen --- .../Source/Python/UPT/GenMetaFile/GenDecFile.py | 5 +++-- .../Source/Python/UPT/GenMetaFile/GenInfFile.py | 7 +++--- BaseTools/Source/Python/UPT/Library/String.py | 26 ++++++++++++++++++= +++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py b/BaseTo= ols/Source/Python/UPT/GenMetaFile/GenDecFile.py index 31abd23..d39c182 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py @@ -65,6 +65,7 @@ from Library.DataType import TAB_SECTION_END from Librar= y.DataType import TAB_SPLIT import Library.DataType as DT from Library.Un= iClassObject import FormatUniEntry +from Library.String import GetUniFileName =20 def GenPcd(Package, Content): # @@ -586,9 +587,9 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeade= r =3D '', Encoding=3DTAB_ENCO =20 if not os.path.exists(os.path.dirname(PackageObject.GetFullPath())): os.makedirs(os.path.dirname(PackageObject.GetFullPath())) - ContainerFile =3D os.path.normpath(os.path.join(os.path.dirname(Packag= eObject.GetFullPath()),=20 - (PackageObject.GetBaseNa= me() + '.uni'))) =20 + ContainerFile =3D=20 + GetUniFileName(os.path.dirname(PackageObject.GetFullPath()),=20 + PackageObject.GetBaseName()) + Content =3D UniFileHeader + '\r\n' Content +=3D '\r\n' =20 diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTo= ols/Source/Python/UPT/GenMetaFile/GenInfFile.py index a131f98..c1362e6 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py @@ -2,7 +2,7 @@ # # This file contained the logical of transfer package object to INF files. # -# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2016, Intel Corporation. All rights=20 +reserved.
# # This program and the accompanying materials are licensed and made availa= ble # under the terms and conditions of the BSD License which accompanies = this @@ -41,6 +41,7 @@ import Logger.Log as Logger from Library import Dat= aType as DT from GenMetaFile import GenMetaFileMisc from Library.UniClass= Object import FormatUniEntry +from Library.String import GetUniFileName =20 =20 ## Transfer Module Object to Inf files @@ -225,8 +226,8 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader= =3D'', Encoding=3DDT.TAB_ENCOD return else: ModuleObject.UNIFlag =3D True - ContainerFile =3D os.path.normpath(os.path.join(os.path.dirname(Module= Object.GetFullPath()), - (ModuleObject.GetBaseNam= e() + '.uni'))) + ContainerFile =3D GetUniFileName(os.path.dirname(ModuleObject.GetFullP= ath()), ModuleObject.GetBaseName()) + if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())): os.makedirs(os.path.dirname(ModuleObject.GetFullPath())) =20 diff --git a/BaseTools/Source/Python/UPT/Library/String.py b/BaseTools/Sour= ce/Python/UPT/Library/String.py index 37ce141..05b5fb1 100644 --- a/BaseTools/Source/Python/UPT/Library/String.py +++ b/BaseTools/Source/Python/UPT/Library/String.py @@ -2,7 +2,7 @@ # This file is used to define common string related functions used in pars= ing # process # -# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
# # This program and the accompanying materials are licensed and made availa= ble # under the terms and conditions of the BSD License which accompanies this @@ -957,3 +957,27 @@ def IsMatchArch(Arch1, Arch2): return True =20 return False + +# Search all files in FilePath to find the FileName with the largest index +# Return the FileName with index +1 under the FilePath +# +def GetUniFileName(FilePath, FileName): + Files =3D os.listdir(FilePath) + LargestIndex =3D -1 + for File in Files: + if File.upper().startswith(FileName.upper()) and File.upper().ends= with('.UNI'): + Index =3D File.upper().replace(FileName.upper(), '').replace('= .UNI', '') + if Index: + try: + Index =3D int(Index) + except Exception: + Index =3D -1 + else: + Index =3D 0 + if Index > LargestIndex: + LargestIndex =3D Index + 1 + + if LargestIndex > -1: + return os.path.normpath(os.path.join(FilePath, FileName + str(Larg= estIndex) + '.uni')) + else: + return os.path.normpath(os.path.join(FilePath, FileName + '.uni')) --=20 2.7.2.windows.1