]> git.immae.eu Git - github/wallabag/wallabag.git/blame - vendor/symfony/intl/Symfony/Component/Intl/Resources/bin/update-icu-component.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / Resources / bin / update-icu-component.php
CommitLineData
4f5b44bd
NL
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12use Symfony\Component\Icu\IcuData;
13use Symfony\Component\Intl\Intl;
14use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompiler;
15use Symfony\Component\Intl\ResourceBundle\Transformer\BundleTransformer;
16use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContext;
17use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\CurrencyBundleTransformationRule;
18use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LanguageBundleTransformationRule;
19use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LocaleBundleTransformationRule;
20use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\RegionBundleTransformationRule;
21use Symfony\Component\Intl\Util\SvnRepository;
22use Symfony\Component\Filesystem\Filesystem;
23
24require_once __DIR__ . '/common.php';
25require_once __DIR__ . '/autoload.php';
26
27if ($GLOBALS['argc'] > 3 || 2 === $GLOBALS['argc'] && '-h' === $GLOBALS['argv'][1]) {
28 bailout(<<<MESSAGE
29Usage: php update-icu-component.php <path/to/icu/source> <path/to/icu/build>
30
31Updates the ICU data for Symfony2 to the latest version of the ICU version
32included in the intl extension. For example, if your intl extension includes
33ICU 4.8, the script will download the latest data available for ICU 4.8.
34
35If you downloaded the SVN repository before, you can pass the path to the
36repository source in the first optional argument.
37
38If you also built the repository before, you can pass the directory where that
39build is stored in the second parameter. The build directory needs to contain
40the subdirectories bin/ and lib/.
41
42For running this script, the intl extension must be loaded and all vendors
43must have been installed through composer:
44
45 composer install --dev
46
47MESSAGE
48 );
49}
50
51echo LINE;
52echo centered("ICU Resource Bundle Compilation") . "\n";
53echo LINE;
54
55if (!Intl::isExtensionLoaded()) {
56 bailout('The intl extension for PHP is not installed.');
57}
58
59if (!class_exists('\Symfony\Component\Icu\IcuData')) {
60 bailout('You must run "composer update --dev" before running this script.');
61}
62
63$filesystem = new Filesystem();
64
65$icuVersionInPhp = Intl::getIcuVersion();
66
67echo "Found intl extension with ICU version $icuVersionInPhp.\n";
68
69$shortIcuVersion = strip_minor_versions($icuVersionInPhp);
70$urls = parse_ini_file(__DIR__ . '/icu.ini');
71
72if (!isset($urls[$shortIcuVersion])) {
73 bailout('The version ' . $shortIcuVersion . ' is not available in the icu.ini file.');
74}
75
76echo "icu.ini parsed. Available versions:\n";
77
78foreach ($urls as $urlVersion => $url) {
79 echo " $urlVersion\n";
80}
81
82if ($GLOBALS['argc'] >= 2) {
83 $sourceDir = $GLOBALS['argv'][1];
84 $svn = new SvnRepository($sourceDir);
85
86 echo "Using existing SVN repository at {$sourceDir}.\n";
87} else {
88 echo "Starting SVN checkout for version $shortIcuVersion. This may take a while...\n";
89
90 $sourceDir = sys_get_temp_dir() . '/icu-data/' . $shortIcuVersion . '/source';
91 $svn = SvnRepository::download($urls[$shortIcuVersion], $sourceDir);
92
93 echo "SVN checkout to {$sourceDir} complete.\n";
94}
95
96if ($GLOBALS['argc'] >= 3) {
97 $buildDir = $GLOBALS['argv'][2];
98} else {
99 // Always build genrb so that we can determine the ICU version of the
100 // download by running genrb --version
101 echo "Building genrb.\n";
102
103 cd($sourceDir);
104
105 echo "Running configure...\n";
106
107 $buildDir = sys_get_temp_dir() . '/icu-data/' . $shortIcuVersion . '/build';
108
109 $filesystem->remove($buildDir);
110 $filesystem->mkdir($buildDir);
111
112 run('./configure --prefix=' . $buildDir . ' 2>&1');
113
114 echo "Running make...\n";
115
116 // If the directory "lib" does not exist in the download, create it or we
117 // will run into problems when building libicuuc.so.
118 $filesystem->mkdir($sourceDir . '/lib');
119
120 // If the directory "bin" does not exist in the download, create it or we
121 // will run into problems when building genrb.
122 $filesystem->mkdir($sourceDir . '/bin');
123
124 echo "[1/5] libicudata.so...";
125
126 cd($sourceDir . '/stubdata');
127 run('make 2>&1 && make install 2>&1');
128
129 echo " ok.\n";
130
131 echo "[2/5] libicuuc.so...";
132
133 cd($sourceDir . '/common');
134 run('make 2>&1 && make install 2>&1');
135
136 echo " ok.\n";
137
138 echo "[3/5] libicui18n.so...";
139
140 cd($sourceDir . '/i18n');
141 run('make 2>&1 && make install 2>&1');
142
143 echo " ok.\n";
144
145 echo "[4/5] libicutu.so...";
146
147 cd($sourceDir . '/tools/toolutil');
148 run('make 2>&1 && make install 2>&1');
149
150 echo " ok.\n";
151
152 echo "[5/5] genrb...";
153
154 cd($sourceDir . '/tools/genrb');
155 run('make 2>&1 && make install 2>&1');
156
157 echo " ok.\n";
158}
159
160$genrb = $buildDir . '/bin/genrb';
161$genrbEnv = 'LD_LIBRARY_PATH=' . $buildDir . '/lib ';
162
163echo "Using $genrb.\n";
164
165$icuVersionInDownload = get_icu_version_from_genrb($genrbEnv . ' ' . $genrb);
166
167echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n";
168
169$context = new CompilationContext(
170 $sourceDir . '/data',
171 IcuData::getResourceDirectory(),
172 $filesystem,
173 new BundleCompiler($genrb, $genrbEnv),
174 $icuVersionInDownload
175);
176
177$transformer = new BundleTransformer();
178$transformer->addRule(new LanguageBundleTransformationRule());
179$transformer->addRule(new RegionBundleTransformationRule());
180$transformer->addRule(new CurrencyBundleTransformationRule());
181$transformer->addRule(new LocaleBundleTransformationRule());
182
183echo "Starting resource bundle compilation. This may take a while...\n";
184
185$transformer->compileBundles($context);
186
187echo "Resource bundle compilation complete.\n";
188
189$svnInfo = <<<SVN_INFO
190SVN information
191===============
192
193URL: {$svn->getUrl()}
194Revision: {$svn->getLastCommit()->getRevision()}
195Author: {$svn->getLastCommit()->getAuthor()}
196Date: {$svn->getLastCommit()->getDate()}
197
198SVN_INFO;
199
200$svnInfoFile = $context->getBinaryDir() . '/svn-info.txt';
201
202file_put_contents($svnInfoFile, $svnInfo);
203
204echo "Wrote $svnInfoFile.\n";
205
206$versionFile = $context->getBinaryDir() . '/version.txt';
207
208file_put_contents($versionFile, "$icuVersionInDownload\n");
209
210echo "Wrote $versionFile.\n";
211
212echo "Done.\n";