-
Notifications
You must be signed in to change notification settings - Fork 5
/
shared_library_task.feature
209 lines (197 loc) · 7.83 KB
/
shared_library_task.feature
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
Feature: PaperHouse::SharedLibraryTask
PaperHouse provides a rake task called
`PaperHouse::SharedLibraryTask` to build a shared library from *.c
and *.h files. These source files can be located in multiple
subdirectories.
@linux
Scenario: Build a shared library from one *.c and *.h file
Given the current project directory is "examples/shared_library"
When I successfully run `rake hello`
Then the output should contain:
"""
gcc -H -fPIC -I. -c hello.c -o ./hello.o
gcc -H -fPIC -I. -c main.c -o ./main.o
gcc -shared -Wl,-soname,libhello.so.0 -o ./libhello.so.0.1.0 ./hello.o -lm
ln -s libhello.so.0.1.0 libhello.so
ln -s libhello.so.0.1.0 libhello.so.0
gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@mac
Scenario: Build a shared library from one *.c and *.h file
Given the current project directory is "examples/shared_library"
When I successfully run `rake hello`
Then the output should contain:
"""
gcc -H -fPIC -I. -c hello.c -o ./hello.o
gcc -H -fPIC -I. -c main.c -o ./main.o
gcc -shared -Wl,-install_name,libhello.so.0 -o ./libhello.so.0.1.0 ./hello.o -lm
ln -s libhello.so.0.1.0 libhello.so
ln -s libhello.so.0.1.0 libhello.so.0
gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@linux
Scenario: Build a shared library from one *.c and *.h file using llvm-gcc by specifying `CC=` option
Given the current project directory is "examples/shared_library"
When I successfully run `rake hello CC=llvm-gcc`
Then the output should contain:
"""
llvm-gcc -H -fPIC -I. -c hello.c -o ./hello.o
llvm-gcc -H -fPIC -I. -c main.c -o ./main.o
llvm-gcc -shared -Wl,-soname,libhello.so.0 -o ./libhello.so.0.1.0 ./hello.o -lm
ln -s libhello.so.0.1.0 libhello.so
ln -s libhello.so.0.1.0 libhello.so.0
llvm-gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@mac
Scenario: Build a shared library from one *.c and *.h file using llvm-gcc by specifying `CC=` option
Given the current project directory is "examples/shared_library"
When I successfully run `rake hello CC=llvm-gcc`
Then the output should contain:
"""
llvm-gcc -H -fPIC -I. -c hello.c -o ./hello.o
llvm-gcc -H -fPIC -I. -c main.c -o ./main.o
llvm-gcc -shared -Wl,-install_name,libhello.so.0 -o ./libhello.so.0.1.0 ./hello.o -lm
ln -s libhello.so.0.1.0 libhello.so
ln -s libhello.so.0.1.0 libhello.so.0
llvm-gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@linux
Scenario: Build a shared library from one *.c and *.h file using llvm-gcc
Given the current project directory is "examples/shared_library"
When I successfully run `rake -f Rakefile.llvm hello`
Then the output should contain:
"""
llvm-gcc -H -fPIC -I. -c hello.c -o ./hello.o
llvm-gcc -H -fPIC -I. -c main.c -o ./main.o
llvm-gcc -shared -Wl,-soname,libhello.so.0 -o ./libhello.so.0.1.0 ./hello.o -lm
ln -s libhello.so.0.1.0 libhello.so
ln -s libhello.so.0.1.0 libhello.so.0
llvm-gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@mac
Scenario: Build a shared library from one *.c and *.h file using llvm-gcc
Given the current project directory is "examples/shared_library"
When I successfully run `rake -f Rakefile.llvm hello`
Then the output should contain:
"""
llvm-gcc -H -fPIC -I. -c hello.c -o ./hello.o
llvm-gcc -H -fPIC -I. -c main.c -o ./main.o
llvm-gcc -shared -Wl,-install_name,libhello.so.0 -o ./libhello.so.0.1.0 ./hello.o -lm
ln -s libhello.so.0.1.0 libhello.so
ln -s libhello.so.0.1.0 libhello.so.0
llvm-gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@linux
Scenario: Build a shared library from multiple *.c and *.h files in subcirectories
Given the current project directory is "examples/shared_library_subdirs"
When I successfully run `rake hello`
Then the output should contain:
"""
gcc -H -Werror -Wall -Wextra -fPIC -Iincludes -Isources -c sources/hello.c -o objects/hello.o
gcc -H -fPIC -Iincludes -Isources -c sources/main.c -o ./main.o
mkdir -p objects
gcc -shared -Wl,-soname,libhello.so.0 -o objects/libhello.so.0.1.0 objects/hello.o
ln -s objects/libhello.so.0.1.0 libhello.so
ln -s objects/libhello.so.0.1.0 libhello.so.0
gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "objects/libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
@mac
Scenario: Build a shared library from multiple *.c and *.h files in subcirectories
Given the current project directory is "examples/shared_library_subdirs"
When I successfully run `rake hello`
Then the output should contain:
"""
gcc -H -Werror -Wall -Wextra -fPIC -Iincludes -Isources -c sources/hello.c -o objects/hello.o
gcc -H -fPIC -Iincludes -Isources -c sources/main.c -o ./main.o
mkdir -p objects
gcc -shared -Wl,-install_name,libhello.so.0 -o objects/libhello.so.0.1.0 objects/hello.o
ln -s objects/libhello.so.0.1.0 libhello.so
ln -s objects/libhello.so.0.1.0 libhello.so.0
gcc -o ./hello ./main.o -L. -lhello
"""
And a file named "objects/libhello.so.0.1.0" should exist
And a file named "hello" should exist
And I successfully run `./hello`
And the output should contain:
"""
Hello, PaperHouse!
"""
Scenario: Automatically rebuild an executable when dependent library is updated
Given the current project directory is "examples/shared_library"
And I successfully run `rake hello`
And I successfully run `sleep 1`
And I successfully run `touch libhello.so.0`
When I successfully run `rake hello`
Then the output should contain:
"""
gcc -o ./hello ./main.o -L. -lhello
"""
Scenario: Clean
Given the current project directory is "examples/shared_library"
When I successfully run `rake hello`
When I successfully run `rake clean`
Then a file named "hello.o" should not exist
And a file named "main.o" should not exist
And a file named ".libhello.depends" should exist
And a file named ".hello.depends" should exist
And a file named "libhello.so.0.1.0" should exist
And a file named "hello" should exist
Scenario: Clobber
Given the current project directory is "examples/shared_library"
When I successfully run `rake hello`
When I successfully run `rake clobber`
Then a file named "hello.o" should not exist
And a file named "main.o" should not exist
And a file named ".libhello.depends" should not exist
And a file named ".hello.depends" should not exist
And a file named "libhello.so.0.1.0" should not exist
And a file named "hello" should not exist