darb 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +22 -0
  3. data/README.md +34 -0
  4. data/Rakefile +63 -0
  5. data/bin/darb +151 -0
  6. metadata +50 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd23cf5c7a22b6f9171bf6d8cfbe70b05c503717
4
+ data.tar.gz: 6a6e591041866f36564f5b7af752a4d8dcb3a89d
5
+ SHA512:
6
+ metadata.gz: 72b8e2661c38f0db275804ea0ab061636bd589800a117d0d307bbcf04bae3597f02262d5f97ce0231489b0c5c42216a8a481601a2c8ccce33e755d270774ff2d
7
+ data.tar.gz: 5d46eba8752f40b541a679a811b011b97de7aec6b00a47e7d56d7d73521fdea86ab45160f59f4f134dd87471215afa0d941e651479611fed4a1002333fdf5d1e
data/COPYING ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2005-2014, Joel VanderWerf, vjoel@users.sourceforge.net
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,34 @@
1
+ darb
2
+ ====
3
+
4
+ DATA-Archived RuBy script: deploy your main and lib files in one executable ruby script file.
5
+
6
+ Darb packages a main script and some library scripts into one script file. The library files are appended to the __DATA__ section. Darb cannot handle binary files, such as .so or .dll.
7
+
8
+ This is useful if you want to pass around a script and not worry about what versions of libraries it might find, or when you want to break a script up into smaller files, but avoid the resulting deployment hassles: unpackaging and keeping files together.
9
+
10
+ Installation
11
+ ------------
12
+
13
+ Install as gem:
14
+
15
+ gem install 'darb'
16
+
17
+ or simply copy [bin/darb](bin/darb) into your bin dir.
18
+
19
+ Usage
20
+ -----
21
+
22
+ Please see [bin/darb](bin/darb) for detailed documentation, or run with the `-h` or `--help` switch.
23
+
24
+ See also
25
+ --------
26
+
27
+ Mauricio Fernandez' file FS based on ruby's DATA feature: http://eigenclass.org/hiki.rb?cmd=view&p=pure+ruby+compiler&key=block
28
+
29
+ About
30
+ -----
31
+
32
+ Copyright (C) 2006-2014 Joel VanderWerf, mailto:vjoel@users.sourceforge.net.
33
+
34
+ License is BSD. See [COPYING](COPYING).
@@ -0,0 +1,63 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ PRJ = "darb"
5
+
6
+ def version
7
+ @version ||= begin
8
+ darb = File.join(File.dirname(__FILE__), "bin", "darb")
9
+ `#{darb} -v`.chomp
10
+ end
11
+ end
12
+
13
+ def tag
14
+ @tag ||= "#{PRJ}-#{version}"
15
+ end
16
+
17
+ desc "Run tests"
18
+ Rake::TestTask.new :test do |t|
19
+ t.libs << "lib"
20
+ t.libs << "ext"
21
+ t.test_files = FileList["test/**/*.rb"]
22
+ end
23
+
24
+ desc "Commit, tag, and push repo; build and push gem"
25
+ task :release => "release:is_new_version" do
26
+ require 'tempfile'
27
+
28
+ sh "gem build #{PRJ}.gemspec"
29
+
30
+ file = Tempfile.new "template"
31
+ begin
32
+ file.puts "release #{version}"
33
+ file.close
34
+ sh "git commit --allow-empty -a -v -t #{file.path}"
35
+ ensure
36
+ file.close unless file.closed?
37
+ file.unlink
38
+ end
39
+
40
+ sh "git tag #{tag}"
41
+ sh "git push"
42
+ sh "git push --tags"
43
+
44
+ sh "gem push #{tag}.gem"
45
+ end
46
+
47
+ namespace :release do
48
+ desc "Diff to latest release"
49
+ task :diff do
50
+ latest = `git describe --abbrev=0 --tags --match '#{PRJ}-*'`.chomp
51
+ sh "git diff #{latest}"
52
+ end
53
+
54
+ desc "Log to latest release"
55
+ task :log do
56
+ latest = `git describe --abbrev=0 --tags --match '#{PRJ}-*'`.chomp
57
+ sh "git log #{latest}.."
58
+ end
59
+
60
+ task :is_new_version do
61
+ abort "#{tag} exists; update version!" unless `git tag -l #{tag}`.empty?
62
+ end
63
+ end
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ DARB_VERSION = '0.6'
4
+
5
+ if ARGV.delete("-v")
6
+ puts DARB_VERSION
7
+ exit
8
+ end
9
+
10
+ if ARGV.empty? || ARGV.delete("-h") || ARGV.delete("--help")
11
+ puts <<-HELP; exit
12
+ Usage: darb main.rb feature1 feature2 feature3=path/to/file ... > script.rb
13
+
14
+ DARB == DATA-Archived RuBy script.
15
+
16
+ Writes a darb archive script to standard out. One argument is
17
+ required and the rest are optional. There are no options except
18
+ -h and --help.
19
+
20
+ The main.rb code is executed when the archive is executed. Darb
21
+ simply inserts this code into the archive, after one initial line
22
+ to set up a customized #require. This main part of the archive can
23
+ be freely edited after generating the archive. After the __END__
24
+ line, the archive contains the #require implementation, an offset
25
+ table, and the library files themselves. Darb makes no effort to
26
+ separate the embedded files or make them easily extractable
27
+
28
+ Each of the features can be #require-d from the main.rb file, and
29
+ will be loaded as needed from the DATA segment of the archive. As
30
+ with Kernel#require, feature names are added to $LOADED_FEATURES
31
+ and only loaded once per feature name. #require falls back to the
32
+ original Kernel#require if the feature is not found in the archive.
33
+ Works correctly with autoloading files that are outside (not inside)
34
+ the archive. Works correctly with nested requires.
35
+
36
+ Feature syntax:
37
+
38
+ - the .rb is optional
39
+
40
+ - other extensions are permitted, but .so is not supported
41
+
42
+ - the 'feature3=path/to/file' argument means that darb should
43
+ copy the file from the given path into the archive, and load
44
+ it in response to "require 'feature3'".
45
+
46
+ Error messages are reported correctly in terms of the original
47
+ file and line.
48
+
49
+ Darb works correctly when some or all input files have cr-lf line
50
+ endings (mswin style) instead of just lf (unix style). Archives
51
+ generated on mswin run on unix/linux and vice versa. However, if
52
+ you edit the archive on windows, be sure to save it with lf line
53
+ endings. In general, don't edit the DATA section. Edit the source
54
+ files and rerun darb.
55
+
56
+ Darb prepends a hash-bang line to the output if the darb script
57
+ itself has one (it simply copies the line).
58
+
59
+ Limitations: main.rb cannot have its own DATA section (that is,
60
+ block of data separated from code by __END__).
61
+
62
+ Side effects: Darb defines the private instance method
63
+ Kernel#empty_binding, which simply returns a new binding with
64
+ no local variables.
65
+
66
+ AUTHOR : Joel VanderWerf, vjoel@users.sourceforge.net
67
+ VERSION : 0.5
68
+ LICENSE : Ruby license (credit appreciated), with no
69
+ restrictions on generated code.
70
+ HELP
71
+ end
72
+
73
+ STDOUT.binmode
74
+
75
+ main = ARGV.shift
76
+
77
+ offset = 0
78
+ files = []
79
+ file_bodies = []
80
+
81
+ table_lines = ARGV.map do |feature|
82
+ if /=/ =~ feature
83
+ feature, file = feature.split("=").map {|f|f.strip}
84
+ else
85
+ feature, file = feature, feature
86
+ end
87
+
88
+ feature += ".rb" unless /\.\w+$/ =~ feature
89
+ file += ".rb" unless /\.\w+$/ =~ file
90
+ file = File.expand_path(file)
91
+ files << file
92
+
93
+ file_bodies << file_body = File.read(file)
94
+ len = file_body.length
95
+ line = %{ "#{feature}" => [#{offset}, #{len}]}
96
+ offset += len
97
+ line
98
+ end
99
+ table = table_lines.join(",\n")
100
+
101
+ hashbang_line = File.open(__FILE__) {|f|f.gets}
102
+ puts hashbang_line if /^#!/ =~ hashbang_line
103
+ puts "DATA.binmode"
104
+ puts %{eval(DATA.inject("") {|s,l| break s if /^__END__$/=~l; s<<l})}
105
+ puts
106
+ puts File.read(main)
107
+ puts "__END__"
108
+ puts <<EOS, file_bodies
109
+ Kernel.module_eval do
110
+ table = {
111
+ #{table}
112
+ }
113
+ start_pos = DATA.pos
114
+
115
+ orig_require = instance_method(:require) # Thanks, batsman!
116
+ orig_autoload = instance_method(:autoload)
117
+
118
+ def empty_binding
119
+ binding
120
+ end
121
+ private :empty_binding
122
+
123
+ define_method(:require) do |feature|
124
+ darb_feature = feature.dup
125
+ darb_feature += ".rb" unless /\\.\\w+$/ =~ darb_feature
126
+ k, (pos,len) = table.find {|k,v|k==darb_feature}
127
+ if k
128
+ if $LOADED_FEATURES.include? darb_feature
129
+ false
130
+ else
131
+ DATA.seek start_pos + pos
132
+ str = DATA.read(len)
133
+ begin
134
+ eval str, empty_binding, darb_feature
135
+ rescue Exception => ex
136
+ bt = ex.backtrace
137
+ s = bt.pop until /empty_binding'$/ =~ s
138
+ bt[-1].slice!(/:in `empty_binding'/)
139
+ raise ex, ex.message, bt
140
+ end
141
+ $LOADED_FEATURES << darb_feature
142
+ true
143
+ end
144
+ else
145
+ orig_require.bind(self).call(feature)
146
+ end
147
+ end
148
+ end
149
+
150
+ __END__
151
+ EOS
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darb
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.6'
5
+ platform: ruby
6
+ authors:
7
+ - Joel VanderWerf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Deploy your main and lib files in one executable ruby script file.
14
+ email: vjoel@users.sourceforge.net
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files:
18
+ - README.md
19
+ - COPYING
20
+ files:
21
+ - COPYING
22
+ - README.md
23
+ - Rakefile
24
+ - bin/darb
25
+ homepage: https://github.com/vjoel/darb
26
+ licenses:
27
+ - BSD
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.1
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: DATA-Archived RuBy script
49
+ test_files: []
50
+ has_rdoc: