rubinjam 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ded6c9f6eb92813d7602488c593406a4f333f523
4
+ data.tar.gz: 6671928069a5c2e10fb1e61435b85740d97519b3
5
+ SHA512:
6
+ metadata.gz: 8f229a8694bf29678aa3b207012a75539840520ad6aa9448b3396d2a965d5a9e24b4fdf14cd28d091916481fa9c770c78ab3703012f02bbfa21894a2a29c7758
7
+ data.tar.gz: 14b21b5efd99913d1cbedc952b0e49436cb10371163ae21a5ab50e6d29c2d22414456cfe3aeaedcbbe413530d59a001b4a0d5d1bd570087194058c31ecfedbea
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/rubinjam ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'rubinjam'
6
+
7
+ OptionParser.new do |opts|
8
+ opts.banner = <<BANNER
9
+ Rubinjam
10
+
11
+ Jam a gem into a universal binary that works with any ruby
12
+
13
+ Usage:
14
+ rubinjam # convert current directory into a binary
15
+
16
+ Options:
17
+ BANNER
18
+ opts.on("-h", "--help","Show this.") { puts opts; exit }
19
+ opts.on('-v', '--version','Show Version'){ require 'rubinjam/version'; puts Rubinjam::VERSION; exit}
20
+ end.parse!
21
+
22
+ name, content = Rubinjam.pack(Dir.pwd)
23
+ File.write(name, content)
24
+ `chmod +x #{name}`
25
+ raise "Unable to add execution bit" unless $?.success?
@@ -0,0 +1,3 @@
1
+ module Rubinjam
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rubinjam.rb ADDED
@@ -0,0 +1,99 @@
1
+ require "tmpdir"
2
+ require "bundler"
3
+ require "rubinjam/version"
4
+
5
+ module Rubinjam
6
+ class << self
7
+ def pack(dir)
8
+ Dir.chdir(dir) do
9
+ binaries = Dir["bin/*"]
10
+ raise "No binary found in ./bin" if binaries.size == 0
11
+ raise "Can only pack exactly 1 binary, found #{binaries.join(",")} in ./bin" unless binaries.size == 1
12
+ content = environment + File.read(binaries.first)
13
+ [File.basename(binaries.first), content]
14
+ end
15
+ end
16
+
17
+ def pack_gem(gem, version)
18
+ Dir.mktmpdir do |dir|
19
+ Dir.chdir(dir) do
20
+ # unpack
21
+ command = ["gem", "unpack", gem]
22
+ command << "-v" << version if version
23
+ IO.popen(command).read
24
+
25
+ # bundle
26
+ Dir.chdir(Dir["*"].first) { Rubinjam.pack(Dir.pwd) }
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def libraries
34
+ libs_from_paths(["lib"]).merge(gem_libraries)
35
+ end
36
+
37
+ def gem_libraries
38
+ return {} unless gemspec = Dir["*.gemspec"].first
39
+ return {} unless File.read(gemspec) =~ /add_(runtime_)?dependency/
40
+
41
+ Dir.mktmpdir do |dir|
42
+ sh "cp -R . #{dir}/"
43
+ Dir.chdir(dir) do
44
+ write "Gemfile", <<-RUBY.gsub(/^ /, "")
45
+ source "https://rubygems.org"
46
+ gemspec
47
+ RUBY
48
+ sh("rm -f Gemfile.lock")
49
+ bundle = "bundle install --quiet --path bundle"
50
+ sh("#{bundle} --local || #{bundle}")
51
+ paths = sh("bundle exec ruby -e 'puts $LOAD_PATH'").split("\n")
52
+ paths = paths.grep(%r{/gems/}).reject { |r| r =~ %r{/gems/bundler-\d} }
53
+ libs_from_paths(paths)
54
+ end
55
+ end
56
+ end
57
+
58
+ def libs_from_paths(paths)
59
+ paths.select { |p| Dir.exist?(p) }.inject({}) do |all, path|
60
+ Dir.chdir path do
61
+ all.merge!(Hash[Dir["**/*.rb"].map { |f| [f.sub(/\.rb$/, ""), File.read(f)] }])
62
+ end
63
+ end
64
+ end
65
+
66
+ def sh(command, options={})
67
+ result = Bundler.with_clean_env { `#{command} 2>/dev/null` }
68
+ raise "#{options[:fail] ? "SUCCESS" : "FAIL"} #{command}\n#{result}" if $?.success? == !!options[:fail]
69
+ result
70
+ end
71
+
72
+ def write(file, content)
73
+ FileUtils.mkdir_p(File.dirname(file))
74
+ File.open(file, "w") { |f| f.write content }
75
+ end
76
+
77
+ def environment
78
+ <<-RUBY.gsub(/^ /, "")
79
+ #!/usr/bin/env ruby
80
+ # generated by rubinjam v#{VERSION} -- https://github.com/grosser/rubinjam
81
+ module Rubinjam
82
+ LIBRARIES = {
83
+ #{libraries.map { |name,content| "#{name.inspect} => #{content.inspect}" }.join(",\n ")}
84
+ }
85
+ end
86
+
87
+ def require(file)
88
+ if code = Rubinjam::LIBRARIES[file]
89
+ return if code == :loaded
90
+ eval(code, TOPLEVEL_BINDING, "rubinjam/\#{file}")
91
+ Rubinjam::LIBRARIES[file] = :loaded
92
+ else
93
+ super
94
+ end
95
+ end
96
+ RUBY
97
+ end
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubinjam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email: michael@grosser.it
29
+ executables:
30
+ - rubinjam
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - bin/rubinjam
36
+ - lib/rubinjam.rb
37
+ - lib/rubinjam/version.rb
38
+ homepage: https://github.com/grosser/rubinjam
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.2.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Jam a gem into a universal binary that works with any ruby
62
+ test_files: []