rubygems-precompiled 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/features/installing_with_cache.feature +6 -7
- data/features/precompiling_gems.feature +1 -0
- data/features/steps/command_steps.rb +20 -5
- data/features/steps/file_steps.rb +2 -1
- data/features/steps/rubygem_steps.rb +6 -0
- data/lib/rubygems/precompiled.rb +39 -89
- data/lib/rubygems/precompiled/base_cache.rb +19 -0
- data/lib/rubygems/precompiled/file_cache.rb +17 -0
- data/lib/rubygems/precompiled/http_cache.rb +30 -0
- data/lib/rubygems/precompiled/version.rb +1 -1
- data/lib/rubygems/precompiler.rb +8 -8
- data/rubygems-precompiled.gemspec +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 718a7b49fe7f73247987a88ae55bbfddf0efee7e
|
4
|
+
data.tar.gz: 7b0c230d2c75810b6c936b2d83a5fb46641f3bac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9f67856cba175412a497ce3a67b17ac26cf3fd56062cfb6b55614ca297b2f31bfd1bca00af96231274886e708fe231901c9a93d8216c30027bb7892531a3a11
|
7
|
+
data.tar.gz: e5c35c515a6cfc1598e30a15aaf37b94c70cb073c22080e3b0763cdb58d2305e36592f1ec61dc05bb192ce16f09011dc1ce761e94d841c27a3b51a6c958e9ea9
|
@@ -3,8 +3,6 @@ Feature: Installing using a compiled-cache
|
|
3
3
|
Background:
|
4
4
|
Given I have wiped the folder "/tmp/precompiled-workroot"
|
5
5
|
|
6
|
-
# Scenario: Installing a compiled gem without the cache
|
7
|
-
|
8
6
|
Scenario: Installing a compiled gem with a cache miss
|
9
7
|
Given I use the gem configuration option
|
10
8
|
"""
|
@@ -16,14 +14,14 @@ Feature: Installing using a compiled-cache
|
|
16
14
|
Then I should see "Building native extensions"
|
17
15
|
Then I should not see "Loading native extension from cache"
|
18
16
|
|
19
|
-
When I
|
17
|
+
When I run ruby
|
20
18
|
"""
|
21
|
-
|
19
|
+
require "test_ext/test_ext"
|
20
|
+
puts CompiledClass.new.test_method
|
22
21
|
"""
|
23
22
|
|
24
23
|
Then I should see "Hello, world!"
|
25
24
|
|
26
|
-
# this works in reality but the test is dodgy on ruby 2. Needs investment in time to fix
|
27
25
|
Scenario: Installing a compiled gem with a cache hit
|
28
26
|
Given I use the gem configuration option
|
29
27
|
"""
|
@@ -38,9 +36,10 @@ Feature: Installing using a compiled-cache
|
|
38
36
|
Then I should not see "Building native extensions"
|
39
37
|
Then I should see "Loading native extension from cache"
|
40
38
|
|
41
|
-
When I
|
39
|
+
When I run ruby
|
42
40
|
"""
|
43
|
-
|
41
|
+
require "test_ext/test_ext"
|
42
|
+
puts CompiledClass.new.test_method
|
44
43
|
"""
|
45
44
|
|
46
45
|
Then I should see "Hello, world!"
|
@@ -28,6 +28,7 @@ Feature: Pre-compiling gems
|
|
28
28
|
And the command should return a success status code
|
29
29
|
|
30
30
|
Scenario: Pre-compiling a single compiled gem with --build-config
|
31
|
+
Given this version of rubygems supports build options
|
31
32
|
When I run the command "gem precompile --verbose --build-config='--foo --bar' compiled-gem.gem"
|
32
33
|
|
33
34
|
Then I should see "build-args --foo --bar"
|
@@ -35,14 +35,29 @@ def execute(command)
|
|
35
35
|
puts @last_stderr
|
36
36
|
end
|
37
37
|
|
38
|
-
When /^I (?:run
|
38
|
+
When /^I (?:run ruby)$/ do |command|
|
39
|
+
installroot = "/tmp/precompiled-workroot/installroot"
|
40
|
+
extension_path = if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0.0")
|
41
|
+
"#{installroot}/gems/compiled-gem-0.0.1/lib"
|
42
|
+
else
|
43
|
+
"#{installroot}/extensions/#{Gem::Platform.local}/#{RbConfig::CONFIG["ruby_version"]}-static/compiled-gem-0.0.1"
|
44
|
+
end
|
45
|
+
|
46
|
+
cmd = %{cat <<RUBY | ruby -I "#{extension_path}"
|
47
|
+
#{command}
|
48
|
+
RUBY}
|
49
|
+
execute(cmd)
|
50
|
+
raise RuntimeError, "Command '#{command}' exited with non-zero exit status" unless @last_status == 0
|
51
|
+
end
|
52
|
+
|
53
|
+
When /^I (?:run the command|execute) "(.*?)"( ignoring the exit code)?$/ do |command, ignore_exit_code|
|
39
54
|
execute(command)
|
40
55
|
raise RuntimeError, "Command '#{command}' exited with non-zero exit status" unless ignore_exit_code or @last_status == 0
|
41
|
-
|
42
56
|
end
|
57
|
+
|
43
58
|
When /^I (?:run the command|execute)$/ do |command|
|
44
|
-
|
45
|
-
|
59
|
+
execute(command)
|
60
|
+
raise RuntimeError, "Command '#{command}' exited with non-zero exit status" unless @last_status == 0
|
46
61
|
end
|
47
62
|
|
48
63
|
Then /^I should( not)? see "(.*?)"( on (stdout|stderr))?$/ do |invert, expect, any, channel|
|
@@ -65,7 +80,7 @@ Then /^the command should leave behind temporary directories/ do
|
|
65
80
|
data = @last_stdout + @last_stderr
|
66
81
|
data.each_line do |l|
|
67
82
|
if m = l.match(/Leaving (.*) in place/)
|
68
|
-
expect(Dir.exists?(m[1])).to
|
83
|
+
expect(Dir.exists?(m[1])).to be true
|
69
84
|
end
|
70
85
|
end
|
71
86
|
end
|
@@ -21,11 +21,12 @@ Given /^I have changed to a temporary directory(?: containing "(.*?)")?$/ do |gl
|
|
21
21
|
FileUtils.chdir(directory)
|
22
22
|
end
|
23
23
|
After do
|
24
|
+
FileUtils.chdir(OriginalWorkingDirectory)
|
24
25
|
cleanup.each { |dir| FileUtils.rm_rf(dir) }
|
25
26
|
end
|
26
27
|
|
27
28
|
Then /^the folder "(.*?)" should exist$/ do |folder|
|
28
|
-
File.directory?(folder).
|
29
|
+
expect(File.directory?(folder)).to be true
|
29
30
|
end
|
30
31
|
|
31
32
|
Then /^the file "(.*?)" should (not )?exist$/ do |file, invert|
|
data/lib/rubygems/precompiled.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'rubygems/precompiled/version'
|
2
|
+
require "rubygems/precompiled/file_cache"
|
3
|
+
require "rubygems/precompiled/http_cache"
|
4
|
+
|
2
5
|
require 'rubygems/installer'
|
3
6
|
require 'rubygems/ext/builder'
|
4
7
|
require 'rubygems/package/tar_reader'
|
@@ -9,66 +12,6 @@ require 'uri'
|
|
9
12
|
require 'tempfile'
|
10
13
|
|
11
14
|
module Precompiled
|
12
|
-
|
13
|
-
def self.included(base)
|
14
|
-
base.send(:alias_method, :build_extensions_without_cache, :build_extensions)
|
15
|
-
base.send(:alias_method, :build_extensions, :build_extensions_with_cache)
|
16
|
-
end
|
17
|
-
|
18
|
-
class BaseCache
|
19
|
-
def initialize(root_uri)
|
20
|
-
@root_uri = root_uri
|
21
|
-
end
|
22
|
-
|
23
|
-
def retrieve(spec)
|
24
|
-
raise "Must be overriden!"
|
25
|
-
end
|
26
|
-
def contains?(spec)
|
27
|
-
false
|
28
|
-
end
|
29
|
-
def cache_key(spec)
|
30
|
-
"/ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}/#{Gem::Platform.local.to_s}/#{spec.name}-#{spec.version}.tar.gz"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class FileCache < BaseCache
|
35
|
-
def path_for(spec)
|
36
|
-
File.join(@root_uri.path, cache_key(spec))
|
37
|
-
end
|
38
|
-
def contains?(spec)
|
39
|
-
File.exists?(path_for(spec))
|
40
|
-
end
|
41
|
-
|
42
|
-
def retrieve(spec)
|
43
|
-
yield path_for(spec)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class HttpCache < BaseCache
|
48
|
-
def uri_to_spec(spec)
|
49
|
-
URI.join(@root_uri, File.join(@root_uri.path, cache_key(spec)))
|
50
|
-
end
|
51
|
-
def contains?(spec)
|
52
|
-
uri = uri_to_spec(spec)
|
53
|
-
http = Net::HTTP.start(uri.host, uri.port)
|
54
|
-
http.head(uri.path).code == "200"
|
55
|
-
end
|
56
|
-
def retrieve(spec)
|
57
|
-
tempfile = Tempfile.new('cache-hit')
|
58
|
-
uri = uri_to_spec(spec)
|
59
|
-
http = Net::HTTP.start(uri.host, uri.port)
|
60
|
-
http.request_get(uri.path) do |resp|
|
61
|
-
resp.read_body do |segment|
|
62
|
-
tempfile.write(segment)
|
63
|
-
end
|
64
|
-
tempfile.close
|
65
|
-
end
|
66
|
-
|
67
|
-
yield tempfile
|
68
|
-
tempfile.delete
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
15
|
GemCache = {
|
73
16
|
'file' => FileCache,
|
74
17
|
'http' => HttpCache
|
@@ -84,43 +27,50 @@ module Precompiled
|
|
84
27
|
end
|
85
28
|
end
|
86
29
|
|
87
|
-
|
88
|
-
|
30
|
+
module InstallerExtension
|
31
|
+
def self.included(base)
|
32
|
+
base.send(:alias_method, :build_extensions_without_cache, :build_extensions)
|
33
|
+
base.send(:alias_method, :build_extensions, :build_extensions_with_cache)
|
34
|
+
end
|
35
|
+
|
89
36
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
37
|
+
def build_extensions_with_cache
|
38
|
+
cache = Precompiled.precompiled_caches.find { |cache| cache.contains?(spec) }
|
39
|
+
|
40
|
+
if cache
|
41
|
+
$stderr.puts "Loading native extension from cache"
|
42
|
+
cache.retrieve(spec) do |path|
|
43
|
+
if spec.respond_to?(:extension_dir)
|
44
|
+
precompile_overlay_tarball(path, spec.extension_dir)
|
45
|
+
else
|
46
|
+
precompile_overlay_tarball(path, @gem_dir)
|
47
|
+
end
|
97
48
|
end
|
49
|
+
else
|
50
|
+
build_extensions_without_cache
|
98
51
|
end
|
99
|
-
else
|
100
|
-
build_extensions_without_cache
|
101
52
|
end
|
102
|
-
end
|
103
53
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
54
|
+
# Private: Extracts a .tar.gz file on-top of the gem's installation directory
|
55
|
+
def precompile_overlay_tarball(tarball, target_root)
|
56
|
+
Zlib::GzipReader.open(tarball) do |gzip_io|
|
57
|
+
Gem::Package::TarReader.new(gzip_io) do |tar|
|
58
|
+
tar.each do |entry|
|
59
|
+
target_path = File.join(target_root, entry.full_name)
|
60
|
+
if entry.directory?
|
61
|
+
FileUtils.mkdir_p(target_path)
|
62
|
+
elsif entry.file?
|
63
|
+
FileUtils.mkdir_p(File.dirname(target_path))
|
64
|
+
File.open(target_path, "w") do |f|
|
65
|
+
f.write entry.read(1024*1024) until entry.eof?
|
66
|
+
end
|
116
67
|
end
|
68
|
+
entry.close
|
117
69
|
end
|
118
|
-
|
119
|
-
|
120
|
-
end
|
70
|
+
end
|
71
|
+
end
|
121
72
|
end
|
122
73
|
end
|
123
|
-
|
124
74
|
end
|
125
75
|
|
126
|
-
Gem::Installer.send(:include, Precompiled)
|
76
|
+
Gem::Installer.send(:include, Precompiled::InstallerExtension)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Precompiled
|
2
|
+
class BaseCache
|
3
|
+
def initialize(root_uri)
|
4
|
+
@root_uri = root_uri
|
5
|
+
end
|
6
|
+
|
7
|
+
def retrieve(spec)
|
8
|
+
raise "Must be overriden!"
|
9
|
+
end
|
10
|
+
|
11
|
+
def contains?(spec)
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_key(spec)
|
16
|
+
"/ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}/#{Gem::Platform.local.to_s}/#{spec.name}-#{spec.version}.tar.gz"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems/precompiled/base_cache"
|
2
|
+
|
3
|
+
module Precompiled
|
4
|
+
class FileCache < BaseCache
|
5
|
+
def path_for(spec)
|
6
|
+
File.join(@root_uri.path, cache_key(spec))
|
7
|
+
end
|
8
|
+
|
9
|
+
def contains?(spec)
|
10
|
+
File.exists?(path_for(spec))
|
11
|
+
end
|
12
|
+
|
13
|
+
def retrieve(spec)
|
14
|
+
yield path_for(spec)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rubygems/precompiled/base_cache"
|
2
|
+
|
3
|
+
module Precompiled
|
4
|
+
class HttpCache < BaseCache
|
5
|
+
def uri_to_spec(spec)
|
6
|
+
URI.join(@root_uri, File.join(@root_uri.path, cache_key(spec)))
|
7
|
+
end
|
8
|
+
|
9
|
+
def contains?(spec)
|
10
|
+
uri = uri_to_spec(spec)
|
11
|
+
http = Net::HTTP.start(uri.host, uri.port)
|
12
|
+
http.head(uri.path).code == "200"
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve(spec)
|
16
|
+
tempfile = Tempfile.new('cache-hit')
|
17
|
+
uri = uri_to_spec(spec)
|
18
|
+
http = Net::HTTP.start(uri.host, uri.port)
|
19
|
+
http.request_get(uri.path) do |resp|
|
20
|
+
resp.read_body do |segment|
|
21
|
+
tempfile.write(segment)
|
22
|
+
end
|
23
|
+
tempfile.close
|
24
|
+
end
|
25
|
+
|
26
|
+
yield tempfile
|
27
|
+
tempfile.delete
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rubygems/precompiler.rb
CHANGED
@@ -34,34 +34,34 @@ class Gem::Precompiler
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
37
|
+
# Private: Extracts the gem files into the specified path
|
38
38
|
#
|
39
39
|
def extract_files_into(dir)
|
40
40
|
@installer.unpack(dir)
|
41
41
|
end
|
42
42
|
|
43
|
-
#
|
43
|
+
# Public: Returns the name of the gem
|
44
44
|
#
|
45
45
|
# Returns a string
|
46
46
|
def gem_name
|
47
47
|
@spec.name
|
48
48
|
end
|
49
49
|
|
50
|
-
#
|
50
|
+
# Public: Returns the version string of the gem
|
51
51
|
#
|
52
|
-
#
|
52
|
+
# Returns a Gem::Version
|
53
53
|
def gem_version
|
54
54
|
@spec.version
|
55
55
|
end
|
56
56
|
|
57
|
-
#
|
57
|
+
# Public: Returns the relative require-paths specified by the gem
|
58
58
|
#
|
59
59
|
# Returns an array of strings
|
60
60
|
def gem_require_paths
|
61
61
|
@spec.require_paths
|
62
62
|
end
|
63
63
|
|
64
|
-
#
|
64
|
+
# Public: Does the gem actually have any compiled extensions?
|
65
65
|
#
|
66
66
|
# Returns boolean - true if the gem has a c-extension that needs building
|
67
67
|
def has_extension?
|
@@ -96,7 +96,7 @@ class Gem::Precompiler
|
|
96
96
|
File.join(*[@target_dir, "#{gem_name}-#{gem_version.to_s}.tar.gz"].compact)
|
97
97
|
end
|
98
98
|
|
99
|
-
#
|
99
|
+
# Private: Calls the code necessary to build all the extensions
|
100
100
|
# into a specified install root
|
101
101
|
#
|
102
102
|
# Returns a list of files beneath that root making up the build
|
@@ -171,7 +171,7 @@ class Gem::Precompiler
|
|
171
171
|
FileUtils.mv(temp_output.path, output_path)
|
172
172
|
end
|
173
173
|
|
174
|
-
#
|
174
|
+
# Private: Yield a reference to a TarWriter that writes to
|
175
175
|
# the specified .tar.gz file
|
176
176
|
#
|
177
177
|
def targz_file(path, &block)
|
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
24
24
|
spec.add_development_dependency "cucumber"
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubygems-precompiled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Haggett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: cucumber
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +87,9 @@ files:
|
|
87
87
|
- features/steps/rubygem_steps.rb
|
88
88
|
- lib/rubygems/commands/precompile_command.rb
|
89
89
|
- lib/rubygems/precompiled.rb
|
90
|
+
- lib/rubygems/precompiled/base_cache.rb
|
91
|
+
- lib/rubygems/precompiled/file_cache.rb
|
92
|
+
- lib/rubygems/precompiled/http_cache.rb
|
90
93
|
- lib/rubygems/precompiled/version.rb
|
91
94
|
- lib/rubygems/precompiler.rb
|
92
95
|
- lib/rubygems_plugin.rb
|