summaryrefslogtreecommitdiffstats
path: root/php-endroid-qrcode.spec
blob: 6d7291cdb20a32c23c2f6a217bb9119d55f88c78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# remirepo/fedora spec file for php-endroid-qrcode
#
# Copyright (c) 2017-2018 Remi Collet
# License: CC-BY-SA
# http://creativecommons.org/licenses/by-sa/4.0/
#
# Please, preserve the changelog entries
#
%global gh_commit    c9644bec2a9cc9318e98d1437de3c628dcd1ef93
%global gh_short     %(c=%{gh_commit}; echo ${c:0:7})
%global gh_owner     endroid
%global gh_project   QrCode

%global pk_vendor    %{gh_owner}
%global pk_project   qrcode

%global ns_vendor    Endroid
%global ns_project   QrCode
%global php_home     %{_datadir}/php
%global with_tests   0%{!?_without_tests:1}

Name:           php-%{pk_vendor}-%{pk_project}
Version:        1.9.3
Release:        3%{?dist}
Summary:        Endroid QR Code

Group:          Development/Libraries
License:        MIT
URL:            https://github.com/%{gh_owner}/%{gh_project}
Source0:        https://github.com/%{gh_owner}/%{gh_project}/archive/%{gh_commit}/%{name}-%{version}-%{gh_short}.tar.gz

# Assets relocation
Patch0:         %{name}-rpm.patch
Patch1:         %{name}-el6-rpm.patch

BuildArch:      noarch
%if %{with_tests}
# For tests
BuildRequires:  php(language) >= 5.4
BuildRequires:  php-gd
BuildRequires:  php-composer(symfony/options-resolver) <  4
BuildRequires:  php-composer(symfony/options-resolver) >= 2.3
BuildRequires:  php-reflection
BuildRequires:  php-pcre
BuildRequires:  php-spl
# From composer.json, "require-dev": {
#        "symfony/browser-kit": "^2.3|^3.0",
#        "symfony/framework-bundle": "^2.3|^3.0",
#        "symfony/http-kernel": "^2.3|^3.0",
#        "sensio/framework-extra-bundle": "^3.0",
#        "phpunit/phpunit": "^4.0|^5.0"
BuildRequires:  php-composer(phpunit/phpunit)
# Required by autoloader
BuildRequires:  php-composer(fedora/autoloader)
%endif
# Unbundled assets
%if 0%{?rhel} != 6
BuildRequires:  open-sans-fonts
%endif

# From composer.json, "require": {
#        "php": ">=5.4",
#        "ext-gd": "*",
#        "symfony/options-resolver": "^2.3|^3.0"
Requires:       php(language) >= 5.4
Requires:       php-gd
Requires:       php-composer(symfony/options-resolver) <  4
Requires:       php-composer(symfony/options-resolver) >= 2.3
# From phpcompatinfo report for version 1.9.3
Requires:       php-reflection
Requires:       php-pcre
Requires:       php-spl
# Required by autoloader
Requires:       php-composer(fedora/autoloader)
# Unbundled assets
%if 0%{?rhel} != 6
Requires:       open-sans-fonts
%else
Provides:       bundled(open-sans-fonts)
%endif

Provides:       php-composer(%{pk_vendor}/%{pk_project}) = %{version}


%description
This library based on QRcode Perl CGI & PHP scripts by Y. Swetake
helps you generate images containing a QR code.

Autoloader: %{php_home}/%{ns_vendor}/%{ns_project}/autoload.php


%prep
%setup -q -n %{gh_project}-%{gh_commit}

%if 0%{?rhel} != 6
: Drop bundled font
rm -r assets/font

: Relocate assets
%patch0 -p0
%else
%patch1 -p0
%endif
sed -e 's:@ASSETS@:%{_datadir}/%{name}/assets:' -i src/QrCode.php

: Fix wrong-file-end-of-line-encoding
sed -e 's/\r//' -i *.md

: Fix perms
find . -type f -exec chmod -x {} \;

: Generate autoloader
cat << 'EOF' | tee src/autoload.php
<?php
/* Autoloader for %{name} and its dependencies */
require_once '%{php_home}/Fedora/Autoloader/autoload.php';

\Fedora\Autoloader\Autoload::addPsr4('%{ns_vendor}\\%{ns_project}\\', __DIR__);
if (file_exists('%{php_home}/Symfony3/Component/OptionsResolver/autoload.php')) {
    \Fedora\Autoloader\Autoload::addPsr4('Symfony\\Component\\', '%{php_home}/Symfony3/Component');
} else {
    \Fedora\Autoloader\Autoload::addPsr4('Symfony\\Component\\', '%{php_home}/Symfony/Component');
}
EOF


%build
# Empty build section, most likely nothing required.


%install
: Library
mkdir -p      %{buildroot}%{php_home}/%{ns_vendor}
cp -pr src    %{buildroot}%{php_home}/%{ns_vendor}/%{ns_project}

: Assets
mkdir -p      %{buildroot}%{_datadir}/%{name}
cp -pr assets %{buildroot}%{_datadir}/%{name}/assets


%check
%if %{with_tests}
mkdir vendor
cat << 'EOF' | tee vendor/autoload.php
<?php
require '%{buildroot}%{php_home}/%{ns_vendor}/%{ns_project}/autoload.php';
\Fedora\Autoloader\Autoload::addPsr4('%{ns_vendor}\\%{ns_project}\\Tests\\', __DIR__ . '/../tests');
EOF

export RPM_ASSETS_BUILDROOT=%{buildroot}

: Minimal test suite without Symfony integration
ret=0
for cmd in php php56 php70 php71 php72; do
  if which $cmd; then
    $cmd %{_bindir}/phpunit --bootstrap vendor/autoload.php --verbose tests/QrCodeTest.php || ret=1
  fi
done
exit $ret
%else
: Test suite disabled
%endif


%files
%{!?_licensedir:%global license %%doc}
%license LICENSE
%doc composer.json
%doc README.md
%{_datadir}/%{name}
%dir %{php_home}/%{ns_vendor}
     %{php_home}/%{ns_vendor}/%{ns_project}

%changelog
* Mon Jan 15 2018 Remi Collet <remi@remirepo.net> - 1.9.3-2
- simpler autoloader for Symfony

* Tue Jun 27 2017 Remi Collet <remi@remirepo.net> - 1.9.3-1
- initial package, version 1.9.3