pkg_maker: Make the --sign-cmd option not required 99/314699/1 accepted/tizen_8.0_unified accepted/tizen/8.0/unified/20240724.010413
authorAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 17 Jul 2024 13:01:44 +0000 (15:01 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 17 Jul 2024 14:15:23 +0000 (14:15 +0000)
When the --sign-cmd option is not used, signing the checksum.sha256
file with an external tool is not performed. The call to the external
signing tool has also been slightly improved: in addition to simply
checking whether the signing succeeded, stdout and stderr are logged
in case of failure.

Change-Id: I5495251749a4c5d3d5cc43b7974e5b1fe11100e6

src/pkg_maker/isu_pkgs_maker.py
src/pkg_maker/isu_pkgs_maker_py2.py

index 89a92a5..bb3212a 100755 (executable)
@@ -662,10 +662,17 @@ class ISUSinglePkgMaker:
                         file.write(f"{hash}  {f_path.relative_to(self._ctx.pkg_dir)}\n")
 
         sign_cmd = self._ctx.sign_cmd
-        logger.info("Signing {} file with external command".format(self.CHECKSUM_FILE))
-        signed_sum_path = str(sum_path) + '.sign'
-        if subprocess.call([sign_cmd, sum_path, signed_sum_path]) != 0:
-            logger.warning("Subprocess call to signing command failed!")
+        if sign_cmd is not None:
+            logger.info("Signing {} file with external command".format(self.CHECKSUM_FILE))
+            signed_sum_path = str(sum_path) + '.sign'
+            process = subprocess.Popen([sign_cmd, sum_path, signed_sum_path],
+                                       stdout=subprocess.PIPE,
+                                       stderr=subprocess.PIPE)
+            stdout, stderr = process.communicate()
+            if process.returncode != 0:
+                logger.error("{} error {}:".format(sign_cmd, process.returncode))
+                logger.error("stdout: {}\nstderr: {}".format(stdout.decode('utf8'), stderr.decode('utf8')))
+                raise Exception("Subprocess call to signing command failed!")
 
     def _zip_pkg(self) -> Path:
         out_name = self._ctx.out_dir / self._ctx.cfg.name
index 21bd392..678f709 100755 (executable)
@@ -684,10 +684,17 @@ class ISUSinglePkgMaker:
                         line = u"{}  {}\n".format(hash ,os.path.relpath(f_path, start=str(self._ctx.pkg_dir)))
                         file.write(line)
         sign_cmd = self._ctx.sign_cmd
-        logger.info("Signing {} file with external command".format(self.CHECKSUM_FILE))
-        signed_sum_path = sum_path + '.sign'
-        if subprocess.call([sign_cmd, sum_path, signed_sum_path]) != 0:
-            logger.warning("Subprocess call to signing command failed!")
+        if sign_cmd is not None:
+            logger.info("Signing {} file with external command".format(self.CHECKSUM_FILE))
+            signed_sum_path = sum_path + '.sign'
+            process = subprocess.Popen([sign_cmd, sum_path, signed_sum_path],
+                                       stdout=subprocess.PIPE,
+                                       stderr=subprocess.PIPE)
+            stdout, stderr = process.communicate()
+            if process.returncode != 0:
+                logger.error("{} error {}:".format(sign_cmd, process.returncode))
+                logger.error("stdout: {}\nstderr: {}".format(stdout.decode('utf8'), stderr.decode('utf8')))
+                raise Exception("Subprocess call to signing command failed!")
 
     def _zip_pkg(self):
         out_name = os.path.join(self._ctx.out_dir, self._ctx.cfg.name)