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.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE.md +8 -0
  3. data/.gitignore +12 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG-2.4.md +166 -0
  6. data/CHANGELOG-2.5.md +87 -0
  7. data/CHANGELOG-2.6.md +62 -0
  8. data/CHANGELOG-2.7.md +22 -0
  9. data/Gemfile +6 -0
  10. data/LICENSE.txt +25 -0
  11. data/README.md +114 -0
  12. data/Rakefile +164 -0
  13. data/appveyor-key.asc.asc +61 -0
  14. data/appveyor.yml +141 -0
  15. data/docker/Dockerfile +50 -0
  16. data/docker/Rakefile +22 -0
  17. data/gems/rubyinstaller-build.yaml +2 -0
  18. data/lib/devkit.rb +3 -0
  19. data/lib/ruby_installer.rb +3 -0
  20. data/lib/ruby_installer/build.rb +23 -0
  21. data/lib/ruby_installer/build/ca_cert_file.rb +66 -0
  22. data/lib/ruby_installer/build/colors.rb +45 -0
  23. data/lib/ruby_installer/build/components/01_msys2.rb +97 -0
  24. data/lib/ruby_installer/build/components/02_pacman_update.rb +35 -0
  25. data/lib/ruby_installer/build/components/03_dev_tools.rb +68 -0
  26. data/lib/ruby_installer/build/components/base.rb +58 -0
  27. data/lib/ruby_installer/build/components_installer.rb +53 -0
  28. data/lib/ruby_installer/build/dll_directory.rb +97 -0
  29. data/lib/ruby_installer/build/erb_compiler.rb +61 -0
  30. data/lib/ruby_installer/build/gem_version.rb +5 -0
  31. data/lib/ruby_installer/build/gems.rb +74 -0
  32. data/lib/ruby_installer/build/msys2_installation.rb +280 -0
  33. data/lib/ruby_installer/build/openstruct.rb +29 -0
  34. data/lib/ruby_installer/build/release.rb +120 -0
  35. data/lib/ruby_installer/build/singleton.rb +45 -0
  36. data/lib/ruby_installer/build/task.rb +20 -0
  37. data/lib/ruby_installer/build/utils.rb +110 -0
  38. data/lib/ruby_installer/runtime.rb +18 -0
  39. data/lib/ruby_installer/runtime/ridk.rb +195 -0
  40. data/packages/ri-msys/Rakefile +72 -0
  41. data/packages/ri-msys/recipes/sandbox/70-add-msys2-installation.rake +18 -0
  42. data/packages/ri/Rakefile +60 -0
  43. data/recipes/archive-7z/10-define-variables.rake +2 -0
  44. data/recipes/archive-7z/70-create-archive.rake +10 -0
  45. data/recipes/archive-7z/90-define-main-task.rake +2 -0
  46. data/recipes/installer-inno/10-define-variables.rake +2 -0
  47. data/recipes/installer-inno/50-generate-filelist.rake +28 -0
  48. data/recipes/installer-inno/60-generate-iss-file.rake +8 -0
  49. data/recipes/installer-inno/70-run-iscc.rake +19 -0
  50. data/recipes/installer-inno/90-define-main-task.rake +2 -0
  51. data/recipes/installer-inno/events.iss +88 -0
  52. data/recipes/installer-inno/images/fake.bmp +0 -0
  53. data/recipes/installer-inno/images/wizard-large.bmp +0 -0
  54. data/recipes/installer-inno/images/wizard-logo.bmp +0 -0
  55. data/recipes/installer-inno/ri_gui.iss +286 -0
  56. data/recipes/installer-inno/rubyinstaller.iss.erb +157 -0
  57. data/recipes/installer-inno/util.iss +271 -0
  58. data/recipes/msys2/10-define-variables.rake +6 -0
  59. data/recipes/msys2/30-download-msys2-base.rake +4 -0
  60. data/recipes/msys2/40-extract-msys2-base.rake +9 -0
  61. data/recipes/msys2/50-init-msys.rake +8 -0
  62. data/recipes/msys2/50-install-components.rake +19 -0
  63. data/recipes/msys2/90-define-main-task.rake +2 -0
  64. data/recipes/sandbox/10-define-variables.rake +6 -0
  65. data/recipes/sandbox/20-add-runtime-files.rake +15 -0
  66. data/recipes/sandbox/20-define-import-files.rake +16 -0
  67. data/recipes/sandbox/20-define-import-readline.rake +28 -0
  68. data/recipes/sandbox/20-extend-irb.rake +13 -0
  69. data/recipes/sandbox/40-fix-rake-shebang.rake +6 -0
  70. data/recipes/sandbox/40-generate-rake-cmd.rake +7 -0
  71. data/recipes/sandbox/40-generate-version-file.rake +20 -0
  72. data/recipes/sandbox/50-do-import-files.rake +17 -0
  73. data/recipes/sandbox/50-gather-sandbox-files.rake +6 -0
  74. data/recipes/sandbox/60-define-gem-wrappers.rake +5 -0
  75. data/recipes/sandbox/60-side-by-side-assembly.rake +81 -0
  76. data/recipes/sandbox/70-add-gem-bin-wrappers.rake +10 -0
  77. data/recipes/sandbox/70-install-gems.rake +11 -0
  78. data/recipes/sandbox/80-copy-msys-files.rake +8 -0
  79. data/recipes/sandbox/90-define-main-task.rake +2 -0
  80. data/recipes/sandbox/LICENSE.txt +24 -0
  81. data/recipes/sandbox/rubyinstaller-2.3.4-x64.files +4 -0
  82. data/recipes/sandbox/rubyinstaller-2.3.4-x86.files +4 -0
  83. data/recipes/sandbox/rubyinstaller-2.3.4.files +43 -0
  84. data/recipes/sandbox/rubyinstaller-2.4.10-x64.files +4 -0
  85. data/recipes/sandbox/rubyinstaller-2.4.10-x86.files +4 -0
  86. data/recipes/sandbox/rubyinstaller-2.4.10.files +44 -0
  87. data/recipes/sandbox/rubyinstaller-2.5.8-x64.files +6 -0
  88. data/recipes/sandbox/rubyinstaller-2.5.8-x86.files +6 -0
  89. data/recipes/sandbox/rubyinstaller-2.5.8.files +33 -0
  90. data/recipes/sandbox/rubyinstaller-2.6.6-x64.files +6 -0
  91. data/recipes/sandbox/rubyinstaller-2.6.6-x86.files +6 -0
  92. data/recipes/sandbox/rubyinstaller-2.6.6.files +35 -0
  93. data/recipes/sandbox/rubyinstaller-2.7.1-x64.files +6 -0
  94. data/recipes/sandbox/rubyinstaller-2.7.1-x86.files +6 -0
  95. data/recipes/sandbox/rubyinstaller-2.7.1.files +35 -0
  96. data/recipes/sandbox/rubyinstaller-head-x64.files +6 -0
  97. data/recipes/sandbox/rubyinstaller-head-x86.files +6 -0
  98. data/recipes/sandbox/rubyinstaller-head.files +35 -0
  99. data/recipes/unpack/10-define-variables.rake +5 -0
  100. data/recipes/unpack/20-define-msys-packages.rake +1 -0
  101. data/recipes/unpack/30-add-ri2-repo-to-msys.rake +41 -0
  102. data/recipes/unpack/50-install-msys-packages.rake +28 -0
  103. data/recipes/unpack/90-define-main-task.rake +2 -0
  104. data/recipes/unpack/appveyor-repo-key.asc +29 -0
  105. data/resources/files/irbrc_predefiner.rb +21 -0
  106. data/resources/files/operating_system.rb +21 -0
  107. data/resources/files/readline.rb +17 -0
  108. data/resources/files/reline.rb +437 -0
  109. data/resources/files/reline/ansi.rb +177 -0
  110. data/resources/files/reline/config.rb +297 -0
  111. data/resources/files/reline/general_io.rb +75 -0
  112. data/resources/files/reline/history.rb +56 -0
  113. data/resources/files/reline/key_actor.rb +7 -0
  114. data/resources/files/reline/key_actor/base.rb +7 -0
  115. data/resources/files/reline/key_actor/emacs.rb +517 -0
  116. data/resources/files/reline/key_actor/vi_command.rb +518 -0
  117. data/resources/files/reline/key_actor/vi_insert.rb +517 -0
  118. data/resources/files/reline/key_stroke.rb +53 -0
  119. data/resources/files/reline/kill_ring.rb +113 -0
  120. data/resources/files/reline/line_editor.rb +2231 -0
  121. data/resources/files/reline/unicode.rb +527 -0
  122. data/resources/files/reline/unicode/east_asian_width.rb +1145 -0
  123. data/resources/files/reline/version.rb +3 -0
  124. data/resources/files/reline/windows.rb +273 -0
  125. data/resources/files/ridk.cmd +39 -0
  126. data/resources/files/ridk.ps1 +26 -0
  127. data/resources/files/ridk_use/ridk.cmd +13 -0
  128. data/resources/files/ridk_use/ridk.ps1 +17 -0
  129. data/resources/files/ridk_use/ridk_use.rb +221 -0
  130. data/resources/files/setrbvars.cmd +14 -0
  131. data/resources/icons/ruby-doc.ico +0 -0
  132. data/resources/ssl/README-SSL.md +37 -0
  133. data/resources/ssl/c_rehash.rb +167 -0
  134. data/resources/ssl/cacert.pem +4105 -0
  135. data/rubyinstaller-build.gemspec +28 -0
  136. metadata +226 -0
@@ -0,0 +1,29 @@
1
+ module RubyInstaller
2
+ module Build
3
+ class Openstruct
4
+ def initialize(hash={})
5
+ @__attrs = {}
6
+ hash.each do |k,v|
7
+ send("#{k}=", v)
8
+ end
9
+ end
10
+
11
+ def method_missing(meth, *args)
12
+ if meth=~/\A(.*)=\z/ && args.length == 1
13
+ attr = $1
14
+ self.class.class_eval do
15
+ define_method(attr) do
16
+ @__attrs[attr]
17
+ end
18
+ define_method(meth) do |val|
19
+ @__attrs[attr] = val
20
+ end
21
+ end
22
+ @__attrs[attr] = args.first
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,120 @@
1
+ module RubyInstaller
2
+ module Build
3
+ class Release
4
+ def hfile(ver)
5
+ "CHANGELOG-#{ver}.md"
6
+ end
7
+
8
+ def version_regex
9
+ '[\w]+-(?<ver>\d+\.\d+\.\d+(\.[a-z]\w*)?-[\d\w]+)'
10
+ end
11
+
12
+ def headline_regex(rel=nil)
13
+ "^(?<pre>[^\\w]*)(?<release>#{rel ? Regexp.escape(rel) : version_regex})(?<sp1>[^\\w]+)(?<date>[2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D])(?<sp2>[ \\w]*)$"
14
+ end
15
+
16
+ def reldate
17
+ Time.now.strftime("%Y-%m-%d")
18
+ end
19
+
20
+ def release_text(rel)
21
+ ver = rel_to_ver(rel)
22
+ m = File.read(hfile(ver)).match(/(?<annotation>#{headline_regex(rel)}.*?)(#{headline_regex}|\z)/m) || raise("Unable to find release #{rel.inspect} in #{hfile(ver)}")
23
+ m[:annotation]
24
+ end
25
+
26
+ def release_name(rel)
27
+ ver = rel_to_ver(rel)
28
+ m = File.read(hfile(ver)).match(/#{headline_regex(rel)}/)
29
+ m[:release]
30
+ end
31
+
32
+ def rel_to_ver(rel)
33
+ m = rel.match(/^#{version_regex}$/)
34
+ raise "invalid version string #{rel.inspect}" unless m
35
+ m[:ver][0, 3] # Extract major and minor version "2.4" etc.
36
+ end
37
+
38
+ def update_history(rel)
39
+ hfile = hfile(rel_to_ver(rel))
40
+ hin = File.read(hfile)
41
+ hout = hin.sub(/#{headline_regex(rel)}/) do
42
+ $1 + $2 + $3 + reldate + $5
43
+ end
44
+ if hout != hin
45
+ $stderr.puts "Updating #{hfile} for release."
46
+ File.write(hfile, hout)
47
+ Rake::FileUtilsExt.sh "git", "commit", hfile, "-m", "Update release date in #{hfile}"
48
+ end
49
+ end
50
+
51
+ def tag_version(rel)
52
+ $stderr.puts "Tag release #{rel} with annotation:"
53
+ rt = release_text(rel).gsub(/\A[# ]+/, "")
54
+ $stderr.puts(rt.gsub(/^/, " "))
55
+ IO.popen(["git", "tag", "--file=-", rel, "--cleanup=whitespace"], "w") do |fd|
56
+ fd.write rt
57
+ end
58
+ end
59
+
60
+ CONTENT_TYPE_FOR_EXT = {
61
+ ".exe" => "application/vnd.microsoft.portable-executable",
62
+ ".asc" => "application/pgp-signature",
63
+ ".7z" => "application/zip",
64
+ ".yml" => "application/x-yaml",
65
+ }
66
+
67
+ def upload_to_github(tag:, repo:, token: nil, files:)
68
+ require "octokit"
69
+
70
+ client = Octokit::Client.new(access_token: token)
71
+ release = client.releases(repo).find{|r| r.tag_name==tag }
72
+ $stderr.puts "#{ release ? "Add to" : "Create" } github release #{tag}"
73
+
74
+ if tag =~ /head$/
75
+ if release
76
+ headline = release.name
77
+ body = release.body
78
+ .gsub(/[2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D] [0-2H][0-9H]:[0-6M][0-9M]:[0-6S][0-9S] UTC/, Time.now.utc.strftime("%Y-%m-%d %H:%M:%S UTC"))
79
+ .gsub(/(Ruby version #{RUBY_PLATFORM}.*?```).*?(```)/m) do
80
+ $1 + "\n" + `ruby --version` + "\n" + $2
81
+ end
82
+ else
83
+ headline = tag
84
+ body = "Latest build of #{tag}"
85
+ end
86
+ else
87
+ headline = IO.popen(["git", "tag", "-l", tag, "--format=%(subject)"], &:read)
88
+ body = IO.popen(["git", "tag", "-l", tag, "--format=%(body)"], &:read)
89
+ end
90
+ raise "invalid headline of tag #{tag.inspect} #{headline.inspect}" if headline.to_s.strip.empty?
91
+ raise "invalid body of tag #{tag.inspect} #{body.inspect}" if body.to_s.strip.empty?
92
+
93
+ if release
94
+ release = client.update_release(release.url, name: headline, body: body)
95
+ else
96
+ release = client.create_release(repo, tag,
97
+ target_commitish: "master",
98
+ name: headline,
99
+ body: body,
100
+ draft: true,
101
+ prerelease: true
102
+ )
103
+ end
104
+
105
+ old_assets = client.release_assets(release.url)
106
+
107
+ files.each do |fname|
108
+ if old_asset=old_assets.find{|a| a.name == File.basename(fname) }
109
+ $stderr.puts "Delete old #{old_asset.name}"
110
+ client.delete_release_asset(old_asset.url)
111
+ end
112
+
113
+ $stderr.print "Uploading #{fname} (#{File.size(fname)} bytes) ... "
114
+ client.upload_asset(release.url, fname, content_type: CONTENT_TYPE_FOR_EXT[File.extname(fname)])
115
+ $stderr.puts "OK"
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,45 @@
1
+ module RubyInstaller
2
+ module Build # Use for: Build, Runtime
3
+ class << self
4
+ # Add +path+ as a search path for DLLs
5
+ #
6
+ # This can be used to allow ruby extension files (typically named +<extension>.so+ ) to import dependent DLLs from another directory.
7
+ #
8
+ # If this method is called with a block, the path is temporary added until the block is finished.
9
+ # The method returns a DllDirectory instance, when called without a block.
10
+ # It can be used to remove the directory later.
11
+ def add_dll_directory(path, &block)
12
+ DllDirectory.new(path, &block)
13
+ end
14
+
15
+ # :nodoc:
16
+ def msys2_installation
17
+ @msys2_installation ||= Msys2Installation.new
18
+ end
19
+
20
+ # Switch to explicit DLL search paths added by add_dll_directory().
21
+ # Then enable paths set by RUBY_DLL_PATH environment variable and the MSYS2-MINGW directory, if available.
22
+ def enable_dll_search_paths
23
+ ENV['RUBY_DLL_PATH'].to_s.split(File::PATH_SEPARATOR).each do |path|
24
+ DllDirectory.new(path) rescue DllDirectory::Error
25
+ end
26
+
27
+ msys2_installation.enable_dll_search_paths
28
+ end
29
+
30
+ # Add MSYS2 to the PATH and set other environment variables required to run MSYS2.
31
+ #
32
+ # This method tries to find a MSYS2 installation or exits with a description how to install MSYS2.
33
+ #
34
+ # +mingwarch+ should be either 'mingw32', 'mingw64' or nil.
35
+ # In the latter case the mingw architecture is used based on the architecture of the running Ruby process.
36
+ def enable_msys_apps(**opts)
37
+ msys2_installation.enable_msys_apps(**opts)
38
+ end
39
+
40
+ def disable_msys_apps(**opts)
41
+ msys2_installation.disable_msys_apps(**opts)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ require "rake"
2
+ require "ruby_installer/build"
3
+
4
+ module RubyInstaller
5
+ module Build
6
+ class Task < Openstruct
7
+ include Rake::DSL
8
+ include Utils
9
+
10
+ def initialize(thisdir: , **hash)
11
+ super(hash)
12
+ self.thisdir = thisdir
13
+
14
+ ovl_glob(File.join(thisdir, "[0-9][0-9]-*.rake")).sort.each do |taskfile|
15
+ eval_file(ovl_expand_file(taskfile))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,110 @@
1
+ module RubyInstaller
2
+ module Build
3
+ module Utils
4
+ WINDOWS_CMD_SHEBANG = <<-EOT.freeze
5
+ :""||{ ""=> %q<-*- ruby -*-
6
+ @"%~dp0ruby" -x "%~f0" %*
7
+ @exit /b %ERRORLEVEL%
8
+ };{ #
9
+ bindir="${0%/*}" #
10
+ exec "$bindir/ruby" -x "$0" "$@" #
11
+ >, #
12
+ } #
13
+ EOT
14
+
15
+ def msys_sh(cmd)
16
+ Build.enable_msys_apps
17
+ pwd = Dir.pwd
18
+ sh "sh", "-lc", "cd `cygpath -u #{pwd.inspect}`; #{cmd}"
19
+ end
20
+
21
+ def with_env(hash)
22
+ olds = hash.map{|k, _| [k, ENV[k.to_s]] }
23
+ hash.each do |k, v|
24
+ ENV[k.to_s] = v
25
+ end
26
+ begin
27
+ yield
28
+ ensure
29
+ olds.each do |k, v|
30
+ ENV[k.to_s] = v
31
+ end
32
+ end
33
+ end
34
+
35
+ GEM_ROOT = File.expand_path("../../../..", __FILE__)
36
+
37
+ # Return the gem files of "rubyinstaller-build"
38
+ #
39
+ # The gemspec is either already loaded or taken from our root directory.
40
+ def rubyinstaller_build_gem_files
41
+ spec = Gem.loaded_specs["rubyinstaller-build"]
42
+ if spec
43
+ # A loaded gemspec has empty #files -> fetch the files from it's path.
44
+ # This is preferred to gemspec loading to avoid a dependency to git.
45
+ Dir["**/*", base: spec.full_gem_path].select do |f|
46
+ FileTest.file?(File.join(spec.full_gem_path, f))
47
+ end
48
+ else
49
+ # Not yet loaded -> load the gemspec and return the files added to the gemspec.
50
+ Gem::Specification.load(File.join(GEM_ROOT, "rubyinstaller-build.gemspec")).files
51
+ end
52
+ end
53
+
54
+ # Scan the current and the gem root directory for files matching rel_pattern.
55
+ #
56
+ # All paths returned are relative.
57
+ def ovl_glob(rel_pattern)
58
+ gem_files = Dir.glob(File.join(GEM_ROOT, rel_pattern)).map do |path|
59
+ path.sub(GEM_ROOT+"/", "")
60
+ end
61
+
62
+ (gem_files + Dir.glob(rel_pattern)).uniq
63
+ end
64
+
65
+ # Returns the absolute path of rel_file within the current directory or,
66
+ # if it doesn't exist, from the gem root directory.
67
+ #
68
+ # Raises Errno::ENOENT if neither of them exist.
69
+ def ovl_expand_file(rel_file)
70
+ if File.exist?(rel_file)
71
+ File.expand_path(rel_file)
72
+ elsif File.exist?(a=File.join(GEM_ROOT, rel_file))
73
+ File.expand_path(a)
74
+ else
75
+ raise Errno::ENOENT, rel_file
76
+ end
77
+ end
78
+
79
+ # Returns the absolute path of rel_file within the gem root directory.
80
+ #
81
+ # Raises Errno::ENOENT if it doesn't exist.
82
+ def gem_expand_file(rel_file)
83
+ if File.exist?(a=File.join(GEM_ROOT, rel_file))
84
+ File.expand_path(a)
85
+ else
86
+ raise Errno::ENOENT, rel_file
87
+ end
88
+ end
89
+
90
+ def eval_file(filename)
91
+ code = File.read(filename, encoding: "UTF-8")
92
+ instance_eval(code, filename)
93
+ end
94
+
95
+
96
+ def ovl_read_file(file_rel)
97
+ File.read(ovl_expand_file(file_rel), encoding: "UTF-8")
98
+ end
99
+
100
+ def ovl_compile_erb(erb_file_rel)
101
+ ErbCompiler.new(erb_file_rel).result
102
+ end
103
+
104
+ # Quote a string according to the rules of Inno-Setup
105
+ def q_inno(text)
106
+ '"' + text.to_s.gsub('"', '""') + '"'
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,18 @@
1
+ module RubyInstaller
2
+ module Runtime
3
+ autoload :Colors, 'ruby_installer/runtime/colors'
4
+ autoload :ComponentsInstaller, 'ruby_installer/runtime/components_installer'
5
+ autoload :DllDirectory, 'ruby_installer/runtime/dll_directory'
6
+ autoload :Msys2Installation, 'ruby_installer/runtime/msys2_installation'
7
+ autoload :Ridk, 'ruby_installer/runtime/ridk'
8
+ autoload :PACKAGE_VERSION, 'ruby_installer/runtime/package_version'
9
+ autoload :GIT_COMMIT, 'ruby_installer/runtime/package_version'
10
+
11
+ module Components
12
+ autoload :Base, 'ruby_installer/runtime/components/base'
13
+ end
14
+
15
+ require 'ruby_installer/runtime/singleton'
16
+ BuildOrRuntime = self
17
+ end
18
+ end
@@ -0,0 +1,195 @@
1
+ module RubyInstaller
2
+ module Runtime
3
+ # :nodoc:
4
+ module Ridk
5
+ class << self
6
+ include Colors
7
+
8
+ def run!(args)
9
+ enable_colors
10
+ case args[0]
11
+ when 'install'
12
+ print_logo
13
+ puts
14
+ install(args[1..-1])
15
+ when 'enable', 'exec'
16
+ puts Runtime.msys2_installation.enable_msys_apps_per_cmd
17
+ when 'disable'
18
+ puts Runtime.msys2_installation.disable_msys_apps_per_cmd
19
+ when 'enableps1', 'execps1'
20
+ puts Runtime.msys2_installation.enable_msys_apps_per_ps1
21
+ when 'disableps1'
22
+ puts Runtime.msys2_installation.disable_msys_apps_per_ps1
23
+ when 'version'
24
+ print_version
25
+ when 'help', '--help', '-?', '/?', nil
26
+ print_logo
27
+ print_help
28
+ else
29
+ $stderr.puts "Invalid option #{args[0].inspect}"
30
+ end
31
+ end
32
+
33
+ # The ASCII art is thankfully generated by:
34
+ # http://patorjk.com/software/taag/#p=display&f=Big&t=RubyInstaller2
35
+ # http://patorjk.com/software/taag/#p=display&f=Bigfig&t=for%20Windows
36
+ LOGO = %q{
37
+ _____ _ r _____ _ _ _ ry ___ y
38
+ | __ \ | | r|_ _| | | | | | ry|__ \ y
39
+ | |__) | _| |__ _ _ r | | _ __ ___| |_ __ _| | | ___ _ __ry ) |y
40
+ | _ / | | | '_ \| | | |r | | | '_ \/ __| __/ _` | | |/ _ \ '__ry/ / y
41
+ | | \ \ |_| | |_) | |_| |r_| |_| | | \__ \ || (_| | | | __/ | ry/ /_ y
42
+ |_| \_\__,_|_.__/ \__, r|_____|_| |_|___/\__\__,_|_|_|\___|_|ry|____|y
43
+ __/ | c _ c
44
+ |___/ c _|_ _ __ | | o __ _| _ _ c
45
+ c | (_) | |^| | | |(_|(_)\^/_> c
46
+ }[1..-1]
47
+
48
+ def print_logo
49
+ puts LOGO.gsub(/r(.*?)r/){ magenta($1) }
50
+ .gsub(/y(.*?)y/){ cyan($1) }
51
+ .gsub(/c(.*?)c/){ yellow($1) }
52
+ end
53
+
54
+ DEFAULT_COMPONENTS = %w[1 3]
55
+
56
+ def install(args)
57
+ ci = ComponentsInstaller.new
58
+ inst_defaults = DEFAULT_COMPONENTS
59
+
60
+ if args.empty?
61
+ # Interactive installation
62
+ loop do
63
+ ci.installable_components.each do |comp|
64
+ puts format(" % 2d - %s", comp.task_index, comp.description)
65
+ end
66
+ puts
67
+ print "Which components shall be installed? If unsure press ENTER [#{inst_defaults.join(",")}] "
68
+
69
+ inp = STDIN.gets
70
+ inp = inp.tr(",", " ").strip if inp
71
+ if !inp
72
+ break
73
+ elsif inp.empty? && inst_defaults.empty?
74
+ break
75
+ elsif inp.empty?
76
+ inst_list = inst_defaults
77
+ elsif inp =~ /\A(?:(\d+|\w+)\s*)+\z/
78
+ inst_list = [inp]
79
+ else
80
+ puts red("Please enter a comma separated list of the components to be installed")
81
+ end
82
+
83
+ if inst_list
84
+ puts
85
+ begin
86
+ ci.install(args_to_tasks(ci, inst_list).map(&:name))
87
+ rescue => err
88
+ puts red("Installation failed: #{err}")
89
+ end
90
+
91
+ ci.reload
92
+ inst_defaults = []
93
+ puts
94
+ end
95
+ end
96
+
97
+ else
98
+ # Unattended installation
99
+ ci.install(args_to_tasks(ci, args).map(&:name))
100
+ end
101
+ end
102
+
103
+ private def args_to_tasks(ci, args)
104
+ tasks = args.join(" ").split(" ").map do |idx_or_name|
105
+ if idx_or_name =~ /\A\d+\z/ && (task=ci.installable_components.find{|c| idx_or_name.to_i == c.task_index })
106
+ task
107
+ elsif idx_or_name =~ /\A\w+\z/ && (task=ci.installable_components.find{|c| idx_or_name == c.name })
108
+ task
109
+ else
110
+ puts red("Can not find component #{idx_or_name.inspect}")
111
+ end
112
+ end.compact
113
+ end
114
+
115
+ def msys_version_info(msys_path)
116
+ require "rexml/document"
117
+ doc = File.open( File.join(msys_path, "components.xml") ) do |fd|
118
+ REXML::Document.new fd
119
+ end
120
+ {
121
+ "title" => doc.elements.to_a("//Packages/Package/Title").first.text,
122
+ "version" => doc.elements.to_a("//Packages/Package/Version").first.text,
123
+ }
124
+ end
125
+
126
+ private def ignore_err
127
+ orig_verbose, $VERBOSE = $VERBOSE, nil
128
+ begin
129
+ yield
130
+ rescue
131
+ end
132
+ $VERBOSE = orig_verbose
133
+ end
134
+
135
+ def print_version
136
+ require "yaml"
137
+ require "rbconfig"
138
+
139
+ h = {
140
+ "ruby" => { "path" => RbConfig::TOPDIR,
141
+ "version" => RUBY_VERSION,
142
+ "platform" => RUBY_PLATFORM },
143
+ "ruby_installer" => { "package_version" => RubyInstaller::Runtime::PACKAGE_VERSION,
144
+ "git_commit" => RubyInstaller::Runtime::GIT_COMMIT },
145
+ }
146
+
147
+ ignore_err do
148
+ msys = Runtime.msys2_installation
149
+ msys.enable_msys_apps(if_no_msys: :raise)
150
+
151
+ msys_ver = ignore_err{ msys_version_info(msys.msys_path) }
152
+ h["msys2"] = { "path" => msys.msys_path }.merge(msys_ver || {})
153
+ end
154
+
155
+ ignore_err do
156
+ cc = RbConfig::CONFIG['CC_VERSION']
157
+ ver, _ = `#{cc}`.split("\n", 2)
158
+ h["cc"] = ver
159
+ end
160
+
161
+ # Add compiler used to build ruby, if different from current gcc
162
+ ruby_cc = RbConfig::CONFIG['CC_VERSION_MESSAGE'].split("\n", 2).first
163
+ h["ruby"]["cc"] = ruby_cc if ruby_cc.gsub(/\.exe/, "") != h["cc"]
164
+
165
+ ignore_err do
166
+ ver, _ = `sh --version`.split("\n", 2)
167
+ h["sh"] = ver
168
+ end
169
+
170
+ ignore_err do
171
+ h["os"] = `ver`.strip
172
+ end
173
+
174
+ puts h.to_yaml
175
+ end
176
+
177
+ def print_help
178
+ $stdout.puts <<-EOT
179
+ Usage:
180
+ #{$0} [option]
181
+
182
+ Option:
183
+ install Install MSYS2 and MINGW dev tools
184
+ exec <command> Execute a command within MSYS2 context
185
+ enable Set environment variables for MSYS2
186
+ disable Unset environment variables for MSYS2
187
+ version Print RubyInstaller and MSYS2 versions
188
+ use Switch to a different ruby version
189
+ help | --help | -? | /? Display this help and exit
190
+ EOT
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end