Class: RubyInstaller::Build::Components::Base

Inherits:
Rake::Task
  • Object
show all
Includes:
RubyInstaller::Build::Colors
Defined in:
lib/ruby_installer/build/components/base.rb

Direct Known Subclasses

DevTools, Msys2, PacmanUpdate

Constant Summary

Constants included from RubyInstaller::Build::Colors

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RubyInstaller::Build::Colors

colored, disable_colors, enable_colors, initialize

Constructor Details

#initialize(*_, **_) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
# File 'lib/ruby_installer/build/components/base.rb', line 16

def initialize(*_, **_)
  @msys = nil
  enable_colors
  super
end

Instance Attribute Details

#builtin_packages_dirObject

Returns the value of attribute builtin_packages_dir.



10
11
12
# File 'lib/ruby_installer/build/components/base.rb', line 10

def builtin_packages_dir
  @builtin_packages_dir
end

#msysObject



22
23
24
# File 'lib/ruby_installer/build/components/base.rb', line 22

def msys
  @msys ||= BuildOrRuntime.msys2_installation
end

#pacman_argsObject

Returns the value of attribute pacman_args.



9
10
11
# File 'lib/ruby_installer/build/components/base.rb', line 9

def pacman_args
  @pacman_args
end

#task_indexObject

Returns the value of attribute task_index.



7
8
9
# File 'lib/ruby_installer/build/components/base.rb', line 7

def task_index
  @task_index
end

Class Method Details

.dependsObject



12
13
14
# File 'lib/ruby_installer/build/components/base.rb', line 12

def self.depends
  []
end

Instance Method Details

#autorebaseObject



110
111
112
113
114
# File 'lib/ruby_installer/build/components/base.rb', line 110

def autorebase
  if msys.mingwarch == "mingw32"
    run_verbose(File.join(msys.msys_path, "autorebase.bat"))
  end
end

#check_hash(path, hash) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ruby_installer/build/components/base.rb', line 86

def check_hash(path, hash)
  if !File.exist?(path)
    false
  elsif hash.nil?
    true
  else
    require "digest"

    print "Verify integrity of #{File.basename(path)} ..."
    res = Digest::SHA256.file(path).hexdigest == hash.downcase
    puts(res ? green(" OK") : red(" Failed"))
    res
  end
end

#download(uri, hash = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ruby_installer/build/components/base.rb', line 57

def download(uri, hash=nil)
  require "open-uri"

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

  until check_hash(temp_path, 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
  temp_path
end

#kill_all_msys2_processesObject



101
102
103
104
105
106
107
108
# File 'lib/ruby_installer/build/components/base.rb', line 101

def kill_all_msys2_processes
  puts 'Kill all running msys2 binaries to avoid error "size of shared memory region changed"'
  # See https://github.com/msys2/MSYS2-packages/issues/258
  OsProcess.each_process_with_dll("msys-2.0.dll") do |pr|
    puts yellow(" - killing process #{pr.pid}: #{pr.each_module.first[1]}")
    Process.kill(9, pr.pid)
  end
end

#puts(*args) ⇒ Object



53
54
55
# File 'lib/ruby_installer/build/components/base.rb', line 53

def puts(*args)
  $stderr.puts *args
end

#run_verbose(*args) ⇒ Object



48
49
50
51
# File 'lib/ruby_installer/build/components/base.rb', line 48

def run_verbose(*args)
  puts "> #{ cyan(shell_join(args)) }"
  system(*args)
end

#shell_escape(str) ⇒ Object

This is extracted from github.com/larskanis/shellwords



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_installer/build/components/base.rb', line 27

def shell_escape(str)
  str = str.to_s

  # An empty argument will be skipped, so return empty quotes.
  return '""' if str.empty?

  str = str.dup

  str.gsub!(/((?:\\)*)"/){ "\\" * ($1.length*2) + "\\\"" }
  if str =~ /\s/
    str.gsub!(/(\\+)\z/){ "\\" * ($1.length*2) }
    str = "\"#{str}\""
  end

  return str
end

#shell_join(array) ⇒ Object



44
45
46
# File 'lib/ruby_installer/build/components/base.rb', line 44

def shell_join(array)
  array.map { |arg| shell_escape(arg) }.join(' ')
end