forked from speedata/publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
397 lines (356 loc) · 11.9 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
require "pathname"
require 'rake/clean'
CLEAN.include("publisher.pdf","publisher.log","publisher.protocol","publisher.vars")
CLOBBER.include("build/sourcedoc","src/go/sp/sp","src/go/sp/docgo", "src/go/sp/bin","src/go/sp/pkg")
installdir = Pathname.new(__FILE__).join("..")
srcdir = installdir.join("src")
builddir = installdir.join("build")
@versions = {}
File.read("version").each_line do |line|
product,versionnumber = line.chomp.split(/=/) # / <-- ignore this slash
@versions[product]=versionnumber
end
ENV['GOPATH'] = "#{srcdir}/go"
def build_go(srcdir,destbin,goos,goarch,targettype)
if goarch
ENV['GOARCH'] = goarch
end
if goos
ENV['GOOS'] = goos
end
publisher_version = @versions['publisher_version']
binaryname = goos == "windows" ? "sp.exe" : "sp"
# Now compile the go executable
cmdline = "go build -ldflags '-X main.dest=#{targettype} -X main.version=#{publisher_version}' -o #{destbin}/#{binaryname} sp/main"
sh cmdline do |ok, res|
if ! ok
puts "Go compilation failed"
return false
end
end
return true
end
desc "Build sphelper program"
task :sphelper do
ENV["GOBIN"] = "#{installdir}/bin"
sh "go install -ldflags \"-X main.basedir=#{installdir}\" sphelper/sphelper"
end
desc "Show rake description"
task :default do
puts
puts "Run 'rake -T' for a list of tasks."
puts
puts "1: Use 'rake build' to build the 'sp' binary. That should be\n the starting point."
puts "2: Then try to build the documentation by running 'rake doc'\n followed by 'sp doc' to read the documentation."
puts
end
desc "Compile and install necessary software"
task :build => [:sphelper] do
sh "#{installdir}/bin/sphelper build"
end
desc "Generate documentation"
task :doc => [:sphelper] do
sh "#{installdir}/bin/sphelper doc"
puts "done"
end
desc "Update the examples in the documentation"
task :updateexamples do
Dir.chdir(installdir.join("doc","manual")) do
Dir.glob('doc/examples-*/**').select { |f| File.directory? f}.each do |dir|
puts "Update example in #{dir}"
Dir.chdir(dir) do
`sp`
`sp clean`
`convert publisher.pdf[0] -thumbnail 240 thumbnail.png`
end
end
end
end
desc "Generate schema and translations from master"
task :schema => [:sphelper] do
# generate the lua translation + schema
sh "#{installdir}/bin/sphelper genschema"
end
desc "Source documentation"
task :sourcedoc => [:sphelper] do
sh "#{installdir}/bin/sphelper sourcedoc"
if RUBY_PLATFORM =~ /darwin/
sh "open #{builddir}/sourcedoc/publisher.html"
else
puts "Generated source documentation in \n#{builddir}/sourcedoc/publisher.html"
end
end
desc "Update program messages"
task :messages do
lang = "de_DE"
Dir.chdir(srcdir) do
srcfiles = Dir.glob("lua/**/*.lua")
# xgettext creates the pot file
sh 'xgettext --from-code="UTF-8" -k"log" -k"err" -k"warning" -s -o po/publisher.pot ' + srcfiles.join(" ")
# msgmerge moves new messages to the po file
sh "msgmerge -s -U po/#{lang}.po po/publisher.pot"
# msgfmt creates the mo file
sh "msgfmt -c -v -o po/#{lang}.mo po/#{lang}.po"
end
end
desc "New language for program messages"
task :newmsglang, :lang do |t,args|
unless args[:lang]
raise "No language given. Use rake newmsglang[de_DE] to create a new language template."
end
Dir.chdir(srcdir) do
lang = args[:lang]
srcfiles = Dir.glob("lua/**/*.lua")
sh 'xgettext --from-code="UTF-8" -k"log" -k"err" -k"warning" -s -o po/publisher.pot ' + srcfiles.join(" ")
sh "msginit -l #{lang} -o po/#{lang}.po -i po/publisher.pot"
end
end
desc "Update gh-pages"
task :ghpages => [:sphelper] do
sh "#{installdir}/bin/sphelper doc"
cp_r "#{builddir}/manual","webpage"
sh "#{installdir}/bin/sphelper dashdoc"
IO.write("webpage/speedata_Publisher_(en).xml","<entry>\n <version>#{@versions['publisher_version']}</version>\n <url>https://download.speedata.de/publisher/dashdoc/speedatapublisher-en.tgz</url>\n</entry>\n")
IO.write("webpage/speedata_Publisher_(de).xml","<entry>\n <version>#{@versions['publisher_version']}</version>\n <url>https://download.speedata.de/publisher/dashdoc/speedatapublisher-de.tgz</url>\n</entry>\n")
end
task :mkdashzip => [:sphelper] do
sh "#{installdir}/bin/sphelper doc"
cp_r "#{builddir}/manual","webpage"
sh "#{installdir}/bin/sphelper dashdoc"
Dir.chdir(builddir) do
sh "tar --exclude='.DS_Store' -czf ../webpage/speedatapublisher-de.tgz speedatapublisher-de.docset"
sh "tar --exclude='.DS_Store' -czf ../webpage/speedatapublisher-en.tgz speedatapublisher-en.docset"
end
end
# For now: only a small test
desc "Test source code"
task :test do
ENV["LUA_PATH"] = "#{srcdir}/lua/?.lua;#{installdir}/lib/?.lua;#{installdir}/test/?.lua"
ENV["PUBLISHER_BASE_PATH"] = installdir.to_s
inifile = srcdir.join("sdini.lua")
sh "texlua --lua=#{inifile} #{installdir}/bin/luatest tc_xpath.lua"
end
desc "Run quality assurance"
task :qa do
sh "#{installdir}/bin/sp compare #{installdir}/qa"
end
desc "Clean QA intermediate files"
task :cleanqa do
FileUtils.rm Dir.glob("qa/**/pagediff-*.png")
FileUtils.rm Dir.glob("qa/**/reference-*.png")
FileUtils.rm Dir.glob("qa/**/source-*.png")
FileUtils.rm Dir.glob("qa/**/publisher.vars")
FileUtils.rm Dir.glob("qa/**/publisher.status")
FileUtils.rm Dir.glob("qa/**/publisher.protocol")
FileUtils.rm Dir.glob("qa/**/publisher.pdf")
end
# The environment variable LUATEX_BIN must point to a directory with the following structure
# ├── darwin
# │ ├── amd64
# │ └── 386
# ├── linux
# │ ├── amd64
# │ └── 386
# └── windows
# ├── amd64
# └── 386
#
# and each of these amd64/386 directories look like this:
# ├── 0_79_1
# │ ├── kpathsea620w64.dll
# │ ├── lua52w64.dll
# │ ├── luatex.dll
# │ ├── luatex.exe
# │ └── msvcr100.dll
# └── default -> 0_79_1/
#
# The task looks for a directory named "default" and uses the binary files in that directory
desc "Make ZIP files for all platforms and installer for windows"
task :dist => [:sphelper] do
sh "#{installdir}/bin/sphelper dist windows/amd64 windows/386 linux/amd64 linux/386 darwin/amd64 darwin/386"
end
desc "Make ZIP files - set NODOC=true for stripped zip file"
task :zip => [:sphelper] do
srcbindir = ENV["LUATEX_BIN"] || ""
if ! test(?d,srcbindir) then
puts "Environment variable LUATEX_BIN does not exist.\nMake sure it points to a path which contains `luatex'.\nUse like this: rake zip LUATEX_BIN=/path/to/bin\nAborting"
next
end
publisher_version = @versions['publisher_version']
dest="#{builddir}/speedata-publisher"
targetbin="#{dest}/bin"
targetshare="#{dest}/share"
targetsw=File.join(dest,"sw")
targetfonts=File.join(targetsw,"fonts")
targetschema=File.join(targetshare,"schema")
rm_rf dest
mkdir_p dest
mkdir_p targetbin
mkdir_p File.join(targetsw,"img")
mkdir_p targetschema
mkdir_p targetsw
if ENV['NODOC'] != "true" then
Rake::Task["doc"].execute
cp_r "#{builddir}/manual",File.join(targetshare,"doc")
end
platform = nil
arch = nil
execfilename = "sdluatex"
if test(?f, srcbindir +"/sdluatex") then
cp_r(srcbindir +"/sdluatex",targetbin)
elsif test(?f,srcbindir +"/luatex.exe") then
cp_r(Dir.glob(srcbindir +"/*") ,targetbin)
File.open(targetbin + "/texmf.cnf", "w") { |file| file.write("#dummy\n") }
platform = "windows"
execfilename = "luatex.exe"
elsif test(?f,srcbindir +"/sdluatex.exe") then
cp_r(Dir.glob(srcbindir +"/*") ,targetbin)
File.open(targetbin + "/texmf.cnf", "w") { |file| file.write("#dummy\n") }
platform = "windows"
execfilename = "sdluatex.exe"
elsif test(?f,srcbindir +"/luatex") then
cp_r(srcbindir +"/luatex","#{targetbin}/sdluatex")
end
cmd = "file #{targetbin}/#{execfilename}"
res = `#{cmd}`.gsub(/^.*luatex.*:/,'')
case res
when /Mach-O/
platform = "darwin"
when /Linux/
platform = "linux"
end
case res
when /x86-64/,/x86_64/,/64-bit/,/PE32\+/
arch = "amd64"
when /32-bit/,/80386/,/i386/
arch = "386"
end
if !platform or !arch then
puts "Could not determine architecture (amd64/386) or platform (windows/linux/darwin)"
puts "This is the output of 'file':"
puts res
next
end
zipname = "speedata-publisher-#{platform}-#{arch}-#{publisher_version}.zip"
rm_rf File.join(builddir,zipname)
if build_go(srcdir,targetbin,platform,arch,"directory") == false then next end
cp_r(File.join("fonts"),targetfonts)
cp_r(Dir.glob("img/*"),File.join(targetsw,"img"))
cp_r(File.join("lib"),targetshare)
cp_r(File.join("schema","layoutschema-de.rng"),targetschema)
cp_r(File.join("schema","layoutschema-en.rng"),targetschema)
Dir.chdir("src") do
cp_r(["tex","hyphenation"],targetsw)
# do not copy every Lua file to the dest
# and leave out .gitignore and others
Dir.glob("**/*.lua").reject { |x|
x =~ /viznode|fileutils/
}.each { |x|
FileUtils.mkdir_p(File.join(targetsw , File.dirname(x)))
FileUtils.cp(x,File.join(targetsw,File.dirname(x)))
}
end
sh "#{installdir}/bin/sphelper mkreadme #{platform} #{dest}"
dirname = "speedata-publisher"
cmdline = "zip -rq #{zipname} #{dirname}"
Dir.chdir("build") do
puts cmdline
puts `#{cmdline}`
end
end
desc "Prepare a .deb directory"
task :deb => [:sphelper] do
srcbindir = ENV["LUATEX_BIN"] || ""
if ! test(?d,srcbindir) then
puts "Environment variable LUATEX_BIN does not exist.\nMake sure it points to a path which contains `luatex'.\nUse like this: rake zip LUATEX_BIN=/path/to/bin\nAborting"
next
end
publisher_version = @versions['publisher_version']
destdir = builddir.join("deb")
targetbin = destdir.join("usr","bin")
targetdoc = destdir.join("usr","share","doc","speedata-publisher")
targetshare = destdir.join("usr","share")
targetfonts = targetshare.join("speedata-publisher", "fonts")
targetimg = targetshare.join("speedata-publisher", "img")
targetlib = targetshare.join("speedata-publisher", "lib")
targetschema = targetshare.join("speedata-publisher", "schema")
targetsw = targetshare.join("speedata-publisher", "sw")
rm_rf destdir
Rake::Task["doc"].execute
mkdir_p targetbin
mkdir_p targetdoc
mkdir_p targetfonts
mkdir_p targetimg
mkdir_p targetlib
mkdir_p targetschema
mkdir_p targetsw
cp_r "#{builddir}/manual/.",targetdoc
platform = nil
arch = nil
execfilename = "sdluatex"
if test(?f, srcbindir +"/sdluatex") then
cp_r(srcbindir +"/sdluatex",targetbin)
else
puts "copying failed, #{srcbindir}"
next
end
cmd = "file #{targetbin}/#{execfilename}"
res = `#{cmd}`.gsub(/^.*luatex.*:/,'')
case res
when /Linux/
platform = "linux"
end
case res
when /x86-64/,/x86_64/,/64-bit/
arch = "amd64"
debarch = arch
when /32-bit/,/80386/,/i386/
arch = "386"
debarch = "i386"
end
if platform != "linux" then
puts "platform is not linux"
next
end
if !arch then
puts "Could not determine architecture (amd64/386)"
puts "This is the output of 'file':"
puts res
next
end
if build_go(srcdir,targetbin,platform,arch,"linux-usr") == false then next end
cp_r("fonts/.",targetfonts)
cp_r(Dir.glob("img/*"),targetimg)
cp_r("lib/.",targetlib)
cp_r(File.join("schema","layoutschema-de.rng"),targetschema)
cp_r(File.join("schema","layoutschema-en.rng"),targetschema)
Dir.chdir("src") do
cp_r(["tex","hyphenation"],targetsw)
# do not copy every Lua file to the dest
# and leave out .gitignore and others
Dir.glob("**/*.lua").reject { |x|
x =~ /viznode|fileutils/
}.each { |x|
mkdir_p(targetsw.join(File.dirname(x)))
cp(x,targetsw.join(File.dirname(x)))
}
end
# control-file
mkdir_p destdir.join("DEBIAN")
size = `du -ks #{destdir}/usr | cut -f 1`.chomp
File.open(destdir.join("DEBIAN","control"), "w") do |f|
f << %Q{Package: speedata-publisher
Version: #{publisher_version}
Section: text
Priority: optional
Architecture: #{debarch}
Installed-Size: #{size}
Maintainer: speedata <[email protected]>
Description: speedata publisher
}.gsub(/^ /,"")
end # file.open
end
desc "Show the version number"
task :publisherversion do
puts @versions['publisher_version']
end