pg 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/BSDL +22 -0
- data/ChangeLog +6595 -0
- data/Contributors.rdoc +46 -0
- data/History.rdoc +492 -0
- data/LICENSE +56 -0
- data/Manifest.txt +72 -0
- data/POSTGRES +23 -0
- data/README-OS_X.rdoc +68 -0
- data/README-Windows.rdoc +56 -0
- data/README.ja.rdoc +14 -0
- data/README.rdoc +178 -0
- data/Rakefile +215 -0
- data/Rakefile.cross +298 -0
- data/ext/errorcodes.def +968 -0
- data/ext/errorcodes.rb +45 -0
- data/ext/errorcodes.txt +478 -0
- data/ext/extconf.rb +94 -0
- data/ext/gvl_wrappers.c +17 -0
- data/ext/gvl_wrappers.h +241 -0
- data/ext/pg.c +640 -0
- data/ext/pg.h +365 -0
- data/ext/pg_binary_decoder.c +229 -0
- data/ext/pg_binary_encoder.c +162 -0
- data/ext/pg_coder.c +549 -0
- data/ext/pg_connection.c +4252 -0
- data/ext/pg_copy_coder.c +596 -0
- data/ext/pg_errors.c +95 -0
- data/ext/pg_result.c +1501 -0
- data/ext/pg_text_decoder.c +981 -0
- data/ext/pg_text_encoder.c +682 -0
- data/ext/pg_tuple.c +541 -0
- data/ext/pg_type_map.c +166 -0
- data/ext/pg_type_map_all_strings.c +116 -0
- data/ext/pg_type_map_by_class.c +239 -0
- data/ext/pg_type_map_by_column.c +312 -0
- data/ext/pg_type_map_by_mri_type.c +284 -0
- data/ext/pg_type_map_by_oid.c +355 -0
- data/ext/pg_type_map_in_ruby.c +299 -0
- data/ext/util.c +149 -0
- data/ext/util.h +65 -0
- data/ext/vc/pg.sln +26 -0
- data/ext/vc/pg_18/pg.vcproj +216 -0
- data/ext/vc/pg_19/pg_19.vcproj +209 -0
- data/lib/pg.rb +74 -0
- data/lib/pg/basic_type_mapping.rb +459 -0
- data/lib/pg/binary_decoder.rb +22 -0
- data/lib/pg/coder.rb +83 -0
- data/lib/pg/connection.rb +291 -0
- data/lib/pg/constants.rb +11 -0
- data/lib/pg/exceptions.rb +11 -0
- data/lib/pg/result.rb +31 -0
- data/lib/pg/text_decoder.rb +47 -0
- data/lib/pg/text_encoder.rb +69 -0
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +15 -0
- data/spec/data/expected_trace.out +26 -0
- data/spec/data/random_binary_data +0 -0
- data/spec/helpers.rb +380 -0
- data/spec/pg/basic_type_mapping_spec.rb +508 -0
- data/spec/pg/connection_spec.rb +1872 -0
- data/spec/pg/connection_sync_spec.rb +41 -0
- data/spec/pg/result_spec.rb +491 -0
- data/spec/pg/tuple_spec.rb +280 -0
- data/spec/pg/type_map_by_class_spec.rb +138 -0
- data/spec/pg/type_map_by_column_spec.rb +222 -0
- data/spec/pg/type_map_by_mri_type_spec.rb +136 -0
- data/spec/pg/type_map_by_oid_spec.rb +149 -0
- data/spec/pg/type_map_in_ruby_spec.rb +164 -0
- data/spec/pg/type_map_spec.rb +22 -0
- data/spec/pg/type_spec.rb +949 -0
- data/spec/pg_spec.rb +50 -0
- metadata +322 -0
- metadata.gz.sig +0 -0
data/Rakefile
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
# -*- rake -*-
|
2
|
+
|
3
|
+
require 'rbconfig'
|
4
|
+
require 'pathname'
|
5
|
+
require 'tmpdir'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'rake/extensiontask'
|
9
|
+
rescue LoadError
|
10
|
+
abort "This Rakefile requires rake-compiler (gem install rake-compiler)"
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'hoe'
|
15
|
+
rescue LoadError
|
16
|
+
abort "This Rakefile requires hoe (gem install hoe)"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/clean'
|
20
|
+
|
21
|
+
# Build directory constants
|
22
|
+
BASEDIR = Pathname( __FILE__ ).dirname
|
23
|
+
SPECDIR = BASEDIR + 'spec'
|
24
|
+
LIBDIR = BASEDIR + 'lib'
|
25
|
+
EXTDIR = BASEDIR + 'ext'
|
26
|
+
PKGDIR = BASEDIR + 'pkg'
|
27
|
+
TMPDIR = BASEDIR + 'tmp'
|
28
|
+
|
29
|
+
DLEXT = RbConfig::CONFIG['DLEXT']
|
30
|
+
EXT = LIBDIR + "pg_ext.#{DLEXT}"
|
31
|
+
|
32
|
+
GEMSPEC = 'pg.gemspec'
|
33
|
+
|
34
|
+
TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
|
35
|
+
|
36
|
+
CLOBBER.include( TEST_DIRECTORY.to_s )
|
37
|
+
CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
|
38
|
+
|
39
|
+
# Set up Hoe plugins
|
40
|
+
Hoe.plugin :mercurial
|
41
|
+
Hoe.plugin :signing
|
42
|
+
Hoe.plugin :deveiate
|
43
|
+
Hoe.plugin :bundler
|
44
|
+
|
45
|
+
Hoe.plugins.delete :rubyforge
|
46
|
+
Hoe.plugins.delete :compiler
|
47
|
+
|
48
|
+
load 'Rakefile.cross'
|
49
|
+
|
50
|
+
|
51
|
+
# Hoe specification
|
52
|
+
$hoespec = Hoe.spec 'pg' do
|
53
|
+
self.readme_file = 'README.rdoc'
|
54
|
+
self.history_file = 'History.rdoc'
|
55
|
+
self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
|
56
|
+
self.extra_rdoc_files.include( 'POSTGRES', 'LICENSE' )
|
57
|
+
self.extra_rdoc_files.include( 'ext/*.c' )
|
58
|
+
self.license 'BSD-3-Clause'
|
59
|
+
|
60
|
+
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
61
|
+
self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
|
62
|
+
|
63
|
+
self.dependency 'rake-compiler', '~> 1.0', :developer
|
64
|
+
self.dependency 'rake-compiler-dock', ['~> 0.7.0'], :developer
|
65
|
+
self.dependency 'hoe-deveiate', '~> 0.9', :developer
|
66
|
+
self.dependency 'hoe-bundler', '~> 1.0', :developer
|
67
|
+
self.dependency 'rspec', '~> 3.5', :developer
|
68
|
+
self.dependency 'rdoc', '~> 5.1', :developer
|
69
|
+
|
70
|
+
self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
|
71
|
+
|
72
|
+
self.require_ruby_version( '>= 2.0.0' )
|
73
|
+
|
74
|
+
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
75
|
+
self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
|
76
|
+
|
77
|
+
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
78
|
+
end
|
79
|
+
|
80
|
+
ENV['VERSION'] ||= $hoespec.spec.version.to_s
|
81
|
+
|
82
|
+
# Tests should pass before checking in
|
83
|
+
task 'hg:precheckin' => [ :check_history, :check_manifest, :spec, :gemspec ]
|
84
|
+
|
85
|
+
# Support for 'rvm specs'
|
86
|
+
task :specs => :spec
|
87
|
+
|
88
|
+
# Compile before testing
|
89
|
+
task :spec => :compile
|
90
|
+
|
91
|
+
# gem-testers support
|
92
|
+
task :test do
|
93
|
+
# rake-compiler always wants to copy the compiled extension into lib/, but
|
94
|
+
# we don't want testers to have to re-compile, especially since that
|
95
|
+
# often fails because they can't (and shouldn't have to) write to tmp/ in
|
96
|
+
# the installed gem dir. So we clear the task rake-compiler set up
|
97
|
+
# to break the dependency between :spec and :compile when running under
|
98
|
+
# rubygems-test, and then run :spec.
|
99
|
+
Rake::Task[ EXT.to_s ].clear if File.exist?(EXT.to_s)
|
100
|
+
Rake::Task[ :spec ].execute
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "Turn on warnings and debugging in the build."
|
104
|
+
task :maint do
|
105
|
+
ENV['MAINTAINER_MODE'] = 'yes'
|
106
|
+
end
|
107
|
+
|
108
|
+
# Rake-compiler task
|
109
|
+
Rake::ExtensionTask.new do |ext|
|
110
|
+
ext.name = 'pg_ext'
|
111
|
+
ext.gem_spec = $hoespec.spec
|
112
|
+
ext.ext_dir = 'ext'
|
113
|
+
ext.lib_dir = 'lib'
|
114
|
+
ext.source_pattern = "*.{c,h}"
|
115
|
+
ext.cross_compile = true
|
116
|
+
ext.cross_platform = CrossLibraries.map &:for_platform
|
117
|
+
|
118
|
+
ext.cross_config_options += CrossLibraries.map do |lib|
|
119
|
+
{
|
120
|
+
lib.for_platform => [
|
121
|
+
"--enable-windows-cross",
|
122
|
+
"--with-pg-include=#{lib.static_postgresql_incdir}",
|
123
|
+
"--with-pg-lib=#{lib.static_postgresql_libdir}",
|
124
|
+
# libpq-fe.h resides in src/interfaces/libpq/ before make install
|
125
|
+
"--with-opt-include=#{lib.static_postgresql_libdir}",
|
126
|
+
]
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
# Add libpq.dll to windows binary gemspec
|
131
|
+
ext.cross_compiling do |spec|
|
132
|
+
spec.files << "lib/libpq.dll"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# Use the fivefish formatter for docs generated from development checkout
|
138
|
+
if File.directory?( '.hg' )
|
139
|
+
require 'rdoc/task'
|
140
|
+
|
141
|
+
Rake::Task[ 'docs' ].clear
|
142
|
+
RDoc::Task.new( 'docs' ) do |rdoc|
|
143
|
+
rdoc.main = "README.rdoc"
|
144
|
+
rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb", 'ext/**/*.{c,h}' )
|
145
|
+
rdoc.generator = :fivefish
|
146
|
+
rdoc.title = "PG: The Ruby PostgreSQL Driver"
|
147
|
+
rdoc.rdoc_dir = 'doc'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# Make the ChangeLog update if the repo has changed since it was last built
|
153
|
+
file '.hg/branch' do
|
154
|
+
warn "WARNING: You need the Mercurial repo to update the ChangeLog"
|
155
|
+
end
|
156
|
+
Rake::Task["ChangeLog"].clear
|
157
|
+
file 'ChangeLog' do |task|
|
158
|
+
if File.exist?('.hg/branch')
|
159
|
+
$stderr.puts "Updating the changelog..."
|
160
|
+
begin
|
161
|
+
include Hoe::MercurialHelpers
|
162
|
+
content = make_changelog()
|
163
|
+
rescue NameError
|
164
|
+
abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
|
165
|
+
end
|
166
|
+
File.open( task.name, 'w', 0644 ) do |fh|
|
167
|
+
fh.print( content )
|
168
|
+
end
|
169
|
+
else
|
170
|
+
touch 'ChangeLog'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Rebuild the ChangeLog immediately before release
|
175
|
+
task :prerelease => 'ChangeLog'
|
176
|
+
|
177
|
+
|
178
|
+
desc "Stop any Postmaster instances that remain after testing."
|
179
|
+
task :cleanup_testing_dbs do
|
180
|
+
require 'spec/lib/helpers'
|
181
|
+
PgTestingHelpers.stop_existing_postmasters()
|
182
|
+
Rake::Task[:clean].invoke
|
183
|
+
end
|
184
|
+
|
185
|
+
desc "Update list of server error codes"
|
186
|
+
task :update_error_codes do
|
187
|
+
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_11_1"
|
188
|
+
|
189
|
+
ERRORCODES_TXT = "ext/errorcodes.txt"
|
190
|
+
sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
|
191
|
+
|
192
|
+
ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
|
193
|
+
end
|
194
|
+
|
195
|
+
file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
|
196
|
+
# trigger compilation of changed errorcodes.def
|
197
|
+
touch 'ext/pg_errors.c'
|
198
|
+
end
|
199
|
+
|
200
|
+
task :gemspec => GEMSPEC
|
201
|
+
file GEMSPEC => __FILE__
|
202
|
+
task GEMSPEC do |task|
|
203
|
+
spec = $hoespec.spec
|
204
|
+
spec.files.delete( '.gemtest' )
|
205
|
+
spec.signing_key = nil
|
206
|
+
spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
207
|
+
spec.cert_chain = [ 'certs/ged.pem' ]
|
208
|
+
File.open( task.name, 'w' ) do |fh|
|
209
|
+
fh.write( spec.to_ruby )
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
CLOBBER.include( '*.gemspec' )
|
214
|
+
task :default => :gemspec
|
215
|
+
|
data/Rakefile.cross
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
# -*- rake -*-
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'rake/clean'
|
7
|
+
require 'rake/extensiontask'
|
8
|
+
require 'rake/extensioncompiler'
|
9
|
+
require 'ostruct'
|
10
|
+
|
11
|
+
MISCDIR = BASEDIR + 'misc'
|
12
|
+
|
13
|
+
NUM_CPUS = if File.exist?('/proc/cpuinfo')
|
14
|
+
File.read('/proc/cpuinfo').scan('processor').length
|
15
|
+
elsif RUBY_PLATFORM.include?( 'darwin' )
|
16
|
+
`system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
|
17
|
+
else
|
18
|
+
1
|
19
|
+
end
|
20
|
+
|
21
|
+
class CrossLibrary < OpenStruct
|
22
|
+
include Rake::DSL
|
23
|
+
|
24
|
+
def initialize(for_platform, openssl_config, toolchain)
|
25
|
+
super()
|
26
|
+
|
27
|
+
self.for_platform = for_platform
|
28
|
+
self.openssl_config = openssl_config
|
29
|
+
self.host_platform = toolchain
|
30
|
+
|
31
|
+
# Cross-compilation constants
|
32
|
+
self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.1a'
|
33
|
+
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '11.1'
|
34
|
+
|
35
|
+
# Check if symlinks work in the current working directory.
|
36
|
+
# This fails, if rake-compiler-dock is running on a Windows box.
|
37
|
+
begin
|
38
|
+
FileUtils.rm_f '.test_symlink'
|
39
|
+
FileUtils.ln_s '/', '.test_symlink'
|
40
|
+
rescue SystemCallError
|
41
|
+
# Symlinks don't work -> use home directory instead
|
42
|
+
self.compile_home = Pathname( "~/.ruby-pg-build" ).expand_path
|
43
|
+
else
|
44
|
+
self.compile_home = Pathname( "./build" ).expand_path
|
45
|
+
end
|
46
|
+
self.static_sourcesdir = compile_home + 'sources'
|
47
|
+
self.static_builddir = compile_home + 'builds' + for_platform
|
48
|
+
|
49
|
+
# Static OpenSSL build vars
|
50
|
+
self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
|
51
|
+
|
52
|
+
self.openssl_source_uri =
|
53
|
+
URI( "http://www.openssl.org/source/openssl-#{openssl_version}.tar.gz" )
|
54
|
+
self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
|
55
|
+
self.openssl_makefile = static_openssl_builddir + 'Makefile'
|
56
|
+
|
57
|
+
self.libssl = static_openssl_builddir + 'libssl.a'
|
58
|
+
self.libcrypto = static_openssl_builddir + 'libcrypto.a'
|
59
|
+
|
60
|
+
self.openssl_patches = Rake::FileList[ (MISCDIR + "openssl-#{openssl_version}.*.patch").to_s ]
|
61
|
+
|
62
|
+
# Static PostgreSQL build vars
|
63
|
+
self.static_postgresql_builddir = static_builddir + "postgresql-#{postgresql_version}"
|
64
|
+
self.postgresql_source_uri = begin
|
65
|
+
uristring = "http://ftp.postgresql.org/pub/source/v%s/postgresql-%s.tar.bz2" %
|
66
|
+
[ postgresql_version, postgresql_version ]
|
67
|
+
URI( uristring )
|
68
|
+
end
|
69
|
+
self.postgresql_tarball = static_sourcesdir + File.basename( postgresql_source_uri.path )
|
70
|
+
|
71
|
+
self.static_postgresql_srcdir = static_postgresql_builddir + 'src'
|
72
|
+
self.static_postgresql_libdir = static_postgresql_srcdir + 'interfaces/libpq'
|
73
|
+
self.static_postgresql_incdir = static_postgresql_srcdir + 'include'
|
74
|
+
|
75
|
+
self.postgresql_global_makefile = static_postgresql_srcdir + 'Makefile.global'
|
76
|
+
self.postgresql_shlib_makefile = static_postgresql_srcdir + 'Makefile.shlib'
|
77
|
+
self.postgresql_shlib_mf_orig = static_postgresql_srcdir + 'Makefile.shlib.orig'
|
78
|
+
self.postgresql_lib = static_postgresql_libdir + 'libpq.dll'
|
79
|
+
self.postgresql_patches = Rake::FileList[ (MISCDIR + "postgresql-#{postgresql_version}.*.patch").to_s ]
|
80
|
+
|
81
|
+
# clean intermediate files and folders
|
82
|
+
CLEAN.include( static_builddir.to_s )
|
83
|
+
|
84
|
+
|
85
|
+
def download(url, save_to)
|
86
|
+
part = save_to+".part"
|
87
|
+
sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
|
88
|
+
FileUtils.mv part, save_to
|
89
|
+
end
|
90
|
+
|
91
|
+
def run(*args)
|
92
|
+
sh *args
|
93
|
+
end
|
94
|
+
|
95
|
+
#####################################################################
|
96
|
+
### C R O S S - C O M P I L A T I O N - T A S K S
|
97
|
+
#####################################################################
|
98
|
+
|
99
|
+
|
100
|
+
directory static_sourcesdir.to_s
|
101
|
+
|
102
|
+
#
|
103
|
+
# Static OpenSSL build tasks
|
104
|
+
#
|
105
|
+
directory static_openssl_builddir.to_s
|
106
|
+
|
107
|
+
# openssl source file should be stored there
|
108
|
+
file openssl_tarball => static_sourcesdir do |t|
|
109
|
+
download( openssl_source_uri, t.name )
|
110
|
+
end
|
111
|
+
|
112
|
+
# Extract the openssl builds
|
113
|
+
file static_openssl_builddir => openssl_tarball do |t|
|
114
|
+
puts "extracting %s to %s" % [ openssl_tarball, static_openssl_builddir.parent ]
|
115
|
+
static_openssl_builddir.mkpath
|
116
|
+
run 'tar', '-xzf', openssl_tarball.to_s, '-C', static_openssl_builddir.parent.to_s
|
117
|
+
openssl_makefile.unlink if openssl_makefile.exist?
|
118
|
+
|
119
|
+
openssl_patches.each do |patchfile|
|
120
|
+
puts " applying patch #{patchfile}..."
|
121
|
+
run 'patch', '-Np1', '-d', static_openssl_builddir.to_s,
|
122
|
+
'-i', File.expand_path( patchfile, BASEDIR )
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
self.cmd_prelude = [
|
127
|
+
"env",
|
128
|
+
"CROSS_COMPILE=#{host_platform}-",
|
129
|
+
"CFLAGS=-DDSO_WIN32",
|
130
|
+
]
|
131
|
+
|
132
|
+
|
133
|
+
# generate the makefile in a clean build location
|
134
|
+
file openssl_makefile => static_openssl_builddir do |t|
|
135
|
+
chdir( static_openssl_builddir ) do
|
136
|
+
cmd = cmd_prelude.dup
|
137
|
+
cmd << "./Configure" << openssl_config
|
138
|
+
|
139
|
+
run( *cmd )
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
desc "compile static openssl libraries"
|
144
|
+
task :openssl_libs => [ libssl, libcrypto ]
|
145
|
+
|
146
|
+
task :compile_static_openssl => openssl_makefile do |t|
|
147
|
+
chdir( static_openssl_builddir ) do
|
148
|
+
cmd = cmd_prelude.dup
|
149
|
+
cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
|
150
|
+
|
151
|
+
run( *cmd )
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
desc "compile static #{libssl}"
|
156
|
+
file libssl => :compile_static_openssl do |t|
|
157
|
+
rm t.name.gsub(/\.a$/, ".dll.a")
|
158
|
+
end
|
159
|
+
|
160
|
+
desc "compile static #{libcrypto}"
|
161
|
+
file libcrypto => :compile_static_openssl do |t|
|
162
|
+
rm t.name.gsub(/\.a$/, ".dll.a")
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
#
|
168
|
+
# Static PostgreSQL build tasks
|
169
|
+
#
|
170
|
+
directory static_postgresql_builddir.to_s
|
171
|
+
|
172
|
+
|
173
|
+
# postgresql source file should be stored there
|
174
|
+
file postgresql_tarball => static_sourcesdir do |t|
|
175
|
+
download( postgresql_source_uri, t.name )
|
176
|
+
end
|
177
|
+
|
178
|
+
# Extract the postgresql sources
|
179
|
+
file static_postgresql_builddir => postgresql_tarball do |t|
|
180
|
+
puts "extracting %s to %s" % [ postgresql_tarball, static_postgresql_builddir.parent ]
|
181
|
+
static_postgresql_builddir.mkpath
|
182
|
+
run 'tar', '-xjf', postgresql_tarball.to_s, '-C', static_postgresql_builddir.parent.to_s
|
183
|
+
|
184
|
+
postgresql_patches.each do |patchfile|
|
185
|
+
puts " applying patch #{patchfile}..."
|
186
|
+
run 'patch', '-Np1', '-d', static_postgresql_builddir.to_s,
|
187
|
+
'-i', File.expand_path( patchfile, BASEDIR )
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# generate the makefile in a clean build location
|
192
|
+
file postgresql_global_makefile => [ static_postgresql_builddir, :openssl_libs ] do |t|
|
193
|
+
options = [
|
194
|
+
"--target=#{host_platform}",
|
195
|
+
"--host=#{host_platform}",
|
196
|
+
'--with-openssl',
|
197
|
+
'--without-zlib',
|
198
|
+
]
|
199
|
+
|
200
|
+
chdir( static_postgresql_builddir ) do
|
201
|
+
configure_path = static_postgresql_builddir + 'configure'
|
202
|
+
cmd = [ configure_path.to_s, *options ]
|
203
|
+
cmd << "CFLAGS=-L#{static_openssl_builddir}"
|
204
|
+
cmd << "LDFLAGS=-L#{static_openssl_builddir}"
|
205
|
+
cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
|
206
|
+
cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32"
|
207
|
+
cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
|
208
|
+
|
209
|
+
run( *cmd )
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
# make libpq.dll
|
215
|
+
task postgresql_lib => [ postgresql_global_makefile ] do |t|
|
216
|
+
# Work around missing dependency to libcommon in PostgreSQL-9.4.0
|
217
|
+
chdir( static_postgresql_srcdir + "common" ) do
|
218
|
+
sh 'make', "-j#{NUM_CPUS}"
|
219
|
+
end
|
220
|
+
|
221
|
+
chdir( postgresql_lib.dirname ) do
|
222
|
+
sh 'make',
|
223
|
+
"-j#{NUM_CPUS}",
|
224
|
+
postgresql_lib.basename.to_s,
|
225
|
+
'SHLIB_LINK=-lssl -lcrypto -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
#desc 'compile libpg.a'
|
231
|
+
task :libpq => postgresql_lib
|
232
|
+
|
233
|
+
# copy libpq.dll to lib dir
|
234
|
+
dest_libpq = "lib/#{postgresql_lib.basename}"
|
235
|
+
directory File.dirname(dest_libpq)
|
236
|
+
file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
|
237
|
+
cp postgresql_lib, dest_libpq
|
238
|
+
end
|
239
|
+
|
240
|
+
stage_libpq = "tmp/#{for_platform}/stage/#{dest_libpq}"
|
241
|
+
directory File.dirname(stage_libpq)
|
242
|
+
file stage_libpq => [postgresql_lib, File.dirname(stage_libpq)] do |t|
|
243
|
+
cp postgresql_lib, stage_libpq
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
if File.exist?(File.expand_path("~/.rake-compiler/config.yml"))
|
249
|
+
CrossLibraries = [
|
250
|
+
['i386-mingw32', 'mingw', 'i686-w64-mingw32'],
|
251
|
+
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
|
252
|
+
].map do |platform, openssl_config, toolchain|
|
253
|
+
CrossLibrary.new platform, openssl_config, toolchain
|
254
|
+
end
|
255
|
+
else
|
256
|
+
$stderr.puts "Cross-compilation disabled -- rake-compiler not properly installed"
|
257
|
+
CrossLibraries = []
|
258
|
+
end
|
259
|
+
|
260
|
+
desc 'cross compile pg for win32'
|
261
|
+
task :cross => [ :mingw32, :libpq ]
|
262
|
+
|
263
|
+
task :mingw32 do
|
264
|
+
# Use Rake::ExtensionCompiler helpers to find the proper host
|
265
|
+
unless Rake::ExtensionCompiler.mingw_host then
|
266
|
+
warn "You need to install mingw32 cross compile functionality to be able to continue."
|
267
|
+
warn "Please refer to your distribution/package manager documentation about installation."
|
268
|
+
fail
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
# To reduce the gem file size strip mingw32 dlls before packaging
|
273
|
+
ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
|
274
|
+
task "tmp/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so" do |t|
|
275
|
+
sh "i686-w64-mingw32-strip -S tmp/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so"
|
276
|
+
end
|
277
|
+
|
278
|
+
task "tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so" do |t|
|
279
|
+
sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
desc "Build the windows binary gems"
|
284
|
+
task 'gem:windows' => ['ChangeLog'] do
|
285
|
+
require 'rake_compiler_dock'
|
286
|
+
|
287
|
+
# Copy gem signing key and certs to be accessable from the docker container
|
288
|
+
mkdir_p 'build/gem'
|
289
|
+
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
|
290
|
+
sh "bundle package"
|
291
|
+
|
292
|
+
RakeCompilerDock.sh <<-EOT
|
293
|
+
mkdir ~/.gem &&
|
294
|
+
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
|
295
|
+
bundle install --local &&
|
296
|
+
rake cross native gem MAKE="make -j`nproc`"
|
297
|
+
EOT
|
298
|
+
end
|