This repository has been archived by the owner on Nov 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile
65 lines (51 loc) · 1.63 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
require 'rake/clean'
CLEAN.include 'tmp/', '*/**.o'
CLOBBER << 'build/'
main = 'src/main.c'
src_files = Rake::FileList['src/*.c'].exclude main
obj_files = src_files.ext '.o'
test_files = Rake::FileList['test/*.c'].exclude 'test/Unity'
UNITY = 'test/Unity/src/unity.c'
BUILD_FLAGS = '-std=c99 -g -Wall -Wextra -pedantic -Werror'
TEST_FLAGS = '-std=c99 -Wall'
MEM_FLAGS = '--quiet --tool=memcheck --leak-check=full --error-exitcode=1'
task :default do
sh 'rake -T', :verbose => false
end
desc 'Build and run the executable'
task :run => %i[build] do
sh 'build/main'
end
desc 'Build the executable'
task :build => ['build/main', :clean]
# Compile the executable into `build/`
file 'build/main' => obj_files do |task|
sh "gcc #{obj_files.sub('src', 'build')} #{main} -o #{task.name.sub('src', 'build')}"
end
# Create object files in `build/` from source files in `src`
rule '.o' => '.c' do |task|
mkdir_p 'build'
sh "gcc #{BUILD_FLAGS} -c #{task.source} -o #{task.name.sub('src', 'build')}"
end
desc 'Run the feature tests'
task :cucumber => %i[build] do
sh 'cucumber'
sh 'rake clean', :verbose => false
end
desc 'Run the unit tests'
task :test => [:build, 'build/test'] do
sh 'build/test'
end
# Creates the test executable in `build`
file 'build/test' do |task|
sh "gcc #{TEST_FLAGS} #{test_files} #{src_files} #{UNITY} -o build/test"
end
desc 'Check for memory leaks'
task :memcheck => ['build/test', :clean] do
abort 'You need valgrind to run the memory check!' if %x[which valgrind] == ''
sh "valgrind #{MEM_FLAGS} build/test"
end
desc "Output the project directory using 'tree'"
task :tree do
sh "tree -a -I 'Unity|.git'"
end