p4ruby 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +5 -8
- data/install.rb +190 -140
- data/p4ruby.gemspec +1 -1
- metadata +3 -3
data/README
CHANGED
@@ -25,16 +25,13 @@ installs it. Some options are available,
|
|
25
25
|
--uninstall Uninstall.
|
26
26
|
--local Use the local files in work/distfiles (for manual download)
|
27
27
|
|
28
|
-
== Download (this installer only)
|
29
|
-
|
30
|
-
* http://rubyforge.org/frs/?group_id=6957
|
31
|
-
|
32
28
|
== Links
|
33
29
|
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
30
|
+
* Download (this installer only): http://rubyforge.org/frs/?group_id=6957
|
31
|
+
* Simplified wrapper for P4Ruby: http://perforce.rubyforge.org
|
32
|
+
* P4Ruby documentation 2008.1: http://perforce.com/perforce/doc.081/manuals/p4script/p4script.pdf
|
33
|
+
* Perforce documentation: http://perforce.com/perforce/technical.html
|
34
|
+
* Repository (this installer only): http://github.com/quix/p4ruby
|
38
35
|
|
39
36
|
== Credits
|
40
37
|
|
data/install.rb
CHANGED
@@ -9,13 +9,42 @@ require 'fileutils'
|
|
9
9
|
require 'optparse'
|
10
10
|
require 'pathname'
|
11
11
|
|
12
|
+
def main
|
13
|
+
Installer.new.run
|
14
|
+
end
|
15
|
+
|
12
16
|
class Installer
|
13
17
|
include FileUtils
|
14
18
|
|
15
19
|
CONFIG = Config::CONFIG
|
20
|
+
BIT64 = (1.size == 8)
|
21
|
+
|
22
|
+
RB_BASENAME = Pathname.new "P4.rb"
|
23
|
+
SO_BASENAME = Pathname.new "P4.#{CONFIG['DLEXT']}"
|
24
|
+
|
25
|
+
RAW_INSTALL_FILES = [
|
26
|
+
Pathname.new(CONFIG["sitelibdir"]) + RB_BASENAME,
|
27
|
+
Pathname.new(CONFIG["sitearchdir"]) + SO_BASENAME,
|
28
|
+
]
|
29
|
+
|
30
|
+
GEM_INSTALL_FILES = [
|
31
|
+
Pathname.new("lib") + RB_BASENAME,
|
32
|
+
Pathname.new("ext") + SO_BASENAME,
|
33
|
+
]
|
34
|
+
|
35
|
+
SERVER = "ftp.perforce.com"
|
36
|
+
SERVER_TOP_DIR = Pathname.new "perforce"
|
37
|
+
|
38
|
+
P4API_REMOTE_BASENAME = Pathname.new "p4api.tgz"
|
39
|
+
P4RUBY_REMOTE_BASENAME = Pathname.new "p4ruby.tgz"
|
40
|
+
|
41
|
+
WORK_DIR = Pathname.new "work"
|
42
|
+
DISTFILES_DIR = WORK_DIR + "distfiles"
|
43
|
+
BUILD_DIR = WORK_DIR + "build"
|
16
44
|
|
17
45
|
def parse_command_line
|
18
|
-
OptionParser.new("Usage: ruby install.rb [options]", 24, "") {
|
46
|
+
OptionParser.new("Usage: ruby install.rb [options]", 24, "") {
|
47
|
+
|parser|
|
19
48
|
parser.on(
|
20
49
|
"--version NN.N",
|
21
50
|
"Version to download, e.g. 08.1. Default finds latest.") {
|
@@ -64,19 +93,18 @@ class Installer
|
|
64
93
|
if @s.uninstall
|
65
94
|
uninstall
|
66
95
|
elsif @s.list_platforms
|
67
|
-
|
96
|
+
puts platforms
|
68
97
|
elsif @s.list_versions
|
69
|
-
|
70
|
-
elsif @s.platform
|
71
|
-
if @s.platform =~ %r!\Ant!
|
72
|
-
windows_install
|
73
|
-
else
|
74
|
-
fetch
|
75
|
-
build
|
76
|
-
unix_install
|
77
|
-
end
|
78
|
-
else
|
98
|
+
puts versions
|
99
|
+
elsif @s.platform.nil?
|
79
100
|
platform_fail
|
101
|
+
elsif @s.platform =~ %r!\Ant!
|
102
|
+
windows_install
|
103
|
+
else
|
104
|
+
fetch
|
105
|
+
build
|
106
|
+
install
|
107
|
+
verify_install
|
80
108
|
end
|
81
109
|
end
|
82
110
|
|
@@ -84,19 +112,19 @@ class Installer
|
|
84
112
|
if CONFIG["LIBRUBYARG_SHARED"].empty?
|
85
113
|
raise "error: ruby must be configured with --enable-shared"
|
86
114
|
end
|
87
|
-
@s.server = "ftp.perforce.com"
|
88
|
-
@s.server_top_dir = Pathname.new "perforce"
|
89
115
|
|
90
|
-
@s.
|
91
|
-
|
92
|
-
|
116
|
+
@s.p4api = LazyStruct.new.tap { |t|
|
117
|
+
t.basename = P4API_REMOTE_BASENAME
|
118
|
+
}
|
119
|
+
|
120
|
+
@s.p4ruby = LazyStruct.new.tap { |t|
|
121
|
+
t.basename = P4RUBY_REMOTE_BASENAME
|
122
|
+
}
|
93
123
|
|
94
|
-
@s.p4api = LazyStruct.new.tap { |t| t.file = Pathname.new "p4api.tgz" }
|
95
|
-
@s.p4ruby = LazyStruct.new.tap { |t| t.file = Pathname.new "p4ruby.tgz" }
|
96
124
|
@s.specs = [ @s.p4ruby, @s.p4api ]
|
97
125
|
@s.specs.each { |spec|
|
98
126
|
spec.attribute(:local) {
|
99
|
-
|
127
|
+
DISTFILES_DIR + spec.basename
|
100
128
|
}
|
101
129
|
}
|
102
130
|
|
@@ -113,29 +141,57 @@ class Installer
|
|
113
141
|
end
|
114
142
|
|
115
143
|
@s.attribute(:version_dir) {
|
116
|
-
|
144
|
+
SERVER_TOP_DIR + "r#{@s.version}"
|
117
145
|
}
|
146
|
+
|
118
147
|
@s.p4api.attribute(:remote) {
|
119
|
-
@s.version_dir + "bin.#{@s.platform}" + @s.p4api.
|
148
|
+
@s.version_dir + "bin.#{@s.platform}" + @s.p4api.basename
|
120
149
|
}
|
121
150
|
@s.p4ruby.attribute(:remote) {
|
122
|
-
@s.version_dir + "tools" + @s.p4ruby.
|
151
|
+
@s.version_dir + "tools" + @s.p4ruby.basename
|
123
152
|
}
|
153
|
+
|
124
154
|
@s.attribute(:ftp) {
|
125
|
-
Net::FTP.new(
|
155
|
+
Net::FTP.new(SERVER).tap { |t|
|
156
|
+
t.passive = true
|
157
|
+
t.login
|
158
|
+
}
|
126
159
|
}
|
127
160
|
end
|
128
161
|
|
129
|
-
def
|
162
|
+
def guess_cpu
|
163
|
+
case CONFIG["target_cpu"]
|
164
|
+
when %r!ia!i
|
165
|
+
"ia64"
|
166
|
+
when %r!86!
|
167
|
+
# note: with '_'
|
168
|
+
"x86" + (BIT64 ? "_64" : "")
|
169
|
+
when %r!(ppc|sparc)!i
|
170
|
+
# note: without '_'
|
171
|
+
$1 + (BIT64 ? "64" : "")
|
172
|
+
else
|
173
|
+
""
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def guess_version(os)
|
130
178
|
if match = `uname -a`.match(%r!#{os}\s+\S+\s+(\d+)\.(\d+)!i)
|
131
|
-
match.captures.join
|
179
|
+
version = match.captures.join
|
180
|
+
cpu = guess_cpu
|
181
|
+
platforms = self.platforms
|
182
|
+
(0..version.to_i).map { |n|
|
183
|
+
[os, n.to_s, cpu].join
|
184
|
+
}.select { |platform|
|
185
|
+
platforms.include? platform
|
186
|
+
}.last
|
187
|
+
else
|
188
|
+
nil
|
132
189
|
end
|
133
190
|
end
|
134
191
|
|
135
192
|
def guess_platform(opts = {})
|
136
193
|
config_os = CONFIG["target_os"].downcase
|
137
|
-
|
138
|
-
windows_cpu = (bit64 ? "x64" : "x86")
|
194
|
+
windows_cpu = BIT64 ? "x64" : "x86"
|
139
195
|
|
140
196
|
if config_os =~ %r!cygwin!i
|
141
197
|
"cygwin" + windows_cpu
|
@@ -144,63 +200,44 @@ class Installer
|
|
144
200
|
elsif @s.local
|
145
201
|
"<local>"
|
146
202
|
else
|
147
|
-
if
|
148
|
-
|
203
|
+
if match = config_os.match(%r!\A\D+!)
|
204
|
+
guess_version(match[0])
|
149
205
|
else
|
150
|
-
|
151
|
-
version = find_os_version(os)
|
152
|
-
if version.nil?
|
153
|
-
nil
|
154
|
-
else
|
155
|
-
cpu =
|
156
|
-
case CONFIG["target_cpu"]
|
157
|
-
when %r!ia!i
|
158
|
-
"ia64"
|
159
|
-
when %r!86!
|
160
|
-
"x86" + (bit64 ? "_64" : "") # note: with '_'
|
161
|
-
when %r!(ppc|sparc)!i
|
162
|
-
$1 + (bit64 ? "64" : "") # note: without '_'
|
163
|
-
else
|
164
|
-
""
|
165
|
-
end
|
166
|
-
|
167
|
-
available_platforms = platforms
|
168
|
-
platform = nil
|
169
|
-
version.to_i.downto(0) { |n|
|
170
|
-
platform = [os, n.to_s, cpu].join
|
171
|
-
if available_platforms.include? platform
|
172
|
-
break
|
173
|
-
end
|
174
|
-
}
|
175
|
-
platform
|
176
|
-
end
|
206
|
+
nil
|
177
207
|
end
|
178
208
|
end
|
179
209
|
end
|
180
210
|
|
181
211
|
def platform_fail
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
212
|
+
install_fail {
|
213
|
+
@s.version = "<version>"
|
214
|
+
@s.platform = "<platform>"
|
215
|
+
message = %Q{
|
216
|
+
Auto-fetch not yet handled for this platform. Run:
|
217
|
+
|
218
|
+
\truby install.rb --list-platforms
|
219
|
+
|
220
|
+
to see the available platforms, then run
|
221
|
+
|
222
|
+
\truby install.rb --platform PLATFORM
|
223
|
+
|
224
|
+
with your platform.
|
225
|
+
|
226
|
+
If all of the above fails, manually fetch
|
227
|
+
|
228
|
+
\tftp://#{SERVER}/#{@s.p4api.remote}
|
229
|
+
|
230
|
+
Copy it to #{@s.p4api.local} and run install.rb --local.
|
231
|
+
}.gsub(%r!^ +(?=\S)!, "")
|
198
232
|
|
199
|
-
|
200
|
-
|
233
|
+
mkdir_p(DISTFILES_DIR)
|
234
|
+
puts message
|
235
|
+
}
|
236
|
+
end
|
201
237
|
|
202
|
-
|
203
|
-
|
238
|
+
def install_fail
|
239
|
+
yield
|
240
|
+
exit(1)
|
204
241
|
end
|
205
242
|
|
206
243
|
def sys(*args)
|
@@ -217,8 +254,8 @@ class Installer
|
|
217
254
|
|
218
255
|
def fetch_spec(spec)
|
219
256
|
unless @s.local
|
220
|
-
mkdir_p(
|
221
|
-
puts "downloading ftp://#{
|
257
|
+
mkdir_p(spec.local.dirname)
|
258
|
+
puts "downloading ftp://#{SERVER}/#{spec.remote} ..."
|
222
259
|
@s.ftp.getbinaryfile(spec.remote, spec.local)
|
223
260
|
end
|
224
261
|
end
|
@@ -250,23 +287,11 @@ class Installer
|
|
250
287
|
end
|
251
288
|
|
252
289
|
def versions
|
253
|
-
remote_files_matching(
|
290
|
+
remote_files_matching(SERVER_TOP_DIR, %r!r([0-8]\d\.\d)!) { |match|
|
254
291
|
match.captures.first
|
255
292
|
}.sort
|
256
293
|
end
|
257
294
|
|
258
|
-
def list_platforms
|
259
|
-
platforms.each { |platform|
|
260
|
-
puts platform
|
261
|
-
}
|
262
|
-
end
|
263
|
-
|
264
|
-
def list_versions
|
265
|
-
versions.each { |version|
|
266
|
-
puts version
|
267
|
-
}
|
268
|
-
end
|
269
|
-
|
270
295
|
def latest_version
|
271
296
|
versions.last
|
272
297
|
end
|
@@ -276,79 +301,105 @@ class Installer
|
|
276
301
|
end
|
277
302
|
|
278
303
|
def ruby(*args)
|
279
|
-
exe =
|
280
|
-
CONFIG["bindir"],
|
281
|
-
CONFIG["RUBY_INSTALL_NAME"])
|
304
|
+
exe = Pathname.new(CONFIG["bindir"]) + CONFIG["RUBY_INSTALL_NAME"]
|
282
305
|
sys(exe, *args)
|
283
306
|
end
|
284
307
|
|
285
308
|
def build
|
286
|
-
rm_rf(
|
287
|
-
mkdir_p(
|
309
|
+
rm_rf(BUILD_DIR)
|
310
|
+
mkdir_p(BUILD_DIR)
|
288
311
|
|
289
312
|
@s.specs.each { |spec|
|
290
|
-
unpack(spec.local,
|
313
|
+
unpack(spec.local, BUILD_DIR)
|
291
314
|
}
|
292
315
|
|
293
|
-
Dir.chdir(
|
316
|
+
Dir.chdir(BUILD_DIR) {
|
294
317
|
api_dir = Pathname.glob("p4api*").last
|
295
318
|
p4ruby_dir = Pathname.glob("p4ruby*").last
|
296
319
|
Dir.chdir(p4ruby_dir) {
|
297
320
|
ruby("p4conf.rb", "--apidir", "../#{api_dir}")
|
298
321
|
make
|
299
322
|
}
|
300
|
-
@s.p4ruby_build_dir =
|
323
|
+
@s.p4ruby_build_dir = BUILD_DIR + p4ruby_dir
|
301
324
|
}
|
302
325
|
end
|
303
326
|
|
304
|
-
def
|
327
|
+
def raw_install_to_gem_install
|
328
|
+
RAW_INSTALL_FILES.each_with_index { |source, index|
|
329
|
+
dest = GEM_INSTALL_FILES[index]
|
330
|
+
mkdir_p(dest.dirname)
|
331
|
+
puts "move #{source} --> #{dest}"
|
332
|
+
mv(source, dest)
|
333
|
+
}
|
334
|
+
end
|
335
|
+
|
336
|
+
def install
|
337
|
+
Dir.chdir(@s.p4ruby_build_dir) {
|
338
|
+
make("install")
|
339
|
+
}
|
305
340
|
if @s.gem_config
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
341
|
+
raw_install_to_gem_install
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def verify_install(on_error = nil)
|
346
|
+
files =
|
347
|
+
if @s.gem_config
|
348
|
+
GEM_INSTALL_FILES
|
349
|
+
else
|
350
|
+
RAW_INSTALL_FILES
|
351
|
+
end.map { |t| t.expand_path }
|
352
|
+
|
353
|
+
if files.all? { |t| t.exist? }
|
354
|
+
puts "Installed files:"
|
355
|
+
puts files
|
356
|
+
elsif on_error
|
357
|
+
install_fail(&on_error)
|
316
358
|
else
|
317
|
-
|
318
|
-
|
359
|
+
install_fail {
|
360
|
+
puts "These files were supposed to be installed, but were not:"
|
361
|
+
puts files
|
362
|
+
puts "Install failed!"
|
319
363
|
}
|
320
364
|
end
|
321
365
|
end
|
322
366
|
|
323
367
|
def windows_install
|
324
368
|
#
|
325
|
-
# p4ruby is
|
326
|
-
# -- switcharoo --
|
369
|
+
# For Windows, p4ruby is located in the p4api directory on the
|
370
|
+
# perforce server -- switcharoo --
|
327
371
|
#
|
328
372
|
spec = @s.p4api
|
329
373
|
|
330
374
|
version = [CONFIG["MAJOR"], CONFIG["MINOR"]].join
|
331
|
-
spec.
|
375
|
+
spec.basename = "p4ruby#{version}.exe"
|
332
376
|
fetch_spec(spec)
|
333
377
|
|
378
|
+
error = lambda {
|
379
|
+
puts "The Perforce Windows P4Ruby installer failed!"
|
380
|
+
puts "Re-run it manually here: "
|
381
|
+
puts spec.local.expand_path
|
382
|
+
}
|
383
|
+
|
334
384
|
if system(spec.local, "/S", "/v/qn")
|
335
|
-
|
336
|
-
|
385
|
+
if @s.gem_config
|
386
|
+
sleep(1)
|
387
|
+
raw_install_to_gem_install
|
388
|
+
sleep(1)
|
389
|
+
unless system(spec.local, "/V", "/x", "/S", "/v/qn")
|
390
|
+
# We don't much care if this fails; just write to the log
|
391
|
+
puts "Note: the Perforce Windows P4Ruby uninstaller failed."
|
392
|
+
end
|
393
|
+
end
|
394
|
+
verify_install(error)
|
337
395
|
else
|
338
|
-
|
339
|
-
puts "**** Re-run it manually here: "
|
340
|
-
puts File.expand_path(spec.local)
|
396
|
+
install_fail(&error)
|
341
397
|
end
|
342
398
|
end
|
343
399
|
|
344
|
-
def installed_p4ruby_files
|
345
|
-
[ Pathname.new(CONFIG["sitelibdir"]) + "P4.rb" ] +
|
346
|
-
Pathname.glob(Pathname.new(CONFIG["sitearchdir"]) + "P4.*")
|
347
|
-
end
|
348
|
-
|
349
400
|
def uninstall
|
350
|
-
|
351
|
-
if
|
401
|
+
RAW_INSTALL_FILES.each { |file|
|
402
|
+
if file.exist?
|
352
403
|
puts "delete #{file}"
|
353
404
|
rm_f(file)
|
354
405
|
end
|
@@ -356,16 +407,6 @@ class Installer
|
|
356
407
|
end
|
357
408
|
end
|
358
409
|
|
359
|
-
# version < 1.8.7 compatibility
|
360
|
-
module Kernel
|
361
|
-
unless respond_to? :tap
|
362
|
-
def tap
|
363
|
-
yield self
|
364
|
-
self
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
410
|
#
|
370
411
|
# An OpenStruct with optional lazy-evaluated fields.
|
371
412
|
#
|
@@ -416,5 +457,14 @@ class LazyStruct < OpenStruct
|
|
416
457
|
include Mixin
|
417
458
|
end
|
418
459
|
|
419
|
-
|
420
|
-
|
460
|
+
# version < 1.8.7 compatibility
|
461
|
+
module Kernel
|
462
|
+
unless respond_to? :tap
|
463
|
+
def tap
|
464
|
+
yield self
|
465
|
+
self
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
main
|
data/p4ruby.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: p4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perforce Software (ruby gem by James M. Lawrence)
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-04 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
requirements: []
|
57
57
|
|
58
58
|
rubyforge_project: p4ruby
|
59
|
-
rubygems_version: 1.
|
59
|
+
rubygems_version: 1.3.0
|
60
60
|
signing_key:
|
61
61
|
specification_version: 2
|
62
62
|
summary: Ruby interface to the Perforce API
|