This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
/
make
executable file
·80 lines (60 loc) · 1.71 KB
/
make
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
78
79
80
#!/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["PATH"] ||= ""
ENV["PATH"] += ":%s/deps/bin" % dir
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