p4ruby 2014.2.0.pre3-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +24 -0
- data/ext/P4/clientprogressruby.cpp +99 -0
- data/ext/P4/clientprogressruby.h +52 -0
- data/ext/P4/clientuserruby.cpp +726 -0
- data/ext/P4/clientuserruby.h +133 -0
- data/ext/P4/extconf.rb +546 -0
- data/ext/P4/gc_hack.h +10 -0
- data/ext/P4/p4.cpp +1338 -0
- data/ext/P4/p4clientapi.cpp +724 -0
- data/ext/P4/p4clientapi.h +239 -0
- data/ext/P4/p4error.cpp +122 -0
- data/ext/P4/p4error.h +61 -0
- data/ext/P4/p4mapmaker.cpp +459 -0
- data/ext/P4/p4mapmaker.h +69 -0
- data/ext/P4/p4mergedata.cpp +272 -0
- data/ext/P4/p4mergedata.h +97 -0
- data/ext/P4/p4result.cpp +259 -0
- data/ext/P4/p4result.h +86 -0
- data/ext/P4/p4rubydebug.h +45 -0
- data/ext/P4/p4specdata.cpp +108 -0
- data/ext/P4/p4specdata.h +52 -0
- data/ext/P4/p4utils.cpp +62 -0
- data/ext/P4/p4utils.h +46 -0
- data/ext/P4/specmgr.cpp +687 -0
- data/ext/P4/specmgr.h +102 -0
- data/ext/P4/undefdups.h +64 -0
- data/lib/1.9/P4.so +0 -0
- data/lib/2.0/P4.so +0 -0
- data/lib/2.1/P4.so +0 -0
- data/lib/2.2/P4.so +0 -0
- data/lib/P4.rb +672 -0
- data/lib/P4.so +0 -0
- data/lib/P4/version.rb +3 -0
- data/p4-doc/user/p4rubynotes.txt +789 -0
- metadata +77 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
|
3
|
+
Copyright (c) 2001-2008, Perforce Software, Inc. All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
1. Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
+
ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
26
|
+
*******************************************************************************/
|
27
|
+
|
28
|
+
/*******************************************************************************
|
29
|
+
* Name : clientuserruby.h
|
30
|
+
*
|
31
|
+
* Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
|
32
|
+
*
|
33
|
+
* Description : Ruby bindings for the Perforce API. User interface class
|
34
|
+
* for getting Perforce results into Ruby.
|
35
|
+
*
|
36
|
+
******************************************************************************/
|
37
|
+
|
38
|
+
/*******************************************************************************
|
39
|
+
* ClientUserRuby - the user interface part. Gets responses from the Perforce
|
40
|
+
* server, and converts the data to Ruby form for returning to the caller.
|
41
|
+
******************************************************************************/
|
42
|
+
class SpecMgr;
|
43
|
+
class ClientProgress;
|
44
|
+
|
45
|
+
class ClientUserRuby: public ClientUser, public KeepAlive {
|
46
|
+
public:
|
47
|
+
ClientUserRuby(SpecMgr *s);
|
48
|
+
|
49
|
+
// Client User methods overridden here
|
50
|
+
void OutputText(const char *data, int length);
|
51
|
+
void Message(Error *e);
|
52
|
+
void OutputStat(StrDict *values);
|
53
|
+
void OutputBinary(const char *data, int length);
|
54
|
+
void InputData(StrBuf *strbuf, Error *e);
|
55
|
+
void Diff(FileSys *f1, FileSys *f2, int doPage, char *diffFlags, Error *e);
|
56
|
+
void Prompt(const StrPtr &msg, StrBuf &rsp, int noEcho, Error *e);
|
57
|
+
|
58
|
+
int Resolve(ClientMerge *m, Error *e);
|
59
|
+
int Resolve(ClientResolveA *m, int preview, Error *e);
|
60
|
+
|
61
|
+
ClientProgress* CreateProgress( int type );
|
62
|
+
int ProgressIndicator();
|
63
|
+
|
64
|
+
void Finished();
|
65
|
+
|
66
|
+
// Local methods
|
67
|
+
VALUE SetInput(VALUE i);
|
68
|
+
void SetCommand(const char *c) {
|
69
|
+
cmd = c;
|
70
|
+
}
|
71
|
+
void SetApiLevel(int l);
|
72
|
+
void SetTrack(bool t) {
|
73
|
+
track = t;
|
74
|
+
}
|
75
|
+
|
76
|
+
P4Result& GetResults() {
|
77
|
+
return results;
|
78
|
+
}
|
79
|
+
int ErrorCount();
|
80
|
+
void Reset();
|
81
|
+
|
82
|
+
void RaiseRubyException();
|
83
|
+
|
84
|
+
// GC support
|
85
|
+
void GCMark();
|
86
|
+
|
87
|
+
// Debugging support
|
88
|
+
void SetDebug(int d) {
|
89
|
+
debug = d;
|
90
|
+
}
|
91
|
+
|
92
|
+
// Handler support
|
93
|
+
VALUE SetHandler(VALUE handler);
|
94
|
+
VALUE GetHandler() {
|
95
|
+
return handler;
|
96
|
+
}
|
97
|
+
|
98
|
+
// Progress API support
|
99
|
+
VALUE SetProgress( VALUE p );
|
100
|
+
VALUE GetProgress() {
|
101
|
+
return progress;
|
102
|
+
}
|
103
|
+
|
104
|
+
// override from KeepAlive
|
105
|
+
virtual int IsAlive() {
|
106
|
+
return alive;
|
107
|
+
}
|
108
|
+
|
109
|
+
private:
|
110
|
+
VALUE MkMergeInfo(ClientMerge *m, StrPtr &hint);
|
111
|
+
VALUE MkActionMergeInfo(ClientResolveA *m, StrPtr &hint);
|
112
|
+
void ProcessOutput(const char * method, VALUE data);
|
113
|
+
void ProcessMessage(Error * e);
|
114
|
+
bool CallOutputMethod(const char * method, VALUE data);
|
115
|
+
|
116
|
+
private:
|
117
|
+
StrBuf cmd;
|
118
|
+
SpecMgr * specMgr;
|
119
|
+
P4Result results;
|
120
|
+
VALUE input;
|
121
|
+
VALUE mergeData;
|
122
|
+
VALUE mergeResult;
|
123
|
+
VALUE handler;
|
124
|
+
VALUE cOutputHandler;
|
125
|
+
VALUE progress;
|
126
|
+
VALUE cProgress;
|
127
|
+
int debug;
|
128
|
+
int apiLevel;
|
129
|
+
int alive;
|
130
|
+
int rubyExcept;
|
131
|
+
bool track;
|
132
|
+
};
|
133
|
+
|
data/ext/P4/extconf.rb
ADDED
@@ -0,0 +1,546 @@
|
|
1
|
+
# File: extconf.rb
|
2
|
+
|
3
|
+
$:.push File.expand_path("../../../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'mkmf'
|
6
|
+
require 'net/ftp'
|
7
|
+
require 'P4/version'
|
8
|
+
require 'rbconfig'
|
9
|
+
|
10
|
+
#==============================================================================
|
11
|
+
# Provide platform variables in P4-specific format
|
12
|
+
|
13
|
+
def p4osplat
|
14
|
+
@p4osplat ||= calculate_p4osplat
|
15
|
+
end
|
16
|
+
|
17
|
+
def calculate_p4osplat
|
18
|
+
plat = RbConfig::CONFIG['arch'].split(/-/)[0].upcase
|
19
|
+
|
20
|
+
# On Mac OSX, fix the build to 64 bit arch
|
21
|
+
if p4osname == 'DARWIN'
|
22
|
+
plat = 'X86_64'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Translate Ruby's arch names into Perforce's. Mostly the same so
|
26
|
+
# only the exceptions are handled here.
|
27
|
+
case plat
|
28
|
+
when /^I.86$/
|
29
|
+
plat = 'X86'
|
30
|
+
when /^AMD64$/
|
31
|
+
plat = 'X86_64'
|
32
|
+
when 'POWERPC'
|
33
|
+
plat = 'PPC'
|
34
|
+
end
|
35
|
+
|
36
|
+
return plat
|
37
|
+
end
|
38
|
+
|
39
|
+
def p4osname
|
40
|
+
@p4osname ||= calculate_p4osname
|
41
|
+
end
|
42
|
+
|
43
|
+
def calculate_p4osname
|
44
|
+
osname = RbConfig::CONFIG['arch'].split(/-/)[1].upcase
|
45
|
+
osname = osname.gsub(/MSWIN32(_\d+)?/, "NT")
|
46
|
+
osname = osname.split('-').shift
|
47
|
+
|
48
|
+
case osname
|
49
|
+
when /FREEBSD/
|
50
|
+
osname = 'FREEBSD'
|
51
|
+
when /DARWIN/
|
52
|
+
osname = 'DARWIN'
|
53
|
+
when /AIX/
|
54
|
+
osname = 'AIX'
|
55
|
+
when /SOLARIS/
|
56
|
+
osname = 'SOLARIS'
|
57
|
+
end
|
58
|
+
|
59
|
+
return osname
|
60
|
+
end
|
61
|
+
|
62
|
+
def p4osver
|
63
|
+
@p4osver ||= calculate_p4osver
|
64
|
+
end
|
65
|
+
|
66
|
+
def calculate_p4osver
|
67
|
+
ver = ''
|
68
|
+
|
69
|
+
case p4osname
|
70
|
+
when 'NT'
|
71
|
+
# do nothing
|
72
|
+
when /MINGW/
|
73
|
+
# do nothing
|
74
|
+
when /FREEBSD([0-9]+)/
|
75
|
+
ver = $1
|
76
|
+
when /DARWIN/
|
77
|
+
ver = CONFIG['arch'].upcase.gsub(/.*DARWIN(\d+).*/, '\1')
|
78
|
+
when /AIX(5)\.(\d)/
|
79
|
+
ver = $1 + $2
|
80
|
+
when /SOLARIS2\.(\d+)/
|
81
|
+
ver = $1
|
82
|
+
else
|
83
|
+
# use uname -r to see if it works
|
84
|
+
begin
|
85
|
+
ver=`uname -r`.chomp
|
86
|
+
ver_re = /^(\d+)\.(\d+)/
|
87
|
+
md = ver_re.match(ver)
|
88
|
+
if (md)
|
89
|
+
maj = md[1].to_i
|
90
|
+
min = md[2].to_i
|
91
|
+
ver = maj.to_s + min.to_s
|
92
|
+
end
|
93
|
+
rescue
|
94
|
+
# Nothing - if it failed, it failed.
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
return ver
|
99
|
+
end
|
100
|
+
|
101
|
+
def uname_platform
|
102
|
+
@uname_platform ||= calculate_uname_platform
|
103
|
+
end
|
104
|
+
|
105
|
+
def calculate_uname_platform
|
106
|
+
plat = "UNKNOWN"
|
107
|
+
begin
|
108
|
+
plat = `uname -p`
|
109
|
+
plat = plat.chomp.upcase
|
110
|
+
rescue
|
111
|
+
# Nothing - if it failed, it failed.
|
112
|
+
end
|
113
|
+
plat
|
114
|
+
end
|
115
|
+
|
116
|
+
#==============================================================================
|
117
|
+
# Setup additional compiler and linker options.
|
118
|
+
#
|
119
|
+
# We generally need to launch these things before we configure most of the flags.
|
120
|
+
# (See the main script at the end.)
|
121
|
+
|
122
|
+
def set_platform_opts
|
123
|
+
|
124
|
+
# Expand any embedded variables (like '$(CC)')
|
125
|
+
CONFIG["CC"] = RbConfig::CONFIG["CC"]
|
126
|
+
CONFIG["LDSHARED"] = RbConfig::CONFIG["LDSHARED"]
|
127
|
+
|
128
|
+
# Make sure we have a CXX value (sometimes there isn't one)
|
129
|
+
CONFIG["CXX"] = CONFIG["CC"] unless CONFIG.has_key?("CXX")
|
130
|
+
|
131
|
+
# O/S specific oddities
|
132
|
+
|
133
|
+
case p4osname
|
134
|
+
when /DARWIN/
|
135
|
+
CONFIG['CC'] = 'xcrun c++'
|
136
|
+
CONFIG['CXX'] = 'xcrun c++'
|
137
|
+
CONFIG['LDSHARED'] = CONFIG['CXX'] + ' -bundle'
|
138
|
+
when /FREEBSD/, /LINUX/
|
139
|
+
# FreeBSD 6 and some Linuxes use 'cc' for linking by default. The
|
140
|
+
# gcc detection patterns above won't catch that, so for these
|
141
|
+
# platforms, we specifically convert cc to c++.
|
142
|
+
CONFIG['LDSHARED'].sub!(/^cc/, 'c++')
|
143
|
+
when /MINGW32/
|
144
|
+
# When building with MinGW we need to statically link libgcc
|
145
|
+
# and make sure we're linking with gcc and not g++. On older
|
146
|
+
# Rubies, they use LDSHARED; newer ones (>=1.9) use LDSHAREDXX
|
147
|
+
CONFIG['LDSHARED'].sub!(/g\+\+/, 'gcc')
|
148
|
+
CONFIG['LDSHAREDXX'].sub!(/g\+\+/, 'gcc')
|
149
|
+
CONFIG['LDSHARED'] = CONFIG['LDSHARED'] + ' -static-libgcc'
|
150
|
+
CONFIG['LDSHAREDXX'] = CONFIG['LDSHARED'] + ' -static-libgcc'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def set_platform_cppflags
|
155
|
+
$CPPFLAGS += "-DOS_#{p4osname} "
|
156
|
+
$CPPFLAGS += "-DOS_#{p4osname}#{p4osver} "
|
157
|
+
$CPPFLAGS += "-DOS_#{p4osname}#{p4osver}#{p4osplat} "
|
158
|
+
|
159
|
+
if (p4osname == 'NT')
|
160
|
+
$CPPFLAGS += '/DCASE_INSENSITIVE '
|
161
|
+
end
|
162
|
+
|
163
|
+
if (p4osname == 'MINGW32')
|
164
|
+
$CPPFLAGS += '-DOS_NT -DCASE_INSENSITIVE '
|
165
|
+
end
|
166
|
+
|
167
|
+
if (p4osname == 'SOLARIS')
|
168
|
+
$CPPFLAGS += '-Dsolaris '
|
169
|
+
end
|
170
|
+
|
171
|
+
if (p4osname == 'DARWIN')
|
172
|
+
$CPPFLAGS += '-DCASE_INSENSITIVE '
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def set_platform_cflags
|
177
|
+
if (p4osname == 'DARWIN')
|
178
|
+
# Only build for 64 bit if we have more than one arch defined in CFLAGS
|
179
|
+
$CFLAGS.slice!("-arch i386")
|
180
|
+
$CFLAGS.slice!("-arch ppc");
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Initialize the base sets of platform libraries *before other initializers*
|
185
|
+
# to preserve linking order.
|
186
|
+
def set_platform_libs
|
187
|
+
|
188
|
+
case p4osname
|
189
|
+
when 'SOLARIS'
|
190
|
+
osver = `uname -r`
|
191
|
+
osver.gsub!(/5\./, '2')
|
192
|
+
if (osver == '25')
|
193
|
+
$LDFLAGS += '/usr/ucblib/libucb.a '
|
194
|
+
end
|
195
|
+
have_library('nsl')
|
196
|
+
have_library('socket')
|
197
|
+
when 'NT'
|
198
|
+
have_library('advapi32')
|
199
|
+
have_library('wsock32')
|
200
|
+
have_library('kernel32')
|
201
|
+
have_library('oldnames')
|
202
|
+
when 'CYGWIN'
|
203
|
+
# Clear out 'bogus' libs on cygwin
|
204
|
+
CONFIG['LIBS'] = ''
|
205
|
+
when 'DARWIN'
|
206
|
+
if p4osver.to_i >= 8
|
207
|
+
# Only build for 64 bit if we have more than one arch defined in CFLAGS
|
208
|
+
$LDFLAGS.slice!('-arch i386')
|
209
|
+
$LDFLAGS.slice!('-arch ppc')
|
210
|
+
$LDFLAGS += ' -framework CoreFoundation -framework Foundation'
|
211
|
+
end
|
212
|
+
when 'LINUX', 'MINGW32'
|
213
|
+
have_library('supc++')
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
#==============================================================================
|
218
|
+
# Manage p4api version
|
219
|
+
#
|
220
|
+
# The p4ruby implementation has some branching to support different versions
|
221
|
+
# of the C++ API. So we need to generate a p4rubyconf.h file that will setup
|
222
|
+
# this #define based branching based on the C++ API being compiled against.
|
223
|
+
|
224
|
+
# This captures the version information of the P4API C++ library we're building
|
225
|
+
# against. This is mostly parsed into this structure and then spit out into
|
226
|
+
# a header file we compile into the Ruby API.
|
227
|
+
class P4ApiVersion
|
228
|
+
|
229
|
+
def P4ApiVersion.load(dir)
|
230
|
+
#
|
231
|
+
# 2007.2 and later APIs put the Version file in the 'sample'
|
232
|
+
# subdirectory. Look there if we can't find it in the API root
|
233
|
+
#
|
234
|
+
ver_file = dir + "/Version"
|
235
|
+
unless File.exists?(ver_file)
|
236
|
+
ver_file = dir + "/sample/Version"
|
237
|
+
return nil unless File.exists?(ver_file)
|
238
|
+
end
|
239
|
+
|
240
|
+
re = Regexp.new('^RELEASE = (\d+)\s+(\d+)\s+(\w*\S*)\s*;')
|
241
|
+
rp = Regexp.new('^PATCHLEVEL = (.*)\s*;')
|
242
|
+
rs = Regexp.new('^SUPPDATE = (.*)\s*;')
|
243
|
+
|
244
|
+
p4api_version = nil
|
245
|
+
|
246
|
+
File.open(ver_file, "r") do
|
247
|
+
|f|
|
248
|
+
f.each_line do
|
249
|
+
|line|
|
250
|
+
if md = re.match(line)
|
251
|
+
p4api_version = P4ApiVersion.new(md[1], md[2])
|
252
|
+
p4api_version.set_type(md[3])
|
253
|
+
elsif md = rp.match(line)
|
254
|
+
p4api_version.patchlevel = md[1]
|
255
|
+
elsif md = rs.match(line)
|
256
|
+
p4api_version.suppdate = md[1]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
puts("Found #{p4api_version} Perforce API in #{dir}")
|
261
|
+
return p4api_version
|
262
|
+
end
|
263
|
+
|
264
|
+
def initialize(major, minor = nil)
|
265
|
+
if (major.kind_of?(String) && !minor)
|
266
|
+
if (major =~ /(\d+)\.(\d+)/)
|
267
|
+
major = $1
|
268
|
+
minor = $2
|
269
|
+
else
|
270
|
+
raise("Bad API version: #{major}")
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
@major = major.to_i
|
275
|
+
@minor = minor.to_i
|
276
|
+
@type = nil
|
277
|
+
|
278
|
+
@patchlevel = nil
|
279
|
+
@suppdate = nil
|
280
|
+
end
|
281
|
+
|
282
|
+
def set_type(type)
|
283
|
+
if (type.kind_of?(String))
|
284
|
+
@type = type
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
attr_accessor :patchlevel, :suppdate
|
289
|
+
attr_reader :major, :minor, :type
|
290
|
+
|
291
|
+
include Comparable
|
292
|
+
|
293
|
+
def to_s
|
294
|
+
if (@type and not @type.empty?)
|
295
|
+
"#{major}.#{minor}.#{@type.upcase}"
|
296
|
+
else
|
297
|
+
"#{major}.#{minor}"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def to_i
|
302
|
+
major << 8 | minor
|
303
|
+
end
|
304
|
+
|
305
|
+
def <=>(other)
|
306
|
+
hi = @major <=> other.major
|
307
|
+
lo = @minor <=> other.minor
|
308
|
+
|
309
|
+
return hi == 0 ? lo : hi
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def macro_def(macro, value, string=true)
|
314
|
+
if (string)
|
315
|
+
%Q{#define #{macro}\t"#{value}"}
|
316
|
+
else
|
317
|
+
%Q{#define #{macro}\t#{value}}
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def create_p4rubyconf_header(p4api_version, libs)
|
322
|
+
File.open("p4rubyconf.h", "w") do
|
323
|
+
|ch|
|
324
|
+
ch.puts(macro_def("P4APIVER_STRING", p4api_version.to_s))
|
325
|
+
ch.puts(macro_def("P4APIVER_ID", p4api_version.to_i, false))
|
326
|
+
ch.puts(macro_def("P4API_PATCHLEVEL", p4api_version.patchlevel, false))
|
327
|
+
ch.puts(macro_def("P4API_PATCHLEVEL_STRING", p4api_version.patchlevel.to_s))
|
328
|
+
ch.puts(macro_def("P4RUBY_VERSION", P4::VERSION))
|
329
|
+
ch.puts(macro_def("WITH_LIBS", libs, true))
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
#==============================================================================
|
334
|
+
# P4API (C++ API) Helpers
|
335
|
+
#
|
336
|
+
# We do not have system installers yet, so allow most people to just get a
|
337
|
+
# version downloaded if since they very likely do not care about it.
|
338
|
+
|
339
|
+
# If the user has *not* specified --with-p4api-dir, check the --enable-p4api-download
|
340
|
+
# flag, and download the p4api before proceeding, unless that's disabled.
|
341
|
+
#
|
342
|
+
# This may be a little confusing. If people specify --with-p4api-dir, we want
|
343
|
+
# use only use that setting. If that setting is wrong, we want to fail.
|
344
|
+
#
|
345
|
+
# If they don't set the --with-p4api-dir, we'll proceed as if --enable-p4api-download
|
346
|
+
# has been set. Otherwise, they can --disable-p4api-download to ensure we
|
347
|
+
# just don't bother doing anything.
|
348
|
+
def resolve_p4api_dir
|
349
|
+
p4api_dir = nil
|
350
|
+
|
351
|
+
# When running rake compile, use this instead of other options, I'm not sure how
|
352
|
+
# gem/bundler options are passed through via rake
|
353
|
+
if ENV.has_key?('p4api_dir')
|
354
|
+
p4api_dir = ENV['p4api_dir']
|
355
|
+
dir_config('p4api', "#{p4api_dir}/include", "#{p4api_dir}/lib")
|
356
|
+
end
|
357
|
+
|
358
|
+
if !p4api_dir && !with_config('p4api-dir') && enable_config('p4api-download', true)
|
359
|
+
download_api_via_ftp
|
360
|
+
unzip_file
|
361
|
+
p4api_dir = downloaded_p4api_dir
|
362
|
+
dir_config('p4api', "#{p4api_dir}/include", "#{p4api_dir}/lib")
|
363
|
+
elsif with_config('p4api_dir')
|
364
|
+
p4api_dir = with_config('p4api-dir')
|
365
|
+
elsif !p4api_dir
|
366
|
+
raise '--with-p4api-dir option has not been specified, and --disable-p4api-download is in effect'
|
367
|
+
end
|
368
|
+
|
369
|
+
p4api_dir
|
370
|
+
end
|
371
|
+
|
372
|
+
# Our 'cpu' label we use as part of the directory name on ftp.perforce.com
|
373
|
+
def p4_cpu(os)
|
374
|
+
cpu = RbConfig::CONFIG['target_cpu']
|
375
|
+
case os
|
376
|
+
when :darwin, :linux
|
377
|
+
if cpu =~ /i686/
|
378
|
+
'x86'
|
379
|
+
else
|
380
|
+
cpu
|
381
|
+
end
|
382
|
+
else
|
383
|
+
case cpu
|
384
|
+
when /ia/i
|
385
|
+
'ia64'
|
386
|
+
else
|
387
|
+
cpu
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
# The p4_platform is our label that basically ends up being part of the
|
393
|
+
# directory name where we can download files from.
|
394
|
+
def p4_platform_label
|
395
|
+
case RbConfig::CONFIG["target_os"].downcase
|
396
|
+
when /nt|mswin|mingw/
|
397
|
+
# Ruby on windows is only MinGW via Rubyinstaller.org, though this may
|
398
|
+
# not work on all rubies.
|
399
|
+
if RbConfig::CONFIG['MAJOR'].to_i >= 2
|
400
|
+
raise 'We do not support Ruby 2.0+ on Windows, due to MinGW incompatibility with the C++ API'
|
401
|
+
end
|
402
|
+
'mingwx86'
|
403
|
+
when /darwin/
|
404
|
+
"darwin90#{p4_cpu(:darwin)}"
|
405
|
+
when /solaris/
|
406
|
+
"solaris10#{p4_cpu(:solaris)}"
|
407
|
+
when /linux/
|
408
|
+
"linux26#{p4_cpu(:linux)}"
|
409
|
+
when /cygwin/
|
410
|
+
raise 'cygwin is not supported for the --download-p4api option'
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def platform_dir_name
|
415
|
+
"bin.#{p4_platform_label}"
|
416
|
+
end
|
417
|
+
|
418
|
+
def ftp_download_dir(version)
|
419
|
+
"perforce/#{version}/#{platform_dir_name}"
|
420
|
+
end
|
421
|
+
|
422
|
+
def filename
|
423
|
+
if RbConfig::CONFIG['target_os'].downcase =~ /nt|mswin|mingw/
|
424
|
+
'p4api.zip'
|
425
|
+
else
|
426
|
+
'p4api.tgz'
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
def remote_files_matching(ftp, dir, regex)
|
431
|
+
ftp.ls(dir.to_s).map { |entry|
|
432
|
+
if match = entry.match(regex)
|
433
|
+
yield match
|
434
|
+
else
|
435
|
+
nil
|
436
|
+
end
|
437
|
+
}.reject { |entry|
|
438
|
+
entry.nil?
|
439
|
+
}
|
440
|
+
end
|
441
|
+
|
442
|
+
def find_latest_with_p4api(ftp, versions)
|
443
|
+
versions.reverse_each { |v|
|
444
|
+
begin
|
445
|
+
remote_files_matching(ftp, "r#{v}/#{platform_dir_name}/", /p4api/) do
|
446
|
+
return v
|
447
|
+
end
|
448
|
+
rescue
|
449
|
+
next
|
450
|
+
end
|
451
|
+
}
|
452
|
+
end
|
453
|
+
|
454
|
+
def find_latest_version_dir(ftp)
|
455
|
+
ftp.chdir('perforce')
|
456
|
+
|
457
|
+
# Capture all versions
|
458
|
+
versions = remote_files_matching(ftp, '.', /r(1\d\.\d)/) { |m| m.captures.first }.sort
|
459
|
+
|
460
|
+
version = find_latest_with_p4api(ftp, versions)
|
461
|
+
|
462
|
+
ftp.chdir('..')
|
463
|
+
|
464
|
+
"r#{version}"
|
465
|
+
end
|
466
|
+
|
467
|
+
# Downloads the C++ P4API via FTP to the local directory, then 'initializes' it
|
468
|
+
# by unpacking it.
|
469
|
+
def download_api_via_ftp
|
470
|
+
ftp = Net::FTP.new('ftp.perforce.com')
|
471
|
+
ftp.passive=true
|
472
|
+
ftp.login
|
473
|
+
|
474
|
+
version_dir = find_latest_version_dir(ftp)
|
475
|
+
|
476
|
+
dir = ftp_download_dir(version_dir)
|
477
|
+
ftp.chdir(dir)
|
478
|
+
|
479
|
+
puts "downloading #{filename} from #{dir} on ftp.perforce.com"
|
480
|
+
ftp.getbinaryfile(filename)
|
481
|
+
|
482
|
+
ensure
|
483
|
+
ftp.close if ftp and !ftp.closed?
|
484
|
+
end
|
485
|
+
|
486
|
+
def unzip_file
|
487
|
+
if RbConfig::CONFIG['target_os'].downcase =~ /nt|mswin|mingw/
|
488
|
+
`unzip #{filename}`
|
489
|
+
else
|
490
|
+
`tar xzf #{filename}`
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
def downloaded_p4api_dir
|
495
|
+
File.absolute_path(Dir.entries('.').select { |x| x =~ /^p4api/ and File.directory?(x) }.first)
|
496
|
+
end
|
497
|
+
|
498
|
+
|
499
|
+
#==============================================================================
|
500
|
+
# Main script
|
501
|
+
|
502
|
+
puts "p4osname #{p4osname}"
|
503
|
+
puts "p4osver #{p4osver}"
|
504
|
+
|
505
|
+
# Specify different toolsets based on the platform type.
|
506
|
+
set_platform_opts
|
507
|
+
|
508
|
+
# We setup these flags in the beginning, before any libraries are detected,
|
509
|
+
# based solely on platform detection.
|
510
|
+
set_platform_cppflags
|
511
|
+
set_platform_cflags
|
512
|
+
|
513
|
+
puts "$CPPFLAGS #{$CPPFLAGS}"
|
514
|
+
puts "$CFLAGS #{$CFLAGS}"
|
515
|
+
|
516
|
+
# Setup additional system library definitions based on platform type before
|
517
|
+
# we setup other libraries, in order to preserve linking order
|
518
|
+
set_platform_libs
|
519
|
+
|
520
|
+
puts "$LDFLAGS #{$LDFLAGS}"
|
521
|
+
|
522
|
+
p4api_dir = resolve_p4api_dir
|
523
|
+
puts "P4API Path #{p4api_dir}"
|
524
|
+
|
525
|
+
do_ssl = have_library('ssl') and have_library('crypto')
|
526
|
+
|
527
|
+
unless do_ssl
|
528
|
+
have_library('p4sslstub') or raise
|
529
|
+
end
|
530
|
+
|
531
|
+
have_library('supp') or raise
|
532
|
+
have_library('rpc') or raise
|
533
|
+
have_library('client') or raise
|
534
|
+
|
535
|
+
puts "$libs #{$libs}"
|
536
|
+
|
537
|
+
# Parse the Version file into a ruby structure
|
538
|
+
version_info = P4ApiVersion.load(p4api_dir)
|
539
|
+
create_p4rubyconf_header(version_info, $libs)
|
540
|
+
|
541
|
+
# This will generate a standard extconf.h based on what we discover locally.
|
542
|
+
# These are typically just 'yes I have such and such a library', which I
|
543
|
+
# don't believe we need to rely on actually.
|
544
|
+
create_header
|
545
|
+
|
546
|
+
create_makefile('P4')
|