rubyinstaller-build 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE.md +8 -0
- data/.gitignore +12 -0
- data/.yardopts +7 -0
- data/CHANGELOG-2.4.md +166 -0
- data/CHANGELOG-2.5.md +87 -0
- data/CHANGELOG-2.6.md +62 -0
- data/CHANGELOG-2.7.md +22 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +25 -0
- data/README.md +114 -0
- data/Rakefile +164 -0
- data/appveyor-key.asc.asc +61 -0
- data/appveyor.yml +141 -0
- data/docker/Dockerfile +50 -0
- data/docker/Rakefile +22 -0
- data/gems/rubyinstaller-build.yaml +2 -0
- data/lib/devkit.rb +3 -0
- data/lib/ruby_installer.rb +3 -0
- data/lib/ruby_installer/build.rb +23 -0
- data/lib/ruby_installer/build/ca_cert_file.rb +66 -0
- data/lib/ruby_installer/build/colors.rb +45 -0
- data/lib/ruby_installer/build/components/01_msys2.rb +97 -0
- data/lib/ruby_installer/build/components/02_pacman_update.rb +35 -0
- data/lib/ruby_installer/build/components/03_dev_tools.rb +68 -0
- data/lib/ruby_installer/build/components/base.rb +58 -0
- data/lib/ruby_installer/build/components_installer.rb +53 -0
- data/lib/ruby_installer/build/dll_directory.rb +97 -0
- data/lib/ruby_installer/build/erb_compiler.rb +61 -0
- data/lib/ruby_installer/build/gem_version.rb +5 -0
- data/lib/ruby_installer/build/gems.rb +74 -0
- data/lib/ruby_installer/build/msys2_installation.rb +280 -0
- data/lib/ruby_installer/build/openstruct.rb +29 -0
- data/lib/ruby_installer/build/release.rb +120 -0
- data/lib/ruby_installer/build/singleton.rb +45 -0
- data/lib/ruby_installer/build/task.rb +20 -0
- data/lib/ruby_installer/build/utils.rb +110 -0
- data/lib/ruby_installer/runtime.rb +18 -0
- data/lib/ruby_installer/runtime/ridk.rb +195 -0
- data/packages/ri-msys/Rakefile +72 -0
- data/packages/ri-msys/recipes/sandbox/70-add-msys2-installation.rake +18 -0
- data/packages/ri/Rakefile +60 -0
- data/recipes/archive-7z/10-define-variables.rake +2 -0
- data/recipes/archive-7z/70-create-archive.rake +10 -0
- data/recipes/archive-7z/90-define-main-task.rake +2 -0
- data/recipes/installer-inno/10-define-variables.rake +2 -0
- data/recipes/installer-inno/50-generate-filelist.rake +28 -0
- data/recipes/installer-inno/60-generate-iss-file.rake +8 -0
- data/recipes/installer-inno/70-run-iscc.rake +19 -0
- data/recipes/installer-inno/90-define-main-task.rake +2 -0
- data/recipes/installer-inno/events.iss +88 -0
- data/recipes/installer-inno/images/fake.bmp +0 -0
- data/recipes/installer-inno/images/wizard-large.bmp +0 -0
- data/recipes/installer-inno/images/wizard-logo.bmp +0 -0
- data/recipes/installer-inno/ri_gui.iss +286 -0
- data/recipes/installer-inno/rubyinstaller.iss.erb +157 -0
- data/recipes/installer-inno/util.iss +271 -0
- data/recipes/msys2/10-define-variables.rake +6 -0
- data/recipes/msys2/30-download-msys2-base.rake +4 -0
- data/recipes/msys2/40-extract-msys2-base.rake +9 -0
- data/recipes/msys2/50-init-msys.rake +8 -0
- data/recipes/msys2/50-install-components.rake +19 -0
- data/recipes/msys2/90-define-main-task.rake +2 -0
- data/recipes/sandbox/10-define-variables.rake +6 -0
- data/recipes/sandbox/20-add-runtime-files.rake +15 -0
- data/recipes/sandbox/20-define-import-files.rake +16 -0
- data/recipes/sandbox/20-define-import-readline.rake +28 -0
- data/recipes/sandbox/20-extend-irb.rake +13 -0
- data/recipes/sandbox/40-fix-rake-shebang.rake +6 -0
- data/recipes/sandbox/40-generate-rake-cmd.rake +7 -0
- data/recipes/sandbox/40-generate-version-file.rake +20 -0
- data/recipes/sandbox/50-do-import-files.rake +17 -0
- data/recipes/sandbox/50-gather-sandbox-files.rake +6 -0
- data/recipes/sandbox/60-define-gem-wrappers.rake +5 -0
- data/recipes/sandbox/60-side-by-side-assembly.rake +81 -0
- data/recipes/sandbox/70-add-gem-bin-wrappers.rake +10 -0
- data/recipes/sandbox/70-install-gems.rake +11 -0
- data/recipes/sandbox/80-copy-msys-files.rake +8 -0
- data/recipes/sandbox/90-define-main-task.rake +2 -0
- data/recipes/sandbox/LICENSE.txt +24 -0
- data/recipes/sandbox/rubyinstaller-2.3.4-x64.files +4 -0
- data/recipes/sandbox/rubyinstaller-2.3.4-x86.files +4 -0
- data/recipes/sandbox/rubyinstaller-2.3.4.files +43 -0
- data/recipes/sandbox/rubyinstaller-2.4.10-x64.files +4 -0
- data/recipes/sandbox/rubyinstaller-2.4.10-x86.files +4 -0
- data/recipes/sandbox/rubyinstaller-2.4.10.files +44 -0
- data/recipes/sandbox/rubyinstaller-2.5.8-x64.files +6 -0
- data/recipes/sandbox/rubyinstaller-2.5.8-x86.files +6 -0
- data/recipes/sandbox/rubyinstaller-2.5.8.files +33 -0
- data/recipes/sandbox/rubyinstaller-2.6.6-x64.files +6 -0
- data/recipes/sandbox/rubyinstaller-2.6.6-x86.files +6 -0
- data/recipes/sandbox/rubyinstaller-2.6.6.files +35 -0
- data/recipes/sandbox/rubyinstaller-2.7.1-x64.files +6 -0
- data/recipes/sandbox/rubyinstaller-2.7.1-x86.files +6 -0
- data/recipes/sandbox/rubyinstaller-2.7.1.files +35 -0
- data/recipes/sandbox/rubyinstaller-head-x64.files +6 -0
- data/recipes/sandbox/rubyinstaller-head-x86.files +6 -0
- data/recipes/sandbox/rubyinstaller-head.files +35 -0
- data/recipes/unpack/10-define-variables.rake +5 -0
- data/recipes/unpack/20-define-msys-packages.rake +1 -0
- data/recipes/unpack/30-add-ri2-repo-to-msys.rake +41 -0
- data/recipes/unpack/50-install-msys-packages.rake +28 -0
- data/recipes/unpack/90-define-main-task.rake +2 -0
- data/recipes/unpack/appveyor-repo-key.asc +29 -0
- data/resources/files/irbrc_predefiner.rb +21 -0
- data/resources/files/operating_system.rb +21 -0
- data/resources/files/readline.rb +17 -0
- data/resources/files/reline.rb +437 -0
- data/resources/files/reline/ansi.rb +177 -0
- data/resources/files/reline/config.rb +297 -0
- data/resources/files/reline/general_io.rb +75 -0
- data/resources/files/reline/history.rb +56 -0
- data/resources/files/reline/key_actor.rb +7 -0
- data/resources/files/reline/key_actor/base.rb +7 -0
- data/resources/files/reline/key_actor/emacs.rb +517 -0
- data/resources/files/reline/key_actor/vi_command.rb +518 -0
- data/resources/files/reline/key_actor/vi_insert.rb +517 -0
- data/resources/files/reline/key_stroke.rb +53 -0
- data/resources/files/reline/kill_ring.rb +113 -0
- data/resources/files/reline/line_editor.rb +2231 -0
- data/resources/files/reline/unicode.rb +527 -0
- data/resources/files/reline/unicode/east_asian_width.rb +1145 -0
- data/resources/files/reline/version.rb +3 -0
- data/resources/files/reline/windows.rb +273 -0
- data/resources/files/ridk.cmd +39 -0
- data/resources/files/ridk.ps1 +26 -0
- data/resources/files/ridk_use/ridk.cmd +13 -0
- data/resources/files/ridk_use/ridk.ps1 +17 -0
- data/resources/files/ridk_use/ridk_use.rb +221 -0
- data/resources/files/setrbvars.cmd +14 -0
- data/resources/icons/ruby-doc.ico +0 -0
- data/resources/ssl/README-SSL.md +37 -0
- data/resources/ssl/c_rehash.rb +167 -0
- data/resources/ssl/cacert.pem +4105 -0
- data/rubyinstaller-build.gemspec +28 -0
- metadata +226 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require "fiddle"
|
|
2
|
+
|
|
3
|
+
module RubyInstaller
|
|
4
|
+
module Build # Use for: Build, Runtime
|
|
5
|
+
# :nodoc:
|
|
6
|
+
class DllDirectory
|
|
7
|
+
class Error < RuntimeError
|
|
8
|
+
end
|
|
9
|
+
class WinApiError < Error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
KERNEL32 = Fiddle.dlopen('kernel32.dll')
|
|
13
|
+
begin
|
|
14
|
+
SetDefaultDllDirectories = Fiddle::Function.new(
|
|
15
|
+
KERNEL32['SetDefaultDllDirectories'], [Fiddle::TYPE_LONG], Fiddle::TYPE_INT
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
AddDllDirectory = Fiddle::Function.new(
|
|
19
|
+
KERNEL32['AddDllDirectory'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
RemoveDllDirectory = Fiddle::Function.new(
|
|
23
|
+
KERNEL32['RemoveDllDirectory'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT
|
|
24
|
+
)
|
|
25
|
+
rescue Fiddle::DLError
|
|
26
|
+
@@add_dll_dir_available = false
|
|
27
|
+
else
|
|
28
|
+
@@add_dll_dir_available = ENV['RI_FORCE_PATH_FOR_DLL'] == '1' ? false : true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
attr_reader :path
|
|
32
|
+
|
|
33
|
+
# Set default search paths to the application directory (where ruby.exe resides) and to paths that are added per DllDirectory.new().
|
|
34
|
+
# It disables the PATH environment variable for DLL search.
|
|
35
|
+
#
|
|
36
|
+
# This method is usually called while RubyInstaller startup.
|
|
37
|
+
def self.set_defaults
|
|
38
|
+
if @@add_dll_dir_available
|
|
39
|
+
set_default_dll_directories_winapi
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# See RubyInstaller::Build.add_dll_directory
|
|
44
|
+
def initialize(path)
|
|
45
|
+
path = File.expand_path(path)
|
|
46
|
+
|
|
47
|
+
if @@add_dll_dir_available
|
|
48
|
+
# Prefer Winapi function AddDllDirectory(), which requires Windows 7 with KB2533623 or newer.
|
|
49
|
+
self.class.set_default_dll_directories_winapi
|
|
50
|
+
@handle = self.class.add_dll_directory_winapi(path)
|
|
51
|
+
@path = path
|
|
52
|
+
else
|
|
53
|
+
raise Error, "invalid path #{path}" unless File.directory?(path)
|
|
54
|
+
# For older systems fall back to the legacy method of using PATH environment variable.
|
|
55
|
+
if ENV['PATH'].include?(path)
|
|
56
|
+
@handle = nil
|
|
57
|
+
@path = nil
|
|
58
|
+
else
|
|
59
|
+
$stderr.puts "Temporarily enhancing PATH by #{path}..." if $DEBUG
|
|
60
|
+
ENV['PATH'] = path + ";" + ENV['PATH']
|
|
61
|
+
@handle = nil
|
|
62
|
+
@path = path
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
return unless block_given?
|
|
66
|
+
begin
|
|
67
|
+
yield self
|
|
68
|
+
ensure
|
|
69
|
+
remove
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Set default search paths to LOAD_LIBRARY_SEARCH_DEFAULT_DIRS to include path added by add_dll_directory_winapi() and exclude paths set per PATH environment variable.
|
|
74
|
+
def self.set_default_dll_directories_winapi
|
|
75
|
+
raise WinApiError, "SetDefaultDllDirectories failed" if SetDefaultDllDirectories.call(0x00001000)==0
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def self.add_dll_directory_winapi(path)
|
|
79
|
+
strutf16 = (path + "\0").encode(Encoding::UTF_16LE)
|
|
80
|
+
strptr = Fiddle::Pointer.malloc(strutf16.bytesize)
|
|
81
|
+
strptr[0, strptr.size] = strutf16
|
|
82
|
+
handle = AddDllDirectory.call(strptr)
|
|
83
|
+
raise WinApiError, "AddDllDirectory failed for #{path}" if handle.null?
|
|
84
|
+
handle
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# This method removes the given directory from the active DLL search paths.
|
|
88
|
+
def remove
|
|
89
|
+
if @handle
|
|
90
|
+
raise WinApiError, "RemoveDllDirectory failed for #{@path}" if RemoveDllDirectory.call(@handle) == 0
|
|
91
|
+
elsif @path
|
|
92
|
+
ENV['PATH'] = ENV['PATH'].sub(@path + ";", "")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
|
|
4
|
+
module RubyInstaller
|
|
5
|
+
module Build
|
|
6
|
+
class ErbCompiler
|
|
7
|
+
class Box
|
|
8
|
+
def initialize(co, task)
|
|
9
|
+
@co = co
|
|
10
|
+
@task = task
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def method_missing(meth, *args, &block)
|
|
14
|
+
@task.send(meth, *args, &block)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def binding
|
|
18
|
+
Kernel.binding
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Quote a text string with the quotation rules of the resulting files.
|
|
22
|
+
def q(text)
|
|
23
|
+
meth = case @co.result_filename
|
|
24
|
+
when /\.iss$/ then :q_inno
|
|
25
|
+
else raise "can not determine quote rules for #{@co.result_filename}"
|
|
26
|
+
end
|
|
27
|
+
send(meth, text)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
include Utils
|
|
32
|
+
|
|
33
|
+
attr_reader :erb_filename
|
|
34
|
+
attr_reader :erb_filename_abs
|
|
35
|
+
|
|
36
|
+
def initialize(erb_file_rel, result_file_rel=nil)
|
|
37
|
+
@erb_filename = erb_file_rel
|
|
38
|
+
@erb_filename_abs = ovl_expand_file(erb_file_rel)
|
|
39
|
+
@erb = ERB.new(File.read(@erb_filename_abs, encoding: "UTF-8"))
|
|
40
|
+
@result_file_rel = result_file_rel || erb_file_rel.sub(/\.erb$/, "")
|
|
41
|
+
@erb.filename = @result_file_rel
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def result_filename
|
|
45
|
+
@result_file_rel
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def result(task=nil)
|
|
49
|
+
box = Box.new(self, task)
|
|
50
|
+
@erb.result(box.binding)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def write_result(task=nil, filename=nil)
|
|
54
|
+
filename ||= result_filename
|
|
55
|
+
FileUtils.mkdir_p File.dirname(filename)
|
|
56
|
+
File.binwrite(filename, result(task))
|
|
57
|
+
filename
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
module RubyInstaller
|
|
4
|
+
module Build
|
|
5
|
+
module Gems
|
|
6
|
+
class InstallSpec
|
|
7
|
+
include RubyInstaller::Build::Utils
|
|
8
|
+
|
|
9
|
+
attr_accessor :gem_name
|
|
10
|
+
attr_accessor :gem_version
|
|
11
|
+
attr_accessor :gem_build
|
|
12
|
+
|
|
13
|
+
attr_accessor :gem_cmd
|
|
14
|
+
attr_accessor :gem_install_opts
|
|
15
|
+
|
|
16
|
+
def initialize(gem_name)
|
|
17
|
+
@gem_name = gem_name.dup
|
|
18
|
+
@gem_cmd = "gem"
|
|
19
|
+
@gem_install_opts = []
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
fname = ovl_expand_file("gems/#{gem_name}.yaml")
|
|
23
|
+
rescue Errno::ENOENT
|
|
24
|
+
else
|
|
25
|
+
yaml = YAML.load_file(fname)
|
|
26
|
+
raise ArgumentError, "Not a Hash in #{fname}" unless yaml.is_a?(Hash)
|
|
27
|
+
|
|
28
|
+
yaml.each do |key, value|
|
|
29
|
+
send("#{key}=", value)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def install
|
|
35
|
+
if gem_build
|
|
36
|
+
out = run_capture_output(gem_cmd, "build", gem_build)
|
|
37
|
+
if out =~ /File: (.*)/
|
|
38
|
+
gem_file = $1
|
|
39
|
+
else
|
|
40
|
+
raise "Failed to build #{gem_name}"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if gem_version
|
|
45
|
+
version_opts = ["--version", gem_version]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
run(gem_cmd, "install", *gem_install_opts, gem_file || gem_name, *version_opts)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def run(*args)
|
|
52
|
+
puts args.join(" ")
|
|
53
|
+
res = system(*args)
|
|
54
|
+
raise "Command failed: #{args.join(" ")}" unless res
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def run_capture_output(*args)
|
|
58
|
+
puts args.join(" ")
|
|
59
|
+
IO.popen(args, &:read)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.install(*gems, **options)
|
|
64
|
+
gems.each do |name|
|
|
65
|
+
spec = InstallSpec.new(name)
|
|
66
|
+
options.each do |key, value|
|
|
67
|
+
spec.send("#{key}=", value)
|
|
68
|
+
end
|
|
69
|
+
spec.install
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
require "rbconfig"
|
|
2
|
+
|
|
3
|
+
module RubyInstaller
|
|
4
|
+
module Build # Use for: Build, Runtime
|
|
5
|
+
# :nodoc:
|
|
6
|
+
class Msys2Installation
|
|
7
|
+
MSYS2_INSTALL_KEY = "SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/"
|
|
8
|
+
|
|
9
|
+
class MsysNotFound < RuntimeError
|
|
10
|
+
end
|
|
11
|
+
class CommandError < RuntimeError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attr_reader :mingwdir
|
|
15
|
+
attr_reader :mingwarch
|
|
16
|
+
attr_reader :mingw_package_prefix
|
|
17
|
+
attr_reader :ruby_bin_dir
|
|
18
|
+
|
|
19
|
+
def initialize(msys_path: nil, mingwarch: nil, mingw_package_prefix: nil, ruby_bin_dir: nil)
|
|
20
|
+
@msys_path = msys_path
|
|
21
|
+
@msys_path_fixed = msys_path ? true : false
|
|
22
|
+
@mingwdir = nil
|
|
23
|
+
@mingwarch = mingwarch || (RUBY_PLATFORM=~/x64/ ? 'mingw64' : 'mingw32')
|
|
24
|
+
@mingw_package_prefix = mingw_package_prefix || (RUBY_PLATFORM=~/x64/ ? "mingw-w64-x86_64" : "mingw-w64-i686")
|
|
25
|
+
@ruby_bin_dir = ruby_bin_dir || File.join(RbConfig::TOPDIR, "bin")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reset_cache
|
|
29
|
+
@msys_path = nil unless @msys_path_fixed
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def iterate_msys_paths
|
|
33
|
+
# Prefer MSYS2 when installed within the ruby directory.
|
|
34
|
+
yield File.join(RbConfig::TOPDIR, "msys64")
|
|
35
|
+
yield File.join(RbConfig::TOPDIR, "msys32")
|
|
36
|
+
|
|
37
|
+
# Then try MSYS2 next to the ruby directory.
|
|
38
|
+
yield File.join(File.dirname(RbConfig::TOPDIR), "msys64")
|
|
39
|
+
yield File.join(File.dirname(RbConfig::TOPDIR), "msys32")
|
|
40
|
+
|
|
41
|
+
# If msys2 is installed at the default location
|
|
42
|
+
yield "c:/msys64"
|
|
43
|
+
yield "c:/msys32"
|
|
44
|
+
|
|
45
|
+
# If msys2 is installed per installer.exe
|
|
46
|
+
require "win32/registry"
|
|
47
|
+
begin
|
|
48
|
+
Win32::Registry::HKEY_CURRENT_USER.open(backslachs(MSYS2_INSTALL_KEY)) do |reg|
|
|
49
|
+
reg.each_key do |subkey|
|
|
50
|
+
subreg = reg.open(subkey)
|
|
51
|
+
begin
|
|
52
|
+
if subreg['DisplayName'] =~ /^MSYS2 / && File.directory?(il=subreg['InstallLocation'])
|
|
53
|
+
yield il
|
|
54
|
+
end
|
|
55
|
+
rescue Encoding::InvalidByteSequenceError, Win32::Registry::Error
|
|
56
|
+
# Ignore entries without valid installer data or broken character encoding
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
rescue Win32::Registry::Error
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
ENV['PATH'].split(";").each do |path|
|
|
64
|
+
# If /path/to/msys64 is in the PATH (e.g. Chocolatey)
|
|
65
|
+
yield path
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# If msys2 is installed by scoop package manager
|
|
69
|
+
yield IO.popen(["scoop", "prefix", "msys2"], &:read).strip rescue StandardError
|
|
70
|
+
|
|
71
|
+
raise MsysNotFound, "MSYS2 could not be found"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def msys_path
|
|
75
|
+
@msys_path ||= begin
|
|
76
|
+
iterate_msys_paths do |path|
|
|
77
|
+
if File.exist?(File.join(path, "usr/bin/msys-2.0.dll"))
|
|
78
|
+
break backslachs(path)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def msys_bin_path
|
|
85
|
+
backslachs( File.join(msys_path, "/usr/bin") )
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def mingw_bin_path
|
|
89
|
+
backslachs( File.join(msys_path, mingwarch, "bin") )
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def mingw_prefix
|
|
93
|
+
"/#{mingwarch}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def enable_dll_search_paths
|
|
97
|
+
@mingwdir ||= begin
|
|
98
|
+
DllDirectory.set_defaults
|
|
99
|
+
path = mingw_bin_path
|
|
100
|
+
DllDirectory.new(path) if File.directory?(path)
|
|
101
|
+
rescue MsysNotFound
|
|
102
|
+
# We silently ignore this error to allow Ruby installations without MSYS2.
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def disable_dll_search_paths
|
|
107
|
+
@mingwdir.remove if @mingwdir
|
|
108
|
+
@mingwdir = nil
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private def backslachs(path)
|
|
112
|
+
path.gsub("/", "\\")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private def msys_apps_envvars
|
|
116
|
+
vars = {}
|
|
117
|
+
msys_bin = msys_bin_path
|
|
118
|
+
mingw_bin = mingw_bin_path
|
|
119
|
+
ruby_bin = backslachs( ruby_bin_dir )
|
|
120
|
+
|
|
121
|
+
vars['PATH'] = ruby_bin + ";" + mingw_bin + ";" + msys_bin
|
|
122
|
+
vars['RI_DEVKIT'] = msys_path
|
|
123
|
+
vars['MSYSTEM'] = mingwarch.upcase
|
|
124
|
+
vars['PKG_CONFIG_PATH'] = "#{mingw_prefix}/lib/pkgconfig:#{mingw_prefix}/share/pkgconfig"
|
|
125
|
+
vars['ACLOCAL_PATH'] = "#{mingw_prefix}/share/aclocal:/usr/share/aclocal"
|
|
126
|
+
vars['MANPATH'] = "#{mingw_prefix}/share/man"
|
|
127
|
+
vars['MINGW_PACKAGE_PREFIX'] = mingw_package_prefix
|
|
128
|
+
locale = IO.popen([File.join(msys_bin, "locale"), "-uU"], &:read) rescue SystemCallError
|
|
129
|
+
vars['LANG'] = locale=~/UTF-8/ ? locale.to_s.strip : 'C'
|
|
130
|
+
|
|
131
|
+
vars
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private def with_msys_install_hint(if_no_msys = :hint)
|
|
135
|
+
case if_no_msys
|
|
136
|
+
when :hint
|
|
137
|
+
begin
|
|
138
|
+
yield
|
|
139
|
+
rescue MsysNotFound
|
|
140
|
+
$stderr.puts "MSYS2 could not be found. Please run 'ridk install'"
|
|
141
|
+
$stderr.puts "or download and install MSYS2 manually from https://msys2.github.io/"
|
|
142
|
+
exit 1
|
|
143
|
+
end
|
|
144
|
+
when :raise
|
|
145
|
+
yield
|
|
146
|
+
else
|
|
147
|
+
raise ArgumentError, "invalid value #{if_no_msys.inspect} for variable if_no_msys"
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def enable_msys_apps(if_no_msys: :hint, for_gem_install: false)
|
|
152
|
+
vars = with_msys_install_hint(if_no_msys) do
|
|
153
|
+
msys_apps_envvars
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
changed = false
|
|
157
|
+
|
|
158
|
+
if (path=vars.delete("PATH")) && !ENV['PATH'].include?(path)
|
|
159
|
+
phrase = "Temporarily enhancing PATH for MSYS/MINGW..."
|
|
160
|
+
if for_gem_install && defined?(Gem)
|
|
161
|
+
Gem.ui.say(phrase) if Gem.configuration.verbose
|
|
162
|
+
elsif $DEBUG
|
|
163
|
+
$stderr.puts phrase
|
|
164
|
+
end
|
|
165
|
+
changed = true
|
|
166
|
+
ENV['PATH'] = path + ";" + ENV['PATH']
|
|
167
|
+
end
|
|
168
|
+
vars.each do |key, val|
|
|
169
|
+
changed = true if ENV[key] != val
|
|
170
|
+
ENV[key] = val
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
changed
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def disable_msys_apps(if_no_msys: :hint)
|
|
177
|
+
vars = with_msys_install_hint(if_no_msys) do
|
|
178
|
+
msys_apps_envvars
|
|
179
|
+
end
|
|
180
|
+
changed = false
|
|
181
|
+
if path=vars.delete("PATH")
|
|
182
|
+
old_path = ENV['PATH']
|
|
183
|
+
ENV['PATH'] = old_path.gsub(path + ";", "")
|
|
184
|
+
changed = ENV['PATH'] != old_path
|
|
185
|
+
end
|
|
186
|
+
vars.each do |key, val|
|
|
187
|
+
changed = true if ENV[key]
|
|
188
|
+
ENV.delete(key)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
changed
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def with_msys_apps_enabled(**args)
|
|
195
|
+
changed = enable_msys_apps(**args)
|
|
196
|
+
begin
|
|
197
|
+
yield
|
|
198
|
+
ensure
|
|
199
|
+
disable_msys_apps(**args) if changed
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def with_msys_apps_disabled(**args)
|
|
204
|
+
changed = disable_msys_apps(**args)
|
|
205
|
+
begin
|
|
206
|
+
yield
|
|
207
|
+
ensure
|
|
208
|
+
enable_msys_apps(**args) if changed
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# This method is used for the ridk command.
|
|
213
|
+
def enable_msys_apps_per_cmd
|
|
214
|
+
vars = with_msys_install_hint{ msys_apps_envvars }
|
|
215
|
+
if (path=vars.delete("PATH")) && !ENV['PATH'].include?(path)
|
|
216
|
+
vars['PATH'] = path + ";" + ENV['PATH']
|
|
217
|
+
end
|
|
218
|
+
vars.map do |key, val|
|
|
219
|
+
"#{key}=#{val}"
|
|
220
|
+
end.join("\n")
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# This method is used for the ridk command.
|
|
224
|
+
def disable_msys_apps_per_cmd
|
|
225
|
+
vars = with_msys_install_hint{ msys_apps_envvars }
|
|
226
|
+
str = "".dup
|
|
227
|
+
if path=vars.delete("PATH")
|
|
228
|
+
str << "PATH=#{ ENV['PATH'].gsub(path + ";", "") }\n"
|
|
229
|
+
end
|
|
230
|
+
str << vars.map do |key, val|
|
|
231
|
+
"#{key}="
|
|
232
|
+
end.join("\n")
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# This method is used for the ridk command.
|
|
236
|
+
def enable_msys_apps_per_ps1
|
|
237
|
+
vars = with_msys_install_hint{ msys_apps_envvars }
|
|
238
|
+
if (path=vars.delete("PATH")) && !ENV['PATH'].include?(path)
|
|
239
|
+
vars['PATH'] = path + ";" + ENV['PATH']
|
|
240
|
+
end
|
|
241
|
+
vars.map do |key, val|
|
|
242
|
+
"$env:#{key}=\"#{val.gsub('"', '`"')}\""
|
|
243
|
+
end.join(";")
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# This method is used for the ridk command.
|
|
247
|
+
def disable_msys_apps_per_ps1
|
|
248
|
+
vars = with_msys_install_hint{ msys_apps_envvars }
|
|
249
|
+
str = "".dup
|
|
250
|
+
if path=vars.delete("PATH")
|
|
251
|
+
str << "$env:PATH=\"#{ ENV['PATH'].gsub(path + ";", "").gsub('"', '`"') }\";"
|
|
252
|
+
end
|
|
253
|
+
str << vars.map do |key, val|
|
|
254
|
+
"$env:#{key}=''"
|
|
255
|
+
end.join(";")
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def install_packages(packages, verbose: false)
|
|
259
|
+
return if packages.empty?
|
|
260
|
+
|
|
261
|
+
with_msys_apps_enabled do
|
|
262
|
+
Gem.ui.say("Installing required msys2 packages: #{packages.join(" ")}") if verbose
|
|
263
|
+
|
|
264
|
+
args = ["pacman", "-S", "--needed", "--noconfirm", *packages]
|
|
265
|
+
Gem.ui.say("> #{args.join(" ")}") if verbose==1
|
|
266
|
+
|
|
267
|
+
res = IO.popen(args, &:read)
|
|
268
|
+
raise CommandError, "pacman failed with the following output:\n#{res}" if !$? || $?.exitstatus != 0
|
|
269
|
+
|
|
270
|
+
Gem.ui.say(res) if verbose==1
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def install_mingw_packages(packages, verbose: false)
|
|
275
|
+
packages = packages.map{|pack| "#{mingw_package_prefix}-#{pack}" }
|
|
276
|
+
install_packages(packages, verbose: verbose)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|