ocra 1.3.0.rc1 → 1.3.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,4 +1,4 @@
1
- === 1.3.0.rc1
1
+ === 1.3.0
2
2
 
3
3
  * Fixed some additional corner cases with absolute and relative
4
4
  require & load paths. Extended test suite to cover a lot more
@@ -47,23 +47,62 @@ dependencies (gems and DLLs) into an executable named
47
47
 
48
48
  ocra --help
49
49
 
50
- --dll dllname Include additional DLLs from the Ruby bindir.
51
- --no-lzma Disable LZMA compression of the executable.
52
- --no-dep-run Don't run script.rb to check for dependencies.
53
- --add-all-core Add all core ruby libraries to the executable.
54
- --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.
55
- --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.
56
- --quiet Suppress output while building executable.
57
- --verbose Show extra output while building executable.
58
- --debug Executable will be verbose.
59
- --debug-extract Executable will unpack to local dir and not delete after.
60
- --help Display this information.
61
- --windows Force Windows application (rubyw.exe)
62
- --console Force console application (ruby.exe)
63
- --no-autoload Don't load/include script.rb's autoloads.
64
- --icon <ico> Replace icon with a custom one.
65
- --version Display version number and exit.
66
- --no-gem-filter Don't filter readme's, doc, C-source, etc. from gems.
50
+ Ocra options:
51
+
52
+ --help Display this information.
53
+ --quiet Suppress output while building executable.
54
+ --verbose Show extra output while building executable.
55
+ --version Display version number and exit.
56
+
57
+ Packaging options:
58
+
59
+ --dll dllname Include additional DLLs from the Ruby bindir.
60
+ --add-all-core Add all core ruby libraries to the executable.
61
+ --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.
62
+ --no-enc Exclude encoding support files
63
+
64
+ Gem content detection modes:
65
+
66
+ --gem-minimal[=gem1,..] Include only loaded scripts
67
+ --gem-guess=[gem1,...] Include loaded scripts & best guess (DEFAULT)
68
+ --gem-all[=gem1,..] Include all scripts & files
69
+ --gem-full[=gem1,..] Include EVERYTHING
70
+ --gem-spec[=gem1,..] Include files in gemspec (Does not work with Rubygems 1.7+)
71
+
72
+ minimal: loaded scripts
73
+ guess: loaded scripts and other files
74
+ all: loaded scripts, other scripts, other files (except extras)
75
+ full: Everything found in the gem directory
76
+
77
+ --[no-]gem-scripts[=..] Other script files than those loaded
78
+ --[no-]gem-files[=..] Other files (e.g. data files)
79
+ --[no-]gem-extras[=..] Extra files (README, etc.)
80
+
81
+ scripts: .rb/.rbw files
82
+ extras: C/C++ sources, object files, test, spec, README
83
+ files: all other files
84
+
85
+ Auto-detection options:
86
+
87
+ --no-dep-run Don't run script.rb to check for dependencies.
88
+ --no-autoload Don't load/include script.rb's autoloads.
89
+ --no-autodll Disable detection of runtime DLL dependencies.
90
+
91
+ Output options:
92
+
93
+ --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.
94
+ --no-lzma Disable LZMA compression of the executable.
95
+ --innosetup <file> Use given Inno Setup script (.iss) to create an installer.
96
+
97
+ Executable options:
98
+
99
+ --windows Force Windows application (rubyw.exe)
100
+ --console Force console application (ruby.exe)
101
+ --chdir-first When exe starts, change working directory to app dir.
102
+ --icon <ico> Replace icon with a custom one.
103
+ --debug Executable will be verbose.
104
+ --debug-extract Executable will unpack to local dir and not delete after.
105
+
67
106
 
68
107
  === Compilation:
69
108
 
@@ -167,11 +206,11 @@ your script. Otherwise, OCRA won't know about it and will not include
167
206
  the source files.
168
207
 
169
208
  RubyGems are handled specially. Whenever a file from a Gem is
170
- detected, OCRA will attempt to include all the files from that
171
- specific Gem (all files listed in the manifest), expect some unlikely
172
- needed files such as readme's and other documentation. This latter can
173
- be overruled using the "<tt>--no-gem-filter</tt>" which will make OCRA
174
- include every file that is listed in the Gem's manifest.
209
+ detected, OCRA will attempt to include all the required files from
210
+ that specific Gem, expect some unlikely needed files such as readme's
211
+ and other documentation. This behaviour can be controlled by using the
212
+ --gem-* options. Behaviour can be changed for all gems or specific
213
+ gems using --gem-*=gemname.
175
214
 
176
215
  Libraries found in non-standard path (for example, if you invoke OCRA
177
216
  with "ruby -I some/path") will be placed into the site dir
@@ -201,7 +240,7 @@ build process. You will also probably need to use the --add-all-core
201
240
  option to include the Ruby core libraries.
202
241
 
203
242
  If your app uses gems, then you can specify them in a
204
- Bundler (http://gembundler.com/) Gemfile, then use the --gemfile
243
+ Bundler (http://gembundler.com) Gemfile, then use the --gemfile
205
244
  option to supply it to Ocra. Ocra will automatically include all
206
245
  gems specified, and all their dependencies.
207
246
 
@@ -214,12 +253,74 @@ directory "someapp" and create an exe named "someapp.exe", without
214
253
  actually running the app during the build, you could use the
215
254
  following command:
216
255
 
217
- ocra someapp/script/server someapp --no-dep-run --add-all-core --gemfile someapp/Gemfile
256
+ ocra someapp/script/rails someapp --output someapp.exe --add-all-core \
257
+ --gemfile someapp/Gemfile --no-dep-run --chdir-first -- server
258
+
259
+ Note the space between "--" and "server"! It's important; "server" is an argument to be passed to rails when the script is ran.
218
260
 
219
261
  Rails 2 apps can be packaged similarly, though you will have to
220
262
  integrate them with Bundler (http://gembundler.com/rails23.html)
221
263
  first.
222
264
 
265
+ === Gem handling
266
+
267
+ By default, Ocra includes all scripts that are loaded by your script
268
+ when it is run before packaging. Ocra detects which gems are using and
269
+ includes any additional non-script files from those gems, except
270
+ trivial files such as C/C++ source code, object files, READMEs, unit
271
+ tests, specs, etc.
272
+
273
+ This behaviour can be changed by using the --gem-* options. There are
274
+ four possible modes:
275
+
276
+ minimal: Include only loaded scripts
277
+ guess: Include loaded scripts and important files (DEFAULT)
278
+ all: Include all scripts and important files
279
+ full: Include all files
280
+
281
+ If you find that files are missing from the resulting executable, try
282
+ first with --gem-all=gemname for the gem that is missing, and if that
283
+ does not work, try --gem-full=gemname. The paranoid can use --gem-full
284
+ to include all files for all required gems.
285
+
286
+ === Creating an installer for your application
287
+
288
+ To make your application start up quicker, or to allow it to
289
+ keep files in its application directory between runs, or if
290
+ you just want to make your program seem more like a "regular"
291
+ Windows application, you can have Ocra generate an installer
292
+ for your app with the free Inno Setup software.
293
+
294
+ You will first have to download and install Inno Setup 5 or
295
+ later, and also add its directory to your PATH (so that Ocra
296
+ can find the ISCC compiler program). Once you've done that,
297
+ you can use the --innosetup option to Ocra to supply an
298
+ Inno Setup script. Do not add any [Files] or [Dirs] sections
299
+ to the script; Ocra will figure those out itself.
300
+
301
+ To continue the Rails example above, let's package the Rails 3
302
+ app into an installer. Save the following as "<tt>someapp.iss</tt>":
303
+
304
+ [Setup]
305
+ AppName=SomeApp
306
+ AppVersion=0.1
307
+ DefaultDirName={pf}\SomeApp
308
+ DefaultGroupName=SomeApp
309
+ OutputBaseFilename=SomeAppInstaller
310
+
311
+ [Icons]
312
+ Name: "{group}\SomeApp"; Filename: "{app}\someapp.exe"
313
+ Name: "{group}\Uninstall SomeApp"; Filename: "{uninstallexe}"
314
+
315
+ Then, run Ocra with this command:
316
+
317
+ ocra someapp/script/rails someapp --output someapp.exe --add-all-core \
318
+ --gemfile someapp/Gemfile --no-dep-run --chdir-first --no-lzma \
319
+ --innosetup someapp.iss -- server
320
+
321
+ If all goes well, a file named "SomeAppInstaller.exe" will be placed
322
+ into the Output directory.
323
+
223
324
  === Environment variables
224
325
 
225
326
  OCRA executables clear the RUBYLIB environment variable before your
@@ -239,7 +340,7 @@ executable, for example
239
340
  === Working directory
240
341
 
241
342
  The OCRA executable does not change the working directory when it is
242
- launched.
343
+ launched, unless you use the "<tt>--chdir-first</tt>" option.
243
344
 
244
345
  You should not assume that the current working directory when invoking
245
346
  an executable built with .exe is the location of the source script. It
@@ -247,9 +348,13 @@ can be the directory where the executable is placed (when invoked
247
348
  through the Windows Explorer), the users' current working directory
248
349
  (when invoking from the Command Prompt), or even
249
350
  <tt>C:\\WINDOWS\\SYSTEM32</tt> when the executable is invoked through
250
- a file association. You can optionally change the directory yourself:
351
+ a file association.
251
352
 
252
- Dir.chdir File.dirname($0)
353
+ With the "<tt>--chdir-first</tt>" option, the working directory will
354
+ always be the common parent directory of your source files. This
355
+ should be fine for most applications. However, if your application
356
+ is designed to run from the command line and take filenames as
357
+ arguments, then you cannot use this option.
253
358
 
254
359
  If you wish to maintain the user's working directory, but need to
255
360
  'require' additional Ruby scripts from the source directory, you can
data/bin/ocra CHANGED
@@ -54,8 +54,16 @@ module Ocra
54
54
  src_normalized =~ /^#{Regexp.escape tgt_normalized}#{SEPARATOR_PAT}/i
55
55
  end
56
56
 
57
+ # Join two pathnames together. Returns the right-hand side if it
58
+ # is an absolute path. Otherwise, returns the full path of the
59
+ # left + right.
57
60
  def /(other)
58
- Ocra.Pathname(@path + '/' + Ocra.Pathname(other).path)
61
+ other = Ocra.Pathname(other)
62
+ if other.absolute?
63
+ other
64
+ else
65
+ Ocra.Pathname(@path + '/' + other.path)
66
+ end
59
67
  end
60
68
 
61
69
  def append_to_filename!(s)
@@ -74,6 +82,30 @@ module Ocra
74
82
  Pathname.pathequal(ext, expected_ext)
75
83
  end
76
84
 
85
+ def entries
86
+ Dir.entries(@path).map { |e| self / e }
87
+ end
88
+
89
+ # Recursively find all files which match a specified regular
90
+ # expression.
91
+ def find_all_files(re)
92
+ entries.map do |pn|
93
+ if pn.directory?
94
+ if pn.basename =~ /^\.\.?$/
95
+ []
96
+ else
97
+ pn.find_all_files(re)
98
+ end
99
+ elsif pn.file?
100
+ if pn.basename =~ re
101
+ pn
102
+ else
103
+ []
104
+ end
105
+ end
106
+ end.flatten
107
+ end
108
+
77
109
  def ==(other); to_posix.downcase == other.to_posix.downcase; end
78
110
  def =~(o); @path =~ o; end
79
111
  def <=>(other); @path.casecmp(other.path); end
@@ -84,6 +116,7 @@ module Ocra
84
116
  def dirname; Pathname.new(File.dirname(@path)); end
85
117
  def basename; Pathname.new(File.basename(@path)); end
86
118
  def expand(dir = nil); Pathname.new(File.expand_path(@path, dir && Ocra.Pathname(dir))); end
119
+ def size; File.size(@path); end
87
120
 
88
121
  alias to_s to_posix
89
122
  alias to_str to_posix
@@ -142,22 +175,25 @@ module Ocra
142
175
  a.sort.inject([]) { |r, e| r.last == e ? r : r << e }
143
176
  end
144
177
 
145
- VERSION = "1.3.0.rc1"
178
+ VERSION = "1.3.0.rc2"
146
179
 
147
180
  IGNORE_MODULES = /^enumerator.so$/
148
181
 
149
- IGNORE_GEMFILES = %r{(
182
+ GEM_SCRIPT_RE = /\.rbw?$/
183
+ GEM_EXTRA_RE = %r{(
150
184
  # Auxiliary files in the root of the gem
151
185
  ^(\.\/)?(History|Install|Manifest|README|Licen[sc]e|Contributors|ChangeLog|BSD|GPL).*$ |
152
186
  # Installation files in the root of the gem
153
187
  ^(\.\/)?(Rakefile|setup.rb|extconf.rb)$ |
154
188
  # Documentation/test directories in the root of the gem
155
- ^(\.\/)?(doc|ext|examples|test|tests|benchmarks)\/ |
189
+ ^(\.\/)?(doc|ext|examples|test|tests|benchmarks|spec)\/ |
156
190
  # Directories anywhere
157
191
  (^|\/)(\.autotest|\.svn|\.cvs|\.git)(\/|$) |
158
192
  # Unlikely extensions
159
- \.(rdoc)$/
193
+ \.(rdoc|c|cpp|c++|cxx|h|hxx|hpp|obj|o|a)$/
160
194
  )}xi
195
+
196
+ GEM_NON_FILE_RE = /(#{GEM_EXTRA_RE}|#{GEM_SCRIPT_RE})/
161
197
 
162
198
  # Alias for the temporary directory where files are extracted.
163
199
  TEMPDIR_ROOT = Pathname.new("\xFF")
@@ -176,18 +212,21 @@ module Ocra
176
212
  :add_all_core => false,
177
213
  :output_override => nil,
178
214
  :load_autoload => true,
215
+ :chdir_first => false,
179
216
  :force_windows => false,
180
217
  :force_console => false,
181
218
  :icon_filename => nil,
182
219
  :gemfile => nil,
220
+ :inno_script => nil,
183
221
  :quiet => false,
184
222
  :verbose => false,
185
223
  :autodll => true,
186
224
  :show_warnings => true,
187
225
  :debug => false,
188
226
  :debug_extract => false,
189
- :gem_filter => true,
190
- :arg => []
227
+ :arg => [],
228
+ :enc => true,
229
+ :gem => []
191
230
  }
192
231
 
193
232
  @options.each_key { |opt| eval("def self.#{opt}; @options[:#{opt}]; end") }
@@ -256,23 +295,61 @@ module Ocra
256
295
  usage = <<EOF
257
296
  ocra [options] script.rb
258
297
 
259
- --dll dllname Include additional DLLs from the Ruby bindir.
260
- --no-lzma Disable LZMA compression of the executable.
261
- --no-dep-run Don't run script.rb to check for dependencies.
262
- --add-all-core Add all core ruby libraries to the executable.
263
- --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.
264
- --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.
265
- --quiet Suppress output while building executable.
266
- --verbose Show extra output while building executable.
267
- --debug Executable will be verbose.
268
- --debug-extract Executable will unpack to local dir and not delete after.
269
- --help Display this information.
270
- --windows Force Windows application (rubyw.exe)
271
- --console Force console application (ruby.exe)
272
- --no-autoload Don't load/include script.rb's autoloads.
273
- --icon <ico> Replace icon with a custom one.
274
- --version Display version number and exit.
275
- --no-gem-filter Don't filter readme's, doc, C-source, etc. from gems.
298
+ Ocra options:
299
+
300
+ --help Display this information.
301
+ --quiet Suppress output while building executable.
302
+ --verbose Show extra output while building executable.
303
+ --version Display version number and exit.
304
+
305
+ Packaging options:
306
+
307
+ --dll dllname Include additional DLLs from the Ruby bindir.
308
+ --add-all-core Add all core ruby libraries to the executable.
309
+ --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.
310
+ --no-enc Exclude encoding support files
311
+
312
+ Gem content detection modes:
313
+
314
+ --gem-minimal[=gem1,..] Include only loaded scripts
315
+ --gem-guess=[gem1,...] Include loaded scripts & best guess (DEFAULT)
316
+ --gem-all[=gem1,..] Include all scripts & files
317
+ --gem-full[=gem1,..] Include EVERYTHING
318
+ --gem-spec[=gem1,..] Include files in gemspec (Does not work with Rubygems 1.7+)
319
+
320
+ minimal: loaded scripts
321
+ guess: loaded scripts and other files
322
+ all: loaded scripts, other scripts, other files (except extras)
323
+ full: Everything found in the gem directory
324
+
325
+ --[no-]gem-scripts[=..] Other script files than those loaded
326
+ --[no-]gem-files[=..] Other files (e.g. data files)
327
+ --[no-]gem-extras[=..] Extra files (README, etc.)
328
+
329
+ scripts: .rb/.rbw files
330
+ extras: C/C++ sources, object files, test, spec, README
331
+ files: all other files
332
+
333
+ Auto-detection options:
334
+
335
+ --no-dep-run Don't run script.rb to check for dependencies.
336
+ --no-autoload Don't load/include script.rb's autoloads.
337
+ --no-autodll Disable detection of runtime DLL dependencies.
338
+
339
+ Output options:
340
+
341
+ --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.
342
+ --no-lzma Disable LZMA compression of the executable.
343
+ --innosetup <file> Use given Inno Setup script (.iss) to create an installer.
344
+
345
+ Executable options:
346
+
347
+ --windows Force Windows application (rubyw.exe)
348
+ --console Force console application (ruby.exe)
349
+ --chdir-first When exe starts, change working directory to app dir.
350
+ --icon <ico> Replace icon with a custom one.
351
+ --debug Executable will be verbose.
352
+ --debug-extract Executable will unpack to local dir and not delete after.
276
353
  EOF
277
354
 
278
355
  while arg = argv.shift
@@ -297,12 +374,17 @@ EOF
297
374
  @options[:force_console] = true
298
375
  when /\A--no-autoload\z/
299
376
  @options[:load_autoload] = false
377
+ when /\A--chdir-first\z/
378
+ @options[:chdir_first] = true
300
379
  when /\A--icon\z/
301
380
  @options[:icon_filename] = Pathname(argv.shift)
302
381
  Ocra.fatal_error "Icon file #{icon_filename} not found.\n" unless icon_filename.exist?
303
382
  when /\A--gemfile\z/
304
383
  @options[:gemfile] = Pathname(argv.shift)
305
384
  Ocra.fatal_error "Gemfile #{gemfile} not found.\n" unless gemfile.exist?
385
+ when /\A--innosetup\z/
386
+ @options[:inno_script] = Pathname(argv.shift)
387
+ Ocra.fatal_error "Inno Script #{inno_script} not found.\n" unless inno_script.exist?
306
388
  when /\A--no-autodll\z/
307
389
  @options[:autodll] = false
308
390
  when /\A--version\z/
@@ -314,11 +396,15 @@ EOF
314
396
  @options[:debug] = true
315
397
  when /\A--debug-extract\z/
316
398
  @options[:debug_extract] = true
317
- when /\A--no-gem-filter\z/
318
- @options[:gem_filter] = false
319
399
  when /\A--\z/
320
400
  @options[:arg] = ARGV.dup
321
401
  ARGV.clear
402
+ when /\A--(no-)?enc\z/
403
+ @options[:enc] = !$1
404
+ when /\A--(no-)?gem-(\w+)(?:=(.*))?$/
405
+ negate, group, list = $1, $2, $3
406
+ @options[:gem] ||= []
407
+ @options[:gem] << [negate, group.to_sym, list && list.split(",") ]
322
408
  when /\A--help\z/, /\A--./
323
409
  puts usage
324
410
  exit 0
@@ -327,6 +413,18 @@ EOF
327
413
  end
328
414
  end
329
415
 
416
+ if Ocra.debug_extract && Ocra.inno_script
417
+ Ocra.fatal_error "The --debug-extract option conflicts with use of Inno Setup"
418
+ end
419
+
420
+ if Ocra.lzma_mode && Ocra.inno_script
421
+ Ocra.fatal_error "LZMA compression must be disabled (--no-lzma) when using Inno Setup"
422
+ end
423
+
424
+ if !Ocra.chdir_first && Ocra.inno_script
425
+ Ocra.fatal_error "Chdir-first mode must be enabled (--chdir-first) when using Inno Setup"
426
+ end
427
+
330
428
  if files.empty?
331
429
  puts usage
332
430
  exit 1
@@ -422,7 +520,13 @@ EOF
422
520
  srcroot
423
521
  end
424
522
  end
425
- src_files = src_files.map { |file| file.relative_path_from(src_prefix) }
523
+ src_files = src_files.map do |file|
524
+ if file.subpath?(src_prefix)
525
+ file.relative_path_from(src_prefix)
526
+ else
527
+ file
528
+ end
529
+ end
426
530
  return src_prefix, src_files
427
531
  end
428
532
 
@@ -478,24 +582,86 @@ EOF
478
582
  gemspecpath = gempath / 'specifications' / "#{fullgemname}.gemspec"
479
583
  @gemspecs << gemspecpath
480
584
  spec = Gem::Specification.load(gemspecpath)
481
- Ocra.msg "Will include gem #{spec.full_name}"
482
-
483
- # Get list of files
484
- files = Pathname(spec.files)
485
- # Filter out some unlikely files (Readme, etc.)
486
- files = files.select { |filename| filename !~ IGNORE_GEMFILES } if Ocra.gem_filter
487
- # Find the full path
488
- files = files.map { |file| (gempath / "gems" / fullgemname / file).expand }
489
- # Filter out non-files
490
- files = files.select { |file| file.file? }
491
-
492
- gem_files += files
585
+
586
+ # Determine which set of files to include for this particular gem
587
+ include = [ :loaded, :files ]
588
+ Ocra.gem.each do |negate, option, list|
589
+ if list.nil? or list.include?(spec.name)
590
+ case option
591
+ when :minimal
592
+ include = [ :loaded ]
593
+ when :guess
594
+ include = [ :loaded, :files ]
595
+ when :all
596
+ include = [ :scripts, :files ]
597
+ when :full
598
+ include = [ :scripts, :files, :extras ]
599
+ when :spec
600
+ include = [ :spec ]
601
+ when :scripts
602
+ if negate
603
+ include.delete(:scripts)
604
+ else
605
+ include.push(:scripts)
606
+ end
607
+ when :files
608
+ if negate
609
+ include.delete(:files)
610
+ else
611
+ include.push(:files)
612
+ end
613
+ when :extras
614
+ if negate
615
+ include.delete(:extras)
616
+ else
617
+ include.push(:extras)
618
+ end
619
+ end
620
+ end
621
+ end
622
+
623
+ Ocra.msg "Detected gem #{spec.full_name} (#{include.join(', ')})"
624
+
625
+ gem_root = gempath / "gems" / spec.full_name
626
+ gem_root_files = nil
627
+ files = []
628
+
629
+ # Find the selected files
630
+ include.each do |set|
631
+ case set
632
+ when :spec
633
+ files << Pathname(spec.files)
634
+ when :loaded
635
+ files << features_from_gems.select { |feature| feature.subpath?(gem_root) }
636
+ when :files
637
+ gem_root_files ||= gem_root.find_all_files(//)
638
+ files << gem_root_files.select { |path| path.relative_path_from(gem_root) !~ GEM_NON_FILE_RE }
639
+ when :extra
640
+ gem_root_files ||= gem_root.find_all_files(//)
641
+ files << gem_root_files.select { |path| path.relative_path_from(gem_root) =~ GEM_EXTRA_RE }
642
+ when :scripts
643
+ gem_root_files ||= gem_root.find_all_files(//)
644
+ files << gem_root_files.select { |path| path.relative_path_from(gem_root) =~ GEM_SCRIPT_RE }
645
+ end
646
+ end
647
+
648
+ files.flatten!
649
+ actual_files = files.select { |file| file.file? }
650
+
651
+ (files - actual_files).each do |missing_file|
652
+ Ocra.warn "#{missing_file} was not found"
653
+ end
654
+
655
+ total_size = actual_files.inject(0) { |size, path| size + path.size }
656
+ Ocra.msg "\t#{actual_files.size} files, #{total_size} bytes"
657
+
658
+ gem_files += actual_files
493
659
  end
494
660
  gem_files = sort_uniq(gem_files)
495
- features -= features_from_gems # FIXME Isn't this duplicated by caller?
496
661
  else
497
662
  gem_files = []
498
663
  end
664
+ features_from_gems -= gem_files
499
665
  return gem_files, features_from_gems
500
666
  end
501
667
 
@@ -538,6 +704,23 @@ EOF
538
704
  # Find the source root and adjust paths
539
705
  src_prefix, src_files = find_src_root(Ocra.files)
540
706
 
707
+ # Include encoding support files
708
+ if Ocra.enc
709
+ all_load_paths.each do |path|
710
+ if path.subpath?(Host.exec_prefix)
711
+ encpath = path / "enc"
712
+ if encpath.exist?
713
+ encfiles = encpath.find_all_files(/\.so$/)
714
+ size = encfiles.inject(0) { |sum,pn| sum + pn.size }
715
+ Ocra.msg "Including #{encfiles.size} encoding support files (#{size} bytes, use --no-enc to exclude)"
716
+ features.push(*encfiles)
717
+ end
718
+ end
719
+ end
720
+ else
721
+ Ocra.msg "Not including encoding support files"
722
+ end
723
+
541
724
  # Find features and decide where to put them in the temporary
542
725
  # directory layout.
543
726
  libs = []
@@ -713,15 +896,16 @@ EOF
713
896
  sb.setenv('GEM_PATH', (TEMPDIR_ROOT / GEMHOMEDIR).to_native)
714
897
 
715
898
  # Add the opcode to launch the script
716
- extra_arg = Ocra.arg.map { |arg| ' "' + arg.gsub(/\"/,'\\"') + '"' }.join
899
+ extra_arg = Ocra.arg.map { |arg| ' "' + arg.gsub("\"","\\\"") + '"' }.join
717
900
  installed_ruby_exe = TEMPDIR_ROOT / BINDIR / rubyexe
718
901
  launch_script = (TEMPDIR_ROOT / target_script).to_native
719
902
  sb.postcreateprocess(installed_ruby_exe,
720
903
  "#{rubyexe} \"#{launch_script}\"#{extra_arg}")
721
-
722
- Ocra.msg "Compressing" unless not Ocra.lzma_mode
723
904
  end
724
- Ocra.msg "Finished building #{executable} (#{File.size(executable)} bytes)"
905
+
906
+ unless Ocra.inno_script
907
+ Ocra.msg "Finished building #{executable} (#{File.size(executable)} bytes)"
908
+ end
725
909
  end
726
910
 
727
911
  module LibraryDetector
@@ -797,7 +981,6 @@ EOF
797
981
  opcode_offset = File.size(path)
798
982
 
799
983
  File.open(path, "ab") do |ocrafile|
800
-
801
984
  if Ocra.lzma_mode
802
985
  @of = ""
803
986
  else
@@ -805,16 +988,18 @@ EOF
805
988
  end
806
989
 
807
990
  if Ocra.debug
991
+ Ocra.msg("Enabling debug mode in executable")
808
992
  ocrafile.write([OP_ENABLE_DEBUG_MODE].pack("V"))
809
993
  end
810
994
 
811
- createinstdir Ocra.debug_extract, !Ocra.debug_extract
995
+ createinstdir Ocra.debug_extract, !Ocra.debug_extract, Ocra.chdir_first
812
996
 
813
997
  yield(self)
814
998
 
815
- if Ocra.lzma_mode
999
+ if Ocra.lzma_mode and not Ocra.inno_script
816
1000
  begin
817
1001
  File.open("tmpin", "wb") { |tmp| tmp.write(@of) }
1002
+ Ocra.msg "Compressing #{@of.size} bytes"
818
1003
  system("\"#{Ocra.lzmapath}\" e tmpin tmpout 2>NUL") or fail
819
1004
  compressed_data = File.open("tmpout", "rb") { |tmp| tmp.read }
820
1005
  ocrafile.write([OP_DECOMPRESS_LZMA, compressed_data.size, compressed_data].pack("VVA*"))
@@ -822,21 +1007,68 @@ EOF
822
1007
  File.unlink("tmpin") if File.exist?("tmpin")
823
1008
  File.unlink("tmpout") if File.exist?("tmpout")
824
1009
  end
825
- else
826
- ocrafile.write(@of) if Ocra.lzma_mode
827
1010
  end
828
1011
 
829
1012
  ocrafile.write([OP_END].pack("V"))
830
1013
  ocrafile.write([opcode_offset].pack("V")) # Pointer to start of opcodes
831
1014
  ocrafile.write(Signature.pack("C*"))
832
1015
  end
1016
+
1017
+ if Ocra.inno_script
1018
+ begin
1019
+ iss = File.read(Ocra.inno_script) + "\n\n"
1020
+
1021
+ iss << "[Dirs]\n"
1022
+ @paths.each_key do |p|
1023
+ iss << "Name: \"{app}/#{p}\"\n"
1024
+ end
1025
+ iss << "\n"
1026
+
1027
+ iss << "[Files]\n"
1028
+ path_escaped = path.to_s.gsub('"', '""')
1029
+ iss << "Source: \"#{path_escaped}\"; DestDir: \"{app}\"\n"
1030
+ @files.each do |tgt, src|
1031
+ src_escaped = src.to_s.gsub('"', '""')
1032
+ target_dir_escaped = Pathname.new(tgt).dirname.to_s.gsub('"', '""')
1033
+ iss << "Source: \"#{src_escaped}\"; DestDir: \"{app}/#{target_dir_escaped}\"\n"
1034
+ end
1035
+ iss << "\n"
1036
+
1037
+ Ocra.verbose_msg "### INNOSETUP SCRIPT ###\n\n#{iss}\n\n"
1038
+
1039
+ f = File.open("ocratemp.iss", "w")
1040
+ f.write(iss)
1041
+ f.close()
1042
+
1043
+ iscc_cmd = ["iscc"]
1044
+ iscc_cmd << "/Q" unless Ocra.verbose
1045
+ iscc_cmd << "ocratemp.iss"
1046
+ Ocra.msg "Running InnoSetup compiler ISCC"
1047
+ result = system(*iscc_cmd)
1048
+ if not result
1049
+ case $?
1050
+ when 0 then raise RuntimeError.new("ISCC reported success, but system reported error?")
1051
+ when 1 then raise RuntimeError.new("ISCC reports invalid command line parameters")
1052
+ when 2 then raise RuntimeError.new("ISCC reports that compilation failed")
1053
+ else raise RuntimeError.new("ISCC failed to run. Is the InnoSetup directory in your PATH?")
1054
+ end
1055
+ end
1056
+ rescue Exception => e
1057
+ Ocra.fatal_error("InnoSetup installer creation failed: #{e.message}")
1058
+ ensure
1059
+ File.unlink("ocratemp.iss") if File.exist?("ocratemp.iss")
1060
+ File.unlink(path) if File.exist?(path)
1061
+ end
1062
+ end
833
1063
  end
834
1064
 
835
1065
  def mkdir(path)
836
1066
  return if @paths[path.path.downcase]
837
1067
  @paths[path.path.downcase] = true
838
1068
  Ocra.verbose_msg "m #{showtempdir path}"
839
- @of << [OP_CREATE_DIRECTORY, path.to_native].pack("VZ*")
1069
+ unless Ocra.inno_script # The directory will be created by InnoSetup with a [Dirs] statement
1070
+ @of << [OP_CREATE_DIRECTORY, path.to_native].pack("VZ*")
1071
+ end
840
1072
  end
841
1073
 
842
1074
  def ensuremkdir(tgt)
@@ -848,18 +1080,22 @@ EOF
848
1080
  end
849
1081
  end
850
1082
 
851
- def createinstdir(next_to_exe = false, delete_after = false)
852
- @of << [OP_CREATE_INST_DIRECTORY, next_to_exe ? 1 : 0, delete_after ? 1 : 0].pack("VVV")
1083
+ def createinstdir(next_to_exe = false, delete_after = false, chdir_before = false)
1084
+ unless Ocra.inno_script # Creation of installation directory will be handled by InnoSetup
1085
+ @of << [OP_CREATE_INST_DIRECTORY, next_to_exe ? 1 : 0, delete_after ? 1 : 0, chdir_before ? 1 : 0].pack("VVVV")
1086
+ end
853
1087
  end
854
1088
 
855
1089
  def createfile(src, tgt)
856
1090
  return if @files[tgt]
857
- @files[tgt] = true
1091
+ @files[tgt] = src
858
1092
  src, tgt = Ocra.Pathname(src), Ocra.Pathname(tgt)
859
1093
  ensuremkdir(tgt.dirname)
860
1094
  str = File.open(src, "rb") { |file| file.read }
861
1095
  Ocra.verbose_msg "a #{showtempdir tgt}"
862
- @of << [OP_CREATE_FILE, tgt.to_native, str.size, str].pack("VZ*VA*")
1096
+ unless Ocra.inno_script # InnoSetup will install the file with a [Files] statement
1097
+ @of << [OP_CREATE_FILE, tgt.to_native, str.size, str].pack("VZ*VA*")
1098
+ end
863
1099
  end
864
1100
 
865
1101
  def createprocess(image, cmdline)
@@ -1,3 +1,3 @@
1
1
  class Ocra
2
- VERSION = '1.3.0.rc1'
2
+ VERSION = '1.3.0.rc2'
3
3
  end
Binary file
Binary file
Binary file
@@ -682,6 +682,27 @@ class TestOcra < Test::Unit::TestCase
682
682
  end
683
683
  end
684
684
 
685
+ # Test that the --chdir-first option changes directory before exe starts script
686
+ def test_chdir_first
687
+ with_fixture 'writefile' do
688
+ # Control test; make sure the writefile script works as expected under default options
689
+ assert system("ruby", ocra, "writefile.rb", *(DefaultArgs))
690
+ pristine_env "writefile.exe" do
691
+ assert !File.exist?("output.txt")
692
+ assert system("writefile.exe")
693
+ assert File.exist?("output.txt")
694
+ end
695
+
696
+ assert system("ruby", ocra, "writefile.rb", *(DefaultArgs + ["--chdir-first"]))
697
+ pristine_env "writefile.exe" do
698
+ assert !File.exist?("output.txt")
699
+ assert system("writefile.exe")
700
+ # If the script ran in its inst directory, then our working dir still shouldn't have any output.txt
701
+ assert !File.exist?("output.txt")
702
+ end
703
+ end
704
+ end
705
+
685
706
  # Would be nice if OCRA could build from source located beneath the
686
707
  # Ruby installation too.
687
708
  def test_exec_prefix
@@ -694,5 +715,18 @@ class TestOcra < Test::Unit::TestCase
694
715
  end
695
716
  end
696
717
  end
718
+
719
+ def test_explicit_in_exec_prefix
720
+ path = File.join(RbConfig::CONFIG["exec_prefix"], "include", "**", "*.h")
721
+ number_of_files = Dir[path].size
722
+ assert number_of_files > 3
723
+ with_fixture "check_includes" do
724
+ assert system("ruby", ocra, "check_includes.rb", path, *DefaultArgs)
725
+ assert File.exist?("check_includes.exe")
726
+ pristine_env "check_includes.exe" do
727
+ assert system("check_includes.exe", number_of_files.to_s)
728
+ end
729
+ end
730
+ end
697
731
 
698
732
  end
metadata CHANGED
@@ -1,68 +1,40 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ocra
3
- version: !ruby/object:Gem::Version
4
- prerelease: true
5
- segments:
6
- - 1
7
- - 3
8
- - 0
9
- - rc1
10
- version: 1.3.0.rc1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0.rc2
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Lars Christensen
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-12-19 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rubyforge
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 2
31
- - 0
32
- - 4
33
- version: 2.0.4
34
- type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
12
+ date: 2011-05-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
37
15
  name: hoe
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &7482744 !ruby/object:Gem::Requirement
40
17
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 2
46
- - 6
47
- - 1
48
- version: 2.6.1
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.9.4
49
22
  type: :development
50
- version_requirements: *id002
51
- description: |-
52
- OCRA (One-Click Ruby Application) builds Windows executables from Ruby
53
- source code. The executable is a self-extracting, self-running
54
- executable that contains the Ruby interpreter, your source code and
55
- any additionally needed ruby libraries or DLL.
23
+ prerelease: false
24
+ version_requirements: *7482744
25
+ description: ! "OCRA (One-Click Ruby Application) builds Windows executables from
26
+ Ruby\r\nsource code. The executable is a self-extracting, self-running\r\nexecutable
27
+ that contains the Ruby interpreter, your source code and\r\nany additionally needed
28
+ ruby libraries or DLL."
56
29
  email: larsch@belunktum.dk
57
- executables:
30
+ executables:
58
31
  - ocra
59
32
  extensions: []
60
-
61
- extra_rdoc_files:
33
+ extra_rdoc_files:
62
34
  - History.txt
63
35
  - Manifest.txt
64
36
  - README.rdoc
65
- files:
37
+ files:
66
38
  - History.txt
67
39
  - Manifest.txt
68
40
  - README.rdoc
@@ -74,40 +46,33 @@ files:
74
46
  - share/ocra/edicon.exe
75
47
  - test/test_ocra.rb
76
48
  - lib/ocra.rb
77
- has_rdoc: true
49
+ - .gemtest
78
50
  homepage: http://ocra.rubyforge.org/
79
51
  licenses: []
80
-
81
52
  post_install_message:
82
- rdoc_options:
53
+ rdoc_options:
83
54
  - --main
84
55
  - README.rdoc
85
- require_paths:
56
+ require_paths:
86
57
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
88
59
  none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
65
  none: false
97
- requirements:
98
- - - ">"
99
- - !ruby/object:Gem::Version
100
- segments:
101
- - 1
102
- - 3
103
- - 1
66
+ requirements:
67
+ - - ! '>'
68
+ - !ruby/object:Gem::Version
104
69
  version: 1.3.1
105
70
  requirements: []
106
-
107
71
  rubyforge_project: ocra
108
- rubygems_version: 1.3.7
72
+ rubygems_version: 1.8.4
109
73
  signing_key:
110
74
  specification_version: 3
111
- summary: OCRA (One-Click Ruby Application) builds Windows executables from Ruby
112
75
  source code
113
- test_files:
76
+ summary: ! "OCRA (One-Click Ruby Application) builds Windows executables from Ruby\r
77
+ source code"
78
+ test_files:
114
79
  - test/test_ocra.rb