@@ -339,6 +339,46 @@ protected function downloadFile(string $url, string $file, ?object $project = nu
339339 }
340340 }
341341
342+ public function downloadFileWithPie (string $ pieName , string $ pieVersion , string $ file , string $ path , object $ project ): void
343+ {
344+ $ workdir = $ this ->getWorkDir ();
345+ $ cmd = <<<EOF
346+ test -f {$ workdir }/runtime/php/php && export PATH= {$ workdir }/runtime/php/: \$PATH ;
347+ export PIE_WORKING_DIRECTORY= {$ workdir }/var/ext/pie/
348+ test -d \$PIE_WORKING_DIRECTORY || mkdir -p \$PIE_WORKING_DIRECTORY ;
349+ cd {$ workdir }/var/ext/
350+ TEMP_FILE=$(mktemp) && echo "TEMP_FILE: \${TEMP_FILE}" ;
351+ { pie download {$ pieName }: {$ pieVersion } ; } > \${TEMP_FILE} 2>&1
352+ cat \${TEMP_FILE}
353+ SOURCE_CODE_DIR= \$(cat \${TEMP_FILE} | grep 'source to: ' | awk -F 'source to: ' '{ print $2 }')
354+ rm -f \${TEMP_FILE}
355+ echo " {$ pieName }: {$ pieVersion } source code: \${SOURCE_CODE_DIR}"
356+ pie info {$ pieName }: {$ pieVersion };
357+ cd \${SOURCE_CODE_DIR}
358+ tar -czf " {$ workdir }/var/ext/ {$ file }" .
359+ cp -f {$ workdir }/var/ext/ {$ file } {$ path }
360+ cd {$ workdir }
361+ EOF ;
362+ echo $ cmd ;
363+ echo PHP_EOL ;
364+ echo '------------RUNNING START------------- ' ;
365+ echo PHP_EOL ;
366+ echo `$ cmd `;
367+ echo '------------RUNNING END------------- ' ;
368+ echo PHP_EOL ;
369+ $ file = $ path ;
370+ // 下载失败
371+ if (!is_file ($ file ) or filesize ($ file ) == 0 ) {
372+ throw new Exception ("with pie Downloading file[ " . basename ($ file ) . "] from failed " );
373+ }
374+ // 下载文件的 hash 不一致
375+ if (!$ this ->skipHashVerify and $ project ->enableHashVerify ) {
376+ if (!$ project ->hashVerify ($ file )) {
377+ throw new Exception ("The {$ project ->hashAlgo } of downloaded file[ $ file] is inconsistent with the configuration " );
378+ }
379+ }
380+ }
381+
342382 /**
343383 * @param Library $lib
344384 * @throws Exception
@@ -396,8 +436,10 @@ public function addLibrary(Library $lib): void
396436
397437 public function addExtension (Extension $ ext ): void
398438 {
399- if ($ ext ->peclVersion ) {
400- $ ext ->file = $ ext ->name . '- ' . $ ext ->peclVersion . '.tgz ' ;
439+ if ($ ext ->peclVersion || $ ext ->pieVersion ) {
440+ $ extensionVersion = !empty ($ ext ->peclVersion ) ? $ ext ->peclVersion : $ ext ->pieVersion ;
441+ $ downloadType = $ ext ->peclVersion ? 'pecl ' : 'pie ' ;
442+ $ ext ->file = $ ext ->name . '- ' . $ extensionVersion . '.tgz ' ;
401443 $ ext ->path = $ this ->extensionDir . '/ ' . $ ext ->file ;
402444 $ ext ->url = "https://pecl.php.net/get/ {$ ext ->file }" ;
403445
@@ -411,8 +453,14 @@ public function addExtension(Extension $ext): void
411453 }
412454 if (!$ this ->getInputOption ('skip-download ' )) {
413455 if (!is_file ($ ext ->path ) or filesize ($ ext ->path ) === 0 ) {
414- echo "[Extension] {$ ext ->file } not found, downloading: " . $ ext ->url . PHP_EOL ;
415- $ this ->downloadFile ($ ext ->url , $ ext ->path , $ ext );
456+ if ($ downloadType === 'pecl ' ) {
457+ echo "[Extension] {$ ext ->file } not found, downloading: " . $ ext ->url . PHP_EOL ;
458+ $ this ->downloadFile ($ ext ->url , $ ext ->path , $ ext );
459+ } else {
460+ echo "[Extension] {$ ext ->file } not found, download with pie.phar " . $ ext ->homePage . PHP_EOL ;
461+ $ this ->downloadFileWithPie ($ ext ->pieName , $ ext ->pieVersion , $ ext ->file , $ ext ->path , $ ext );
462+ }
463+
416464 } else {
417465 echo "[Extension] file cached: " . $ ext ->file . PHP_EOL ;
418466 }
0 commit comments