pg 0.21.0 → 1.4.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.appveyor.yml +36 -0
- data/.gems +6 -0
- data/.github/workflows/binary-gems.yml +86 -0
- data/.github/workflows/source-gem.yml +131 -0
- data/.gitignore +13 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/Gemfile +14 -0
- data/History.rdoc +390 -4
- data/Manifest.txt +8 -4
- data/README-Windows.rdoc +4 -4
- data/README.ja.rdoc +1 -2
- data/README.rdoc +85 -20
- data/Rakefile +32 -142
- data/Rakefile.cross +71 -71
- data/certs/ged.pem +24 -0
- data/certs/larskanis-2022.pem +26 -0
- data/ext/errorcodes.def +84 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +23 -2
- data/ext/extconf.rb +111 -54
- data/ext/gvl_wrappers.c +8 -0
- data/ext/gvl_wrappers.h +40 -33
- data/ext/pg.c +211 -171
- data/ext/pg.h +87 -95
- data/ext/pg_binary_decoder.c +83 -16
- data/ext/pg_binary_encoder.c +14 -13
- data/ext/pg_coder.c +146 -31
- data/ext/pg_connection.c +1441 -1001
- data/ext/pg_copy_coder.c +61 -24
- data/ext/pg_errors.c +1 -1
- data/ext/pg_record_coder.c +521 -0
- data/ext/pg_result.c +623 -208
- data/ext/pg_text_decoder.c +607 -41
- data/ext/pg_text_encoder.c +191 -60
- data/ext/pg_tuple.c +569 -0
- data/ext/pg_type_map.c +43 -10
- data/ext/pg_type_map_all_strings.c +20 -6
- data/ext/pg_type_map_by_class.c +55 -25
- data/ext/pg_type_map_by_column.c +75 -36
- data/ext/pg_type_map_by_mri_type.c +49 -20
- data/ext/pg_type_map_by_oid.c +56 -26
- data/ext/pg_type_map_in_ruby.c +52 -21
- data/ext/{util.c → pg_util.c} +12 -12
- data/ext/{util.h → pg_util.h} +2 -2
- data/lib/pg/basic_type_map_based_on_result.rb +47 -0
- data/lib/pg/basic_type_map_for_queries.rb +193 -0
- data/lib/pg/basic_type_map_for_results.rb +81 -0
- data/lib/pg/basic_type_registry.rb +301 -0
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +24 -3
- data/lib/pg/connection.rb +667 -57
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +9 -2
- data/lib/pg/result.rb +14 -2
- data/lib/pg/text_decoder.rb +21 -26
- data/lib/pg/text_encoder.rb +32 -8
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +3 -2
- data/lib/pg/version.rb +4 -0
- data/lib/pg.rb +51 -38
- data/misc/openssl-pg-segfault.rb +31 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +21 -0
- data/misc/postgres/lib/postgres.rb +16 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +21 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
- data/pg.gemspec +32 -0
- data/rakelib/task_extension.rb +46 -0
- data/sample/array_insert.rb +20 -0
- data/sample/async_api.rb +102 -0
- data/sample/async_copyto.rb +39 -0
- data/sample/async_mixed.rb +56 -0
- data/sample/check_conn.rb +21 -0
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +81 -0
- data/sample/copyto.rb +19 -0
- data/sample/cursor.rb +21 -0
- data/sample/disk_usage_report.rb +177 -0
- data/sample/issue-119.rb +94 -0
- data/sample/losample.rb +69 -0
- data/sample/minimal-testcase.rb +17 -0
- data/sample/notify_wait.rb +72 -0
- data/sample/pg_statistics.rb +285 -0
- data/sample/replication_monitor.rb +222 -0
- data/sample/test_binary_values.rb +33 -0
- data/sample/wal_shipper.rb +434 -0
- data/sample/warehouse_partitions.rb +311 -0
- data.tar.gz.sig +0 -0
- metadata +91 -229
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -6595
- data/lib/pg/basic_type_mapping.rb +0 -426
- data/lib/pg/deprecated_constants.rb +0 -21
- data/spec/data/expected_trace.out +0 -26
- data/spec/data/random_binary_data +0 -0
- data/spec/helpers.rb +0 -352
- data/spec/pg/basic_type_mapping_spec.rb +0 -305
- data/spec/pg/connection_spec.rb +0 -1676
- data/spec/pg/result_spec.rb +0 -456
- data/spec/pg/type_map_by_class_spec.rb +0 -138
- data/spec/pg/type_map_by_column_spec.rb +0 -222
- data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
- data/spec/pg/type_map_by_oid_spec.rb +0 -149
- data/spec/pg/type_map_in_ruby_spec.rb +0 -164
- data/spec/pg/type_map_spec.rb +0 -22
- data/spec/pg/type_spec.rb +0 -777
- data/spec/pg_spec.rb +0 -50
data/README.rdoc
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
= pg
|
|
2
2
|
|
|
3
|
-
home :: https://
|
|
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 9.
|
|
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
|
|
|
@@ -25,25 +25,36 @@ A small example usage:
|
|
|
25
25
|
puts " PID | User | Query"
|
|
26
26
|
result.each do |row|
|
|
27
27
|
puts " %7d | %-16s | %s " %
|
|
28
|
-
row.values_at('
|
|
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://
|
|
35
|
-
{<img src="https://ci.appveyor.com/api/projects/status/
|
|
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 2.
|
|
41
|
-
* PostgreSQL 9.
|
|
40
|
+
* Ruby 2.4 or newer
|
|
41
|
+
* PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
|
|
42
42
|
|
|
43
|
-
It usually
|
|
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:
|
|
@@ -67,7 +78,7 @@ There's also {a Google+ group}[http://goo.gl/TFy1U] and a
|
|
|
67
78
|
want to chat about something.
|
|
68
79
|
|
|
69
80
|
If you want to install as a signed gem, the public certs of the gem signers
|
|
70
|
-
can be found in {the `certs` directory}[https://
|
|
81
|
+
can be found in {the `certs` directory}[https://github.com/ged/ruby-pg/tree/master/certs]
|
|
71
82
|
of the repository.
|
|
72
83
|
|
|
73
84
|
|
|
@@ -107,6 +118,30 @@ to build composite types by assigning an element encoder/decoder.
|
|
|
107
118
|
PG::Coder objects can be used to set up a PG::TypeMap or alternatively
|
|
108
119
|
to convert single values to/from their string representation.
|
|
109
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
|
+
|
|
110
145
|
=== PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
|
111
146
|
|
|
112
147
|
A TypeMap defines which value will be converted by which encoder/decoder.
|
|
@@ -118,18 +153,49 @@ A type map can be assigned per connection or per query respectively per
|
|
|
118
153
|
result set. Type maps can also be used for COPY in and out data streaming.
|
|
119
154
|
See PG::Connection#copy_data .
|
|
120
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
|
|
167
|
+
|
|
168
|
+
|
|
121
169
|
== Contributing
|
|
122
170
|
|
|
123
|
-
To report bugs, suggest features, or check out the source with
|
|
124
|
-
{check out the project page}[
|
|
125
|
-
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].
|
|
126
173
|
|
|
127
|
-
After checking out the source,
|
|
174
|
+
After checking out the source, install all dependencies:
|
|
128
175
|
|
|
129
|
-
$
|
|
176
|
+
$ bundle install
|
|
130
177
|
|
|
131
|
-
|
|
132
|
-
|
|
178
|
+
Cleanup extension files, packaging files, test databases:
|
|
179
|
+
|
|
180
|
+
$ rake clean
|
|
181
|
+
|
|
182
|
+
Compile extension:
|
|
183
|
+
|
|
184
|
+
$ rake compile
|
|
185
|
+
|
|
186
|
+
Run tests/specs with PostgreSQL tools like `initdb` in the path:
|
|
187
|
+
|
|
188
|
+
$ PATH=$PATH:/usr/lib/postgresql/14/bin rake test
|
|
189
|
+
|
|
190
|
+
Or run a specific test with the line number:
|
|
191
|
+
|
|
192
|
+
$ PATH=$PATH:/usr/lib/postgresql/14/bin rspec -Ilib -fd spec/pg/connection_spec.rb:455
|
|
193
|
+
|
|
194
|
+
Generate the API documentation:
|
|
195
|
+
|
|
196
|
+
$ rake docs
|
|
197
|
+
|
|
198
|
+
Make sure, that all bugs and new features are verified by tests.
|
|
133
199
|
|
|
134
200
|
The current maintainers are Michael Granger <ged@FaerieMUD.org> and
|
|
135
201
|
Lars Kanis <lars@greiz-reinsdorf.de>.
|
|
@@ -137,7 +203,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
|
|
|
137
203
|
|
|
138
204
|
== Copying
|
|
139
205
|
|
|
140
|
-
Copyright (c) 1997-
|
|
206
|
+
Copyright (c) 1997-2022 by the authors.
|
|
141
207
|
|
|
142
208
|
* Jeff Davis <ruby-pg@j-davis.com>
|
|
143
209
|
* Guy Decoux (ts) <decoux@moulon.inra.fr>
|
|
@@ -165,4 +231,3 @@ to this library over the years.
|
|
|
165
231
|
|
|
166
232
|
We are thankful to the people at the ruby-list and ruby-dev mailing lists.
|
|
167
233
|
And to the people who developed PostgreSQL.
|
|
168
|
-
|
data/Rakefile
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
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,97 +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_*"
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
CLOBBER.include( TEST_DIRECTORY.to_s )
|
|
26
|
+
CLEAN.include( TESTDIR.to_s )
|
|
37
27
|
CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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.6', :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
|
|
34
|
+
Bundler::GemHelper.install_tasks
|
|
35
|
+
$gem_spec = Bundler.load_gemspec(GEMSPEC)
|
|
102
36
|
|
|
103
37
|
desc "Turn on warnings and debugging in the build."
|
|
104
38
|
task :maint do
|
|
105
39
|
ENV['MAINTAINER_MODE'] = 'yes'
|
|
106
40
|
end
|
|
107
41
|
|
|
108
|
-
ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2:2.0.0'
|
|
109
|
-
|
|
110
42
|
# Rake-compiler task
|
|
111
43
|
Rake::ExtensionTask.new do |ext|
|
|
112
44
|
ext.name = 'pg_ext'
|
|
113
|
-
ext.gem_spec = $
|
|
45
|
+
ext.gem_spec = $gem_spec
|
|
114
46
|
ext.ext_dir = 'ext'
|
|
115
47
|
ext.lib_dir = 'lib'
|
|
116
48
|
ext.source_pattern = "*.{c,h}"
|
|
117
49
|
ext.cross_compile = true
|
|
118
|
-
ext.cross_platform = CrossLibraries.map
|
|
50
|
+
ext.cross_platform = CrossLibraries.map(&:for_platform)
|
|
119
51
|
|
|
120
52
|
ext.cross_config_options += CrossLibraries.map do |lib|
|
|
121
53
|
{
|
|
@@ -131,61 +63,36 @@ Rake::ExtensionTask.new do |ext|
|
|
|
131
63
|
|
|
132
64
|
# Add libpq.dll to windows binary gemspec
|
|
133
65
|
ext.cross_compiling do |spec|
|
|
134
|
-
spec.files << "lib/libpq.dll"
|
|
66
|
+
spec.files << "lib/#{spec.platform}/libpq.dll"
|
|
135
67
|
end
|
|
136
68
|
end
|
|
137
69
|
|
|
70
|
+
RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
|
|
71
|
+
task :test => :spec
|
|
138
72
|
|
|
139
73
|
# Use the fivefish formatter for docs generated from development checkout
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
rdoc.title = "PG: The Ruby PostgreSQL Driver"
|
|
149
|
-
rdoc.rdoc_dir = 'doc'
|
|
150
|
-
end
|
|
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'
|
|
151
82
|
end
|
|
152
83
|
|
|
84
|
+
desc "Build the source gem #{$gem_spec.full_name}.gem into the pkg directory"
|
|
85
|
+
task :gem => :build
|
|
153
86
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
file 'ChangeLog' do |task|
|
|
159
|
-
if File.exist?('.hg/branch')
|
|
160
|
-
$stderr.puts "Updating the changelog..."
|
|
161
|
-
begin
|
|
162
|
-
include Hoe::MercurialHelpers
|
|
163
|
-
content = make_changelog()
|
|
164
|
-
rescue NameError
|
|
165
|
-
abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
|
|
166
|
-
end
|
|
167
|
-
File.open( task.name, 'w', 0644 ) do |fh|
|
|
168
|
-
fh.print( content )
|
|
169
|
-
end
|
|
170
|
-
else
|
|
171
|
-
touch 'ChangeLog'
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# Rebuild the ChangeLog immediately before release
|
|
176
|
-
task :prerelease => 'ChangeLog'
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
desc "Stop any Postmaster instances that remain after testing."
|
|
180
|
-
task :cleanup_testing_dbs do
|
|
181
|
-
require 'spec/lib/helpers'
|
|
182
|
-
PgTestingHelpers.stop_existing_postmasters()
|
|
183
|
-
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()
|
|
184
91
|
end
|
|
185
92
|
|
|
186
93
|
desc "Update list of server error codes"
|
|
187
94
|
task :update_error_codes do
|
|
188
|
-
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/
|
|
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"
|
|
189
96
|
|
|
190
97
|
ERRORCODES_TXT = "ext/errorcodes.txt"
|
|
191
98
|
sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
|
|
@@ -197,20 +104,3 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
|
|
|
197
104
|
# trigger compilation of changed errorcodes.def
|
|
198
105
|
touch 'ext/pg_errors.c'
|
|
199
106
|
end
|
|
200
|
-
|
|
201
|
-
task :gemspec => GEMSPEC
|
|
202
|
-
file GEMSPEC => __FILE__
|
|
203
|
-
task GEMSPEC do |task|
|
|
204
|
-
spec = $hoespec.spec
|
|
205
|
-
spec.files.delete( '.gemtest' )
|
|
206
|
-
spec.signing_key = nil
|
|
207
|
-
spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
|
208
|
-
spec.cert_chain = [ 'certs/ged.pem' ]
|
|
209
|
-
File.open( task.name, 'w' ) do |fh|
|
|
210
|
-
fh.write( spec.to_ruby )
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
CLOBBER.include( '*.gemspec' )
|
|
215
|
-
task :default => :gemspec
|
|
216
|
-
|
data/Rakefile.cross
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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.
|
|
33
|
-
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '
|
|
34
|
+
self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.1q'
|
|
35
|
+
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '14.5'
|
|
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.
|
|
58
|
-
self.
|
|
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
|
-
|
|
130
|
-
"
|
|
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
|
|
137
|
+
task "openssl_libs:#{for_platform}" => [ libssl, libcrypto ]
|
|
149
138
|
|
|
150
|
-
task
|
|
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 #{
|
|
160
|
-
file
|
|
161
|
-
|
|
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 #{
|
|
165
|
-
file
|
|
166
|
-
|
|
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,
|
|
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,21 +210,24 @@ 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=-
|
|
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
|
|
227
|
+
task "native:#{for_platform}" => postgresql_lib
|
|
236
228
|
|
|
237
229
|
# copy libpq.dll to lib dir
|
|
238
|
-
dest_libpq = "lib/#{postgresql_lib.basename}"
|
|
230
|
+
dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
|
|
239
231
|
directory File.dirname(dest_libpq)
|
|
240
232
|
file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
|
|
241
233
|
cp postgresql_lib, dest_libpq
|
|
@@ -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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
|
258
247
|
end
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
248
|
+
|
|
249
|
+
def run(*args)
|
|
250
|
+
sh(*args)
|
|
251
|
+
end
|
|
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
|
|
263
|
+
task :cross => [ :mingw32 ]
|
|
266
264
|
|
|
267
265
|
task :mingw32 do
|
|
268
266
|
# Use Rake::ExtensionCompiler helpers to find the proper host
|
|
@@ -273,30 +271,32 @@ task :mingw32 do
|
|
|
273
271
|
end
|
|
274
272
|
end
|
|
275
273
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
bundle install --local &&
|
|
300
|
-
rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.6:2.0.0
|
|
301
|
-
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}"
|
|
302
302
|
end
|