|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | +/* |
| 4 | + +----------------------------------------------------------------------+ |
| 5 | + | Copyright (c) The PHP Group | |
| 6 | + +----------------------------------------------------------------------+ |
| 7 | + | This source file is subject to version 3.01 of the PHP license, | |
| 8 | + | that is bundled with this package in the file LICENSE, and is | |
| 9 | + | available through the world-wide-web at the following url: | |
| 10 | + | https://www.php.net/license/3_01.txt | |
| 11 | + | If you did not receive a copy of the PHP license and are unable to | |
| 12 | + | obtain it through the world-wide-web, please send a note to | |
| 13 | + | [email protected] so we can mail you a copy immediately. | |
| 14 | + +----------------------------------------------------------------------+ |
| 15 | + */ |
| 16 | + |
| 17 | +/* This is a single entrypoint for non-phpt tests. */ |
| 18 | + |
| 19 | +class Environment |
| 20 | +{ |
| 21 | + public function __construct( |
| 22 | + public string $os, |
| 23 | + public string $cpuArch, |
| 24 | + public bool $zts, |
| 25 | + public bool $debug, |
| 26 | + public bool $githubAction, |
| 27 | + ) {} |
| 28 | +} |
| 29 | + |
| 30 | +function show_usage(): void |
| 31 | +{ |
| 32 | + echo <<<HELP |
| 33 | + Synopsis: |
| 34 | + php run-extra-tests.php |
| 35 | +
|
| 36 | + Environment variables: |
| 37 | + TEST_PHP_OS: One of 'Windows NT', 'Linux', 'FreeBSD', 'Darwin' |
| 38 | + TEST_PHP_CPU_ARCH: One of 'x86', 'x86_64', 'aarch64' |
| 39 | +
|
| 40 | + HELP; |
| 41 | +} |
| 42 | + |
| 43 | +function main(int $argc, array $argv): void |
| 44 | +{ |
| 45 | + if ($argc !== 1) { |
| 46 | + show_usage(); |
| 47 | + exit(1); |
| 48 | + } |
| 49 | + |
| 50 | + $environment = new Environment( |
| 51 | + detect_os(), |
| 52 | + detect_cpu_arch(), |
| 53 | + PHP_ZTS, |
| 54 | + PHP_DEBUG, |
| 55 | + getenv('GITHUB_ACTIONS') === 'true', |
| 56 | + ); |
| 57 | + |
| 58 | + echo "=====================================================================\n"; |
| 59 | + echo "OS: {$environment->os}\n"; |
| 60 | + echo "CPU Arch: {$environment->cpuArch}\n"; |
| 61 | + echo "ZTS: " . ($environment->zts ? 'Yes' : 'No') . "\n"; |
| 62 | + echo "DEBUG: " . ($environment->debug ? 'Yes' : 'No') . "\n"; |
| 63 | + echo "=====================================================================\n"; |
| 64 | + |
| 65 | + echo "No tests in this branch yet.\n"; |
| 66 | + |
| 67 | + echo "All OK\n"; |
| 68 | +} |
| 69 | + |
| 70 | +function output_group_start(Environment $environment, string $name): void |
| 71 | +{ |
| 72 | + if ($environment->githubAction) { |
| 73 | + printf("::group::%s\n", $name); |
| 74 | + } else { |
| 75 | + printf("%s\n", $name); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +function output_group_end(Environment $environment): void |
| 80 | +{ |
| 81 | + if ($environment->githubAction) { |
| 82 | + printf("::endgroup::\n"); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * Returns getenv('TEST_PHP_OS') if defined, otherwise returns one of |
| 88 | + * 'Windows NT', 'Linux', 'FreeBSD', 'Darwin', ... |
| 89 | + */ |
| 90 | +function detect_os(): string |
| 91 | +{ |
| 92 | + $os = (string) getenv('TEST_PHP_OS'); |
| 93 | + if ($os !== '') { |
| 94 | + return $os; |
| 95 | + } |
| 96 | + |
| 97 | + return php_uname('s'); |
| 98 | +} |
| 99 | + |
| 100 | +/** |
| 101 | + * Returns getenv('TEST_PHP_CPU_ARCH') if defined, otherwise returns one of |
| 102 | + * 'x86', 'x86_64', 'aarch64', ... |
| 103 | + */ |
| 104 | +function detect_cpu_arch(): string |
| 105 | +{ |
| 106 | + $cpu = (string) getenv('TEST_PHP_CPU_ARCH'); |
| 107 | + if ($cpu !== '') { |
| 108 | + return $cpu; |
| 109 | + } |
| 110 | + |
| 111 | + $cpu = php_uname('m'); |
| 112 | + if (strtolower($cpu) === 'amd64') { |
| 113 | + $cpu = 'x86_64'; |
| 114 | + } else if (in_array($cpu, ['i386', 'i686'])) { |
| 115 | + $cpu = 'x86'; |
| 116 | + } else if ($cpu === 'arm64') { |
| 117 | + $cpu = 'aarch64'; |
| 118 | + } |
| 119 | + |
| 120 | + return $cpu; |
| 121 | +} |
| 122 | + |
| 123 | +main($argc, $argv); |
0 commit comments