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