rbz 0.2.0 → 0.3.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 +4 -4
- data/README.md +8 -0
- data/examples/bundled/.gitignore +2 -0
- data/examples/bundled/Gemfile +3 -0
- data/examples/bundled/Gemfile.lock +14 -0
- data/examples/bundled/main.rb +7 -0
- data/exe/rbz +2 -46
- data/lib/rbz/cli.rb +80 -0
- data/lib/rbz/templates/bin.rb.erb +58 -0
- data/lib/rbz/version.rb +2 -2
- data/lib/rbz.rb +8 -0
- data/sig/rbz.rbs +1 -1
- metadata +12 -10
- /data/{example → examples/example_1}/main.rb +0 -0
- /data/{example_2 → examples/example_2}/lib/other_file.rb +0 -0
- /data/{example_2 → examples/example_2}/main.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a774e972b1a624ed444a3b1ce0684ecd1a76d6ba5e70b909b628c8d637879cf0
|
|
4
|
+
data.tar.gz: b07e501ad4334413b71019ebc13f93377d1c15d5d5edda4fe7bdb7cfc87bf679
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58a4df4d1eeea6695711a4165b2e3f91e30d0988f92800a89bfca147383324fa506aa89e8904bd912accdc16d9acb316c321f1ec522f76c362acc99e1182cf33
|
|
7
|
+
data.tar.gz: 1a85d186663ebea35e6e385ba8f15b6bdd8388d887353b9d8db65f29574b44c1af187f7d84604101217415ea9ede441d2114811b2ce99a78f16c425f3331e626
|
data/README.md
CHANGED
|
@@ -25,6 +25,14 @@ Once the archive is generated, run it with `ruby`.
|
|
|
25
25
|
|
|
26
26
|
$ ruby my-archive.rbz
|
|
27
27
|
|
|
28
|
+
### Applications with simple Gemfile's
|
|
29
|
+
|
|
30
|
+
If your application's Gemfile is simple (ie. no git or path sources, no C extensions)
|
|
31
|
+
there is a good chance you can package it with rbz.
|
|
32
|
+
|
|
33
|
+
rbz uses `bundle install --standalone` to vendor your dependencies, and then writes
|
|
34
|
+
out it's own loader that sets up the load path to use those vendored gems.
|
|
35
|
+
|
|
28
36
|
## License
|
|
29
37
|
|
|
30
38
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/exe/rbz
CHANGED
|
@@ -1,49 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require "
|
|
4
|
-
require "stringio"
|
|
5
|
-
require "zlib"
|
|
3
|
+
require "rbz"
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
io = StringIO.new
|
|
9
|
-
|
|
10
|
-
Gem::Package::TarWriter.new(io) do |writer|
|
|
11
|
-
Dir.chdir(source) do
|
|
12
|
-
Dir.glob("**/*").each do |e|
|
|
13
|
-
next if File.directory?(e)
|
|
14
|
-
mode = File.lstat(e).mode
|
|
15
|
-
writer.add_file(e, mode) { |fio| fio.write File.read(e, mode: "rb") }
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
puts File.read(__FILE__).split("__END__").last.strip
|
|
21
|
-
puts
|
|
22
|
-
puts "__END__"
|
|
23
|
-
puts [Zlib::Deflate.deflate(io.string)].pack("m")
|
|
24
|
-
|
|
25
|
-
__END__
|
|
26
|
-
|
|
27
|
-
#!/usr/bin/env ruby
|
|
28
|
-
require "tmpdir"
|
|
29
|
-
require "rubygems/package"
|
|
30
|
-
require "stringio"
|
|
31
|
-
require "zlib"
|
|
32
|
-
|
|
33
|
-
Dir.mktmpdir("rbz") do |dir|
|
|
34
|
-
Dir.chdir(dir) do
|
|
35
|
-
tar = StringIO.new(Zlib::Inflate.inflate(DATA.read.unpack1("m")))
|
|
36
|
-
Gem::Package::TarReader.new(tar) do |reader|
|
|
37
|
-
reader.each do |entry|
|
|
38
|
-
next if entry.full_name.start_with?("._")
|
|
39
|
-
next if entry.full_name.start_with?("PaxHeader")
|
|
40
|
-
|
|
41
|
-
FileUtils.mkdir_p(File.dirname(entry.full_name))
|
|
42
|
-
File.write(entry.full_name, entry.read, mode: "wb")
|
|
43
|
-
File.chmod(entry.header.mode, entry.full_name)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
load "main.rb"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
5
|
+
RBZ::CLI.run(ARGV)
|
data/lib/rbz/cli.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require "rubygems/package"
|
|
2
|
+
require "stringio"
|
|
3
|
+
require "zlib"
|
|
4
|
+
require "optionparser"
|
|
5
|
+
require "erb"
|
|
6
|
+
|
|
7
|
+
module RBZ
|
|
8
|
+
module CLI
|
|
9
|
+
def self.run(argv)
|
|
10
|
+
options = {
|
|
11
|
+
main: "main.rb",
|
|
12
|
+
output: $stdout,
|
|
13
|
+
bundle: true
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
parser = OptionParser.new do |parser|
|
|
17
|
+
parser.accept(File) do |path|
|
|
18
|
+
abort "Error: #{path} already exists" if File.exist?(path)
|
|
19
|
+
f = File.open(path, mode: "w")
|
|
20
|
+
File.chmod(0o755, path)
|
|
21
|
+
f
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
parser.banner = "Usage: rbz [options] folder"
|
|
25
|
+
parser.on("-c", "--compile", "Store compiled Ruby iseq")
|
|
26
|
+
parser.on("-m FILE", "--main FILE", "Main entrypoint (relative to folder, default: main.rb)")
|
|
27
|
+
parser.on("-o FILE", "--output FILE", File, "Output path (default: stdout)")
|
|
28
|
+
parser.on("-b", "--[no-]bundle", "Use bundle if exists (default: true)")
|
|
29
|
+
parser.on("--verbose", "Verbose mode")
|
|
30
|
+
end
|
|
31
|
+
parser.parse!(into: options)
|
|
32
|
+
|
|
33
|
+
source = ARGV[0] or abort(parser.to_s)
|
|
34
|
+
output = options[:output]
|
|
35
|
+
io = StringIO.new
|
|
36
|
+
|
|
37
|
+
# Default output to stderr
|
|
38
|
+
$> = $stderr
|
|
39
|
+
|
|
40
|
+
Gem::Package::TarWriter.new(io) do |writer|
|
|
41
|
+
Dir.chdir(source) do
|
|
42
|
+
# Can't use bundle if no Gemfile
|
|
43
|
+
options[:bundle] = false unless File.exist?("Gemfile")
|
|
44
|
+
|
|
45
|
+
if options[:bundle]
|
|
46
|
+
system("bundle install --standalone >/dev/null 2>&1") or abort "Error: bundle install failed"
|
|
47
|
+
File.delete("bundle/bundler/setup.rb")
|
|
48
|
+
Dir.delete("bundle/bundler")
|
|
49
|
+
File.open("bundle/load.rb", "w") do |f|
|
|
50
|
+
f.puts "path = File.expand_path('../..', __FILE__)"
|
|
51
|
+
|
|
52
|
+
Dir["bundle/ruby/**/lib"].each do |dir|
|
|
53
|
+
f.puts %Q[$LOAD_PATH.unshift "\#{path}/#{dir}"]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Dir.glob("**/*").each do |e|
|
|
59
|
+
next if File.directory?(e)
|
|
60
|
+
mode = File.lstat(e).mode
|
|
61
|
+
|
|
62
|
+
if options[:compile] && File.extname(e) == ".rb"
|
|
63
|
+
contents = RubyVM::InstructionSequence.compile_file(e).to_binary
|
|
64
|
+
$stderr.puts "a #{e}.iseq" if options[:verbose] # standard:disable Style/StderrPuts
|
|
65
|
+
writer.add_file(e + ".iseq", mode) { |fio| fio.write(contents) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
$stderr.puts "a #{e}" if options[:verbose] # standard:disable Style/StderrPuts
|
|
69
|
+
writer.add_file(e, mode) { |fio| fio.write(File.binread(e)) }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
output.puts ERB.new(RBZ.templates.join("bin.rb.erb").read, trim_mode: "-").result(binding)
|
|
75
|
+
output.puts
|
|
76
|
+
output.puts "__END__"
|
|
77
|
+
output.puts [Zlib::Deflate.deflate(io.string)].pack("m")
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require "tmpdir"
|
|
3
|
+
require "rubygems/package"
|
|
4
|
+
require "stringio"
|
|
5
|
+
require "zlib"
|
|
6
|
+
require "digest"
|
|
7
|
+
require "tmpdir"
|
|
8
|
+
|
|
9
|
+
<% if options[:compile] -%>
|
|
10
|
+
module ISeqMixin
|
|
11
|
+
def load_iseq(path)
|
|
12
|
+
if File.exist?(path + ".iseq")
|
|
13
|
+
path = path + ".iseq"
|
|
14
|
+
RubyVM::InstructionSequence.load_from_binary(File.binread(path))
|
|
15
|
+
end
|
|
16
|
+
rescue SyntaxError, RuntimeError
|
|
17
|
+
nil
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
<% end -%>
|
|
21
|
+
|
|
22
|
+
sha256 = Digest::SHA256.hexdigest(File.read(__FILE__))
|
|
23
|
+
dir = File.join(Dir.tmpdir, "rbz-#{sha256}")
|
|
24
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
|
25
|
+
|
|
26
|
+
Dir.chdir(dir) do
|
|
27
|
+
sentinel = File.join(dir, ".rbz")
|
|
28
|
+
if !File.exist?(sentinel)
|
|
29
|
+
tar = StringIO.new(Zlib::Inflate.inflate(DATA.read.unpack1("m")))
|
|
30
|
+
Gem::Package::TarReader.new(tar) do |reader|
|
|
31
|
+
reader.each do |entry|
|
|
32
|
+
next if entry.full_name.start_with?("._")
|
|
33
|
+
next if entry.full_name.start_with?("PaxHeader")
|
|
34
|
+
|
|
35
|
+
FileUtils.mkdir_p(File.dirname(entry.full_name))
|
|
36
|
+
File.binwrite(entry.full_name, entry.read)
|
|
37
|
+
File.chmod(entry.header.mode, entry.full_name)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
File.write(sentinel, "")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
<%- if options[:compile] -%>
|
|
45
|
+
class << RubyVM::InstructionSequence
|
|
46
|
+
prepend ISeqMixin
|
|
47
|
+
end
|
|
48
|
+
<%- end -%>
|
|
49
|
+
|
|
50
|
+
<%- if options[:bundle] -%>
|
|
51
|
+
bundle_path = File.join(dir, "bundle/load.rb")
|
|
52
|
+
if File.exist?(bundle_path)
|
|
53
|
+
require bundle_path
|
|
54
|
+
end
|
|
55
|
+
<%- end -%>
|
|
56
|
+
|
|
57
|
+
load File.expand_path("<%= options[:main] %>", dir)
|
|
58
|
+
end
|
data/lib/rbz/version.rb
CHANGED
data/lib/rbz.rb
CHANGED
data/sig/rbz.rbs
CHANGED
metadata
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbz
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adam Daniels
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
|
-
description:
|
|
14
12
|
email:
|
|
15
13
|
- adam@mediadrive.ca
|
|
16
14
|
executables:
|
|
@@ -23,11 +21,17 @@ files:
|
|
|
23
21
|
- README.md
|
|
24
22
|
- Rakefile
|
|
25
23
|
- example.rbz
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
24
|
+
- examples/bundled/.gitignore
|
|
25
|
+
- examples/bundled/Gemfile
|
|
26
|
+
- examples/bundled/Gemfile.lock
|
|
27
|
+
- examples/bundled/main.rb
|
|
28
|
+
- examples/example_1/main.rb
|
|
29
|
+
- examples/example_2/lib/other_file.rb
|
|
30
|
+
- examples/example_2/main.rb
|
|
29
31
|
- exe/rbz
|
|
30
32
|
- lib/rbz.rb
|
|
33
|
+
- lib/rbz/cli.rb
|
|
34
|
+
- lib/rbz/templates/bin.rb.erb
|
|
31
35
|
- lib/rbz/version.rb
|
|
32
36
|
- sig/rbz.rbs
|
|
33
37
|
homepage: https://github.com/adam12/rbz
|
|
@@ -36,7 +40,6 @@ licenses:
|
|
|
36
40
|
metadata:
|
|
37
41
|
homepage_uri: https://github.com/adam12/rbz
|
|
38
42
|
source_code_uri: https://github.com/adam12/rbz
|
|
39
|
-
post_install_message:
|
|
40
43
|
rdoc_options: []
|
|
41
44
|
require_paths:
|
|
42
45
|
- lib
|
|
@@ -51,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
51
54
|
- !ruby/object:Gem::Version
|
|
52
55
|
version: '0'
|
|
53
56
|
requirements: []
|
|
54
|
-
rubygems_version: 3.
|
|
55
|
-
signing_key:
|
|
57
|
+
rubygems_version: 3.6.9
|
|
56
58
|
specification_version: 4
|
|
57
59
|
summary: Single file Ruby archives. Crazy? Maybe.
|
|
58
60
|
test_files: []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|