[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>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
class BundleCompiler implements ResourceBundleCompilerInterface
|
class BundleCompiler implements BundleCompilerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string The path to the "genrb" executable.
|
* @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.
|
* 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.
|
* @throws RuntimeException If the "genrb" cannot be found.
|
||||||
*/
|
*/
|
||||||
public function __construct($genrb = 'genrb')
|
public function __construct($genrb = 'genrb', $envVars = '')
|
||||||
{
|
{
|
||||||
exec('which ' . $genrb, $output, $status);
|
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>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
interface ResourceBundleCompilerInterface
|
interface BundleCompilerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Compiles a resource bundle at the given source to the given target
|
* Compiles a resource bundle at the given source to the given target
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Intl\ResourceBundle\Transformer;
|
namespace Symfony\Component\Intl\ResourceBundle\Transformer;
|
||||||
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Intl\ResourceBundle\Compiler\ResourceBundleCompilerInterface;
|
use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompilerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of {@link CompilationContextInterface}.
|
* Default implementation of {@link CompilationContextInterface}.
|
||||||
@ -37,7 +37,7 @@ class CompilationContext implements CompilationContextInterface
|
|||||||
private $filesystem;
|
private $filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ResourceBundleCompilerInterface
|
* @var BundleCompilerInterface
|
||||||
*/
|
*/
|
||||||
private $compiler;
|
private $compiler;
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class CompilationContext implements CompilationContextInterface
|
|||||||
*/
|
*/
|
||||||
private $icuVersion;
|
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->sourceDir = $sourceDir;
|
||||||
$this->binaryDir = $binaryDir;
|
$this->binaryDir = $binaryDir;
|
||||||
|
@ -43,7 +43,7 @@ interface CompilationContextInterface
|
|||||||
/**
|
/**
|
||||||
* Returns a resource bundle compiler.
|
* 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();
|
public function getCompiler();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ function run($command)
|
|||||||
|
|
||||||
if (0 !== $status) {
|
if (0 !== $status) {
|
||||||
$output = implode("\n", $output);
|
$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.");
|
bailout("\"$command\" failed.");
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,17 @@ use Symfony\Component\Filesystem\Filesystem;
|
|||||||
require_once __DIR__ . '/common.php';
|
require_once __DIR__ . '/common.php';
|
||||||
require_once __DIR__ . '/autoload.php';
|
require_once __DIR__ . '/autoload.php';
|
||||||
|
|
||||||
if (1 !== $GLOBALS['argc']) {
|
if ($GLOBALS['argc'] > 2) {
|
||||||
bailout(<<<MESSAGE
|
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
|
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
|
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.
|
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
|
For running this script, the intl extension must be loaded and all vendors
|
||||||
must have been installed through composer:
|
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.');
|
bailout('You must run "composer update --dev" before running this script.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filesystem = new Filesystem();
|
||||||
|
|
||||||
$icuVersionInPhp = Intl::getIcuVersion();
|
$icuVersionInPhp = Intl::getIcuVersion();
|
||||||
|
|
||||||
echo "Found intl extension with ICU version $icuVersionInPhp.\n";
|
echo "Found intl extension with ICU version $icuVersionInPhp.\n";
|
||||||
@ -70,45 +75,76 @@ foreach ($urls as $urlVersion => $url) {
|
|||||||
echo " $urlVersion\n";
|
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
|
// Always build genrb so that we can determine the ICU version of the
|
||||||
// download by running genrb --version
|
// download by running genrb --version
|
||||||
echo "Building genrb.\n";
|
echo "Building genrb.\n";
|
||||||
|
|
||||||
cd($svn->getPath());
|
cd($sourceDir);
|
||||||
|
|
||||||
echo "Running make clean...\n";
|
|
||||||
|
|
||||||
run('make clean');
|
|
||||||
|
|
||||||
echo "Running configure...\n";
|
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";
|
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";
|
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";
|
echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n";
|
||||||
|
|
||||||
$context = new CompilationContext(
|
$context = new CompilationContext(
|
||||||
$svn->getPath() . '/data',
|
$sourceDir . '/data',
|
||||||
IcuData::getResourceDirectory(),
|
IcuData::getResourceDirectory(),
|
||||||
new Filesystem(),
|
$filesystem,
|
||||||
new BundleCompiler($genrb),
|
new BundleCompiler($genrb, $genrbEnv),
|
||||||
$icuVersionInDownload
|
$icuVersionInDownload
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -39,14 +39,14 @@ class SvnRepository
|
|||||||
/**
|
/**
|
||||||
* Downloads the ICU data for the given version.
|
* Downloads the ICU data for the given version.
|
||||||
*
|
*
|
||||||
* @param string $url The URL to download from.
|
* @param string $url The URL to download from.
|
||||||
* @param string $version The ICU version to download.
|
* @param string $targetDir The directory in which to store the repository.
|
||||||
*
|
*
|
||||||
* @return SvnRepository The directory where the data is stored.
|
* @return SvnRepository The directory where the data is stored.
|
||||||
*
|
*
|
||||||
* @throws RuntimeException If an error occurs during the download.
|
* @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);
|
exec('which svn', $output, $result);
|
||||||
|
|
||||||
@ -54,17 +54,9 @@ class SvnRepository
|
|||||||
throw new RuntimeException('The command "svn" is not installed.');
|
throw new RuntimeException('The command "svn" is not installed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$targetDir = sys_get_temp_dir() . '/icu-data/' . $version;
|
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
|
|
||||||
if ($filesystem->exists($targetDir)) {
|
if (!$filesystem->exists($targetDir)) {
|
||||||
exec('svn update ' . $targetDir, $output, $result);
|
|
||||||
|
|
||||||
if ($result !== 0) {
|
|
||||||
throw new RuntimeException('The SVN checkout of ' . $targetDir . 'failed.');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$filesystem->remove($targetDir);
|
$filesystem->remove($targetDir);
|
||||||
$filesystem->mkdir($targetDir);
|
$filesystem->mkdir($targetDir);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user