mirror of
https://github.com/php/php-src.git
synced 2024-11-23 01:44:06 +08:00
Show build provider and unify version information printing (#14657)
* Show build provider information in "php -v" Vendors such as distributions can set the `PHP_BUILD_PROVIDER` variable, that gets printed in phpinfo. However, I find that users check `php -v` more often than phpinfo to see what PHP they're running. The problem with this is that it does not show that build provider information. This change makes the build provider information printed on an additional line of the version information. * Put on same line so it works with or without env var Unbreaks build without PHP_BUILD_PROVIDER set. * change wording in provider version text better grammatically; many different possibilities here though * Unify SAPI version printing This makes it so that all of the SAPIs share the same code for printing version information. This is useful in case of any future changes to the version information, such as i.e. adding build provider to the output. * Make include for php_print_version explicit * Preserve phpdbg version and output channel php_printf doesn't have same semantics, as phpdbg_out could be on a different output than stdout/err. Also add the phpdbg version (in case it differs from PHP's, to keep similar output before this PR) * remove size variables we don't use them and CI doesn't like unused variables * Fix format string insecurity
This commit is contained in:
parent
225034dbbc
commit
afc5738154
41
main/main.c
41
main/main.c
@ -108,6 +108,47 @@ PHPAPI unsigned int php_version_id(void)
|
||||
return PHP_VERSION_ID;
|
||||
}
|
||||
|
||||
PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
|
||||
{
|
||||
char *version_info;
|
||||
spprintf(&version_info, 0, "PHP %s (%s) (built: %s %s) (%s)\nCopyright (c) The PHP Group\n%s%s",
|
||||
PHP_VERSION, sapi_module->name, __DATE__, __TIME__,
|
||||
#ifdef ZTS
|
||||
"ZTS"
|
||||
#else
|
||||
"NTS"
|
||||
#endif
|
||||
#ifdef PHP_BUILD_COMPILER
|
||||
" " PHP_BUILD_COMPILER
|
||||
#endif
|
||||
#ifdef PHP_BUILD_ARCH
|
||||
" " PHP_BUILD_ARCH
|
||||
#endif
|
||||
#if ZEND_DEBUG
|
||||
" DEBUG"
|
||||
#endif
|
||||
#ifdef HAVE_GCOV
|
||||
" GCOV"
|
||||
#endif
|
||||
,
|
||||
#ifdef PHP_BUILD_PROVIDER
|
||||
"Built by " PHP_BUILD_PROVIDER "\n"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
,
|
||||
get_zend_version()
|
||||
);
|
||||
return version_info;
|
||||
}
|
||||
|
||||
PHPAPI void php_print_version(sapi_module_struct *sapi_module)
|
||||
{
|
||||
char *version_info = php_get_version(sapi_module);
|
||||
php_printf("%s", version_info);
|
||||
efree(version_info);
|
||||
}
|
||||
|
||||
/* {{{ PHP_INI_MH */
|
||||
static PHP_INI_MH(OnSetFacility)
|
||||
{
|
||||
|
@ -36,6 +36,12 @@ PHPAPI const char *php_version(void);
|
||||
*/
|
||||
PHPAPI unsigned int php_version_id(void);
|
||||
|
||||
/* Prints the PHP version string for the -v option. It's in main/ so that
|
||||
* it can be shared between SAPIs.
|
||||
*/
|
||||
PHPAPI char *php_get_version(sapi_module_struct *sapi_module);
|
||||
PHPAPI void php_print_version(sapi_module_struct *sapi_module);
|
||||
|
||||
PHPAPI zend_result php_request_startup(void);
|
||||
PHPAPI void php_request_shutdown(void *dummy);
|
||||
PHPAPI zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_module);
|
||||
|
@ -2384,11 +2384,7 @@ parent_loop_end:
|
||||
}
|
||||
SG(headers_sent) = 1;
|
||||
SG(request_info).no_headers = 1;
|
||||
#if ZEND_DEBUG
|
||||
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
||||
#else
|
||||
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
||||
#endif
|
||||
php_print_version(&cgi_sapi_module);
|
||||
php_request_shutdown((void *) 0);
|
||||
fcgi_shutdown();
|
||||
exit_status = 0;
|
||||
|
@ -17,6 +17,6 @@ echo "Done\n";
|
||||
--EXPECTF--
|
||||
string(%d) "PHP %s (cgi%s (built: %s
|
||||
Copyright (c) The PHP Group
|
||||
Zend Engine v%s, Copyright (c) Zend Technologies
|
||||
%AZend Engine v%s, Copyright (c) Zend Technologies
|
||||
"
|
||||
Done
|
||||
|
@ -625,28 +625,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
|
||||
goto out;
|
||||
|
||||
case 'v': /* show php version & quit */
|
||||
php_printf("PHP %s (%s) (built: %s %s) (%s)\nCopyright (c) The PHP Group\n%s",
|
||||
PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,
|
||||
#ifdef ZTS
|
||||
"ZTS"
|
||||
#else
|
||||
"NTS"
|
||||
#endif
|
||||
#ifdef PHP_BUILD_COMPILER
|
||||
" " PHP_BUILD_COMPILER
|
||||
#endif
|
||||
#ifdef PHP_BUILD_ARCH
|
||||
" " PHP_BUILD_ARCH
|
||||
#endif
|
||||
#if ZEND_DEBUG
|
||||
" DEBUG"
|
||||
#endif
|
||||
#ifdef HAVE_GCOV
|
||||
" GCOV"
|
||||
#endif
|
||||
,
|
||||
get_zend_version()
|
||||
);
|
||||
php_print_version(&cli_sapi_module);
|
||||
sapi_deactivate();
|
||||
goto out;
|
||||
|
||||
|
@ -14,6 +14,6 @@ echo "Done\n";
|
||||
--EXPECTF--
|
||||
string(%d) "PHP %s (cli) (built: %s)%s
|
||||
Copyright (c) The PHP Group
|
||||
Zend Engine v%s, Copyright (c) Zend Technologies
|
||||
%AZend Engine v%s, Copyright (c) Zend Technologies
|
||||
"
|
||||
Done
|
||||
|
@ -1705,11 +1705,7 @@ int main(int argc, char *argv[])
|
||||
SG(headers_sent) = 1;
|
||||
SG(request_info).no_headers = 1;
|
||||
|
||||
#if ZEND_DEBUG
|
||||
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
||||
#else
|
||||
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
||||
#endif
|
||||
php_print_version(&sapi_module);
|
||||
php_request_shutdown((void *) 0);
|
||||
fcgi_shutdown();
|
||||
exit_status = FPM_EXIT_OK;
|
||||
|
@ -1272,11 +1272,7 @@ static int cli_main( int argc, char * argv[] )
|
||||
break;
|
||||
case 'v':
|
||||
if (php_request_startup() != FAILURE) {
|
||||
#if ZEND_DEBUG
|
||||
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
||||
#else
|
||||
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
||||
#endif
|
||||
php_print_version(&sapi_module);
|
||||
#ifdef PHP_OUTPUT_NEWAPI
|
||||
php_output_end_all();
|
||||
#else
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "phpdbg_arginfo.h"
|
||||
#include "zend_vm.h"
|
||||
#include "php_ini_builder.h"
|
||||
#include "php_main.h"
|
||||
|
||||
#include "ext/standard/basic_functions.h"
|
||||
|
||||
@ -1369,14 +1370,14 @@ phpdbg_main:
|
||||
if (show_help) {
|
||||
phpdbg_do_help_cmd(exec);
|
||||
} else if (show_version) {
|
||||
phpdbg_out(
|
||||
"phpdbg %s (built: %s %s)\nPHP %s, Copyright (c) The PHP Group\n%s",
|
||||
PHPDBG_VERSION,
|
||||
__DATE__,
|
||||
__TIME__,
|
||||
PHP_VERSION,
|
||||
get_zend_version()
|
||||
);
|
||||
char *version_info = php_get_version(&phpdbg_sapi_module);
|
||||
/* we also want to include phpdbg version */
|
||||
char *prepended_version_info;
|
||||
spprintf(&prepended_version_info, 0,
|
||||
"phpdbg %s, %s", PHPDBG_VERSION, version_info);
|
||||
phpdbg_out("%s", prepended_version_info);
|
||||
efree(prepended_version_info);
|
||||
efree(version_info);
|
||||
}
|
||||
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
|
||||
php_module_shutdown();
|
||||
|
Loading…
Reference in New Issue
Block a user