Sha256: 475e180c6773e4f4e292bd49e2df13b3a16e4a2304eac9a44f2512ee9b3ee4b0

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

#!/usr/bin/env ruby

ENV["GEM_HOME"] = File.expand_path("../../vendor/gems", __FILE__)
ENV["GEM_PATH"] = File.expand_path("../../vendor/gems", __FILE__)

require "rubygems"

id  = ARGV.shift

require "couchrest"
require "fileutils"
require "tmpdir"
require "rest_client"
 
db = CouchRest.database!(ENV["CLOUDANT_URL"] + "/make")

Dir.mktmpdir do |dir|
  Dir.chdir(dir) do
    doc = db.get(id)

    command = doc["command"]
    prefix = doc["prefix"]
    deps = doc["deps"] || []

    File.open("input.tgz", "wb") do |file|
      file.print doc.fetch_attachment("input")
    end

    deps.each_with_index do |dep, index|
      puts "downloading #{dep}"
      File.open("dep_#{index}.tgz", "wb") do |file|
        begin
          file.print RestClient.get(dep)
        rescue Exception => ex
          puts ex.inspect
        end 
      end
    end
      
    FileUtils.mkdir_p "deps"

    Dir.chdir("deps") do
      deps.each_with_index do |dep, index|
        %x{ tar xzf ../dep_#{index}.tgz 2>&1 }
      end
    end

    unless deps.empty?
      ENV["LDFLAGS"] ||= ""
      ENV["LDFLAGS"] += " -L%s/deps/lib" % dir

      ENV["CFLAGS"] ||= ""
      ENV["CFLAGS"] += " -I%s/deps/include" % dir

      ENV["CXXFLAGS"] ||= ""
      ENV["CXXFLAGS"] += " -I%s/deps/include" % dir
    end

    FileUtils.mkdir_p "input"

    Dir.chdir("input") do
      %x{ tar xzf ../input.tgz 2>&1 }
      system command
    end

    Dir.chdir(prefix) do
      %x{ tar czf #{dir}/output.tgz * 2>&1 }
    end

    begin
      doc.put_attachment("output", File.open("#{dir}/output.tgz"))
    rescue RestClient::Conflict
      # temporarily work around problem with bigcouch
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vulcan-0.8.0 server/bin/make
vulcan-0.7.2 server/bin/make
vulcan-0.7.1 server/bin/make
vulcan-0.7.0 server/bin/make
vulcan-0.6.1 server/bin/make
vulcan-0.6.0 server/bin/make