travis-setup.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. /**
  20. * Install PHP extensions required for testing by Travis CI.
  21. *
  22. * @author Victor Berchet <victor@suumit.com>
  23. * @since 2.2
  24. */
  25. $installer = new PhpExtensions();
  26. if (isset($argv[1]) && 'APC' === strtoupper($argv[1])) {
  27. $installer->install('apc');
  28. } else {
  29. $installer->install('xcache');
  30. }
  31. $installer->install('memcache');
  32. $installer->install('memcached');
  33. class PhpExtensions
  34. {
  35. protected $extensions;
  36. protected $phpVersion;
  37. protected $iniPath;
  38. public function __construct()
  39. {
  40. $this->phpVersion = phpversion();
  41. $this->iniPath = php_ini_loaded_file();
  42. $this->extensions = array(
  43. 'memcache' => array(
  44. 'url' => 'http://pecl.php.net/get/memcache-2.2.6.tgz',
  45. 'php_version' => array(),
  46. 'cfg' => array('--enable-memcache'),
  47. 'ini' => array('extension=memcache.so'),
  48. ),
  49. 'memcached' => array(
  50. 'url' => 'http://pecl.php.net/get/memcached-1.0.2.tgz',
  51. 'php_version' => array(
  52. // memcached 1.0.2 does not build on PHP 5.4
  53. array('<', '5.4'),
  54. ),
  55. 'cfg' => array(),
  56. 'ini' => array('extension=memcached.so'),
  57. ),
  58. 'apc' => array(
  59. 'url' => 'http://pecl.php.net/get/APC-3.1.9.tgz',
  60. 'php_version' => array(
  61. // apc 3.1.9 causes a segfault on PHP 5.4
  62. array('<', '5.4'),
  63. ),
  64. 'cfg' => array(),
  65. 'ini' => array(
  66. 'extension=apc.so',
  67. 'apc.enabled=1',
  68. 'apc.enable_cli=1'
  69. ),
  70. ),
  71. 'xcache' => array(
  72. 'url' => 'http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz',
  73. 'php_version' => array(
  74. // xcache does not build with Travis CI (as of 2012-01-09)
  75. array('<', '5'),
  76. ),
  77. 'cfg' => array('--enable-xcache'),
  78. 'ini' => array(
  79. 'extension=xcache.so',
  80. 'xcache.cacher=false',
  81. 'xcache.admin.enable_auth=0',
  82. 'xcache.var_size=1M',
  83. ),
  84. ),
  85. );
  86. }
  87. public function install($name)
  88. {
  89. if (array_key_exists($name, $this->extensions)) {
  90. $extension = $this->extensions[$name];
  91. echo "== extension: $name ==\n";
  92. foreach ($extension['php_version'] as $version) {
  93. if (!version_compare($this->phpVersion, $version[1], $version[0])) {
  94. printf(
  95. "=> not installed, requires a PHP version %s %s (%s installed)\n",
  96. $version[0],
  97. $version[1],
  98. $this->phpVersion
  99. );
  100. return;
  101. }
  102. }
  103. $this->system(sprintf("wget %s > /dev/null 2>&1", $extension['url']));
  104. $file = basename($extension['url']);
  105. $this->system(sprintf("tar -xzf %s > /dev/null 2>&1", $file));
  106. $folder = basename($file, ".tgz");
  107. $folder = basename($folder, ".tar.gz");
  108. $this->system(sprintf(
  109. 'sh -c "cd %s && phpize && ./configure %s && make && sudo make install" > /dev/null 2>&1',
  110. $folder,
  111. implode(' ', $extension['cfg'])
  112. ));
  113. foreach ($extension['ini'] as $ini) {
  114. $this->system(sprintf("echo %s >> %s", $ini, $this->iniPath));
  115. }
  116. printf("=> installed (%s)\n", $folder);
  117. }
  118. }
  119. private function system($cmd)
  120. {
  121. $ret = 0;
  122. system($cmd, $ret);
  123. if (0 !== $ret) {
  124. printf("=> Command '%s' failed !", $cmd);
  125. exit($ret);
  126. }
  127. }
  128. }