pg 0.9.0 → 0.10.0

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.
data/README CHANGED
@@ -5,8 +5,8 @@ library works with PostgreSQL 7.4 and later.
5
5
 
6
6
  == Requirements
7
7
 
8
- * Ruby 1.8.6 or later.
9
- * PostgreSQL 7.3 or later installed.
8
+ * Ruby 1.8.7-p174 or later.
9
+ * PostgreSQL 7.4 or later installed.
10
10
 
11
11
  It may work with earlier versions as well, but those are not regularly tested.
12
12
 
data/Rakefile CHANGED
@@ -11,12 +11,14 @@
11
11
  #
12
12
 
13
13
  BEGIN {
14
+ require 'rbconfig'
14
15
  require 'pathname'
15
16
  basedir = Pathname.new( __FILE__ ).dirname
16
17
 
17
18
  libdir = basedir + "lib"
18
- extdir = basedir + "ext"
19
+ extdir = libdir + Config::CONFIG['sitearch']
19
20
 
21
+ $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
20
22
  $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
21
23
  $LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
22
24
  }
@@ -75,7 +77,7 @@ elsif VERSION_FILE.exist?
75
77
  PKG_VERSION = VERSION_FILE.read[ /VERSION\s*=\s*['"](\d+\.\d+\.\d+)['"]/, 1 ]
76
78
  end
77
79
 
78
- PKG_VERSION ||= '0.0.0'
80
+ PKG_VERSION = '0.0.0' unless defined?( PKG_VERSION ) && !PKG_VERSION.nil?
79
81
 
80
82
  PKG_FILE_NAME = "#{PKG_NAME.downcase}-#{PKG_VERSION}"
81
83
  GEM_FILE_NAME = "#{PKG_FILE_NAME}.gem"
@@ -90,7 +92,7 @@ EXTCONF = EXTDIR + 'extconf.rb'
90
92
 
91
93
  ARTIFACTS_DIR = Pathname.new( CC_BUILD_ARTIFACTS )
92
94
 
93
- TEXT_FILES = Rake::FileList.new( %w[Rakefile ChangeLog README LICENSE] )
95
+ TEXT_FILES = Rake::FileList.new( %w[Rakefile ChangeLog README* LICENSE] )
94
96
  BIN_FILES = Rake::FileList.new( "#{BINDIR}/*" )
95
97
  LIB_FILES = Rake::FileList.new( "#{LIBDIR}/**/*.rb" )
96
98
  EXT_FILES = Rake::FileList.new( "#{EXTDIR}/**/*.{c,h,rb}" )
@@ -167,26 +169,36 @@ if !RAKE_TASKDIR.exist?
167
169
  end
168
170
 
169
171
  require RAKE_TASKDIR + 'helpers.rb'
172
+ include RakefileHelpers
170
173
 
171
174
  # Set the build ID if the mercurial executable is available
172
175
  if hg = which( 'hg' )
173
- id = IO.read('|-') or exec hg.to_s, 'id', '-n'
174
- PKG_BUILD = 'pre' + (id.chomp[ /^[[:xdigit:]]+/ ] || '1')
176
+ id = `#{hg} id -n`.chomp
177
+ PKG_BUILD = (id.chomp[ /^[[:xdigit:]]+/ ] || '1')
175
178
  else
176
- PKG_BUILD = 'pre0'
179
+ PKG_BUILD = '0'
177
180
  end
178
181
  SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}"
179
182
  SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem"
180
183
 
181
184
  # Documentation constants
182
- RDOCDIR = DOCSDIR + 'api'
185
+ API_DOCSDIR = DOCSDIR + 'api'
186
+ README_FILE = TEXT_FILES.find {|path| path =~ /^README/ } || 'README'
183
187
  RDOC_OPTIONS = [
184
- '-w', '4',
185
- '-HN',
186
- '-i', '.',
187
- '-m', 'README',
188
- '-t', PKG_NAME,
189
- '-W', 'http://bitbucket.org/ged/ruby-pg/browser/'
188
+ '--tab-width=4',
189
+ '--show-hash',
190
+ '--include', BASEDIR.to_s,
191
+ "--main=#{README_FILE}",
192
+ "--title=#{PKG_NAME}",
193
+ ]
194
+ YARD_OPTIONS = [
195
+ '--use-cache',
196
+ '--protected',
197
+ '-r', README_FILE,
198
+ '--exclude', 'extconf\\.rb',
199
+ '--files', 'ChangeLog,LICENSE',
200
+ '--output-dir', API_DOCSDIR.to_s,
201
+ '--title', "#{PKG_NAME} #{PKG_VERSION}",
190
202
  ]
191
203
 
192
204
  # Release constants
@@ -194,28 +206,30 @@ SMTP_HOST = "mail.faeriemud.org"
194
206
  SMTP_PORT = 465 # SMTP + SSL
195
207
 
196
208
  # Project constants
197
- PROJECT_HOST = 'bitbucket.org'
198
- PROJECT_PUBDIR = '/ged/ruby-pg/downloads/'
209
+ PROJECT_HOST = 'deveiate.org'
210
+ PROJECT_PUBDIR = '/usr/local/www/public/code/'
199
211
  PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}"
200
212
  PROJECT_SCPPUBURL = "#{PROJECT_HOST}:#{PROJECT_PUBDIR}"
201
213
  PROJECT_SCPDOCURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}"
202
214
 
215
+ GEM_PUBHOST = 'rubygems.org'
216
+
203
217
  # Gem dependencies: gemname => version
204
218
  DEPENDENCIES = {
205
219
  }
206
220
 
207
221
  # Developer Gem dependencies: gemname => version
208
222
  DEVELOPMENT_DEPENDENCIES = {
209
- 'rake' => '>= 0.8.7',
210
- 'rcodetools' => '>= 0.7.0.0',
211
- 'rcov' => '>= 0.8.1.2.0',
212
- 'rdoc' => '>= 2.4.3',
213
- 'RedCloth' => '>= 4.0.3',
214
- 'rspec' => '>= 1.2.6',
215
- 'termios' => '>= 0',
216
- 'text-format' => '>= 1.0.0',
217
- 'tmail' => '>= 1.2.3.1',
218
- 'diff-lcs' => '>= 1.1.2',
223
+ 'rake' => '~> 0.8.7',
224
+ 'rcodetools' => '~> 0.7.0.0',
225
+ 'rcov' => '~> 0.8.1.2.0',
226
+ 'yard' => '~> 0.6.1',
227
+ 'RedCloth' => '~> 4.2.3',
228
+ 'rspec' => '~> 2.0.1',
229
+ 'ruby-termios' => '~> 0.9.6',
230
+ 'text-format' => '~> 1.0.0',
231
+ 'tmail' => '~> 1.2.3.1',
232
+ 'rake-compiler' => '~>0.7.0',
219
233
  }
220
234
 
221
235
  # Non-gem requirements: packagename => version
@@ -234,13 +248,14 @@ GEMSPEC = Gem::Specification.new do |gem|
234
248
  "This library works with PostgreSQL 7.4 and later.",
235
249
  ].join( "\n" )
236
250
 
237
- gem.authors = "Michael Granger"
238
- gem.email = ["ged@FaerieMUD.org"]
251
+ gem.authors = ["Jeff Davis", "Michael Granger"]
252
+ gem.email = ["ruby-pg@j-davis.com", "ged@FaerieMUD.org"]
239
253
  gem.homepage = 'http://bitbucket.org/ged/ruby-pg/'
254
+ gem.licenses = ["Ruby", "GPL", "BSD"]
240
255
 
241
256
  gem.has_rdoc = true
242
257
  gem.rdoc_options = RDOC_OPTIONS
243
- gem.extra_rdoc_files = %w[ChangeLog README LICENSE]
258
+ gem.extra_rdoc_files = TEXT_FILES - [ 'Rakefile' ]
244
259
 
245
260
  gem.bindir = BINDIR.relative_path_from(BASEDIR).to_s
246
261
  gem.executables = BIN_FILES.select {|pn| File.executable?(pn) }.
@@ -254,6 +269,13 @@ GEMSPEC = Gem::Specification.new do |gem|
254
269
  gem.files = RELEASE_FILES
255
270
  gem.test_files = SPEC_FILES
256
271
 
272
+ # signing key and certificate chain
273
+ gem.signing_key = '/Volumes/Keys/ged-private_gem_key.pem'
274
+ gem.cert_chain = [File.expand_path('~/.gem/ged-public_gem_cert.pem')]
275
+
276
+
277
+ gem.required_ruby_version = '>=1.8.7'
278
+
257
279
  DEPENDENCIES.each do |name, version|
258
280
  version = '>= 0' if version.length.zero?
259
281
  gem.add_runtime_dependency( name, version )
@@ -294,7 +316,7 @@ import LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist?
294
316
  #####################################################################
295
317
 
296
318
  ### Default task
297
- task :default => [:clean, :local, :spec, :rdoc, :package]
319
+ task :default => [:clean, :local, :spec, :apidocs, :package]
298
320
 
299
321
  ### Task the local Rakefile can append to -- no-op by default
300
322
  task :local
@@ -1,26 +1,61 @@
1
1
  #!rake
2
2
 
3
- require 'rake/extensiontask'
4
- require 'rake/extensioncompiler'
3
+ require 'uri'
4
+ require 'tempfile'
5
5
  require 'rbconfig'
6
6
 
7
- # C extension constants
7
+ MISCDIR = BASEDIR + 'misc'
8
+
8
9
  EXT_MAKEFILE = EXTDIR + 'Makefile'
9
10
  EXT_SOURCES = FileList[ EXTDIR + '*.c' ]
10
- EXT_SO = EXTDIR + "pg.#{CONFIG['DLEXT']}"
11
-
12
- SITEARCH_DIR = LIBDIR + Config::CONFIG['sitearch']
11
+ EXT_SO = EXTDIR + "pg_ext.#{CONFIG['DLEXT']}"
13
12
 
14
13
  NUM_CPUS = if File.exist?('/proc/cpuinfo')
15
14
  File.read('/proc/cpuinfo').scan('processor').length
15
+ elsif RUBY_PLATFORM.include?( 'darwin' )
16
+ `system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
16
17
  else
17
18
  1
18
19
  end
19
20
 
20
21
  # Cross-compilation constants
21
- COMPILE_HOME = File.expand_path("~/.rake-compiler")
22
- OPENSSL_VERSION = ENV['OPENSSL_VERSION'] || '0.9.8l'
23
- POSTGRESQL_VERSION = ENV['POSTGRESQL_VERSION'] || '8.4.2'
22
+ OPENSSL_VERSION = ENV['OPENSSL_VERSION'] || '1.0.0a'
23
+ POSTGRESQL_VERSION = ENV['POSTGRESQL_VERSION'] || '9.0.1'
24
+
25
+ COMPILE_HOME = Pathname( "~/.rake-compiler" ).expand_path
26
+ STATIC_SOURCESDIR = COMPILE_HOME + 'sources'
27
+ STATIC_BUILDDIR = COMPILE_HOME + 'builds'
28
+
29
+ # Static OpenSSL build vars
30
+ STATIC_OPENSSL_BUILDDIR = STATIC_BUILDDIR + "openssl-#{OPENSSL_VERSION}"
31
+
32
+ OPENSSL_SOURCE_URI =
33
+ URI( "http://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz" )
34
+ OPENSSL_TARBALL = STATIC_SOURCESDIR + File.basename( OPENSSL_SOURCE_URI.path )
35
+ OPENSSL_MAKEFILE = STATIC_OPENSSL_BUILDDIR + 'Makefile'
36
+
37
+ LIBSSLEAY32 = STATIC_OPENSSL_BUILDDIR + 'libssleay32.a'
38
+ LIBEAY32 = STATIC_OPENSSL_BUILDDIR + 'libeay32.a'
39
+
40
+ OPENSSL_PATCHES = Rake::FileList[ MISCDIR + "openssl-#{OPENSSL_VERSION}.*.patch" ]
41
+
42
+ # Static PostgreSQL build vars
43
+ STATIC_POSTGRESQL_BUILDDIR = STATIC_BUILDDIR + "postgresql-#{POSTGRESQL_VERSION}"
44
+ POSTGRESQL_SOURCE_URI = begin
45
+ uristring = "http://ftp9.us.postgresql.org/pub/mirrors/postgresql/source/" +
46
+ "v%s/postgresql-%s.tar.gz" % [ POSTGRESQL_VERSION, POSTGRESQL_VERSION ]
47
+ URI( uristring )
48
+ end
49
+ POSTGRESQL_TARBALL = STATIC_SOURCESDIR + File.basename( POSTGRESQL_SOURCE_URI.path )
50
+
51
+ STATIC_POSTGRESQL_SRCDIR = STATIC_POSTGRESQL_BUILDDIR + 'src'
52
+ STATIC_POSTGRESQL_LIBDIR = STATIC_POSTGRESQL_SRCDIR + 'interfaces/libpq'
53
+ STATIC_POSTGRESQL_INCDIR = STATIC_POSTGRESQL_SRCDIR + 'include'
54
+
55
+ POSTGRESQL_GLOBAL_MAKEFILE = STATIC_POSTGRESQL_SRCDIR + 'Makefile.global'
56
+ POSTGRESQL_SHLIB_MAKEFILE = STATIC_POSTGRESQL_SRCDIR + 'Makefile.shlib'
57
+ POSTGRESQL_SHLIB_MF_ORIG = STATIC_POSTGRESQL_SRCDIR + 'Makefile.shlib.orig'
58
+ POSTGRESQL_LIB = STATIC_POSTGRESQL_LIBDIR + 'libpq.a'
24
59
 
25
60
  CROSS_PREFIX = if RUBY_PLATFORM.include?( 'darwin' )
26
61
  'i386-mingw32'
@@ -32,6 +67,13 @@ end
32
67
  SPEC_DATA = Rake::FileList[ SPECDIR + 'data/*' ]
33
68
  GEMSPEC.test_files += SPEC_DATA.to_a
34
69
 
70
+ # Clean up any testing database directories
71
+ TESTING_TMPDIRS = Rake::FileList[ "#{BASEDIR}/tmp_test_*" ]
72
+ CLOBBER.include( STATIC_SOURCESDIR.to_s, *TESTING_TMPDIRS )
73
+
74
+ # clean intermediate files and folders
75
+ CLEAN.include( STATIC_BUILDDIR.to_s )
76
+
35
77
 
36
78
  #####################################################################
37
79
  ### T A S K S
@@ -47,197 +89,224 @@ namespace :spec do
47
89
  task :text => [ :compile ]
48
90
  end
49
91
 
50
- ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
51
-
52
- Rake::ExtensionTask.new do |ext|
53
- ext.name = 'pg_ext'
54
- ext.gem_spec = GEMSPEC
55
- ext.ext_dir = 'ext'
56
- ext.lib_dir = 'lib'
57
- ext.source_pattern = "*.{c,h}"
58
-
59
- # If there's an explicit 'compile' argument, use everything after it as options.
60
- if offset = ARGV.index( 'compile' )
61
- trace "config options = %p" % [ ARGV[(offset + 1)..-1] ]
62
- ext.config_options = ARGV[ (offset + 1)..-1 ]
63
- # Otherwise, just grab everything from the first option onward
64
- elsif offset = ARGV.index( ARGV.find {|arg| arg =~ /^--/ } )
65
- trace "config options = %p" % [ ARGV[offset..-1] ]
66
- ext.config_options = ARGV[ offset..-1 ]
67
- else
68
- trace "No config options (ARGV = %p)" % [ ARGV ]
69
- end
92
+ ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.2'
93
+
94
+ begin
95
+ require 'rake/clean'
96
+ require 'rake/extensiontask'
97
+ require 'rake/extensioncompiler'
98
+
99
+ Rake::ExtensionTask.new do |ext|
100
+ ext.name = 'pg_ext'
101
+ ext.gem_spec = GEMSPEC
102
+ ext.ext_dir = EXTDIR.to_s
103
+ ext.lib_dir = LIBDIR.to_s
104
+ ext.source_pattern = "*.{c,h}"
105
+
106
+ # If there's an explicit 'compile' argument, use everything after it as options.
107
+ if offset = ARGV.index( 'compile' )
108
+ trace "config options = %p" % [ ARGV[(offset + 1)..-1] ]
109
+ ext.config_options = ARGV[ (offset + 1)..-1 ]
110
+ # Otherwise, just grab everything from the first option onward
111
+ elsif offset = ARGV.index( ARGV.find {|arg| arg =~ /^--/ } )
112
+ trace "config options = %p" % [ ARGV[offset..-1] ]
113
+ ext.config_options = ARGV[ offset..-1 ]
114
+ else
115
+ trace "No config options (ARGV = %p)" % [ ARGV ]
116
+ end
70
117
 
71
- ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
72
- ext.cross_platform = %w[i386-mswin32 i386-mingw32] # forces the Windows platform instead of the default one
118
+ ext.cross_compile = true
119
+ ext.cross_platform = %w[i386-mswin32 i386-mingw32]
73
120
 
74
- # configure options only for cross compile
75
- ext.cross_config_options += [
76
- "--with-pg-include=#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/interfaces/libpq",
77
- "--with-opt-include=#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/include",
78
- "--with-pg-lib=#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/interfaces/libpq",
79
- "--with-opt-lib=#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}",
80
- "--enable-static-build",
81
- ]
121
+ # configure options only for cross compile
122
+ ext.cross_config_options += [
123
+ "--with-pg-include=#{STATIC_POSTGRESQL_LIBDIR}",
124
+ "--with-opt-include=#{STATIC_POSTGRESQL_INCDIR}",
125
+ "--with-pg-lib=#{STATIC_POSTGRESQL_LIBDIR}",
126
+ "--with-opt-lib=#{STATIC_OPENSSL_BUILDDIR}",
127
+ "--enable-static-build",
128
+ ]
82
129
 
83
- end
130
+ end
84
131
 
85
132
 
86
- desc "Stop any Postmaster instances that remain after testing."
87
- task :cleanup_testing_dbs do
88
- require 'spec/lib/helpers'
89
- PgTestingHelpers.stop_existing_postmasters()
90
- Rake::Task[:clean].invoke
91
- end
92
133
 
134
+ #####################################################################
135
+ ### C R O S S - C O M P I L A T I O N - T A S K S
136
+ #####################################################################
93
137
 
94
- #####################################################################
95
- ### C R O S S - C O M P I L A T I O N - T A S K S
96
- #####################################################################
97
138
 
139
+ directory STATIC_SOURCESDIR.to_s
98
140
 
99
- # define a location where sources will be stored
100
- directory "#{COMPILE_HOME}/sources"
101
- directory "#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}"
141
+ #
142
+ # Static OpenSSL build tasks
143
+ #
144
+ directory STATIC_OPENSSL_BUILDDIR.to_s
102
145
 
103
- # clean intermediate files and folders
104
- CLEAN.include("#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}")
105
-
106
- # openssl source file should be stored there
107
- file "#{COMPILE_HOME}/sources/openssl-#{OPENSSL_VERSION}.tar.gz" => ["#{COMPILE_HOME}/sources"] do |t|
108
- # download the source file using wget or curl
109
- chdir File.dirname(t.name) do
110
- #http://www.openssl.org/source/openssl-0.9.8k.tar.gz
111
- url = "http://www.openssl.org/source/#{File.basename(t.name)}"
112
- sh "wget #{url} || curl -O #{url}"
146
+ # openssl source file should be stored there
147
+ file OPENSSL_TARBALL => STATIC_SOURCESDIR do |t|
148
+ download( OPENSSL_SOURCE_URI, t.name )
113
149
  end
114
- end
115
150
 
116
- # Extract the openssl builds
117
- file "#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}" => ["#{COMPILE_HOME}/sources/openssl-#{OPENSSL_VERSION}.tar.gz"] do |t|
118
- chdir File.dirname(t.name) do
119
- t.prerequisites.each { |f| sh "tar xfz ../sources/#{File.basename(f)}" }
151
+ # Extract the openssl builds
152
+ file STATIC_OPENSSL_BUILDDIR => OPENSSL_TARBALL do |t|
153
+ trace "extracting %s to %s" % [ OPENSSL_TARBALL, STATIC_OPENSSL_BUILDDIR.parent ]
154
+ STATIC_OPENSSL_BUILDDIR.mkpath
155
+ run 'tar', '-xzf', OPENSSL_TARBALL.to_s, '-C', STATIC_OPENSSL_BUILDDIR.parent.to_s
156
+ OPENSSL_MAKEFILE.unlink if OPENSSL_MAKEFILE.exist?
157
+
158
+ OPENSSL_PATCHES.each do |patchfile|
159
+ trace " applying patch #{patchfile}..."
160
+ run 'patch', '-Np1', '-d', STATIC_OPENSSL_BUILDDIR.to_s,
161
+ '-i', File.expand_path( patchfile, BASEDIR )
162
+ end
120
163
  end
121
- end
122
164
 
123
- # generate the makefile in a clean build location
124
- file "#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}/Makefile" =>
125
- ["#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}"] do |t|
165
+ CMD_PRELUDE = [
166
+ 'env',
167
+ "CC=#{CROSS_PREFIX}-gcc",
168
+ "CFLAGS=-DDSO_WIN32",
169
+ "AR=#{CROSS_PREFIX}-ar",
170
+ "RANLIB=#{CROSS_PREFIX}-ranlib"
171
+ ]
126
172
 
127
- chdir File.dirname(t.name) do
128
- sh File.expand_path("Configure"), 'mingw'
173
+
174
+ # generate the makefile in a clean build location
175
+ file OPENSSL_MAKEFILE => STATIC_OPENSSL_BUILDDIR do |t|
176
+ Dir.chdir( STATIC_OPENSSL_BUILDDIR ) do
177
+ cmd = CMD_PRELUDE.dup
178
+ cmd << "./Configure" << 'mingw'
179
+
180
+ run( *cmd )
181
+ end
129
182
  end
130
- end
131
183
 
132
- # make
133
- file "#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}/libssleay32.a" => ["#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}/Makefile"] do |t|
134
- chdir File.dirname(t.prerequisites.first) do
135
- sh <<-EOT
136
- export cross=#{CROSS_PREFIX}- &&
137
- make -j#{NUM_CPUS} CC="${cross}gcc -DDSO_WIN32" AR="${cross}ar r" RANLIB="${cross}ranlib" build_libs &&
138
- cp libcrypto.a libeay32.a &&
139
- cp libssl.a libssleay32.a
140
- EOT
184
+ desc "compile static openssl libraries"
185
+ task :openssl_libs => [ LIBSSLEAY32, LIBEAY32 ]
186
+
187
+ task :compile_static_openssl => OPENSSL_MAKEFILE do |t|
188
+ Dir.chdir( STATIC_OPENSSL_BUILDDIR ) do
189
+ cmd = CMD_PRELUDE.dup
190
+ cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
191
+
192
+ run( *cmd )
193
+ end
141
194
  end
142
- end
143
195
 
144
- #desc 'compile static libssl.a'
145
- task 'openssl-make' => ["#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}/libssleay32.a"]
196
+ desc "compile static #{LIBEAY32}"
197
+ file LIBEAY32 => :compile_static_openssl do |t|
198
+ FileUtils.cp( STATIC_OPENSSL_BUILDDIR + 'libcrypto.a', LIBEAY32.to_s )
199
+ end
146
200
 
201
+ desc "compile static #{LIBSSLEAY32}"
202
+ file LIBSSLEAY32 => :compile_static_openssl do |t|
203
+ FileUtils.cp( STATIC_OPENSSL_BUILDDIR + 'libssl.a', LIBSSLEAY32.to_s )
204
+ end
147
205
 
148
- # define a location where sources will be stored
149
- directory "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}"
150
206
 
151
- # clean intermediate files and folders
152
- CLEAN.include("#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}")
153
207
 
208
+ #
209
+ # Static PostgreSQL build tasks
210
+ #
211
+ directory STATIC_POSTGRESQL_BUILDDIR.to_s
154
212
 
155
- # postgresql source file should be stored there
156
- file "#{COMPILE_HOME}/sources/postgresql-#{POSTGRESQL_VERSION}.tar.bz2" => ["#{COMPILE_HOME}/sources"] do |t|
157
- # download the source file using wget or curl
158
- chdir File.dirname(t.name) do
159
- #http://wwwmaster.postgresql.org/redir/53/h/source/v8.4.0/postgresql-8.4.0.tar.bz2
160
- url = "http://wwwmaster.postgresql.org/redir/53/h/source/v#{POSTGRESQL_VERSION}/#{File.basename(t.name)}"
161
- sh "wget #{url} || curl -O #{url}"
162
- end
163
- end
164
213
 
165
- # Extract the postgresql sources
166
- file "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}" => ["#{COMPILE_HOME}/sources/postgresql-#{POSTGRESQL_VERSION}.tar.bz2"] do |t|
167
- chdir File.dirname(t.name) do
168
- t.prerequisites.each { |f| sh "tar xfj ../sources/#{File.basename(f)}" }
214
+ # postgresql source file should be stored there
215
+ file POSTGRESQL_TARBALL => STATIC_SOURCESDIR do |t|
216
+ download( POSTGRESQL_SOURCE_URI, t.name )
169
217
  end
170
- end
171
218
 
172
- # generate the makefile in a clean build location
173
- file "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.global" =>
174
- ["#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}",
175
- "#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}/libssleay32.a"] do |t|
176
-
177
- options = [
178
- '--target=i386-mingw32',
179
- "--host=#{Rake::ExtensionCompiler.mingw_host}",
180
- '--with-openssl',
181
- '--without-zlib',
182
- '--disable-shared',
183
- ]
219
+ # Extract the postgresql sources
220
+ file STATIC_POSTGRESQL_BUILDDIR => POSTGRESQL_TARBALL do |t|
221
+ trace "extracting %s to %s" % [ POSTGRESQL_TARBALL, STATIC_POSTGRESQL_BUILDDIR.parent ]
222
+ STATIC_POSTGRESQL_BUILDDIR.mkpath
223
+ run 'tar', '-xzf', POSTGRESQL_TARBALL.to_s, '-C', STATIC_POSTGRESQL_BUILDDIR.parent.to_s
224
+ mv POSTGRESQL_SHLIB_MAKEFILE, POSTGRESQL_SHLIB_MF_ORIG
225
+ end
184
226
 
185
- chdir "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}" do
186
- configure_path = File.expand_path("#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/configure")
187
- sh <<-EOT
188
- export CFLAGS=-L#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION} &&
189
- export LDFLAGS=-L#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION} &&
190
- export LDFLAGS_SL=-L#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION} &&
191
- export "LIBS=-lwsock32 -lgdi32" &&
192
- export CPPFLAGS=-I#{COMPILE_HOME}/builds/openssl-#{OPENSSL_VERSION}/include &&
193
- #{configure_path} #{options.join(" ")}
194
- EOT
227
+ # generate the makefile in a clean build location
228
+ file POSTGRESQL_GLOBAL_MAKEFILE => [ STATIC_POSTGRESQL_BUILDDIR, :openssl_libs ] do |t|
229
+ options = [
230
+ '--target=i386-mingw32',
231
+ "--host=#{Rake::ExtensionCompiler.mingw_host}",
232
+ '--with-openssl',
233
+ '--without-zlib',
234
+ '--disable-shared',
235
+ ]
236
+
237
+ Dir.chdir( STATIC_POSTGRESQL_BUILDDIR ) do
238
+ configure_path = STATIC_POSTGRESQL_BUILDDIR + 'configure'
239
+ cmd = [ configure_path.to_s, *options ]
240
+ cmd << "CFLAGS=-L#{STATIC_OPENSSL_BUILDDIR}"
241
+ cmd << "LDFLAGS=-L#{STATIC_OPENSSL_BUILDDIR}"
242
+ cmd << "LDFLAGS_SL=-L#{STATIC_OPENSSL_BUILDDIR}"
243
+ cmd << "LIBS=-lwsock32 -lgdi32"
244
+ cmd << "CPPFLAGS=-I#{STATIC_OPENSSL_BUILDDIR}/include"
245
+
246
+ run( *cmd )
247
+ end
195
248
  end
196
- end
197
249
 
198
- # backup Makefile.shlib
199
- file "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.shlib.bak" => ["#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.global"] do |t|
200
- cp "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.shlib", t.name
201
- end
202
250
 
203
- # patch the Makefile.shlib
204
- file "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.shlib" => ["#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.shlib.bak"] do |t|
205
- content = File.open(t.name, 'rb') { |f| f.read }
251
+ # patch the Makefile.shlib -- depend on the build dir so it's only
252
+ # rewritten if the tarball is re-extracted.
253
+ file POSTGRESQL_SHLIB_MAKEFILE => POSTGRESQL_SHLIB_MF_ORIG do |t|
254
+ tf = Tempfile.new( POSTGRESQL_SHLIB_MAKEFILE.basename )
255
+ POSTGRESQL_SHLIB_MF_ORIG.open( File::RDONLY ) do |ifh|
256
+ ifh.each_line do |line|
257
+ tf.print( line.sub(/^(\s*haslibarule\s*=\s*yes)/, "# \\1 ") )
258
+ end
259
+ end
260
+ tf.close
206
261
 
207
- out = ""
262
+ FileUtils.mv( tf.path, t.name, :verbose => $trace )
263
+ end
208
264
 
209
- content.each_line do |line|
210
- if line =~ /^(\s*haslibarule\s*=\s*yes)/
211
- out << "##{$1}\n"
212
- else
213
- out << line
265
+
266
+ # make libpq.a
267
+ file POSTGRESQL_LIB => [ POSTGRESQL_GLOBAL_MAKEFILE, POSTGRESQL_SHLIB_MAKEFILE ] do |t|
268
+ Dir.chdir( POSTGRESQL_LIB.dirname ) do
269
+ sh 'make', "-j#{NUM_CPUS}", POSTGRESQL_LIB.basename.to_s, 'PORTNAME=win32'
214
270
  end
215
271
  end
216
272
 
217
- when_writing("Patching Makefile.shlib") {
218
- File.open(t.name, 'wb') { |f| f.write(out) }
219
- }
220
- end
221
273
 
274
+ #desc 'compile static libpg.a'
275
+ task :static_libpq => POSTGRESQL_LIB
222
276
 
223
- # make libpq.a
224
- file "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/interfaces/libpq/libpq.a" => ["#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.global", "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/Makefile.shlib"] do |t|
225
- chdir File.dirname(t.name) do
226
- sh "make -j#{NUM_CPUS} libpq.a PORTNAME=win32"
277
+ desc 'cross compile pg for win32'
278
+ task :cross do
279
+ ENV['CROSS_COMPILING'] = 'yes'
280
+ end
281
+ task :cross => [ :mingw32, :static_libpq ]
282
+
283
+ task :mingw32 do
284
+ # Use Rake::ExtensionCompiler helpers to find the proper host
285
+ unless Rake::ExtensionCompiler.mingw_host then
286
+ warn "You need to install mingw32 cross compile functionality to be able to continue."
287
+ warn "Please refer to your distribution/package manager documentation about installation."
288
+ fail
289
+ end
227
290
  end
228
- end
229
-
230
- #desc 'compile static libpg.a'
231
- task 'postgresql-make' => ['openssl-make', "#{COMPILE_HOME}/builds/postgresql-#{POSTGRESQL_VERSION}/src/interfaces/libpq/libpq.a"]
232
-
233
- desc 'cross compile pg for win32'
234
- task 'cross' => [:mingw32, 'postgresql-make']
235
291
 
236
- task :mingw32 do
237
- # Use Rake::ExtensionCompiler helpers to find the proper host
238
- unless Rake::ExtensionCompiler.mingw_host then
239
- warn "You need to install mingw32 cross compile functionality to be able to continue."
240
- warn "Please refer to your distribution/package manager documentation about installation."
292
+ rescue LoadError => err
293
+ task :no_rake_compiler do
294
+ log "You'll need to install rake-compiler to compile this."
241
295
  fail
242
296
  end
297
+
298
+ task :compile => :no_rake_compiler
299
+ task :cross => :no_rake_compiler
300
+ task :mingw32 => :no_rake_compiler
301
+ task :static_libpq => :no_rake_compiler
302
+ end
303
+
304
+
305
+ desc "Stop any Postmaster instances that remain after testing."
306
+ task :cleanup_testing_dbs do
307
+ require 'spec/lib/helpers'
308
+ PgTestingHelpers.stop_existing_postmasters()
309
+ Rake::Task[:clean].invoke
243
310
  end
311
+
312
+