pg 0.17.1 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/BSDL +2 -2
- data/ChangeLog +0 -3506
- data/History.rdoc +308 -0
- data/Manifest.txt +35 -19
- data/README-Windows.rdoc +17 -28
- data/README.ja.rdoc +1 -2
- data/README.rdoc +113 -14
- data/Rakefile +67 -30
- data/Rakefile.cross +109 -83
- data/ext/errorcodes.def +101 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +33 -2
- data/ext/extconf.rb +55 -58
- data/ext/gvl_wrappers.c +4 -0
- data/ext/gvl_wrappers.h +27 -39
- data/ext/pg.c +262 -130
- data/ext/pg.h +266 -54
- data/ext/pg_binary_decoder.c +229 -0
- data/ext/pg_binary_encoder.c +163 -0
- data/ext/pg_coder.c +561 -0
- data/ext/pg_connection.c +1689 -990
- data/ext/pg_copy_coder.c +599 -0
- data/ext/pg_errors.c +6 -0
- data/ext/pg_record_coder.c +491 -0
- data/ext/pg_result.c +897 -164
- data/ext/pg_text_decoder.c +987 -0
- data/ext/pg_text_encoder.c +814 -0
- data/ext/pg_tuple.c +549 -0
- data/ext/pg_type_map.c +166 -0
- data/ext/pg_type_map_all_strings.c +116 -0
- data/ext/pg_type_map_by_class.c +244 -0
- data/ext/pg_type_map_by_column.c +313 -0
- data/ext/pg_type_map_by_mri_type.c +284 -0
- data/ext/pg_type_map_by_oid.c +356 -0
- data/ext/pg_type_map_in_ruby.c +299 -0
- data/ext/pg_util.c +149 -0
- data/ext/pg_util.h +65 -0
- data/lib/pg/basic_type_mapping.rb +522 -0
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +104 -0
- data/lib/pg/connection.rb +153 -41
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +2 -1
- data/lib/pg/result.rb +33 -6
- data/lib/pg/text_decoder.rb +46 -0
- data/lib/pg/text_encoder.rb +59 -0
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +16 -0
- data/lib/pg.rb +29 -9
- data/spec/{lib/helpers.rb → helpers.rb} +151 -64
- data/spec/pg/basic_type_mapping_spec.rb +630 -0
- data/spec/pg/connection_spec.rb +1180 -477
- data/spec/pg/connection_sync_spec.rb +41 -0
- data/spec/pg/result_spec.rb +456 -120
- data/spec/pg/tuple_spec.rb +333 -0
- data/spec/pg/type_map_by_class_spec.rb +138 -0
- data/spec/pg/type_map_by_column_spec.rb +226 -0
- data/spec/pg/type_map_by_mri_type_spec.rb +136 -0
- data/spec/pg/type_map_by_oid_spec.rb +149 -0
- data/spec/pg/type_map_in_ruby_spec.rb +164 -0
- data/spec/pg/type_map_spec.rb +22 -0
- data/spec/pg/type_spec.rb +1123 -0
- data/spec/pg_spec.rb +26 -20
- data.tar.gz.sig +0 -0
- metadata +148 -91
- metadata.gz.sig +0 -0
- data/sample/array_insert.rb +0 -20
- data/sample/async_api.rb +0 -106
- data/sample/async_copyto.rb +0 -39
- data/sample/async_mixed.rb +0 -56
- data/sample/check_conn.rb +0 -21
- data/sample/copyfrom.rb +0 -81
- data/sample/copyto.rb +0 -19
- data/sample/cursor.rb +0 -21
- data/sample/disk_usage_report.rb +0 -186
- data/sample/issue-119.rb +0 -94
- data/sample/losample.rb +0 -69
- data/sample/minimal-testcase.rb +0 -17
- data/sample/notify_wait.rb +0 -72
- data/sample/pg_statistics.rb +0 -294
- data/sample/replication_monitor.rb +0 -231
- data/sample/test_binary_values.rb +0 -33
- data/sample/wal_shipper.rb +0 -434
- data/sample/warehouse_partitions.rb +0 -320
data/README.ja.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -1,15 +1,16 @@
|
|
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
|
6
5
|
|
6
|
+
{<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]
|
7
|
+
|
7
8
|
|
8
9
|
== Description
|
9
10
|
|
10
11
|
Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
|
11
12
|
|
12
|
-
It works with {PostgreSQL
|
13
|
+
It works with {PostgreSQL 9.2 and later}[http://www.postgresql.org/support/versioning/].
|
13
14
|
|
14
15
|
A small example usage:
|
15
16
|
|
@@ -21,7 +22,7 @@ A small example usage:
|
|
21
22
|
conn = PG.connect( dbname: 'sales' )
|
22
23
|
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
|
23
24
|
puts " PID | User | Query"
|
24
|
-
|
25
|
+
result.each do |row|
|
25
26
|
puts " %7d | %-16s | %s " %
|
26
27
|
row.values_at('procpid', 'usename', 'current_query')
|
27
28
|
end
|
@@ -29,18 +30,30 @@ A small example usage:
|
|
29
30
|
|
30
31
|
== Build Status
|
31
32
|
|
32
|
-
{<img src="https://travis-ci.org/ged/ruby-pg.
|
33
|
+
{<img src="https://travis-ci.org/ged/ruby-pg.svg?branch=master" alt="Build Status Travis-CI" />}[https://travis-ci.org/ged/ruby-pg]
|
34
|
+
{<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]
|
33
35
|
|
34
36
|
|
35
37
|
== Requirements
|
36
38
|
|
37
|
-
* Ruby
|
38
|
-
* PostgreSQL
|
39
|
+
* Ruby 2.2 or newer
|
40
|
+
* PostgreSQL 9.2.x or later (with headers, -dev packages, etc).
|
39
41
|
|
40
|
-
It
|
42
|
+
It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
|
41
43
|
not regularly tested.
|
42
44
|
|
43
45
|
|
46
|
+
== Versioning
|
47
|
+
|
48
|
+
We tag and release gems according to the {Semantic Versioning}[http://semver.org/] principle.
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
For example:
|
53
|
+
|
54
|
+
spec.add_dependency 'pg', '~> 1.0'
|
55
|
+
|
56
|
+
|
44
57
|
== How To Install
|
45
58
|
|
46
59
|
Install via RubyGems:
|
@@ -63,12 +76,99 @@ There's also {a Google+ group}[http://goo.gl/TFy1U] and a
|
|
63
76
|
{mailing list}[http://groups.google.com/group/ruby-pg] if you get stuck, or just
|
64
77
|
want to chat about something.
|
65
78
|
|
79
|
+
If you want to install as a signed gem, the public certs of the gem signers
|
80
|
+
can be found in {the `certs` directory}[https://github.com/ged/ruby-pg/tree/master/certs]
|
81
|
+
of the repository.
|
82
|
+
|
83
|
+
|
84
|
+
== Type Casts
|
85
|
+
|
86
|
+
Pg can optionally type cast result values and query parameters in Ruby or
|
87
|
+
native C code. This can speed up data transfers to and from the database,
|
88
|
+
because String allocations are reduced and conversions in (slower) Ruby code
|
89
|
+
can be omitted.
|
90
|
+
|
91
|
+
Very basic type casting can be enabled by:
|
92
|
+
|
93
|
+
conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
|
94
|
+
# ... this works for result value mapping:
|
95
|
+
conn.exec("select 1, now(), '{2,3}'::int[]").values
|
96
|
+
# => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
|
97
|
+
|
98
|
+
conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
|
99
|
+
# ... and this for param value mapping:
|
100
|
+
conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
|
101
|
+
# => [["1", "1.2300000000000000E+00", "{2,3}"]]
|
102
|
+
|
103
|
+
But Pg's type casting is highly customizable. That's why it's divided into
|
104
|
+
2 layers:
|
105
|
+
|
106
|
+
=== Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
|
107
|
+
|
108
|
+
This is the lower layer, containing encoding classes that convert Ruby
|
109
|
+
objects for transmission to the DBMS and decoding classes to convert
|
110
|
+
received data back to Ruby objects. The classes are namespaced according
|
111
|
+
to their format and direction in PG::TextEncoder, PG::TextDecoder,
|
112
|
+
PG::BinaryEncoder and PG::BinaryDecoder.
|
113
|
+
|
114
|
+
It is possible to assign a type OID, format code (text or binary) and
|
115
|
+
optionally a name to an encoder or decoder object. It's also possible
|
116
|
+
to build composite types by assigning an element encoder/decoder.
|
117
|
+
PG::Coder objects can be used to set up a PG::TypeMap or alternatively
|
118
|
+
to convert single values to/from their string representation.
|
119
|
+
|
120
|
+
The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
|
121
|
+
* 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] 💡
|
122
|
+
* BE: {Int2}[rdoc-ref:PG::BinaryEncoder::Int2], {Int4}[rdoc-ref:PG::BinaryEncoder::Int4], {Int8}[rdoc-ref:PG::BinaryEncoder::Int8]
|
123
|
+
* Float: {TE}[rdoc-ref:PG::TextEncoder::Float], {TD}[rdoc-ref:PG::TextDecoder::Float], {BD}[rdoc-ref:PG::BinaryDecoder::Float]
|
124
|
+
* Numeric: {TE}[rdoc-ref:PG::TextEncoder::Numeric], {TD}[rdoc-ref:PG::TextDecoder::Numeric]
|
125
|
+
* 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]
|
126
|
+
* 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]
|
127
|
+
* 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]
|
128
|
+
* 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]
|
129
|
+
* Timestamp:
|
130
|
+
* TE: {local}[rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone], {UTC}[rdoc-ref:PG::TextEncoder::TimestampUtc], {with-TZ}[rdoc-ref:PG::TextEncoder::TimestampWithTimeZone]
|
131
|
+
* TD: {local}[rdoc-ref:PG::TextDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::TextDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::TextDecoder::TimestampUtcToLocal]
|
132
|
+
* BD: {local}[rdoc-ref:PG::BinaryDecoder::TimestampLocal], {UTC}[rdoc-ref:PG::BinaryDecoder::TimestampUtc], {UTC-to-local}[rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal]
|
133
|
+
* Date: {TE}[rdoc-ref:PG::TextEncoder::Date], {TD}[rdoc-ref:PG::TextDecoder::Date]
|
134
|
+
* JSON and JSONB: {TE}[rdoc-ref:PG::TextEncoder::JSON], {TD}[rdoc-ref:PG::TextDecoder::JSON]
|
135
|
+
* Inet: {TE}[rdoc-ref:PG::TextEncoder::Inet], {TD}[rdoc-ref:PG::TextDecoder::Inet]
|
136
|
+
* Array: {TE}[rdoc-ref:PG::TextEncoder::Array], {TD}[rdoc-ref:PG::TextDecoder::Array]
|
137
|
+
* Composite Type (also called "Row" or "Record"): {TE}[rdoc-ref:PG::TextEncoder::Record], {TD}[rdoc-ref:PG::TextDecoder::Record]
|
138
|
+
|
139
|
+
The following text formats can also be encoded although they are not used as column type:
|
140
|
+
* COPY input and output data: {TE}[rdoc-ref:PG::TextEncoder::CopyRow], {TD}[rdoc-ref:PG::TextDecoder::CopyRow]
|
141
|
+
* Literal for insertion into SQL string: {TE}[rdoc-ref:PG::TextEncoder::QuotedLiteral]
|
142
|
+
* SQL-Identifier: {TE}[rdoc-ref:PG::TextEncoder::Identifier], {TD}[rdoc-ref:PG::TextDecoder::Identifier]
|
143
|
+
|
144
|
+
=== PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
|
145
|
+
|
146
|
+
A TypeMap defines which value will be converted by which encoder/decoder.
|
147
|
+
There are different type map strategies, implemented by several derivations
|
148
|
+
of this class. They can be chosen and configured according to the particular
|
149
|
+
needs for type casting. The default type map is PG::TypeMapAllStrings.
|
150
|
+
|
151
|
+
A type map can be assigned per connection or per query respectively per
|
152
|
+
result set. Type maps can also be used for COPY in and out data streaming.
|
153
|
+
See PG::Connection#copy_data .
|
154
|
+
|
155
|
+
The following base type maps are available:
|
156
|
+
* PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
|
157
|
+
* PG::TypeMapByClass - selects encoder based on the class of the value to be sent
|
158
|
+
* PG::TypeMapByColumn - selects encoder and decoder by column order
|
159
|
+
* PG::TypeMapByOid - selects decoder by PostgreSQL type OID
|
160
|
+
* PG::TypeMapInRuby - define a custom type map in ruby
|
161
|
+
|
162
|
+
The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
|
163
|
+
* PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
|
164
|
+
* PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
|
165
|
+
* PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
|
166
|
+
|
66
167
|
|
67
168
|
== Contributing
|
68
169
|
|
69
|
-
To report bugs, suggest features, or check out the source with
|
70
|
-
{check out the project page}[
|
71
|
-
Git, there's also a {Github mirror}[https://github.com/ged/ruby-pg].
|
170
|
+
To report bugs, suggest features, or check out the source with Git,
|
171
|
+
{check out the project page}[https://github.com/ged/ruby-pg].
|
72
172
|
|
73
173
|
After checking out the source, run:
|
74
174
|
|
@@ -83,7 +183,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
|
|
83
183
|
|
84
184
|
== Copying
|
85
185
|
|
86
|
-
Copyright (c) 1997-
|
186
|
+
Copyright (c) 1997-2019 by the authors.
|
87
187
|
|
88
188
|
* Jeff Davis <ruby-pg@j-davis.com>
|
89
189
|
* Guy Decoux (ts) <decoux@moulon.inra.fr>
|
@@ -95,7 +195,7 @@ Copyright (c) 1997-2013 by the authors.
|
|
95
195
|
* Noboru Saitou <noborus@netlab.jp>
|
96
196
|
|
97
197
|
You may redistribute this software under the same terms as Ruby itself; see
|
98
|
-
|
198
|
+
https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
|
99
199
|
for details.
|
100
200
|
|
101
201
|
Portions of the code are from the PostgreSQL project, and are distributed
|
@@ -111,4 +211,3 @@ to this library over the years.
|
|
111
211
|
|
112
212
|
We are thankful to the people at the ruby-list and ruby-dev mailing lists.
|
113
213
|
And to the people who developed PostgreSQL.
|
114
|
-
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# -*- rake -*-
|
2
2
|
|
3
3
|
require 'rbconfig'
|
4
4
|
require 'pathname'
|
@@ -29,10 +29,14 @@ TMPDIR = BASEDIR + 'tmp'
|
|
29
29
|
DLEXT = RbConfig::CONFIG['DLEXT']
|
30
30
|
EXT = LIBDIR + "pg_ext.#{DLEXT}"
|
31
31
|
|
32
|
+
GEMSPEC = 'pg.gemspec'
|
33
|
+
|
32
34
|
TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
|
33
35
|
|
34
36
|
CLOBBER.include( TEST_DIRECTORY.to_s )
|
35
37
|
CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
|
38
|
+
CLEAN.include "lib/*/libpq.dll"
|
39
|
+
CLEAN.include "lib/pg_ext.*"
|
36
40
|
|
37
41
|
# Set up Hoe plugins
|
38
42
|
Hoe.plugin :mercurial
|
@@ -53,27 +57,24 @@ $hoespec = Hoe.spec 'pg' do
|
|
53
57
|
self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
|
54
58
|
self.extra_rdoc_files.include( 'POSTGRES', 'LICENSE' )
|
55
59
|
self.extra_rdoc_files.include( 'ext/*.c' )
|
60
|
+
self.license 'BSD-2-Clause'
|
56
61
|
|
57
62
|
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
58
63
|
self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
|
59
64
|
|
60
|
-
self.dependency 'rake-compiler', '~> 0
|
61
|
-
self.dependency '
|
62
|
-
self.dependency 'hoe-deveiate', '~> 0.
|
65
|
+
self.dependency 'rake-compiler', '~> 1.0', :developer
|
66
|
+
self.dependency 'rake-compiler-dock', ['~> 1.0'], :developer
|
67
|
+
self.dependency 'hoe-deveiate', '~> 0.9', :developer
|
63
68
|
self.dependency 'hoe-bundler', '~> 1.0', :developer
|
69
|
+
self.dependency 'rspec', '~> 3.5', :developer
|
70
|
+
self.dependency 'rdoc', '~> 5.1', :developer
|
64
71
|
|
65
|
-
self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL']
|
66
72
|
self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
|
67
73
|
|
68
|
-
self.require_ruby_version( '>=
|
74
|
+
self.require_ruby_version( '>= 2.2' )
|
69
75
|
|
70
76
|
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
71
77
|
self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
|
72
|
-
self.spec_extras[:rdoc_options] = [
|
73
|
-
'-f', 'fivefish',
|
74
|
-
'-t', 'pg: The Ruby Interface to PostgreSQL',
|
75
|
-
'-m', 'README.rdoc',
|
76
|
-
]
|
77
78
|
|
78
79
|
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
79
80
|
end
|
@@ -81,7 +82,7 @@ end
|
|
81
82
|
ENV['VERSION'] ||= $hoespec.spec.version.to_s
|
82
83
|
|
83
84
|
# Tests should pass before checking in
|
84
|
-
task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
|
85
|
+
task 'hg:precheckin' => [ :check_history, :check_manifest, :spec, :gemspec ]
|
85
86
|
|
86
87
|
# Support for 'rvm specs'
|
87
88
|
task :specs => :spec
|
@@ -97,7 +98,7 @@ task :test do
|
|
97
98
|
# the installed gem dir. So we clear the task rake-compiler set up
|
98
99
|
# to break the dependency between :spec and :compile when running under
|
99
100
|
# rubygems-test, and then run :spec.
|
100
|
-
Rake::Task[ EXT.to_s ].clear
|
101
|
+
Rake::Task[ EXT.to_s ].clear if File.exist?(EXT.to_s)
|
101
102
|
Rake::Task[ :spec ].execute
|
102
103
|
end
|
103
104
|
|
@@ -106,8 +107,6 @@ task :maint do
|
|
106
107
|
ENV['MAINTAINER_MODE'] = 'yes'
|
107
108
|
end
|
108
109
|
|
109
|
-
ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2:2.0.0'
|
110
|
-
|
111
110
|
# Rake-compiler task
|
112
111
|
Rake::ExtensionTask.new do |ext|
|
113
112
|
ext.name = 'pg_ext'
|
@@ -116,18 +115,39 @@ Rake::ExtensionTask.new do |ext|
|
|
116
115
|
ext.lib_dir = 'lib'
|
117
116
|
ext.source_pattern = "*.{c,h}"
|
118
117
|
ext.cross_compile = true
|
119
|
-
ext.cross_platform = CrossLibraries.map
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
118
|
+
ext.cross_platform = CrossLibraries.map(&:for_platform)
|
119
|
+
|
120
|
+
ext.cross_config_options += CrossLibraries.map do |lib|
|
121
|
+
{
|
122
|
+
lib.for_platform => [
|
123
|
+
"--enable-windows-cross",
|
124
|
+
"--with-pg-include=#{lib.static_postgresql_incdir}",
|
125
|
+
"--with-pg-lib=#{lib.static_postgresql_libdir}",
|
126
|
+
# libpq-fe.h resides in src/interfaces/libpq/ before make install
|
127
|
+
"--with-opt-include=#{lib.static_postgresql_libdir}",
|
128
|
+
]
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
# Add libpq.dll to windows binary gemspec
|
133
|
+
ext.cross_compiling do |spec|
|
134
|
+
spec.files << "lib/#{spec.platform}/libpq.dll"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
# Use the fivefish formatter for docs generated from development checkout
|
140
|
+
if File.directory?( '.hg' )
|
141
|
+
require 'rdoc/task'
|
142
|
+
|
143
|
+
Rake::Task[ 'docs' ].clear
|
144
|
+
RDoc::Task.new( 'docs' ) do |rdoc|
|
145
|
+
rdoc.main = "README.rdoc"
|
146
|
+
rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb", 'ext/**/*.{c,h}' )
|
147
|
+
rdoc.generator = :fivefish
|
148
|
+
rdoc.title = "PG: The Ruby PostgreSQL Driver"
|
149
|
+
rdoc.rdoc_dir = 'doc'
|
150
|
+
end
|
131
151
|
end
|
132
152
|
|
133
153
|
|
@@ -135,10 +155,12 @@ end
|
|
135
155
|
file '.hg/branch' do
|
136
156
|
warn "WARNING: You need the Mercurial repo to update the ChangeLog"
|
137
157
|
end
|
158
|
+
Rake::Task["ChangeLog"].clear
|
138
159
|
file 'ChangeLog' do |task|
|
139
160
|
if File.exist?('.hg/branch')
|
140
161
|
$stderr.puts "Updating the changelog..."
|
141
162
|
begin
|
163
|
+
include Hoe::MercurialHelpers
|
142
164
|
content = make_changelog()
|
143
165
|
rescue NameError
|
144
166
|
abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
|
@@ -164,13 +186,11 @@ end
|
|
164
186
|
|
165
187
|
desc "Update list of server error codes"
|
166
188
|
task :update_error_codes do
|
167
|
-
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=
|
189
|
+
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_12_0"
|
168
190
|
|
169
191
|
ERRORCODES_TXT = "ext/errorcodes.txt"
|
170
192
|
sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
|
171
|
-
end
|
172
193
|
|
173
|
-
file 'ext/errorcodes.def' => ['ext/errorcodes.rb', 'ext/errorcodes.txt'] do
|
174
194
|
ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
|
175
195
|
end
|
176
196
|
|
@@ -178,3 +198,20 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
|
|
178
198
|
# trigger compilation of changed errorcodes.def
|
179
199
|
touch 'ext/pg_errors.c'
|
180
200
|
end
|
201
|
+
|
202
|
+
task :gemspec => GEMSPEC
|
203
|
+
file GEMSPEC => __FILE__
|
204
|
+
task GEMSPEC do |task|
|
205
|
+
spec = $hoespec.spec
|
206
|
+
spec.files.delete( '.gemtest' )
|
207
|
+
spec.signing_key = nil
|
208
|
+
spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
209
|
+
spec.cert_chain = [ 'certs/ged.pem' ]
|
210
|
+
File.open( task.name, 'w' ) do |fh|
|
211
|
+
fh.write( spec.to_ruby )
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
CLOBBER.include( '*.gemspec' )
|
216
|
+
task :default => :gemspec
|
217
|
+
|
data/Rakefile.cross
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# -*- rake -*-
|
2
2
|
|
3
3
|
require 'uri'
|
4
4
|
require 'tempfile'
|
@@ -21,19 +21,32 @@ end
|
|
21
21
|
class CrossLibrary < OpenStruct
|
22
22
|
include Rake::DSL
|
23
23
|
|
24
|
-
def initialize(for_platform, openssl_config)
|
24
|
+
def initialize(for_platform, openssl_config, toolchain)
|
25
25
|
super()
|
26
26
|
|
27
27
|
self.for_platform = for_platform
|
28
28
|
self.openssl_config = openssl_config
|
29
|
+
self.host_platform = toolchain
|
29
30
|
|
30
31
|
# Cross-compilation constants
|
31
|
-
self.openssl_version = ENV['OPENSSL_VERSION'] || '1.
|
32
|
-
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '
|
33
|
-
|
34
|
-
|
32
|
+
self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.1d'
|
33
|
+
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '12.1'
|
34
|
+
|
35
|
+
# Check if symlinks work in the current working directory.
|
36
|
+
# This fails, if rake-compiler-dock is running on a Windows box.
|
37
|
+
begin
|
38
|
+
FileUtils.rm_f '.test_symlink'
|
39
|
+
FileUtils.ln_s '/', '.test_symlink'
|
40
|
+
rescue NotImplementedError, SystemCallError
|
41
|
+
# Symlinks don't work -> use home directory instead
|
42
|
+
self.compile_home = Pathname( "~/.ruby-pg-build" ).expand_path
|
43
|
+
else
|
44
|
+
self.compile_home = Pathname( "./build" ).expand_path
|
45
|
+
end
|
35
46
|
self.static_sourcesdir = compile_home + 'sources'
|
36
47
|
self.static_builddir = compile_home + 'builds' + for_platform
|
48
|
+
CLOBBER.include( static_sourcesdir )
|
49
|
+
CLEAN.include( static_builddir )
|
37
50
|
|
38
51
|
# Static OpenSSL build vars
|
39
52
|
self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
|
@@ -43,8 +56,8 @@ class CrossLibrary < OpenStruct
|
|
43
56
|
self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
|
44
57
|
self.openssl_makefile = static_openssl_builddir + 'Makefile'
|
45
58
|
|
46
|
-
self.
|
47
|
-
self.
|
59
|
+
self.libssl = static_openssl_builddir + 'libssl.a'
|
60
|
+
self.libcrypto = static_openssl_builddir + 'libcrypto.a'
|
48
61
|
|
49
62
|
self.openssl_patches = Rake::FileList[ (MISCDIR + "openssl-#{openssl_version}.*.patch").to_s ]
|
50
63
|
|
@@ -64,36 +77,12 @@ class CrossLibrary < OpenStruct
|
|
64
77
|
self.postgresql_global_makefile = static_postgresql_srcdir + 'Makefile.global'
|
65
78
|
self.postgresql_shlib_makefile = static_postgresql_srcdir + 'Makefile.shlib'
|
66
79
|
self.postgresql_shlib_mf_orig = static_postgresql_srcdir + 'Makefile.shlib.orig'
|
67
|
-
self.postgresql_lib = static_postgresql_libdir + 'libpq.
|
80
|
+
self.postgresql_lib = static_postgresql_libdir + 'libpq.dll'
|
68
81
|
self.postgresql_patches = Rake::FileList[ (MISCDIR + "postgresql-#{postgresql_version}.*.patch").to_s ]
|
69
82
|
|
70
|
-
# Use rake-compilers config.yml to determine the toolchain that was used
|
71
|
-
# to build Ruby for this platform.
|
72
|
-
self.host_platform = begin
|
73
|
-
config_file = YAML.load_file(File.expand_path("~/.rake-compiler/config.yml"))
|
74
|
-
_, rbfile = config_file.find{|key, fname| key.start_with?("rbconfig-#{for_platform}-") }
|
75
|
-
IO.read(rbfile).match(/CONFIG\["CC"\] = "(.*)"/)[1].sub(/\-gcc/, '')
|
76
|
-
rescue
|
77
|
-
nil
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
83
|
# clean intermediate files and folders
|
82
84
|
CLEAN.include( static_builddir.to_s )
|
83
85
|
|
84
|
-
|
85
|
-
ENV['RUBY_CC_VERSION'] ||= '1.8.7: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
86
|
#####################################################################
|
98
87
|
### C R O S S - C O M P I L A T I O N - T A S K S
|
99
88
|
#####################################################################
|
@@ -126,17 +115,15 @@ class CrossLibrary < OpenStruct
|
|
126
115
|
end
|
127
116
|
|
128
117
|
self.cmd_prelude = [
|
129
|
-
|
130
|
-
"
|
118
|
+
"env",
|
119
|
+
"CROSS_COMPILE=#{host_platform}-",
|
131
120
|
"CFLAGS=-DDSO_WIN32",
|
132
|
-
"AR=#{host_platform}-ar",
|
133
|
-
"RANLIB=#{host_platform}-ranlib"
|
134
121
|
]
|
135
122
|
|
136
123
|
|
137
124
|
# generate the makefile in a clean build location
|
138
125
|
file openssl_makefile => static_openssl_builddir do |t|
|
139
|
-
|
126
|
+
chdir( static_openssl_builddir ) do
|
140
127
|
cmd = cmd_prelude.dup
|
141
128
|
cmd << "./Configure" << openssl_config
|
142
129
|
|
@@ -145,10 +132,10 @@ class CrossLibrary < OpenStruct
|
|
145
132
|
end
|
146
133
|
|
147
134
|
desc "compile static openssl libraries"
|
148
|
-
task
|
135
|
+
task "openssl_libs:#{for_platform}" => [ libssl, libcrypto ]
|
149
136
|
|
150
|
-
task
|
151
|
-
|
137
|
+
task "compile_static_openssl:#{for_platform}" => openssl_makefile do |t|
|
138
|
+
chdir( static_openssl_builddir ) do
|
152
139
|
cmd = cmd_prelude.dup
|
153
140
|
cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
|
154
141
|
|
@@ -156,14 +143,14 @@ class CrossLibrary < OpenStruct
|
|
156
143
|
end
|
157
144
|
end
|
158
145
|
|
159
|
-
desc "compile static #{
|
160
|
-
file
|
161
|
-
|
146
|
+
desc "compile static #{libssl}"
|
147
|
+
file libssl => "compile_static_openssl:#{for_platform}" do |t|
|
148
|
+
rm t.name.gsub(/\.a$/, ".dll.a")
|
162
149
|
end
|
163
150
|
|
164
|
-
desc "compile static #{
|
165
|
-
file
|
166
|
-
|
151
|
+
desc "compile static #{libcrypto}"
|
152
|
+
file libcrypto => "compile_static_openssl:#{for_platform}" do |t|
|
153
|
+
rm t.name.gsub(/\.a$/, ".dll.a")
|
167
154
|
end
|
168
155
|
|
169
156
|
|
@@ -184,7 +171,6 @@ class CrossLibrary < OpenStruct
|
|
184
171
|
puts "extracting %s to %s" % [ postgresql_tarball, static_postgresql_builddir.parent ]
|
185
172
|
static_postgresql_builddir.mkpath
|
186
173
|
run 'tar', '-xjf', postgresql_tarball.to_s, '-C', static_postgresql_builddir.parent.to_s
|
187
|
-
mv postgresql_shlib_makefile, postgresql_shlib_mf_orig
|
188
174
|
|
189
175
|
postgresql_patches.each do |patchfile|
|
190
176
|
puts " applying patch #{patchfile}..."
|
@@ -194,22 +180,21 @@ class CrossLibrary < OpenStruct
|
|
194
180
|
end
|
195
181
|
|
196
182
|
# generate the makefile in a clean build location
|
197
|
-
file postgresql_global_makefile => [ static_postgresql_builddir,
|
183
|
+
file postgresql_global_makefile => [ static_postgresql_builddir, "openssl_libs:#{for_platform}" ] do |t|
|
198
184
|
options = [
|
199
185
|
"--target=#{host_platform}",
|
200
186
|
"--host=#{host_platform}",
|
201
187
|
'--with-openssl',
|
202
188
|
'--without-zlib',
|
203
|
-
'--disable-shared',
|
204
189
|
]
|
205
190
|
|
206
|
-
|
191
|
+
chdir( static_postgresql_builddir ) do
|
207
192
|
configure_path = static_postgresql_builddir + 'configure'
|
208
193
|
cmd = [ configure_path.to_s, *options ]
|
209
194
|
cmd << "CFLAGS=-L#{static_openssl_builddir}"
|
210
195
|
cmd << "LDFLAGS=-L#{static_openssl_builddir}"
|
211
196
|
cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
|
212
|
-
cmd << "LIBS=-lwsock32 -lgdi32"
|
197
|
+
cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32"
|
213
198
|
cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
|
214
199
|
|
215
200
|
run( *cmd )
|
@@ -217,51 +202,62 @@ class CrossLibrary < OpenStruct
|
|
217
202
|
end
|
218
203
|
|
219
204
|
|
220
|
-
#
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
205
|
+
# make libpq.dll
|
206
|
+
task postgresql_lib => [ postgresql_global_makefile ] do |t|
|
207
|
+
# Work around missing dependency to libcommon in PostgreSQL-9.4.0
|
208
|
+
chdir( static_postgresql_srcdir + "common" ) do
|
209
|
+
sh 'make', "-j#{NUM_CPUS}"
|
210
|
+
end
|
211
|
+
chdir( static_postgresql_srcdir + "port" ) do
|
212
|
+
sh 'make', "-j#{NUM_CPUS}"
|
228
213
|
end
|
229
|
-
tf.close
|
230
214
|
|
231
|
-
|
215
|
+
chdir( postgresql_lib.dirname ) do
|
216
|
+
sh 'make',
|
217
|
+
"-j#{NUM_CPUS}",
|
218
|
+
postgresql_lib.basename.to_s,
|
219
|
+
'SHLIB_LINK=-lssl -lcrypto -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
|
220
|
+
end
|
232
221
|
end
|
233
222
|
|
234
223
|
|
235
|
-
#
|
236
|
-
task
|
237
|
-
|
238
|
-
|
239
|
-
|
224
|
+
#desc 'compile libpg.a'
|
225
|
+
task "native:#{for_platform}" => postgresql_lib
|
226
|
+
|
227
|
+
# copy libpq.dll to lib dir
|
228
|
+
dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
|
229
|
+
directory File.dirname(dest_libpq)
|
230
|
+
file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
|
231
|
+
cp postgresql_lib, dest_libpq
|
240
232
|
end
|
241
233
|
|
234
|
+
stage_libpq = "tmp/#{for_platform}/stage/#{dest_libpq}"
|
235
|
+
directory File.dirname(stage_libpq)
|
236
|
+
file stage_libpq => [postgresql_lib, File.dirname(stage_libpq)] do |t|
|
237
|
+
cp postgresql_lib, stage_libpq
|
238
|
+
end
|
239
|
+
end
|
242
240
|
|
243
|
-
|
244
|
-
|
241
|
+
def download(url, save_to)
|
242
|
+
part = save_to+".part"
|
243
|
+
sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
|
244
|
+
FileUtils.mv part, save_to
|
245
245
|
end
|
246
|
-
end
|
247
246
|
|
248
|
-
|
249
|
-
|
250
|
-
['i386-mingw32', 'mingw'],
|
251
|
-
['x64-mingw32', 'mingw64'],
|
252
|
-
].map do |platform, openssl_config|
|
253
|
-
CrossLibrary.new platform, openssl_config
|
247
|
+
def run(*args)
|
248
|
+
sh(*args)
|
254
249
|
end
|
255
|
-
else
|
256
|
-
$stderr.puts "Cross-compilation disabled -- rake-compiler not properly installed"
|
257
|
-
CrossLibraries = []
|
258
250
|
end
|
259
251
|
|
260
|
-
|
261
|
-
|
262
|
-
|
252
|
+
CrossLibraries = [
|
253
|
+
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
|
254
|
+
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
|
255
|
+
].map do |platform, openssl_config, toolchain|
|
256
|
+
CrossLibrary.new platform, openssl_config, toolchain
|
263
257
|
end
|
264
|
-
|
258
|
+
|
259
|
+
desc 'cross compile pg for win32'
|
260
|
+
task :cross => [ :mingw32 ]
|
265
261
|
|
266
262
|
task :mingw32 do
|
267
263
|
# Use Rake::ExtensionCompiler helpers to find the proper host
|
@@ -271,3 +267,33 @@ task :mingw32 do
|
|
271
267
|
fail
|
272
268
|
end
|
273
269
|
end
|
270
|
+
|
271
|
+
task 'gem:windows:prepare' do
|
272
|
+
require 'io/console'
|
273
|
+
require 'rake_compiler_dock'
|
274
|
+
|
275
|
+
# Copy gem signing key and certs to be accessable from the docker container
|
276
|
+
mkdir_p 'build/gem'
|
277
|
+
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
|
278
|
+
sh "bundle package"
|
279
|
+
begin
|
280
|
+
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
|
281
|
+
rescue OpenSSL::PKey::PKeyError
|
282
|
+
ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
|
283
|
+
retry
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
CrossLibraries.each do |xlib|
|
288
|
+
platform = xlib.for_platform
|
289
|
+
desc "Build fat binary gem for platform #{platform}"
|
290
|
+
task "gem:windows:#{platform}" => ['ChangeLog', 'gem:windows:prepare', xlib.openssl_tarball, xlib.postgresql_tarball] do
|
291
|
+
RakeCompilerDock.sh <<-EOT, platform: platform
|
292
|
+
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
|
293
|
+
bundle install --local &&
|
294
|
+
rake native:#{platform} pkg/#{$hoespec.spec.full_name}-#{platform}.gem MAKE="make -j`nproc`"
|
295
|
+
EOT
|
296
|
+
end
|
297
|
+
desc "Build the windows binary gems"
|
298
|
+
multitask 'gem:windows' => "gem:windows:#{platform}"
|
299
|
+
end
|