Class: Bubing::ExecutableBundler

Inherits:
Bundler
  • Object
show all
Defined in:
lib/bubing/executable_bundler.rb

Constant Summary collapse

RUN_TEMPLATE =
'%{envs} ./lib/%{interpreter} ./bin/%{binary} "$@"'

Constants inherited from Bundler

Bundler::PATH_RE

Instance Method Summary collapse

Constructor Details

#initialize(binary, directory, **options) ⇒ ExecutableBundler

Returns a new instance of ExecutableBundler.



5
6
7
8
9
10
11
12
13
14
# File 'lib/bubing/executable_bundler.rb', line 5

def initialize(binary, directory, **options)
  super
  @bin_dir = File.join(@directory, 'bin')
  @run_script = options[:run_script] || 'run.sh'

  @envs = options[:envs] || {}
  if @envs['LD_LIBRARY_PATH'].nil?
    @envs['LD_LIBRARY_PATH'] = './lib'
  end
end

Instance Method Details

#bundle!Object



16
17
18
19
20
21
22
23
24
# File 'lib/bubing/executable_bundler.rb', line 16

def bundle!
  super
  copy(@interpreter, @lib_dir)
  copy(@binary, @bin_dir)
  log("Preparing #{@run_script}...")
  run_file = make_run

  FileUtils.chmod('+x', run_file)
end

#make_runObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bubing/executable_bundler.rb', line 26

def make_run
  File.join(@directory, @run_script).tap do |run_file|
    envs = @envs.each_with_object([]) do |(k, v), ary|
      ary << "#{k}=#{v}"
    end.join(' ')
    run = RUN_TEMPLATE % {envs: envs, interpreter: File.basename(@interpreter), binary: File.basename(@binary)}
    File.open(run_file, 'w') do |file|
      file.write("#!/bin/bash\n")
      file.write("#{run}\n")
    end
  end
end