diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-04-04 19:49:24 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-04-04 19:49:24 +0900 |
commit | 38f576d15fc5cd8f5508d6f159004ee5f871ecdb (patch) | |
tree | 944c110fca7d0aaf920a946b7b65574a7e49ffaf | |
parent | 88e81f4b3fc5286f45c7928130095f23cecd1c41 (diff) | |
download | poe-38f576d15fc5cd8f5508d6f159004ee5f871ecdb.tar.gz |
rakefile: snapshot をサポート
-rw-r--r-- | Rakefile | 56 |
1 files changed, 34 insertions, 22 deletions
@@ -3,17 +3,24 @@ require "json" require "tmpdir" require "shellwords" -begin - $config_file = File.expand_path(ENV["CONFIG"] || "config.json") - $config = JSON.parse(File.read($config_file)) -rescue - puts "Failed to load config: #{$config_file}" - puts "You can specify config file with CONFIG environment variable" - raise +def load_config + begin + $config_file ||= File.expand_path(ENV["CONFIG"] || "config.json") + $tmp_config = JSON.parse(File.read($config_file)) + $datadir = $tmp_config["datadir"] + rescue + puts "Failed to load config: #{$config_file}" + puts "You can specify config file with CONFIG environment variable" + raise + end end -def save_config - File.write($config_file, JSON.pretty_generate($config)) +def add_compiler(lang, id, val) + load_config + list = $tmp_config["compilers"][lang] || {} + list[id] = val + $tmp_config["compilers"][lang] = list.sort.reverse.to_h + File.write($config_file, JSON.pretty_generate($tmp_config)) end def retriable @@ -26,6 +33,8 @@ rescue retry end +load_config + namespace :compiler do RUBY_MIRROR = "https://cache.ruby-lang.org/pub/ruby" desc "Install a ruby" @@ -33,22 +42,27 @@ namespace :compiler do version = args[:version] id = "ruby-#{version}" if version =~ /^(1\.1[a-d]|1\.[02-9]|2\..)/ + archive_dir = "ruby-#{version}" url = "#{RUBY_MIRROR}/#{$1}/ruby-#{version}.tar.gz" elsif version =~ /^0\./ + archive_dir = "ruby-#{version}" url = "#{RUBY_MIRROR}/1.0/ruby-#{version}.tar.gz" + elsif version =~ /snapshot/ + archive_dir = version + url = "#{RUBY_MIRROR}/#{version}.tar.gz" else raise ArgumentError, "unknown ruby" end - destdir = $config["datadir"] + "/env/ruby/#{id}" + destdir = $datadir + "/env/ruby/#{id}" raise ArgumentError, "already installed?" if Dir.exist?(destdir.to_s) prefix = "/opt" - Dir.mktmpdir { |dir| - FileUtils.chdir(dir) { + Dir.mktmpdir { |tmpdir| + FileUtils.chdir(tmpdir) { system("curl -o archive.tar.gz #{Shellwords.escape(url)}") or raise("failed to download") system("tar xf archive.tar.gz") or raise("failed to extract") - FileUtils.chdir("ruby-#{version}") { + FileUtils.chdir(archive_dir) { to_be_applied = [] patch_ccnames = ["ruby/#{version.split("-").join("/")}", "ruby/#{version.split("-")[0]}", "ruby"] patch_ccnames.each { |patch_ccname| @@ -73,11 +87,10 @@ namespace :compiler do system("make install DESTDIR=#{destdir}") or raise("failed to install") } - ($config["compilers"]["ruby"] ||= {})[id] = { + add_compiler("ruby", id, { version: `LD_LIBRARY_PATH=#{destdir}#{prefix}/lib #{destdir}#{prefix}/bin/ruby -v`.lines.first.chomp, commandline: ["#{prefix}/bin/ruby", "{}"] - } - save_config + }) } } } @@ -94,12 +107,12 @@ namespace :compiler do url = PHPS[version] or raise(ArgumentError, "unknown php") name = url.split("/").last - destdir = $config["datadir"] + "/env/php/#{id}" + destdir = $datadir + "/env/php/#{id}" raise ArgumentError, "already installed?" if Dir.exist?(destdir.to_s) prefix = "/opt" - Dir.mktmpdir { |dir| - FileUtils.chdir(dir) { + Dir.mktmpdir { |tmpdir| + FileUtils.chdir(tmpdir) { system("curl -O #{Shellwords.escape(url)}") or raise("failed to download") system("tar xf #{Shellwords.escape(name)}") or raise("failed to extract") FileUtils.chdir(name.split(".tar.gz").first) { @@ -109,11 +122,10 @@ namespace :compiler do system("make install INSTALL_ROOT=#{destdir.to_s}") or raise("failed to install") } - ($config["compilers"]["php"] ||= {})[id] = { + add_compiler("php", id, { version: `LD_LIBRARY_PATH=#{destdir}#{prefix}/lib #{destdir}#{prefix}/bin/php -v`.lines.first.chomp, commandline: ["#{prefix}/bin/php", "{}"] - } - save_config + }) } } } |