sqlanywhere 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (12) hide show
  1. data/CHANGELOG +29 -25
  2. data/LICENSE +23 -23
  3. data/README +134 -130
  4. data/Rakefile +199 -196
  5. data/ext/extconf.rb +30 -30
  6. data/ext/sacapi.h +678 -678
  7. data/ext/sacapidll.c +167 -167
  8. data/ext/sacapidll.h +253 -253
  9. data/ext/sqlanywhere.c +1686 -1686
  10. data/test/sqlanywhere_test.rb +413 -413
  11. data/test/test.sql +87 -87
  12. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,25 +1,29 @@
1
- =CHANGE LOG
2
-
3
- =====0.1.3 -- 2008/12/31
4
- - Removed 'hint file' in lib directory
5
- - Added extensions to gemspec to force a local compile
6
-
7
- =====0.1.2 -- 2008/12/18
8
- - Fixed bug when trying to read input value from OUTPUT parameter
9
- - Added error checking to C2RB
10
- - Fixed Rake to handle .bundle on OSX
11
-
12
- =====0.1.1 -- 2008/11/06
13
- - Created a source gem rake task
14
- - Created a 'hint' file if the source gem is used directly
15
- - Changed file permissions on archives
16
- - Changed archives to be specific to platform (.zip on windows, .tar.gz
17
- otherwise)
18
- - Changed default rake task to only build library, not gem
19
- - Added a gem rake task
20
-
21
- =====0.1.0 -- 2008/10/15
22
- - Initial Release
23
- - Wraps DBCAPI functionality
24
- - Includes a simple unit test suite
25
-
1
+ =CHANGE LOG
2
+
3
+ =====0.1.4 -- 2009/03/25
4
+ - Changed Rakefile to automatically create lib directory
5
+ - Fixed bug that tried to build native extensions on binary distsributions
6
+
7
+ =====0.1.3 -- 2008/12/31
8
+ - Removed 'hint file' in lib directory
9
+ - Added extensions to gemspec to force a local compile
10
+
11
+ =====0.1.2 -- 2008/12/18
12
+ - Fixed bug when trying to read input value from OUTPUT parameter
13
+ - Added error checking to C2RB
14
+ - Fixed Rake to handle .bundle on OSX
15
+
16
+ =====0.1.1 -- 2008/11/06
17
+ - Created a source gem rake task
18
+ - Created a 'hint' file if the source gem is used directly
19
+ - Changed file permissions on archives
20
+ - Changed archives to be specific to platform (.zip on windows, .tar.gz
21
+ otherwise)
22
+ - Changed default rake task to only build library, not gem
23
+ - Added a gem rake task
24
+
25
+ =====0.1.0 -- 2008/10/15
26
+ - Initial Release
27
+ - Wraps DBCAPI functionality
28
+ - Includes a simple unit test suite
29
+
data/LICENSE CHANGED
@@ -1,23 +1,23 @@
1
- /*====================================================
2
- *
3
- * Copyright 2008-2009 iAnywhere Solutions, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- *
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- *
19
- * While not a requirement of the license, if you do modify this file, we
20
- * would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
21
- *
22
- *
23
- *====================================================*/
1
+ /*====================================================
2
+ *
3
+ * Copyright 2008-2009 iAnywhere Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ *
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * While not a requirement of the license, if you do modify this file, we
20
+ * would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
21
+ *
22
+ *
23
+ *====================================================*/
data/README CHANGED
@@ -1,130 +1,134 @@
1
- =SQL Anywhere Ruby Driver
2
-
3
- This is a native SQL Anywhere driver for Ruby. This library wraps the
4
- functionality provided by the SQL Anywhere DBCAPI library. This driver
5
- is intended to be a base-level library to be used by interface libraries
6
- such as Ruby-DBI and ActiveRecord.
7
-
8
- This driver can be used with SQL Anywhere 11 and SQL Anywhere 10.
9
-
10
- This driver is licensed under the Apache License, Version 2.
11
-
12
- ==Build Instructions
13
-
14
- ===Requirements
15
- * C Compiler
16
- * Ruby
17
- * RubyGem Package manager
18
-
19
-
20
- ===All Platforms
21
-
22
- To build the library (.so), use:
23
-
24
- rake
25
-
26
- To build and install the gem, use:
27
-
28
- rake gem
29
- rake install
30
-
31
- The other rake tasks are
32
-
33
- rake clean -> Cleans up all temp files (ex *.~)
34
- rake clobber -> Cleans up all built files (ex *.gem, *.o, *.so)
35
-
36
- ===Additional Install Notes for Windows
37
-
38
- The popular One-Click Ruby Installer for Windows (RubyInstaller) is built using
39
- Microsoft Visual C++ 6.0. Since problems can arise by combining binaries from
40
- different compilers, we advise you use this compiler.
41
-
42
- If you want to use a more recent version of the MS C++ compiler, you will need to make a few changes:
43
-
44
- 1. Open the file: <RUBY DIR>\lib\ruby\1.8\i386-mswin32\config.h, and comment out the first three lines so they look like:
45
-
46
- //#if _MSC_VER != 1200
47
- //#error MSC version unmatch
48
- //#endif
49
-
50
- This removes the check for C++ Version 6.0
51
-
52
- 2. Open <tt>rakefile</tt> and set:
53
-
54
- APPLY_MANIFEST = true
55
-
56
- This will add the manifest to the compiled binaries.
57
-
58
- By default, rake will attempt to use Microsoft <tt>nmake</tt> when building under Windows. To use another make program, set:
59
-
60
- USE_NMAKE_ON_WIN = FALSE
61
-
62
- ==Running Unit Tests
63
-
64
- 1. Change to the the <tt>test</tt> directory
65
-
66
- cd test
67
-
68
- 2. Create a testing database:
69
-
70
- dbinit test
71
-
72
- 3. Start the testing database:
73
-
74
- dbeng11 test.db
75
-
76
- 4. Create the test schema:
77
-
78
- dbisql -c "eng=test;uid=dba;pwd=sql" test.sql
79
-
80
- 5. Run the unit tests:
81
-
82
- ruby sqlanywhere_test.rb
83
-
84
- <b>If the tests fail to run, make sure you have set up the SQL Anywhere environment variables correctly.</b> For more information
85
- review the online documentation here[http://dcx.sybase.com/index.php#http%3A%2F%2Fdcx.sybase.com%2F1100en%2Fdbadmin_en11%2Fda-envvar-sect1-3672410.html].
86
-
87
- ==Sample
88
-
89
- This script makes a connection, prints <tt>Successful Ruby Connection</tt> to the SQL
90
- Anywhere console, then disconnects.
91
-
92
- # load the SQLAnywhere gem
93
- begin
94
- require 'rubygems'
95
- gem 'sqlanywhere'
96
- unless defined? SQLAnywhere
97
- require 'sqlanywhere'
98
- end
99
- end
100
-
101
- # create an interface
102
- api = SQLAnywhere::SQLAnywhereInterface.new()
103
-
104
- # initialize the interface (loads the DLL/SO)
105
- SQLAnywhere::API.sqlany_initialize_interface( api )
106
-
107
- # initialize our api object
108
- api.sqlany_init()
109
-
110
- # create a connection
111
- conn = api.sqlany_new_connection()
112
-
113
- # establish a connection
114
- api.sqlany_connect(conn, "uid=dba;pwd=sql")
115
-
116
- # execute a query without a result set
117
- api.sqlany_execute_immediate(conn, "MESSAGE 'Successful Ruby Connection'")
118
-
119
- # disconnect from the database
120
- api.sqlany_disconnect(conn)
121
-
122
- # free the connection resources
123
- api.sqlany_free_connection(conn)
124
-
125
- # free resources the api object uses
126
- api.sqlany_fini()
127
-
128
- # close the interface
129
- SQLAnywhere::API.sqlany_finalize_interface( api )
130
-
1
+ =SQL Anywhere Ruby Driver
2
+
3
+ This is a native SQL Anywhere driver for Ruby. This library wraps the
4
+ functionality provided by the SQL Anywhere DBCAPI library. This driver
5
+ is intended to be a base-level library to be used by interface libraries
6
+ such as Ruby-DBI and ActiveRecord.
7
+
8
+ This driver can be used with SQL Anywhere 11 and SQL Anywhere 10.
9
+
10
+ This driver is licensed under the Apache License, Version 2.
11
+
12
+ The official code repository is located on GitHub. The repository can be cloned with:
13
+
14
+ git clone git://github.com/sqlanywhere/sqlanywhere.git
15
+
16
+ ==Build Instructions
17
+
18
+ ===Requirements
19
+ * C Compiler
20
+ * Ruby
21
+ * RubyGem Package manager
22
+
23
+
24
+ ===All Platforms
25
+
26
+ To build the library (.so), use:
27
+
28
+ rake
29
+
30
+ To build and install the gem, use:
31
+
32
+ rake gem
33
+ rake install
34
+
35
+ The other rake tasks are
36
+
37
+ rake clean -> Cleans up all temp files (ex *.~)
38
+ rake clobber -> Cleans up all built files (ex *.gem, *.o, *.so)
39
+
40
+ ===Additional Install Notes for Windows
41
+
42
+ The popular One-Click Ruby Installer for Windows (RubyInstaller) is built using
43
+ Microsoft Visual C++ 6.0. Since problems can arise by combining binaries from
44
+ different compilers, we advise you use this compiler.
45
+
46
+ If you want to use a more recent version of the MS C++ compiler, you will need to make a few changes:
47
+
48
+ 1. Open the file: <RUBY DIR>\lib\ruby\1.8\i386-mswin32\config.h, and comment out the first three lines so they look like:
49
+
50
+ //#if _MSC_VER != 1200
51
+ //#error MSC version unmatch
52
+ //#endif
53
+
54
+ This removes the check for C++ Version 6.0
55
+
56
+ 2. Open <tt>rakefile</tt> and set:
57
+
58
+ APPLY_MANIFEST = true
59
+
60
+ This will add the manifest to the compiled binaries.
61
+
62
+ By default, rake will attempt to use Microsoft <tt>nmake</tt> when building under Windows. To use another make program, set:
63
+
64
+ USE_NMAKE_ON_WIN = FALSE
65
+
66
+ ==Running Unit Tests
67
+
68
+ 1. Change to the the <tt>test</tt> directory
69
+
70
+ cd test
71
+
72
+ 2. Create a testing database:
73
+
74
+ dbinit test
75
+
76
+ 3. Start the testing database:
77
+
78
+ dbeng11 test.db
79
+
80
+ 4. Create the test schema:
81
+
82
+ dbisql -c "eng=test;uid=dba;pwd=sql" test.sql
83
+
84
+ 5. Run the unit tests:
85
+
86
+ ruby sqlanywhere_test.rb
87
+
88
+ <b>If the tests fail to run, make sure you have set up the SQL Anywhere environment variables correctly.</b> For more information
89
+ review the online documentation here[http://dcx.sybase.com/index.php#http%3A%2F%2Fdcx.sybase.com%2F1100en%2Fdbadmin_en11%2Fda-envvar-sect1-3672410.html].
90
+
91
+ ==Sample
92
+
93
+ This script makes a connection, prints <tt>Successful Ruby Connection</tt> to the SQL
94
+ Anywhere console, then disconnects.
95
+
96
+ # load the SQLAnywhere gem
97
+ begin
98
+ require 'rubygems'
99
+ gem 'sqlanywhere'
100
+ unless defined? SQLAnywhere
101
+ require 'sqlanywhere'
102
+ end
103
+ end
104
+
105
+ # create an interface
106
+ api = SQLAnywhere::SQLAnywhereInterface.new()
107
+
108
+ # initialize the interface (loads the DLL/SO)
109
+ SQLAnywhere::API.sqlany_initialize_interface( api )
110
+
111
+ # initialize our api object
112
+ api.sqlany_init()
113
+
114
+ # create a connection
115
+ conn = api.sqlany_new_connection()
116
+
117
+ # establish a connection
118
+ api.sqlany_connect(conn, "uid=dba;pwd=sql")
119
+
120
+ # execute a query without a result set
121
+ api.sqlany_execute_immediate(conn, "MESSAGE 'Successful Ruby Connection'")
122
+
123
+ # disconnect from the database
124
+ api.sqlany_disconnect(conn)
125
+
126
+ # free the connection resources
127
+ api.sqlany_free_connection(conn)
128
+
129
+ # free resources the api object uses
130
+ api.sqlany_fini()
131
+
132
+ # close the interface
133
+ SQLAnywhere::API.sqlany_finalize_interface( api )
134
+
data/Rakefile CHANGED
@@ -1,196 +1,199 @@
1
- #====================================================
2
- #
3
- # Copyright 2008-2009 iAnywhere Solutions, Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- #
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- # While not a requirement of the license, if you do modify this file, we
20
- # would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
21
- #
22
- #
23
- #====================================================
24
-
25
- require 'ftools'
26
- require 'rbconfig'
27
- require 'rake/clean'
28
- require 'rake/rdoctask'
29
- require 'rubygems'
30
- require 'rubygems/builder'
31
-
32
- # By default, windows will try to use nmake instead of make. If you are on windows but using
33
- # a different compiler that uses standard make, set this to false.
34
- USE_NMAKE_ON_WIN = true
35
-
36
- # By default on windows, ruby expects to be compiled by Visual Studio C++ 6.0. If you are using
37
- # a newer version of Visual Studio, you will need to apply a manifest to the dll. To apply the
38
- # manifest set this to true.
39
- APPLY_MANIFEST = false
40
-
41
- PACKAGE_NAME = "sqlanywhere"
42
- ARCH=Config::CONFIG['arch']
43
-
44
- pkg_version = ""
45
-
46
- library_file = ARCH =~ /darwin/ ? "sqlanywhere.bundle" : "sqlanywhere.so"
47
-
48
- # The package version of determined by parsing the c source file. This ensures the version is
49
- # only ever specified ins a single place.
50
- File.open(File.join("ext", "sqlanywhere.c") ) do |f|
51
- f.grep( /const char\* VERSION/ ) do |line|
52
- pkg_version = /\s*const char\* VERSION\s*=\s*["|']([^"']*)["|'];\s*/.match(line)[1]
53
- end
54
- end
55
-
56
- # If we can't determine the version, throw up your hands and exit
57
- raise RuntimeError, "Could not determine current package version!" if pkg_version.empty?
58
-
59
- MAKE = (ARCH =~ /win32/ and USE_NMAKE_ON_WIN) ? 'nmake' : 'make'
60
-
61
- spec = Gem::Specification.new do |spec|
62
- spec.authors = ["Eric Farrar"]
63
- spec.email = 'eric.farrar@ianywhere.com'
64
- spec.name = 'sqlanywhere'
65
- spec.summary = 'SQL Anywhere library for Ruby'
66
- spec.description = <<-EOF
67
- SQL Anywhere Driver for Ruby
68
- EOF
69
- spec.version = pkg_version
70
- spec.autorequire = 'sqlanywhere'
71
- spec.has_rdoc = true
72
- spec.rubyforge_project = 'sqlanywhere'
73
- spec.homepage = 'http://sqlanywhere.rubyforge.org'
74
- spec.platform = Gem::Platform::CURRENT
75
- spec.required_ruby_version = '>= 1.8.6'
76
- spec.require_paths = ['lib']
77
- spec.extensions << 'ext/extconf.rb'
78
- spec.test_file = 'test/sqlanywhere_test.rb'
79
- spec.rdoc_options << '--title' << 'SQL Anywhere Ruby Driver' <<
80
- '--main' << 'README' <<
81
- '--line-numbers'
82
- spec.extra_rdoc_files = ['README', 'CHANGELOG', 'LICENSE', 'ext/sqlanywhere.c']
83
- end
84
-
85
- # The default task is to build the library (.dll or .so)
86
- desc "Build the library"
87
- task :default => [File.join("lib", library_file)]
88
-
89
- # Builds the binary gem for this platform
90
- desc "Build the gem"
91
- task :gem => ["sqlanywhere-#{pkg_version}-#{spec.platform}.gem"]
92
-
93
- file "sqlanywhere-#{pkg_version}-#{spec.platform}.gem" => ["Rakefile",
94
- "test/test.sql",
95
- "test/sqlanywhere_test.rb",
96
- "README",
97
- "CHANGELOG",
98
- "LICENSE",
99
- File.join("lib", library_file)] do
100
- # Get the updated list of files to include in the gem
101
- spec.files = Dir['ext/**/*'] + Dir['lib/**/*'] + Dir['test/**/*'] + Dir['CHANGELOG'] + Dir['LICENSE'] + Dir['README'] + Dir['Rakefile']
102
- # Set the gem to be platform specific since it includes compiled binaries
103
- spec.platform = Gem::Platform::CURRENT
104
- Gem::Builder.new(spec).build
105
- end
106
-
107
- # Builds the source gem for any platform
108
- desc "Build the source gem"
109
- task :source_gem => ["sqlanywhere-#{pkg_version}.gem"]
110
-
111
- file "sqlanywhere-#{pkg_version}.gem" => ["Rakefile",
112
- "test/test.sql",
113
- "test/sqlanywhere_test.rb",
114
- "README",
115
- "CHANGELOG",
116
- "LICENSE"] do
117
- # Get the updated list of files to include in the gem
118
- spec.files = Dir['ext/**/*'] + Dir['lib/**/*'] + Dir['test/**/*'] + Dir['CHANGELOG'] + Dir['LICENSE'] + Dir['README'] + Dir['Rakefile']
119
- # Since this contains no compilked binaries, set it to be platform RUBY
120
- spec.platform = Gem::Platform::RUBY
121
- Gem::Builder.new(spec).build
122
- end
123
-
124
- file File.join("lib", library_file) => [File.join("ext", library_file)] do
125
- File.copy(File.join("ext", library_file), "lib")
126
- end
127
-
128
- file File.join("ext", library_file) => ["ext/sqlanywhere.c"] do
129
- sh "cd ext && ruby extconf.rb"
130
- sh "cd ext && #{MAKE}"
131
- sh "cd ext && mt -outputresource:sqlanywhere.so;2 -manifest sqlanywhere.so.manifest" if APPLY_MANIFEST
132
- end
133
-
134
- desc "Install the gem"
135
- task :install => [:gem] do
136
- sh "gem install sqlanywhere-#{pkg_version}-#{spec.platform}.gem"
137
- end
138
-
139
- # This builds the distributables. On windows it builds a platform specific gem, a source gem, and a souce zip archive.
140
- # On other platforms this builds a platform specific gem, a source gem, and a source tar.gz archive.
141
- desc "Build distributables (src zip, src tar.gz, gem)"
142
- task :dist do |t|
143
- puts "Cleaning Build Environment..."
144
- Rake.application['clobber'].invoke
145
-
146
- files = Dir.glob('*')
147
-
148
- puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version} directory..."
149
- FileUtils.mkdir_p "#{File.join('build', PACKAGE_NAME)}-#{pkg_version}"
150
-
151
- puts "Copying files to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}..."
152
- FileUtils.cp_r files, "#{File.join('build', PACKAGE_NAME)}-#{pkg_version}"
153
-
154
- if( ARCH =~ /win32/ ) then
155
- system "attrib -R #{File.join('build', PACKAGE_NAME)}-#{pkg_version} /S"
156
- else
157
- system "find #{File.join('build', PACKAGE_NAME)}-#{pkg_version} -type d -exec chmod 755 {} \\;"
158
- system "find #{File.join('build', PACKAGE_NAME)}-#{pkg_version} -type f -exec chmod 644 {} \\;"
159
- end
160
-
161
- if( ARCH =~ /win32/ ) then
162
- puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.zip..."
163
- system "cd build && zip -q -r #{PACKAGE_NAME}-#{pkg_version}.zip #{PACKAGE_NAME}-#{pkg_version}"
164
- else
165
- puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar..."
166
- system "tar cf #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar -C build #{PACKAGE_NAME}-#{pkg_version}"
167
-
168
- puts "GZipping to create #{File.join('build', PACKAGE_NAME, PACKAGE_NAME)}-#{pkg_version}.tar.gz..."
169
- system "gzip #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar"
170
- end
171
-
172
- puts "Building GEM source distributable..."
173
- Rake.application['source_gem'].invoke
174
-
175
- puts "Copying source GEM to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.gem..."
176
- FileUtils.cp "#{PACKAGE_NAME}-#{pkg_version}.gem", "build"
177
-
178
- puts "Building GEM binary distributable..."
179
- Rake.application['gem'].invoke
180
-
181
- puts "Copying binary GEM to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}-#{spec.platform}.gem..."
182
- FileUtils.cp "#{PACKAGE_NAME}-#{pkg_version}-#{spec.platform}.gem", "build"
183
- end
184
-
185
- Rake::RDocTask.new do |rd|
186
- rd.title = "SQL Anywhere Ruby Driver"
187
- rd.main = "README"
188
- rd.rdoc_files.include('README', 'CHANGELOG', 'LICENSE', 'ext/sqlanywhere.c')
189
- end
190
-
191
- desc "Publish the RDOCs on RubyForge"
192
- task :publish_rdoc => ["html/index.html"] do
193
- system "pscp -r html/* efarrar@rubyforge.org:/var/www/gforge-projects/sqlanywhere/sqlanywhere"
194
- end
195
-
196
- CLOBBER.include("sqlanywhere-#{pkg_version}-#{spec.platform}.gem", "sqlanywhere-#{pkg_version}.gem", "lib/*", "ext/*.obj", "ext/*.def", "ext/*.so", "ext/*.bundle", "ext/*.log", "ext/*.exp", "ext/*.lib", "ext/*.pdb", "ext/Makefile", "ext/*.so.manifest", "ext/*.o", "build/**/*", "build")
1
+ #====================================================
2
+ #
3
+ # Copyright 2008-2009 iAnywhere Solutions, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ #
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # While not a requirement of the license, if you do modify this file, we
20
+ # would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
21
+ #
22
+ #
23
+ #====================================================
24
+
25
+ require 'ftools'
26
+ require 'rbconfig'
27
+ require 'rake/clean'
28
+ require 'rake/rdoctask'
29
+ require 'rubygems'
30
+ require 'rubygems/builder'
31
+
32
+ # By default, windows will try to use nmake instead of make. If you are on windows but using
33
+ # a different compiler that uses standard make, set this to false.
34
+ USE_NMAKE_ON_WIN = true
35
+
36
+ # By default on windows, ruby expects to be compiled by Visual Studio C++ 6.0. If you are using
37
+ # a newer version of Visual Studio, you will need to apply a manifest to the dll. To apply the
38
+ # manifest set this to true.
39
+ APPLY_MANIFEST = false
40
+
41
+ PACKAGE_NAME = "sqlanywhere"
42
+ ARCH=Config::CONFIG['arch']
43
+
44
+ Dir.mkdir('lib') unless File.directory?('lib')
45
+
46
+ pkg_version = ""
47
+
48
+ library_file = ARCH =~ /darwin/ ? "sqlanywhere.bundle" : "sqlanywhere.so"
49
+
50
+ # The package version of determined by parsing the c source file. This ensures the version is
51
+ # only ever specified ins a single place.
52
+ File.open(File.join("ext", "sqlanywhere.c") ) do |f|
53
+ f.grep( /const char\* VERSION/ ) do |line|
54
+ pkg_version = /\s*const char\* VERSION\s*=\s*["|']([^"']*)["|'];\s*/.match(line)[1]
55
+ end
56
+ end
57
+
58
+ # If we can't determine the version, throw up your hands and exit
59
+ raise RuntimeError, "Could not determine current package version!" if pkg_version.empty?
60
+
61
+ MAKE = (ARCH =~ /win32/ and USE_NMAKE_ON_WIN) ? 'nmake' : 'make'
62
+
63
+ spec = Gem::Specification.new do |spec|
64
+ spec.authors = ["Eric Farrar"]
65
+ spec.email = 'eric.farrar@ianywhere.com'
66
+ spec.name = 'sqlanywhere'
67
+ spec.summary = 'SQL Anywhere library for Ruby'
68
+ spec.description = <<-EOF
69
+ SQL Anywhere Driver for Ruby
70
+ EOF
71
+ spec.version = pkg_version
72
+ spec.autorequire = 'sqlanywhere'
73
+ spec.has_rdoc = true
74
+ spec.rubyforge_project = 'sqlanywhere'
75
+ spec.homepage = 'http://sqlanywhere.rubyforge.org'
76
+ spec.platform = Gem::Platform::CURRENT
77
+ spec.required_ruby_version = '>= 1.8.6'
78
+ spec.require_paths = ['lib']
79
+ spec.test_file = 'test/sqlanywhere_test.rb'
80
+ spec.rdoc_options << '--title' << 'SQL Anywhere Ruby Driver' <<
81
+ '--main' << 'README' <<
82
+ '--line-numbers'
83
+ spec.extra_rdoc_files = ['README', 'CHANGELOG', 'LICENSE', 'ext/sqlanywhere.c']
84
+ end
85
+
86
+ # The default task is to build the library (.dll or .so)
87
+ desc "Build the library"
88
+ task :default => [File.join("lib", library_file)]
89
+
90
+ # Builds the binary gem for this platform
91
+ desc "Build the gem"
92
+ task :gem => ["sqlanywhere-#{pkg_version}-#{spec.platform}.gem"]
93
+
94
+ file "sqlanywhere-#{pkg_version}-#{spec.platform}.gem" => ["Rakefile",
95
+ "test/test.sql",
96
+ "test/sqlanywhere_test.rb",
97
+ "README",
98
+ "CHANGELOG",
99
+ "LICENSE",
100
+ File.join("lib", library_file)] do
101
+ # Get the updated list of files to include in the gem
102
+ spec.files = Dir['ext/**/*'] + Dir['lib/**/*'] + Dir['test/**/*'] + Dir['CHANGELOG'] + Dir['LICENSE'] + Dir['README'] + Dir['Rakefile']
103
+ # Set the gem to be platform specific since it includes compiled binaries
104
+ spec.platform = Gem::Platform::CURRENT
105
+ spec.extensions = ''
106
+ Gem::Builder.new(spec).build
107
+ end
108
+
109
+ # Builds the source gem for any platform
110
+ desc "Build the source gem"
111
+ task :source_gem => ["sqlanywhere-#{pkg_version}.gem"]
112
+
113
+ file "sqlanywhere-#{pkg_version}.gem" => ["Rakefile",
114
+ "test/test.sql",
115
+ "test/sqlanywhere_test.rb",
116
+ "README",
117
+ "CHANGELOG",
118
+ "LICENSE"] do
119
+ # Get the updated list of files to include in the gem
120
+ spec.files = Dir['ext/**/*'] + Dir['lib/**/*'] + Dir['test/**/*'] + Dir['CHANGELOG'] + Dir['LICENSE'] + Dir['README'] + Dir['Rakefile']
121
+ # Since this contains no compilked binaries, set it to be platform RUBY
122
+ spec.platform = Gem::Platform::RUBY
123
+ spec.extensions = 'ext/extconf.rb'
124
+ Gem::Builder.new(spec).build
125
+ end
126
+
127
+ file File.join("lib", library_file) => [File.join("ext", library_file)] do
128
+ File.copy(File.join("ext", library_file), "lib")
129
+ end
130
+
131
+ file File.join("ext", library_file) => ["ext/sqlanywhere.c"] do
132
+ sh "cd ext && ruby extconf.rb"
133
+ sh "cd ext && #{MAKE}"
134
+ sh "cd ext && mt -outputresource:sqlanywhere.so;2 -manifest sqlanywhere.so.manifest" if APPLY_MANIFEST
135
+ end
136
+
137
+ desc "Install the gem"
138
+ task :install => [:gem] do
139
+ sh "gem install sqlanywhere-#{pkg_version}-#{spec.platform}.gem"
140
+ end
141
+
142
+ # This builds the distributables. On windows it builds a platform specific gem, a source gem, and a souce zip archive.
143
+ # On other platforms this builds a platform specific gem, a source gem, and a source tar.gz archive.
144
+ desc "Build distributables (src zip, src tar.gz, gem)"
145
+ task :dist do |t|
146
+ puts "Cleaning Build Environment..."
147
+ Rake.application['clobber'].invoke
148
+
149
+ files = Dir.glob('*')
150
+
151
+ puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version} directory..."
152
+ FileUtils.mkdir_p "#{File.join('build', PACKAGE_NAME)}-#{pkg_version}"
153
+
154
+ puts "Copying files to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}..."
155
+ FileUtils.cp_r files, "#{File.join('build', PACKAGE_NAME)}-#{pkg_version}"
156
+
157
+ if( ARCH =~ /win32/ ) then
158
+ system "attrib -R #{File.join('build', PACKAGE_NAME)}-#{pkg_version} /S"
159
+ else
160
+ system "find #{File.join('build', PACKAGE_NAME)}-#{pkg_version} -type d -exec chmod 755 {} \\;"
161
+ system "find #{File.join('build', PACKAGE_NAME)}-#{pkg_version} -type f -exec chmod 644 {} \\;"
162
+ end
163
+
164
+ if( ARCH =~ /win32/ ) then
165
+ puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.zip..."
166
+ system "cd build && zip -q -r #{PACKAGE_NAME}-#{pkg_version}.zip #{PACKAGE_NAME}-#{pkg_version}"
167
+ else
168
+ puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar..."
169
+ system "tar cf #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar -C build #{PACKAGE_NAME}-#{pkg_version}"
170
+
171
+ puts "GZipping to create #{File.join('build', PACKAGE_NAME, PACKAGE_NAME)}-#{pkg_version}.tar.gz..."
172
+ system "gzip #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar"
173
+ end
174
+
175
+ puts "Building GEM source distributable..."
176
+ Rake.application['source_gem'].invoke
177
+
178
+ puts "Copying source GEM to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.gem..."
179
+ FileUtils.cp "#{PACKAGE_NAME}-#{pkg_version}.gem", "build"
180
+
181
+ puts "Building GEM binary distributable..."
182
+ Rake.application['gem'].invoke
183
+
184
+ puts "Copying binary GEM to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}-#{spec.platform}.gem..."
185
+ FileUtils.cp "#{PACKAGE_NAME}-#{pkg_version}-#{spec.platform}.gem", "build"
186
+ end
187
+
188
+ Rake::RDocTask.new do |rd|
189
+ rd.title = "SQL Anywhere Ruby Driver"
190
+ rd.main = "README"
191
+ rd.rdoc_files.include('README', 'CHANGELOG', 'LICENSE', 'ext/sqlanywhere.c')
192
+ end
193
+
194
+ desc "Publish the RDOCs on RubyForge"
195
+ task :publish_rdoc => ["html/index.html"] do
196
+ system "pscp -r html/* efarrar@rubyforge.org:/var/www/gforge-projects/sqlanywhere/sqlanywhere"
197
+ end
198
+
199
+ CLOBBER.include("sqlanywhere-#{pkg_version}-#{spec.platform}.gem", "sqlanywhere-#{pkg_version}.gem", "lib/*", "ext/*.obj", "ext/*.def", "ext/*.so", "ext/*.bundle", "ext/*.log", "ext/*.exp", "ext/*.lib", "ext/*.pdb", "ext/Makefile", "ext/*.so.manifest", "ext/*.o", "build/**/*", "build")