summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-06-13 08:48:33 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-06-13 08:48:33 -0500
commit3c552274695aae4439ce0a6d83dd36c8179089cf (patch)
treec999cd5116f480f525026bb672cdac5587146724
parent85992a5d4a25712c7367f889e9f3589928449673 (diff)
downloadbundler-seg-version-build-metadata.tar.gz
Avoid git shenanigans with the build metadata fileseg-version-build-metadata
-rw-r--r--Rakefile4
-rw-r--r--lib/bundler.rb2
-rw-r--r--lib/bundler/build_metadata.rb36
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/env.rb1
-rw-r--r--lib/bundler/generated/build_metadata.rb9
-rw-r--r--spec/commands/version_spec.rb6
-rw-r--r--spec/install/gemfile/git_spec.rb4
-rw-r--r--task/build_metadata.rake37
-rw-r--r--task/git_hooks.rake12
-rw-r--r--task/release.rake7
11 files changed, 76 insertions, 44 deletions
diff --git a/Rakefile b/Rakefile
index 7074f83026..245de80793 100644
--- a/Rakefile
+++ b/Rakefile
@@ -354,10 +354,6 @@ task :update_certs => "spec:rubygems:clone_rubygems_master" do
Bundler::SSLCerts::CertificateManager.update_from!(RUBYGEMS_REPO)
end
-require "bundler/gem_tasks"
-task :build => ["man:build", "generate_files"]
-task :release => ["man:require", "man:build"]
-
task :default => :spec
Dir["task/*.{rb,rake}"].each(&method(:load))
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 6828455684..9ef9e13a67 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -13,7 +13,7 @@ require "bundler/rubygems_integration"
require "bundler/version"
require "bundler/constants"
require "bundler/current_ruby"
-require "bundler/generated/build_metadata"
+require "bundler/build_metadata"
module Bundler
environment_preserver = EnvironmentPreserver.new(ENV, %w[PATH GEM_PATH])
diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb
new file mode 100644
index 0000000000..54436f982d
--- /dev/null
+++ b/lib/bundler/build_metadata.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+module Bundler
+ # Represents metadata from when the Bundler gem was built.
+ module BuildMetadata
+ # begin ivars
+ @release = false
+ # end ivars
+
+ # A hash representation of the build metadata.
+ def self.to_h
+ {
+ "Built At" => built_at,
+ "Git SHA" => git_commit_sha,
+ "Released Version" => release?,
+ }
+ end
+
+ # A string representing the date the bundler gem was built.
+ def self.built_at
+ @built_at ||= Time.now.utc.strftime("%Y-%m-%d").freeze
+ end
+
+ # The SHA for the git commit the bundler gem was built from.
+ def self.git_commit_sha
+ @git_commit_sha ||= Dir.chdir(File.expand_path("..", __FILE__)) do
+ `git rev-parse --short HEAD`.strip.freeze
+ end
+ end
+
+ # Whether this is an official release build of Bundler.
+ def self.release?
+ @release
+ end
+ end
+end
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index f09cfb95cd..d237901369 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -394,7 +394,7 @@ module Bundler
desc "version", "Prints the bundler's version information"
def version
if ARGV.include?("version")
- build_info = " (#{BUILD_METADATA[:built_at]} commit #{BUILD_METADATA[:git_sha]})"
+ build_info = " (#{BuildMetadata.built_at} commit #{BuildMetadata.git_commit_sha})"
end
Bundler.ui.info "Bundler version #{Bundler::VERSION}#{build_info}"
end
diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb
index 325b96fbfa..333173ac27 100644
--- a/lib/bundler/env.rb
+++ b/lib/bundler/env.rb
@@ -14,6 +14,7 @@ module Bundler
out = String.new
append_formatted_table("Environment", environment, out)
+ append_formatted_table("Bundler Build Metadata", BuildMetadata.to_h, out)
unless Bundler.settings.all.empty?
out << "\n## Bundler settings\n\n```\n"
diff --git a/lib/bundler/generated/build_metadata.rb b/lib/bundler/generated/build_metadata.rb
deleted file mode 100644
index 1f7bbda390..0000000000
--- a/lib/bundler/generated/build_metadata.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-module Bundler
- BUILD_METADATA = {
- :built_at => Time.now.strftime("%Y-%m-%d").freeze,
- :git_sha => Dir.chdir(File.expand_path("..", __FILE__)) { `git rev-parse --short HEAD`.strip }.freeze,
- :release => false,
- }.freeze
-end
diff --git a/spec/commands/version_spec.rb b/spec/commands/version_spec.rb
index 4feac234a8..478edb9e67 100644
--- a/spec/commands/version_spec.rb
+++ b/spec/commands/version_spec.rb
@@ -17,10 +17,10 @@ RSpec.describe "bundle version" do
context "with version" do
it "outputs the version with build metadata" do
- date = Bundler::BUILD_METADATA[:built_at]
- git_sha = Bundler::BUILD_METADATA[:git_sha]
+ date = Bundler::BuildMetadata.built_at
+ git_commit_sha = Bundler::BuildMetadata.git_commit_sha
bundle! "version"
- expect(out).to eq("Bundler version #{Bundler::VERSION} (#{date} commit #{git_sha})")
+ expect(out).to eq("Bundler version #{Bundler::VERSION} (#{date} commit #{git_commit_sha})")
end
end
end
diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb
index 31abb4de72..59bbc9c016 100644
--- a/spec/install/gemfile/git_spec.rb
+++ b/spec/install/gemfile/git_spec.rb
@@ -1144,11 +1144,11 @@ RSpec.describe "bundle install with git sources" do
end
`git commit -m 'commit for iteration #{i}' ext/foo.c`
end
- git_sha = git_reader.ref_for("HEAD")
+ git_commit_sha = git_reader.ref_for("HEAD")
install_gemfile <<-G
source "file://#{gem_repo1}"
- gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{git_sha}"
+ gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{git_commit_sha}"
G
run <<-R
diff --git a/task/build_metadata.rake b/task/build_metadata.rake
index a896ed4801..e06a795259 100644
--- a/task/build_metadata.rake
+++ b/task/build_metadata.rake
@@ -1,20 +1,33 @@
# frozen_string_literal: true
-file "lib/bundler/generated/build_metadata.rb" => [".git/HEAD", ".git/logs/HEAD", __FILE__, :git_hooks] do |t|
- sh "git update-index --assume-unchanged #{t.name}", :verbose => false
+def write_build_metadata(build_metadata)
+ build_metadata_file = "lib/bundler/build_metadata.rb"
+
+ ivars = build_metadata.sort.map do |k, v|
+ " @#{k} = #{BUNDLER_SPEC.send(:ruby_code, v)}"
+ end.join("\n")
+
+ contents = File.read(build_metadata_file)
+ contents.sub!(/^(\s+# begin ivars).+(^\s+# end ivars)/m, "\\1\n#{ivars}\n\\2")
+ File.open(build_metadata_file, "w") {|f| f << contents }
+end
+
+task :build_metadata do
build_metadata = {
- :built_at => BUNDLER_SPEC.date.strftime("%Y-%m-%d"),
- :git_sha => `git rev-parse --short HEAD`.strip,
+ :built_at => BUNDLER_SPEC.date.utc.strftime("%Y-%m-%d"),
+ :git_commit_sha => `git rev-parse --short HEAD`.strip,
:release => Rake::Task["release"].instance_variable_get(:@already_invoked),
}
- File.open(t.name, "w") {|f| f << <<-RUBY }
-# frozen_string_literal: true
-
-module Bundler
- BUILD_METADATA = {
-#{build_metadata.sort.map {|k, v| " #{k.inspect} => #{BUNDLER_SPEC.send(:ruby_code, v)}," }.join("\n")}
- }.freeze
+ write_build_metadata(build_metadata)
end
- RUBY
+
+namespace :build_metadata do
+ task :clean do
+ build_metadata = {
+ :release => false,
+ }
+
+ write_build_metadata(build_metadata)
+ end
end
diff --git a/task/git_hooks.rake b/task/git_hooks.rake
index 0b8aab2ff9..e70d66afaa 100644
--- a/task/git_hooks.rake
+++ b/task/git_hooks.rake
@@ -1,18 +1,6 @@
# frozen_string_literal: true
directory ".git/hooks"
-file ".git/hooks/post-commit" => [__FILE__] do |t|
- File.open(t.name, "w") {|f| f << <<-SH }
-#! /usr/bin/env sh
-
-set -e
-
-.git/hooks/run-ruby bin/rake generate_files
- SH
-
- chmod 0o755, t.name, :verbose => false
-end
-
file ".git/hooks/pre-commit" => [__FILE__] do |t|
File.open(t.name, "w") {|f| f << <<-SH }
#!/bin/sh
diff --git a/task/release.rake b/task/release.rake
index 104fe1f857..8feaec3ae4 100644
--- a/task/release.rake
+++ b/task/release.rake
@@ -1,4 +1,11 @@
# frozen_string_literal: true
+
+require "bundler/gem_tasks"
+task :build => ["build_metadata", "man:build", "generate_files"] do
+ Rake::Task["build_metadata:clean"].tap(&:reenable).real_invoke
+end
+task :release => ["man:require", "man:build", "build_metadata"]
+
namespace :release do
def confirm(prompt = "")
loop do