pg 0.18.3 → 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.
- 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 +129 -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/BSDL +2 -2
- data/Gemfile +14 -0
- data/History.rdoc +448 -4
- data/Manifest.txt +8 -21
- data/README-Windows.rdoc +4 -4
- data/README.ja.rdoc +1 -2
- data/README.rdoc +69 -17
- data/Rakefile +33 -135
- data/Rakefile.cross +70 -69
- data/certs/ged.pem +24 -0
- data/certs/larskanis-2022.pem +26 -0
- data/ext/errorcodes.def +109 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +35 -2
- data/ext/extconf.rb +120 -54
- data/ext/gvl_wrappers.c +8 -0
- data/ext/gvl_wrappers.h +44 -33
- data/ext/pg.c +213 -171
- data/ext/pg.h +92 -98
- data/ext/pg_binary_decoder.c +84 -15
- data/ext/pg_binary_encoder.c +24 -21
- data/ext/pg_coder.c +175 -39
- data/ext/pg_connection.c +1730 -1135
- data/ext/pg_copy_coder.c +94 -27
- data/ext/pg_record_coder.c +521 -0
- data/ext/pg_result.c +640 -221
- data/ext/pg_text_decoder.c +608 -40
- data/ext/pg_text_encoder.c +253 -99
- data/ext/pg_tuple.c +569 -0
- data/ext/pg_type_map.c +61 -21
- data/ext/pg_type_map_all_strings.c +19 -5
- data/ext/pg_type_map_by_class.c +54 -24
- data/ext/pg_type_map_by_column.c +79 -40
- data/ext/pg_type_map_by_mri_type.c +48 -19
- data/ext/pg_type_map_by_oid.c +55 -25
- data/ext/pg_type_map_in_ruby.c +51 -20
- 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 +723 -65
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +9 -2
- data/lib/pg/result.rb +24 -7
- data/lib/pg/text_decoder.rb +24 -22
- data/lib/pg/text_encoder.rb +40 -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 +61 -36
- 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 +1 -1
- data/sample/async_api.rb +4 -8
- data/sample/async_copyto.rb +1 -1
- data/sample/async_mixed.rb +1 -1
- data/sample/check_conn.rb +1 -1
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +1 -1
- data/sample/copyto.rb +1 -1
- data/sample/cursor.rb +1 -1
- data/sample/disk_usage_report.rb +6 -15
- data/sample/issue-119.rb +2 -2
- data/sample/losample.rb +1 -1
- data/sample/minimal-testcase.rb +2 -2
- data/sample/notify_wait.rb +1 -1
- data/sample/pg_statistics.rb +6 -15
- data/sample/replication_monitor.rb +9 -18
- data/sample/test_binary_values.rb +1 -1
- data/sample/wal_shipper.rb +2 -2
- data/sample/warehouse_partitions.rb +8 -17
- data.tar.gz.sig +0 -0
- metadata +80 -230
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -5804
- data/lib/pg/basic_type_mapping.rb +0 -399
- data/spec/data/expected_trace.out +0 -26
- data/spec/data/random_binary_data +0 -0
- data/spec/helpers.rb +0 -355
- data/spec/pg/basic_type_mapping_spec.rb +0 -251
- data/spec/pg/connection_spec.rb +0 -1538
- data/spec/pg/result_spec.rb +0 -449
- 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 -690
- data/spec/pg_spec.rb +0 -50
data/README.rdoc
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
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
|
+
|
|
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]
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
== Description
|
|
9
11
|
|
|
10
12
|
Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
|
|
11
13
|
|
|
12
|
-
It works with {PostgreSQL
|
|
14
|
+
It works with {PostgreSQL 9.3 and later}[http://www.postgresql.org/support/versioning/].
|
|
13
15
|
|
|
14
16
|
A small example usage:
|
|
15
17
|
|
|
@@ -21,27 +23,38 @@ A small example usage:
|
|
|
21
23
|
conn = PG.connect( dbname: 'sales' )
|
|
22
24
|
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
|
|
23
25
|
puts " PID | User | Query"
|
|
24
|
-
|
|
26
|
+
result.each do |row|
|
|
25
27
|
puts " %7d | %-16s | %s " %
|
|
26
|
-
row.values_at('
|
|
28
|
+
row.values_at('pid', 'usename', 'query')
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
== Build Status
|
|
31
33
|
|
|
32
|
-
{<img src="https://
|
|
33
|
-
{<img src="https://ci.appveyor.com/api/projects/status/
|
|
34
|
-
|
|
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]
|
|
35
37
|
|
|
36
38
|
== Requirements
|
|
37
39
|
|
|
38
|
-
* Ruby
|
|
39
|
-
* PostgreSQL
|
|
40
|
+
* Ruby 2.4 or newer
|
|
41
|
+
* PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
|
|
40
42
|
|
|
41
|
-
It
|
|
43
|
+
It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
|
|
42
44
|
not regularly tested.
|
|
43
45
|
|
|
44
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
|
+
|
|
45
58
|
== How To Install
|
|
46
59
|
|
|
47
60
|
Install via RubyGems:
|
|
@@ -64,6 +77,10 @@ There's also {a Google+ group}[http://goo.gl/TFy1U] and a
|
|
|
64
77
|
{mailing list}[http://groups.google.com/group/ruby-pg] if you get stuck, or just
|
|
65
78
|
want to chat about something.
|
|
66
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
|
+
|
|
67
84
|
|
|
68
85
|
== Type Casts
|
|
69
86
|
|
|
@@ -101,6 +118,30 @@ to build composite types by assigning an element encoder/decoder.
|
|
|
101
118
|
PG::Coder objects can be used to set up a PG::TypeMap or alternatively
|
|
102
119
|
to convert single values to/from their string representation.
|
|
103
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
|
+
|
|
104
145
|
=== PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
|
105
146
|
|
|
106
147
|
A TypeMap defines which value will be converted by which encoder/decoder.
|
|
@@ -110,13 +151,25 @@ needs for type casting. The default type map is PG::TypeMapAllStrings.
|
|
|
110
151
|
|
|
111
152
|
A type map can be assigned per connection or per query respectively per
|
|
112
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
|
|
113
167
|
|
|
114
168
|
|
|
115
169
|
== Contributing
|
|
116
170
|
|
|
117
|
-
To report bugs, suggest features, or check out the source with
|
|
118
|
-
{check out the project page}[
|
|
119
|
-
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].
|
|
120
173
|
|
|
121
174
|
After checking out the source, run:
|
|
122
175
|
|
|
@@ -131,7 +184,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
|
|
|
131
184
|
|
|
132
185
|
== Copying
|
|
133
186
|
|
|
134
|
-
Copyright (c) 1997-
|
|
187
|
+
Copyright (c) 1997-2019 by the authors.
|
|
135
188
|
|
|
136
189
|
* Jeff Davis <ruby-pg@j-davis.com>
|
|
137
190
|
* Guy Decoux (ts) <decoux@moulon.inra.fr>
|
|
@@ -143,7 +196,7 @@ Copyright (c) 1997-2015 by the authors.
|
|
|
143
196
|
* Noboru Saitou <noborus@netlab.jp>
|
|
144
197
|
|
|
145
198
|
You may redistribute this software under the same terms as Ruby itself; see
|
|
146
|
-
|
|
199
|
+
https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
|
|
147
200
|
for details.
|
|
148
201
|
|
|
149
202
|
Portions of the code are from the PostgreSQL project, and are distributed
|
|
@@ -159,4 +212,3 @@ to this library over the years.
|
|
|
159
212
|
|
|
160
213
|
We are thankful to the people at the ruby-list and ruby-dev mailing lists.
|
|
161
214
|
And to the people who developed PostgreSQL.
|
|
162
|
-
|
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,103 +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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
self.spec_extras[:rdoc_options] = [
|
|
78
|
-
'-f', 'fivefish',
|
|
79
|
-
'-t', 'pg: The Ruby Interface to PostgreSQL',
|
|
80
|
-
'-m', 'README.rdoc',
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
ENV['VERSION'] ||= $hoespec.spec.version.to_s
|
|
87
|
-
|
|
88
|
-
# Tests should pass before checking in
|
|
89
|
-
task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
|
|
90
|
-
|
|
91
|
-
# Support for 'rvm specs'
|
|
92
|
-
task :specs => :spec
|
|
93
|
-
|
|
94
|
-
# Compile before testing
|
|
95
|
-
task :spec => :compile
|
|
96
|
-
|
|
97
|
-
# gem-testers support
|
|
98
|
-
task :test do
|
|
99
|
-
# rake-compiler always wants to copy the compiled extension into lib/, but
|
|
100
|
-
# we don't want testers to have to re-compile, especially since that
|
|
101
|
-
# often fails because they can't (and shouldn't have to) write to tmp/ in
|
|
102
|
-
# the installed gem dir. So we clear the task rake-compiler set up
|
|
103
|
-
# to break the dependency between :spec and :compile when running under
|
|
104
|
-
# rubygems-test, and then run :spec.
|
|
105
|
-
Rake::Task[ EXT.to_s ].clear
|
|
106
|
-
Rake::Task[ :spec ].execute
|
|
107
|
-
end
|
|
34
|
+
Bundler::GemHelper.install_tasks
|
|
35
|
+
$gem_spec = Bundler.load_gemspec(GEMSPEC)
|
|
108
36
|
|
|
109
37
|
desc "Turn on warnings and debugging in the build."
|
|
110
38
|
task :maint do
|
|
111
39
|
ENV['MAINTAINER_MODE'] = 'yes'
|
|
112
40
|
end
|
|
113
41
|
|
|
114
|
-
ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2:2.0.0'
|
|
115
|
-
|
|
116
42
|
# Rake-compiler task
|
|
117
43
|
Rake::ExtensionTask.new do |ext|
|
|
118
44
|
ext.name = 'pg_ext'
|
|
119
|
-
ext.gem_spec = $
|
|
45
|
+
ext.gem_spec = $gem_spec
|
|
120
46
|
ext.ext_dir = 'ext'
|
|
121
47
|
ext.lib_dir = 'lib'
|
|
122
48
|
ext.source_pattern = "*.{c,h}"
|
|
123
49
|
ext.cross_compile = true
|
|
124
|
-
ext.cross_platform = CrossLibraries.map
|
|
50
|
+
ext.cross_platform = CrossLibraries.map(&:for_platform)
|
|
125
51
|
|
|
126
52
|
ext.cross_config_options += CrossLibraries.map do |lib|
|
|
127
53
|
{
|
|
@@ -137,53 +63,40 @@ Rake::ExtensionTask.new do |ext|
|
|
|
137
63
|
|
|
138
64
|
# Add libpq.dll to windows binary gemspec
|
|
139
65
|
ext.cross_compiling do |spec|
|
|
140
|
-
|
|
141
|
-
spec.files << "lib/#{spec.platform.to_s.gsub(/^x86-/, "i386-")}/libpq.dll"
|
|
66
|
+
spec.files << "lib/#{spec.platform}/libpq.dll"
|
|
142
67
|
end
|
|
143
68
|
end
|
|
144
69
|
|
|
70
|
+
RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
|
|
71
|
+
task :test => :spec
|
|
145
72
|
|
|
146
|
-
#
|
|
147
|
-
|
|
148
|
-
warn "WARNING: You need the Mercurial repo to update the ChangeLog"
|
|
149
|
-
end
|
|
150
|
-
file 'ChangeLog' do |task|
|
|
151
|
-
if File.exist?('.hg/branch')
|
|
152
|
-
$stderr.puts "Updating the changelog..."
|
|
153
|
-
begin
|
|
154
|
-
include Hoe::MercurialHelpers
|
|
155
|
-
content = make_changelog()
|
|
156
|
-
rescue NameError
|
|
157
|
-
abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
|
|
158
|
-
end
|
|
159
|
-
File.open( task.name, 'w', 0644 ) do |fh|
|
|
160
|
-
fh.print( content )
|
|
161
|
-
end
|
|
162
|
-
else
|
|
163
|
-
touch 'ChangeLog'
|
|
164
|
-
end
|
|
165
|
-
end
|
|
73
|
+
# Use the fivefish formatter for docs generated from development checkout
|
|
74
|
+
require 'rdoc/task'
|
|
166
75
|
|
|
167
|
-
|
|
168
|
-
|
|
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'
|
|
82
|
+
end
|
|
169
83
|
|
|
84
|
+
desc "Build the source gem #{$gem_spec.full_name}.gem into the pkg directory"
|
|
85
|
+
task :gem => :build
|
|
170
86
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
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()
|
|
176
91
|
end
|
|
177
92
|
|
|
178
93
|
desc "Update list of server error codes"
|
|
179
94
|
task :update_error_codes do
|
|
180
|
-
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=
|
|
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"
|
|
181
96
|
|
|
182
97
|
ERRORCODES_TXT = "ext/errorcodes.txt"
|
|
183
98
|
sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
|
|
184
|
-
end
|
|
185
99
|
|
|
186
|
-
file 'ext/errorcodes.def' => ['ext/errorcodes.rb', 'ext/errorcodes.txt'] do
|
|
187
100
|
ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
|
|
188
101
|
end
|
|
189
102
|
|
|
@@ -191,18 +104,3 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
|
|
|
191
104
|
# trigger compilation of changed errorcodes.def
|
|
192
105
|
touch 'ext/pg_errors.c'
|
|
193
106
|
end
|
|
194
|
-
|
|
195
|
-
task :gemspec => GEMSPEC
|
|
196
|
-
file GEMSPEC => __FILE__
|
|
197
|
-
task GEMSPEC do |task|
|
|
198
|
-
spec = $hoespec.spec
|
|
199
|
-
spec.files.delete( '.gemtest' )
|
|
200
|
-
spec.version = "#{spec.version}.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
|
201
|
-
File.open( task.name, 'w' ) do |fh|
|
|
202
|
-
fh.write( spec.to_ruby )
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
CLOBBER.include( GEMSPEC.to_s )
|
|
207
|
-
task :default => :gemspec
|
|
208
|
-
|
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.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.
|
|
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,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=-
|
|
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
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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,29 +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
|
-
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
|