]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTool/UPT: Add Test Install
authorHess Chen <hesheng.chen@intel.com>
Fri, 29 Jul 2016 07:58:23 +0000 (15:58 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 3 Aug 2016 02:47:52 +0000 (10:47 +0800)
Add a new function to test if a DIST file list
one by one to see if they can meet the requirement
of Dependency.

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/Core/DependencyRules.py
BaseTools/Source/Python/UPT/Logger/StringTable.py
BaseTools/Source/Python/UPT/TestInstall.py [new file with mode: 0644]
BaseTools/Source/Python/UPT/UPT.py

index 4608ed60303b842e4334463492e0291302d84f70..7039a7d6262b957cec8572735210c7dcd9eee44e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is for installed package information database operations\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
@@ -184,6 +184,25 @@ class DependencyRules(object):
         self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]\r
         return self.CheckDpDepexSatisfied(DpObj)\r
 \r
+    # # Check whether multiple DP depex satisfied by current workspace for Install\r
+    #\r
+    # @param DpObjList:  A distribution object list\r
+    # @return: True if distribution depex satisfied\r
+    #          False else\r
+    #\r
+    def CheckTestInstallPdDepexSatisfied(self, DpObjList):\r
+        self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]\r
+        for DpObj in DpObjList:\r
+            if self.CheckDpDepexSatisfied(DpObj):\r
+                for PkgKey in DpObj.PackageSurfaceArea.keys():\r
+                    PkgObj = DpObj.PackageSurfaceArea[PkgKey]\r
+                    self.PkgsToBeDepend.append((PkgObj.Guid, PkgObj.Version))\r
+            else:\r
+                return False, DpObj\r
+\r
+        return True, DpObj\r
+\r
+\r
     ## Check whether a DP depex satisfied by current workspace \r
     #  (excluding the original distribution's packages to be replaced) for Replace\r
     #\r
index 96f0e1cd6ef3aa5151f5fc761ea91366e1e31df8..4c42661ea2e4f94bfef715f32b5c9c4f3ed7a251 100644 (file)
@@ -858,3 +858,8 @@ HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED = _(
     "Specify the UEFI Distribution Package file name to be replaced")\r
 HLP_USE_GUIDED_PATHS = _(\r
     "Install packages to the following directory path by default: <PackageName>_<PACKAGE_GUID>_<PACKAGE_VERSION>")\r
+HLP_TEST_INSTALL = _(\r
+    "Specify the UEFI Distribution Package filenames to install")\r
+\r
+MSG_TEST_INSTALL_PASS = _("All distribution package file are satisfied for dependence check.")\r
+MSG_TEST_INSTALL_FAIL = _("NOT all distribution package file are satisfied for dependence check.")\r
diff --git a/BaseTools/Source/Python/UPT/TestInstall.py b/BaseTools/Source/Python/UPT/TestInstall.py
new file mode 100644 (file)
index 0000000..dae4415
--- /dev/null
@@ -0,0 +1,100 @@
+# # @file\r
+# Test Install distribution package\r
+#\r
+# Copyright (c) 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
+# distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+"""\r
+Test Install multiple distribution package\r
+"""\r
+# #\r
+# Import Modules\r
+#\r
+from Library import GlobalData\r
+import Logger.Log as Logger\r
+from Logger import StringTable as ST\r
+import Logger.ToolError as TE\r
+from Core.DependencyRules import DependencyRules\r
+from InstallPkg import UnZipDp\r
+\r
+import shutil\r
+from traceback import format_exc\r
+from platform import python_version\r
+from sys import platform\r
+\r
+# # Tool entrance method\r
+#\r
+# This method mainly dispatch specific methods per the command line options.\r
+# If no error found, return zero value so the caller of this tool can know\r
+# if it's executed successfully or not.\r
+#\r
+# @param  Options: command Options\r
+#\r
+def Main(Options=None):\r
+    ContentZipFile, DistFile = None, None\r
+    ReturnCode = 0\r
+\r
+    try:\r
+        DataBase = GlobalData.gDB\r
+        WorkspaceDir = GlobalData.gWORKSPACE\r
+        if not Options.DistFiles:\r
+            Logger.Error("TestInstallPkg", TE.OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE)\r
+\r
+        DistPkgList = []\r
+        for DistFile in Options.DistFiles:\r
+            DistPkg, ContentZipFile, __, DistFile = UnZipDp(WorkspaceDir, DistFile)\r
+            DistPkgList.append(DistPkg)\r
+\r
+        #\r
+        # check dependency\r
+        #\r
+        Dep = DependencyRules(DataBase)\r
+        Result = True\r
+        DpObj = None\r
+        try:\r
+            Result, DpObj = Dep.CheckTestInstallPdDepexSatisfied(DistPkgList)\r
+        except:\r
+            Result = False\r
+\r
+        if Result:\r
+            Logger.Quiet(ST.MSG_TEST_INSTALL_PASS)\r
+        else:\r
+            Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL)\r
+\r
+    except TE.FatalError, XExcept:\r
+        ReturnCode = XExcept.args[0]\r
+        if Logger.GetLevel() <= Logger.DEBUG_9:\r
+            Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r
+\r
+    except Exception, x:\r
+        ReturnCode = TE.CODE_ERROR\r
+        Logger.Error(\r
+                    "\nTestInstallPkg",\r
+                    TE.CODE_ERROR,\r
+                    ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.DistFiles,\r
+                    ExtraData=ST.MSG_SEARCH_FOR_HELP,\r
+                    RaiseError=False\r
+                    )\r
+        Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r
+\r
+    finally:\r
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)\r
+        if DistFile:\r
+            DistFile.Close()\r
+        if ContentZipFile:\r
+            ContentZipFile.Close()\r
+        if GlobalData.gUNPACK_DIR:\r
+            shutil.rmtree(GlobalData.gUNPACK_DIR)\r
+            GlobalData.gUNPACK_DIR = None\r
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE)\r
+    if ReturnCode == 0:\r
+        Logger.Quiet(ST.MSG_FINISH)\r
+    return ReturnCode\r
+\r
index 59c4a88f8efea8141c03cad349f755e95624d415..8dd949ae90388d4f7066b473a9f99a1c24732499 100644 (file)
@@ -46,6 +46,7 @@ import InstallPkg
 import RmPkg\r
 import InventoryWs\r
 import ReplacePkg\r
+import TestInstall\r
 from Library.Misc import GetWorkspace\r
 from Library import GlobalData\r
 from Core.IpiDb import IpiDatabase\r
@@ -69,6 +70,9 @@ def CheckConflictOption(Opt):
         Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_R_EXCLUSIVE)\r
     elif Opt.PackFileToCreate and  Opt.PackFileToRemove:\r
         Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE)\r
+    elif Opt.TestDistFiles and (Opt.PackFileToCreate or Opt.PackFileToInstall \\r
+                                or Opt.PackFileToRemove or Opt.PackFileToReplace):\r
+        Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE)\r
 \r
     if Opt.CustomPath and Opt.UseGuidedPkgPath:\r
         Logger.Warn("UPT", ST.WARN_CUSTOMPATH_OVERRIDE_USEGUIDEDPATH)\r
@@ -146,6 +150,9 @@ def Main():
 \r
     Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS)\r
 \r
+    Parser.add_option("-j", "--test-install", action="append", type="string",\r
+                      dest="Test_Install_Distribution_Package_Files", help=ST.HLP_TEST_INSTALL)\r
+\r
     Opt = Parser.parse_args()[0]\r
 \r
     Var2Var = [\r
@@ -159,6 +166,7 @@ def Main():
         ("PackFileToReplace", Opt.Replace_Distribution_Package_File),\r
         ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File),\r
         ("UseGuidedPkgPath", Opt.Use_Guided_Paths),\r
+        ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files)\r
     ]\r
 \r
     for Var in Var2Var:\r
@@ -265,6 +273,14 @@ def Main():
             Opt.PackFileToReplace = AbsPath\r
             RunModule = ReplacePkg.Main\r
 \r
+        elif Opt.Test_Install_Distribution_Package_Files:\r
+            for Dist in Opt.Test_Install_Distribution_Package_Files:\r
+                if not Dist.endswith('.dist'):\r
+                    Logger.Error("TestInstall", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Dist)\r
+\r
+            setattr(Opt, 'DistFiles', Opt.Test_Install_Distribution_Package_Files)\r
+            RunModule = TestInstall.Main\r
+\r
         else:\r
             Parser.print_usage()\r
             return OPTION_MISSING\r