diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-08-17 17:23:49 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-08-19 00:25:26 -0400 |
commit | 597d0b832aef22fb895c98bcb3606f2748565129 (patch) | |
tree | 25f0e65a2f48fd8c9a15a0aca1cf133895537825 | |
parent | a12410d52bc3190c16965dfdfbfc703d0776b2ca (diff) | |
download | bundler-seg-globally-cache-built-extensions.tar.gz |
Move cached extensions to cache/extensionsseg-globally-cache-built-extensions
-rw-r--r-- | lib/bundler/source.rb | 13 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 15 | ||||
-rw-r--r-- | lib/bundler/source/path.rb | 4 | ||||
-rw-r--r-- | lib/bundler/source/rubygems.rb | 6 | ||||
-rw-r--r-- | spec/install/global_cache_spec.rb | 46 | ||||
-rw-r--r-- | spec/support/builders.rb | 8 |
6 files changed, 74 insertions, 18 deletions
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 38e001535c..956cf39d56 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -73,5 +73,18 @@ module Bundler Bundler.ui.info message end end + + def extension_cache_path(spec) + return unless Bundler.feature_flag.global_gem_cache? + return unless source_slug = extension_cache_slug(spec) + Bundler.user_cache.join( + "extensions", Gem::Platform.local.to_s, Bundler.ruby_scope, + source_slug, spec.full_name + ) + end + + def extension_cache_slug(_) + nil + end end end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index ce9ffc9c3b..c66cbb17fb 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -209,8 +209,6 @@ module Bundler # When using local git repos, this is set to the local repo. def cache_path @cache_path ||= begin - git_scope = "#{base_name}-#{uri_hash}" - if Bundler.requires_sudo? || Bundler.feature_flag.global_gem_cache? Bundler.user_cache else @@ -219,11 +217,6 @@ module Bundler end end - def extension_cache_path(spec) - return unless Bundler.feature_flag.global_gem_cache? - cache_path.join("extensions", Bundler.ruby_scope, extension_dir_name) - end - def app_cache_dirname "#{base_name}-#{shortref_for_path(cached_revision || revision)}" end @@ -323,6 +316,14 @@ module Bundler StubSpecification.from_stub(stub) end end + + def git_scope + "#{base_name}-#{uri_hash}" + end + + def extension_cache_slug(_) + extension_dir_name + end end end end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 64d00e2ec6..afd8723168 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -244,10 +244,6 @@ 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/rubygems.rb b/lib/bundler/source/rubygems.rb index 7939e6db77..fa60bb0c84 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -500,9 +500,9 @@ 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) + def extension_cache_slug(spec) + return unless remote = spec.remote + remote.cache_slug end end end diff --git a/spec/install/global_cache_spec.rb b/spec/install/global_cache_spec.rb index c48bb1bd89..3664d3963a 100644 --- a/spec/install/global_cache_spec.rb +++ b/spec/install/global_cache_spec.rb @@ -186,4 +186,50 @@ RSpec.describe "global gem caching" do end end end + + describe "extension caching", :rubygems => "2.2" do + it "works" do + build_git "very_simple_git_binary", &:add_c_extension + build_lib "very_simple_path_binary", &:add_c_extension + revision = revision_for(lib_path("very_simple_git_binary-1.0"))[0, 12] + + install_gemfile! <<-G + source "file:#{gem_repo1}" + + gem "very_simple_binary" + gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}" + gem "very_simple_path_binary", :path => "#{lib_path("very_simple_path_binary-1.0")}" + G + + gem_binary_cache = home(".bundle", "cache", "extensions", specific_local_platform.to_s, Bundler.ruby_scope, + Digest(:MD5).hexdigest("#{gem_repo1}/"), "very_simple_binary-1.0") + git_binary_cache = home(".bundle", "cache", "extensions", specific_local_platform.to_s, Bundler.ruby_scope, + "very_simple_git_binary-1.0-#{revision}", "very_simple_git_binary-1.0") + + cached_extensions = Pathname.glob(home(".bundle", "cache", "extensions", "*", "*", "*", "*", "*")).sort + expect(cached_extensions).to eq [gem_binary_cache, git_binary_cache].sort + + run! <<-R + require 'very_simple_binary_c'; puts ::VERY_SIMPLE_BINARY_IN_C + require 'very_simple_git_binary_c'; puts ::VERY_SIMPLE_GIT_BINARY_IN_C + R + expect(out).to eq "VERY_SIMPLE_BINARY_IN_C\nVERY_SIMPLE_GIT_BINARY_IN_C" + + FileUtils.rm Dir[home(".bundle", "cache", "extensions", "**", "*binary_c*")] + + gem_binary_cache.join("very_simple_binary_c.rb").open("w") {|f| f << "puts File.basename(__FILE__)" } + git_binary_cache.join("very_simple_git_binary_c.rb").open("w") {|f| f << "puts File.basename(__FILE__)" } + + bundle! "config --local path different_path" + bundle! :install + + expect(Dir[home(".bundle", "cache", "extensions", "**", "*binary_c*")]).to all(end_with(".rb")) + + run! <<-R + require 'very_simple_binary_c' + require 'very_simple_git_binary_c' + R + expect(out).to eq "very_simple_binary_c.rb\nvery_simple_git_binary_c.rb" + end + end end diff --git a/spec/support/builders.rb b/spec/support/builders.rb index 93b173a5d0..e8208eacd9 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -566,7 +566,7 @@ module Spec # exit 1 unless with_config("simple") - extension_name = "very_simple_binary_c" + extension_name = "#{name}_c" if extra_lib_dir = with_config("ext-lib") # add extra libpath if --with-ext-lib is # passed in as a build_arg @@ -576,11 +576,11 @@ module Spec end create_makefile extension_name RUBY - write "ext/very_simple_binary.c", <<-C + write "ext/#{name}.c", <<-C #include "ruby.h" - void Init_very_simple_binary_c() { - rb_define_module("VerySimpleBinaryInC"); + void Init_#{name}_c() { + rb_define_module("#{Builders.constantize(name)}_IN_C"); } C end |