From 05698f70edcd3106021425ac36023964e527e72e Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 22 Jun 2020 14:06:25 +0200 Subject: new package open https://github.com/goodspb/pdlib/pull/25 fix linker command open https://github.com/goodspb/pdlib/pull/26 fix skip test open https://github.com/goodspb/pdlib/pull/27 display version open https://github.com/goodspb/pdlib/pull/29 fix build --- .gitignore | 9 +++ 27.patch | 35 ++++++++++ 29.patch | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 4 ++ PHPINFO | 6 ++ REFLECTION | 127 +++++++++++++++++++++++++++++++++++ php-pdlib.spec | 204 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 566 insertions(+) create mode 100644 .gitignore create mode 100644 27.patch create mode 100644 29.patch create mode 100644 Makefile create mode 100644 PHPINFO create mode 100644 REFLECTION create mode 100644 php-pdlib.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01f0400 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +clog +package-*.xml +*.tgz +*.tar.bz2 +*.tar.gz +*.tar.xz +*.tar.xz.asc +*.src.rpm +*/*rpm diff --git a/27.patch b/27.patch new file mode 100644 index 0000000..495aecc --- /dev/null +++ b/27.patch @@ -0,0 +1,35 @@ +From b70ff4eb17468da206745e890f479eee7522bc63 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Mon, 22 Jun 2020 11:20:55 +0200 +Subject: [PATCH] display extension and library version in phpinfo + +--- + pdlib.cc | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/pdlib.cc b/pdlib.cc +index 76bf514..c1db7e4 100644 +--- a/pdlib.cc ++++ b/pdlib.cc +@@ -33,6 +33,7 @@ extern "C" { + #include "src/face_recognition.h" + #include "src/cnn_face_detection.h" + #include "src/face_landmark_detection.h" ++#include + + /* If you declare any globals in php_pdlib.h uncomment this: + ZEND_DECLARE_MODULE_GLOBALS(pdlib) +@@ -245,8 +246,13 @@ PHP_RSHUTDOWN_FUNCTION(pdlib) + */ + PHP_MINFO_FUNCTION(pdlib) + { ++ char buf[32]; ++ + php_info_print_table_start(); + php_info_print_table_header(2, "pdlib support", "enabled"); ++ php_info_print_table_row(2, "pdlib extension version", PHP_PDLIB_VERSION); ++ snprintf(buf, sizeof(buf), "%d.%d.%d", DLIB_MAJOR_VERSION, DLIB_MINOR_VERSION, DLIB_PATCH_VERSION); ++ php_info_print_table_row(2, "dlib library version", buf); + php_info_print_table_end(); + + /* Remove comments if you have entries in php.ini diff --git a/29.patch b/29.patch new file mode 100644 index 0000000..fb4103c --- /dev/null +++ b/29.patch @@ -0,0 +1,181 @@ +From ba797b3c50e3746649cdd39f17a4f875227dff15 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Mon, 22 Jun 2020 12:46:30 +0200 +Subject: [PATCH 1/3] hounours system CXXFLAGS + +--- + config.m4 | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/config.m4 b/config.m4 +index 5b3872c..d51d38e 100644 +--- a/config.m4 ++++ b/config.m4 +@@ -18,8 +18,6 @@ dnl Make sure that the comment is aligned: + [ --with-pdlib Include pdlib support]) + + if test "$PHP_PDLIB" != "no"; then +- dnl using C++11 +- CXXFLAGS="-std=c++11" + PHP_REQUIRE_CXX() + PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD) + PHP_SUBST(PDLIB_SHARED_LIBADD) +@@ -49,5 +47,6 @@ if test "$PHP_PDLIB" != "no"; then + PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, PDLIB_SHARED_LIBADD) + PHP_EVAL_INCLINE($LIBDLIB_CFLAGS) + +- PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, cxx) ++ dnl using C++11 ++ PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -std=c++11, cxx) + fi + +From 8f424195e0ca1bd27c5d711f74d9357cd4a1a4bc Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Mon, 22 Jun 2020 12:47:43 +0200 +Subject: [PATCH 2/3] fix unused variables + +--- + pdlib.cc | 5 +---- + 1 file changed, 1 insertion(+), 4 deletions(-) + +diff --git a/pdlib.cc b/pdlib.cc +index 76bf514..b2afe4c 100644 +--- a/pdlib.cc ++++ b/pdlib.cc +@@ -38,9 +38,6 @@ extern "C" { + ZEND_DECLARE_MODULE_GLOBALS(pdlib) + */ + +-/* True global resources - no need for thread safety here */ +-static int le_pdlib; +- + static zend_class_entry *cnn_face_detection_ce = nullptr; + static zend_object_handlers cnn_face_detection_obj_handlers; + +@@ -70,7 +67,7 @@ PHP_INI_END() + PHP_FUNCTION(confirm_pdlib_compiled) + { + char *arg = NULL; +- size_t arg_len, len; ++ size_t arg_len; + zend_string *strg; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) { + +From 912ab43641cb0d9530f2e501358c48e9fe1cf608 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Mon, 22 Jun 2020 12:54:12 +0200 +Subject: [PATCH 3/3] fix [-Werror=format-security] + +--- + src/chinese_whispers.cc | 2 +- + src/cnn_face_detection.cc | 5 ++--- + src/face_landmark_detection.cc | 8 ++++---- + src/face_recognition.cc | 4 ++-- + 4 files changed, 9 insertions(+), 10 deletions(-) + +diff --git a/src/chinese_whispers.cc b/src/chinese_whispers.cc +index 026ef13..0653f9b 100644 +--- a/src/chinese_whispers.cc ++++ b/src/chinese_whispers.cc +@@ -97,7 +97,7 @@ PHP_FUNCTION(dlib_chinese_whispers) + } + } catch (exception& e) + { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } +diff --git a/src/cnn_face_detection.cc b/src/cnn_face_detection.cc +index 83ea66f..a989e80 100644 +--- a/src/cnn_face_detection.cc ++++ b/src/cnn_face_detection.cc +@@ -42,7 +42,7 @@ PHP_METHOD(CnnFaceDetection, __construct) + deserialize(cnn_face_detection_model_path) >> *pnet; + cfd->net = pnet; + } catch (exception& e) { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } +@@ -77,7 +77,6 @@ PHP_METHOD(CnnFaceDetection, detect) + + net_type *pnet = cfd->net; + auto dets = (*pnet)(img); +- int rect_count = 0; + array_init(return_value); + + // Scale the detection locations back to the original image size +@@ -101,7 +100,7 @@ PHP_METHOD(CnnFaceDetection, detect) + } + catch (exception& e) + { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } +diff --git a/src/face_landmark_detection.cc b/src/face_landmark_detection.cc +index 8336964..51139f6 100644 +--- a/src/face_landmark_detection.cc ++++ b/src/face_landmark_detection.cc +@@ -52,7 +52,7 @@ PHP_FUNCTION(dlib_face_landmark_detection) + + zval ARRAY_NAME_WITH_INDEX(face, j); + array_init(&ARRAY_NAME_WITH_INDEX(face, j)); +- for (int k = 0; k < shape.num_parts(); k++) { ++ for (unsigned int k = 0; k < shape.num_parts(); k++) { + zval ARRAY_NAME_WITH_INDEX(part, k); + array_init(&ARRAY_NAME_WITH_INDEX(part, k)); + dlib::point p = shape.part(k); +@@ -95,7 +95,7 @@ PHP_METHOD(FaceLandmarkDetection, __construct) + fld->sp = new shape_predictor; + deserialize(shape_predictor_file_path) >> *(fld->sp); + } catch (exception& e) { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } +@@ -151,7 +151,7 @@ PHP_METHOD(FaceLandmarkDetection, detect) + array_init(&rect_arr); + array_init(&parts_arr); + +- for (int i = 0; i < shape.num_parts(); i++) { ++ for (unsigned int i = 0; i < shape.num_parts(); i++) { + zval part; + array_init(&part); + dlib::point p = shape.part(i); +@@ -169,7 +169,7 @@ PHP_METHOD(FaceLandmarkDetection, detect) + add_assoc_zval(return_value, "rect", &rect_arr); + add_assoc_zval(return_value, "parts", &parts_arr); + } catch (exception& e) { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } +diff --git a/src/face_recognition.cc b/src/face_recognition.cc +index 99a3d97..401e964 100644 +--- a/src/face_recognition.cc ++++ b/src/face_recognition.cc +@@ -37,7 +37,7 @@ PHP_METHOD(FaceRecognition, __construct) + fr->net = new anet_type; + deserialize(face_recognition_model_path) >> *(fr->net); + } catch (exception& e) { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } +@@ -183,7 +183,7 @@ PHP_METHOD(FaceRecognition, computeDescriptor) + add_next_index_double(return_value, d); + } + } catch (exception& e) { +- zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what()); ++ zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "%s", e.what()); + return; + } + } diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91b0fd5 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SRCDIR := $(shell pwd) +NAME := $(shell basename $(SRCDIR)) +include ../../common/Makefile + diff --git a/PHPINFO b/PHPINFO new file mode 100644 index 0000000..4e6a38c --- /dev/null +++ b/PHPINFO @@ -0,0 +1,6 @@ + +pdlib + +pdlib support => enabled +pdlib extension version => 1.0.1 +dlib library version => 19.20.0 diff --git a/REFLECTION b/REFLECTION new file mode 100644 index 0000000..01fa628 --- /dev/null +++ b/REFLECTION @@ -0,0 +1,127 @@ +Extension [ extension #90 pdlib version 1.0.1 ] { + + - Functions { + Function [ function confirm_pdlib_compiled ] { + } + Function [ function dlib_chinese_whispers ] { + + - Parameters [1] { + Parameter #0 [ $edges ] + } + } + Function [ function dlib_face_detection ] { + + - Parameters [2] { + Parameter #0 [ $img_path ] + Parameter #1 [ $upsample_num ] + } + } + Function [ function dlib_face_landmark_detection ] { + + - Parameters [2] { + Parameter #0 [ $shape_predictor_file_path ] + Parameter #1 [ $img_path ] + } + } + } + + - Classes [3] { + Class [ class CnnFaceDetection ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [2] { + Method [ public method __construct ] { + + - Parameters [1] { + Parameter #0 [ $cnn_face_detection_model_path ] + } + } + + Method [ public method detect ] { + + - Parameters [2] { + Parameter #0 [ $img_path ] + Parameter #1 [ $upsample_num ] + } + } + } + } + + Class [ class FaceLandmarkDetection ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [2] { + Method [ public method __construct ] { + + - Parameters [1] { + Parameter #0 [ $shape_predictor_file_path ] + } + } + + Method [ public method detect ] { + + - Parameters [2] { + Parameter #0 [ $img_path ] + Parameter #1 [ $bounding_box ] + } + } + } + } + + Class [ class FaceRecognition ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [2] { + Method [ public method __construct ] { + + - Parameters [1] { + Parameter #0 [ $face_recognition_model_path ] + } + } + + Method [ public method computeDescriptor ] { + + - Parameters [3] { + Parameter #0 [ $img_path ] + Parameter #1 [ $landmarks ] + Parameter #2 [ $num_jitters ] + } + } + } + } + } +} + diff --git a/php-pdlib.spec b/php-pdlib.spec new file mode 100644 index 0000000..eda6711 --- /dev/null +++ b/php-pdlib.spec @@ -0,0 +1,204 @@ +# remirepo spec file for php-pdlib +# +# Copyright (c) 2020 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/4.0/ +# +# Please, preserve the changelog entries +# +%if 0%{?scl:1} +%global sub_prefix %{scl_prefix} +%scl_package php-pdlib +%else +%global pkg_name %{name} +%endif + +# use master, see https://github.com/goodspb/pdlib/issues/28 +%global gh_commit 45c0b7441aa1f4348996d0f5ca55a2c8b072a381 +%global gh_short %(c=%{gh_commit}; echo ${c:0:7}) +%global gh_owner goodspb +%global gh_project pdlib +%global gh_date 20200620 +%global pecl_name pdlib +%global with_zts 0%{!?_without_zts:%{?__ztsphp:1}} +%global ini_name 40-%{pecl_name}.ini + +%if ! 0%{?dtsversion} +%if 0%{?rhel} == 6 +%global dtsenable export PHP_AUTOCONF=autoconf268;export PHP_AUTOHEADER=autoheader268;source /opt/rh/devtoolset-7/enable +BuildRequires: devtoolset-7-toolchain +BuildRequires: autoconf268 +%endif +%if 0%{?rhel} == 7 +%global dtsenable source /opt/rh/devtoolset-7/enable +BuildRequires: devtoolset-7-toolchain +%endif +%endif + +Summary: A PHP extension for Dlib +Name: %{?sub_prefix}php-%{pecl_name} +Version: 1.0 +%if 0%{?gh_date:1} +Release: 1.%{gh_date}git%{gh_short}%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +%else +Release: 1%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +%endif +License: MIT +URL: https://github.com/%{gh_owner}/%{gh_project} +Source0: https://github.com/%{gh_owner}/%{gh_project}/archive/%{gh_commit}/%{gh_project}-%{version}-%{gh_short}.tar.gz + +Patch0: https://patch-diff.githubusercontent.com/raw/goodspb/pdlib/pull/27.patch +Patch1: https://patch-diff.githubusercontent.com/raw/goodspb/pdlib/pull/29.patch + +BuildRequires: %{?scl_prefix}php-devel > 7 +BuildRequires: dlib-devel + +Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} +Requires: %{?scl_prefix}php(api) = %{php_core_api} +%{?_sclreq:Requires: %{?scl_prefix}runtime%{?_sclreq}%{?_isa}} + +%if "%{?vendor}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} +# Other third party repo stuff +%if "%{php_version}" > "7.2" +Obsoletes: php72u-%{pecl_name} <= %{version} +Obsoletes: php72w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.3" +Obsoletes: php73-%{pecl_name} <= %{version} +Obsoletes: php73w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.4" +Obsoletes: php74-%{pecl_name} <= %{version} +Obsoletes: php74w-%{pecl_name} <= %{version} +%endif +%endif + +%if 0%{?fedora} < 20 && 0%{?rhel} < 7 +# Filter shared private +%{?filter_provides_in: %filter_provides_in %{_libdir}/.*\.so$} +%{?filter_setup} +%endif + + +%description +PDlib - A PHP extension for Dlib. + +Package built for PHP %(%{__php} -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')%{?scl: as Software Collection (%{scl} by %{?scl_vendor}%{!?scl_vendor:rh})}. + + +%prep +%setup -qc +mv %{gh_project}-%{gh_commit} NTS + +cd NTS +%patch0 -p1 -b .pr27 +%patch1 -p1 -b .pr29 + +# Sanity check, really often broken +extver=$(sed -n '/#define PHP_PDLIB_VERSION/{s/.* "//;s/".*$//;p}' php_pdlib.h) +if test "x${extver}" != "x%{version}%{?gh_date:-dev}"; then + : Error: Upstream extension version is ${extver}, expecting %{version}%{?gh_date:-dev}. + #exit 1 +fi +cd .. + +%if %{with_zts} +# duplicate for ZTS build +cp -pr NTS ZTS +%endif + +# Drop in the bit of configuration +cat << 'EOF' | tee %{ini_name} +; Enable '%{summary}' extension module +extension = %{pecl_name}.so +EOF + + +%build +%{?dtsenable} + +cd NTS +%{_bindir}/phpize +%configure \ + --with-php-config=%{_bindir}/php-config \ + --with-libdir=%{_lib} \ + --with-pdlib +make %{?_smp_mflags} + +%if %{with_zts} +cd ../ZTS +%{_bindir}/zts-phpize +%configure \ + --with-php-config=%{_bindir}/zts-php-config \ + --with-libdir=%{_lib} \ + --with-pdlib +make %{?_smp_mflags} +%endif + + +%install +%{?dtsenable} + +# Install the NTS stuff +make -C NTS install INSTALL_ROOT=%{buildroot} +install -D -m 644 %{ini_name} %{buildroot}%{php_inidir}/%{ini_name} + +%if %{with_zts} +# Install the ZTS stuff +make -C ZTS install INSTALL_ROOT=%{buildroot} +install -D -m 644 %{ini_name} %{buildroot}%{php_ztsinidir}/%{ini_name} +%endif + + + +%check +export NO_INTERACTION=1 +export SKIP_ONLINE_TESTS=1 +export REPORT_EXIT_STATUS=1 + +cd NTS +: Minimal load test for NTS extension +%{__php} --no-php-ini \ + --define extension=%{buildroot}%{php_extdir}/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for NTS extension +TEST_PHP_EXECUTABLE=%{__php} \ +TEST_PHP_ARGS="-n -d extension=%{buildroot}%{php_extdir}/%{pecl_name}.so" \ +%{__php} -n run-tests.php --show-diff || : ignore + +%if %{with_zts} +cd ../ZTS +: Minimal load test for ZTS extension +%{__ztsphp} --no-php-ini \ + --define extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for ZTS extension +TEST_PHP_EXECUTABLE=%{__ztsphp} \ +TEST_PHP_ARGS="-n -d extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so" \ +%{__ztsphp} -n run-tests.php --show-diff +%endif + + +%files +%{!?_licensedir:%global license %%doc} +%license NTS/LICENSE +%doc NTS/README.md + +%config(noreplace) %{php_inidir}/%{ini_name} +%{php_extdir}/%{pecl_name}.so + +%if %{with_zts} +%config(noreplace) %{php_ztsinidir}/%{ini_name} +%{php_ztsextdir}/%{pecl_name}.so +%endif + + +%changelog +* Mon Jun 22 2020 Remi Collet - 1.0-1.20200620git45c0b74 +- new package +- open https://github.com/goodspb/pdlib/pull/25 fix linker command +- open https://github.com/goodspb/pdlib/pull/26 fix skip test +- open https://github.com/goodspb/pdlib/pull/27 display version +- open https://github.com/goodspb/pdlib/pull/29 fix build -- cgit