forked from ender672/rubyinstaller
/
msys.rake
77 lines (63 loc) · 2.53 KB
/
msys.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'rake'
require 'rake/clean'
namespace(:compiler) do
namespace(:msys) do
# mingw needs downloads, sandbox and sandbox/mingw
package = RubyInstaller::MSYS
directory package.target
CLEAN.include(package.target)
# Put files for the :download task
package.files.each do |f|
file_source = "#{package.url}/#{f}"
file_target = "downloads/#{f}"
download file_target => file_source
# depend on downloads directory
file file_target => "downloads"
# download task need these files as pre-requisites
task :download => file_target
end
# Prepare the :sandbox, it requires the :download task
task :extract => [:extract_utils, :download, package.target] do
# grab the files from the download task
files = Rake::Task['compiler:msys:download'].prerequisites
files.each { |f|
extract(File.join(RubyInstaller::ROOT, f), package.target)
}
end
# prepares the msys environment to be used
task :prepare do
# relocate all content from usr to / since
# msys is hardcoded to mount /usr and cannot be overwriten
from_folder = File.join(package.target, "usr")
Dir.glob("#{from_folder}/*").reject { |f| f =~ /local$/ }.each do |f|
cp_r f, package.target
end
Dir.glob("#{from_folder}/local/*").each do |f|
cp_r f, package.target
end
rm_rf from_folder
# create the fstab file, mount /mingw to sandbox/mingw
# mount also /usr/local to sandbox/msys/usr
File.open(File.join(package.target, "etc", "fstab"), 'w') do |f|
f.puts "#{File.join(RubyInstaller::ROOT, RubyInstaller::MinGW.target)} /mingw"
end
#remove the chdir to $HOME in the /etc/profile
profile = File.join(package.target, "etc", "profile")
contents = File.read(profile).gsub(/cd \"\$HOME\"/) do |match|
"# commented to allow calling from current directory\n##{match}"
end
File.open(profile, 'w') { |f| f.write(contents) }
end
def msys_sh(*args)
cmd = args.join(' ')
sh "\"#{File.join(RubyInstaller::ROOT, RubyInstaller::MSYS.target, "bin")}/bash.exe\" --login -i -c \"#{cmd}\""
end
def msys_system(*args)
cmd = args.join(' ')
system "\"#{File.join(RubyInstaller::ROOT, RubyInstaller::MSYS.target, "bin")}/bash.exe\" --login -i -c \"#{cmd}\""
end
end
end
task :download => ['compiler:msys:download']
task :extract => ['compiler:msys:extract']
task :prepare => ['compiler:msys:prepare']