Skip to content

Commit

Permalink
Add rake set-version-to-timestamp task
Browse files Browse the repository at this point in the history
This ensures the generated gem has a unique version number, so define
`RE2::VERSION` in a separate file to make this possible.
  • Loading branch information
stanhu committed Jul 18, 2023
1 parent 7eb8da7 commit bfc359a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,28 @@ task gem_build_path do
add_vendored_libraries
end

desc "Temporarily set VERSION to a unique timestamp"
task "set-version-to-timestamp" do
# this task is used by bin/test-gem-build
# to test building, packaging, and installing a precompiled gem
version_constant_re = /^\s*VERSION\s*=\s*["'](.*)["']$/

version_file_path = File.join(__dir__, "lib/re2/version.rb")
version_file_contents = File.read(version_file_path)

current_version_string = version_constant_re.match(version_file_contents)[1]
current_version = Gem::Version.new(current_version_string)

fake_version = Gem::Version.new(format("%s.test.%s", current_version.bump, Time.now.strftime("%Y.%m%d.%H%M")))

unless version_file_contents.gsub!(version_constant_re, " VERSION = \"#{fake_version}\"")
raise("Could not hack the VERSION constant")
end

File.open(version_file_path, "w") { |f| f.write(version_file_contents) }

puts "NOTE: wrote version as \"#{fake_version}\""
end

task :spec => :compile
task :default => :spec
1 change: 1 addition & 0 deletions lib/re2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
end

require "re2/scanner"
require "re2/version"
5 changes: 5 additions & 0 deletions lib/re2/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module RE2
VERSION = "1.7.0"
end
9 changes: 8 additions & 1 deletion re2.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
begin
require File.expand_path(File.join(File.dirname(__FILE__), "lib/re2/version"))
rescue LoadError
puts "WARNING: Could not load RE2::VERSION"
end

Gem::Specification.new do |s|
s.name = "re2"
s.summary = "Ruby bindings to re2."
s.description = 'Ruby bindings to re2, "an efficient, principled regular expression library".'
s.version = "1.7.0"
s.version = defined?(RE2::VERSION) ? RE2::VERSION : "0.0.0"
s.authors = ["Paul Mucur"]
s.homepage = "https://github.com/mudge/re2"
s.extensions = ["ext/re2/extconf.rb"]
Expand All @@ -15,6 +21,7 @@ Gem::Specification.new do |s|
"lib/re2.rb",
"lib/re2/scanner.rb",
"lib/re2/string.rb",
"lib/re2/version.rb",
"LICENSE.txt",
"README.md",
"Rakefile"
Expand Down
32 changes: 32 additions & 0 deletions scripts/test-gem-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env bash
#
# run as part of CI
#
if [[ $# -lt 2 ]] ; then
echo "usage: $(basename $0) <output_dir> <platform>"
exit 1
fi

set -e -u

OUTPUT_DIR=$1
BUILD_NATIVE_GEM=$2

test -e /etc/os-release && cat /etc/os-release

set -x

bundle install --local || bundle install
bundle exec rake set-version-to-timestamp

if [[ "${BUILD_NATIVE_GEM}" == "ruby" ]] ; then
# TODO we're only compiling so that we retrieve tarballs, we can do better.
bundle exec rake clean compile
bundle exec rake gem
else
bundle exec rake gem:${BUILD_NATIVE_GEM}:builder
fi

mkdir -p ${OUTPUT_DIR}
cp -v pkg/*.gem ${OUTPUT_DIR}
ls -l ${OUTPUT_DIR}/*
33 changes: 33 additions & 0 deletions scripts/test-gem-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env bash
#
# run as part of CI
#
if [[ $# -lt 1 ]] ; then
echo "usage: $(basename $0) <gems_dir> [install_flags]"
exit 1
fi

GEMS_DIR=$1
shift
INSTALL_FLAGS=$*

test -e /etc/os-release && cat /etc/os-release

set -e -x -u

pushd $GEMS_DIR

gemfile=$(ls *.gem | head -n1)
ls -l ${gemfile}
gem install --no-document ${gemfile} -- ${INSTALL_FLAGS}
gem list -d re2
popd

if [ -n "${BUNDLE_APP_CONFIG:-}" ] ; then
export BUNDLE_CACHE_PATH="${BUNDLE_APP_CONFIG}/cache"
fi

bundle install --local || bundle install

rm -rf lib ext # ensure we don't use the local files
rake spec

0 comments on commit bfc359a

Please sign in to comment.