blondie 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/blondie.gemspec +31 -0
- data/exe/blondie +15 -0
- data/lib/blondie.rb +21 -0
- data/lib/blondie/builder.rb +104 -0
- data/lib/blondie/checker.rb +60 -0
- data/lib/blondie/version.rb +3 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: accc433a491395989d6bcf41013304978d3da5261088ddbc34010ad77fbde637
|
4
|
+
data.tar.gz: 0fe6e89649671bb4510c032493adc7959142ec0dee5534c9eca4d73031405367
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12754f357cf407a3ee653d6e992e733ecdaf4d971b043f49e803059610daf2222381074852280d3c51a0d577138b649f6f66c59e5840d12e26857d0eed893de0
|
7
|
+
data.tar.gz: 600e98cf807dcff3847d08e5f1925ddea5e80edd0c949cd9798cdfaa33f70a56a93e107255e5f4bd422ea1eb1518c1c9d85c87a5192b7ed158f10d113fa71c65
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
blondie (0.1.0)
|
5
|
+
minitar (~> 0.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
method_source (1.0.0)
|
13
|
+
minitar (0.9)
|
14
|
+
pry (0.14.0)
|
15
|
+
coderay (~> 1.1)
|
16
|
+
method_source (~> 1.0)
|
17
|
+
rake (12.3.2)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
blondie!
|
37
|
+
pry
|
38
|
+
rake (~> 12.0)
|
39
|
+
rspec (~> 3.0)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Bryn Bayliss
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Blondie
|
2
|
+
...you've got to ask yourself one question: 'Do I feel lucky?' Well, with
|
3
|
+
blondie
|
4
|
+
take the luck out the draw. 🤠
|
5
|
+
|
6
|
+
Blondie is a tool to check your gemfile for any dependencies with C extensions
|
7
|
+
before bundling
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'blondie'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install blondie
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Blondie takes an absolute path to a Gemfile, it then either provides a list of
|
28
|
+
the gems with C extensions or lets you know that none of your dependencies have
|
29
|
+
extensions
|
30
|
+
|
31
|
+
`blondie /path/to/Gemfile`
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Brynbayliss87/blondie.
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "blondie"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/blondie.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require_relative 'lib/blondie/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "blondie"
|
7
|
+
spec.version = Blondie::VERSION
|
8
|
+
spec.authors = ["Bryn Bayliss"]
|
9
|
+
spec.email = ["brynbayliss@hotmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Ruby gem, to check if any gems defined in your gemfile contain C extensions}
|
12
|
+
spec.homepage = "https://github.com/brynbayliss87/blondie"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = ["blondie"]
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_dependency 'minitar', '~> 0.9'
|
31
|
+
end
|
data/exe/blondie
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "blondie"
|
3
|
+
|
4
|
+
path = ARGV[0]
|
5
|
+
puts "Checking extensions..."
|
6
|
+
|
7
|
+
exts = Blondie::Linter.new(path).gems_with_extensions_list
|
8
|
+
|
9
|
+
unless exts.empty?
|
10
|
+
exts.each do |ext|
|
11
|
+
puts "C Extension found in: #{ext}"
|
12
|
+
end
|
13
|
+
else
|
14
|
+
puts "No C extensions found"
|
15
|
+
end
|
data/lib/blondie.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "blondie/version"
|
2
|
+
require "blondie/builder"
|
3
|
+
require "blondie/checker"
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module Blondie
|
7
|
+
class Linter
|
8
|
+
|
9
|
+
attr_reader :gemfile_path
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@gemfile_path = path
|
13
|
+
end
|
14
|
+
|
15
|
+
def gems_with_extensions_list
|
16
|
+
builder = Blondie::Builder.new(gemfile_path)
|
17
|
+
checker = Blondie::Checker.new(builder.urls)
|
18
|
+
checker.gems_with_extensions
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
module Blondie
|
5
|
+
class Builder
|
6
|
+
RUBY_GEMS_URL = "https://rubygems.org/downloads/".freeze
|
7
|
+
|
8
|
+
attr_reader :gemfile_path
|
9
|
+
|
10
|
+
def initialize(gemfile_path)
|
11
|
+
@gemfile_path = gemfile_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def urls
|
15
|
+
@urls ||= {}.tap do |hash|
|
16
|
+
gems_hash.each do |key, value|
|
17
|
+
version = value.last&.gsub(/\"|'/, "")
|
18
|
+
specifier = value.first.gsub(/\"|'/, "") if value.count == 2
|
19
|
+
specifier&.gsub!("\"", "")
|
20
|
+
library = key.gsub(/('|,|")/, "")
|
21
|
+
url = "#{RUBY_GEMS_URL}#{library}"
|
22
|
+
url += versioned_url(library, specifier, version)
|
23
|
+
hash[library] = url
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def versioned_url(library, specifier, version)
|
31
|
+
return "-#{version}.gem" if version && !specifier_greater?(specifier)
|
32
|
+
|
33
|
+
"-#{resolve_latest_version(library, specifier, version)}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def resolve_latest_version(library, specifier, version)
|
37
|
+
version += ".0" if version&.count(".") == 1
|
38
|
+
version += ".0.0" if version && version.count(".") == 0
|
39
|
+
versions = `gem search ^#{library}$ --remote --all`
|
40
|
+
versions = versions.split(",")
|
41
|
+
versions = clean_up_versions(versions)
|
42
|
+
|
43
|
+
case specifier
|
44
|
+
when ">", ">=", nil
|
45
|
+
versions.first
|
46
|
+
when "~>"
|
47
|
+
versions.each_with_index do |v, index|
|
48
|
+
next_ver = if index == 0
|
49
|
+
versions[index]
|
50
|
+
else
|
51
|
+
versions[index - 1]
|
52
|
+
end
|
53
|
+
if v == version
|
54
|
+
return next_ver unless version_bump?(v, next_ver)
|
55
|
+
return v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
raise 'gem version does not exist'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def clean_up_versions(versions)
|
63
|
+
versions.delete_at(0)
|
64
|
+
versions = versions.select do |v|
|
65
|
+
v.strip!
|
66
|
+
!v.include?("ruby") && (
|
67
|
+
v.include?("java") ||
|
68
|
+
v.include?("i386-mingw32") ||
|
69
|
+
v.include?("i386-mswin32")
|
70
|
+
) || (
|
71
|
+
!v.include?("ruby") ||
|
72
|
+
!v.include?("java") ||
|
73
|
+
!v.include?("i386-mingw32") ||
|
74
|
+
!v.include?("i386-mswin32")
|
75
|
+
)
|
76
|
+
end
|
77
|
+
versions.each { |v| v.gsub!(/(\(|\s|\)|,|ruby|java|i386-mingw32|i386-mswin32)/, "")}
|
78
|
+
end
|
79
|
+
|
80
|
+
def version_bump?(current_version, next_version)
|
81
|
+
return false if current_version[0].to_i == (next_version[0].to_i - 1) && current_version[2] < next_version[2]
|
82
|
+
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def specifier_greater?(specifier)
|
87
|
+
specifier && specifier.match(">")
|
88
|
+
end
|
89
|
+
|
90
|
+
def gems_hash
|
91
|
+
@gems_hash ||= {}.tap do |hash|
|
92
|
+
File.foreach(gemfile_path) do |line|
|
93
|
+
deps = line.split(" ")
|
94
|
+
if deps&.first&.[](0..3) == "gem"
|
95
|
+
next if deps.count > 4
|
96
|
+
value = [ deps[2] ]
|
97
|
+
value << deps[3]
|
98
|
+
hash[deps[1]] = value.compact
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'yaml'
|
4
|
+
require 'minitar'
|
5
|
+
|
6
|
+
module Blondie
|
7
|
+
class Checker
|
8
|
+
|
9
|
+
attr_reader :urls
|
10
|
+
|
11
|
+
def initialize(urls)
|
12
|
+
@urls = urls
|
13
|
+
@extensions = []
|
14
|
+
@gems_with_extensions = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def gems_with_extensions
|
18
|
+
find_extensions if @gems_with_extensions.empty?
|
19
|
+
@gems_with_extensions
|
20
|
+
end
|
21
|
+
|
22
|
+
def extensions
|
23
|
+
find_extensions if @extensions.empty?
|
24
|
+
@extensions
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def find_extensions
|
30
|
+
Dir.mktmpdir do |directory|
|
31
|
+
urls.each do |gem_name, url|
|
32
|
+
filename = url.split("/").last
|
33
|
+
create_tempfile(url, directory, filename)
|
34
|
+
|
35
|
+
Minitar.unpack("#{directory}/#{filename}", "#{directory}/gem_tar")
|
36
|
+
|
37
|
+
metadata = "#{directory}/gem_tar/metadata.gz"
|
38
|
+
check_metadata(metadata, gem_name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def check_metadata(metadata, gem_name)
|
44
|
+
c_extensions = Zlib::GzipReader.open(metadata) do |gz|
|
45
|
+
YAML.load(gz.read)
|
46
|
+
end.extensions
|
47
|
+
|
48
|
+
if !c_extensions.empty?
|
49
|
+
@extensions += c_extensions
|
50
|
+
@gems_with_extensions << gem_name
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_tempfile(url, directory, filename)
|
55
|
+
File.open("#{directory}/#{filename}", "w") do |f|
|
56
|
+
f.write(URI.open(url).read)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blondie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryn Bayliss
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- brynbayliss@hotmail.com
|
44
|
+
executables:
|
45
|
+
- blondie
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- blondie.gemspec
|
60
|
+
- exe/blondie
|
61
|
+
- lib/blondie.rb
|
62
|
+
- lib/blondie/builder.rb
|
63
|
+
- lib/blondie/checker.rb
|
64
|
+
- lib/blondie/version.rb
|
65
|
+
homepage: https://github.com/brynbayliss87/blondie
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
allowed_push_host: https://rubygems.org
|
70
|
+
homepage_uri: https://github.com/brynbayliss87/blondie
|
71
|
+
source_code_uri: https://github.com/brynbayliss87/blondie
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.3.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.2.16
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Ruby gem, to check if any gems defined in your gemfile contain C extensions
|
91
|
+
test_files: []
|