ocra 1.1.5.pre3 → 1.2.0.rc1

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.
@@ -1,4 +1,4 @@
1
- === 1.1.5
1
+ === 1.2.0
2
2
 
3
3
  * Ignore console events (Ctrl-C, Ctrl-Break). Ruby process handles
4
4
  them anyway and exist, allowing the stub to clean up temporary
@@ -27,6 +27,10 @@
27
27
  directory layout would not be maintained, e.g. when running "ocra
28
28
  bin/script share/data.dat".
29
29
 
30
+ * Added support for passing arguments to script. Specify argument to
31
+ your script after a "--" marker. Arguments will be passed both at
32
+ compile time and run time. (#27815)
33
+
30
34
  === 1.1.4
31
35
 
32
36
  * The tempdir marker is now pretty-printed as "<tempdir>" in the
data/README.txt CHANGED
@@ -78,7 +78,11 @@ in the forums there aswell.
78
78
  == REQUIREMENTS:
79
79
 
80
80
  * Windows
81
- * Working Ruby installation
81
+
82
+ * Working Ruby installation, tested with:
83
+ * One-Click Installer (187_27_rc2)
84
+ * RubyInstaller (1.8.7p299, 1.9.1p249, 1.9.2p0)
85
+
82
86
  * MinGW Installation (when working with the source code only)
83
87
 
84
88
  == INSTALL:
@@ -220,6 +224,19 @@ of files, for example
220
224
 
221
225
  ocra script.rb assets/**/*.png
222
226
 
227
+ === Command Line Arguments
228
+
229
+ To pass command line argument to your script (both while building and
230
+ when run from the resulting executable), specify them after a "--"
231
+ marker. For example:
232
+
233
+ ocra script.rb -- --some-options=value
234
+
235
+ This will pass "--some-options=value" to the script when build and
236
+ when running the executable. Any extra argument specified by the user
237
+ when invoking the executable will be appended after the compile-time
238
+ arguments.
239
+
223
240
  === Window/Console
224
241
 
225
242
  By default, OCRA builds console application from .rb-files and
data/bin/ocra CHANGED
@@ -11,7 +11,7 @@ module Ocra
11
11
  OP_SETENV = 5
12
12
  OP_POST_CREATE_PROCESS = 6
13
13
 
14
- VERSION = "1.1.5.pre3"
14
+ VERSION = "1.2.0.rc1"
15
15
 
16
16
  IGNORE_MODULES = /^enumerator.so$/
17
17
 
@@ -43,7 +43,8 @@ module Ocra
43
43
  :quiet => false,
44
44
  :autodll => true,
45
45
  :show_warnings => true,
46
- :gem_filter => true
46
+ :gem_filter => true,
47
+ :arg => []
47
48
  }
48
49
 
49
50
  @options.each_key { |opt| eval("def self.#{opt}; @options[:#{opt}]; end") }
@@ -143,7 +144,10 @@ EOF
143
144
  @options[:show_warnings] = false
144
145
  when /\A--no-gem-filter\z/
145
146
  @options[:gem_filter] = false
146
- when /\A--help\z/, /\A--/
147
+ when /\A--\z/
148
+ @options[:arg] = ARGV.dup
149
+ ARGV.clear
150
+ when /\A--help\z/, /\A--./
147
151
  puts usage
148
152
  exit
149
153
  else
@@ -195,13 +199,13 @@ EOF
195
199
  # (directory or file). Return the absolute path to 'tgt' if it can't
196
200
  # be reached from 'src'.
197
201
  def Ocra.relative_path(src, tgt)
198
- a = src.split('/')
199
- b = tgt.split('/')
202
+ a = posixpath(src).split('/')
203
+ b = posixpath(tgt).split('/')
200
204
  while a.first && a.first.downcase == b.first.downcase
201
205
  a.shift
202
206
  b.shift
203
207
  end
204
- return tgt if b.first =~ /^[a-z]:/i
208
+ return tgt if abspath?(b.first)
205
209
  a.size.times { b.unshift '..' }
206
210
  return b.join('/')
207
211
  end
@@ -214,57 +218,38 @@ EOF
214
218
  src_normalized =~ /^#{Regexp.escape tgt_normalized}[\/\\]/i
215
219
  end
216
220
 
221
+ # Returns true if 'path' is absolute, false otherwise.
222
+ def Ocra.abspath?(path)
223
+ path =~ /\A[A-Z]:/i
224
+ end
225
+
217
226
  # Guess the load path (from 'paths') that was used to load
218
227
  # 'path'. This is primarily relevant on Ruby 1.8 which stores
219
228
  # "unqualified" paths in $LOADED_FEATURES.
220
229
  def Ocra.find_load_path(paths, path)
221
- if path[1,1] == ":"
230
+ if abspath?(path)
231
+ # Find the shortest path in 'paths' that contain 'path'
222
232
  rps = paths.map {|p| relative_path(File.expand_path(p), path) }
223
233
  rps.zip(paths).sort_by {|x| x[0].size }.first[1]
224
234
  else
235
+ # Select the paths that contain 'path' and select the shortest
225
236
  candidates = paths.select { |p| File.exist?(File.expand_path(path, p)) }
226
237
  candidates.sort_by {|p| p.size}.last
227
238
  end
228
239
  end
229
-
230
- def Ocra.build_exe
231
- @added_load_paths = $LOAD_PATH - @load_path_before
232
240
 
233
- restore_environment
234
-
235
- # Attempt to autoload libraries before doing anything else.
236
- attempt_load_autoload if Ocra.load_autoload
237
-
238
- # Store the currently loaded files (before we require rbconfig for
239
- # our own use).
240
- features = $LOADED_FEATURES.dup
241
-
242
- # Find gemspecs to include
243
- if defined?(Gem)
244
- gemspecs = Gem.loaded_specs.map { |name,info| info.loaded_from }
245
- else
246
- gemspecs = []
247
- end
248
-
249
- require 'rbconfig'
250
- exec_prefix = RbConfig::CONFIG['exec_prefix']
251
- src_prefix = Dir.pwd
252
- sitelibdir = RbConfig::CONFIG['sitelibdir']
253
- bindir = RbConfig::CONFIG['bindir']
254
- libruby_so = RbConfig::CONFIG['LIBRUBY_SO']
255
-
256
- # Find the root of all files specified on the command line and use
257
- # it as the "src" of the output. Adjust 'Ocra.files' to be
258
- # relative to the resulting root.
259
- files = Ocra.files.map { |file| Dir[Ocra.posixpath(file)] }.flatten
260
- files = files.map { |file| File.expand_path(file) }
261
- src_prefix = files.inject(File.dirname(files[0])) do |srcroot, path|
262
- if subpath?(path, exec_prefix)
241
+ # Find the root of all files specified on the command line and use
242
+ # it as the "src" of the output.
243
+ def Ocra.find_src_root(files)
244
+ src_files = files.map { |file| Dir[posixpath(file)] }.flatten
245
+ src_files = src_files.map { |file| File.expand_path(file) }
246
+ src_prefix = src_files.inject(File.dirname(src_files[0])) do |srcroot, path|
247
+ if subpath?(path, @ruby_exec_prefix)
263
248
  srcroot
264
249
  else
265
250
  loop do
266
251
  relpath = relative_path(srcroot, path)
267
- if relpath =~ /^[A-Z]:$/i
252
+ if abspath?(relpath)
268
253
  puts "ERROR: No common directory contains all specified files"
269
254
  end
270
255
  if relpath =~ /^\.\.\//
@@ -276,20 +261,20 @@ EOF
276
261
  srcroot
277
262
  end
278
263
  end
279
- files = files.map { |file| relative_path(src_prefix, file) }
280
- Ocra.files.replace(files)
281
-
282
- instsitelibdir = relative_path(exec_prefix, sitelibdir)
283
-
284
- load_path = []
264
+ src_files = src_files.map { |file| relative_path(src_prefix, file) }
265
+ return src_prefix, src_files
266
+ end
285
267
 
286
- # Detect loaded gems and add additional gem files to the
287
- # executable. Ruby 1.8 provides Gem.loaded_specs to detect gems,
288
- # but this is empty with Ruby 1.9. So instead, we look for any
289
- # loaded file from a gem path.
268
+ # Searches for features that are loaded from gems, then produces a
269
+ # list of files included in those gems' manifests. Also returns a
270
+ # list of original features that are caused gems to be
271
+ # included. Ruby 1.8 provides Gem.loaded_specs to detect gems, but
272
+ # this is empty with Ruby 1.9. So instead, we look for any loaded
273
+ # file from a gem path.
274
+ def Ocra.find_gem_files(features)
275
+ features_from_gems = []
290
276
  if defined?(Gem)
291
277
  gems = []
292
- features_from_gems = []
293
278
  features.each do |filename|
294
279
  if filename !~ /^[a-z]:/i
295
280
  filename = find_load_path($:, filename)
@@ -309,7 +294,7 @@ EOF
309
294
  gem_files = []
310
295
  gems.each do |gempath, fullgemname|
311
296
  gemspecpath = File.join(gempath, "specifications", fullgemname + ".gemspec")
312
- gemspecs << gemspecpath
297
+ @gemspecs << gemspecpath
313
298
  spec = Gem::Specification.load(gemspecpath)
314
299
 
315
300
  # Get list of files
@@ -328,21 +313,61 @@ EOF
328
313
  else
329
314
  gem_files = []
330
315
  end
316
+ return gem_files, features_from_gems
317
+ end
318
+
319
+ def Ocra.build_exe
320
+ @added_load_paths = $LOAD_PATH - @load_path_before
321
+
322
+ restore_environment
331
323
 
332
- # Find loaded files
324
+ # Attempt to autoload libraries before doing anything else.
325
+ attempt_load_autoload if Ocra.load_autoload
326
+
327
+ # Store the currently loaded files (before we require rbconfig for
328
+ # our own use).
329
+ features = $LOADED_FEATURES.dup
330
+
331
+ # Find gemspecs to include
332
+ if defined?(Gem)
333
+ @gemspecs = Gem.loaded_specs.map { |name,info| info.loaded_from }
334
+ else
335
+ @gemspecs = []
336
+ end
337
+
338
+ require 'rbconfig'
339
+ @ruby_exec_prefix = RbConfig::CONFIG['exec_prefix']
340
+ src_prefix = Dir.pwd
341
+ sitelibdir = RbConfig::CONFIG['sitelibdir']
342
+ bindir = RbConfig::CONFIG['bindir']
343
+ libruby_so = RbConfig::CONFIG['LIBRUBY_SO']
344
+ instsitelibdir = relative_path(@ruby_exec_prefix, sitelibdir)
345
+
346
+ load_path = []
347
+
348
+ # Find the source root and adjust paths
349
+ src_prefix, src_files = find_src_root(Ocra.files)
350
+ Ocra.files.replace(src_files)
351
+
352
+ # Find gems files and remove them from features
353
+ gem_files, features_from_gems = find_gem_files(features)
354
+ features -= features_from_gems
355
+
356
+ # Find features and decide where to put them in the temporary
357
+ # directory layout.
333
358
  libs = []
334
359
  features.each do |filename|
335
360
  path = find_load_path($:, filename)
336
361
  if path
337
- if filename[1,1] == ":"
362
+ if abspath?(filename)
338
363
  filename = relative_path(File.expand_path(path), filename)
339
364
  end
340
365
  if filename =~ /^\.\.\//
341
366
  puts "=== WARNING: Detected a relative require (#{filename}). This is not recommended." if Ocra.show_warnings
342
367
  end
343
368
  fullpath = File.expand_path(filename, path)
344
- if subpath?(fullpath, exec_prefix)
345
- libs << [ fullpath, relative_path(exec_prefix, fullpath) ]
369
+ if subpath?(fullpath, @ruby_exec_prefix)
370
+ libs << [ fullpath, relative_path(@ruby_exec_prefix, fullpath) ]
346
371
  elsif subpath?(fullpath, src_prefix)
347
372
  targetpath = File.join("src", relative_path(src_prefix, fullpath))
348
373
  libs << [ fullpath, targetpath ]
@@ -360,10 +385,11 @@ EOF
360
385
  end
361
386
  end
362
387
 
363
- # Add files from Gems
388
+ # Decide where to put gem files, either the system gem folder, or
389
+ # GEMHOME.
364
390
  gem_files.each do |gemfile|
365
- if subpath?(gemfile, exec_prefix)
366
- libs << [ gemfile, relative_path(exec_prefix, gemfile) ]
391
+ if subpath?(gemfile, @ruby_exec_prefix)
392
+ libs << [ gemfile, relative_path(@ruby_exec_prefix, gemfile) ]
367
393
  elsif defined?(Gem) and gemhome = Gem.path.find { |pth| subpath?(gemfile, pth) }
368
394
  targetpath = File.join("gemhome", relative_path(gemhome, fullpath))
369
395
  libs << [ gemfile, targetpath ]
@@ -382,11 +408,11 @@ EOF
382
408
  puts "=== Building #{executable}" unless Ocra.quiet
383
409
  OcraBuilder.new(executable, windowed) do |sb|
384
410
  # Add explicitly mentioned files
385
- files.each do |file|
411
+ Ocra.files.each do |file|
386
412
  file = File.join(src_prefix, file)
387
413
 
388
- if subpath?(file, exec_prefix)
389
- target = relative_path(exec_prefix, file)
414
+ if subpath?(file, @ruby_exec_prefix)
415
+ target = relative_path(@ruby_exec_prefix, file)
390
416
  elsif subpath?(file, src_prefix)
391
417
  target = File.join('src', relative_path(src_prefix, file))
392
418
  else
@@ -413,23 +439,23 @@ EOF
413
439
 
414
440
  # Add detected DLLs
415
441
  dlls.each do |dll|
416
- if subpath?(dll, exec_prefix)
417
- target = relative_path(exec_prefix, dll)
442
+ if subpath?(dll, @ruby_exec_prefix)
443
+ target = relative_path(@ruby_exec_prefix, dll)
418
444
  else
419
445
  target = File.join('bin', File.basename(dll))
420
446
  end
421
447
  sb.createfile(dll, target)
422
448
  end
423
449
 
424
- # Add extra DLLs
450
+ # Add extra DLLs specified on the command line
425
451
  Ocra.extra_dlls.each do |dll|
426
452
  sb.createfile(File.join(bindir, dll), File.join("bin", dll))
427
453
  end
428
454
 
429
455
  # Add gemspec files
430
- gemspecs.each do |gemspec|
431
- if subpath?(gemspec, exec_prefix)
432
- path = relative_path(exec_prefix, gemspec)
456
+ @gemspecs.each do |gemspec|
457
+ if subpath?(gemspec, @ruby_exec_prefix)
458
+ path = relative_path(@ruby_exec_prefix, gemspec)
433
459
  sb.createfile(gemspec, path)
434
460
  elsif defined?(Gem) and gemhome = Gem.path.find { |pth| subpath?(gemspec, pth) }
435
461
  path = File.join('gemhome', relative_path(gemhome, gemspec))
@@ -439,7 +465,7 @@ EOF
439
465
  end
440
466
  end
441
467
 
442
- # Add loaded libraries
468
+ # Add loaded libraries (features, gems)
443
469
  libs.each do |path, target|
444
470
  sb.createfile(path, target)
445
471
  end
@@ -450,7 +476,9 @@ EOF
450
476
  sb.setenv('GEM_PATH', "#{TEMPDIR_MARKER}\\gemhome")
451
477
 
452
478
  # Launch the script
453
- sb.postcreateprocess(TEMPDIR_MARKER + "\\bin\\" + rubyexe, "#{rubyexe} \"\xff\\src\\" + Ocra.dospath(Ocra.files[0]) + "\"")
479
+ extra_arg = Ocra.arg.map { |a| ' "' + a.gsub(/\"/,'\\"') + '"' }.join
480
+ sb.postcreateprocess(TEMPDIR_MARKER + "\\bin\\" + rubyexe,
481
+ "#{rubyexe} \"\xff\\src\\" + Ocra.dospath(Ocra.files[0]) + "\"#{extra_arg}")
454
482
 
455
483
  puts "=== Compressing" unless Ocra.quiet or not Ocra.lzma_mode
456
484
  end
@@ -597,7 +625,7 @@ end # module Ocra
597
625
 
598
626
  if File.basename(__FILE__) == File.basename($0)
599
627
  Ocra.init(ARGV)
600
- ARGV.clear
628
+ ARGV.replace(Ocra.arg)
601
629
 
602
630
  if !File.exist?(Ocra.files[0])
603
631
  puts "ERROR: #{Ocra.files[0]} was not found!"
@@ -1,3 +1,3 @@
1
1
  class Ocra
2
- VERSION = '1.1.5.pre3'
2
+ VERSION = '1.2.0.rc1'
3
3
  end
Binary file
Binary file
Binary file
@@ -4,9 +4,6 @@ require "fileutils"
4
4
  require "rbconfig"
5
5
 
6
6
  require 'rbconfig'
7
- puts "Version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
8
- puts "Architecture: #{RbConfig::CONFIG['arch']}"
9
- puts "Host: #{RbConfig::CONFIG['host']}"
10
7
 
11
8
  begin
12
9
  require "rubygems"
@@ -146,17 +143,57 @@ class TestOcra < Test::Unit::TestCase
146
143
  end
147
144
 
148
145
  # Test that arguments are passed correctly to scripts.
149
- def test_arguments
146
+ def test_arguments1
150
147
  with_fixture 'arguments' do
151
148
  assert system("ruby", ocra, "arguments.rb", *DefaultArgs)
152
149
  assert File.exist?("arguments.exe")
153
150
  pristine_env "arguments.exe" do
154
- system("arguments.exe foo \"bar baz\"")
151
+ system("arguments.exe foo \"bar baz \\\"quote\\\"\"")
155
152
  assert_equal 5, $?.exitstatus
156
153
  end
157
154
  end
158
155
  end
159
156
 
157
+ # Test that arguments are passed correctly to scripts (specified at
158
+ # compile time).
159
+ def test_arguments2
160
+ with_fixture 'arguments' do
161
+ args = DefaultArgs + ["--", "foo", "bar baz \"quote\"" ]
162
+ assert system("ruby", ocra, "arguments.rb", *args)
163
+ assert File.exist?("arguments.exe")
164
+ pristine_env "arguments.exe" do
165
+ system("arguments.exe")
166
+ assert_equal 5, $?.exitstatus
167
+ end
168
+ end
169
+ end
170
+
171
+ # Test that arguments are passed correctly to scripts (specified at
172
+ # compile time).
173
+ def test_arguments3
174
+ with_fixture 'arguments' do
175
+ args = DefaultArgs + ["--", "foo"]
176
+ assert system("ruby", ocra, "arguments.rb", *args)
177
+ assert File.exist?("arguments.exe")
178
+ pristine_env "arguments.exe" do
179
+ system("arguments.exe \"bar baz \\\"quote\\\"\"")
180
+ assert_equal 5, $?.exitstatus
181
+ end
182
+ end
183
+ end
184
+
185
+ # Test that arguments are passed correctly at build time.
186
+ def test_buildarg
187
+ with_fixture "buildarg" do
188
+ args = DefaultArgs + [ "--", "--some-option" ]
189
+ assert system("ruby", ocra, "buildarg.rb", *args)
190
+ assert File.exist?("buildarg.exe")
191
+ pristine_env "buildarg.exe" do
192
+ assert system("buildarg.exe")
193
+ end
194
+ end
195
+ end
196
+
160
197
  # Test that the standard output from a script can be redirected to a
161
198
  # file.
162
199
  def test_stdout_redir
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocra
3
3
  version: !ruby/object:Gem::Version
4
- hash: -671420158
5
4
  prerelease: true
6
5
  segments:
7
6
  - 1
8
- - 1
9
- - 5
10
- - pre3
11
- version: 1.1.5.pre3
7
+ - 2
8
+ - 0
9
+ - rc1
10
+ version: 1.2.0.rc1
12
11
  platform: ruby
13
12
  authors:
14
13
  - Lars Christensen
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-08-20 00:00:00 +02:00
18
+ date: 2010-08-22 00:00:00 +02:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -27,7 +26,6 @@ dependencies:
27
26
  requirements:
28
27
  - - ">="
29
28
  - !ruby/object:Gem::Version
30
- hash: 7
31
29
  segments:
32
30
  - 2
33
31
  - 0
@@ -43,7 +41,6 @@ dependencies:
43
41
  requirements:
44
42
  - - ">="
45
43
  - !ruby/object:Gem::Version
46
- hash: 21
47
44
  segments:
48
45
  - 2
49
46
  - 6
@@ -93,7 +90,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
90
  requirements:
94
91
  - - ">="
95
92
  - !ruby/object:Gem::Version
96
- hash: 3
97
93
  segments:
98
94
  - 0
99
95
  version: "0"
@@ -102,7 +98,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
98
  requirements:
103
99
  - - ">"
104
100
  - !ruby/object:Gem::Version
105
- hash: 25
106
101
  segments:
107
102
  - 1
108
103
  - 3