-
Notifications
You must be signed in to change notification settings - Fork 75
/
Rakefile
107 lines (84 loc) · 2.32 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby
# -*- ruby -*-
require 'fileutils'
SRC_DIR = 'src'
MISSION_DIR = 'missions'
SRC_FILES = FileList["#{SRC_DIR}/*"]
MISSION_FILES = SRC_FILES.pathmap("#{MISSION_DIR}/%f")
module Missions
# Remove solution info from source
# __(a,b) => __
def Missions.remove_solution(line)
line = line.gsub(/\b__\([^\)]+\)/, "__")
line
end
def Missions.make_mission_file(infile, outfile)
if infile =~ /lib/
FileUtils::cp_r infile, outfile
else
open(infile) do |ins|
open(outfile, "w") do |outs|
state = :copy
ins.each do |line|
state = :skip if line =~ /^ *-- begin skip/
case state
when :copy
outs.puts remove_solution(line)
else
# do nothing
end
state = :copy if line =~ /^ *-- end skip/
end
end
end
end
end
end
task :default => 'missions:run'
namespace :missions do
desc "Trying to execute the missions"
task :run do
cd 'missions'
sh 'lua missions.lua'
end
desc "Execute the solved missions"
task :run_src do
cd 'src'
sh 'lua missions.lua'
end
desc "Generate the Missions from the source files from scratch."
task :regen => ['missions:delete', 'missions:gen']
desc "Generate the Missions from the changed source files."
task :gen => MISSION_FILES
desc "Delete the generated mission files"
task :delete do
rm_rf MISSION_DIR
end
end
directory MISSION_DIR
SRC_FILES.each do |mission_src|
file mission_src.pathmap("#{MISSION_DIR}/%f") => [MISSION_DIR, mission_src] do |t|
Missions.make_mission_file mission_src, t.name
end
end
namespace :git do
def commit_message
return ENV['m'] if ENV['m']
raise "Commit message expected. Sample:\n rake git:commit m='your commit message'"
end
desc "regenerate missions & push to the git repository"
task :release => ['missions:regen', 'git:add', 'git:commit', 'git:push']
desc "add all the modifications to the git repository, including deletions"
task :add do
sh 'git add .'
sh 'git ls-files -z -d | xargs -0 --no-run-if-empty git rm'
end
desc "Commit with a message"
task :commit do
sh "git commit -m #{commit_message.inspect}"
end
desc "Push to origin"
task :push do
sh "git push origin master"
end
end