]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTool/Upt: Avoid UNI file name conflict
authorHess Chen <hesheng.chen@intel.com>
Fri, 29 Jul 2016 06:09:00 +0000 (14:09 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 3 Aug 2016 02:52:08 +0000 (10:52 +0800)
When creating a UNI file if there is a name conflict, add an index
from 0 to the file name

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <hesheng.chen@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools/Source/Python/UPT/Library/String.py

index 31abd23ccd8cbbca0f34215ec4e886d72b2f36f9..d39c1827ba2674925df53b34d17bd879ae782bfb 100644 (file)
@@ -65,6 +65,7 @@ from Library.DataType import TAB_SECTION_END
 from Library.DataType import TAB_SPLIT\r
 import Library.DataType as DT\r
 from Library.UniClassObject import FormatUniEntry\r
+from Library.String import GetUniFileName\r
 \r
 def GenPcd(Package, Content):\r
     #\r
@@ -586,9 +587,9 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '', Encoding=TAB_ENCO
         \r
     if not os.path.exists(os.path.dirname(PackageObject.GetFullPath())):\r
         os.makedirs(os.path.dirname(PackageObject.GetFullPath()))\r
-    ContainerFile = os.path.normpath(os.path.join(os.path.dirname(PackageObject.GetFullPath()), \r
-                                                  (PackageObject.GetBaseName() + '.uni')))\r
     \r
+    ContainerFile = GetUniFileName(os.path.dirname(PackageObject.GetFullPath()), PackageObject.GetBaseName())\r
+\r
     Content = UniFileHeader + '\r\n'\r
     Content += '\r\n'\r
     \r
index a131f98ead73bf9afb5e7ab7eec9c635a0af44c5..c1362e6fb3d953b9e9950949fb92c843e05cc8a9 100644 (file)
@@ -2,7 +2,7 @@
 #\r
 # This file contained the logical of transfer package object to INF files.\r
 #\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
@@ -41,6 +41,7 @@ import Logger.Log as Logger
 from Library import DataType as DT\r
 from GenMetaFile import GenMetaFileMisc\r
 from Library.UniClassObject import FormatUniEntry\r
+from Library.String import GetUniFileName\r
 \r
 \r
 ## Transfer Module Object to Inf files\r
@@ -225,8 +226,8 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD
         return\r
     else:\r
         ModuleObject.UNIFlag = True\r
-    ContainerFile = os.path.normpath(os.path.join(os.path.dirname(ModuleObject.GetFullPath()),\r
-                                                  (ModuleObject.GetBaseName() + '.uni')))\r
+    ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())\r
+\r
     if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):\r
         os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))\r
 \r
index 37ce1418ae1bc500dd5adac0656090b2c2f91366..05b5fb17da18c989c7f36785ffeb8af2428bf89e 100644 (file)
@@ -2,7 +2,7 @@
 # This file is used to define common string related functions used in parsing\r
 # process\r
 #\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available\r
 # under the terms and conditions of the BSD License which accompanies this\r
@@ -957,3 +957,27 @@ def IsMatchArch(Arch1, Arch2):
                     return True\r
 \r
     return False\r
+\r
+# Search all files in FilePath to find the FileName with the largest index\r
+# Return the FileName with index +1 under the FilePath\r
+#\r
+def GetUniFileName(FilePath, FileName):\r
+    Files = os.listdir(FilePath)\r
+    LargestIndex = -1\r
+    for File in Files:\r
+        if File.upper().startswith(FileName.upper()) and File.upper().endswith('.UNI'):\r
+            Index = File.upper().replace(FileName.upper(), '').replace('.UNI', '')\r
+            if Index:\r
+                try:\r
+                    Index = int(Index)\r
+                except Exception:\r
+                    Index = -1\r
+            else:\r
+                Index = 0\r
+            if Index > LargestIndex:\r
+                LargestIndex = Index + 1\r
+\r
+    if LargestIndex > -1:\r
+        return os.path.normpath(os.path.join(FilePath, FileName + str(LargestIndex) + '.uni'))\r
+    else:\r
+        return os.path.normpath(os.path.join(FilePath, FileName + '.uni'))\r