diff --git a/src/StaticPHP/Util/System/WindowsUtil.php b/src/StaticPHP/Util/System/WindowsUtil.php index a6df4156..9ed7a7b5 100644 --- a/src/StaticPHP/Util/System/WindowsUtil.php +++ b/src/StaticPHP/Util/System/WindowsUtil.php @@ -8,8 +8,10 @@ use StaticPHP\Util\FileSystem; class WindowsUtil { + private static array|false|null $vsCache = null; + /** - * Find windows program using executable name. + * Find Windows program using executable name. * * @param string $name command name (xxx.exe) * @param array $paths search path (default use env path) @@ -39,6 +41,10 @@ class WindowsUtil */ public static function findVisualStudio(): array|false { + if (self::$vsCache !== null) { + return self::$vsCache; + } + // call vswhere (need VS and C++ tools installed), output is json $vswhere_exec = PKG_ROOT_PATH . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'vswhere.exe'; $args = [ @@ -49,13 +55,13 @@ class WindowsUtil $cmd = escapeshellarg($vswhere_exec) . ' ' . implode(' ', $args); $result = f_exec($cmd, $out, $code); if ($code !== 0 || !$result) { - return false; + return self::$vsCache = false; } $json = json_decode(implode("\n", $out), true); if (!is_array($json) || count($json) === 0) { - return false; + return self::$vsCache = false; } - return [ + return self::$vsCache = [ 'version' => $json[0]['installationVersion'], 'major_version' => explode('.', $json[0]['installationVersion'])[0], 'dir' => $json[0]['installationPath'], @@ -89,6 +95,7 @@ class WindowsUtil $ldflags = '/nodefaultlib:msvcrt /nodefaultlib:msvcrtd /defaultlib:libcmt'; } $buildroot = str_replace('\\', '\\\\', BUILD_ROOT_PATH); + $source = str_replace('\\', '/', SOURCE_PATH); $toolchain = <<