ocra 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,27 @@
1
+ === 1.1.2
2
+
3
+ * Warnings can be disabled using --no-warnings.
4
+
5
+ * Fixed not .exe being generated when script calls 'exit'.
6
+
7
+ * Path to the generated executable is now avilable to the running
8
+ script in the OCRA_EXECUTABLE environment variable.
9
+
10
+ * Directories on the command line will now be created.
11
+
12
+ * Supports path globs, fx. "ocra script.rb assets/**/*.png". (See
13
+ documentation for Ruby's Dir class).
14
+
15
+ * Fixed issue with spaces in temporary path (TMP environment).
16
+
17
+ * Improved path comparison to ignore case (this is Windows after all)
18
+ and be a bit more robust.
19
+
20
+ * Added support for RubyGems installed in GEM_HOME (or other part
21
+ handled by RubyGems). If not installed in the Ruby hierarchy, they
22
+ will now be installed in a directory named 'gemhome' under the
23
+ temporary directory.
24
+
1
25
  === 1.1.1
2
26
 
3
27
  * Fixed duplicate entries in the RUBYLIB environment variable.
@@ -2,7 +2,7 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- bin/ocra.rb
5
+ bin/ocra
6
6
  share/ocra/lzma.exe
7
7
  share/ocra/stub.exe
8
8
  share/ocra/stubw.exe
data/README.txt CHANGED
@@ -18,7 +18,7 @@ any additionally needed ruby libraries or DLL.
18
18
  * Both console programs and desktop programs supported (no console will
19
19
  pop up with .rbw files).
20
20
 
21
- If you experience problems with Ocra or have found a bug, please use
21
+ If you experience problems with OCRA or have found a bug, please use
22
22
  the tracker on the RubyForge project page
23
23
  http://rubyforge.org/projects/ocra/. You are welcome to ask questions
24
24
  in the forums there aswell.
@@ -29,7 +29,7 @@ in the forums there aswell.
29
29
 
30
30
  == SYNOPSIS:
31
31
 
32
- ocra.rb [option] your/script.rb
32
+ ocra [option] your/script.rb
33
33
 
34
34
  * OCRA will load your script (using Kernel#load) and build the
35
35
  executable when it exits.
@@ -37,10 +37,10 @@ ocra.rb [option] your/script.rb
37
37
  * Your program should 'require' all necessary files when invoked without
38
38
  arguments, so ocra can detect all dependencies.
39
39
 
40
- * Ocra executables clear the RUBYLIB environment variable but set
41
- RUBYOPT to whatever value it had when you invoked Ocra.
40
+ * OCRA executables clear the RUBYLIB environment variable but set
41
+ RUBYOPT to whatever value it had when you invoked OCRA.
42
42
 
43
- * Ocra does not set up the include path. Use "$:.unshift
43
+ * OCRA does not set up the include path. Use "$:.unshift
44
44
  File.dirname(__FILE__)" at the start of your script if you need to
45
45
  'require' additional source files in the same directory no matter
46
46
  what the user's current working directory is.
@@ -50,6 +50,12 @@ ocra.rb [option] your/script.rb
50
50
  disabled using --no-autodll. DLLs can be manually added using the
51
51
  --dll option.
52
52
 
53
+ * The current working directory is left untouched by OCRA (Details
54
+ below).
55
+
56
+ * When the script is running, the OCRA_EXECUTABLE environment variable
57
+ points to the .exe (with full path).
58
+
53
59
  == REQUIREMENTS:
54
60
 
55
61
  * Windows
@@ -71,16 +77,16 @@ nothing but a working Ruby installation on Windows.
71
77
 
72
78
  == TECHNICAL DETAILS
73
79
 
74
- The Ocra stub extracts the Ruby interpreter and your scripts into a
80
+ The OCRA stub extracts the Ruby interpreter and your scripts into a
75
81
  temporary directory. The directory will contains the same directory
76
82
  layout as your Ruby installlation. The source files for your
77
83
  application will be put in the 'src' subdirectory.
78
84
 
79
85
  === Libraries
80
86
 
81
- Rubygems will be automatically included in the Ocra executable.
87
+ Rubygems will be automatically included in the OCRA executable.
82
88
 
83
- Libraries found in non-standard path (for example, if you invoke Ocra
89
+ Libraries found in non-standard path (for example, if you invoke OCRA
84
90
  with "ruby -I some/path") will be placed into the site dir
85
91
  (lib/ruby/site_ruby). Avoid changing $LOAD_PATH / $: from your script
86
92
  to include paths outside your source tree.
@@ -91,15 +97,18 @@ will be logged).
91
97
 
92
98
  === Environment variables
93
99
 
94
- Ocra executables clear the RUBYLIB environment variable before your
100
+ OCRA executables clear the RUBYLIB environment variable before your
95
101
  script is launched. This is done to ensure that your script does not
96
102
  use load paths from the end user's Ruby installation.
97
103
 
98
- Ocra executables set the RUBYOPT environment variable to the value it
99
- had when you invoked Ocra. For example, if you had "RUBYOPT=rubygems"
100
- on your build PC, Ocra ensures that it is also set on PC's running the
104
+ OCRA executables set the RUBYOPT environment variable to the value it
105
+ had when you invoked OCRA. For example, if you had "RUBYOPT=rubygems"
106
+ on your build PC, OCRA ensures that it is also set on PC's running the
101
107
  executables.
102
108
 
109
+ OCRA executables set OCRA_EXECUTABLE to the full path of the
110
+ executable, fx. "C:\Program Files\MyApp\MyApp.exe".
111
+
103
112
  === Working directory
104
113
 
105
114
  You should not assume that the current working directory when invoking
@@ -130,19 +139,19 @@ source script you can use this idiom:
130
139
 
131
140
  === Detecting OCRA
132
141
 
133
- You can detect whether Ocra is currently building your script by
134
- looking for the 'Ocra' constant. If it is defined, Ocra is currenly
142
+ You can detect whether OCRA is currently building your script by
143
+ looking for the 'OCRA' constant. If it is defined, OCRA is currenly
135
144
  building the executable from your script. For example, you can use
136
145
  this to avoid opening a GUI window when compiling executables:
137
146
 
138
147
  app = MyApp.new
139
- if not defined?(Ocra)
148
+ if not defined?(OCRA)
140
149
  app.main_loop
141
150
  end
142
151
 
143
152
  === Additional files and resources
144
153
 
145
- You can add additional files to the Ocra executable (for example
154
+ You can add additional files to the OCRA executable (for example
146
155
  images) by appending them to the command line. They should be placed
147
156
  in the source directory with your main script (or a subdirectory).
148
157
 
@@ -155,6 +164,9 @@ your program is executed:
155
164
  src/someimage.jpeg
156
165
  src/docs/document.txt
157
166
 
167
+ Paths on the command line can include ** globs to include a hierachy
168
+ of files, for example: "ocra script.rb assets/**/*.png".
169
+
158
170
  == CREDITS:
159
171
 
160
172
  Thanks for Igor Pavlov for the LZMA compressor and decompressor. The
data/Rakefile CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
- require 'bin/ocra'
6
5
 
7
- Hoe.new('ocra', Ocra::VERSION) do |p|
8
- p.developer('Lars Christensen', 'larsch@belunktum.dk')
6
+ Hoe.spec 'ocra' do
7
+ developer "Lars Christensen", "larsch@belunktum.dk"
9
8
  end
10
9
 
11
10
  task :build_stub do
@@ -17,7 +16,7 @@ end
17
16
 
18
17
  file 'share/ocra/stub.exe' => :build_stub
19
18
 
20
- task :test => :stub
19
+ task :test => :build_stub
21
20
 
22
21
  task :standalone => [ 'bin/ocrasa.rb' ]
23
22
 
@@ -33,8 +32,8 @@ task :release_standalone => standalone_zip do
33
32
  sh "rubyforge add_release ocra ocra-standalone #{Ocra::VERSION} #{standalone_zip}"
34
33
  end
35
34
 
36
- file 'bin/ocrasa.rb' => [ 'bin/ocra.rb', 'share/ocra/stub.exe', 'share/ocra/stubw.exe', 'share/ocra/lzma.exe', 'share/ocra/edicon.exe' ] do
37
- cp 'bin/ocra.rb', 'bin/ocrasa.rb'
35
+ file 'bin/ocrasa.rb' => [ 'bin/ocra', 'share/ocra/stub.exe', 'share/ocra/stubw.exe', 'share/ocra/lzma.exe', 'share/ocra/edicon.exe' ] do
36
+ cp 'bin/ocra', 'bin/ocrasa.rb'
38
37
  File.open("bin/ocrasa.rb", "a") do |f|
39
38
  f.puts "__END__"
40
39
 
@@ -75,8 +74,9 @@ task :test_standalone => :standalone do
75
74
  end
76
75
 
77
76
  def each_ruby_version
78
- root = "h:/appl"
79
- Dir.glob(File.join(root, 'ruby-*','bin')).each do |path|
77
+ raise "Set RUBIES to point to where you have various versions of Ruby installed" if ENV['RUBIES'].nil?
78
+ root = ENV['RUBIES']
79
+ Dir.glob(File.join(root, 'ruby*','bin')).each do |path|
80
80
  path.tr!('/','\\')
81
81
  pathenv = ENV['PATH']
82
82
  ENV['PATH'] = path
@@ -10,10 +10,12 @@ module Ocra
10
10
  OP_DECOMPRESS_LZMA = 4
11
11
  OP_SETENV = 5
12
12
 
13
- VERSION = "1.1.1"
13
+ VERSION = "1.1.2"
14
14
 
15
15
  IGNORE_MODULES = /^enumerator.so$/
16
16
 
17
+ PATH_SEPARATOR = /[\/\\]/
18
+
17
19
  class << self
18
20
  attr_accessor :lzma_mode
19
21
  attr_accessor :extra_dlls
@@ -24,6 +26,7 @@ module Ocra
24
26
  attr_accessor :icon_filename
25
27
  attr_accessor :quiet
26
28
  attr_accessor :autodll
29
+ attr_accessor :show_warnings
27
30
  attr_reader :lzmapath
28
31
  attr_reader :ediconpath
29
32
  attr_reader :stubimage
@@ -65,6 +68,7 @@ module Ocra
65
68
  icon_filename = nil
66
69
  quiet = false
67
70
  autodll = true
71
+ show_warnings = true
68
72
 
69
73
  usage = <<EOF
70
74
  ocra [options] script.rb
@@ -102,6 +106,8 @@ EOF
102
106
  when /\A--version\z/
103
107
  puts "Ocra #{VERSION}"
104
108
  exit
109
+ when /\A--no-warnings\z/
110
+ show_warnings = false
105
111
  when /\A--help\z/, /\A--/
106
112
  puts usage
107
113
  exit
@@ -124,6 +130,7 @@ EOF
124
130
  @icon_filename = icon_filename
125
131
  @autodll = autodll
126
132
  @files = files
133
+ @show_warnings = show_warnings
127
134
  end
128
135
 
129
136
  def Ocra.init(argv)
@@ -149,7 +156,7 @@ EOF
149
156
  begin
150
157
  mod.const_get(const)
151
158
  rescue LoadError
152
- puts "=== WARNING: #{mod}::#{const} was not loadable"
159
+ puts "=== WARNING: #{mod}::#{const} was not loadable" if Ocra.show_warnings
153
160
  end
154
161
  end
155
162
  end
@@ -169,6 +176,14 @@ EOF
169
176
  return b.join('/')
170
177
  end
171
178
 
179
+ # Determines if 'src' is contained in 'tgt' (i.e. it is a subpath of
180
+ # 'tgt'). Both must be absolute paths and not contain '..'
181
+ def Ocra.subpath?(src, tgt)
182
+ src_normalized = src.tr('/','\\')
183
+ tgt_normalized = tgt.tr('/','\\')
184
+ src_normalized =~ /^#{Regexp.escape tgt_normalized}[\/\\]/i
185
+ end
186
+
172
187
  def Ocra.find_load_path(paths, path)
173
188
  if path[1,1] == ":"
174
189
  rps = paths.map {|p| relative_path(File.expand_path(p), path) }
@@ -216,22 +231,25 @@ EOF
216
231
  filename = relative_path(File.expand_path(path), filename)
217
232
  end
218
233
  if filename =~ /^\.\.\//
219
- puts "=== WARNING: Detected a relative require (#{filename}). This is not recommended."
234
+ puts "=== WARNING: Detected a relative require (#{filename}). This is not recommended." if Ocra.show_warnings
220
235
  end
221
236
  fullpath = File.expand_path(filename, path)
222
- if fullpath.index(exec_prefix) == 0
237
+ if subpath?(fullpath, exec_prefix)
223
238
  libs << [ fullpath, fullpath[exec_prefix.size+1..-1] ]
224
- elsif fullpath.index(src_prefix) == 0
239
+ elsif subpath?(fullpath, src_prefix)
225
240
  targetpath = "src/" + fullpath[src_prefix.size+1..-1]
226
241
  libs << [ fullpath, targetpath ]
227
242
  if not @added_load_paths.include?(path) and not load_path.include?(path)
228
243
  load_path << File.join("\xFF", File.dirname(targetpath))
229
244
  end
245
+ elsif defined?(Gem) and gemhome = Gem.path.find { |pth| subpath?(fullpath, pth) }
246
+ targetpath = File.join("gemhome", relative_path(gemhome, fullpath))
247
+ libs << [ fullpath, targetpath ]
230
248
  else
231
249
  libs << [ fullpath, File.join(instsitelibdir, filename) ]
232
250
  end
233
251
  else
234
- puts "=== WARNING: Couldn't find #{filename}" unless filename =~ IGNORE_MODULES
252
+ puts "=== WARNING: Couldn't find #{filename}" unless filename =~ IGNORE_MODULES if Ocra.show_warnings
235
253
  end
236
254
  end
237
255
 
@@ -246,8 +264,12 @@ EOF
246
264
  OcraBuilder.new(executable, windowed) do |sb|
247
265
  # Add explicitly mentioned files
248
266
  Ocra.files.each do |file|
249
- path = File.join('src', file).tr('/','\\')
250
- sb.createfile(file, path)
267
+ if File.directory?(file)
268
+ sb.ensuremkdir(File.join('src',file).tr('/','\\'))
269
+ else
270
+ path = File.join('src', file).tr('/','\\')
271
+ sb.createfile(file, path)
272
+ end
251
273
  end
252
274
 
253
275
  # Add the ruby executable and DLL
@@ -263,7 +285,7 @@ EOF
263
285
 
264
286
  # Add detected DLLs
265
287
  dlls.each do |dll|
266
- if dll.tr('\\','/').index(exec_prefix) == 0
288
+ if subpath?(dll.tr('\\','/'), exec_prefix)
267
289
  target = dll[exec_prefix.size+1..-1]
268
290
  else
269
291
  target = File.join('bin', File.basename(dll))
@@ -277,14 +299,17 @@ EOF
277
299
  end
278
300
 
279
301
  # Add gemspecs
280
- gemspecs.each { |gemspec|
281
- pref = gemspec[0,exec_prefix.size]
282
- path = gemspec[exec_prefix.size+1..-1]
283
- if pref != exec_prefix
302
+ gemspecs.each do |gemspec|
303
+ if subpath?(gemspec, exec_prefix)
304
+ path = gemspec[exec_prefix.size+1..-1]
305
+ sb.createfile(gemspec, path.tr('/','\\'))
306
+ elsif defined?(Gem) and gemhome = Gem.path.find { |pth| subpath?(gemspec, pth) }
307
+ path = File.join('gemhome', relative_path(gemhome, gemspec))
308
+ sb.createfile(gemspec, path.tr('/','\\'))
309
+ else
284
310
  raise "#{gemspec} does not exist in the Ruby installation. Don't know where to put it."
285
311
  end
286
- sb.createfile(gemspec, path.tr('/','\\'))
287
- }
312
+ end
288
313
 
289
314
  # Add loaded libraries
290
315
  libs.each do |path, target|
@@ -294,9 +319,10 @@ EOF
294
319
  # Set environment variable
295
320
  sb.setenv('RUBYOPT', ENV['RUBYOPT'] || '')
296
321
  sb.setenv('RUBYLIB', load_path.uniq.join(';'))
322
+ sb.setenv('GEM_HOME', "\xFF\\gemhome")
297
323
 
298
324
  # Launch the script
299
- sb.createprocess("bin\\" + rubyexe, "#{rubyexe} \xff\\src\\" + Ocra.files[0])
325
+ sb.createprocess("bin\\" + rubyexe, "#{rubyexe} \"\xff\\src\\" + Ocra.files[0] + "\"")
300
326
 
301
327
  puts "=== Compressing" unless Ocra.quiet or not Ocra.lzma_mode
302
328
  end
@@ -342,8 +368,8 @@ EOF
342
368
  loaded = loaded_dlls
343
369
  exec_prefix = RbConfig::CONFIG['exec_prefix']
344
370
  loaded.select do |path|
345
- path.tr('\\','/').index(exec_prefix) == 0 and
346
- File.basename(path) =~ /\.dll$/ and
371
+ Ocra.subpath?(path.tr('\\','/'), exec_prefix) and
372
+ File.basename(path) =~ /\.dll$/i and
347
373
  File.basename(path).downcase != RbConfig::CONFIG['LIBRUBY_SO'].downcase
348
374
  end
349
375
  end
@@ -435,7 +461,7 @@ if File.basename(__FILE__) == File.basename($0)
435
461
  ARGV.clear
436
462
 
437
463
  at_exit do
438
- if $!.nil?
464
+ if $!.nil? or $!.kind_of?(SystemExit)
439
465
  Ocra.build_exe
440
466
  exit(0)
441
467
  end
Binary file
Binary file
Binary file
@@ -21,7 +21,7 @@ class TestOcra < Test::Unit::TestCase
21
21
  DefaultArgs.push '--no-autodll' if not $have_win32_api
22
22
 
23
23
  # Name of the tested ocra script.
24
- TESTED_OCRA = ENV['TESTED_OCRA'] || 'ocra.rb'
24
+ TESTED_OCRA = ENV['TESTED_OCRA'] || 'ocra'
25
25
 
26
26
  # Root of OCRA.
27
27
  OcraRoot = File.expand_path(File.join(File.dirname(__FILE__), '..'))
@@ -70,6 +70,26 @@ class TestOcra < Test::Unit::TestCase
70
70
  end
71
71
  end
72
72
  end
73
+
74
+ def with_tmpdir
75
+ tempdirname = File.join(ENV['TEMP'], ".ocratest-#{$$}-#{rand 2**32}").tr('\\','/')
76
+ Dir.mkdir tempdirname
77
+ begin
78
+ FileUtils.cd tempdirname do
79
+ yield
80
+ end
81
+ ensure
82
+ FileUtils.rm_rf tempdirname
83
+ end
84
+ end
85
+
86
+ def with_exe(name)
87
+ orig_exe = File.expand_path(name)
88
+ with_tmpdir do
89
+ cp orig_exe, File.join('.', File.basename(name))
90
+ yield
91
+ end
92
+ end
73
93
 
74
94
  # Test setup method. Creates a tempory directory to work in and
75
95
  # changes to it.
@@ -337,4 +357,44 @@ class TestOcra < Test::Unit::TestCase
337
357
  end
338
358
  end
339
359
  end
360
+
361
+ def test_exit
362
+ with_fixture 'exit' do
363
+ assert system("ruby", ocra, "exit.rb", *DefaultArgs)
364
+ assert File.exist?("exit.exe")
365
+ assert system("exit.exe")
366
+ end
367
+ end
368
+
369
+ def test_ocra_executable_env
370
+ with_fixture 'environment' do
371
+ assert system("ruby", ocra, "environment.rb", *DefaultArgs)
372
+ assert system("environment.exe")
373
+ env = Marshal.load(File.open("environment", "rb") { |f| f.read })
374
+ expected_path = File.expand_path("environment.exe").tr('/','\\')
375
+ assert_equal expected_path, env['OCRA_EXECUTABLE']
376
+ end
377
+ end
378
+
379
+ def test_hierarchy
380
+ with_fixture 'hierarchy' do
381
+ assert system("ruby", ocra, "hierarchy.rb", "assets/**/*", *DefaultArgs)
382
+ with_exe "hierarchy.exe" do
383
+ assert system("hierarchy.exe")
384
+ end
385
+ end
386
+ end
387
+
388
+ def test_temp_with_space
389
+ with_fixture 'helloworld' do
390
+ assert system("ruby", ocra, "helloworld.rb", *DefaultArgs)
391
+ tempdir = File.expand_path("temporary directory")
392
+ mkdir_p tempdir
393
+ with_exe "helloworld.exe" do
394
+ with_env "TMP" => tempdir.tr('/','\\') do
395
+ assert system("helloworld.exe")
396
+ end
397
+ end
398
+ end
399
+ end
340
400
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Christensen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-01 00:00:00 +02:00
12
+ date: 2009-08-10 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.12.2
23
+ version: 2.3.1
24
24
  version:
25
25
  description: |-
26
26
  OCRA (One-Click Ruby Application) builds Windows executables from Ruby
@@ -30,7 +30,7 @@ description: |-
30
30
  email:
31
31
  - larsch@belunktum.dk
32
32
  executables:
33
- - ocra.rb
33
+ - ocra
34
34
  extensions: []
35
35
 
36
36
  extra_rdoc_files:
@@ -42,7 +42,7 @@ files:
42
42
  - Manifest.txt
43
43
  - README.txt
44
44
  - Rakefile
45
- - bin/ocra.rb
45
+ - bin/ocra
46
46
  - share/ocra/lzma.exe
47
47
  - share/ocra/stub.exe
48
48
  - share/ocra/stubw.exe