Skip to content

Commit

Permalink
Merge pull request #581 from sparklemotion/flavorjones-version-info
Browse files Browse the repository at this point in the history
Track metadata in VERSION_INFO
  • Loading branch information
flavorjones authored Nov 19, 2024
2 parents ef13fcb + bdefd49 commit 48eb4fc
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .rdoc_options
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ exclude:
- "bin"
- "rakelib"
- "ext/sqlite3/extconf.rb"
- "vendor"
- "ports"
- "tmp"
hyperlink_all: false
line_numbers: false
locale:
Expand Down
3 changes: 3 additions & 0 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def configure_packaged_libraries
end

ldflags.each { |ldflag| append_ldflags(ldflag) }

append_cppflags("-DUSING_PACKAGED_LIBRARIES")
append_cppflags("-DUSING_PRECOMPILED_LIBRARIES") if cross_build?
end
end

Expand Down
17 changes: 17 additions & 0 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,25 @@ Init_sqlite3_native(void)
rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
rb_define_singleton_method(mSqlite3, "status", rb_sqlite3_status, -1);

/* (String) The version of the sqlite3 library compiled with (e.g., "3.46.1") */
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));

/* (Integer) The version of the sqlite3 library compiled with (e.g., 346001) */
rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));

/* (String) The version of the sqlite3 library loaded at runtime (e.g., "3.46.1") */
rb_define_const(mSqlite3, "SQLITE_LOADED_VERSION", rb_str_new2(sqlite3_libversion()));

#ifdef USING_PACKAGED_LIBRARIES
rb_define_const(mSqlite3, "SQLITE_PACKAGED_LIBRARIES", Qtrue);
#else
rb_define_const(mSqlite3, "SQLITE_PACKAGED_LIBRARIES", Qfalse);
#endif

#ifdef USING_PRECOMPILED_LIBRARIES
rb_define_const(mSqlite3, "SQLITE_PRECOMPILED_LIBRARIES", Qtrue);
#else
rb_define_const(mSqlite3, "SQLITE_PRECOMPILED_LIBRARIES", Qfalse);
#endif
}
2 changes: 2 additions & 0 deletions lib/sqlite3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ def self.threadsafe?
threadsafe > 0
end
end

require "sqlite3/version_info"
1 change: 1 addition & 0 deletions lib/sqlite3/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module SQLite3
# (String) the version of the sqlite3 gem, e.g. "2.1.1"
VERSION = "2.2.0"
end
17 changes: 17 additions & 0 deletions lib/sqlite3/version_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SQLite3
# a hash of descriptive metadata about the current version of the sqlite3 gem
VERSION_INFO = {
ruby: RUBY_DESCRIPTION,
gem: {
version: SQLite3::VERSION
},
sqlite: {
compiled: SQLite3::SQLITE_VERSION,
loaded: SQLite3::SQLITE_LOADED_VERSION,
packaged: SQLite3::SQLITE_PACKAGED_LIBRARIES,
precompiled: SQLite3::SQLITE_PRECOMPILED_LIBRARIES,
sqlcipher: SQLite3.sqlcipher?,
threadsafe: SQLite3.threadsafe?
}
}
end
1 change: 1 addition & 0 deletions rakelib/check-manifest.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ task :check_manifest do
.git
.github
.ruby-lsp
adr
bin
doc
gems
Expand Down
3 changes: 2 additions & 1 deletion sqlite3.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Gem::Specification.new do |s|
"lib/sqlite3/resultset.rb",
"lib/sqlite3/statement.rb",
"lib/sqlite3/value.rb",
"lib/sqlite3/version.rb"
"lib/sqlite3/version.rb",
"lib/sqlite3/version_info.rb"
]

s.extra_rdoc_files = [
Expand Down
7 changes: 2 additions & 5 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require "sqlite3"
require "minitest/autorun"
require "yaml"

puts "info: ruby version: #{RUBY_DESCRIPTION}"
puts "info: gem version: #{SQLite3::VERSION}"
puts "info: sqlite version: #{SQLite3::SQLITE_VERSION}/#{SQLite3::SQLITE_LOADED_VERSION}"
puts "info: sqlcipher?: #{SQLite3.sqlcipher?}"
puts "info: threadsafe?: #{SQLite3.threadsafe?}"
puts SQLite3::VERSION_INFO.to_yaml

module SQLite3
class TestCase < Minitest::Test
Expand Down

0 comments on commit 48eb4fc

Please sign in to comment.