ocra 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-04-05
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/ocra.rb
6
+ share/ocra/lzma.exe
7
+ share/ocra/stub.exe
8
+ test/test_ocra.rb
@@ -0,0 +1,104 @@
1
+ = ocra
2
+
3
+ * http://github.com/larsch/ocra/
4
+
5
+ == DESCRIPTION:
6
+
7
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby
8
+ source code. The executable is a self-extracting, self-running
9
+ executable that contains the Ruby interpreter, your source code and
10
+ any additionally needed ruby libraries or DLL.
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ * LZMA Compression (optional, default on)
15
+ * Windows support only
16
+ * Ruby 1.9 support
17
+ * Both console programs and desktop programs supported (no console will
18
+ pop up with .rbw files).
19
+
20
+ == TODO:
21
+
22
+ * Clean up using manual recursive deletion (not SHop).
23
+
24
+ == SYNOPSIS:
25
+
26
+ ocra.rb [option] your/script.rb
27
+
28
+ * OCRA will load your script (using Kernel#load) and build the
29
+ executable when it exits.
30
+
31
+ * Your program should 'require' all necessary files when invoked without
32
+ arguments, so ocra can detect all dependencies.
33
+
34
+ * Autoloaded constants (e.g. modules and classes) should work. Ocra
35
+ attempts to load all autoload definitions.
36
+
37
+ * Ocra does not set up the include path. Use "$:.unshift
38
+ File.dirname(__FILE__)" at the start of your script if you need to
39
+ 'require' additional source files in the same directory no matter
40
+ what the user's current working directory is.
41
+
42
+ * DLLs needs to be added manually (e.g. sqlite3.dll, gdbm.dll,
43
+ etc.). Use the --dll option.
44
+
45
+ == REQUIREMENTS:
46
+
47
+ * Windows
48
+ * Working Ruby installation
49
+ * MinGW Installation (for building the stub)
50
+
51
+ == INSTALL:
52
+
53
+ * FIX (sudo gem install, anything else)
54
+
55
+ == TECHNICAL DETAILS
56
+
57
+ The Ocra stub extracts the contents into a temporary directory
58
+ (Windows' default temporary directory). The directory will contains
59
+ the same directory layout as your Ruby installlation. The source files
60
+ for your application will be put in the 'src' subdirectory.
61
+
62
+ Libraries found in non-standard path (for example, if you invoke Ocra
63
+ with "ruby -I some/path") will be placed into the site dir
64
+ (lib/ruby/site_ruby).
65
+
66
+ The RUBYOPT and RUBYLIB variables are cleared before your program is
67
+ launched by the executable in order not to interfere with any Ruby
68
+ installation on the end user's installation.
69
+
70
+ Autoloaded constants will be attempted loaded when building the
71
+ executable. Modules that doesn't exist will be ignore (but a warning
72
+ will be logged.)
73
+
74
+ == CREDITS:
75
+
76
+ Thanks for Igor Pavlov for the LZMA compressor and decompressor. The
77
+ source code used was place into Public Domain by Igor Pavlov.
78
+
79
+ Erik Veenstra for rubyscript2exe which provided inspiration.
80
+
81
+ == LICENSE:
82
+
83
+ (The MIT License)
84
+
85
+ Copyright (c) 2009 Lars Christensen
86
+
87
+ Permission is hereby granted, free of charge, to any person obtaining
88
+ a copy of this software and associated documentation files (the
89
+ 'Software'), to deal in the Software without restriction, including
90
+ without limitation the rights to use, copy, modify, merge, publish,
91
+ distribute, sublicense, and/or sell copies of the Software, and to
92
+ permit persons to whom the Software is furnished to do so, subject to
93
+ the following conditions:
94
+
95
+ The above copyright notice and this permission notice shall be
96
+ included in all copies or substantial portions of the Software.
97
+
98
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
99
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
100
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
101
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
102
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
103
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
104
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/ocra.rb'
6
+
7
+ r = Hoe.new('ocra', Ocra::VERSION) do |p|
8
+ # p.rubyforge_name = 'ocrax' # if different than lowercase project name
9
+ p.rubyforge_name = 'ocra'
10
+ p.developer('Lars Christensen', 'larsch@belunktum.dk')
11
+ end
12
+ require 'pp'
13
+ pp r
14
+
15
+ task :stub do
16
+ sh "mingw32-make -C src"
17
+ cp 'src/stub.exe', 'share/ocra/stub.exe'
18
+ end
19
+
20
+ task :test => :stub
21
+
22
+ task :standalone => [ 'bin/ocrasa.rb', 'bin/ocrasa.exe' ]
23
+
24
+
25
+ file 'bin/ocrasa.rb' => [ 'bin/ocra.rb', 'share/ocra/stub.exe', 'share/ocra/lzma.exe' ] do
26
+ cp 'bin/ocra.rb', 'bin/ocrasa.rb'
27
+ File.open("bin/ocrasa.rb", "a") do |f|
28
+ f.puts "__END__"
29
+ stub = File.open("share/ocra/stub.exe", "rb") {|g| g.read}
30
+ stub64 = [stub].pack("m")
31
+ f.puts stub64.size
32
+ f.puts stub64
33
+ lzma = File.open("share/ocra/lzma.exe", "rb") {|g| g.read}
34
+ lzma64 = [lzma].pack("m")
35
+ f.puts lzma64.size
36
+ f.puts lzma64
37
+ end
38
+ end
39
+
40
+ file 'bin/ocrasa.exe' => [ 'bin/ocra.rb', 'bin/ocrasa.rb' ] do
41
+ sh "ruby bin/ocra.rb bin/ocrasa.rb"
42
+ end
43
+
44
+ task :clean do
45
+ rm_rf Dir.glob("bin/*.exe")
46
+ sh "mingw32-make -C src clean"
47
+ end
48
+
49
+ # vim: syntax=Ruby
@@ -0,0 +1,303 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+
4
+ module Ocra
5
+ Signature = [0x41, 0xb6, 0xba, 0x4e]
6
+ OP_END = 0
7
+ OP_CREATE_DIRECTORY = 1
8
+ OP_CREATE_FILE = 2
9
+ OP_CREATE_PROCESS = 3
10
+ OP_DECOMPRESS_LZMA = 4
11
+ OP_SETENV = 5
12
+
13
+ class << self
14
+ attr_accessor :lzma_mode
15
+ attr_accessor :extra_dlls
16
+ attr_accessor :files
17
+ attr_accessor :load_autoload
18
+ attr_accessor :force_windows
19
+ attr_accessor :force_console
20
+ attr_accessor :quiet
21
+ attr_reader :lzmapath
22
+ attr_reader :stubimage
23
+
24
+ def get_next_embedded_image
25
+ DATA.read(DATA.readline.to_i).unpack("m")[0]
26
+ end
27
+ end
28
+
29
+ def Ocra.initialize_ocra
30
+ if defined?(DATA)
31
+ @stubimage = get_next_embedded_image
32
+ lzmaimage = get_next_embedded_image
33
+ @lzmapath = File.join(ENV['TEMP'], 'lzma.exe').tr('/','\\')
34
+ File.open(@lzmapath, "wb") { |file| file << lzmaimage }
35
+ else
36
+ ocrapath = File.dirname(__FILE__)
37
+ @stubimage = File.open(File.join(ocrapath, '../share/ocra/stub.exe'), "rb") { |file| file.read }
38
+ @lzmapath = File.expand_path('../share/ocra/lzma.exe', ocrapath).tr('/','\\')
39
+ raise "lzma.exe not found" unless File.exist?(@lzmapath)
40
+ end
41
+ end
42
+
43
+ def Ocra.parseargs(argv)
44
+ lzma_mode = true
45
+ extra_dlls = []
46
+ files = []
47
+ load_autoload = true
48
+ force_windows = false
49
+ force_console = false
50
+ quiet = false
51
+
52
+ usage = <<EOF
53
+ ocra [options] script.rb
54
+
55
+ --dll dllname Include additional DLLs from the Ruby bindir.
56
+ --no-lzma Disable LZMA compression of the executable.
57
+ --quiet Suppress output.
58
+ --help Display this information.
59
+ --windows Force Windows application (rubyw.exe)
60
+ --console Force console application (ruby.exe)
61
+ --no-autoload Don't load/include script.rb's autoloads
62
+ EOF
63
+
64
+ while arg = argv.shift
65
+ case arg
66
+ when /\A--(no-)?lzma\z/
67
+ lzma_mode = !$1
68
+ when /\A--dll\z/
69
+ extra_dlls << argv.shift
70
+ when /\A--quiet\z/
71
+ quiet = true
72
+ when /\A--windows\z/
73
+ force_windows = true
74
+ when /\A--console\z/
75
+ force_console = true
76
+ when /\A--no-autoload\z/
77
+ load_autoload = false
78
+ when /\A--help\z/, /\A--/
79
+ puts usage
80
+ exit
81
+ else
82
+ files << arg
83
+ end
84
+ end
85
+
86
+ if files.empty?
87
+ puts usage
88
+ exit
89
+ end
90
+
91
+ @lzma_mode = lzma_mode
92
+ @extra_dlls = extra_dlls
93
+ @quiet = quiet
94
+ @force_windows = force_windows
95
+ @force_console = force_console
96
+ @load_autoload = load_autoload
97
+ @files = files
98
+ end
99
+
100
+ def Ocra.init(argv)
101
+ parseargs(argv)
102
+ initialize_ocra
103
+ end
104
+
105
+ # Force loading autoloaded constants. Searches through all modules
106
+ # (and hence classes), and checks their constants for autoloaded
107
+ # ones, then attempts to load them.
108
+ def Ocra.attempt_load_autoload
109
+ modules_checked = []
110
+ loop do
111
+ modules_to_check = []
112
+ ObjectSpace.each_object(Module) do |mod|
113
+ modules_to_check << mod unless modules_checked.include?(mod)
114
+ end
115
+ break if modules_to_check.empty?
116
+ modules_to_check.each do |mod|
117
+ modules_checked << mod
118
+ mod.constants.each do |const|
119
+ if mod.autoload?(const)
120
+ begin
121
+ mod.const_get(const)
122
+ rescue LoadError
123
+ puts "=== WARNING: #{mod}::#{const} was not loadable"
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ def Ocra.build_exe
132
+ # Attempt to autoload libraries before doing anything else.
133
+ attempt_load_autoload if Ocra.load_autoload
134
+
135
+ # Store the currently loaded files (before we require rbconfig for
136
+ # our own use).
137
+ features = $LOADED_FEATURES.dup
138
+
139
+ # Find gemspecs to include
140
+ if defined?(Gem)
141
+ gemspecs = Gem.loaded_specs.map { |name,info| info.loaded_from }
142
+ else
143
+ gemspecs = []
144
+ end
145
+
146
+ require 'rbconfig'
147
+ exec_prefix = RbConfig::CONFIG['exec_prefix']
148
+ src_prefix = File.expand_path(File.dirname(Ocra.files[0]))
149
+ sitelibdir = RbConfig::CONFIG['sitelibdir']
150
+ bindir = RbConfig::CONFIG['bindir']
151
+ libruby_so = RbConfig::CONFIG['LIBRUBY_SO']
152
+
153
+ instsitelibdir = sitelibdir[exec_prefix.size+1..-1]
154
+
155
+ # Find loaded files
156
+ libs = []
157
+ features.each do |filename|
158
+ path = $:.find { |path| File.exist?(File.expand_path(filename, path)) }
159
+ if path
160
+ fullpath = File.expand_path(filename, path)
161
+ if fullpath.index(exec_prefix) == 0
162
+ libs << [ fullpath, fullpath[exec_prefix.size+1..-1] ]
163
+ elsif fullpath.index(src_prefix) == 0
164
+ libs << [ fullpath, "src/" + fullpath[src_prefix.size+1..-1]]
165
+ else
166
+ libs << [ fullpath, File.join(instsitelibdir, filename) ]
167
+ end
168
+ else
169
+ puts "=== WARNING: Couldn't find #{filename}"
170
+ end
171
+ end
172
+
173
+ executable = Ocra.files[0].sub(/(\.rbw?)?$/, '.exe')
174
+
175
+ puts "=== Building #{executable}" unless Ocra.quiet
176
+ OcraBuilder.new(executable) do |sb|
177
+ # Add explicitly mentioned files
178
+ Ocra.files.each do |file|
179
+ path = File.join('src', file).tr('/','\\')
180
+ sb.createfile(file, path)
181
+ end
182
+
183
+ # Add the ruby executable and DLL
184
+ if (Ocra.files[0] =~ /\.rbw$/ && !Ocra.force_windows) || Ocra.force_console
185
+ rubyexe = "ruby.exe"
186
+ else
187
+ rubyexe = "ruby.exe"
188
+ end
189
+ sb.createfile(File.join(bindir, rubyexe), "bin\\" + rubyexe)
190
+ if libruby_so
191
+ sb.createfile(File.join(bindir, libruby_so), "bin\\#{libruby_so}")
192
+ end
193
+
194
+ # Add extra DLLs
195
+ Ocra.extra_dlls.each do |dll|
196
+ sb.createfile(File.join(bindir, dll), File.join("bin", dll).tr('/','\\'))
197
+ end
198
+
199
+ # Add gemspecs
200
+ gemspecs.each { |gemspec|
201
+ pref = gemspec[0,exec_prefix.size]
202
+ path = gemspec[exec_prefix.size+1..-1]
203
+ if pref != exec_prefix
204
+ raise "#{gemspec} does not exist in the Ruby installation. Don't know where to put it."
205
+ end
206
+ sb.createfile(gemspec, path.tr('/','\\'))
207
+ }
208
+
209
+ # Add loaded libraries
210
+ libs.each do |path, target|
211
+ sb.createfile(path, target.tr('/', '\\'))
212
+ end
213
+
214
+ # Set environment variable
215
+ sb.setenv('RUBYOPT', '')
216
+ sb.setenv('RUBYLIB', '')
217
+
218
+ # Launch the script
219
+ sb.createprocess("bin\\" + rubyexe, "#{rubyexe} \xff\\src\\" + Ocra.files[0])
220
+
221
+ puts "=== Compressing" unless Ocra.quiet or not Ocra.lzma_mode
222
+ end
223
+ puts "=== Finished (Final size was #{File.size(executable)})" unless Ocra.quiet
224
+ end
225
+
226
+ class OcraBuilder
227
+ def initialize(path)
228
+ @paths = {}
229
+ File.open(path, "wb") do |ocrafile|
230
+ ocrafile.write(Ocra.stubimage)
231
+ if Ocra.lzma_mode
232
+ @of = ""
233
+ else
234
+ @of = ocrafile
235
+ end
236
+ yield(self)
237
+
238
+ if Ocra.lzma_mode
239
+ begin
240
+ File.open("tmpin", "wb") { |tmp| tmp.write(@of) }
241
+ system("#{Ocra.lzmapath} e tmpin tmpout 2>NUL") or fail
242
+ compressed_data = File.open("tmpout", "rb") { |tmp| tmp.read }
243
+ ocrafile.write([OP_DECOMPRESS_LZMA, compressed_data.size, compressed_data].pack("VVA*"))
244
+ ocrafile.write([OP_END].pack("V"))
245
+ ensure
246
+ File.unlink("tmpin") if File.exist?("tmpin")
247
+ File.unlink("tmpout") if File.exist?("tmpout")
248
+ end
249
+ else
250
+ ocrafile.write(@of) if Ocra.lzma_mode
251
+ end
252
+
253
+ ocrafile.write([OP_END].pack("V"))
254
+ ocrafile.write([Ocra.stubimage.size].pack("V")) # Pointer to start of opcodes
255
+ ocrafile.write(Signature.pack("C*"))
256
+ end
257
+ end
258
+ def mkdir(path)
259
+ @paths[path] = true
260
+ puts "m #{path}" unless Ocra.quiet
261
+ @of << [OP_CREATE_DIRECTORY, path].pack("VZ*")
262
+ end
263
+ def ensuremkdir(tgt)
264
+ return if tgt == "."
265
+ if not @paths[tgt]
266
+ ensuremkdir(File.dirname(tgt))
267
+ mkdir(tgt)
268
+ end
269
+ end
270
+ def createfile(src, tgt)
271
+ ensuremkdir(File.dirname(tgt))
272
+ str = File.open(src, "rb") { |file| file.read }
273
+ puts "a #{tgt}" unless Ocra.quiet
274
+ @of << [OP_CREATE_FILE, tgt, str.size, str].pack("VZ*VA*")
275
+ end
276
+ def createprocess(image, cmdline)
277
+ puts "l #{image} #{cmdline}" unless Ocra.quiet
278
+ @of << [OP_CREATE_PROCESS, image, cmdline].pack("VZ*Z*")
279
+ end
280
+ def setenv(name, value)
281
+ puts "e #{name} #{value}" unless Ocra.quiet
282
+ @of << [OP_SETENV, name, value].pack("VZ*Z*")
283
+ end
284
+ def close
285
+ @of.close
286
+ end
287
+ end # class OcraBuilder
288
+
289
+ end # module Ocra
290
+
291
+ if File.basename(__FILE__) == File.basename($0)
292
+ Ocra.init(ARGV)
293
+ ARGV.clear
294
+
295
+ at_exit do
296
+ Ocra.build_exe
297
+ exit(0)
298
+ end
299
+
300
+ puts "=== Loading script to check dependencies" unless Ocra.quiet
301
+ $0 = Ocra.files[0]
302
+ load Ocra.files[0]
303
+ end
Binary file
Binary file
@@ -0,0 +1,197 @@
1
+ require "test/unit"
2
+ require "ocra"
3
+ require "tmpdir"
4
+ require "fileutils"
5
+ require "rbconfig"
6
+
7
+ class TestOcra < Test::Unit::TestCase
8
+
9
+ def initialize(*args)
10
+ super(*args)
11
+ @testnum = 0
12
+ @ocra = File.expand_path(File.join(File.dirname(__FILE__), '../bin/ocra.rb'))
13
+ ENV['RUBYOPT'] = ""
14
+ end
15
+
16
+ def ocra
17
+ @ocra
18
+ end
19
+
20
+ def setup
21
+ @testnum += 1
22
+ @tempdirname = ".ocratest-#{$$}-#{@testnum}"
23
+ Dir.mkdir @tempdirname
24
+ Dir.chdir @tempdirname
25
+ end
26
+
27
+ def teardown
28
+ Dir.chdir '..'
29
+ FileUtils.rm_rf @tempdirname
30
+ end
31
+
32
+ def test_helloworld
33
+ File.open("helloworld.rb", "w") do |f|
34
+ f << "hello_world = \"Hello, World!\"\n"
35
+ end
36
+ assert system("ruby", ocra, "--quiet", "helloworld.rb")
37
+ assert File.exist?("helloworld.exe")
38
+ assert system("helloworld.exe")
39
+ end
40
+
41
+ def test_writefile
42
+ File.open("writefile.rb", "w") do |f|
43
+ f << "File.open(\"output.txt\", \"w\") do |f| f.write \"output\"; end"
44
+ end
45
+ assert system("ruby", ocra, "--quiet", "writefile.rb")
46
+ assert File.exist?("writefile.exe")
47
+ assert system("writefile.exe")
48
+ assert File.exist?("output.txt")
49
+ assert "output", File.read("output.txt")
50
+ end
51
+
52
+ def test_exitstatus
53
+ File.open("exitstatus.rb", "w") do |f|
54
+ f << "exit 167 if __FILE__ == $0"
55
+ end
56
+ assert system("ruby", ocra, "--quiet", "exitstatus.rb")
57
+ system("exitstatus.exe")
58
+ assert_equal 167, $?.exitstatus
59
+ end
60
+
61
+ def test_arguments
62
+ File.open("arguments.rb", "w") do |f|
63
+ f << "if $0 == __FILE__\n"
64
+ f << "exit 1 if ARGV.size != 2\n"
65
+ f << "exit 2 if ARGV[0] != \"foo\"\n"
66
+ f << "exit 3 if ARGV[1] != \"bar baz\"\n"
67
+ # f << "exit 4 if ARGV[2] != \"\\\"smile\\\"\"\n"
68
+ f << "exit(5)\n"
69
+ f << "end"
70
+ end
71
+ assert system("ruby", ocra, "--quiet", "arguments.rb")
72
+ assert File.exist?("arguments.exe")
73
+ # system(File.expand_path("arguments.exe"), "foo", "bar baz", "\"smile\"")
74
+ system("arguments.exe foo \"bar baz\"")
75
+ assert_equal 5, $?.exitstatus
76
+ end
77
+
78
+ def test_stdout_redir
79
+ File.open("stdoutredir.rb", "w") do |f|
80
+ f << "if $0 == __FILE__\n"
81
+ f << "puts \"Hello, World!\"\n"
82
+ f << "end\n"
83
+ end
84
+ assert system("ruby", ocra, "--quiet", "stdoutredir.rb")
85
+ assert File.exist?("stdoutredir.exe")
86
+ system("stdoutredir.exe > output.txt")
87
+ assert File.exist?("output.txt")
88
+ assert_equal "Hello, World!\n", File.read("output.txt")
89
+ end
90
+
91
+ def test_stdin_redir
92
+ File.open("input.txt", "w") do |f|
93
+ f << "Hello, World!\n"
94
+ end
95
+ File.open("stdinredir.rb", "w") do |f|
96
+ f << "if $0 == __FILE__\n"
97
+ f << " exit 104 if gets == \"Hello, World!\\n\""
98
+ f << "end\n"
99
+ end
100
+ assert system("ruby", ocra, "--quiet", "stdinredir.rb")
101
+ assert File.exist?("stdinredir.exe")
102
+ system("stdinredir.exe < input.txt")
103
+ assert 104, $?.exitstatus
104
+ end
105
+
106
+ def test_gdbmdll
107
+ File.open("gdbmdll.rb", "w") do |f|
108
+ f << "require 'gdbm'\n"
109
+ f << "exit 104 if $0 == __FILE__ and defined?(GDBM)\n"
110
+ end
111
+ bindir = RbConfig::CONFIG['bindir']
112
+
113
+ gdbmdllpath = Dir[File.join(bindir, 'gdbm*.dll')][0]
114
+ raise "gdbm dll was not found" unless gdbmdllpath
115
+ gdbmdll = File.basename(gdbmdllpath)
116
+ assert system("ruby", ocra, "--quiet", "--dll", gdbmdll, "gdbmdll.rb")
117
+ path = ENV['PATH']
118
+ ENV['PATH'] = "."
119
+ begin
120
+ system("gdbmdll.exe")
121
+ ensure
122
+ ENV['PATH'] = path
123
+ end
124
+ assert_equal 104, $?.exitstatus
125
+ end
126
+
127
+ def test_relative_require
128
+ File.open("relativerequire.rb", "w") do |f|
129
+ f << "require 'somedir/somefile.rb'\n"
130
+ f << "exit 160 if __FILE__ == $0 and defined?(SomeConst)"
131
+ end
132
+ Dir.mkdir('somedir')
133
+ File.open("somedir/somefile.rb", "w") do |f|
134
+ f << "SomeConst = 12312\n"
135
+ end
136
+ assert system("ruby", ocra, "--quiet", "relativerequire.rb")
137
+ assert File.exist?("relativerequire.exe")
138
+ system("relativerequire.exe")
139
+ assert_equal 160, $?.exitstatus
140
+ end
141
+
142
+ def test_exiting
143
+ File.open("exiting.rb", "w") do |f|
144
+ f << "exit 214\n"
145
+ end
146
+ assert system("ruby", ocra, "--quiet", "exiting.rb")
147
+ assert File.exist?("exiting.exe")
148
+ system("exiting.exe")
149
+ assert_equal 214, $?.exitstatus
150
+ end
151
+
152
+ def test_autoload
153
+ File.open("autoload.rb", "w") do |f|
154
+ f << "$:.unshift File.dirname(__FILE__)\n"
155
+ f << "autoload :Foo, 'foo'\n"
156
+ f << "Foo if __FILE__ == $0\n"
157
+ end
158
+ File.open("foo.rb", "w") do |f|
159
+ f << "class Foo; end\n"
160
+ end
161
+ assert system("ruby", ocra, "--quiet", "autoload.rb")
162
+ assert File.exist?("autoload.exe")
163
+ File.unlink('foo.rb')
164
+ assert system("autoload.exe")
165
+ # assert_equal 214, $?.exitstatus
166
+ end
167
+
168
+ def test_autoload_missing
169
+ File.open("autoloadmissing.rb", "w") do |f|
170
+ f << "$:.unshift File.dirname(__FILE__)\n"
171
+ f << "autoload :Foo, 'foo'\n"
172
+ end
173
+ assert system("ruby", ocra, "--quiet", "autoloadmissing.rb")
174
+ assert File.exist?("autoloadmissing.exe")
175
+ assert system("autoloadmissing.exe")
176
+ end
177
+
178
+ def test_autoload_nested
179
+ File.open("autoloadnested.rb", "w") do |f|
180
+ f << "$:.unshift File.dirname(__FILE__)\n"
181
+ f << "module Bar\n"
182
+ f << " autoload :Foo, 'foo'\n"
183
+ f << "end\n"
184
+ f << "Bar::Foo if __FILE__ == $0\n"
185
+ end
186
+ File.open("foo.rb", "w") do |f|
187
+ f << "module Bar\n"
188
+ f << "class Foo; end\n"
189
+ f << "end\n"
190
+ end
191
+ assert system("ruby", ocra, "--quiet", "autoloadnested.rb")
192
+ assert File.exist?("autoloadnested.exe")
193
+ File.unlink('foo.rb')
194
+ assert system("autoloadnested.exe")
195
+ # assert_equal 214, $?.exitstatus
196
+ end
197
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ocra
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lars Christensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-19 22:00:00 Z
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.10.0
24
+ version:
25
+ description: |-
26
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby
27
+ source code. The executable is a self-extracting, self-running
28
+ executable that contains the Ruby interpreter, your source code and
29
+ any additionally needed ruby libraries or DLL.
30
+ email:
31
+ - larsch@belunktum.dk
32
+ executables:
33
+ - ocra.rb
34
+ extensions: []
35
+
36
+ extra_rdoc_files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ files:
41
+ - History.txt
42
+ - Manifest.txt
43
+ - README.txt
44
+ - Rakefile
45
+ - bin/ocra.rb
46
+ - share/ocra/lzma.exe
47
+ - share/ocra/stub.exe
48
+ - test/test_ocra.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/larsch/ocra/
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --main
56
+ - README.txt
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project: ocra
74
+ rubygems_version: 1.3.2
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code
78
+ test_files:
79
+ - test/test_ocra.rb