summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-07-31 10:00:21 -0400
committerSamuel Giddins <segiddins@segiddins.me>2017-08-19 00:24:34 -0400
commitec4e3e74760ca14b4c50fc5b6e09820527015ba4 (patch)
tree7b1bdc9b0eff247cad521433ffbe3f6021bc5734
parent1d91876ec50215f30a1b48dec9e919f9a9bcebdd (diff)
downloadbundler-ec4e3e74760ca14b4c50fc5b6e09820527015ba4.tar.gz
Globally cache built extensions for RG & Git sources
-rw-r--r--lib/bundler/rubygems_gem_installer.rb22
-rw-r--r--lib/bundler/source/git.rb5
-rw-r--r--lib/bundler/source/path.rb7
-rw-r--r--lib/bundler/source/path/installer.rb1
-rw-r--r--lib/bundler/source/rubygems.rb8
5 files changed, 41 insertions, 2 deletions
diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb
index 1d9da0e329..dc77168ed6 100644
--- a/lib/bundler/rubygems_gem_installer.rb
+++ b/lib/bundler/rubygems_gem_installer.rb
@@ -18,6 +18,28 @@ module Bundler
super && validate_bundler_checksum(options[:bundler_expected_checksum])
end
+ def build_extensions
+ extension_cache_path = options[:bundler_extension_cache_path]
+ return super unless extension_cache_path
+
+ extension_dir = Pathname.new(spec.extension_dir)
+ build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)
+ if build_complete && !options[:force]
+ SharedHelpers.filesystem_access(extension_dir.parent, &:mkpath)
+ SharedHelpers.filesystem_access(extension_cache_path) do
+ FileUtils.cp_r extension_cache_path, spec.extension_dir
+ end
+ else
+ super
+ if extension_dir.directory? # not made for gems without extensions
+ SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath)
+ SharedHelpers.filesystem_access(extension_cache_path) do
+ FileUtils.cp_r extension_dir, extension_cache_path
+ end
+ end
+ end
+ end
+
private
def validate_bundler_checksum(checksum)
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index fd8f6debea..c21dc75e54 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -219,6 +219,11 @@ module Bundler
end
end
+ def extension_cache_path(spec)
+ return unless Bundler.feature_flag.global_gem_cache?
+ cache_path.join("extensions", Bundler.ruby_scope, spec.full_name)
+ end
+
def app_cache_dirname
"#{base_name}-#{shortref_for_path(cached_revision || revision)}"
end
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index 806ba81935..64d00e2ec6 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -227,7 +227,8 @@ module Bundler
spec,
:env_shebang => false,
:disable_extensions => options[:disable_extensions],
- :build_args => options[:build_args]
+ :build_args => options[:build_args],
+ :bundler_extension_cache_path => extension_cache_path(spec)
)
installer.post_install
rescue Gem::InvalidSpecificationException => e
@@ -243,6 +244,10 @@ module Bundler
Bundler.ui.warn "The validation message from RubyGems was:\n #{e.message}"
end
+
+ def extension_cache_path(spec)
+ nil
+ end
end
end
end
diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb
index 64e63766dd..a0357ffa39 100644
--- a/lib/bundler/source/path/installer.rb
+++ b/lib/bundler/source/path/installer.rb
@@ -7,6 +7,7 @@ module Bundler
attr_reader :spec
def initialize(spec, options = {})
+ @options = options
@spec = spec
@gem_dir = Bundler.rubygems.path(spec.full_gem_path)
@wrappers = true
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 70dc5ac038..7939e6db77 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -148,7 +148,8 @@ module Bundler
:wrappers => true,
:env_shebang => true,
:build_args => opts[:build_args],
- :bundler_expected_checksum => spec.respond_to?(:checksum) && spec.checksum
+ :bundler_expected_checksum => spec.respond_to?(:checksum) && spec.checksum,
+ :bundler_extension_cache_path => extension_cache_path(spec)
).install
end
spec.full_gem_path = installed_spec.full_gem_path
@@ -498,6 +499,11 @@ module Bundler
Bundler.user_cache.join("gems", cache_slug, spec.file_name)
end
+
+ def extension_cache_path(spec)
+ return unless download_path = download_cache_path(spec)
+ download_path.parent.join("extensions", Bundler.ruby_scope, spec.full_name)
+ end
end
end
end