pg 0.18.4 → 1.4.3

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.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.appveyor.yml +36 -0
  4. data/.gems +6 -0
  5. data/.github/workflows/binary-gems.yml +86 -0
  6. data/.github/workflows/source-gem.yml +129 -0
  7. data/.gitignore +13 -0
  8. data/.hgsigs +34 -0
  9. data/.hgtags +41 -0
  10. data/.irbrc +23 -0
  11. data/.pryrc +23 -0
  12. data/.tm_properties +21 -0
  13. data/.travis.yml +49 -0
  14. data/BSDL +2 -2
  15. data/Gemfile +14 -0
  16. data/History.rdoc +436 -4
  17. data/Manifest.txt +8 -21
  18. data/README-Windows.rdoc +4 -4
  19. data/README.ja.rdoc +1 -2
  20. data/README.rdoc +67 -17
  21. data/Rakefile +32 -144
  22. data/Rakefile.cross +70 -69
  23. data/certs/ged.pem +24 -0
  24. data/certs/larskanis-2022.pem +26 -0
  25. data/ext/errorcodes.def +109 -0
  26. data/ext/errorcodes.rb +1 -1
  27. data/ext/errorcodes.txt +35 -2
  28. data/ext/extconf.rb +119 -54
  29. data/ext/gvl_wrappers.c +8 -0
  30. data/ext/gvl_wrappers.h +44 -33
  31. data/ext/pg.c +213 -171
  32. data/ext/pg.h +92 -98
  33. data/ext/pg_binary_decoder.c +82 -15
  34. data/ext/pg_binary_encoder.c +20 -19
  35. data/ext/pg_coder.c +175 -39
  36. data/ext/pg_connection.c +1730 -1135
  37. data/ext/pg_copy_coder.c +94 -27
  38. data/ext/pg_record_coder.c +521 -0
  39. data/ext/pg_result.c +640 -221
  40. data/ext/pg_text_decoder.c +606 -40
  41. data/ext/pg_text_encoder.c +250 -99
  42. data/ext/pg_tuple.c +569 -0
  43. data/ext/pg_type_map.c +55 -15
  44. data/ext/pg_type_map_all_strings.c +19 -5
  45. data/ext/pg_type_map_by_class.c +54 -24
  46. data/ext/pg_type_map_by_column.c +73 -34
  47. data/ext/pg_type_map_by_mri_type.c +48 -19
  48. data/ext/pg_type_map_by_oid.c +55 -25
  49. data/ext/pg_type_map_in_ruby.c +51 -20
  50. data/ext/{util.c → pg_util.c} +12 -12
  51. data/ext/{util.h → pg_util.h} +2 -2
  52. data/lib/pg/basic_type_map_based_on_result.rb +47 -0
  53. data/lib/pg/basic_type_map_for_queries.rb +193 -0
  54. data/lib/pg/basic_type_map_for_results.rb +81 -0
  55. data/lib/pg/basic_type_registry.rb +301 -0
  56. data/lib/pg/binary_decoder.rb +23 -0
  57. data/lib/pg/coder.rb +24 -3
  58. data/lib/pg/connection.rb +723 -65
  59. data/lib/pg/constants.rb +2 -1
  60. data/lib/pg/exceptions.rb +9 -2
  61. data/lib/pg/result.rb +24 -7
  62. data/lib/pg/text_decoder.rb +24 -22
  63. data/lib/pg/text_encoder.rb +40 -8
  64. data/lib/pg/tuple.rb +30 -0
  65. data/lib/pg/type_map_by_column.rb +3 -2
  66. data/lib/pg/version.rb +4 -0
  67. data/lib/pg.rb +61 -36
  68. data/misc/openssl-pg-segfault.rb +31 -0
  69. data/misc/postgres/History.txt +9 -0
  70. data/misc/postgres/Manifest.txt +5 -0
  71. data/misc/postgres/README.txt +21 -0
  72. data/misc/postgres/Rakefile +21 -0
  73. data/misc/postgres/lib/postgres.rb +16 -0
  74. data/misc/ruby-pg/History.txt +9 -0
  75. data/misc/ruby-pg/Manifest.txt +5 -0
  76. data/misc/ruby-pg/README.txt +21 -0
  77. data/misc/ruby-pg/Rakefile +21 -0
  78. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  79. data/pg.gemspec +32 -0
  80. data/rakelib/task_extension.rb +46 -0
  81. data/sample/array_insert.rb +1 -1
  82. data/sample/async_api.rb +4 -8
  83. data/sample/async_copyto.rb +1 -1
  84. data/sample/async_mixed.rb +1 -1
  85. data/sample/check_conn.rb +1 -1
  86. data/sample/copydata.rb +71 -0
  87. data/sample/copyfrom.rb +1 -1
  88. data/sample/copyto.rb +1 -1
  89. data/sample/cursor.rb +1 -1
  90. data/sample/disk_usage_report.rb +6 -15
  91. data/sample/issue-119.rb +2 -2
  92. data/sample/losample.rb +1 -1
  93. data/sample/minimal-testcase.rb +2 -2
  94. data/sample/notify_wait.rb +1 -1
  95. data/sample/pg_statistics.rb +6 -15
  96. data/sample/replication_monitor.rb +9 -18
  97. data/sample/test_binary_values.rb +1 -1
  98. data/sample/wal_shipper.rb +2 -2
  99. data/sample/warehouse_partitions.rb +8 -17
  100. data.tar.gz.sig +0 -0
  101. metadata +79 -225
  102. metadata.gz.sig +0 -0
  103. data/ChangeLog +0 -5911
  104. data/lib/pg/basic_type_mapping.rb +0 -399
  105. data/spec/data/expected_trace.out +0 -26
  106. data/spec/data/random_binary_data +0 -0
  107. data/spec/helpers.rb +0 -355
  108. data/spec/pg/basic_type_mapping_spec.rb +0 -251
  109. data/spec/pg/connection_spec.rb +0 -1544
  110. data/spec/pg/result_spec.rb +0 -449
  111. data/spec/pg/type_map_by_class_spec.rb +0 -138
  112. data/spec/pg/type_map_by_column_spec.rb +0 -222
  113. data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
  114. data/spec/pg/type_map_by_oid_spec.rb +0 -149
  115. data/spec/pg/type_map_in_ruby_spec.rb +0 -164
  116. data/spec/pg/type_map_spec.rb +0 -22
  117. data/spec/pg/type_spec.rb +0 -697
  118. data/spec/pg_spec.rb +0 -50
data/README.rdoc CHANGED
@@ -1,8 +1,8 @@
1
1
  = pg
2
2
 
3
- home :: https://bitbucket.org/ged/ruby-pg
4
- mirror :: https://github.com/ged/ruby-pg
3
+ home :: https://github.com/ged/ruby-pg
5
4
  docs :: http://deveiate.org/code/pg
5
+ clog :: link:/History.rdoc
6
6
 
7
7
  {<img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/ged/ruby-pg">}[https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
8
8
 
@@ -11,7 +11,7 @@ docs :: http://deveiate.org/code/pg
11
11
 
12
12
  Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
13
13
 
14
- It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/].
14
+ It works with {PostgreSQL 9.3 and later}[http://www.postgresql.org/support/versioning/].
15
15
 
16
16
  A small example usage:
17
17
 
@@ -23,27 +23,38 @@ A small example usage:
23
23
  conn = PG.connect( dbname: 'sales' )
24
24
  conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
25
25
  puts " PID | User | Query"
26
- result.each do |row|
26
+ result.each do |row|
27
27
  puts " %7d | %-16s | %s " %
28
- row.values_at('procpid', 'usename', 'current_query')
28
+ row.values_at('pid', 'usename', 'query')
29
29
  end
30
30
  end
31
31
 
32
32
  == Build Status
33
33
 
34
- {<img src="https://travis-ci.org/ged/ruby-pg.png?branch=master" alt="Build Status Travis-CI" />}[https://travis-ci.org/ged/ruby-pg]
35
- {<img src="https://ci.appveyor.com/api/projects/status/at4g4swb2cd4xji7/branch/master?svg=true" alt="Build Status Appveyor" />}[https://ci.appveyor.com/project/ged/ruby-pg]
36
-
34
+ {<img src="https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml/badge.svg?branch=master" alt="Build Status Github Actions" />}[https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml]
35
+ {<img src="https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true" alt="Build Status Appveyor" />}[https://ci.appveyor.com/project/ged/ruby-pg-9j8l3]
36
+ {<img src="https://app.travis-ci.com/larskanis/ruby-pg.svg?branch=master" alt="Build Status" />}[https://app.travis-ci.com/larskanis/ruby-pg]
37
37
 
38
38
  == Requirements
39
39
 
40
- * Ruby 1.9.3-p392, or 2.0.0-p0.
41
- * PostgreSQL 8.4.x or later (with headers, -dev packages, etc).
40
+ * Ruby 2.4 or newer
41
+ * PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
42
42
 
43
- It may work with earlier versions of Ruby/PostgreSQL as well, but those are
43
+ It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
44
44
  not regularly tested.
45
45
 
46
46
 
47
+ == Versioning
48
+
49
+ We tag and release gems according to the {Semantic Versioning}[http://semver.org/] principle.
50
+
51
+ As a result of this policy, you can (and should) specify a dependency on this gem using the {Pessimistic Version Constraint}[http://guides.rubygems.org/patterns/#pessimistic-version-constraint] with two digits of precision.
52
+
53
+ For example:
54
+
55
+ spec.add_dependency 'pg', '~> 1.0'
56
+
57
+
47
58
  == How To Install
48
59
 
49
60
  Install via RubyGems:
@@ -66,6 +77,10 @@ There's also {a Google+ group}[http://goo.gl/TFy1U] and a
66
77
  {mailing list}[http://groups.google.com/group/ruby-pg] if you get stuck, or just
67
78
  want to chat about something.
68
79
 
80
+ If you want to install as a signed gem, the public certs of the gem signers
81
+ can be found in {the `certs` directory}[https://github.com/ged/ruby-pg/tree/master/certs]
82
+ of the repository.
83
+
69
84
 
70
85
  == Type Casts
71
86
 
@@ -103,6 +118,30 @@ to build composite types by assigning an element encoder/decoder.
103
118
  PG::Coder objects can be used to set up a PG::TypeMap or alternatively
104
119
  to convert single values to/from their string representation.
105
120
 
121
+ The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
122
+ * Integer: {TE}[rdoc-ref:PG::TextEncoder::Integer], {TD}[rdoc-ref:PG::TextDecoder::Integer], {BD}[rdoc-ref:PG::BinaryDecoder::Integer] 💡 No links? Switch to {here}[https://deveiate.org/code/pg/README_rdoc.html#label-Type+Casts] 💡
123
+ * BE: {Int2}[rdoc-ref:PG::BinaryEncoder::Int2], {Int4}[rdoc-ref:PG::BinaryEncoder::Int4], {Int8}[rdoc-ref:PG::BinaryEncoder::Int8]
124
+ * Float: {TE}[rdoc-ref:PG::TextEncoder::Float], {TD}[rdoc-ref:PG::TextDecoder::Float], {BD}[rdoc-ref:PG::BinaryDecoder::Float]
125
+ * Numeric: {TE}[rdoc-ref:PG::TextEncoder::Numeric], {TD}[rdoc-ref:PG::TextDecoder::Numeric]
126
+ * Boolean: {TE}[rdoc-ref:PG::TextEncoder::Boolean], {TD}[rdoc-ref:PG::TextDecoder::Boolean], {BE}[rdoc-ref:PG::BinaryEncoder::Boolean], {BD}[rdoc-ref:PG::BinaryDecoder::Boolean]
127
+ * String: {TE}[rdoc-ref:PG::TextEncoder::String], {TD}[rdoc-ref:PG::TextDecoder::String], {BE}[rdoc-ref:PG::BinaryEncoder::String], {BD}[rdoc-ref:PG::BinaryDecoder::String]
128
+ * Bytea: {TE}[rdoc-ref:PG::TextEncoder::Bytea], {TD}[rdoc-ref:PG::TextDecoder::Bytea], {BE}[rdoc-ref:PG::BinaryEncoder::Bytea], {BD}[rdoc-ref:PG::BinaryDecoder::Bytea]
129
+ * Base64: {TE}[rdoc-ref:PG::TextEncoder::ToBase64], {TD}[rdoc-ref:PG::TextDecoder::FromBase64], {BE}[rdoc-ref:PG::BinaryEncoder::FromBase64], {BD}[rdoc-ref:PG::BinaryDecoder::ToBase64]
130
+ * Timestamp:
131
+ * TE: {local}[rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone], {UTC}[rdoc-ref:PG::TextEncoder::TimestampUtc], {with-TZ}[rdoc-ref:PG::TextEncoder::TimestampWithTimeZone]
132
+ * TD: {local}[rdoc-ref:PG::TextDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::TextDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::TextDecoder::TimestampUtcToLocal]
133
+ * BD: {local}[rdoc-ref:PG::BinaryDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::BinaryDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal]
134
+ * Date: {TE}[rdoc-ref:PG::TextEncoder::Date], {TD}[rdoc-ref:PG::TextDecoder::Date]
135
+ * JSON and JSONB: {TE}[rdoc-ref:PG::TextEncoder::JSON], {TD}[rdoc-ref:PG::TextDecoder::JSON]
136
+ * Inet: {TE}[rdoc-ref:PG::TextEncoder::Inet], {TD}[rdoc-ref:PG::TextDecoder::Inet]
137
+ * Array: {TE}[rdoc-ref:PG::TextEncoder::Array], {TD}[rdoc-ref:PG::TextDecoder::Array]
138
+ * Composite Type (also called "Row" or "Record"): {TE}[rdoc-ref:PG::TextEncoder::Record], {TD}[rdoc-ref:PG::TextDecoder::Record]
139
+
140
+ The following text formats can also be encoded although they are not used as column type:
141
+ * COPY input and output data: {TE}[rdoc-ref:PG::TextEncoder::CopyRow], {TD}[rdoc-ref:PG::TextDecoder::CopyRow]
142
+ * Literal for insertion into SQL string: {TE}[rdoc-ref:PG::TextEncoder::QuotedLiteral]
143
+ * SQL-Identifier: {TE}[rdoc-ref:PG::TextEncoder::Identifier], {TD}[rdoc-ref:PG::TextDecoder::Identifier]
144
+
106
145
  === PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
107
146
 
108
147
  A TypeMap defines which value will be converted by which encoder/decoder.
@@ -112,13 +151,25 @@ needs for type casting. The default type map is PG::TypeMapAllStrings.
112
151
 
113
152
  A type map can be assigned per connection or per query respectively per
114
153
  result set. Type maps can also be used for COPY in and out data streaming.
154
+ See PG::Connection#copy_data .
155
+
156
+ The following base type maps are available:
157
+ * PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
158
+ * PG::TypeMapByClass - selects encoder based on the class of the value to be sent
159
+ * PG::TypeMapByColumn - selects encoder and decoder by column order
160
+ * PG::TypeMapByOid - selects decoder by PostgreSQL type OID
161
+ * PG::TypeMapInRuby - define a custom type map in ruby
162
+
163
+ The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
164
+ * PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
165
+ * PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
166
+ * PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
115
167
 
116
168
 
117
169
  == Contributing
118
170
 
119
- To report bugs, suggest features, or check out the source with Mercurial,
120
- {check out the project page}[http://bitbucket.org/ged/ruby-pg]. If you prefer
121
- Git, there's also a {Github mirror}[https://github.com/ged/ruby-pg].
171
+ To report bugs, suggest features, or check out the source with Git,
172
+ {check out the project page}[https://github.com/ged/ruby-pg].
122
173
 
123
174
  After checking out the source, run:
124
175
 
@@ -133,7 +184,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
133
184
 
134
185
  == Copying
135
186
 
136
- Copyright (c) 1997-2015 by the authors.
187
+ Copyright (c) 1997-2019 by the authors.
137
188
 
138
189
  * Jeff Davis <ruby-pg@j-davis.com>
139
190
  * Guy Decoux (ts) <decoux@moulon.inra.fr>
@@ -145,7 +196,7 @@ Copyright (c) 1997-2015 by the authors.
145
196
  * Noboru Saitou <noborus@netlab.jp>
146
197
 
147
198
  You may redistribute this software under the same terms as Ruby itself; see
148
- http://www.ruby-lang.org/en/LICENSE.txt or the LICENSE file in the source
199
+ https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
149
200
  for details.
150
201
 
151
202
  Portions of the code are from the PostgreSQL project, and are distributed
@@ -161,4 +212,3 @@ to this library over the years.
161
212
 
162
213
  We are thankful to the people at the ruby-list and ruby-dev mailing lists.
163
214
  And to the people who developed PostgreSQL.
164
-
data/Rakefile CHANGED
@@ -1,22 +1,13 @@
1
- #!/usr/bin/env rake
1
+ # -*- rake -*-
2
2
 
3
3
  require 'rbconfig'
4
4
  require 'pathname'
5
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
-
6
+ require 'rake/extensiontask'
19
7
  require 'rake/clean'
8
+ require 'rspec/core/rake_task'
9
+ require 'bundler'
10
+ require 'bundler/gem_helper'
20
11
 
21
12
  # Build directory constants
22
13
  BASEDIR = Pathname( __FILE__ ).dirname
@@ -25,98 +16,38 @@ LIBDIR = BASEDIR + 'lib'
25
16
  EXTDIR = BASEDIR + 'ext'
26
17
  PKGDIR = BASEDIR + 'pkg'
27
18
  TMPDIR = BASEDIR + 'tmp'
19
+ TESTDIR = BASEDIR + "tmp_test_specs"
28
20
 
29
21
  DLEXT = RbConfig::CONFIG['DLEXT']
30
22
  EXT = LIBDIR + "pg_ext.#{DLEXT}"
31
23
 
32
24
  GEMSPEC = 'pg.gemspec'
33
25
 
34
- TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
35
-
36
- CLOBBER.include( TEST_DIRECTORY.to_s )
26
+ CLOBBER.include( TESTDIR.to_s )
37
27
  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
28
+ CLEAN.include "lib/*/libpq.dll"
29
+ CLEAN.include "lib/pg_ext.*"
30
+ CLEAN.include "lib/pg/postgresql_lib_path.rb"
47
31
 
48
32
  load 'Rakefile.cross'
49
33
 
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
59
-
60
- self.developer 'Michael Granger', 'ged@FaerieMUD.org'
61
- self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
62
-
63
- self.dependency 'rake-compiler', '~> 0.9', :developer
64
- self.dependency 'rake-compiler-dock', '~> 0.3', :developer
65
- self.dependency 'hoe', '~> 3.12', :developer
66
- self.dependency 'hoe-deveiate', '~> 0.6', :developer
67
- self.dependency 'hoe-bundler', '~> 1.0', :developer
68
- self.dependency 'rspec', '~> 3.0', :developer
69
-
70
- self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL']
71
- self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
72
-
73
- self.require_ruby_version( '>= 1.9.3' )
74
-
75
- self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
76
- self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
77
-
78
- self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
79
- end
80
-
81
- ENV['VERSION'] ||= $hoespec.spec.version.to_s
82
-
83
- # Tests should pass before checking in
84
- task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
85
-
86
- # Support for 'rvm specs'
87
- task :specs => :spec
88
-
89
- # Compile before testing
90
- task :spec => :compile
91
-
92
- # gem-testers support
93
- task :test do
94
- # rake-compiler always wants to copy the compiled extension into lib/, but
95
- # we don't want testers to have to re-compile, especially since that
96
- # often fails because they can't (and shouldn't have to) write to tmp/ in
97
- # the installed gem dir. So we clear the task rake-compiler set up
98
- # to break the dependency between :spec and :compile when running under
99
- # rubygems-test, and then run :spec.
100
- Rake::Task[ EXT.to_s ].clear
101
- Rake::Task[ :spec ].execute
102
- end
34
+ Bundler::GemHelper.install_tasks
35
+ $gem_spec = Bundler.load_gemspec(GEMSPEC)
103
36
 
104
37
  desc "Turn on warnings and debugging in the build."
105
38
  task :maint do
106
39
  ENV['MAINTAINER_MODE'] = 'yes'
107
40
  end
108
41
 
109
- ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2:2.0.0'
110
-
111
42
  # Rake-compiler task
112
43
  Rake::ExtensionTask.new do |ext|
113
44
  ext.name = 'pg_ext'
114
- ext.gem_spec = $hoespec.spec
45
+ ext.gem_spec = $gem_spec
115
46
  ext.ext_dir = 'ext'
116
47
  ext.lib_dir = 'lib'
117
48
  ext.source_pattern = "*.{c,h}"
118
49
  ext.cross_compile = true
119
- ext.cross_platform = CrossLibraries.map &:for_platform
50
+ ext.cross_platform = CrossLibraries.map(&:for_platform)
120
51
 
121
52
  ext.cross_config_options += CrossLibraries.map do |lib|
122
53
  {
@@ -132,68 +63,40 @@ Rake::ExtensionTask.new do |ext|
132
63
 
133
64
  # Add libpq.dll to windows binary gemspec
134
65
  ext.cross_compiling do |spec|
135
- # mingw32-platform strings differ (RUBY_PLATFORM=i386-mingw32 vs. x86-mingw32 for rubygems)
136
- spec.files << "lib/#{spec.platform.to_s.gsub(/^x86-/, "i386-")}/libpq.dll"
66
+ spec.files << "lib/#{spec.platform}/libpq.dll"
137
67
  end
138
68
  end
139
69
 
70
+ RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
71
+ task :test => :spec
140
72
 
141
73
  # Use the fivefish formatter for docs generated from development checkout
142
- if File.directory?( '.hg' )
143
- require 'rdoc/task'
144
-
145
- Rake::Task[ 'docs' ].clear
146
- RDoc::Task.new( 'docs' ) do |rdoc|
147
- rdoc.main = "README.rdoc"
148
- rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb", 'ext/**/*.{c,h}' )
149
- rdoc.generator = :fivefish
150
- rdoc.title = "PG: The Ruby PostgreSQL Driver"
151
- rdoc.rdoc_dir = 'doc'
152
- end
153
- end
154
-
155
-
156
- # Make the ChangeLog update if the repo has changed since it was last built
157
- file '.hg/branch' do
158
- warn "WARNING: You need the Mercurial repo to update the ChangeLog"
74
+ require 'rdoc/task'
75
+
76
+ RDoc::Task.new( 'docs' ) do |rdoc|
77
+ rdoc.main = "README.rdoc"
78
+ rdoc.rdoc_files.include( "*.rdoc", "lib/**/*.rb", 'ext/**/*.{c,h}' )
79
+ rdoc.generator = :fivefish
80
+ rdoc.title = "PG: The Ruby PostgreSQL Driver"
81
+ rdoc.rdoc_dir = 'doc'
159
82
  end
160
- file 'ChangeLog' do |task|
161
- if File.exist?('.hg/branch')
162
- $stderr.puts "Updating the changelog..."
163
- begin
164
- include Hoe::MercurialHelpers
165
- content = make_changelog()
166
- rescue NameError
167
- abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
168
- end
169
- File.open( task.name, 'w', 0644 ) do |fh|
170
- fh.print( content )
171
- end
172
- else
173
- touch 'ChangeLog'
174
- end
175
- end
176
-
177
- # Rebuild the ChangeLog immediately before release
178
- task :prerelease => 'ChangeLog'
179
83
 
84
+ desc "Build the source gem #{$gem_spec.full_name}.gem into the pkg directory"
85
+ task :gem => :build
180
86
 
181
- desc "Stop any Postmaster instances that remain after testing."
182
- task :cleanup_testing_dbs do
183
- require 'spec/lib/helpers'
184
- PgTestingHelpers.stop_existing_postmasters()
185
- Rake::Task[:clean].invoke
87
+ task :clobber do
88
+ puts "Stop any Postmaster instances that remain after testing."
89
+ require_relative 'spec/helpers'
90
+ PG::TestingHelpers.stop_existing_postmasters()
186
91
  end
187
92
 
188
93
  desc "Update list of server error codes"
189
94
  task :update_error_codes do
190
- URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=HEAD"
95
+ URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_14_0"
191
96
 
192
97
  ERRORCODES_TXT = "ext/errorcodes.txt"
193
98
  sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
194
- end
195
99
 
196
- file 'ext/errorcodes.def' => ['ext/errorcodes.rb', 'ext/errorcodes.txt'] do
197
100
  ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
198
101
  end
199
102
 
@@ -201,18 +104,3 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
201
104
  # trigger compilation of changed errorcodes.def
202
105
  touch 'ext/pg_errors.c'
203
106
  end
204
-
205
- task :gemspec => GEMSPEC
206
- file GEMSPEC => __FILE__
207
- task GEMSPEC do |task|
208
- spec = $hoespec.spec
209
- spec.files.delete( '.gemtest' )
210
- spec.version = "#{spec.version}.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
211
- File.open( task.name, 'w' ) do |fh|
212
- fh.write( spec.to_ruby )
213
- end
214
- end
215
-
216
- CLOBBER.include( GEMSPEC.to_s )
217
- task :default => :gemspec
218
-
data/Rakefile.cross CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rake
1
+ # -*- rake -*-
2
2
 
3
3
  require 'uri'
4
4
  require 'tempfile'
@@ -7,6 +7,7 @@ require 'rake/clean'
7
7
  require 'rake/extensiontask'
8
8
  require 'rake/extensioncompiler'
9
9
  require 'ostruct'
10
+ require_relative 'rakelib/task_extension'
10
11
 
11
12
  MISCDIR = BASEDIR + 'misc'
12
13
 
@@ -20,6 +21,7 @@ end
20
21
 
21
22
  class CrossLibrary < OpenStruct
22
23
  include Rake::DSL
24
+ prepend TaskExtension
23
25
 
24
26
  def initialize(for_platform, openssl_config, toolchain)
25
27
  super()
@@ -29,15 +31,15 @@ class CrossLibrary < OpenStruct
29
31
  self.host_platform = toolchain
30
32
 
31
33
  # Cross-compilation constants
32
- self.openssl_version = ENV['OPENSSL_VERSION'] || '1.0.2d'
33
- self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '9.4.4'
34
+ self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.1q'
35
+ self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '14.4'
34
36
 
35
37
  # Check if symlinks work in the current working directory.
36
38
  # This fails, if rake-compiler-dock is running on a Windows box.
37
39
  begin
38
40
  FileUtils.rm_f '.test_symlink'
39
41
  FileUtils.ln_s '/', '.test_symlink'
40
- rescue SystemCallError
42
+ rescue NotImplementedError, SystemCallError
41
43
  # Symlinks don't work -> use home directory instead
42
44
  self.compile_home = Pathname( "~/.ruby-pg-build" ).expand_path
43
45
  else
@@ -45,6 +47,8 @@ class CrossLibrary < OpenStruct
45
47
  end
46
48
  self.static_sourcesdir = compile_home + 'sources'
47
49
  self.static_builddir = compile_home + 'builds' + for_platform
50
+ CLOBBER.include( static_sourcesdir )
51
+ CLEAN.include( static_builddir )
48
52
 
49
53
  # Static OpenSSL build vars
50
54
  self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
@@ -54,8 +58,8 @@ class CrossLibrary < OpenStruct
54
58
  self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
55
59
  self.openssl_makefile = static_openssl_builddir + 'Makefile'
56
60
 
57
- self.libssleay32 = static_openssl_builddir + 'libssleay32.a'
58
- self.libeay32 = static_openssl_builddir + 'libeay32.a'
61
+ self.libssl = static_openssl_builddir + 'libssl.a'
62
+ self.libcrypto = static_openssl_builddir + 'libcrypto.a'
59
63
 
60
64
  self.openssl_patches = Rake::FileList[ (MISCDIR + "openssl-#{openssl_version}.*.patch").to_s ]
61
65
 
@@ -81,19 +85,6 @@ class CrossLibrary < OpenStruct
81
85
  # clean intermediate files and folders
82
86
  CLEAN.include( static_builddir.to_s )
83
87
 
84
-
85
- ENV['RUBY_CC_VERSION'] ||= '1.9.3:2.0.0'
86
-
87
- def download(url, save_to)
88
- part = save_to+".part"
89
- sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
90
- FileUtils.mv part, save_to
91
- end
92
-
93
- def run(*args)
94
- sh *args
95
- end
96
-
97
88
  #####################################################################
98
89
  ### C R O S S - C O M P I L A T I O N - T A S K S
99
90
  #####################################################################
@@ -126,11 +117,9 @@ class CrossLibrary < OpenStruct
126
117
  end
127
118
 
128
119
  self.cmd_prelude = [
129
- 'env',
130
- "CC=#{host_platform}-gcc",
120
+ "env",
121
+ "CROSS_COMPILE=#{host_platform}-",
131
122
  "CFLAGS=-DDSO_WIN32",
132
- "AR=#{host_platform}-ar",
133
- "RANLIB=#{host_platform}-ranlib"
134
123
  ]
135
124
 
136
125
 
@@ -145,9 +134,9 @@ class CrossLibrary < OpenStruct
145
134
  end
146
135
 
147
136
  desc "compile static openssl libraries"
148
- task :openssl_libs => [ libssleay32, libeay32 ]
137
+ task "openssl_libs:#{for_platform}" => [ libssl, libcrypto ]
149
138
 
150
- task :compile_static_openssl => openssl_makefile do |t|
139
+ task "compile_static_openssl:#{for_platform}" => openssl_makefile do |t|
151
140
  chdir( static_openssl_builddir ) do
152
141
  cmd = cmd_prelude.dup
153
142
  cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
@@ -156,14 +145,14 @@ class CrossLibrary < OpenStruct
156
145
  end
157
146
  end
158
147
 
159
- desc "compile static #{libeay32}"
160
- file libeay32 => :compile_static_openssl do |t|
161
- FileUtils.cp( static_openssl_builddir + 'libcrypto.a', libeay32.to_s )
148
+ desc "compile static #{libssl}"
149
+ file libssl => "compile_static_openssl:#{for_platform}" do |t|
150
+ rm t.name.gsub(/\.a$/, ".dll.a")
162
151
  end
163
152
 
164
- desc "compile static #{libssleay32}"
165
- file libssleay32 => :compile_static_openssl do |t|
166
- FileUtils.cp( static_openssl_builddir + 'libssl.a', libssleay32.to_s )
153
+ desc "compile static #{libcrypto}"
154
+ file libcrypto => "compile_static_openssl:#{for_platform}" do |t|
155
+ rm t.name.gsub(/\.a$/, ".dll.a")
167
156
  end
168
157
 
169
158
 
@@ -193,7 +182,7 @@ class CrossLibrary < OpenStruct
193
182
  end
194
183
 
195
184
  # generate the makefile in a clean build location
196
- file postgresql_global_makefile => [ static_postgresql_builddir, :openssl_libs ] do |t|
185
+ file postgresql_global_makefile => [ static_postgresql_builddir, "openssl_libs:#{for_platform}" ] do |t|
197
186
  options = [
198
187
  "--target=#{host_platform}",
199
188
  "--host=#{host_platform}",
@@ -207,7 +196,7 @@ class CrossLibrary < OpenStruct
207
196
  cmd << "CFLAGS=-L#{static_openssl_builddir}"
208
197
  cmd << "LDFLAGS=-L#{static_openssl_builddir}"
209
198
  cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
210
- cmd << "LIBS=-lwsock32 -lgdi32"
199
+ cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32"
211
200
  cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
212
201
 
213
202
  run( *cmd )
@@ -221,18 +210,21 @@ class CrossLibrary < OpenStruct
221
210
  chdir( static_postgresql_srcdir + "common" ) do
222
211
  sh 'make', "-j#{NUM_CPUS}"
223
212
  end
213
+ chdir( static_postgresql_srcdir + "port" ) do
214
+ sh 'make', "-j#{NUM_CPUS}"
215
+ end
224
216
 
225
217
  chdir( postgresql_lib.dirname ) do
226
218
  sh 'make',
227
219
  "-j#{NUM_CPUS}",
228
220
  postgresql_lib.basename.to_s,
229
- 'SHLIB_LINK=-lssleay32 -leay32 -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
221
+ 'SHLIB_LINK=-lssl -lcrypto -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
230
222
  end
231
223
  end
232
224
 
233
225
 
234
226
  #desc 'compile libpg.a'
235
- task :libpq => postgresql_lib
227
+ task "native:#{for_platform}" => postgresql_lib
236
228
 
237
229
  # copy libpq.dll to lib dir
238
230
  dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
@@ -247,22 +239,28 @@ class CrossLibrary < OpenStruct
247
239
  cp postgresql_lib, stage_libpq
248
240
  end
249
241
  end
250
- end
251
242
 
252
- if File.exist?(File.expand_path("~/.rake-compiler/config.yml"))
253
- CrossLibraries = [
254
- ['i386-mingw32', 'mingw', 'i686-w64-mingw32'],
255
- ['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
256
- ].map do |platform, openssl_config, toolchain|
257
- CrossLibrary.new platform, openssl_config, toolchain
243
+ def download(url, save_to)
244
+ part = save_to+".part"
245
+ sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
246
+ FileUtils.mv part, save_to
247
+ end
248
+
249
+ def run(*args)
250
+ sh(*args)
258
251
  end
259
- else
260
- $stderr.puts "Cross-compilation disabled -- rake-compiler not properly installed"
261
- CrossLibraries = []
252
+ end
253
+
254
+ CrossLibraries = [
255
+ ['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
256
+ ['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
257
+ ['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
258
+ ].map do |platform, openssl_config, toolchain|
259
+ CrossLibrary.new platform, openssl_config, toolchain
262
260
  end
263
261
 
264
262
  desc 'cross compile pg for win32'
265
- task :cross => [ :mingw32, :libpq ]
263
+ task :cross => [ :mingw32 ]
266
264
 
267
265
  task :mingw32 do
268
266
  # Use Rake::ExtensionCompiler helpers to find the proper host
@@ -273,29 +271,32 @@ task :mingw32 do
273
271
  end
274
272
  end
275
273
 
276
- # To reduce the gem file size strip mingw32 dlls before packaging
277
- ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
278
- task "tmp/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so" do |t|
279
- sh "i686-w64-mingw32-strip -S tmp/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so"
280
- end
281
-
282
- task "tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so" do |t|
283
- sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/pg_ext.so"
284
- end
274
+ task 'gem:windows:prepare' do
275
+ require 'io/console'
276
+ require 'rake_compiler_dock'
277
+
278
+ # Copy gem signing key and certs to be accessible from the docker container
279
+ mkdir_p 'build/gem'
280
+ sh "cp ~/.gem/gem-*.pem build/gem/ || true"
281
+ sh "bundle package"
282
+ begin
283
+ OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
284
+ rescue OpenSSL::PKey::PKeyError
285
+ ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
286
+ retry
287
+ end
285
288
  end
286
289
 
287
- desc "Build the windows binary gems"
288
- task 'gem:windows' => ['ChangeLog'] do
289
- require 'rake_compiler_dock'
290
-
291
- # Copy gem signing key and certs to be accessable from the docker container
292
- mkdir_p 'build/gem'
293
- sh "cp ~/.gem/gem-*.pem build/gem/"
294
-
295
- RakeCompilerDock.sh <<-EOT
296
- mkdir ~/.gem &&
297
- cp build/gem/gem-*.pem ~/.gem/ &&
298
- bundle install &&
299
- rake cross native gem RUBYOPT=--disable-rubygems RUBY_CC_VERSION=1.9.3:2.0.0:2.1.6:2.2.2
300
- EOT
290
+ CrossLibraries.each do |xlib|
291
+ platform = xlib.for_platform
292
+ desc "Build fat binary gem for platform #{platform}"
293
+ task "gem:windows:#{platform}" => ['gem:windows:prepare', xlib.openssl_tarball, xlib.postgresql_tarball] do
294
+ RakeCompilerDock.sh <<-EOT, platform: platform
295
+ (cp build/gem/gem-*.pem ~/.gem/ || true) &&
296
+ bundle install --local &&
297
+ rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKE="make -j`nproc`" RUBY_CC_VERSION=3.1.0:3.0.0:2.7.0:2.6.0:2.5.0
298
+ EOT
299
+ end
300
+ desc "Build the windows binary gems"
301
+ multitask 'gem:windows' => "gem:windows:#{platform}"
301
302
  end