Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit b8bf87b

Browse files
committed
Get info from Config, which may get info from environment
There is no need to implement the detection logic in the PHP class; instead we can get it from the Config object, where we try to get the respective information from the environment, if not already set.
1 parent 70ed1c2 commit b8bf87b

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

lib/php/libsdk/SDK/Build/PGO/Abstracts/PHP.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,6 @@ public function isThreadSafe() : bool
130130
return true;
131131
}
132132

133-
public function is64bit() : bool
134-
{
135-
$cli = new CLI($this->conf, $this->scenario);
136-
137-
$out = shell_exec($cli->getExeFilename() . " -n -v");
138-
139-
if (preg_match(",x64,", $out, $m) > 0) {
140-
return true;
141-
}
142-
143-
return false;
144-
}
145-
146133
/* Need to cleanup it somewhere. */
147134
public function getIniFilename()
148135
{
@@ -153,7 +140,7 @@ public function getIniFilename()
153140
$this->conf->buildTplVarName("php", "error_log") => $this->getRootDir() . DIRECTORY_SEPARATOR . "pgo_run_error.log",
154141
);
155142

156-
$k = $this->is64bit() ? "x64" : "x86";
143+
$k = SDKConfig::getCurrentArchName();
157144
$scenario_vars = (array)$this->conf->getSectionItem("php", "scenario", $this->scenario, "ini", $k);
158145
if ($scenario_vars) {
159146
foreach ($scenario_vars as $k => $v) {
@@ -238,9 +225,9 @@ public function exec(string $php_cmd, string $args = NULL, array $extra_env = ar
238225
public function getIdString(): string
239226
{
240227
return $this->getVersion() . "-"
241-
. getenv('PHP_SDK_VS') . "-"
228+
. SDKConfig::getCurrentCrtName() . "-"
242229
. ($this->isThreadSafe() ? "ts" : "nts") . "-"
243-
. ($this->is64bit() ? "x64" : "x86")
230+
. SDKConfig::getCurrentArchName()
244231
. "-" . substr(md5(uniqid()), 0, 8);
245232
}
246233
}

lib/php/libsdk/SDK/Config.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,24 @@ public static function setCurrentArchName(string $arch) : void
5757
public static function getCurrentArchName() : string
5858
{/*{{{*/
5959
if (NULL === self::$currentArchName) {
60-
/* XXX this might be not true for other compilers! */
61-
passthru("where cl.exe >nul", $status);
62-
if ($status) {
63-
throw new Exception("Couldn't execute cl.exe.");
64-
}
60+
if (FALSE !== ($env = getenv('PHP_SDK_ARCH'))) {
61+
self::setCurrentArchName($env);
62+
} else {
63+
/* XXX this might be not true for other compilers! */
64+
passthru("where cl.exe >nul", $status);
65+
if ($status) {
66+
throw new Exception("Couldn't execute cl.exe.");
67+
}
6568

66-
exec("cl.exe /? 2>&1", $out);
69+
exec("cl.exe /? 2>&1", $out);
6770

68-
if (preg_match(",x64,", $out[0])) {
69-
self::setCurrentArchName("x64");
70-
} elseif (preg_match(",x86,", $out[0])) {
71-
self::setCurrentArchName("x86");
72-
} else {
73-
throw new Exception("Couldn't determine Arch.");
71+
if (preg_match(",x64,", $out[0])) {
72+
self::setCurrentArchName("x64");
73+
} elseif (preg_match(",x86,", $out[0])) {
74+
self::setCurrentArchName("x86");
75+
} else {
76+
throw new Exception("Couldn't determine Arch.");
77+
}
7478
}
7579
}
7680

@@ -85,18 +89,22 @@ public static function setCurrentCrtName(string $crt) : void
8589
public static function getCurrentCrtName() : ?string
8690
{/*{{{*/
8791
if (NULL === self::$currentCrtName) {
88-
$all_branches = Config::getKnownBranches();
92+
if (FALSE !== ($env = getenv('PHP_SDK_VS'))) {
93+
self::setCurrentCrtName($env);
94+
} else {
95+
$all_branches = Config::getKnownBranches();
8996

90-
if (!isset($all_branches[Config::getCurrentBranchName()])) {
91-
throw new Exception("Couldn't find any configuration for branch '" . Config::getCurrentBranchName() . "'");
92-
}
97+
if (!isset($all_branches[Config::getCurrentBranchName()])) {
98+
throw new Exception("Couldn't find any configuration for branch '" . Config::getCurrentBranchName() . "'");
99+
}
93100

94-
$branch = $all_branches[Config::getCurrentBranchName()];
95-
if (count($branch) > 1) {
96-
throw new Exception("Multiple CRTs are available for this branch, please choose one from " . implode(",", array_keys($branch)));
97-
}
101+
$branch = $all_branches[Config::getCurrentBranchName()];
102+
if (count($branch) > 1) {
103+
throw new Exception("Multiple CRTs are available for this branch, please choose one from " . implode(",", array_keys($branch)));
104+
}
98105

99-
self::setCurrentCrtName(array_keys($branch)[0]);
106+
self::setCurrentCrtName(array_keys($branch)[0]);
107+
}
100108
}
101109

102110
return self::$currentCrtName;

0 commit comments

Comments
 (0)