Compare commits

..

1 Commits

Author SHA1 Message Date
Anatol Belski e55b13cce9 Prepare 2.1.7 2018-07-19 18:31:14 +02:00
241 changed files with 9693 additions and 55737 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright 2017-2019 Anatol Belski Copyright 2017-2018 Anatol Belski
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+16 -92
View File
@@ -8,26 +8,19 @@ The PHP SDK itself and the SDK own tools and code are licensed under the BSD 2-C
# Overview # Overview
The toolset consists on a mix of the hand written scripts, selected MSYS2 parts and standalone programs. It supports any workflows, be it a custom, local or a CI build whatsoever. The PHP SDK 2.0+ is compatible with PHP 7.0 and above. The compatibility with [older versions](http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip "php-sdk-binary-tools-20110915.zip") is kept, also available from the [legacy branch](https://github.com/Microsoft/php-sdk-binary-tools/tree/legacy). The toolset was significantly revamped. Newer tools are now available, better workflows are now possible. The toolset consists on a mix of the hand written scripts, selected MSYS2 parts and standalone programs.
The PHP SDK 2.2+ is compatible with PHP 7.2 and above.
The PHP SDK 2.1 is required to build PHP 7.1 or 7.0.
The legacy binary tools SDK is available from the [legacy branch](https://github.com/php/php-sdk-binary-tools/tree/legacy) and is suitable to build PHP 5.
# Requirements # Requirements
- A 64-bit build host - `Visual C++ 2015` or `Visual C++ 2017` must be installed prior SDK usage
- Windows 7 or later - if `Cygwin` is installed, please read notes in the pitfalls section
- `Visual C++ 2017` or `Visual C++ 2019` must be installed prior SDK usage. Required components - if a 64-bit build is intended, a 64-bit system is required. Cross compilation of 64-bit on 32-bit system is not supported at the moment
- C++ dev - The PHP SDK was successfully tested on Windows 7 or later, earlier versions might work but are not recommended
- Windows SDK
- .NET dev
- if `Cygwin`, `MingW` or any other cross solution is installed, please read notes in the pitfalls section
# Tools # Tools
All the tools included are either scripts or 32-bit binaries. They are therefore runable on any of x86 or x64 supported Windows system.
## SDK ## SDK
- starter scripts, named phpsdk-<crt>-<arch>.bat - starter scripts, named phpsdk-<crt>-<arch>.bat
@@ -40,8 +33,8 @@ The legacy binary tools SDK is available from the [legacy branch](https://github
## Other tools ## Other tools
- `bison` 3.3.2, `re2c` 1.1.1, `lemon` - `bison` 3.0.5, `re2c` 1.0.3, `lemon`
- `awk`, `gawk`, `sed`, `grep`, `jq` - `awk`, `gawk`, `sed`, `grep`
- `diff`, `diff3`, `patch` - `diff`, `diff3`, `patch`
- `md5sum`, `sha1sum`, `sha224sum`, `sha256sum`, `sha384sum`, `sha512sum` - `md5sum`, `sha1sum`, `sha224sum`, `sha256sum`, `sha384sum`, `sha512sum`
- `7za`, `zip`, `unzip`, `unzipsfx` - `7za`, `zip`, `unzip`, `unzipsfx`
@@ -59,7 +52,7 @@ These are not included with the PHP SDK, but might be useful. While Visual C++ i
# Usage # Usage
The PHP SDK should be unzipped into the shortest possible path, preferably somewhere near the drive root. The PHP SDK should be unzipped into the shortest possible path, preferrably somewhere near the drive root.
Usually, the first step to start the PHP SDK is by invoking one of the suitable starter scripts. This automatically puts the console on the correct environment relevant for the desired PHP build configuration. Usually, the first step to start the PHP SDK is by invoking one of the suitable starter scripts. This automatically puts the console on the correct environment relevant for the desired PHP build configuration.
@@ -67,9 +60,9 @@ It is not required to hold the source in the PHP SDK directory. It could be usef
## Basic usage example ## Basic usage example
- `git clone https://github.com/php/php-sdk-binary-tools.git c:\php-sdk` - `git clone https://github.com/Microsoft/php-sdk-binary-tools.git c:\php-sdk`
- `cd c:\php-sdk` - `cd c:\php-sdk`
- `git checkout php-sdk-2.1.9` or later - `git checkout php-sdk-2.0.12` or later
- invoke `phpsdk-vc15-x64.bat` - invoke `phpsdk-vc15-x64.bat`
- `phpsdk_buildtree phpmaster` - `phpsdk_buildtree phpmaster`
- `git clone https://github.com/php/php-src.git && cd php-src`, or fetch a zipball - `git clone https://github.com/php/php-src.git && cd php-src`, or fetch a zipball
@@ -80,7 +73,7 @@ More extensive documentation can be found on the [wiki](https://wiki.php.net/int
## The old way ## The old way
- `git clone https://github.com/php/php-sdk-binary-tools.git c:\php-sdk` - `git clone https://github.com/Microsoft/php-sdk-binary-tools.git c:\php-sdk`
- follow the instructions on the PHP [wiki page](https://wiki.php.net/internals/windows/stepbystepbuild "PHP wiki page") - follow the instructions on the PHP [wiki page](https://wiki.php.net/internals/windows/stepbystepbuild "PHP wiki page")
# Customizing # Customizing
@@ -122,9 +115,7 @@ As of the version 2.1.0, the SDK includes a tool for the [PGO](https://docs.micr
## Preparing PGO training environment ## Preparing PGO training environment
- the pgo folder in the SDK root dir contains templates and scenarios for PGO training - the pgo folder in the SDK root dir contains templates and scenarios for PGO training
- adjust and execute [doc/phpsdk_pgo_prep_elevated.bat.example](doc/phpsdk_pgo_prep_elevated.bat.example) to open ports required for PHP SDK training servers - adjust and execute [doc/phpsdk_pgo_prep_elevated.bat.example](doc/phpsdk_pgo_prep_elevated.bat.example) to open ports required for PHP SDK training servers
- run `phpsdk_pgo --init`. Note that composer requires huge amounts of memory, so - run `phpsdk_pgo --init`
it may be necessary to set the environment variable `COMPOSER_MEMORY_LIMIT=-1`.
The PGO initialization may not succeed in x86 enviroments.
## Creating PGO build ## Creating PGO build
- compile PHP configured using `--enable-pgi` - compile PHP configured using `--enable-pgi`
@@ -147,51 +138,6 @@ After a training case is implemented and put under `pgo/cases`, the work environ
To skip a training case, add a file named `inactive` into the case folder. To skip a training case, add a file named `inactive` into the case folder.
# Debugging PHP
This part covers debugging possibilities for the builds produced by the native VS compilers.
For the cross compiled builds produced with toolsets other than VC++, please check the
documentation for the corresponding toolsets. In any case, general principles on debugging
native programs apply.
Either a debug build of PHP or enabled debug symbols are required to be able to debug PHP.
A debug build is usually more suitable for the development process and can be produced by
adding `--enable-debug` to the configure options. A release build with debug symbols can
be produced by adding `--enable-debug-pack`. These options are mutually exclusive.
## Debugging with Visual Studio
- Configure with either `--enable-debug` or `--enable-debug-pack`.
- A debug build might bring better experience for dev, but sometimes you want to debug a release build.
- `nmake run ARGS=yourscript.php DEBUGGER=1`, that will open a Visual Studio window.
- Any additional runtime options for PHP or the script executed go to ARGS, too.
- Select `Debug -> New Breakpoint -> Function Breakpoint` and add a function where the debugger should break.
- Click `Start`.
Adding a breakpoint before starting debugging might be not necessary, if a crash is debugged. When such a script runs
under the debugger, the debugger will stop at the crashing point. In that case, a breakpoint can be added
around the crashed code directly.
## Debugging test suite with Visual Studio
The [Microsoft Child Process Debugging Power Tool](https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool)
plugin for Visual Studio is required. After installing it, following these steps
- `nmake test TESTS=ext/myext/tests/sometest.phpt DEBUGGER=1`
- Select `Debug -> Other Debug Targets -> Child Process Debugging Settings` and enable child process debugging.
- If necessary, add a breakpoint and start debugging as described in the previous section.
## Debugging with WinDbg
PHP can also be debugged with the tools from the WinDbg package. There is currently no way
implemented in the Makefile to start the WinDbg integrated, so it needs to de done manually.
Either a debug build or a release build with debug symbols is still required, as described
previously.
# Support
- Join `#winphp-dev` on Freenode to discuss any ideas or questions
- File an issue on GitHub
# Pitfalls # Pitfalls
@@ -201,30 +147,8 @@ previously.
- When fetching the binary SDK from git, git `core.autocrlf` configuration directive set to `false` is recommended. - When fetching the binary SDK from git, git `core.autocrlf` configuration directive set to `false` is recommended.
- Tools, based on MSYS2, only accept paths with forward slashes. - Tools, based on MSYS2, only accept paths with forward slashes.
- Both Visual C++ toolset and the Windows SDK components have to be installed for the PHP SDK to work properly. - Both Visual C++ toolset and the Windows SDK components have to be installed for the PHP SDK to work properly.
- The VC++ toolset is still required, even if another compiler, fe. clang, is intended to be used. - The VC++ toolset is still requried, even if another compiler, fe. clang, is intended to be used.
- `task.exe` is not a console application, some systems might not propagate exit code except the batch is explicitly run from `cmd /c`, etc. - `task.exe` is not a console application, some systems might not propagate exit code except the batch is explicitly run from `cmd /c`, etc.
- `7za` should be preferred over `unzip` and `zip` for compatibility reasons. - `7za` should be prefered over `unzip` and `zip` for compatibility reasons.
- If you experience some strange crashes on MSYS2 tools, try the phpsdk_rebase_msys2 tool. MSYS2 tools might be have unstable
on ASLR enabled systems.
# Internal notes
## Releases
Users of the PHP SDK are supposed to use tagged versions for stability and
reproducability. This requires the maintainers of the PHP SDK to create such
tags for *all* *relevant* *changes*. The tag format should be `php-sdk-X.Y.Z`,
with the common major, minor and revision numbers.
Comprehensive changes, which would be hard to test extensively, such as updates
to the bundled PHP or the MinGW tools, should walk through a QA (aka. pre-release)
process, typically with beta versions (e.g. `php-sdk-X.Y.Zbeta1`). Only after
these have been thoroughly tested, and all relevant issues have been resolved,
a GA release should be tagged.
After each tag, a couple of other repositories should be informed about the
available update, ideally in form of a pull request. These repositories are:
* https://github.com/php/php-src (for Windows CI)
* https://github.com/php/php-windows-builder
* https://github.com/php/setup-php-sdk
+1 -1
View File
@@ -1 +1 @@
2.3.1-dev 2.1.7
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Executable → Regular
View File
BIN
View File
Binary file not shown.
Executable → Regular
View File
Executable → Regular
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
+1 -2
View File
@@ -5,8 +5,7 @@ extension=php_sqlite3.dll
extension=php_openssl.dll extension=php_openssl.dll
extension=php_mbstring.dll extension=php_mbstring.dll
extension=php_mysqli.dll extension=php_mysqli.dll
extension=php_zip.dll memory_limit=1G
memory_limit=4G
error_reporting=-1 error_reporting=-1
display_errors=1 display_errors=1
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Executable → Regular
+11 -16
View File
@@ -10,27 +10,22 @@ rem otherwise - retain the old behavior, create structs for all the known build
cmd /c "exit /b 0" cmd /c "exit /b 0"
if "%PHP_SDK_ARCH%" NEQ "" ( if "%PHP_SDK_ARCH%" NEQ "" (
if "%PHP_SDK_VS%" NEQ "" ( if "%PHP_SDK_VC%" NEQ "" (
MD %_%\%PHP_SDK_VS%\%PHP_SDK_ARCH%\deps\bin MD %_%\%PHP_SDK_VC%\%PHP_SDK_ARCH%\deps\bin
MD %_%\%PHP_SDK_VS%\%PHP_SDK_ARCH%\deps\lib MD %_%\%PHP_SDK_VC%\%PHP_SDK_ARCH%\deps\lib
MD %_%\%PHP_SDK_VS%\%PHP_SDK_ARCH%\deps\include MD %_%\%PHP_SDK_VC%\%PHP_SDK_ARCH%\deps\include
cd %_%\%PHP_SDK_VS%\%PHP_SDK_ARCH% cd %_%\%PHP_SDK_VC%\%PHP_SDK_ARCH%
goto exit goto exit
) )
goto create_all goto create_all
) else ( ) else (
:create_all :create_all
for %%i in (vc14 vc15 vs16 vs17) do ( MD %_%\vc14\x86\deps\bin
MD %_%\%%i\x86\deps\bin MD %_%\vc14\x86\deps\lib
MD %_%\%%i\x86\deps\lib MD %_%\vc14\x86\deps\include
MD %_%\%%i\x86\deps\include MD %_%\vc14\x64\deps\bin
MD %_%\%%i\x64\deps\bin MD %_%\vc14\x64\deps\lib
MD %_%\%%i\x64\deps\lib MD %_%\vc14\x64\deps\include
MD %_%\%%i\x64\deps\include
MD %_%\%%i\arm64\deps\bin
MD %_%\%%i\arm64\deps\lib
MD %_%\%%i\arm64\deps\include
)
) )
set _= set _=
Executable → Regular
View File
+13 -5
View File
@@ -1,6 +1,6 @@
<?php <?php
include __DIR__ . "/../lib/php/autoload.php"; include dirname(__FILE__) . "/../lib/php/autoload.php";
use SDK\{Config, Exception}; use SDK\{Config, Exception};
@@ -36,7 +36,7 @@ try {
switch ($name) { switch ($name) {
default: default:
throw new Exception("Unknown switch '$name'"); throw new Exception("Unknown switch '$name'");
break; break;
case "h": case "h":
case "help": case "help":
@@ -126,9 +126,17 @@ try {
usage(3); usage(3);
} }
/* The current CRT needs to match the config one. */ /* The current CRT needs to match the config one. */
$active_crt = getenv("PHP_SDK_VS"); $active_crt = getenv("PHP_SDK_VC");
if (Config::getCurrentCrtName() != $active_crt && !$force) { if (Config::getCurrentCrtName() != $active_crt && !$force) {
throw new Exception("Active CRT name '$active_crt' differs from the branch CRT name '" . Config::getCurrentCrtName() . "'."); throw new Exception("Active CRT '$active_crt' differs from the branch CRT '" . Config::getCurrentCrtName() . "'.");
}
if (NULL === Config::getCurrentStabilityName()) {
if ("master" == Config::getCurrentBranchName()) {
Config::setCurrentStabilityName("staging");
} else {
Config::setCurrentStabilityName("stable");
}
} }
$branch_data = Config::getCurrentBranchData(); $branch_data = Config::getCurrentBranchData();
@@ -180,7 +188,7 @@ function usage(int $code = -1)
echo "Usage: ", PHP_EOL, PHP_EOL; echo "Usage: ", PHP_EOL, PHP_EOL;
echo "Configuration:", PHP_EOL; echo "Configuration:", PHP_EOL;
echo " -b --branch Branch name, eg. 7.0, 7.1, etc. If omited, several guess methods apply.", PHP_EOL; echo " -b --branch Branch name, eg. 7.0, 7.1, etc. If omited, several guess methods apply.", PHP_EOL;
echo " -a --arch Architecture, x86 or x64 or arm64. If omited, cl.exe is used to guess.", PHP_EOL; echo " -a --arch Architecture, x86 or x64. If omited, cl.exe is used to guess.", PHP_EOL;
echo " -t --crt CRT, marked by the corresponding VC++ version, eg. vc11, vc14, etc.", PHP_EOL; echo " -t --crt CRT, marked by the corresponding VC++ version, eg. vc11, vc14, etc.", PHP_EOL;
echo " -s --stability One of stable or staging.", PHP_EOL, PHP_EOL; echo " -s --stability One of stable or staging.", PHP_EOL, PHP_EOL;
echo "Commands:", PHP_EOL; echo "Commands:", PHP_EOL;
Executable → Regular
View File
+9 -9
View File
@@ -29,10 +29,10 @@ $flags = 0;
$opt = getopt($sopt, $lopt); $opt = getopt($sopt, $lopt);
foreach ($opt as $name => $val) { foreach ($opt as $name => $val) {
switch ($name) { switch ($name) {
case "p": case "p":
case "pretty": case "pretty":
$flags = JSON_PRETTY_PRINT; $flags = JSON_PRETTY_PRINT;
break; break;
} }
} }
@@ -65,7 +65,7 @@ foreach ($dirs as $path) {
continue; continue;
} }
if (!preg_match(",.*-(v[c|s]\d+)-(x\d\d)\.zip,", $filename, $m)) { if (!preg_match(",.*-(vc\d+)-(x\d\d)\.zip,", $filename, $m)) {
continue; continue;
} }
@@ -85,16 +85,16 @@ foreach ($dirs as $path) {
$dlls = array(); $dlls = array();
for ($i = 0; $i < $zip->numFiles; $i++) { for( $i = 0; $i < $zip->numFiles; $i++ ){
$stat = $zip->statIndex($i); $stat = $zip->statIndex( $i );
if (substr($stat['name'], -3) != "dll") { if (substr($stat['name'], -3) != "dll") {
continue; continue;
} }
$dlls[] = basename($stat['name']); $dlls[] = basename($stat['name']);
} }
$zip->close(); $zip->close();
unset($zip); unset($zip);
Executable → Regular
+13 -3
View File
@@ -12,9 +12,19 @@ echo.
call %PHP_SDK_BIN_PATH%\phpsdk_version.bat call %PHP_SDK_BIN_PATH%\phpsdk_version.bat
echo. echo.
echo OS architecture: %PHP_SDK_OS_ARCH% if "%PHP_SDK_OS_ARCH%"=="x64" (
echo Build architecture: %PHP_SDK_ARCH% echo OS architecture: 64-bit
echo Visual C++: %PHP_SDK_VC_TOOLSET_VER% ) else (
echo OS architecture: 32-bit
)
if "%PHP_SDK_ARCH%"=="x64" (
echo Build architecture: 64-bit
) else (
echo Build architecture: 32-bit
)
echo Visual C++: %PHP_SDK_VC_NUM%
echo PHP-SDK path: %PHP_SDK_ROOT_PATH% echo PHP-SDK path: %PHP_SDK_ROOT_PATH%
Executable → Regular
+14 -14
View File
@@ -1,14 +1,14 @@
@echo off @echo off
if "%PHP_SDK_PHP_CMD%"=="" ( if "%PHP_SDK_PHP_CMD%"=="" (
call %~dp0phpsdk_setvars.bat call %~dp0phpsdk_setvars.bat
if "!PHP_SDK_PHP_CMD!"=="" ( if "!PHP_SDK_PHP_CMD!"=="" (
echo PHP SDK is not setup echo PHP SDK is not setup
exit /b 3 exit /b 3
) )
) )
cmd /c %PHP_SDK_PHP_CMD% %PHP_SDK_BIN_PATH%\phpsdk_pgo.php %* cmd /c %PHP_SDK_PHP_CMD% %PHP_SDK_BIN_PATH%\phpsdk_pgo.php %*
exit /b %errorlevel% exit /b %errorlevel%
+38 -37
View File
@@ -1,6 +1,6 @@
<?php <?php
include __DIR__ . "/../lib/php/autoload.php"; include dirname(__FILE__) . "/../lib/php/autoload.php";
use SDK\Config; use SDK\Config;
use SDK\Exception; use SDK\Exception;
@@ -21,42 +21,43 @@ try {
$opt = getopt($sopt, $lopt); $opt = getopt($sopt, $lopt);
foreach ($opt as $name => $val) { foreach ($opt as $name => $val) {
switch ($name) { switch ($name) {
case "i": case "i":
case "init": case "init":
$cmd = "init"; $cmd = "init";
break; break;
case "ready": case "ready":
$cmd = "check_init"; $cmd = "check_init";
break; break;
case "t": case "t":
case "train": case "train":
$cmd = "train"; $cmd = "train";
break; break;
case "u": case "u":
case "up": case "up":
$cmd = "up"; $cmd = "up";
break; break;
case "d": case "d":
case "down": case "down":
$cmd = "down"; $cmd = "down";
break; break;
case "s": case "s":
case "scenario": case "scenario":
$scenario = $val; $scenario = $val;
break; break;
case "f": case "f":
case "force": case "force":
$force = true; $force = true;
break; break;
/* XXX This option is for now only integrated for training. It /* XXX This option is for now only integrated for training. It
would make sense to integrate it also with init. */ would make sense to integrate it also with init. */
case "c": case "c":
case "cases": case "cases":
$cases = explode(",", $val); $cases = explode(",", $val);
break; break;
case "h": case "help": case "h": case "help":
usage(0); usage(0);
break; break;
} }
} }
-40
View File
@@ -1,40 +0,0 @@
@echo off
setlocal enableextensions enabledelayedexpansion
set PHPSDK_MSYS2_BASE_ADDR=0x100400000
set PHPSDK_MSYS2_BASE_DYNAMIC=0
:getopt
if /i "%1" equ "--help" goto help
if /i "%1" equ "--addr" (
set PHPSDK_MSYS2_BASE_ADDR=%2 & shift
for /l %%a in (1,1,100) do if "!PHPSDK_MSYS2_BASE_ADDR:~-1!"==" " set PHPSDK_MSYS2_BASE_ADDR=!PHPSDK_MSYS2_BASE_ADDR:~0,-1!
)
shift
if /i "%1" equ "--dynamic" (
set PHPSDK_MSYS2_BASE_DYNAMIC=1
shift
)
if not (%1)==() goto getopt
IF "1" EQU "%PHPSDK_MSYS2_BASE_DYNAMIC%" (
echo Rebasing MSYS2 DLLs to load at a dynamic address
editbin /NOLOGO /DYNAMICBASE %PHP_SDK_ROOT_PATH%\msys2\usr\bin\*.dll
) else (
echo Rebasing MSYS2 DLLs to load at %PHPSDK_MSYS2_BASE_ADDR%
editbin /NOLOGO /REBASE:BASE=%PHPSDK_MSYS2_BASE_ADDR%,DOWN %PHP_SDK_ROOT_PATH%\msys2\usr\bin\*.dll
)
set PHPSDK_MSYS2_BASE_ADDR=
set PHPSDK_MSYS2_BASE_DYNAMIC=
GOTO EXIT
:help
echo phpsdk_rebase_msys2 ^<address^>
echo Rebase MSYS2 DLLs to the given address. If ommited, default is 0x100400000.
:EXIT
exit /b %errorlevel%
Executable → Regular
+51 -125
View File
@@ -15,144 +15,91 @@ if "%2"=="" goto :help
cmd /c "exit /b 0" cmd /c "exit /b 0"
set PHP_SDK_VS=%1 set PHP_SDK_VC=%1
if /i not "%PHP_SDK_VS:~0,2%"=="vc" ( if /i not "%PHP_SDK_VC:~0,2%"=="vc" (
if /i not "%PHP_SDK_VS:~0,2%"=="vs" (
:malformed_vc_string :malformed_vc_string
echo Malformed CRT string "%1" echo Malformed CRT string "%1"
set PHP_SDK_VS= set PHP_SDK_VC=
goto out_error goto out_error
)
) )
if ""=="%PHP_SDK_VS:~2%" ( if ""=="%PHP_SDK_VC:~2%" (
goto malformed_vc_string goto malformed_vc_string
) )
set /a TMP_CHK=%PHP_SDK_VS:~2% set /a TMP_CHK=%PHP_SDK_VC:~2%
if 14 gtr %TMP_CHK% ( if 14 gtr %TMP_CHK% (
if "0"=="%TMP_CHK%" ( if "0"=="%TMP_CHK%" (
if not "0"=="%PHP_SDK_VS:~2%" ( if not "0"=="%PHP_SDK_VC:~2%" (
set TMP_CHK= set TMP_CHK=
goto malformed_vc_string goto malformed_vc_string
) )
) )
echo At least vc14 is required echo At least vc14 is required
set PHP_SDK_VS= set PHP_SDK_VC=
set TMP_CHK= set TMP_CHK=
goto out_error goto out_error
) )
set PHP_SDK_VS_NUM=%TMP_CHK% set PHP_SDK_VC_NUM=%TMP_CHK%
set TMP_CHK= set TMP_CHK=
rem check target arch if /i not "%2"=="x64" (
if "%2"=="x86" set PHP_SDK_ARCH=%2 if /i not "%2"=="x86" (
if "%2"=="x64" set PHP_SDK_ARCH=%2 echo Unsupported arch "%2"
if "%2"=="x86_64" set PHP_SDK_ARCH=x64 goto out_error
if "%2"=="amd64" set PHP_SDK_ARCH=x64 )
if "%2"=="arm64" set PHP_SDK_ARCH=%2
if "%PHP_SDK_ARCH%"=="" (
echo Unsupported target arch %2 >&2
goto out_error
) )
set TOOLSET= set PHP_SDK_ARCH=%2
if NOT "%3"=="" SET TOOLSET=%3
rem check OS arch rem check OS arch
rem todo: allow user choose host sdk arch (i.e. x64 target can be compiled at x64(native) or x86(cross)) set TMPKEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
for /f "usebackq tokens=1*" %%i in (`wmic cpu get Architecture /value /format:table ^| findstr /r "[1234567890][1234567890]*"`) do ( reg query "%TMPKEY%" /v "ProgramFilesDir (x86)" >nul 2>nul
set PHP_SDK_OS_ARCH_NUM=%%i if not errorlevel 1 (
set PHP_SDK_OS_ARCH=x64
) else (
if /i "%PHP_SDK_ARCH%"=="x64" (
echo 32-bit OS detected, native 64-bit toolchain is unavailable.
goto out_error
)
set PHP_SDK_OS_ARCH=x86
) )
set TMPKEY=
goto os_arch_cases
:os_arch_error
echo Unsupported OS arch %PHP_SDK_OS_ARCH% >&2
goto out_error
:os_arch_cases
if "%PHP_SDK_OS_ARCH_NUM%"=="0" set PHP_SDK_OS_ARCH=x86
if "%PHP_SDK_OS_ARCH_NUM%"=="1" (set PHP_SDK_OS_ARCH=mips && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="2" (set PHP_SDK_OS_ARCH=alpha && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="3" (set PHP_SDK_OS_ARCH=ppc && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="4" (set PHP_SDK_OS_ARCH=shx && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="5" (set PHP_SDK_OS_ARCH=arm32 && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="6" (set PHP_SDK_OS_ARCH=ia64 && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="7" (set PHP_SDK_OS_ARCH=alpha64 && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="8" (set PHP_SDK_OS_ARCH=msil && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="9" set PHP_SDK_OS_ARCH=x64
rem wow64
if "%PHP_SDK_OS_ARCH_NUM%"=="10" set PHP_SDK_OS_ARCH=x86
if "%PHP_SDK_OS_ARCH_NUM%"=="11" (set PHP_SDK_OS_ARCH=neutral && goto os_arch_error)
if "%PHP_SDK_OS_ARCH_NUM%"=="12" set PHP_SDK_OS_ARCH=arm64
if "%PHP_SDK_OS_ARCH_NUM%"=="13" (set PHP_SDK_OS_ARCH=arm32 && goto os_arch_error)
rem woa64
if "%PHP_SDK_OS_ARCH_NUM%"=="14" set PHP_SDK_OS_ARCH=x86
if "%PHP_SDK_OS_ARCH%"=="" (
goto os_arch_error
)
set PHP_SDK_OS_ARCH_NUM=
rem cross compile is ok, so we donot need this
rem if not /i "%PHP_SDK_ARCH%"=="PHP_SDK_OS_ARCH" (
rem echo 32-bit OS detected, native 64-bit toolchain is unavailable.
rem goto out_error
rem )
rem get vc base dir rem get vc base dir
if 15 gtr %PHP_SDK_VS_NUM% ( if 15 gtr %PHP_SDK_VC_NUM% (
rem for arch other than x86, use WOW6432 if /i "%PHP_SDK_OS_ARCH%"=="x64" (
if /i not "%PHP_SDK_OS_ARCH%"=="x86" ( set TMPKEY=HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%PHP_SDK_VC:~2%.0\Setup\VC
set TMPKEY=HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC
) else ( ) else (
set TMPKEY=HKLM\SOFTWARE\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC set TMPKEY=HKLM\SOFTWARE\Microsoft\VisualStudio\%PHP_SDK_VC:~2%.0\Setup\VC
) )
reg query !TMPKEY! /v ProductDir >nul 2>&1 reg query !TMPKEY! /v ProductDir >nul 2>&1
if errorlevel 1 ( if errorlevel 1 (
echo Couldn't determine VC%PHP_SDK_VS:~2% directory echo Couldn't determine VC%PHP_SDK_VC:~2% directory
goto out_error; goto out_error;
) )
for /f "tokens=2*" %%a in ('reg query !TMPKEY! /v ProductDir') do set PHP_SDK_VC_DIR=%%b for /f "tokens=2*" %%a in ('reg query !TMPKEY! /v ProductDir') do set PHP_SDK_VC_DIR=%%b
) else ( ) else (
rem build the version range, e.g. "[15,16)" rem vc15 support only for now, could parse out and pass on later
set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1 for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version %PHP_SDK_VC_NUM% -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do set PHP_SDK_VC_DIR=%%b\VC
set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!PHP_SDK_VS_RANGE%!)"
set APPEND=x86.x64
if /i "%PHP_SDK_OS_ARCH%"=="arm64" (
set APPEND=ARM64
)
set VS_VERSION_ARGS="-latest"
if "%TOOLSET%"=="" set VS_VERSION_ARGS=-version !PHP_SDK_VS_RANGE!
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo !VS_VERSION_ARGS! -requires Microsoft.VisualStudio.Component.VC.Tools.!APPEND! -property installationPath -format text') do (
set PHP_SDK_VC_DIR=%%b\VC
)
if not exist "!PHP_SDK_VC_DIR!" ( if not exist "!PHP_SDK_VC_DIR!" (
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo !VS_VERSION_ARGS! -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.!APPEND! -property installationPath -format text') do ( for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version %PHP_SDK_VC_NUM% -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do set PHP_SDK_VC_DIR=%%b\VC
set PHP_SDK_VC_DIR=%%b\VC
)
if not exist "!PHP_SDK_VC_DIR!" ( if not exist "!PHP_SDK_VC_DIR!" (
rem check for a preview release rem check for a preview release
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo !VS_VERSION_ARGS! -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.!APPEND! -property installationPath -format text') do ( for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version %PHP_SDK_VC_NUM% -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do set PHP_SDK_VC_DIR=%%b\VC
set PHP_SDK_VC_DIR=%%b\VC
)
if not exist "!PHP_SDK_VC_DIR!" ( if not exist "!PHP_SDK_VC_DIR!" (
echo Could not determine '%PHP_SDK_VS%' directory echo Could not determine '%PHP_SDK_VC%' directory
goto out_error; goto out_error;
) )
) )
) )
set VSCMD_ARG_no_logo=nologo set VSCMD_ARG_no_logo=nologo
) )
set APPEND=
set TMPKEY= set TMPKEY=
set PHP_SDK_VS_RANGE=
if 15 gtr %PHP_SDK_VS_NUM% ( if 15 gtr %PHP_SDK_VC_NUM% (
rem get sdk dir rem get sdk dir
rem if 10.0 is available, it's ok rem if 10.0 is available, it's ok
rem for arch other than x86, use WOW6432 if /i "%PHP_SDK_OS_ARCH%"=="x64" (
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0 set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0
) else ( ) else (
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0 set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0
@@ -166,8 +113,7 @@ if 15 gtr %PHP_SDK_VS_NUM% (
) )
rem Otherwise 8.1 should be available anyway rem Otherwise 8.1 should be available anyway
rem for arch other than x86, use WOW6432 if /i "%PHP_SDK_OS_ARCH%"=="x64" (
if /i not "%PHP_SDK_OS_ARCH%"=="x86" (
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1 set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1
) else ( ) else (
set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1 set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1
@@ -185,40 +131,20 @@ if 15 gtr %PHP_SDK_VS_NUM% (
) )
if /i "%PHP_SDK_ARCH%"=="x64" ( if /i "%PHP_SDK_ARCH%"=="x64" (
set TARGET_ARCH_NAME=amd64 if 15 gtr %PHP_SDK_VC_NUM% (
set PHP_SDK_VC_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" amd64
) else (
set PHP_SDK_VC_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" amd64
)
) else ( ) else (
set TARGET_ARCH_NAME=%PHP_SDK_ARCH% if 15 gtr %PHP_SDK_VC_NUM% (
set PHP_SDK_VC_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" x86
) else (
set PHP_SDK_VC_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" x86
)
) )
if /i "%PHP_SDK_OS_ARCH%"=="x64" ( rem echo Visual Studio path %PHP_SDK_VC_DIR%
set HOST_ARCH_NAME=amd64
) else (
set HOST_ARCH_NAME=%PHP_SDK_ARCH%
)
if "%HOST_ARCH_NAME%"=="%TARGET_ARCH_NAME%" (
set VCVARSALL_ARCH_NAME=%HOST_ARCH_NAME%
) else if "%HOST_ARCH_NAME%_%TARGET_ARCH_NAME%"=="amd64_x86" (
set VCVARSALL_ARCH_NAME=%TARGET_ARCH_NAME%
) else (
set VCVARSALL_ARCH_NAME=%HOST_ARCH_NAME%_%TARGET_ARCH_NAME%
)
if 15 gtr %PHP_SDK_VS_NUM% (
if NOT "%TOOLSET%"=="" (
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" !VCVARSALL_ARCH_NAME! -vcvars_ver=%TOOLSET%
) else (
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" !VCVARSALL_ARCH_NAME!
)
) else (
if NOT "%TOOLSET%"=="" (
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" !VCVARSALL_ARCH_NAME! -vcvars_ver=%TOOLSET%
) else (
set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" !VCVARSALL_ARCH_NAME!
)
)
set VCVARSALL_ARCH_NAME=
rem echo Visual Studio VC path %PHP_SDK_VC_DIR%
rem echo Windows SDK path %PHP_SDK_WIN_SDK_DIR% rem echo Windows SDK path %PHP_SDK_WIN_SDK_DIR%
Executable → Regular
-7
View File
@@ -17,12 +17,5 @@ set PHP_SDK_PHP_CMD=%PHP_SDK_BIN_PATH%\php\do_php.bat
set PATH=%PHP_SDK_BIN_PATH%;%PHP_SDK_MSYS2_PATH%;%PATH% set PATH=%PHP_SDK_BIN_PATH%;%PHP_SDK_MSYS2_PATH%;%PATH%
for /f "tokens=1* delims=: " %%a in ('link /?') do (
set PHP_SDK_VC_TOOLSET_VER=%%b
goto break0
)
:break0
set PHP_SDK_VC_TOOLSET_VER=%PHP_SDK_VC_TOOLSET_VER:~-13%
exit /b %errorlevel% exit /b %errorlevel%
Executable → Regular
View File
BIN
View File
Binary file not shown.
Executable → Regular
View File
Executable → Regular
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -18,7 +18,7 @@ rem netsh advfirewall set allprofiles state off
rem NGINX rem NGINX
netsh advfirewall firewall add rule name="NGINX for PGO" dir=in action=allow program="C:\php-snap-build\php-sdk\pgo\work\server\nginx\nginx.exe" profile=private netsh advfirewall firewall add rule name="NGINX for PGO" dir=in action=allow program="C:\php-snap-build\php-sdk\pgo\work\server\nginx\nginx.exe" profile=private
for /l %%p in (8081, 1, 8091) do ( for \l %%p in (8081, 1, 8091) do (
netsh advfirewall firewall add rule name="Open Port %%p for PHP PGO" dir=in action=allow protocol=TCP localport=%%p profile=private netsh advfirewall firewall add rule name="Open Port %%p for PHP PGO" dir=in action=allow protocol=TCP localport=%%p profile=private
netsh advfirewall firewall add rule name="Open Port %%p for PHP PGO" dir=in action=allow protocol=UDP localport=%%p profile=private netsh advfirewall firewall add rule name="Open Port %%p for PHP PGO" dir=in action=allow protocol=UDP localport=%%p profile=private
) )
+72 -72
View File
@@ -1,72 +1,72 @@
/** /**
* Run the passed command line hidden, suitable for a scheduled task. * Run the passed command line hidden, suitable for a scheduled task.
* Author: Anatol Belski <ab@php.net> * Author: Anatol Belski <ab@php.net>
* License: BSD 2-Clause * License: BSD 2-Clause
*/ */
#include <windows.h> #include <windows.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define CMD_PRE "cmd.exe /c " #define CMD_PRE "cmd.exe /c "
#define CMD_PRE_LEN (sizeof(CMD_PRE)-1) #define CMD_PRE_LEN (sizeof(CMD_PRE)-1)
#ifdef DEBUG #ifdef DEBUG
int int
main(int argc, char **argv) main(int argc, char **argv)
#else #else
int int
APIENTRY WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPTSTR in_cmd, int show) APIENTRY WinMain(HINSTANCE inst, HINSTANCE prev_inst, LPTSTR in_cmd, int show)
#endif #endif
{ {
STARTUPINFO si; STARTUPINFO si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
DWORD exit_code; DWORD exit_code;
char *cmd = NULL; char *cmd = NULL;
size_t cmd_len = 0, arg_len = 0; size_t cmd_len = 0, arg_len = 0;
char *arg = strchr(GetCommandLine(), ' '); char *arg = strchr(GetCommandLine(), ' ');
if (!arg) { if (!arg) {
return 3; return 3;
} }
#ifdef DEBUG #ifdef DEBUG
printf("passed cmd: '%s'\n", arg); printf("passed cmd: '%s'\n", arg);
#endif #endif
arg_len = strlen(arg); arg_len = strlen(arg);
cmd_len = CMD_PRE_LEN + arg_len + 1; cmd_len = CMD_PRE_LEN + arg_len + 1;
cmd = malloc(cmd_len * sizeof(char)); cmd = malloc(cmd_len * sizeof(char));
memmove(cmd, CMD_PRE, CMD_PRE_LEN); memmove(cmd, CMD_PRE, CMD_PRE_LEN);
memmove(cmd + CMD_PRE_LEN, arg, arg_len); memmove(cmd + CMD_PRE_LEN, arg, arg_len);
cmd[cmd_len-1] = '\0'; cmd[cmd_len-1] = '\0';
#ifdef DEBUG #ifdef DEBUG
printf("constructed cmd: '%s'\n", cmd); printf("constructed cmd: '%s'\n", cmd);
#endif #endif
ZeroMemory( &si, sizeof(si) ); ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si); si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW; si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; si.wShowWindow = SW_HIDE;
ZeroMemory( &pi, sizeof(pi) ); ZeroMemory( &pi, sizeof(pi) );
if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
CloseHandle( pi.hThread ); CloseHandle( pi.hThread );
} else { } else {
free(cmd); free(cmd);
printf( "Error: CreatePracess 0x%08lx \n", GetLastError() ); printf( "Error: CreatePracess 0x%08lx \n", GetLastError() );
return 3; return 3;
} }
WaitForSingleObject( pi.hProcess, INFINITE ); WaitForSingleObject( pi.hProcess, INFINITE );
GetExitCodeProcess(pi.hProcess, &exit_code); GetExitCodeProcess(pi.hProcess, &exit_code);
CloseHandle( pi.hProcess ); CloseHandle( pi.hProcess );
free(cmd); free(cmd);
return exit_code; return exit_code;
} }
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
spl_autoload_register(function($name) { spl_autoload_register(function($name) {
$fl = __DIR__ . DIRECTORY_SEPARATOR . "libsdk" . DIRECTORY_SEPARATOR . $name . ".php"; $fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . "libsdk" . DIRECTORY_SEPARATOR . $name . ".php";
if (file_exists($fl)) { if (file_exists($fl)) {
require_once $fl; require_once $fl;
@@ -2,29 +2,18 @@
namespace SDK\Build\Dependency; namespace SDK\Build\Dependency;
use SDK\{Exception, FileOps}; use SDK\{Config, Exception, FileOps};
class Fetcher class Fetcher
{ {
use FileOps; use FileOps;
/** @var string */
protected $host; protected $host;
/** @var int */
protected $port; protected $port;
/** @var ?string */
protected $stability; protected $stability;
/** @var ?string */
protected $arch; protected $arch;
/** @var Series */
protected $series; protected $series;
/** @var string */
protected $scheme;
public function __construct(string $host, int $port, string $scheme = "https", string $arch = NULL, string $stability = NULL, Series $series = NULL) public function __construct(string $host, int $port, string $scheme = "https", string $arch = NULL, string $stability = NULL, Series $series = NULL)
{/*{{{*/ {/*{{{*/
@@ -33,7 +22,6 @@ class Fetcher
$this->host = $host; $this->host = $host;
$this->port = $port; $this->port = $port;
$this->scheme = $scheme; $this->scheme = $scheme;
$this->series = $series;
}/*}}}*/ }/*}}}*/
public function getSeries() : Series public function getSeries() : Series
@@ -8,25 +8,11 @@ class Manager
{ {
use FileOps; use FileOps;
/** @var string */
protected $stability; protected $stability;
/** @var string */
protected $arch; protected $arch;
/** @var string */
protected $path; protected $path;
/** @var Cache */
protected $cache;
/** @var Series */
protected $series; protected $series;
/** @var Fetcher */
protected $fetcher; protected $fetcher;
/** @var ?bool */
protected $updatesFlag = NULL; protected $updatesFlag = NULL;
public function __construct(string $path, string $stability, string $arch) public function __construct(string $path, string $stability, string $arch)
@@ -55,7 +41,7 @@ class Manager
public function updatesAvailable() : bool public function updatesAvailable() : bool
{/*{{{*/ {/*{{{*/
if (NULL !== $this->updatesFlag) { if (!is_null($this->updatesFlag)) {
return $this->updatesFlag; return $this->updatesFlag;
} }
@@ -8,16 +8,9 @@ class Package
{ {
use FileOps; use FileOps;
/** @var string */
protected $name; protected $name;
/** @var Series */
protected $series; protected $series;
/** @var Fetcher */
protected $fetcher; protected $fetcher;
/** @var string */
protected $filepath; protected $filepath;
public function __construct(string $name, Series $series, Fetcher $fetcher) public function __construct(string $name, Series $series, Fetcher $fetcher)
+1 -10
View File
@@ -8,19 +8,10 @@ use SDK\Exception;
class Series class Series
{ {
/** @var ?Fetcher */
protected $fetcher; protected $fetcher;
/** @var string */
protected $stability; protected $stability;
/** @var string */
protected $arch; protected $arch;
/** @var string */
protected $rawData; protected $rawData;
/** @var Cache */
protected $cache; protected $cache;
public function __construct(string $stability, string $arch, Cache $cache, Fetcher $fetcher = NULL) public function __construct(string $stability, string $arch, Cache $cache, Fetcher $fetcher = NULL)
@@ -53,6 +44,7 @@ class Series
public function getName() : string public function getName() : string
{/*{{{*/ {/*{{{*/
$base = Config::getDepsBaseUri();
$branch_data = Config::getCurrentBranchData(); $branch_data = Config::getCurrentBranchData();
$file = "packages-" . Config::getCurrentBranchName() . "-{$branch_data['crt']}-{$this->arch}-{$this->stability}.txt"; $file = "packages-" . Config::getCurrentBranchName() . "-{$branch_data['crt']}-{$this->arch}-{$this->stability}.txt";
@@ -68,7 +60,6 @@ class Series
return "$base/series/$file"; return "$base/series/$file";
}/*}}}*/ }/*}}}*/
/** @return array<string>|string */
public function getData(bool $raw = false, bool $cache = true) public function getData(bool $raw = false, bool $cache = true)
{/*{{{*/ {/*{{{*/
if ($cache && $this->rawData) { if ($cache && $this->rawData) {
+25 -58
View File
@@ -2,30 +2,16 @@
namespace SDK\Build\PGO\Abstracts; namespace SDK\Build\PGO\Abstracts;
use SDK\Build\PGO\Interfaces\Server;
use SDK\Build\PGO\PHP\CLI; use SDK\Build\PGO\PHP\CLI;
use SDK\{Config as SDKConfig, Exception}; use SDK\Build\PGO\Config as PGOConfig;
use SDK\{Config as SDKConfig, Exception, FileOps};
abstract class PHP abstract class PHP
{ {
/** @var string */
protected $php_root; protected $php_root;
/** @var string */
protected $php_ext_root; protected $php_ext_root;
/** @var string */
protected $opcache_file_cache;
/** @var string */
protected $id;
/** @var string */
protected $scenario;
/** @var \SDK\Build\PGO\Config */
protected $conf;
/** @return void */
protected function setupPaths() protected function setupPaths()
{ {
$this->php_root = $this->getRootDir(); $this->php_root = $this->getRootDir();
@@ -37,20 +23,14 @@ abstract class PHP
} else { } else {
$this->php_ext_root = $this->php_root; $this->php_ext_root = $this->php_root;
} }
if ("cache" == $this->scenario) {
$this->opcache_file_cache = SDKConfig::getTmpDir() . DIRECTORY_SEPARATOR . $this->id;
}
} }
abstract public function getExeFilename() : string;
/* TODO Might be improved. */ /* TODO Might be improved. */
public function isDist() : bool public function isDist() : bool
{ {
return !file_exists("Makefile") && file_exists("php.exe"); return !file_exists("Makefile") && file_exists("php.exe");
} }
/** @return array<string,string> */
protected function createEnv() : array protected function createEnv() : array
{ {
$env = getenv(); $env = getenv();
@@ -59,22 +39,12 @@ abstract class PHP
$deps_root = SDKConfig::getDepsLocalPath(); $deps_root = SDKConfig::getDepsLocalPath();
foreach ($env as $k => $v) { foreach ($env as $k => $v) {
if (strtoupper($k) == "PATH") { if (strtoupper($k) == "PATH") {
$env[$k] = $deps_root . DIRECTORY_SEPARATOR . "bin;" . $env[$k]; $env[$k] = "$deps_root" . DIRECTORY_SEPARATOR . "bin;" . $env[$k];
break; break;
} }
} }
} }
$drive = getenv("HOMEDRIVE");
$path = getenv("HOMEPATH");
if (!$drive || !$path) {
$p = SDKConfig::getTmpDir();
$drive = substr($p, 0, 2);
$path = substr($p, 2);
putenv("HOMEDRIVE=$drive");
putenv("HOMEPATH=$path");
}
return $env; return $env;
} }
@@ -111,7 +81,7 @@ abstract class PHP
public function getVersion(bool $short = false) : string public function getVersion(bool $short = false) : string
{ {
$ret = NULL; $ret = NULL;
$cli = new CLI($this->conf); $cli = new CLI($this->conf, $this->scenario);
$out = shell_exec($cli->getExeFilename() . " -n -v"); $out = shell_exec($cli->getExeFilename() . " -n -v");
@@ -125,7 +95,7 @@ abstract class PHP
} }
} }
if (NULL === $ret) { if (is_null($ret)) {
throw new Exception("Failed to determine the test PHP version."); throw new Exception("Failed to determine the test PHP version.");
} }
@@ -134,7 +104,7 @@ abstract class PHP
public function isThreadSafe() : bool public function isThreadSafe() : bool
{ {
$cli = new CLI($this->conf); $cli = new CLI($this->conf, $this->scenario);
$out = shell_exec($cli->getExeFilename() . " -n -v"); $out = shell_exec($cli->getExeFilename() . " -n -v");
@@ -145,8 +115,20 @@ abstract class PHP
return true; return true;
} }
public function is64bit() : bool
{
$cli = new CLI($this->conf, $this->scenario);
$out = shell_exec($cli->getExeFilename() . " -n -v");
if (preg_match(",x64,", $out, $m) > 0) {
return true;
}
return false;
}
/* Need to cleanup it somewhere. */ /* Need to cleanup it somewhere. */
/** @return string */
public function getIniFilename() public function getIniFilename()
{ {
$ret = tempnam(sys_get_temp_dir(), "ini"); $ret = tempnam(sys_get_temp_dir(), "ini");
@@ -156,7 +138,7 @@ abstract class PHP
$this->conf->buildTplVarName("php", "error_log") => $this->getRootDir() . DIRECTORY_SEPARATOR . "pgo_run_error.log", $this->conf->buildTplVarName("php", "error_log") => $this->getRootDir() . DIRECTORY_SEPARATOR . "pgo_run_error.log",
); );
$k = SDKConfig::getCurrentArchName(); $k = $this->is64bit() ? "x64" : "x86";
$scenario_vars = (array)$this->conf->getSectionItem("php", "scenario", $this->scenario, "ini", $k); $scenario_vars = (array)$this->conf->getSectionItem("php", "scenario", $this->scenario, "ini", $k);
if ($scenario_vars) { if ($scenario_vars) {
foreach ($scenario_vars as $k => $v) { foreach ($scenario_vars as $k => $v) {
@@ -165,11 +147,6 @@ abstract class PHP
} }
} }
/* Special handling, otherwise it'll need functionality to extrapolate ini values. */
if ("cache" == $this->scenario) {
$tpl_vars[$this->conf->buildTplVarName("php", "opcache", "file_cache")] = $this->opcache_file_cache;
}
$this->conf->processTplFile( $this->conf->processTplFile(
$this->getIniTplFilename(), $this->getIniTplFilename(),
$ret, $ret,
@@ -179,7 +156,6 @@ abstract class PHP
return $ret; return $ret;
} }
/** @return string */
protected function getIniTplFilename() protected function getIniTplFilename()
{ {
$tpl_path = $this->conf->getTplDir("php"); $tpl_path = $this->conf->getTplDir("php");
@@ -195,12 +171,11 @@ abstract class PHP
return $construct; return $construct;
} }
/** @param array<string,string> $extra_env */
public function exec(string $php_cmd, string $args = NULL, array $extra_env = array()) : int public function exec(string $php_cmd, string $args = NULL, array $extra_env = array()) : int
{ {
$env = $this->createEnv(); $env = $this->createEnv();
$exe = $this->getExeFilename(); $exe = $this->getExeFilename();
$ini = $this->getIniFilename(); $ini = $this->getIniFilename();
$cert_path = getenv("PHP_SDK_ROOT_PATH") . "\\msys2\\usr\\ssl\\cert.pem"; $cert_path = getenv("PHP_SDK_ROOT_PATH") . "\\msys2\\usr\\ssl\\cert.pem";
$ini .= " -d curl.cainfo=$cert_path"; $ini .= " -d curl.cainfo=$cert_path";
@@ -228,7 +203,7 @@ abstract class PHP
$env[$k] = $v; $env[$k] = $v;
} }
$cmd = "$exe -n -c $ini " . ($args ? "$args " : "") . $php_cmd; $cmd = "$exe -n -c $ini " . ($args ? "$args " : "") . "$php_cmd";
$desc = array( $desc = array(
0 => array("file", "php://stdin", "r"), 0 => array("file", "php://stdin", "r"),
@@ -239,13 +214,5 @@ abstract class PHP
return proc_close($p); return proc_close($p);
} }
public function getIdString(): string
{
return $this->getVersion() . "-"
. SDKConfig::getCurrentCrtName() . "-"
. ($this->isThreadSafe() ? "ts" : "nts") . "-"
. SDKConfig::getCurrentArchName()
. "-" . substr(md5(uniqid()), 0, 8);
}
} }
@@ -4,14 +4,8 @@ namespace SDK\Build\PGO\Abstracts;
use SDK\Build\PGO\Interfaces; use SDK\Build\PGO\Interfaces;
abstract class Server class Server
{ {
/** @var string */
protected $name;
/** @var Interfaces\PHP */
protected $php;
public function getName() : string public function getName() : string
{ {
return $this->name; return $this->name;
@@ -23,3 +17,6 @@ abstract class Server
} }
} }
@@ -2,28 +2,19 @@
namespace SDK\Build\PGO\Abstracts; namespace SDK\Build\PGO\Abstracts;
use SDK\FileOps; use SDK\Build\PGO\Config as PGOConfig;
use SDK\Build\PGO\Interfaces; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Tool; use SDK\Build\PGO\Tool;
abstract class TrainingCase implements Interfaces\TrainingCase class TrainingCase
{ {
use FileOps; use FileOps;
const TYPE_WEB = "web"; const TYPE_WEB = "web";
const TYPE_CLI = "cli"; const TYPE_CLI = "cli";
/** @var array<mixed> */
protected $stat = array(); protected $stat = array();
/** @var \SDK\Build\PGO\Config */
protected $conf;
/** @var mixed */
protected $php;
abstract public function getName() : string;
public function getType() : string public function getType() : string
{ {
$type = $this->conf->getSectionItem($this->getName(), "type"); $type = $this->conf->getSectionItem($this->getName(), "type");
@@ -157,3 +148,4 @@ abstract class TrainingCase implements Interfaces\TrainingCase
return $ret; return $ret;
} }
} }
+5 -31
View File
@@ -2,7 +2,7 @@
namespace SDK\Build\PGO; namespace SDK\Build\PGO;
use SDK\Exception; use SDK\{Config as SDKConfig, Exception};
class Config class Config
{ {
@@ -11,25 +11,14 @@ class Config
const MODE_REINIT = 2; /* currently unused */ const MODE_REINIT = 2; /* currently unused */
const MODE_CHECK_INIT = 3; const MODE_CHECK_INIT = 3;
/** @var int */
protected $mode; protected $mode;
/** @var int */
protected $last_port = 8081; protected $last_port = 8081;
/** @var array<string,mixed> */
protected $sections = array(); protected $sections = array();
/** @var string */
protected $scenario = "default"; protected $scenario = "default";
/** @var array<mixed> */
protected $tpl_vars = array(); protected $tpl_vars = array();
/** @var array<mixed> */
protected $srv = array(); protected $srv = array();
public function __construct(int $mode = self::MODE_RUN) public function __construct(int $mode = MODE_RUN)
{ {
if (self::MODE_CHECK_INIT == $mode) { if (self::MODE_CHECK_INIT == $mode) {
// XXX The check is simple right now, so this is sufficient. // XXX The check is simple right now, so this is sufficient.
@@ -51,6 +40,7 @@ class Config
$this->mode = $mode; $this->mode = $mode;
$base = getenv("PHP_SDK_ROOT_PATH");
if (self::MODE_INIT == $mode) { if (self::MODE_INIT == $mode) {
foreach (array("nginx", "mariadb", "postgresql", "php") as $i) { foreach (array("nginx", "mariadb", "postgresql", "php") as $i) {
$this->importSectionFromDir($i, $this->getTplDir() . DIRECTORY_SEPARATOR . $i); $this->importSectionFromDir($i, $this->getTplDir() . DIRECTORY_SEPARATOR . $i);
@@ -78,7 +68,6 @@ class Config
} }
} }
/** @return bool */
public function isInitialized() public function isInitialized()
{ {
/* XXX Could be some better check. */ /* XXX Could be some better check. */
@@ -173,7 +162,6 @@ class Config
return $ret; return $ret;
} }
/** @param string ...$args */
public function sectionItemExists(...$args) : bool public function sectionItemExists(...$args) : bool
{ {
$i = 0; $i = 0;
@@ -191,10 +179,6 @@ class Config
return $i == count($args); return $i == count($args);
} }
/**
* @param string ...$args
* @return mixed
*/
public function getSectionItem(...$args) public function getSectionItem(...$args)
{ {
$i = 0; $i = 0;
@@ -216,7 +200,6 @@ class Config
return $it; return $it;
} }
/** @param string|int ...$args */
public function setSectionItem(...$args) : void public function setSectionItem(...$args) : void
{ {
$val = array_pop($args); $val = array_pop($args);
@@ -256,7 +239,6 @@ class Config
} }
} }
/** @param string ...$args */
public function buildTplVarName(...$args) : string public function buildTplVarName(...$args) : string
{ {
$tpl_k = array("PHP_SDK_PGO"); $tpl_k = array("PHP_SDK_PGO");
@@ -268,7 +250,6 @@ class Config
return implode("_", $tpl_k); return implode("_", $tpl_k);
} }
/** @param array<string,mixed> $section */
protected function importTplVars(string $section_name, array $section) : void protected function importTplVars(string $section_name, array $section) : void
{ {
foreach($section as $k0 => $v0) { foreach($section as $k0 => $v0) {
@@ -286,7 +267,6 @@ class Config
} }
} }
/** @param array<mixed> $additional_vars */
public function processTpl(string $s, array $additional_vars = array()) : string public function processTpl(string $s, array $additional_vars = array()) : string
{ {
$vars = array_merge($this->tpl_vars, $additional_vars); $vars = array_merge($this->tpl_vars, $additional_vars);
@@ -296,11 +276,10 @@ class Config
return $s; return $s;
} }
/** @param array<mixed> $additional_vars */
public function processTplFile(string $tpl_fn, string $dst_fn, array $additional_vars = array()) : void public function processTplFile(string $tpl_fn, string $dst_fn, array $additional_vars = array()) : void
{ {
if (!file_exists($tpl_fn)) { if (!file_exists($tpl_fn)) {
throw new Exception("Template file '$tpl_fn' doesn't exist."); throw new Exception("Template file '$fn' doesn't exist.");
} }
$s = file_get_contents($tpl_fn); $s = file_get_contents($tpl_fn);
@@ -315,7 +294,6 @@ class Config
} }
} }
/** @return string */
public function getWorkSectionsFilename() public function getWorkSectionsFilename()
{ {
return $this->getWorkDir() . DIRECTORY_SEPARATOR . "phpsdk_pgo.json"; return $this->getWorkDir() . DIRECTORY_SEPARATOR . "phpsdk_pgo.json";
@@ -361,10 +339,6 @@ class Config
return getenv("PHP_SDK_PHP_CMD"); return getenv("PHP_SDK_PHP_CMD");
} }
/**
* @param Interfaces\Server $item
* @return void
*/
public function addSrv($item) : void public function addSrv($item) : void
{ {
$name = strtolower($item->getName()); $name = strtolower($item->getName());
@@ -377,7 +351,6 @@ class Config
$this->srv[$name] = $item; $this->srv[$name] = $item;
} }
/** @return array<string,Interfaces\Server>|Interfaces\Server|null */
public function getSrv(?string $name = NULL) public function getSrv(?string $name = NULL)
{ {
$ret = NULL; $ret = NULL;
@@ -395,3 +368,4 @@ class Config
return $ret; return $ret;
} }
} }
+37 -56
View File
@@ -2,30 +2,23 @@
namespace SDK\Build\PGO; namespace SDK\Build\PGO;
use SDK\{Exception, Lock}; use SDK\{Config as SDKConfig, Exception, Lock};
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\Build\PGO\Server\{MariaDB, NGINX, PostgreSQL}; use SDK\Build\PGO\Server\{MariaDB, NGINX, PostgreSQL};
use SDK\Build\PGO\PHP; use SDK\Build\PGO\PHP;
use SDK\Build\PGO\Tool\{PGO, PackageWorkman}; use SDK\Build\PGO\Tool\{PGO, PackageWorkman};
use SDK\Build\PGO\Interfaces\TrainingCase;
use SDK\Build\PGO\TrainingCaseIterator;
/* TODO add bench action */ /* TODO add bench action */
class Controller class Controller
{ {
/** @var string */
protected $cmd; protected $cmd;
/** @var ?string */
protected $scenario; protected $scenario;
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var array<string>|null */
protected $cases; protected $cases;
/** @param array<string>|null $cases */
public function __construct(string $cmd, ?string $scenario, ?array $cases) public function __construct(string $cmd, ?string $scenario, ?array $cases)
{ {
$this->cmd = $cmd; $this->cmd = $cmd;
@@ -37,7 +30,6 @@ class Controller
$this->cases = $cases; $this->cases = $cases;
} }
/** @return mixed */
protected function vitalizeSrv() protected function vitalizeSrv()
{ {
$all = $this->conf->getSrv("all"); $all = $this->conf->getSrv("all");
@@ -56,15 +48,12 @@ class Controller
return $all; return $all;
} }
/**
* @param string $cmd
* @return PGOConfig
*/
protected function setupConfig($cmd) protected function setupConfig($cmd)
{ {
switch ($cmd) { switch ($cmd) {
default: default:
throw new Exception("Unknown action '{$cmd}'."); throw new Exception("Unknown action '{$cmd}'.");
break;
case "check_init": case "check_init":
$cnf = new PGOConfig(PGOConfig::MODE_CHECK_INIT); $cnf = new PGOConfig(PGOConfig::MODE_CHECK_INIT);
break; break;
@@ -81,10 +70,6 @@ class Controller
return $cnf; return $cnf;
} }
/**
* @param bool $force
* @return void
*/
public function handle($force) public function handle($force)
{ {
/*$mode = (int)("init" !== $this->cmd); /*$mode = (int)("init" !== $this->cmd);
@@ -94,37 +79,38 @@ class Controller
$this->conf = $this->setupConfig($this->cmd); $this->conf = $this->setupConfig($this->cmd);
switch ($this->cmd) { switch ($this->cmd) {
default: default:
throw new Exception("Unknown action '{$this->cmd}'."); throw new Exception("Unknown action '{$this->cmd}'.");
case "init": break;
$lk = new Lock("pgo_init"); case "init":
if (!$lk->locked()) { $lk = new Lock("pgo_init");
echo "Another process runs initialization right now, waiting.", PHP_EOL; if (!$lk->locked()) {
$lk->exclusive(true); echo "Another process runs initialization right now, waiting.", PHP_EOL;
echo "Another process finished running initialization, I quit as well.", PHP_EOL; $lk->exclusive(true);
return; echo "Another process finished running initialization, I quit as well.", PHP_EOL;
} return;
$this->init($force); }
break; $this->init($force);
case "train": break;
$lk = new Lock("pgo_train"); case "train":
if (!$lk->locked()) { $lk = new Lock("pgo_train");
echo "Another process runs training right now, I have to wait.", PHP_EOL; if (!$lk->locked()) {
$lk->exclusive(true); echo "Another process runs training right now, I have to wait.", PHP_EOL;
echo "Another process finished training, I may continue.", PHP_EOL; $lk->exclusive(true);
} echo "Another process finished training, I may continue.", PHP_EOL;
$this->train(); }
break; $this->train();
case "up": break;
$this->up(); case "up":
break; $this->up();
break;
case "down": case "down":
$this->down($force); $this->down($force);
break; break;
case "check_init": case "check_init":
// pass // pass
break; break;
} }
} }
@@ -162,7 +148,6 @@ class Controller
} }
} }
/** @return void */
public function init(bool $force = false) public function init(bool $force = false)
{ {
echo "\nInitializing PGO training environment.\n\n"; echo "\nInitializing PGO training environment.\n\n";
@@ -196,13 +181,11 @@ class Controller
echo "PGO training environment Initialization complete.\n"; echo "PGO training environment Initialization complete.\n";
} }
/** @return bool */
public function isInitialized() public function isInitialized()
{ {
return $this->conf->isinitialized(); return $this->conf->isinitialized();
} }
/** @return void */
public function train() public function train()
{ {
if (!$this->isInitialized()) { if (!$this->isInitialized()) {
@@ -251,7 +234,6 @@ class Controller
echo "PGO training complete.\n"; echo "PGO training complete.\n";
} }
/** @return void */
public function up() public function up()
{ {
@@ -260,7 +242,7 @@ class Controller
} }
echo "\nStarting up PGO environment.\n\n"; echo "\nStarting up PGO environment.\n\n";
foreach ($this->vitalizeSrv() as $srv) { foreach ($this->vitalizeSrv("all") as $srv) {
$srv->up(); $srv->up();
echo "\n"; echo "\n";
} }
@@ -270,7 +252,6 @@ class Controller
echo "The PGO environment is up.\n"; echo "The PGO environment is up.\n";
} }
/** @return void */
public function down(bool $force = false) public function down(bool $force = false)
{ {
if (!$this->isInitialized()) { if (!$this->isInitialized()) {
@@ -279,7 +260,7 @@ class Controller
/* XXX check it was started of course. */ /* XXX check it was started of course. */
echo "\nShutting down PGO environment.\n\n"; echo "\nShutting down PGO environment.\n\n";
foreach ($this->vitalizeSrv() as $srv) { foreach ($this->vitalizeSrv("all") as $srv) {
$srv->down($force); $srv->down($force);
echo "\n"; echo "\n";
} }
@@ -2,6 +2,7 @@
namespace SDK\Build\PGO\Interfaces; namespace SDK\Build\PGO\Interfaces;
use SDK\Build\PGO\Config;
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
interface PHP interface PHP
@@ -14,3 +15,4 @@ interface PHP
public function getVersion(bool $short = false) : string; public function getVersion(bool $short = false) : string;
public function getExeFilename() : string; public function getExeFilename() : string;
} }
@@ -2,6 +2,7 @@
namespace SDK\Build\PGO\Interfaces; namespace SDK\Build\PGO\Interfaces;
use SDK\Build\PGO\Config;
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
interface Server interface Server
@@ -12,7 +13,5 @@ interface Server
public function up() : void; public function up() : void;
public function down(bool $force = false) : void; public function down(bool $force = false) : void;
public function getName() : string; public function getName() : string;
/** @return \SDK\Build\PGO\Interfaces\PHP */
public function getPhp();
} }
@@ -10,3 +10,4 @@ interface DB extends Interfaces\Server
public function __construct(Config $conf); public function __construct(Config $conf);
public function query(string $s, string $db = NULL) : void; public function query(string $s, string $db = NULL) : void;
} }
@@ -9,10 +9,6 @@ interface HTTP extends Interfaces\Server
{ {
public function __construct(Config $conf, Interfaces\PHP $php); public function __construct(Config $conf, Interfaces\PHP $php);
public function getPhp() : Interfaces\PHP; public function getPhp() : Interfaces\PHP;
/**
* @param array<mixed> $tpl_vars
* @return void
*/
public function addServer(string $part_tpl_fn, array $tpl_vars = array()); public function addServer(string $part_tpl_fn, array $tpl_vars = array());
} }
@@ -25,3 +25,4 @@ interface TrainingCase
/* Get training type, it's like "web", "cli", etc.*/ /* Get training type, it's like "web", "cli", etc.*/
public function getType() : string; public function getType() : string;
} }
+6 -5
View File
@@ -5,19 +5,17 @@ namespace SDK\Build\PGO\PHP;
use SDK\Build\PGO\Interfaces; use SDK\Build\PGO\Interfaces;
use SDK\Build\PGO\Abstracts; use SDK\Build\PGO\Abstracts;
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\{Exception}; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
class CLI extends Abstracts\PHP implements Interfaces\PHP class CLI extends Abstracts\PHP implements Interfaces\PHP
{ {
protected $conf;
public function __construct(PGOConfig $conf) public function __construct(PGOConfig $conf)
{ {
$this->conf = $conf; $this->conf = $conf;
$this->scenario = $conf->getScenario(); $this->scenario = $conf->getScenario();
// Don't do that, it'll be a recursive dependency.
// Once we need to train CLI, we'll need to split
// a new class, this one is a utility class.
//$this->id = $this->getIdString();
$this->setupPaths(); $this->setupPaths();
} }
@@ -52,4 +50,7 @@ class CLI extends Abstracts\PHP implements Interfaces\PHP
return $exe; return $exe;
} }
} }
+3 -27
View File
@@ -5,14 +5,12 @@ namespace SDK\Build\PGO\PHP;
use SDK\Build\PGO\Interfaces; use SDK\Build\PGO\Interfaces;
use SDK\Build\PGO\Abstracts; use SDK\Build\PGO\Abstracts;
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\{Exception, FileOps}; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
class FCGI extends Abstracts\PHP implements Interfaces\PHP class FCGI extends Abstracts\PHP implements Interfaces\PHP
{ {
use FileOps; protected $conf;
/** @var bool */
protected $is_tcp; protected $is_tcp;
public function __construct(PGOConfig $conf, bool $is_tcp) public function __construct(PGOConfig $conf, bool $is_tcp)
@@ -24,7 +22,6 @@ class FCGI extends Abstracts\PHP implements Interfaces\PHP
$this->conf = $conf; $this->conf = $conf;
$this->is_tcp = $is_tcp; $this->is_tcp = $is_tcp;
$this->scenario = $conf->getScenario(); $this->scenario = $conf->getScenario();
$this->id = $this->getIdString();
$this->setupPaths(); $this->setupPaths();
} }
@@ -67,15 +64,6 @@ echo "PHP FCGI initialization done.\n";*/
{ {
echo "Starting PHP FCGI.\n"; echo "Starting PHP FCGI.\n";
if ("cache" == $this->scenario) {
if (file_exists($this->opcache_file_cache)) {
$this->rm($this->opcache_file_cache);
}
if (!mkdir($this->opcache_file_cache)) {
throw new Exception("Failed to create '{$this->opcache_file_cache}'");
}
}
$exe = $this->getExeFilename(); $exe = $this->getExeFilename();
$ini = $this->getIniFilename(); $ini = $this->getIniFilename();
$host = $this->conf->getSectionItem("php", "fcgi", "host"); $host = $this->conf->getSectionItem("php", "fcgi", "host");
@@ -94,10 +82,6 @@ echo "PHP FCGI initialization done.\n";*/
/* Give some time, it might be slow on PGI enabled proc. */ /* Give some time, it might be slow on PGI enabled proc. */
sleep(3); sleep(3);
/*while(false !== ($s = fread($pipes[2], 1024))) {
echo "$s";
}*/
$c = proc_close($p); $c = proc_close($p);
if ($c) { if ($c) {
@@ -115,15 +99,7 @@ echo "PHP FCGI initialization done.\n";*/
exec("taskkill /f /im php-cgi.exe >nul 2>&1"); exec("taskkill /f /im php-cgi.exe >nul 2>&1");
/* XXX Add cleanup interface. */
if ("cache" == $this->scenario) {
try {
$this->rm($this->opcache_file_cache);
} catch (\UnexpectedValueException $e) {
echo $e->getMessage(), "\n";
}
}
echo "PHP FCGI stopped.\n"; echo "PHP FCGI stopped.\n";
} }
} }
@@ -5,20 +5,15 @@ namespace SDK\Build\PGO\Server;
use SDK\Build\PGO\Interfaces\Server\DB; use SDK\Build\PGO\Interfaces\Server\DB;
use SDK\Build\PGO\Abstracts\Server; use SDK\Build\PGO\Abstracts\Server;
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\{Exception, FileOps}; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
class MariaDB extends Server implements DB class MariaDB extends Server implements DB
{ {
use FileOps; use FileOps;
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var string */
protected $base; protected $base;
/** @var string */
protected $name = "MariaDB"; protected $name = "MariaDB";
public function __construct(PGOConfig $conf) public function __construct(PGOConfig $conf)
@@ -27,7 +22,6 @@ class MariaDB extends Server implements DB
$this->base = $conf->getSrvDir(strtolower($this->name)); $this->base = $conf->getSrvDir(strtolower($this->name));
} }
/** @return void */
protected function setupDist() protected function setupDist()
{ {
/* pass */ /* pass */
@@ -121,7 +115,7 @@ class MariaDB extends Server implements DB
$pass_arg = $pass ? "-p$pass " : ""; $pass_arg = $pass ? "-p$pass " : "";
$db_arg = $db ? "-D $db" : ""; $db_arg = $db ? "-D $db" : "";
shell_exec(".\\bin\\mysql.exe -u $user $pass_arg -h $host -P $port $db_arg -e \"$s\""); $ret = shell_exec(".\\bin\\mysql.exe -u $user $pass_arg -h $host -P $port $db_arg -e \"$s\"");
//var_dump($this->base, getcwd(), ".\\bin\\mysql.exe -u $user $pass_arg -h $host -P $port -e \"$s\""); //var_dump($this->base, getcwd(), ".\\bin\\mysql.exe -u $user $pass_arg -h $host -P $port -e \"$s\"");
chdir($cwd); chdir($cwd);
@@ -142,8 +136,9 @@ class MariaDB extends Server implements DB
$pass_arg = $pass ? "-p$pass " : ""; $pass_arg = $pass ? "-p$pass " : "";
$db_arg = $db ? "-D $db" : ""; $db_arg = $db ? "-D $db" : "";
shell_exec(".\\bin\\mysql.exe -u $user $pass_arg -h $host -P $port $db_arg < \"$path\""); $ret = shell_exec(".\\bin\\mysql.exe -u $user $pass_arg -h $host -P $port $db_arg < \"$path\"");
chdir($cwd); chdir($cwd);
} }
} }
+4 -13
View File
@@ -5,23 +5,16 @@ namespace SDK\Build\PGO\Server;
use SDK\Build\PGO\Interfaces; use SDK\Build\PGO\Interfaces;
use SDK\Build\PGO\Abstracts; use SDK\Build\PGO\Abstracts;
use SDK\Build\PGO\{Config as PGOConfig}; use SDK\Build\PGO\{Config as PGOConfig};
use SDK\{Exception, FileOps}; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
class NGINX extends Abstracts\Server implements Interfaces\Server\HTTP class NGINX extends Abstracts\Server implements Interfaces\Server\HTTP
{ {
use FileOps; use FileOps;
/** @var string */
protected $name = "NGINX"; protected $name = "NGINX";
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var string */
protected $base; protected $base;
/** @var Interfaces\PHP */
protected $php; protected $php;
public function __construct(PGOConfig $conf, Interfaces\PHP $php) public function __construct(PGOConfig $conf, Interfaces\PHP $php)
@@ -36,6 +29,7 @@ class NGINX extends Abstracts\Server implements Interfaces\Server\HTTP
$nginx_conf_in = $this->conf->getTplDir($this->name) . DIRECTORY_SEPARATOR . "nginx.conf"; $nginx_conf_in = $this->conf->getTplDir($this->name) . DIRECTORY_SEPARATOR . "nginx.conf";
$conf_fn = $this->base . DIRECTORY_SEPARATOR . "conf" . DIRECTORY_SEPARATOR . "nginx.conf"; $conf_fn = $this->base . DIRECTORY_SEPARATOR . "conf" . DIRECTORY_SEPARATOR . "nginx.conf";
$vars = array();
$port = $this->conf->getSectionItem($this->name, "port"); $port = $this->conf->getSectionItem($this->name, "port");
if (!$port) { if (!$port) {
$port = $this->conf->getNextPort(); $port = $this->conf->getNextPort();
@@ -83,7 +77,7 @@ class NGINX extends Abstracts\Server implements Interfaces\Server\HTTP
$h = popen("start /b .\\nginx.exe 2>&1", "r"); $h = popen("start /b .\\nginx.exe 2>&1", "r");
if (!is_resource($h)) { if (!is_resource($h)) {
chdir($cwd); chdir($cwd);
throw new Exception("Failed to start NGINX."); throw new Exception("Failed to start MariaDB.");
} }
sleep(3); sleep(3);
@@ -132,10 +126,6 @@ class NGINX extends Abstracts\Server implements Interfaces\Server\HTTP
} }
/* Use only for init phase! */ /* Use only for init phase! */
/**
* @param array<mixed> $tpl_vars
* @return void
*/
public function addServer(string $part_tpl_fn, array $tpl_vars = array()) public function addServer(string $part_tpl_fn, array $tpl_vars = array())
{ {
if (!file_exists($part_tpl_fn)) { if (!file_exists($part_tpl_fn)) {
@@ -158,3 +148,4 @@ class NGINX extends Abstracts\Server implements Interfaces\Server\HTTP
} }
} }
} }
@@ -5,23 +5,16 @@ namespace SDK\Build\PGO\Server;
use SDK\Build\PGO\Interfaces\Server\DB; use SDK\Build\PGO\Interfaces\Server\DB;
use SDK\Build\PGO\Abstracts\Server; use SDK\Build\PGO\Abstracts\Server;
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\{Exception, FileOps}; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Tool\PackageWorkman; use SDK\Build\PGO\Tool\PackageWorkman;
class PostgreSQL extends Server implements DB class PostgreSQL extends Server implements DB
{ {
use FileOps; use FileOps;
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var string */
protected $base; protected $base;
/** @var string */
protected $data_dir; protected $data_dir;
/** @var string */
protected $name = "PostgreSQL"; protected $name = "PostgreSQL";
public function __construct(PGOConfig $conf) public function __construct(PGOConfig $conf)
@@ -31,7 +24,6 @@ class PostgreSQL extends Server implements DB
$this->data_dir = $this->base . DIRECTORY_SEPARATOR . "data"; $this->data_dir = $this->base . DIRECTORY_SEPARATOR . "data";
} }
/** @return void */
protected function setupDist() protected function setupDist()
{ {
$user = $this->conf->getSectionItem($this->name, "user"); $user = $this->conf->getSectionItem($this->name, "user");
@@ -98,6 +90,10 @@ class PostgreSQL extends Server implements DB
echo "Stopping " . $this->name . ".\n"; echo "Stopping " . $this->name . ".\n";
$user = $this->conf->getSectionItem($this->name, "user");
$pass = $this->conf->getSectionItem($this->name, "pass");
$cmd = $this->base . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "pg_ctl.exe stop -D " . $this->data_dir . " -m fast"; $cmd = $this->base . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "pg_ctl.exe stop -D " . $this->data_dir . " -m fast";
exec($cmd); exec($cmd);
@@ -112,6 +108,7 @@ class PostgreSQL extends Server implements DB
public function createDb(string $db_name) : void public function createDb(string $db_name) : void
{ {
$user = $this->conf->getSectionItem($this->name, "user"); $user = $this->conf->getSectionItem($this->name, "user");
$pass = $this->conf->getSectionItem($this->name, "pass");
$host = $this->conf->getSectionItem($this->name, "host"); $host = $this->conf->getSectionItem($this->name, "host");
$port = $this->conf->getSectionItem($this->name, "port"); $port = $this->conf->getSectionItem($this->name, "port");
@@ -122,6 +119,7 @@ class PostgreSQL extends Server implements DB
public function dropDb(string $db_name) : void public function dropDb(string $db_name) : void
{ {
$user = $this->conf->getSectionItem($this->name, "user"); $user = $this->conf->getSectionItem($this->name, "user");
//$pass = $this->conf->getSectionItem($this->name, "pass");
$host = $this->conf->getSectionItem($this->name, "host"); $host = $this->conf->getSectionItem($this->name, "host");
$port = $this->conf->getSectionItem($this->name, "port"); $port = $this->conf->getSectionItem($this->name, "port");
@@ -134,11 +132,13 @@ class PostgreSQL extends Server implements DB
$ret = NULL; $ret = NULL;
$user = $this->conf->getSectionItem($this->name, "user"); $user = $this->conf->getSectionItem($this->name, "user");
//$pass = $this->conf->getSectionItem($this->name, "pass");
$host = $this->conf->getSectionItem($this->name, "host"); $host = $this->conf->getSectionItem($this->name, "host");
$port = $this->conf->getSectionItem($this->name, "port"); $port = $this->conf->getSectionItem($this->name, "port");
$db_arg = $db ? "-d $db" : ""; $db_arg = $db ? "-d $db" : "";
$cmd = $this->base . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "psql.exe -h $host -p $port -U $user $db_arg -c \"$s\""; $cmd = $this->base . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "psql.exe -h $host -p $port -U $user $db_arg -c \"$s\"";
shell_exec($cmd); $ret = shell_exec($cmd);
} }
} }
+6 -11
View File
@@ -2,19 +2,14 @@
namespace SDK\Build\PGO\Tool; namespace SDK\Build\PGO\Tool;
use SDK\Exception; use SDK\{Config as SDKConfig, Exception};
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\Build\PGO\Interfaces; use SDK\Build\PGO\Interfaces;
class PGO class PGO
{ {
/** @var Interfaces\PHP */
protected $php; protected $php;
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var int */
protected $idx = 0; protected $idx = 0;
public function __construct(PGOConfig $conf, Interfaces\PHP $php) public function __construct(PGOConfig $conf, Interfaces\PHP $php)
@@ -39,7 +34,6 @@ class PGO
return $dn . DIRECTORY_SEPARATOR . $bn . ".pgd"; return $dn . DIRECTORY_SEPARATOR . $bn . ".pgd";
} }
/** @return array<string> */
protected function getWorkItems() : array protected function getWorkItems() : array
{ {
$exe = glob($this->php->getRootDir() . DIRECTORY_SEPARATOR . "*.exe"); $exe = glob($this->php->getRootDir() . DIRECTORY_SEPARATOR . "*.exe");
@@ -47,7 +41,7 @@ class PGO
$dll = array_merge($dll, glob($this->php->getExtRootDir() . DIRECTORY_SEPARATOR . "php*.dll")); $dll = array_merge($dll, glob($this->php->getExtRootDir() . DIRECTORY_SEPARATOR . "php*.dll"));
/* find out next index */ /* find out next index */
$tpl = glob($this->php->getRootDir() . DIRECTORY_SEPARATOR . "php{7,8,}{ts,}.dll", GLOB_BRACE)[0]; $tpl = glob($this->php->getRootDir() . DIRECTORY_SEPARATOR . "php7{ts,}.dll", GLOB_BRACE)[0];
if (!$tpl) { if (!$tpl) {
throw new Exception("Couldn't find php7[ts].dll in the PHP root dir."); throw new Exception("Couldn't find php7[ts].dll in the PHP root dir.");
} }
@@ -69,11 +63,11 @@ class PGO
$pgc = $this->getPgcName($base); $pgc = $this->getPgcName($base);
$pgd = $this->getPgdName($base); $pgd = $this->getPgdName($base);
shell_exec("pgosweep $base $pgc"); `pgosweep $base $pgc`;
//passthru("pgosweep $base $pgc"); //passthru("pgosweep $base $pgc");
if ($merge) { if ($merge) {
shell_exec("pgomgr /merge:1000 $pgc $pgd"); `pgomgr /merge:1000 $pgc $pgd`;
//passthru("pgomgr /merge:1000 $pgc $pgd"); //passthru("pgomgr /merge:1000 $pgc $pgd");
/* File is already spent, no need to keep it. /* File is already spent, no need to keep it.
If seeing linker warnings about no pgc If seeing linker warnings about no pgc
@@ -104,9 +98,10 @@ class PGO
$its = glob($this->php->getRootDir() . DIRECTORY_SEPARATOR . "*.pgd"); $its = glob($this->php->getRootDir() . DIRECTORY_SEPARATOR . "*.pgd");
$its = array_merge($its, glob($this->php->getExtRootDir() . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . "*.pgd")); $its = array_merge($its, glob($this->php->getExtRootDir() . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . "*.pgd"));
foreach (array_unique($its) as $pgd) { foreach (array_unique($its) as $pgd) {
shell_exec("pgomgr /clear $pgd"); `pgomgr /clear $pgd`;
//passthru("pgomgr /clear $pgd"); //passthru("pgomgr /clear $pgd");
} }
} }
} }
} }
@@ -2,7 +2,7 @@
namespace SDK\Build\PGO\Tool; namespace SDK\Build\PGO\Tool;
use SDK\{Exception, FileOps}; use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
@@ -10,7 +10,6 @@ class PackageWorkman
{ {
use FileOps; use FileOps;
/** @var PGOConfig */
protected $conf; protected $conf;
public function __construct(PGOConfig $conf) public function __construct(PGOConfig $conf)
@@ -48,10 +47,11 @@ class PackageWorkman
echo "Unpacking '$cache_fn' to '$tgt_name'\n"; echo "Unpacking '$cache_fn' to '$tgt_name'\n";
try { try {
$this->unzip($cache_fn, $zip_tgt_dn, $tgt_bn); $this->unzip($cache_fn, $zip_tgt_dn, $tgt_bn);
} catch (\Throwable $e) { } catch (Throwable $e) {
$this->rm($cache_fn); $this->rm($cache_fn);
throw $e; throw $e;
} }
} }
} }
} }
+5 -10
View File
@@ -4,23 +4,19 @@ namespace SDK\Build\PGO\Tool;
use SDK\{Config as SDKConfig, Exception}; use SDK\{Config as SDKConfig, Exception};
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
use SDK\Build\PGO\Interfaces\TrainingCase; use SDK\Build\PGO\Interfaces\{TrainingCase, Server, Server\DB, PHP};
class Training class Training
{ {
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var TrainingCase */
protected $t_case; protected $t_case;
public function __construct(PGOConfig $conf, TrainingCase $t_case) public function __construct(PGOConfig $conf, TrainingCase $t_case)
{ {
$this->conf = $conf; $this->conf = $conf;
$this->t_case = $t_case; $this->t_case = $t_case;
$type = $this->t_case->getType(); if (!in_array($this->t_case->getType(), array("web", "cli"))) {
if (!in_array($type, array("web", "cli"))) {
throw new Exception("Unknown training type '$type'."); throw new Exception("Unknown training type '$type'.");
} }
} }
@@ -30,7 +26,6 @@ class Training
return $this->t_case; return $this->t_case;
} }
/** @param array<string,mixed> $stat */
public function runWeb(int $max_runs, ?array &$stat = array()) : void public function runWeb(int $max_runs, ?array &$stat = array()) : void
{ {
$url_list_fn = $this->t_case->getJobFilename(); $url_list_fn = $this->t_case->getJobFilename();
@@ -109,11 +104,11 @@ class Training
} }
/* TODO Extend with number runs. */ /* TODO Extend with number runs. */
/** @param array<string,mixed> $stat */
public function run(int $max_runs = 1, ?array &$stat = array()) : void public function run(int $max_runs = 1, ?array &$stat = array()) : void
{ {
$type = $this->t_case->getType(); $type = $this->t_case->getType();
switch ($type) { switch ($type)
{
case "web": case "web":
$this->runWeb($max_runs, $stat); $this->runWeb($max_runs, $stat);
break; break;
@@ -2,23 +2,15 @@
namespace SDK\Build\PGO; namespace SDK\Build\PGO;
use SDK\{Config as SDKConfig, Exception, FileOps};
use SDK\Build\PGO\Config as PGOConfig; use SDK\Build\PGO\Config as PGOConfig;
/**
* @implements \Iterator<?string,Interfaces\TrainingCase>
*/
class TrainingCaseIterator implements \Iterator class TrainingCaseIterator implements \Iterator
{ {
/** @var PGOConfig */
protected $conf; protected $conf;
/** @var array<string> */
protected $items = array(); protected $items = array();
/** @var int */
protected $idx; protected $idx;
/** @var object */
protected $el; protected $el;
public function __construct(PGOConfig $conf) public function __construct(PGOConfig $conf)
@@ -29,7 +21,7 @@ class TrainingCaseIterator implements \Iterator
$items = glob($this->conf->getCasesTplDir() . DIRECTORY_SEPARATOR . "*"); $items = glob($this->conf->getCasesTplDir() . DIRECTORY_SEPARATOR . "*");
foreach ($items as $it) { foreach ($items as $it) {
if (!is_dir($it)) { if(!is_dir($it)) {
continue; continue;
} }
@@ -59,10 +51,9 @@ class TrainingCaseIterator implements \Iterator
return $base . DIRECTORY_SEPARATOR . "TrainingCaseHandler.php"; return $base . DIRECTORY_SEPARATOR . "TrainingCaseHandler.php";
} }
#[\ReturnTypeWillChange]
public function current() public function current()
{ {
$base = $this->items[$this->idx]; $base = $this->items[$this->idx];
$ns = basename($base); $ns = basename($base);
/* Don't overwrite generated config. */ /* Don't overwrite generated config. */
@@ -83,25 +74,21 @@ class TrainingCaseIterator implements \Iterator
return $this->el; return $this->el;
} }
#[\ReturnTypeWillChange]
public function next() public function next()
{ {
$this->idx++; $this->idx++;
} }
#[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
$this->idx = 0; $this->idx = 0;
} }
#[\ReturnTypeWillChange]
public function valid() public function valid()
{ {
return $this->idx < count($this->items); return $this->idx < count($this->items);
} }
#[\ReturnTypeWillChange]
public function key() public function key()
{ {
if (!is_object($this->el)) { if (!is_object($this->el)) {
@@ -110,4 +97,6 @@ class TrainingCaseIterator implements \Iterator
return $this->el->getName(); return $this->el->getName();
} }
} }
+7 -6
View File
@@ -2,12 +2,13 @@
namespace SDK; namespace SDK;
use SDK\Config;
use SDK\Cache;
use SDK\Exception;
class Cache class Cache
{ {
/** @var string */
protected $id; protected $id;
/** @var string */
protected $hash; protected $hash;
public function __construct(string $id) public function __construct(string $id)
@@ -47,7 +48,7 @@ class Cache
$old_sum = md5_file($p); $old_sum = md5_file($p);
$new_sum = md5($content); $new_sum = md5($content);
return $old_sum !== $new_sum; return $old_sum != $new_sum;
}/*}}}*/ }/*}}}*/
public function cacheContent(string $path, string $content, bool $relative = false) : void public function cacheContent(string $path, string $content, bool $relative = false) : void
@@ -63,7 +64,7 @@ class Cache
do { do {
$got = fwrite($fd, substr($content, $wrote)); $got = fwrite($fd, substr($content, $wrote));
if (false === $got) { if (false == $got) {
break; break;
} }
$wrote += $got; $wrote += $got;
@@ -82,7 +83,7 @@ class Cache
{/*{{{*/ {/*{{{*/
$p = $this->getCacheablePath($path, $relative); $p = $this->getCacheablePath($path, $relative);
if (file_exists($p)) { if ($this->isFileCached($p)) {
return file_get_contents($p); return file_get_contents($p);
} }
+37 -89
View File
@@ -3,44 +3,26 @@
namespace SDK; namespace SDK;
use SDK\Build\Dependency\Fetcher; use SDK\Build\Dependency\Fetcher;
use SDK\Cache;
use SDK\Exception;
class Config class Config
{ {
/* Config variables. */ /* Config variables. */
protected static $depsHost = 'windows.php.net';
/** @var string */
protected static $depsHost = 'downloads.php.net';
/** @var int */
protected static $depsPort = 443; protected static $depsPort = 443;
/** @var string */
protected static $depsUriScheme = "https"; protected static $depsUriScheme = "https";
protected static $depsBaseUri = "/downloads/php-sdk/deps";
/** @var string */ /* protected static $sdkNugetFeedUrl = "http://127.0.0.1/sdk/nuget"; */
protected static $depsBaseUri = "/~windows/php-sdk/deps";
/** @var string */
protected static $sdkNugetFeedUrl = "http://127.0.0.1/sdk/nuget"; // experimental?
/** @var array<mixed> */
protected static $knownBranches = array (); protected static $knownBranches = array ();
/* Helper props and methods. */ /* Helper props and methods. */
/** @var ?string */
protected static $currentBranchName = NULL; protected static $currentBranchName = NULL;
/** @var ?string */
protected static $currentArchName = NULL; protected static $currentArchName = NULL;
/** @var ?string */
protected static $currentCrtName = NULL; protected static $currentCrtName = NULL;
/** @var ?string */
protected static $currentStabilityName = NULL; protected static $currentStabilityName = NULL;
/** @var ?string */
protected static $depsLocalPath = NULL; protected static $depsLocalPath = NULL;
public static function getDepsHost() : string public static function getDepsHost() : string
@@ -48,7 +30,7 @@ class Config
return self::$depsHost; return self::$depsHost;
}/*}}}*/ }/*}}}*/
public static function getDepsPort() : int public static function getDepsPort() : string
{/*{{{*/ {/*{{{*/
return self::$depsPort; return self::$depsPort;
}/*}}}*/ }/*}}}*/
@@ -67,8 +49,8 @@ class Config
{/*{{{*/ {/*{{{*/
$arch = strtolower($arch); $arch = strtolower($arch);
if ("x64" != $arch && "x86" != $arch && "arm64" != $arch) { if ("x64" != $arch && "x86" != $arch) {
throw new Exception("Unknown arch keyword, x86 or x64 or arm64 is accepted"); throw new Exception("Unknown arch keyword, either x86 or x64 is accepted");
} }
self::$currentArchName = $arch; self::$currentArchName = $arch;
@@ -77,26 +59,20 @@ class Config
public static function getCurrentArchName() : string public static function getCurrentArchName() : string
{/*{{{*/ {/*{{{*/
if (NULL === self::$currentArchName) { if (NULL === self::$currentArchName) {
if (FALSE !== ($env = getenv('PHP_SDK_ARCH'))) { /* XXX this might be not true for other compilers! */
self::setCurrentArchName($env); passthru("where cl.exe >nul", $status);
if ($status) {
throw new Exception("Couldn't execute cl.exe.");
}
exec("cl.exe /? 2>&1", $out);
if (preg_match(",x64,", $out[0])) {
self::setCurrentArchName("x64");
} elseif (preg_match(",x86,", $out[0])) {
self::setCurrentArchName("x86");
} else { } else {
/* XXX this might be not true for other compilers! */ throw new Exception("Couldn't determine Arch.");
passthru("where cl.exe >nul", $status);
if ($status) {
throw new Exception("Couldn't execute cl.exe.");
}
exec("cl.exe /? 2>&1", $out);
if (preg_match(",x64,", $out[0])) {
self::setCurrentArchName("x64");
} elseif (preg_match(",x86,", $out[0])) {
self::setCurrentArchName("x86");
} elseif (preg_match(",arm64,", $out[0])) {
self::setCurrentArchName("arm64");
} else {
throw new Exception("Couldn't determine Arch.");
}
} }
} }
@@ -111,22 +87,18 @@ class Config
public static function getCurrentCrtName() : ?string public static function getCurrentCrtName() : ?string
{/*{{{*/ {/*{{{*/
if (NULL === self::$currentCrtName) { if (NULL === self::$currentCrtName) {
if (FALSE !== ($env = getenv('PHP_SDK_VS'))) { $all_branches = Config::getKnownBranches();
self::setCurrentCrtName($env);
} else {
$all_branches = Config::getKnownBranches();
if (!isset($all_branches[Config::getCurrentBranchName()])) { if (!isset($all_branches[Config::getCurrentBranchName()])) {
throw new Exception("Couldn't find any configuration for branch '" . Config::getCurrentBranchName() . "'"); throw new Exception("Couldn't find any configuration for branch '" . Config::getCurrentBranchName() . "'");
}
$branch = $all_branches[Config::getCurrentBranchName()];
if (count($branch) > 1) {
throw new Exception("Multiple CRTs are available for this branch, please choose one from " . implode(",", array_keys($branch)));
}
self::setCurrentCrtName(array_keys($branch)[0]);
} }
$branch = $all_branches[Config::getCurrentBranchName()];
if (count($branch) > 1) {
throw new Exception("Multiple CRTs are available for this branch, please choose one from " . implode(",", array_keys($branch)));
}
self::setCurrentCrtName(array_keys($branch)[0]);
} }
return self::$currentCrtName; return self::$currentCrtName;
@@ -154,7 +126,6 @@ class Config
return self::$currentStabilityName; return self::$currentStabilityName;
} /*}}}*/ } /*}}}*/
/** @return array<mixed> */
public static function getKnownBranches() : array public static function getKnownBranches() : array
{/*{{{*/ {/*{{{*/
if (empty(self::$knownBranches)) { if (empty(self::$knownBranches)) {
@@ -167,9 +138,9 @@ class Config
$fetcher = new Fetcher(self::$depsHost, self::$depsPort, self::$depsUriScheme); $fetcher = new Fetcher(self::$depsHost, self::$depsPort, self::$depsUriScheme);
$tmp = $fetcher->getByUri(self::$depsBaseUri . "/series/"); $tmp = $fetcher->getByUri(self::$depsBaseUri . "/series/");
if ("" !== $tmp) { if (false !== $tmp) {
$data = array(); $data = array();
if (preg_match_all(",packages-(.+)-(v[cs]\d+)-(x86|x64|arm64)-(stable|staging)\.txt,Us", $tmp, $m, PREG_SET_ORDER)) { if (preg_match_all(",/packages-(.+)-(vc\d+)-(x86|x64)-(stable|staging)\.txt,U", $tmp, $m, PREG_SET_ORDER)) {
foreach ($m as $b) { foreach ($m as $b) {
if (!isset($data[$b[1]])) { if (!isset($data[$b[1]])) {
$data[$b[1]] = array(); $data[$b[1]] = array();
@@ -212,11 +183,6 @@ class Config
$branch = NULL; $branch = NULL;
$found = false; $found = false;
$rmtools_branch = getenv("PHP_RMTOOLS_PHP_BUILD_BRANCH");
if ("master" == $rmtools_branch) {
return "master";
}
/* Try to figure out the branch. The worky scenarios are /* Try to figure out the branch. The worky scenarios are
- CWD is in php-src - CWD is in php-src
- phpize is on the path - phpize is on the path
@@ -247,19 +213,6 @@ class Config
if (is_numeric($major) && is_numeric($minor)) { if (is_numeric($major) && is_numeric($minor)) {
$branch = "$major.$minor"; $branch = "$major.$minor";
} }
/* Verify that we use an available branch name. Master has some
version, but no dedicated series. For master, it rather
makes sense to use master as branch name. */
$git = trim(shell_exec("where git.exe"));
if ($git && is_dir(".git")) {
$cmd = "\"$git\" branch";
$ret = trim(shell_exec($cmd));
if (preg_match_all(",\*\s+master,", $ret) > 0) {
$branch = "master";
}
}
} }
return $branch; return $branch;
@@ -275,7 +228,6 @@ class Config
return self::$currentBranchName; return self::$currentBranchName;
}/*}}}*/ }/*}}}*/
/** @return array<mixed> */
public static function getCurrentBranchData() : array public static function getCurrentBranchData() : array
{/*{{{*/ {/*{{{*/
$ret = array(); $ret = array();
@@ -286,7 +238,6 @@ class Config
throw new Exception("Unknown branch '$current_branch_name'"); throw new Exception("Unknown branch '$current_branch_name'");
} }
$crt = null;
$cur_crt = Config::getCurrentCrtName(); $cur_crt = Config::getCurrentCrtName();
if (count($branches[$current_branch_name]) > 1) { if (count($branches[$current_branch_name]) > 1) {
if (NULL === $cur_crt) { if (NULL === $cur_crt) {
@@ -301,7 +252,7 @@ class Config
} }
} }
if (!$cur_crt_usable) { if (!$cur_crt_usable) {
throw new Exception("The passed CRT '$cur_crt' doesn't match any available for branch '$current_branch_name'"); throw new Exception("The passed CRT '$cur_crt' doesn't match any availbale for branch '$current_branch_name'");
} }
$data = $branches[$current_branch_name][$cur_crt]; $data = $branches[$current_branch_name][$cur_crt];
} else { } else {
@@ -309,7 +260,7 @@ class Config
$crt = key($branches[$current_branch_name]); $crt = key($branches[$current_branch_name]);
$data = $branches[$current_branch_name][$crt]; $data = $branches[$current_branch_name][$crt];
if ($crt != $cur_crt) { if ($crt != $cur_crt) {
throw new Exception("The passed CRT '$cur_crt' doesn't match any available for branch '$current_branch_name'"); throw new Exception("The passed CRT '$cur_crt' doesn't match any availbale for branch '$current_branch_name'");
} }
} }
@@ -326,13 +277,10 @@ class Config
} }
} }
if (!isset($ret["arch"]) || !$ret["arch"]) { if (!$ret["stability"]) {
throw new Exception("Failed to find config with arch '" . self::getCurrentArchName() . "'");
}
if (!isset($ret["stability"]) || !$ret["stability"]) {
throw new Exception("Failed to find config with stability '" . self::getCurrentStabilityName() . "'"); throw new Exception("Failed to find config with stability '" . self::getCurrentStabilityName() . "'");
} }
if (!isset($ret["crt"]) || !$ret["crt"]) { if (!$ret["crt"]) {
throw new Exception("Failed to find config with arch '" . self::getCurrentArchName() . "'"); throw new Exception("Failed to find config with arch '" . self::getCurrentArchName() . "'");
} }
+4 -11
View File
@@ -2,6 +2,9 @@
namespace SDK; namespace SDK;
use SDK\Config;
use SDK\Exception;
trait FileOps trait FileOps
{ {
protected function md(string $name = "", bool $tmp = false) : string protected function md(string $name = "", bool $tmp = false) : string
@@ -90,7 +93,6 @@ trait FileOps
if ($item->isFile()) { if ($item->isFile()) {
if (!call_user_func($cb, $src_path, $dst_path)) { if (!call_user_func($cb, $src_path, $dst_path)) {
assert(is_string($cb));
throw new Exception("Unable to $cb '$src_path' to '$dst_path'"); throw new Exception("Unable to $cb '$src_path' to '$dst_path'");
} }
} }
@@ -117,9 +119,6 @@ trait FileOps
protected function download(string $url, string $dest_fn = NULL) : ?string protected function download(string $url, string $dest_fn = NULL) : ?string
{/*{{{*/ {/*{{{*/
$fd = NULL; $fd = NULL;
$retry = 0;
retry:
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
@@ -138,9 +137,6 @@ retry:
curl_setopt($ch, CURLOPT_USERAGENT, Config::getSdkUserAgentName()); curl_setopt($ch, CURLOPT_USERAGENT, Config::getSdkUserAgentName());
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
// workaround for <https://github.com/microsoft/php-sdk-binary-tools/issues/69>
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$ret = curl_exec($ch); $ret = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@@ -150,9 +146,6 @@ retry:
if ($dest_fn) { if ($dest_fn) {
fclose($fd); fclose($fd);
} }
if ($retry++ < 3) {
goto retry;
}
throw new Exception($err); throw new Exception($err);
} }
@@ -200,7 +193,7 @@ retry:
$name = substr($name, 0, -1);*/ $name = substr($name, 0, -1);*/
$name = rtrim($stat["name"], "/"); $name = rtrim($stat["name"], "/");
while (strstr($name, '/') !== false) { while (strchr($name, '/') !== false) {
$name = dirname($name); $name = dirname($name);
} }
+2 -12
View File
@@ -2,21 +2,14 @@
namespace SDK; namespace SDK;
use SDK\{Config, Exception};
class Lock class Lock
{ {
/** @var ?resource */
protected $fd; protected $fd;
/** @var string */
protected $fn; protected $fn;
/** @var bool */
protected $locked = false; protected $locked = false;
/** @var bool|int */
protected $wouldBlock = false; protected $wouldBlock = false;
/** @var bool|int */
protected $shared = false; protected $shared = false;
public function __construct(string $tag, bool $auto = true, bool $autoShared = false) public function __construct(string $tag, bool $auto = true, bool $autoShared = false)
@@ -75,9 +68,6 @@ class Lock
} else { } else {
$this->fd = fopen($this->fn, "wb"); $this->fd = fopen($this->fn, "wb");
} }
if (false === $this->fd) {
throw new Exception("Failed to open lock under '$this->fn'");
}
$this->locked = flock($this->fd, $flags, $this->wouldBlock); $this->locked = flock($this->fd, $flags, $this->wouldBlock);
return $this->locked; return $this->locked;
}/*}}}*/ }/*}}}*/
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Executable → Regular
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More