[Intl] Fixed various problems in the resource compilation process
This commit is contained in:
parent
4a5c453266
commit
467cc93447
|
@ -18,7 +18,7 @@ use Symfony\Component\Intl\Exception\RuntimeException;
|
|||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Symfony\Component\Intl\ResourceBundle\Compiler;
|
|||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface ResourceBundleCompilerInterface
|
||||
interface BundleCompilerInterface
|
||||
{
|
||||
/**
|
||||
* Compiles a resource bundle at the given source to the given target
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -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(<<<MESSAGE
|
||||
Usage: php update-icu-component.php
|
||||
Usage: php update-icu-component.php <path/to/icu/source>
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Reference in New Issue