Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Building/UnixBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Php\Pie\Platform\TargetPhp\PhpizePath;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\Util\Process;
use Php\Pie\Util\ProcessFailedWithLimitedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process as SymfonyProcess;

use function count;
Expand Down Expand Up @@ -78,7 +80,11 @@ public function __invoke(
$optionsOutput = count($configureOptions) ? ' with options: ' . implode(' ', $configureOptions) : '.';
$output->writeln('<info>Configure complete</info>' . $optionsOutput);

$this->make($targetPlatform, $downloadedPackage, $output, $outputCallback);
try {
$this->make($targetPlatform, $downloadedPackage, $output, $outputCallback);
} catch (ProcessFailedException $p) {
throw ProcessFailedWithLimitedOutput::fromProcessFailedException($p);
}

$expectedSoFile = $downloadedPackage->extractedSourcePath . '/modules/' . $downloadedPackage->package->extensionName()->name() . '.so';

Expand Down
56 changes: 56 additions & 0 deletions src/Util/ProcessFailedWithLimitedOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Php\Pie\Util;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

use function file_put_contents;
use function sprintf;
use function strlen;
use function sys_get_temp_dir;
use function uniqid;

use const DIRECTORY_SEPARATOR;

class ProcessFailedWithLimitedOutput extends ProcessFailedException
{
public static function fromProcessFailedException(ProcessFailedException $previous): self|ProcessFailedException
{
$process = $previous->getProcess();

if (strlen($process->getOutput()) > 5000) {
$tempOutputFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('pie_make_output_', true);
file_put_contents(
$tempOutputFile,
sprintf(
"Output:\n================\n%s\n\nError Output:\n================\n%s",
$process->getOutput(),
$process->getErrorOutput(),
),
);

return new self($process, $tempOutputFile);
}

return $previous;
}

public function __construct(Process $process, string $fileWithOutput)
{
parent::__construct($process);

$error = sprintf(
'The command "%s" failed. Output was saved in "%s" as it was too long' . "\n\nExit Code: %s(%s)\n\nWorking directory: %s",
$process->getCommandLine(),
$fileWithOutput,
$process->getExitCode() ?? '?',
$process->getExitCodeText() ?? '?',
$process->getWorkingDirectory() ?? '?',
);

$this->message = $error;
}
}
Loading