Class: Zui::FullRuntime

Inherits:
Object
  • Object
show all
Defined in:
lib/zui/full_runtime.rb

Constant Summary collapse

SYSTEM_LIBRARIES =
/\A(?:ld-linux|libc\.|libdl\.|libgcc_s\.|libm\.|libpthread\.|librt\.|libSystem\.|libutil\.)/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform: Platform.current, ruby: RbConfig.ruby, environment: ENV, rbconfig: RbConfig::CONFIG, spec_loader: nil) ⇒ FullRuntime

Returns a new instance of FullRuntime.



15
16
17
18
19
20
21
22
# File 'lib/zui/full_runtime.rb', line 15

def initialize(platform: Platform.current, ruby: RbConfig.ruby, environment: ENV,
               rbconfig: RbConfig::CONFIG, spec_loader: nil)
  @platform = platform.assert_supported!
  @ruby = File.expand_path(ruby)
  @environment = environment.to_h
  @rbconfig = rbconfig.to_h
  @spec_loader = spec_loader || method(:project_specs)
end

Instance Attribute Details

#platformObject (readonly)

Returns the value of attribute platform.



13
14
15
# File 'lib/zui/full_runtime.rb', line 13

def platform
  @platform
end

Instance Method Details

#install(project:, destination:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zui/full_runtime.rb', line 24

def install(project:, destination:)
  project = File.expand_path(project)
  destination = File.expand_path(destination)
  raise ArgumentError, "Ruby executable not found: #{@ruby}" unless File.file?(@ruby)
  raise ArgumentError, "full runtime destination already exists: #{destination}" if File.exist?(destination)

  FileUtils.mkdir_p(destination)
  executable = install_executable(destination)
  library_paths = install_standard_library(destination)
  install_runtime_libraries(destination)
  install_native_dependencies(destination)
  gems = install_project_gems(project, destination)
  environment = {
    "RUBYLIB" => library_paths,
    "GEM_HOME" => ["gems"],
    "GEM_PATH" => ["gems"]
  }
  dynamic_library_variable = platform.macos? ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"
  environment[dynamic_library_variable] = ["lib"] unless platform.windows?

  ApplicationRuntime.new(
    engine: "cruby",
    version: ruby_version,
    executable:,
    environment:,
    gems: gems.map(&:full_name)
  ).write(destination)
rescue StandardError
  FileUtils.remove_entry(destination) if destination && File.exist?(destination)
  raise
end