diff --git a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php b/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php index eaa32f4b29..174aa179f4 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php +++ b/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php @@ -18,7 +18,7 @@ use Symfony\Component\Intl\Exception\RuntimeException; * * @author Bernhard Schussek */ -class BundleCompiler implements ResourceBundleCompilerInterface +class BundleCompiler implements BundleCompilerInterface { /** * @var string The path to the "genrb" executable. @@ -28,11 +28,13 @@ class BundleCompiler implements ResourceBundleCompilerInterface /** * Creates a new compiler based on the "genrb" executable. * - * @param string $genrb Optional. The path to the "genrb" executable. + * @param string $genrb Optional. The path to the "genrb" executable. + * @param string $envVars Optional. Environment variables to be loaded when + * running "genrb". * * @throws RuntimeException If the "genrb" cannot be found. */ - public function __construct($genrb = 'genrb') + public function __construct($genrb = 'genrb', $envVars = '') { exec('which ' . $genrb, $output, $status); @@ -43,7 +45,7 @@ class BundleCompiler implements ResourceBundleCompilerInterface )); } - $this->genrb = $genrb; + $this->genrb = ($envVars ? $envVars . ' ' : '') . $genrb; } /** diff --git a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php b/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php index 94f629c07e..6184ea3eb1 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php +++ b/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php @@ -16,7 +16,7 @@ namespace Symfony\Component\Intl\ResourceBundle\Compiler; * * @author Bernhard Schussek */ -interface ResourceBundleCompilerInterface +interface BundleCompilerInterface { /** * Compiles a resource bundle at the given source to the given target diff --git a/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php b/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php index f0bf136b6e..cdc1951b96 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php +++ b/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Intl\ResourceBundle\Transformer; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Intl\ResourceBundle\Compiler\ResourceBundleCompilerInterface; +use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompilerInterface; /** * Default implementation of {@link CompilationContextInterface}. @@ -37,7 +37,7 @@ class CompilationContext implements CompilationContextInterface private $filesystem; /** - * @var ResourceBundleCompilerInterface + * @var BundleCompilerInterface */ private $compiler; @@ -46,7 +46,7 @@ class CompilationContext implements CompilationContextInterface */ private $icuVersion; - public function __construct($sourceDir, $binaryDir, Filesystem $filesystem, ResourceBundleCompilerInterface $compiler, $icuVersion) + public function __construct($sourceDir, $binaryDir, Filesystem $filesystem, BundleCompilerInterface $compiler, $icuVersion) { $this->sourceDir = $sourceDir; $this->binaryDir = $binaryDir; diff --git a/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php b/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php index cbda8ebc18..f05c28079a 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php +++ b/src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php @@ -43,7 +43,7 @@ interface CompilationContextInterface /** * Returns a resource bundle compiler. * - * @return \Symfony\Component\Intl\ResourceBundle\Compiler\ResourceBundleCompilerInterface The loaded resource bundle compiler. + * @return \Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompilerInterface The loaded resource bundle compiler. */ public function getCompiler(); diff --git a/src/Symfony/Component/Intl/Resources/bin/common.php b/src/Symfony/Component/Intl/Resources/bin/common.php index c9f023d6f6..4fadbe8233 100644 --- a/src/Symfony/Component/Intl/Resources/bin/common.php +++ b/src/Symfony/Component/Intl/Resources/bin/common.php @@ -47,7 +47,7 @@ function run($command) if (0 !== $status) { $output = implode("\n", $output); - echo "Error:\n" . LINE . "$output\n" . LINE; + echo "Error while running:\n " . getcwd() . '$ ' . $command . "\nOutput:\n" . LINE . "$output\n" . LINE; bailout("\"$command\" failed."); } diff --git a/src/Symfony/Component/Intl/Resources/bin/update-icu-component.php b/src/Symfony/Component/Intl/Resources/bin/update-icu-component.php index 7912e8c2c5..f92bdb91bd 100644 --- a/src/Symfony/Component/Intl/Resources/bin/update-icu-component.php +++ b/src/Symfony/Component/Intl/Resources/bin/update-icu-component.php @@ -24,14 +24,17 @@ use Symfony\Component\Filesystem\Filesystem; require_once __DIR__ . '/common.php'; require_once __DIR__ . '/autoload.php'; -if (1 !== $GLOBALS['argc']) { +if ($GLOBALS['argc'] > 2) { bailout(<< Updates the ICU data for Symfony2 to the latest version of the ICU version included in the intl extension. For example, if your intl extension includes ICU 4.8, the script will download the latest data available for ICU 4.8. +If you downloaded the SVN repository before, you can pass the path to the +repository in the first optional argument. + For running this script, the intl extension must be loaded and all vendors must have been installed through composer: @@ -53,6 +56,8 @@ if (!class_exists('\Symfony\Component\Icu\IcuData')) { bailout('You must run "composer update --dev" before running this script.'); } +$filesystem = new Filesystem(); + $icuVersionInPhp = Intl::getIcuVersion(); echo "Found intl extension with ICU version $icuVersionInPhp.\n"; @@ -70,45 +75,76 @@ foreach ($urls as $urlVersion => $url) { echo " $urlVersion\n"; } -echo "Starting SVN checkout for version $shortIcuVersion. This may take a while...\n"; +if (2 === $GLOBALS['argc']) { + $sourceDir = $GLOBALS['argv'][1]; + $svn = new SvnRepository($sourceDir); -$svn = SvnRepository::download($urls[$shortIcuVersion], $shortIcuVersion); + echo "Using existing SVN repository at {$sourceDir}.\n"; +} else { + echo "Starting SVN checkout for version $shortIcuVersion. This may take a while...\n"; -echo "SVN checkout to {$svn->getPath()} complete.\n"; + $sourceDir = sys_get_temp_dir() . '/icu-data/' . $shortIcuVersion . '/source'; + $svn = SvnRepository::download($urls[$shortIcuVersion], $sourceDir); + + echo "SVN checkout to {$sourceDir} complete.\n"; +} // Always build genrb so that we can determine the ICU version of the // download by running genrb --version echo "Building genrb.\n"; -cd($svn->getPath()); - -echo "Running make clean...\n"; - -run('make clean'); +cd($sourceDir); echo "Running configure...\n"; -run('./configure 2>&1'); +$buildDir = sys_get_temp_dir() . '/icu-data/' . $shortIcuVersion . '/build'; -cd($svn->getPath() . '/tools'); +$filesystem->remove($buildDir); +$filesystem->mkdir($buildDir); + +run('./configure --prefix=' . $buildDir . ' 2>&1'); echo "Running make...\n"; -run('make 2>&1'); +echo "libicudata.so\n"; -$genrb = $svn->getPath() . '/bin/genrb'; +cd($sourceDir . '/stubdata'); +run('make 2>&1 && make install 2>&1'); + +echo "libicuuc.so\n"; + +cd($sourceDir . '/common'); +run('make 2>&1 && make install 2>&1'); + +echo "libicui18n.so\n"; + +cd($sourceDir . '/i18n'); +run('make 2>&1 && make install 2>&1'); + +echo "libicutu.so\n"; + +cd($sourceDir . '/tools/toolutil'); +run('make 2>&1 && make install 2>&1'); + +echo "genrb\n"; + +cd($sourceDir . '/tools/genrb'); +run('make 2>&1 && make install 2>&1'); + +$genrb = $buildDir . '/bin/genrb'; +$genrbEnv = 'LD_LIBRARY_PATH=' . $buildDir . '/lib '; echo "Using $genrb.\n"; -$icuVersionInDownload = get_icu_version_from_genrb($genrb); +$icuVersionInDownload = get_icu_version_from_genrb($genrbEnv . ' ' . $genrb); echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n"; $context = new CompilationContext( - $svn->getPath() . '/data', + $sourceDir . '/data', IcuData::getResourceDirectory(), - new Filesystem(), - new BundleCompiler($genrb), + $filesystem, + new BundleCompiler($genrb, $genrbEnv), $icuVersionInDownload ); diff --git a/src/Symfony/Component/Intl/Util/SvnRepository.php b/src/Symfony/Component/Intl/Util/SvnRepository.php index 514e41c838..5a9b781a1e 100644 --- a/src/Symfony/Component/Intl/Util/SvnRepository.php +++ b/src/Symfony/Component/Intl/Util/SvnRepository.php @@ -39,14 +39,14 @@ class SvnRepository /** * Downloads the ICU data for the given version. * - * @param string $url The URL to download from. - * @param string $version The ICU version to download. + * @param string $url The URL to download from. + * @param string $targetDir The directory in which to store the repository. * * @return SvnRepository The directory where the data is stored. * * @throws RuntimeException If an error occurs during the download. */ - public static function download($url, $version) + public static function download($url, $targetDir) { exec('which svn', $output, $result); @@ -54,17 +54,9 @@ class SvnRepository throw new RuntimeException('The command "svn" is not installed.'); } - $targetDir = sys_get_temp_dir() . '/icu-data/' . $version; - $filesystem = new Filesystem(); - if ($filesystem->exists($targetDir)) { - exec('svn update ' . $targetDir, $output, $result); - - if ($result !== 0) { - throw new RuntimeException('The SVN checkout of ' . $targetDir . 'failed.'); - } - } else { + if (!$filesystem->exists($targetDir)) { $filesystem->remove($targetDir); $filesystem->mkdir($targetDir);