]> git.immae.eu Git - github/wallabag/wallabag.git/blob - 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
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
12 use Symfony\Component\Icu\IcuData;
13 use Symfony\Component\Intl\Intl;
14 use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompiler;
15 use Symfony\Component\Intl\ResourceBundle\Transformer\BundleTransformer;
16 use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContext;
17 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\CurrencyBundleTransformationRule;
18 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LanguageBundleTransformationRule;
19 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LocaleBundleTransformationRule;
20 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\RegionBundleTransformationRule;
21 use Symfony\Component\Intl\Util\SvnRepository;
22 use Symfony\Component\Filesystem\Filesystem;
23
24 require_once __DIR__ . '/common.php';
25 require_once __DIR__ . '/autoload.php';
26
27 if ($GLOBALS['argc'] > 3 || 2 === $GLOBALS['argc'] && '-h' === $GLOBALS['argv'][1]) {
28 bailout(<<<MESSAGE
29 Usage: php update-icu-component.php <path/to/icu/source> <path/to/icu/build>
30
31 Updates the ICU data for Symfony2 to the latest version of the ICU version
32 included in the intl extension. For example, if your intl extension includes
33 ICU 4.8, the script will download the latest data available for ICU 4.8.
34
35 If you downloaded the SVN repository before, you can pass the path to the
36 repository source in the first optional argument.
37
38 If you also built the repository before, you can pass the directory where that
39 build is stored in the second parameter. The build directory needs to contain
40 the subdirectories bin/ and lib/.
41
42 For running this script, the intl extension must be loaded and all vendors
43 must have been installed through composer:
44
45 composer install --dev
46
47 MESSAGE
48 );
49 }
50
51 echo LINE;
52 echo centered("ICU Resource Bundle Compilation") . "\n";
53 echo LINE;
54
55 if (!Intl::isExtensionLoaded()) {
56 bailout('The intl extension for PHP is not installed.');
57 }
58
59 if (!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
67 echo "Found intl extension with ICU version $icuVersionInPhp.\n";
68
69 $shortIcuVersion = strip_minor_versions($icuVersionInPhp);
70 $urls = parse_ini_file(__DIR__ . '/icu.ini');
71
72 if (!isset($urls[$shortIcuVersion])) {
73 bailout('The version ' . $shortIcuVersion . ' is not available in the icu.ini file.');
74 }
75
76 echo "icu.ini parsed. Available versions:\n";
77
78 foreach ($urls as $urlVersion => $url) {
79 echo " $urlVersion\n";
80 }
81
82 if ($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
96 if ($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
163 echo "Using $genrb.\n";
164
165 $icuVersionInDownload = get_icu_version_from_genrb($genrbEnv . ' ' . $genrb);
166
167 echo "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
183 echo "Starting resource bundle compilation. This may take a while...\n";
184
185 $transformer->compileBundles($context);
186
187 echo "Resource bundle compilation complete.\n";
188
189 $svnInfo = <<<SVN_INFO
190 SVN information
191 ===============
192
193 URL: {$svn->getUrl()}
194 Revision: {$svn->getLastCommit()->getRevision()}
195 Author: {$svn->getLastCommit()->getAuthor()}
196 Date: {$svn->getLastCommit()->getDate()}
197
198 SVN_INFO;
199
200 $svnInfoFile = $context->getBinaryDir() . '/svn-info.txt';
201
202 file_put_contents($svnInfoFile, $svnInfo);
203
204 echo "Wrote $svnInfoFile.\n";
205
206 $versionFile = $context->getBinaryDir() . '/version.txt';
207
208 file_put_contents($versionFile, "$icuVersionInDownload\n");
209
210 echo "Wrote $versionFile.\n";
211
212 echo "Done.\n";