Class: RubyInstaller::Build::Components::Msys2

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_installer/build/components/01_msys2.rb

Constant Summary

Constants included from RubyInstaller::Build::Colors

RubyInstaller::Build::Colors::ColorMap, RubyInstaller::Build::Colors::ESC, RubyInstaller::Build::Colors::NND

Instance Attribute Summary

Attributes inherited from Base

#msys, #pacman_args, #task_index

Instance Method Summary collapse

Methods inherited from Base

depends, #initialize, #puts, #run_verbose, #shell_escape, #shell_join

Methods included from RubyInstaller::Build::Colors

#colored, #disable_colors, #enable_colors

Constructor Details

This class inherits a constructor from RubyInstaller::Build::Components::Base

Instance Method Details

#descriptionObject



5
6
7
# File 'lib/ruby_installer/build/components/01_msys2.rb', line 5

def description
  "MSYS2 base installation"
end

#execute(args) ⇒ Object



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
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ruby_installer/build/components/01_msys2.rb', line 23

def execute(args)
  require "open-uri"

  uri = msys2_download_uri
  filename = File.basename(uri)
  temp_path = File.join(ENV["TMP"] || ENV["TEMP"] || ENV["USERPROFILE"] || "C:/", filename)

  until check_hash(temp_path, msys2_download_hash)
    puts "Download #{yellow(uri)}\n  to #{yellow(temp_path)}"
    File.open(temp_path, "wb") do |fd|
      progress = 0
      total = 0
      params = {
        "Accept-Encoding" => 'identity',
        :content_length_proc => lambda{|length| total = length },
        :progress_proc => lambda{|bytes|
          new_progress = (bytes * 100) / total
          print "\rDownloading %s (%3d%%) " % [filename, new_progress]
          progress = new_progress
        }
      }
      OpenURI.open_uri(uri, params) do |io|
        fd << io.read
      end
      puts
    end
  end

  puts "Run the MSYS2 installer ..."
  if run_verbose(temp_path) && msys.with_msys_apps_enabled { run_verbose("sh", "-lc", "true") }
    puts green(" Success")
  else
    puts red(" Failed")
    raise "MSYS2 installer failed"
  end
end

#needed?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby_installer/build/components/01_msys2.rb', line 9

def needed?
  begin
    if msys.with_msys_apps_enabled(if_no_msys: :raise) { run_verbose("sh", "-lc", "true") }
      puts "MSYS2 seems to be " + green("properly installed")
      false
    else
      true
    end
  rescue Msys2Installation::MsysNotFound
    puts "MSYS2 seems to be " + red("unavailable")
    true
  end
end