123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Rake::Task
Instance Chain:
self, ::RubyInstaller::Build::Colors, Rake::Task
Inherits: Rake::Task
  • Object
Defined in: lib/ruby_installer/build/components/base.rb

Constant Summary

::RubyInstaller::Build::Colors - Included

ColorMap, ESC, NND

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(*_, **_) ⇒ Base

[ GitHub ]

  
# File 'lib/ruby_installer/build/components/base.rb', line 16

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

Class Method Details

.depends

[ GitHub ]

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

def self.depends
  []
end

Instance Attribute Details

#builtin_packages_dir (rw)

[ GitHub ]

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

attr_accessor :builtin_packages_dir

#msys (rw)

[ GitHub ]

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

def msys
  @msys ||= BuildOrRuntime.msys2_installation
end

#msys=(value) (rw)

[ GitHub ]

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

attr_writer :msys

#pacman_args (rw)

[ GitHub ]

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

attr_accessor :pacman_args

#task_index (rw)

[ GitHub ]

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

attr_accessor :task_index

Instance Method Details

#autorebase

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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_processes

[ GitHub ]

  
# 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)

[ GitHub ]

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

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

#run_verbose(*args)

[ GitHub ]

  
# 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)

This is extracted from github.com/larskanis/shellwords

[ GitHub ]

  
# 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)

[ GitHub ]

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

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