Skip to content

Commit 01a4d87

Browse files
authored
fix windows test failures: path separators and arch normalization (crazywhalecc#1148)
2 parents 8a37303 + ad9b9ec commit 01a4d87

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/StaticPHP/Artifact/Artifact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function getSourceDir(): string
327327
public function getSourceRoot(): string
328328
{
329329
if (isset($this->config['metadata']['source-root'])) {
330-
return $this->getSourceDir() . '/' . ltrim($this->config['metadata']['source-root'], '/');
330+
return FileSystem::convertPath($this->getSourceDir() . '/' . ltrim($this->config['metadata']['source-root'], '/'));
331331
}
332332
return $this->getSourceDir();
333333
}

src/StaticPHP/Artifact/ArtifactCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ public function getAllBinaryInfo(string $artifact_name): array
223223
public function getCacheFullPath(array $cache_info): string
224224
{
225225
return match ($cache_info['cache_type']) {
226-
'archive', 'file' => DOWNLOAD_PATH . '/' . $cache_info['filename'],
227-
'git' => DOWNLOAD_PATH . '/' . $cache_info['dirname'],
226+
'archive', 'file' => FileSystem::convertPath(DOWNLOAD_PATH . '/' . $cache_info['filename']),
227+
'git' => FileSystem::convertPath(DOWNLOAD_PATH . '/' . $cache_info['dirname']),
228228
'local' => $cache_info['dirname'], // local dirname is absolute path
229229
default => throw new SPCInternalException("Unknown cache type: {$cache_info['cache_type']}"),
230230
};

tests/StaticPHP/Artifact/ArtifactTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,16 @@ public function testGetSourceDirWithAbsoluteExtractInConfig(): void
254254
ApplicationContext::initialize();
255255
ApplicationContext::set(ArtifactCache::class, $cache);
256256

257+
// Use a platform-appropriate absolute path: a Unix-style /tmp/... isn't
258+
// absolute on Windows (no drive letter), so the test would otherwise
259+
// fall through into the SOURCE_PATH-prefixed branch on Windows.
260+
$extract = DIRECTORY_SEPARATOR === '\\' ? 'C:\tmp\my-pkg-extract' : '/tmp/my-pkg-extract';
261+
257262
$artifact = new Artifact('my-pkg', [
258-
'source' => ['type' => 'url', 'url' => 'https://example.com/file.tar.gz', 'extract' => '/tmp/my-pkg-extract'],
263+
'source' => ['type' => 'url', 'url' => 'https://example.com/file.tar.gz', 'extract' => $extract],
259264
]);
260265

261-
$expected = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, '/tmp/my-pkg-extract');
266+
$expected = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $extract);
262267
$this->assertSame($expected, $artifact->getSourceDir());
263268
}
264269

@@ -703,11 +708,7 @@ private function getCurrentPlatform(): string
703708
'Windows' => 'windows',
704709
default => 'linux',
705710
};
706-
$arch = php_uname('m');
707-
if ($arch === 'arm64') {
708-
$arch = 'aarch64';
709-
}
710-
return "{$os}-{$arch}";
711+
return "{$os}-" . arch2gnu(php_uname('m'));
711712
}
712713

713714
private function injectArtifactConfig(string $name, array $config): void

0 commit comments

Comments
 (0)