Class: Releasy::WindowsWrapperMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/releasy/windows_wrapper_maker.rb

Overview

Creates wrappers and executables by wrapping Ocra’s functionality.

Instance Method Summary collapse

Instance Method Details

#build_executable(executable_file, ruby_file, options = {}) ⇒ Object

Creates an win32 executable file (xxx.exe) that runs via a Ruby executable at bin/ruby(w).exe Paths given to the executable are relative to the directory that the executable is in. Assumes that user’s source will be put into ./src/ and that ruby executables will be in ./bin/

Parameters:

  • executable_file (String)

    File to create, which should be a .exe file.

  • ruby_file (String)

    Path of script to run with the executable.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :rubyopt (String)

    RUBYOPT environment variable - Options to pass to Ruby (”)

  • :rubylib (String)

    RUBYLIB environment variable - Paths, relative to ./src/, to add to $LOAD_PATH (”).

  • :gem_path (String)

    GEM_PATH environment variable - Path, relative to ./, to load gems from (‘vendor’).

  • :windows (Boolean)

    True for an application that uses windows, false for a console application (false)

  • :icon (String)

    Path to Windows icon file (.ico) that the executable should use (nil).



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/releasy/windows_wrapper_maker.rb', line 18

def build_executable(executable_file, ruby_file, options = {})
  options = {
      :rubyopt => '',
      :rubylib => '',
      :gem_path => 'vendor',
      :windows => false,
      :icon => nil,
  }.merge! options

  load_ocra unless defined? Ocra::OcraBuilder
  set_ocra_options options[:icon]

  Ocra::OcraBuilder.new(executable_file, options[:windows]) do |sb|
    root = Ocra.Pathname Ocra::TEMPDIR_ROOT

    sb.setenv('RUBYOPT', options[:rubyopt])
    sb.setenv('RUBYLIB', options[:rubylib])
    sb.setenv('GEM_PATH', (root / options[:gem_path]).to_native)
    sb.setenv('BUNDLE_GEMFILE', '')
    sb.setenv('BUNDLE_BIN_PATH', '')

    ruby_executable = options[:windows] ? "rubyw.exe" : "ruby.exe"
    exe = root / 'bin' / ruby_executable
    script = (root / ruby_file).to_native

    sb.postcreateprocess(exe, "#{ruby_executable} \"#{script}\"")
  end

  nil
end