Skip to content

Commit

Permalink
Merge pull request #115 from asgrim/support-sub-build-path
Browse files Browse the repository at this point in the history
Added support for build-path php-ext configuration
  • Loading branch information
asgrim authored Nov 21, 2024
2 parents 96ebe7b + 19a357d commit 139b831
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"require": {
"php": "8.1.*||8.2.*||8.3.*||8.4.*",
"ext-zip": "*",
"composer/composer": "^2.8.2",
"composer/composer": "dev-main",
"fidry/cpu-core-counter": "^1.2",
"illuminate/container": "^10.47",
"symfony/console": "^6.4",
Expand Down
19 changes: 11 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions docs/extension-maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,34 @@ If an end user does not specify a flag defined in the `configure-options`
definition, it will simply not be passed to `./configure`. There is no way to
specify a default value in the `configure-options` definition.

#### `build-path`

The `build-path` setting may be used if your source code is not in the root
of your repository. For example, if your repository structure is like:

```
/
docs/
src/
config.m4
config.w32
myext.c
...etc
```

In this case, the actual extension source code would be built in `src/`, so you
should specify this path in `build-path`, for example:

```json
{
"name": "myvendor/myext",
"php-ext": {
"extension-name": "myext",
"build-path": "src"
}
}
```

### Extension dependencies

Extension authors may define some dependencies in `require`, but practically,
Expand Down
6 changes: 6 additions & 0 deletions src/DependencyResolver/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct(
public readonly array $configureOptions,
public readonly bool $supportZts,
public readonly bool $supportNts,
public readonly string|null $buildPath,
) {
}

Expand All @@ -58,6 +59,10 @@ public static function fromComposerCompletePackage(CompletePackageInterface $com
? $phpExtOptions['support-nts']
: true;

$buildPath = $phpExtOptions !== null && array_key_exists('build-path', $phpExtOptions)
? $phpExtOptions['build-path']
: null;

return new self(
$completePackage,
ExtensionType::tryFrom($completePackage->getType()) ?? ExtensionType::PhpModule,
Expand All @@ -68,6 +73,7 @@ public static function fromComposerCompletePackage(CompletePackageInterface $com
$configureOptions,
$supportZts,
$supportNts,
$buildPath,
);
}

Expand Down
13 changes: 13 additions & 0 deletions src/Downloading/DownloadedPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

use Php\Pie\DependencyResolver\Package;

use function is_string;
use function realpath;

use const DIRECTORY_SEPARATOR;

/**
* @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks
*
Expand All @@ -21,6 +26,14 @@ private function __construct(

public static function fromPackageAndExtractedPath(Package $package, string $extractedSourcePath): self
{
if ($package->buildPath !== null) {
$extractedSourcePathWithBuildPath = realpath($extractedSourcePath . DIRECTORY_SEPARATOR . $package->buildPath);

if (is_string($extractedSourcePathWithBuildPath)) {
$extractedSourcePath = $extractedSourcePathWithBuildPath;
}
}

return new self($package, $extractedSourcePath);
}
}
57 changes: 57 additions & 0 deletions test/integration/Building/UnixBuildTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Process\Process;

use function dirname;

#[CoversClass(UnixBuild::class)]
final class UnixBuildTest extends TestCase
{
Expand All @@ -44,6 +46,7 @@ public function testUnixBuildCanBuildExtension(): void
[ConfigureOption::fromComposerJsonDefinition(['name' => 'enable-pie_test_ext'])],
true,
true,
null,
),
self::TEST_EXTENSION_PATH,
);
Expand Down Expand Up @@ -96,6 +99,7 @@ public function testUnixBuildWillThrowExceptionWhenExpectedBinaryNameMismatches(
[ConfigureOption::fromComposerJsonDefinition(['name' => 'enable-pie_test_ext'])],
true,
true,
null,
),
self::TEST_EXTENSION_PATH,
);
Expand All @@ -116,4 +120,57 @@ public function testUnixBuildWillThrowExceptionWhenExpectedBinaryNameMismatches(
(new Process(['phpize', '--clean'], $downloadedPackage->extractedSourcePath))->mustRun();
}
}

public function testUnixBuildCanBuildExtensionWithBuildPath(): void
{
if (Platform::isWindows()) {
self::markTestSkipped('Unix build test cannot be run on Windows');
}

$output = new BufferedOutput();

$downloadedPackage = DownloadedPackage::fromPackageAndExtractedPath(
new Package(
$this->createMock(CompletePackage::class),
ExtensionType::PhpModule,
ExtensionName::normaliseFromString('pie_test_ext'),
'pie_test_ext',
'0.1.0',
null,
[ConfigureOption::fromComposerJsonDefinition(['name' => 'enable-pie_test_ext'])],
true,
true,
'pie_test_ext',
),
dirname(self::TEST_EXTENSION_PATH),
);

$unixBuilder = new UnixBuild();
$builtBinary = $unixBuilder->__invoke(
$downloadedPackage,
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null),
['--enable-pie_test_ext'],
$output,
null,
);

self::assertNotEmpty($builtBinary);

$outputString = $output->fetch();

self::assertStringContainsString('phpize complete.', $outputString);
self::assertStringContainsString('Configure complete with options: --enable-pie_test_ext', $outputString);
self::assertStringContainsString('Build complete:', $outputString);
self::assertStringContainsString('pie_test_ext.so', $outputString);

self::assertSame(
0,
(new Process(['make', 'test'], $downloadedPackage->extractedSourcePath))
->mustRun()
->getExitCode(),
);

(new Process(['make', 'clean'], $downloadedPackage->extractedSourcePath))->mustRun();
(new Process(['phpize', '--clean'], $downloadedPackage->extractedSourcePath))->mustRun();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function testDeterminingReleaseAssetUrlForWindows(): void
[],
true,
true,
null,
);

$io = $this->createMock(IOInterface::class);
Expand Down
1 change: 1 addition & 0 deletions test/integration/Installing/UnixInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function testUnixInstallCanInstallExtension(string $phpConfig): void
[ConfigureOption::fromComposerJsonDefinition(['name' => 'enable-pie_test_ext'])],
true,
true,
null,
),
self::TEST_EXTENSION_PATH,
);
Expand Down
1 change: 1 addition & 0 deletions test/integration/Installing/WindowsInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testWindowsInstallCanInstallExtension(): void
[],
true,
true,
null,
),
self::TEST_EXTENSION_PATH,
);
Expand Down
1 change: 1 addition & 0 deletions test/unit/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function testProcessingConfigureOptionsFromInput(): void
],
true,
true,
null,
);
$inputDefinition = new InputDefinition();
$inputDefinition->addOption(new InputOption('with-stuff', null, InputOption::VALUE_REQUIRED));
Expand Down
13 changes: 13 additions & 0 deletions test/unit/DependencyResolver/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testFromComposerCompletePackage(): void
self::assertSame('1.2.3', $package->version);
self::assertSame('vendor/foo:1.2.3', $package->prettyNameAndVersion());
self::assertNull($package->downloadUrl);
self::assertNull($package->buildPath);
}

public function testFromComposerCompletePackageWithExtensionName(): void
Expand Down Expand Up @@ -72,8 +73,20 @@ public function testGithubOrgAndRepo(string $composerPackageName, string|null $d
[],
true,
true,
null,
);

self::assertSame($expectedGithubOrgAndRepo, $package->githubOrgAndRepository());
}

public function testFromComposerCompletePackageWithBuildPath(): void
{
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
$composerCompletePackage->setPhpExt(['build-path' => 'some/subdirectory/path/']);

$package = Package::fromComposerCompletePackage($composerCompletePackage);

self::assertSame('vendor/foo:1.2.3', $package->prettyNameAndVersion());
self::assertSame('some/subdirectory/path/', $package->buildPath);
}
}
27 changes: 27 additions & 0 deletions test/unit/Downloading/DownloadedPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

use function realpath;
use function uniqid;

use const DIRECTORY_SEPARATOR;

#[CoversClass(DownloadedPackage::class)]
final class DownloadedPackageTest extends TestCase
{
Expand All @@ -29,6 +32,7 @@ public function testFromPackageAndExtractedPath(): void
[],
true,
true,
null,
);

$extractedSourcePath = uniqid('/path/to/downloaded/package', true);
Expand All @@ -38,4 +42,27 @@ public function testFromPackageAndExtractedPath(): void
self::assertSame($extractedSourcePath, $downloadedPackage->extractedSourcePath);
self::assertSame($package, $downloadedPackage->package);
}

public function testFromPackageAndExtractedPathWithBuildPath(): void
{
$package = new Package(
$this->createMock(CompletePackage::class),
ExtensionType::PhpModule,
ExtensionName::normaliseFromString('foo'),
'foo/bar',
'1.2.3',
null,
[],
true,
true,
'Downloading',
);

$extractedSourcePath = realpath(__DIR__ . '/../');

$downloadedPackage = DownloadedPackage::fromPackageAndExtractedPath($package, $extractedSourcePath);

self::assertSame($extractedSourcePath . DIRECTORY_SEPARATOR . 'Downloading', $downloadedPackage->extractedSourcePath);
self::assertSame($package, $downloadedPackage->package);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testForPackage(): void
[],
true,
true,
null,
);

$exception = CouldNotFindReleaseAsset::forPackage($package, ['something.zip', 'something2.zip']);
Expand All @@ -51,6 +52,7 @@ public function testForPackageWithMissingTag(): void
[],
true,
true,
null,
);

$exception = CouldNotFindReleaseAsset::forPackageWithMissingTag($package);
Expand Down
3 changes: 3 additions & 0 deletions test/unit/Downloading/GithubPackageReleaseAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function testUrlIsReturnedWhenFindingWindowsDownloadUrl(): void
[],
true,
true,
null,
);

$releaseAssets = new GithubPackageReleaseAssets('https://test-github-api-base-url.thephp.foundation');
Expand Down Expand Up @@ -137,6 +138,7 @@ public function testUrlIsReturnedWhenFindingWindowsDownloadUrlWithCompilerAndThr
[],
true,
true,
null,
);

$releaseAssets = new GithubPackageReleaseAssets('https://test-github-api-base-url.thephp.foundation');
Expand Down Expand Up @@ -176,6 +178,7 @@ public function testFindWindowsDownloadUrlForPackageThrowsExceptionWhenAssetNotF
[],
true,
true,
null,
);

$releaseAssets = new GithubPackageReleaseAssets('https://test-github-api-base-url.thephp.foundation');
Expand Down
Loading

0 comments on commit 139b831

Please sign in to comment.