4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
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
;
24 require_once __DIR__
. '/common.php';
25 require_once __DIR__
. '/autoload.php';
27 if ($GLOBALS['argc'] > 3 || 2 === $GLOBALS['argc'] && '-h' === $GLOBALS['argv'][1]) {
29 Usage: php update-icu-component.php <path/to/icu/source> <path/to/icu/build>
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.
35 If you downloaded the SVN repository before, you can pass the path to the
36 repository source in the first optional argument.
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/.
42 For running this script, the intl extension must be loaded and all vendors
43 must have been installed through composer:
45 composer install --dev
52 echo centered("ICU Resource Bundle Compilation") . "\n";
55 if (!Intl
::isExtensionLoaded()) {
56 bailout('The intl extension for PHP is not installed.');
59 if (!class_exists('\Symfony\Component\Icu\IcuData')) {
60 bailout('You must run "composer update --dev" before running this script.');
63 $filesystem = new Filesystem();
65 $icuVersionInPhp = Intl
::getIcuVersion();
67 echo "Found intl extension with ICU version $icuVersionInPhp.\n";
69 $shortIcuVersion = strip_minor_versions($icuVersionInPhp);
70 $urls = parse_ini_file(__DIR__
. '/icu.ini');
72 if (!isset($urls[$shortIcuVersion])) {
73 bailout('The version ' . $shortIcuVersion . ' is not available in the icu.ini file.');
76 echo "icu.ini parsed. Available versions:\n";
78 foreach ($urls as $urlVersion => $url) {
79 echo " $urlVersion\n";
82 if ($GLOBALS['argc'] >= 2) {
83 $sourceDir = $GLOBALS['argv'][1];
84 $svn = new SvnRepository($sourceDir);
86 echo "Using existing SVN repository at {$sourceDir}.\n";
88 echo "Starting SVN checkout for version $shortIcuVersion. This may take a while...\n";
90 $sourceDir = sys_get_temp_dir() . '/icu-data/' . $shortIcuVersion . '/source';
91 $svn = SvnRepository
::download($urls[$shortIcuVersion], $sourceDir);
93 echo "SVN checkout to {$sourceDir} complete.\n";
96 if ($GLOBALS['argc'] >= 3) {
97 $buildDir = $GLOBALS['argv'][2];
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";
105 echo "Running configure...\n";
107 $buildDir = sys_get_temp_dir() . '/icu-data/' . $shortIcuVersion . '/build';
109 $filesystem->remove($buildDir);
110 $filesystem->mkdir($buildDir);
112 run('./configure --prefix=' . $buildDir . ' 2>&1');
114 echo "Running make...\n";
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');
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');
124 echo "[1/5] libicudata.so...";
126 cd($sourceDir . '/stubdata');
127 run('make 2>&1 && make install 2>&1');
131 echo "[2/5] libicuuc.so...";
133 cd($sourceDir . '/common');
134 run('make 2>&1 && make install 2>&1');
138 echo "[3/5] libicui18n.so...";
140 cd($sourceDir . '/i18n');
141 run('make 2>&1 && make install 2>&1');
145 echo "[4/5] libicutu.so...";
147 cd($sourceDir . '/tools/toolutil');
148 run('make 2>&1 && make install 2>&1');
152 echo "[5/5] genrb...";
154 cd($sourceDir . '/tools/genrb');
155 run('make 2>&1 && make install 2>&1');
160 $genrb = $buildDir . '/bin/genrb';
161 $genrbEnv = 'LD_LIBRARY_PATH=' . $buildDir . '/lib ';
163 echo "Using $genrb.\n";
165 $icuVersionInDownload = get_icu_version_from_genrb($genrbEnv . ' ' . $genrb);
167 echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n";
169 $context = new CompilationContext(
170 $sourceDir . '/data',
171 IcuData
::getResourceDirectory(),
173 new BundleCompiler($genrb, $genrbEnv),
174 $icuVersionInDownload
177 $transformer = new BundleTransformer();
178 $transformer->addRule(new LanguageBundleTransformationRule());
179 $transformer->addRule(new RegionBundleTransformationRule());
180 $transformer->addRule(new CurrencyBundleTransformationRule());
181 $transformer->addRule(new LocaleBundleTransformationRule());
183 echo "Starting resource bundle compilation. This may take a while...\n";
185 $transformer->compileBundles($context);
187 echo "Resource bundle compilation complete.\n";
189 $svnInfo = <<<SVN_INFO
193 URL: {$svn->getUrl()}
194 Revision: {$svn->getLastCommit()->getRevision()}
195 Author: {$svn->getLastCommit()->getAuthor()}
196 Date: {$svn->getLastCommit()->getDate()}
200 $svnInfoFile = $context->getBinaryDir() . '/svn-info.txt';
202 file_put_contents($svnInfoFile, $svnInfo);
204 echo "Wrote $svnInfoFile.\n";
206 $versionFile = $context->getBinaryDir() . '/version.txt';
208 file_put_contents($versionFile, "$icuVersionInDownload\n");
210 echo "Wrote $versionFile.\n";