Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 256 lines (208 sloc) 5.975 kb
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
1 #===============================================================================
2 # post-setup.rb - setup documentation
3 #===============================================================================
d9b079a Initial revision
tim authored
4
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
5 EXAMPLES = '.examples'
6 STD_URI = 'http:\/\/www.imagemagick.org'
7 STD_URI_RE = /"#{STD_URI}/
8 DONT_RUN = ['fonts.rb'] # never run these examples
9 ENTITY = Hash['&' => '&amp;', '>' => '&gt;', '<' => '&lt;']
d9b079a Initial revision
tim authored
10
adb1508 Update for use with setup.rb
rmagick authored
11 if defined?(Installer) && self.class == Installer
d9b079a Initial revision
tim authored
12
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
13 RUBYPROG = get_config('ruby-prog')
4d636b1 Replace obsolete 'srcdir' method call with 'curr_srcdir'
rmagick authored
14 SRCDIR = curr_srcdir()
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
15 ALLOW_EXAMPLE_ERRORS = get_config('allow-example-errors') == 'yes'
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
16 BUILD_HTMLDOC = get_config('disable-htmldoc') != 'yes'
d9b079a Initial revision
tim authored
17
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
18 else
d9b079a Initial revision
tim authored
19
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
20 RUBYPROG = 'ruby'
21 SRCDIR = '.'
22 ALLOW_EXAMPLE_ERRORS = true
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
23 BUILD_HTMLDOC = true
d9b079a Initial revision
tim authored
24
25 end
26
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
27
28 #
29 # A set of example programs in a directory and the output image each example produces.
30 #
31
32 class ExampleSet
33 def initialize(of)
34 @status_quo = get_status_quo()
35 @errs = 0
d9b079a Initial revision
tim authored
36 begin
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
37 File.open(EXAMPLES) do |f|
38 @targets = Marshal.load(f)
39 end
40 rescue
41 @targets = Hash.new
42 @n = 0
43 @of = of
44 @first_time = true
45 else
46 @first_time = false
47 end
48 end
49
50 def persist
51 File.open(EXAMPLES, 'w') do |f|
52 Marshal.dump(@targets, f)
53 end
54 end
55
56 def targets(example)
57 @targets[example] || Array.new
58 end
59
60 def get_status_quo
61 sq = Dir["*"]
62 sq.delete_if { |entry| File.directory?(entry) }
63 end
64
65 def update_targets(example, new)
66 t = targets(example) + new
67 @targets[example] = t.uniq
68 end
69
70 def update_status_quo(example)
71 new_status_quo = get_status_quo()
72 new = new_status_quo - @status_quo
73 update_targets(example, new)
74 @status_quo = new_status_quo
75 end
76
77 def build(example)
78 cmd = "#{RUBYPROG} -I #{SRCDIR}/lib -I #{SRCDIR}/ext/RMagick #{example}"
79 print cmd
80 print " (example #{@n += 1} of #{@of})" if @first_time
81 puts
82 system cmd
83
84 if $? != 0 then
85 puts("post-setup.rb: #{example} example returned error code #{$?}")
86 @errs += 1 unless ALLOW_EXAMPLE_ERRORS
87 if @errs > 4
88 err(<<-END_EXFAIL
89 Too many examples failed. The RMagick documentation cannot be installed
90 successfully. Consult the README.txt file and try again, or send email
d495765 Replace personal email address with rmagick at rubyforge.org
rmagick authored
91 to rmagick@rubyforge.org.
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
92 END_EXFAIL
93 )
94 end
95 end
96
97 update_status_quo(example)
98 end
99
100 def update(example)
101 targets = targets(example)
102 up_to_date = ! targets.empty?
103 targets.each do |target|
104 up_to_date &&= File.exists?(target) && (File.stat(target) >= File.stat(example))
d9b079a Initial revision
tim authored
105 end
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
106 build(example) unless up_to_date
107 end
108
8ec3518 Move the `err' method inside the ExampleSet class, where it belongs!
rmagick authored
109 #
110 # print message and exit
111 #
112 def err(msg)
113 $stderr.puts "#{$0}: #{msg}"
20cd61f Return 1 if the examples didn't complete successfully.
rmagick authored
114 exit 1
8ec3518 Move the `err' method inside the ExampleSet class, where it belongs!
rmagick authored
115 end
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
116
d9b079a Initial revision
tim authored
117 end
118
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
119
120 #
121 # Modify file lines via proc. If no lines changed, discard new version.
122 #
123 def filter(filename, backup=nil, &filter)
124 if ! File.writable? filename then
125 raise ArgumentError, "`#{filename}' is write-protected"
126 end
127
128 backup_name = filename + '.' + (backup || 'old')
129 File.rename(filename, backup_name)
130 changed = false
131 begin
132 File.open(filename, 'w') do |output|
133 File.foreach(backup_name) do |line|
134 old = line
135 line = filter.call(line)
136 output.puts(line)
137 changed ||= line != old
138 end
139 end
140 rescue
141 File.rename(backup_name, filename)
142 raise
143 end
144
145 if !changed
146 newname = filename + '.xxx'
147 File.rename(filename, newname)
148 File.rename(backup_name, filename)
149 File.unlink(newname)
150 elsif !backup
151 # Don't remove old copy if a backup extension was specified
152 File.unlink(backup_name) rescue nil
153 end
d9b079a Initial revision
tim authored
154 end
155
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
156
157 #
158 # Copy an example to the doc directory, wrap in HTML tags
159 #
160 def filetoHTML(file, html)
161 return if File.exists?(html) && File.stat(html) >= File.stat(file)
162
163 File.open(file) do |src|
164 File.open(html, 'w') do |dest|
165 dest.puts <<-END_EXHTMLHEAD
f2b76b2 Use new XHTML when generating example script HTML files
rmagick authored
166 <!DOCTYPE public PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
167 <html xmlns="http://www.w3.org/1999/xhtml">
168 <head>
169 <meta name="generator" content="ex2html.rb" />
170 <meta http-equiv="Content-Type" content=
171 "text/html; charset=us-ascii" />
172 <link rel="stylesheet" type="text/css" href="css/popup.css" />
173
174 <title>RMagick example: #{file}</title>
175 </head>
176
177 <body>
178 <h1>#{file}</h1>
179 <div class="bodybox">
180 <div class="bodyfloat">
181 <pre>
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
182 END_EXHTMLHEAD
183
184 src.each do |line|
185 line.gsub!(/[&><]/) { |s| ENTITY[s] }
186 dest.puts(line)
187 end
188
189 dest.puts <<-END_EXHTMLTAIL
f2b76b2 Use new XHTML when generating example script HTML files
rmagick authored
190 </pre>
191 </div>
192 </div>
193 <div id="close"><a href="javascript:window.close();">Close window</a></div>
194 </body>
195 </html>
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
196 END_EXHTMLTAIL
d9b079a Initial revision
tim authored
197 end
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
198 File.chmod(0644, html)
199 end
d9b079a Initial revision
tim authored
200
201 end
202
4d636b1 Replace obsolete 'srcdir' method call with 'curr_srcdir'
rmagick authored
203 puts "setup.rb: entering post-setup phase..."
d9b079a Initial revision
tim authored
204
a8aea27 Add test for CVS sandbox
tim authored
205
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
206 if BUILD_HTMLDOC
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
207
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
208 #
209 # Don't bother if we're in the sandbox
210 #
211 if File.exists? 'CVS/Entries'
212 puts "post-setup.rb: in CVS sandbox - stopping..."
213 exit
214 end
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
215
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
216 puts "post-setup.rb: setting up documentation..."
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
217
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
218 # We're in the source directory. Process the doc in-place. The post-install.rb
219 # script moves the generated documentation to the ultimate installation directories.
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
220
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
221 cwd = Dir.getwd()
222 Dir.chdir('doc') # need to work with 1.6.x, can't use block form
223 begin
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
224
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
225 # Step 1A: edit the shebang line in the examples
226 Dir.chdir('ex')
227 files = Dir['*.rb']
228 files.each do |file|
229 filter(file) { |line| line.sub(/\A\#!\s*\S*ruby\s/, '#!'+RUBYPROG+' ') }
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
230
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
231 # Step 1B: Make a copy of the example as HTML in the doc directory
232 filetoHTML(file, "../#{file}.html")
233 end
234
235 # Step 2: run the examples
236 examples = Dir['*.rb'].sort
237 examples -= DONT_RUN
238 es = ExampleSet.new(examples.length)
239 begin
240 examples.each { |example| es.update(example) }
241 ensure
242 es.persist
243 end
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
244
245 ensure
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
246 Dir.chdir(cwd)
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
247 end
248
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
249 else
250
251 puts "post-setup.rb: --disable-htmldoc specified. No documentation will be set up."
252
e9c83e9 Re-write - don't rebuild things that are up to date.
tim authored
253 end
d9b079a Initial revision
tim authored
254
fcadb74 Support the --disable-htmldoc option to ./configure and setup.rb
rmagick authored
255 exit
Something went wrong with that request. Please try again.