-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
executable file
·77 lines (62 loc) · 2.38 KB
/
Rakefile
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
task :default => :generate_new_mode_from_excel
desc "Update all the code, based on the spreadsheet in spreadsheet/model.xlsx"
task :generate_new_mode_from_excel => [:clean,'ext/model.c',:put_generated_files_in_right_place,:fix_test_require, :change_last_modified_date]
desc "Generates c version of the model"
file 'ext/model.c' do
require 'excel_to_code'
command = ExcelToC.new
command.excel_file = "spreadsheet/model.xlsx"
command.output_directory = 'ext'
command.output_name = 'model'
command.cells_that_can_be_set_at_runtime = { "Control" => (5.upto(57).to_a.map { |r| "e#{r}" }) }
command.cells_to_keep = {
# The names, limits, 10 worders, long descriptions
"Control" => (5.upto(57).to_a.map { |r| ["d#{r}","f#{r}","h#{r}","i#{r}","j#{r}","k#{r}","bo#{r}","bp#{r}","bq#{r}","br#{r}"] }).flatten,
"Intermediate output" => :all,
"CostPerCapita" => :all,
"Land Use" => :all,
"Flows" => :all,
"AQ Outputs" => :all,
}
# Add the version number
command.cells_to_keep["Control"] << "m1"
# Add the example pathways
rows = (4..60).to_a
('m'..'z').to_a.push('aa','ab').each do |column|
rows.each do |row|
command.cells_to_keep["Control"].push("#{column}#{row}")
end
end
command.actually_compile_code = true
command.actually_run_tests = true
command.run_in_memory = true
command.go!
end
# Put things in their place
task :put_generated_files_in_right_place do
require 'ffi'
libfile = FFI.map_library_name('model')
if File.exists?(File.join('ext',libfile))
mv File.join('ext',libfile), File.join('lib','model',libfile)
end
mv 'ext/model.rb', 'lib/model/model.rb'
mv 'ext/test_model.rb', 'test/test_model.rb'
rm 'ext/Makefile'
end
task :fix_test_require do
test = IO.readlines('test/test_model.rb').join
test.gsub!("require_relative 'model'","require_relative '../lib/model'")
File.open('test/test_model.rb','w') { |f| f.puts test }
end
desc "This updates the Model.last_modified_date attribute to the current time"
task :change_last_modified_date do
File.open('lib/model/model_version.rb','w') do |f|
f.puts "def Model.last_modified_date() @last_modified_date ||= Time.utc(*#{Time.now.to_a}); end"
end
end
desc "Remove all the spreadsheet code, ready to be regenerated"
task :clean do
rm 'lib/model/model.rb', :force => true
rm 'test/test_model.rb', :force => true
rm 'ext/model.c', :force => true
end