aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks/compiler.rake
blob: e886cc9927d1cb5279722465477a7797118f4761 (plain)
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
require "fileutils"
require "tmpdir"
require "shellwords"

namespace :compiler do
  RUBIES = {
    "2.3.0" => "https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz",
    "2.2.4" => "https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.gz",
    "2.2.3" => "https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz",
    "2.1.8" => "https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.8.tar.gz",
    "2.0.0-p648" => "https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p648.tar.gz",
  }
  desc "Install a ruby"
  task :ruby, :version
  task ruby: :environment do |t, args|
    url = RUBIES[args[:version]] or raise(ArgumentError, "unknown ruby")
    name = url.split("/").last

    destdir = Rails.root.join("playground/ruby/#{args[:version]}")
    raise ArgumentError, "already installed?" if Dir.exist?(destdir.to_s)
    prefix = "/opt"

    Dir.mktmpdir { |dir|
      FileUtils.chdir(dir) {
        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) {
          system("./configure --prefix=#{prefix} --enable-shared --disable-install-doc") or raise("failed to configure")
          system("make -j6") or raise("failed to make")
          system("make install DESTDIR=#{destdir.to_s}") or raise("failed to install")

          Compiler.create!(language: "ruby",
                           version: args[:version],
                           version_long: `LD_LIBRARY_PATH=#{destdir}#{prefix}/lib #{destdir}#{prefix}/bin/ruby -v`.lines.first.chomp,
                           command_line: "#{prefix}/bin/ruby PROGRAM")
        }
      }
    }
  end

  PHPS = {
    "7.0.2" => "http://jp2.php.net/distributions/php-7.0.2.tar.gz",
    "5.6.17" => "http://jp2.php.net/distributions/php-5.6.17.tar.gz",
  }
  desc "Install a php"
  task :php, :version
  task php: :environment do |t, args|
    url = PHPS[args[:version]] or raise(ArgumentError, "unknown php")
    name = url.split("/").last

    destdir = Rails.root.join("playground/php/#{args[:version]}")
    raise ArgumentError, "already installed?" if Dir.exist?(destdir.to_s)
    prefix = "/opt"

    Dir.mktmpdir { |dir|
      FileUtils.chdir(dir) {
        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) {
          system("./configure --prefix=#{prefix} --enable-shared") or raise("failed to configure")
          system("make -j6") or raise("failed to make")
          system("make install INSTALL_ROOT=#{destdir.to_s}") or raise("failed to install")

          Compiler.create!(language: "php",
                           version: args[:version],
                           version_long: `LD_LIBRARY_PATH=#{destdir}#{prefix}/lib #{destdir}#{prefix}/bin/php -v`.lines.first.chomp,
                           command_line: "#{prefix}/bin/php PROGRAM")
        }
      }
    }
  end
end