@@ -211,6 +211,39 @@ function clean_composer(string $dir)
211211 chdir ($ cwd );
212212}
213213
214+ /**
215+ * Executes a system command to build a package file.
216+ * Shows a start and a finish message and terminates if an error occurs.
217+ * Captures all outputs (stdout+stderr) and only displays them if an error has occurred.
218+ *
219+ * @param string $packageName Name of the package file to be created.
220+ * @param string $command The full system command to execute.
221+ *
222+ * @return void
223+ */
224+ function build_and_check (string $ packageName , string $ command ): void
225+ {
226+ echo "Building {$ packageName } ... " ;
227+
228+ // Redirect stderr to stdout
229+ $ fullCommand = $ command . ' 2>&1 ' ;
230+ $ output = [];
231+ $ exitCode = 0 ;
232+
233+ exec ($ fullCommand , $ output , $ exitCode );
234+
235+ if ($ exitCode !== 0 ) {
236+ echo "failed. \n" ;
237+ fwrite (STDERR , "ERROR: Command failed ( $ exitCode): $ command \n" );
238+ if (!empty ($ output )) {
239+ fwrite (STDERR , "Output: \n" . implode ("\n" , $ output ) . "\n" );
240+ }
241+ exit ($ exitCode );
242+ }
243+
244+ echo "done. \n" ;
245+ }
246+
214247$ time = time ();
215248
216249// Set path to git binary (e.g., /usr/local/git/bin/git or /usr/bin/git)
@@ -563,34 +596,29 @@ function clean_composer(string $dir)
563596 if (!$ excludeZip ) {
564597 $ packageName = 'Joomla_ ' . $ version . '. ' . $ fromName . '_to_ ' . $ fullVersion . '- ' . $ packageStability . '-Patch_Package.zip ' ;
565598 echo "Building " . $ packageName . "... " ;
566- chdir ($ time );
567- system ('zip ../packages/ ' . $ packageName . ' -@ < ../diffconvert/ ' . $ version . '. ' . $ num . '> /dev/null ' );
568- chdir ('.. ' );
569- echo "done. \n" ;
599+ $ command = "cd {$ time } && zip ../packages/ {$ packageName } -@ < ../diffconvert/ {$ version }. {$ num }" ;
600+ build_and_check ($ packageName , $ command );
570601 $ checksums [$ packageName ] = [];
571602 }
572603
573604 if (!$ excludeGzip ) {
574605 $ packageName = 'Joomla_ ' . $ version . '. ' . $ fromName . '_to_ ' . $ fullVersion . '- ' . $ packageStability . '-Patch_Package.tar.gz ' ;
575- echo "Building " . $ packageName . "... " ;
576- system ('tar --create --gzip --no-recursion --directory ' . $ time . ' --file packages/ ' . $ packageName . ' --files-from diffconvert/ ' . $ version . '. ' . $ num . '> /dev/null ' );
577- echo "done. \n" ;
606+ $ command = "tar --create --gzip --no-recursion --directory {$ time } --file packages/ {$ packageName } --files-from diffconvert/ {$ version }. {$ num }" ;
607+ build_and_check ($ packageName , $ command );
578608 $ checksums [$ packageName ] = [];
579609 }
580610
581611 if (!$ excludeBzip2 ) {
582612 $ packageName = 'Joomla_ ' . $ version . '. ' . $ fromName . '_to_ ' . $ fullVersion . '- ' . $ packageStability . '-Patch_Package.tar.bz2 ' ;
583- echo "Building " . $ packageName . "... " ;
584- system ('tar --create --bzip2 --no-recursion --directory ' . $ time . ' --file packages/ ' . $ packageName . ' --files-from diffconvert/ ' . $ version . '. ' . $ num . '> /dev/null ' );
585- echo "done. \n" ;
613+ $ command = "tar --create --bzip2 --no-recursion --directory {$ time } --file packages/ {$ packageName } --files-from diffconvert/ {$ version }. {$ num }" ;
614+ build_and_check ($ packageName , $ command );
586615 $ checksums [$ packageName ] = [];
587616 }
588617
589618 if (!$ excludeZstd ) {
590619 $ packageName = 'Joomla_ ' . $ version . '. ' . $ fromName . '_to_ ' . $ fullVersion . '- ' . $ packageStability . '-Patch_Package.tar.zst ' ;
591- echo "Building " . $ packageName . "... " ;
592- system ('tar "-I zstd --ultra -22" --create --no-recursion --directory ' . $ time . ' --file packages/ ' . $ packageName . ' --files-from diffconvert/ ' . $ version . '. ' . $ num . '> /dev/null ' );
593- echo "done. \n" ;
620+ $ command = "tar --create --no-recursion --directory {$ time } --files-from diffconvert/ {$ version }. {$ num } | zstd --ultra -22 -o packages/ {$ packageName }" ;
621+ build_and_check ($ packageName , $ command );
594622 $ checksums [$ packageName ] = [];
595623 }
596624}
@@ -601,33 +629,29 @@ function clean_composer(string $dir)
601629// Create full archive packages.
602630if (!$ excludeZip ) {
603631 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Full_Package.zip ' ;
604- echo "Building " . $ packageName . "... " ;
605- system ('zip -r ../packages/ ' . $ packageName . ' * > /dev/null ' );
606- echo "done. \n" ;
632+ $ command = "zip -r ../packages/ {$ packageName } * " ;
633+ build_and_check ($ packageName , $ command );
607634 $ checksums [$ packageName ] = [];
608635}
609636
610637if (!$ excludeGzip ) {
611638 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Full_Package.tar.gz ' ;
612- echo "Building " . $ packageName . "... " ;
613- system ('tar --create --gzip --file ../packages/ ' . $ packageName . ' * > /dev/null ' );
614- echo "done. \n" ;
639+ $ command = "tar --create --gzip --file ../packages/ {$ packageName } * " ;
640+ build_and_check ($ packageName , $ command );
615641 $ checksums [$ packageName ] = [];
616642}
617643
618644if (!$ excludeBzip2 ) {
619645 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Full_Package.tar.bz2 ' ;
620- echo "Building " . $ packageName . "... " ;
621- system ('tar --create --bzip2 --file ../packages/ ' . $ packageName . ' * > /dev/null ' );
622- echo "done. \n" ;
646+ $ command = "tar --create --bzip2 --file ../packages/ {$ packageName } * " ;
647+ build_and_check ($ packageName , $ command );
623648 $ checksums [$ packageName ] = [];
624649}
625650
626651if (!$ excludeZstd ) {
627652 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Full_Package.tar.zst ' ;
628- echo "Building " . $ packageName . "... " ;
629- system ('tar "-I zstd --ultra -22" --create --file ../packages/ ' . $ packageName . ' * > /dev/null ' );
630- echo "done. \n" ;
653+ $ command = "tar --create * | zstd --ultra -22 -o ../packages/ {$ packageName }" ;
654+ build_and_check ($ packageName , $ command );
631655 $ checksums [$ packageName ] = [];
632656}
633657
@@ -644,33 +668,29 @@ function clean_composer(string $dir)
644668
645669 if (!$ excludeZip ) {
646670 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Update_Package.zip ' ;
647- echo "Building " . $ packageName . "... " ;
648- system ('zip -r ../packages/ ' . $ packageName . ' * > /dev/null ' );
649- echo "done. \n" ;
671+ $ command = "zip -r ../packages/ {$ packageName } * " ;
672+ build_and_check ($ packageName , $ command );
650673 $ checksums [$ packageName ] = [];
651674 }
652675
653676 if (!$ excludeGzip ) {
654677 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Update_Package.tar.gz ' ;
655- echo "Building " . $ packageName . "... " ;
656- system ('tar --create --gzip --file ../packages/ ' . $ packageName . ' * > /dev/null ' );
657- echo "done. \n" ;
678+ $ command = "tar --create --gzip --file ../packages/ {$ packageName } * " ;
679+ build_and_check ($ packageName , $ command );
658680 $ checksums [$ packageName ] = [];
659681 }
660682
661683 if (!$ excludeBzip2 ) {
662684 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Update_Package.tar.bz2 ' ;
663- echo "Building " . $ packageName . "... " ;
664- system ('tar --create --bzip2 --file ../packages/ ' . $ packageName . ' * > /dev/null ' );
665- echo "done. \n" ;
685+ $ command = "tar --create --bzip2 --file ../packages/ {$ packageName } * " ;
686+ build_and_check ($ packageName , $ command );
666687 $ checksums [$ packageName ] = [];
667688 }
668689
669690 if (!$ excludeZstd ) {
670691 $ packageName = 'Joomla_ ' . $ fullVersion . '- ' . $ packageStability . '-Update_Package.tar.zst ' ;
671- echo "Building " . $ packageName . "... " ;
672- system ('tar "-I zstd --ultra -22" --create --file ../packages/ ' . $ packageName . ' * > /dev/null ' );
673- echo "done. \n" ;
692+ $ command = "tar --create * | zstd --ultra -22 -o ../packages/ {$ packageName }" ;
693+ build_and_check ($ packageName , $ command );
674694 $ checksums [$ packageName ] = [];
675695 }
676696}
0 commit comments