Rakefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. require 'date'
  2. require 'digest/md5'
  3. require 'fileutils'
  4. class String
  5. def underscore
  6. self.gsub(/::/, '/').
  7. gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  8. gsub(/([a-z\d])([A-Z])/,'\1_\2').
  9. tr("-", "_").
  10. downcase
  11. end
  12. def unindent
  13. gsub(/^#{self[/\A\s*/]}/, '')
  14. end
  15. end
  16. task :phar, :version do |t, args|
  17. version = args[:version]
  18. File.open("stub.php", "w") do |f|
  19. f.write(<<-STUB.unindent)
  20. <?php
  21. Phar::mapPhar();
  22. $basePath = 'phar://' . __FILE__ . '/';
  23. spl_autoload_register(function($class) use ($basePath)
  24. {
  25. if (0 !== strpos($class, "Imagine\\\\")) {
  26. return false;
  27. }
  28. $path = str_replace('\\\\', DIRECTORY_SEPARATOR, substr($class, 8));
  29. $file = $basePath.$path.'.php';
  30. if (file_exists($file)) {
  31. require_once $file;
  32. return true;
  33. }
  34. });
  35. __HALT_COMPILER();
  36. STUB
  37. end
  38. system "phar-build -s #{Dir.pwd}/lib/Imagine -S #{Dir.pwd}/stub.php --phar #{Dir.pwd}/imagine-v#{version}.phar --ns --strip-files '.php$'"
  39. File.unlink("stub.php")
  40. end
  41. task :test do
  42. exitcode = 0
  43. if ENV["TRAVIS"] == 'true'
  44. puts "Travis CI"
  45. system "sudo apt-get install -y imagemagick libtiff-dev libjpeg-dev libdjvulibre-dev libwmf-dev libmagickcore-dev libmagickwand-dev"
  46. system "wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz"
  47. system "tar -xzf imagick-3.1.0RC2.tgz"
  48. system "sh -c \"cd imagick-3.1.0RC2 && phpize && ./configure --with-imagick=/usr/local && make && sudo make install\""
  49. system "sudo apt-get install -y graphicsmagick libgraphicsmagick1-dev"
  50. system "wget http://pecl.php.net/get/gmagick-1.1.0RC3.tgz"
  51. system "tar -xzf gmagick-1.1.0RC3.tgz"
  52. system "sh -c \"cd gmagick-1.1.0RC3 && phpize && ./configure --with-gmagick=/usr/local && make && sudo make install\""
  53. end
  54. ini_file = Hash[`php --ini`.split("\n").map {|l| l.split(/:\s+/)}]["Loaded Configuration File"]
  55. original_ini_contents = File.read(ini_file)
  56. puts "testing with gmagick enabled"
  57. File.open(ini_file, "w") do |f|
  58. f.write(original_ini_contents)
  59. f.write(<<-INI.unindent)
  60. extension=gmagick.so
  61. INI
  62. end
  63. exitcode = 1 unless system "phpunit tests/"
  64. puts "testing with imagick enabled"
  65. File.open(ini_file, "w") do |f|
  66. f.write(original_ini_contents)
  67. f.write(<<-INI.unindent)
  68. extension=imagick.so
  69. INI
  70. end
  71. exitcode = 1 unless system "phpunit tests/"
  72. File.open(ini_file, "w") do |f|
  73. f.write(original_ini_contents)
  74. end
  75. exit exitcode
  76. end
  77. task :clean do
  78. system "git clean -df"
  79. end
  80. task :pear, :version do |t, args|
  81. require 'nokogiri'
  82. Dir.chdir("lib")
  83. version = args[:version]
  84. now = DateTime.now
  85. hash = Digest::MD5.new
  86. xml = Nokogiri::XML::Builder.new do |xml|
  87. xml.package(:packagerversion => "1.8.0", :version => "2.0",
  88. :xmlns => "http://pear.php.net/dtd/package-2.0",
  89. "xmlns:tasks" => "http://pear.php.net/dtd/tasks-1.0",
  90. "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
  91. "xsi:schemaLocation" => [
  92. "http://pear.php.net/dtd/tasks-1.0",
  93. "http://pear.php.net/dtd/tasks-1.0.xsd",
  94. "http://pear.php.net/dtd/package-2.0",
  95. "http://pear.php.net/dtd/package-2.0.xsd"
  96. ].join(" ")) {
  97. xml.name "Imagine"
  98. xml.channel "pear.avalanche123.com"
  99. xml.summary "PHP 5.3 Object Oriented image manipulation library."
  100. xml.description "Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries."
  101. xml.lead {
  102. xml.name "Bulat Shakirzyanov"
  103. xml.user "avalanche123"
  104. xml.email "mallluhuct at gmail.com"
  105. xml.active "yes"
  106. }
  107. xml.date now.strftime('%Y-%m-%d')
  108. xml.time now.strftime('%H:%M:%S')
  109. xml.version {
  110. xml.release version
  111. xml.api version
  112. }
  113. xml.stability {
  114. xml.release "beta"
  115. xml.api "beta"
  116. }
  117. xml.license "MIT", :uri => "http://www.opensource.org/licenses/mit-license.php"
  118. xml.notes "-"
  119. xml.contents {
  120. xml.dir(:name => "/") {
  121. `git ls-files`.split("\n").each { |f|
  122. open(f, "r") do |io|
  123. while (!io.eof)
  124. hash.update(io.readpartial(1024))
  125. end
  126. end
  127. xml.file(:md5sum => hash.hexdigest, :role => "php", :name => f)
  128. }
  129. }
  130. }
  131. xml.dependencies {
  132. xml.required {
  133. xml.php {
  134. xml.min "5.3.2"
  135. }
  136. xml.pearinstaller {
  137. xml.min "1.4.0"
  138. }
  139. }
  140. }
  141. xml.phprelease
  142. }
  143. end
  144. File.open("package.xml", "w") { |f| f.write(xml.to_xml) }
  145. system "pear package"
  146. File.unlink("package.xml")
  147. FileUtils.mv("Imagine-#{version}.tgz", "../")
  148. end
  149. task :sami do
  150. system "bin/sami.php update docs/sami_configuration.php -v"
  151. end
  152. desc "create a new Imagine release - involves "
  153. task :release, :version do |t, args|
  154. version = args[:version]
  155. Rake::Task["test"]
  156. Rake::Task["sami"].invoke
  157. system "git add docs/API"
  158. system "git commit -m \"updated api docs for release #{version}\""
  159. Rake::Task["pear"].invoke(version)
  160. Rake::Task["phar"].invoke(version)
  161. system "git checkout master"
  162. system "git merge develop"
  163. system "git tag v#{version} -m \"release v#{version}\""
  164. system "git push"
  165. system "git push --tags"
  166. end