8 * @param string $path package root
11 public function findPackageInfo($path) {
13 if (!strlen($name = $this->findPackageName($path, $header))) {
16 if (!$release = $this->findPackageReleaseVersion($path, $header, $name)) {
19 } catch (Exception
$e) {
23 return compact("name", "release");
26 private function findPackageName($path, &$header = null) {
27 $grep_res = (new ExecCmd("grep"))->run(
29 ["-HEo", "phpext_[^ ]+_ptr"],
30 explode("\n", (new ExecCmd("find"))->run([
31 $path, "-type", "f", "-name", "php_*.h"
35 if (!list($header, $phpext_ptr) = explode(":", $grep_res)) {
38 if (!$name = substr($phpext_ptr, 7, -4)) {
45 private function findPackageReleaseVersion($path, $header, $name) {
46 $uc_name = strtoupper($name);
47 $cpp_tmp = new Tempfile("cpp");
48 $cpp_hnd = $cpp_tmp->getStream();
49 fprintf($cpp_hnd, "#include \"%s\"\n", $header);
50 fprintf($cpp_hnd, "#if defined(PHP_PECL_%s_VERSION)\n", $uc_name);
51 fprintf($cpp_hnd, "PHP_PECL_%s_VERSION\n", $uc_name);
52 fprintf($cpp_hnd, "#elif defined(PHP_%s_VERSION)\n", $uc_name);
53 fprintf($cpp_hnd, "PHP_%s_VERSION\n", $uc_name);
54 fprintf($cpp_hnd, "#elif defined(%s_VERSION)\n", $uc_name);
55 fprintf($cpp_hnd, "%s_VERSION\n", $uc_name);
56 fprintf($cpp_hnd, "#endif\n");
58 $php_cnf = (defined("PHP_BINARY") ? PHP_BINARY
: "php") . "-config";
59 $php_inc = (new ExecCmd($php_cnf))->run([
62 $ext_inc = (new ExecCmd("find"))->run([
63 $path, "-not", "-path", "*/.*", "-type", "d", "-printf", "-I'%p' "
65 $cpp_res = (new ExecCmd("cpp $php_inc $ext_inc"))->run([
68 return trim(substr($cpp_res, strrpos($cpp_res, "\n")), "\"\n");