update-icu-component.php 6.1 KB

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