-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.rb
197 lines (158 loc) · 4.88 KB
/
package.rb
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
# package.rb
# ----------
# by Rennex
require "ftools"
# settings
$destdir = "rudl_packages"
$version = "0.8"
$target_ruby = "1.8.2"
# print warning to fend off mugglers
puts "This will create a RUDL package."
puts "It is only used by developers on the RUDL project."
puts
#--------------
# main program
#--------------
def main
what = ARGV[0]
# if the first argument is "list", only list the files to be zipped
if what =~ /list/i
what = ARGV[1]
$list = true
end
# What shall we package?
case what
when /source|src/i
zipit("source")
when /setup/i
zipit("setup-release")
else
zipit("setup-release")
zipit("source")
end
puts "Done!"
end
# recursively list the contents of the dir, ignoring the
# dir names and dirs named "CVS"
def lsdir(name)
if name
name += "/" unless name =~ /\/$/
name += "**/*"
else
name = "**/*"
end
files = Dir[name]
files.reject! {|f|
File.stat(f).directory? or f =~ %r{(^|/)CVS(/|$)}i
}
return files
end
# helper method to exclude the files that we don't want to include
class Array
def reject_list!(ary)
self.reject! {|f|
# got to use this break trick because "return true" exits the whole method
found = ary.each do |re|
if re.is_a? Regexp
# why does Regexp.new(re, Regexp::IGNORECASE) ignore my flags?
break "exclude" if f.downcase =~ re
else
# compare strings as case-insensitive
break "exclude" if f.downcase == re.downcase
end
end
found == "exclude"
}
end
end
# create either the source or setup archive
def zipit(what)
# which archive are we creating?
case what
when "source"
files =
lsdir("docs") +
lsdir("lib") +
lsdir("include") +
lsdir("samples") +
lsdir("utility") +
Dir["*.{c,h,txt,rb}"] << "configure" << "make.bat"
when /setup/
files =
lsdir("dll") +
lsdir("docs") +
lsdir("samples") +
lsdir("utility") +
Dir["*.txt"] << "RUDL.so" << "install-on-windows.rb"
else
raise "Oh God please no!"
end
files.reject_list! [
/\.(obj|def|exp|pdb)$/,
/^\.\#/, # backups created by (Win)CVS
"makefile",
"mkmf.log",
/^package.*\.rb$/,
$destdir,
/^samples\/work\//,
]
if not $list
Dir.mkdir($destdir) unless File.exists?($destdir)
# creating source package?
if what == "source"
outfile = "rudl-#$version-source.tar"
tempdir2 = "rudl-#$version/"
tempdir = "#$destdir/#{tempdir2}"
puts "Tarring #$destdir/#{outfile}..."
if File.exists?(tempdir)
unless Dir[tempdir + "*"].empty?
puts "Temporary directory #{tempdir} already contains files!"
exit
end
else
Dir.mkdir(tempdir)
end
rem = [] # tempfiles to be deleted afterwards
# copy each file to the tempdir, and log the actions
files.each do |filename|
targetdir = tempdir + File.dirname(filename)
unless File.dirname(filename) == "." or File.exists?(targetdir)
Dir.mkdir(targetdir)
rem << ["dir", targetdir]
end
File.syscopy(filename, tempdir + filename)
rem << ["file", tempdir + filename]
end
olddir = Dir.pwd
Dir.chdir($destdir)
system("tar -cf #{outfile} #{tempdir2}")
puts "GZipping #{outfile}.gz..."
system("gzip -f9 #{outfile}")
Dir.chdir(olddir)
puts "Deleting temporary files..."
rem.reverse.each do |filetype, filename|
if filetype == "dir"
Dir.delete(filename)
else
File.delete(filename)
end
end
Dir.delete(tempdir)
else
if what == "setup-release"
else
raise "not yet implemented"
end
outfile = "#$destdir/rudl-#$version-for-ruby-#$target_ruby-#{what}build.zip"
File.delete(outfile) if File.exists?(outfile)
# zip em up! one at a time, to avoid truncated command lines
puts "Zipping #{outfile}..."
files.each do |filename|
system("zip -9 -q #{outfile} \"#{filename}\"")
end
end
else
puts files
end
end
main