diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-29 00:31:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-30 19:03:18 +0900 |
commit | b2d96abb42abbe2e01f010ffc9ac51f0f9a50002 (patch) | |
tree | 57791da8a71280c335109916376e13f5e0c63af3 /lib/tracer/tracer.gemspec | |
parent | cfbae7dae052180e5dde05a27948ae8d779eccab (diff) |
Extract version number from the source
"requiring version.rb" strategy has some issues.
- cannot work when cross-compiling
- often introduces wrong namespace
- must know the superclasses
- costs at each runtime than at build-time
etc.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3375
Diffstat (limited to 'lib/tracer/tracer.gemspec')
-rw-r--r-- | lib/tracer/tracer.gemspec | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/tracer/tracer.gemspec b/lib/tracer/tracer.gemspec index 9eab333f79..63e845cf84 100644 --- a/lib/tracer/tracer.gemspec +++ b/lib/tracer/tracer.gemspec @@ -1,13 +1,15 @@ -begin - require_relative "lib/tracer/version" -rescue LoadError - # for Ruby core repository - require_relative "version" +# frozen_string_literal: true + +name = File.basename(__FILE__, ".gemspec") +version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir| + break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line| + /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1 + end rescue nil end Gem::Specification.new do |spec| - spec.name = "tracer" - spec.version = Tracer::VERSION + spec.name = name + spec.version = version spec.authors = ["Keiju ISHITSUKA"] spec.email = ["keiju@ruby-lang.org"] |