-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrakefile.rb
289 lines (265 loc) · 8.99 KB
/
rakefile.rb
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
require 'fileutils'
require './rakefile.module.builder'
require './rakefile.module.env'
module PATHS
self::CLI = "./cli"
self::LIB = "./lib"
self::PROTOCOL_TEST = "./tests/protocol"
self::WORKFLOW_TEST = "./tests/workflow"
self::EXAMPLES = "./examples"
self::TRANSPORT = "./environment/transport"
end
namespace :cli do
desc 'Build CLI'
task :build do
Dir.chdir(PATHS::CLI) do
sh 'cargo build --release'
end
end
end
namespace :lib do
namespace :build do
desc 'Build Rust Lib'
task :rs do
Dir.chdir("#{PATHS::LIB}/rust") do
sh 'cargo build --release'
end
end
desc 'Build Typescript Lib'
task :ts do
Dir.chdir("#{PATHS::LIB}/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
task :all => ['rs', 'ts']
end
end
namespace :transport do
namespace :rs do
desc 'Build Rust Server'
task :server do
Dir.chdir("#{PATHS::TRANSPORT}/server/rust") do
sh 'cargo build --release'
end
end
task :client do
Dir.chdir("#{PATHS::TRANSPORT}/client/rust") do
sh 'cargo build --release'
end
end
desc 'Build Server & Client'
task :build => ['server', 'client']
end
namespace :ts do
desc 'Build Rust Server'
task :server do
Dir.chdir("#{PATHS::TRANSPORT}/server/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
task :client do
Dir.chdir("#{PATHS::TRANSPORT}/client/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
desc 'Build Server & Client'
task :build => ['server', 'client']
end
desc 'Build All'
task :build => ['rs:build', 'ts:build']
end
namespace :test do
namespace :protocol do
desc 'Generate Test Protocols'
task :generate do
sh "#{PATHS::CLI}/target/release/clibri --src #{PATHS::PROTOCOL_TEST}/prot/protocol.prot -rs #{PATHS::PROTOCOL_TEST}/rust/src/protocol.rs -ts #{PATHS::PROTOCOL_TEST}/typescript/src/protocol.ts -o --em"
end
desc 'Build Protocol Test Executors'
task :build do
Dir.chdir("#{PATHS::PROTOCOL_TEST}/rust") do
sh 'cargo build --release'
end
Dir.chdir("#{PATHS::PROTOCOL_TEST}/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
desc 'Executing Tests'
task :execute do
errors = []
Dir.chdir("#{PATHS::PROTOCOL_TEST}/typescript") do
begin
sh 'node ./dist/index.js write'
rescue StandardError => e
errors << e
end
end
Dir.chdir("#{PATHS::PROTOCOL_TEST}/rust") do
begin
sh './target/release/clibri_protocol_rust_test write'
rescue StandardError => e
errors << e
end
end
Dir.chdir("#{PATHS::PROTOCOL_TEST}/typescript") do
begin
sh 'node ./dist/index.js read'
rescue StandardError => e
errors << e
end
end
Dir.chdir("#{PATHS::PROTOCOL_TEST}/rust") do
begin
sh './target/release/clibri_protocol_rust_test read'
rescue StandardError => e
errors << e
end
end
es = errors.reduce('') { |acc, e| [acc, e].join('\n') }
raise es unless errors.empty?
end
desc 'Test'
task :all => ['cli:build', 'generate', 'build', 'execute']
end
namespace :examples do
desc 'Producer - rust / Consumer - rust'
task :rs_rs do
Dir.chdir("#{PATHS::EXAMPLES}") do
sh '../cli/target/release/clibri -s ./prot/protocol.prot -wf ./prot/protocol-rs-rs.workflow -cd ./consumer/rust/src/consumer/ -pd ./producer/rust/src/producer/'
end
Dir.chdir("#{PATHS::EXAMPLES}/producer/rust") do
sh 'cargo build --release'
end
Dir.chdir("#{PATHS::EXAMPLES}/consumer/rust") do
sh 'cargo build --release'
end
end
desc 'Producer - typescript / Consumer - typescript'
task :ts_ts do
Dir.chdir("#{PATHS::EXAMPLES}") do
sh '../cli/target/release/clibri -s ./prot/protocol.prot -wf ./prot/protocol-ts-ts.workflow -cd ./consumer/typescript/src/consumer/ -pd ./producer/typescript/src/producer/'
end
Dir.chdir("#{PATHS::EXAMPLES}/producer/typescript") do
sh 'npm install'
sh 'npm run build'
end
Dir.chdir("#{PATHS::EXAMPLES}/consumer/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
desc 'Producer - rust / Consumer - typescript'
task :rs_ts do
Dir.chdir("#{PATHS::EXAMPLES}") do
sh '../cli/target/release/clibri -s ./prot/protocol.prot -wf ./prot/protocol-rs-ts.workflow -cd ./consumer/typescript/src/consumer/ -pd ./producer/rust/src/producer/'
end
Dir.chdir("#{PATHS::EXAMPLES}/producer/rust") do
sh 'cargo build --release'
end
Dir.chdir("#{PATHS::EXAMPLES}/consumer/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
desc 'Create All'
task :create => ['rs_rs', 'ts_ts', 'rs_ts']
end
namespace :workflow do
desc 'Rust test executor'
task :rs_executor do
Dir.chdir("#{PATHS::WORKFLOW_TEST}/executor") do
sh 'cargo build --release'
end
Dir.chdir("#{PATHS::WORKFLOW_TEST}") do
sh './executor/target/release/clibri_test_executor --producer=./run-producer-rs-gitactions.sh --consumer=./run-consumer-rs-gitactions.sh'
end
end
desc 'Producer - rust / Consumer - rust'
task :rs_rs do
Dir.chdir("#{PATHS::WORKFLOW_TEST}") do
sh '../../cli/target/release/clibri -s ./prot/protocol.prot -wf ./prot/protocol-rs-rs.workflow -cd ./consumer/rust/src/consumer/ -pd ./producer/rust/src/producer/'
end
Dir.chdir("#{PATHS::WORKFLOW_TEST}/producer/rust") do
sh 'cargo build --release'
end
Dir.chdir("#{PATHS::WORKFLOW_TEST}/consumer/rust") do
sh 'cargo build --release'
end
end
desc "Test Producer/Consumer - rust"
task :rs_test => ['rs_rs', 'rs_executor']
desc 'TS test executor'
task :ts_executor do
Dir.chdir("#{PATHS::WORKFLOW_TEST}/executor") do
sh 'cargo build --release'
end
Dir.chdir("#{PATHS::WORKFLOW_TEST}") do
sh './executor/target/release/clibri_test_executor --node --producer=./producer/typescript/dist/index.js --consumer=./consumer/typescript/dist/index.js'
end
end
desc 'Producer - typescript / Consumer - typescript'
task :ts_ts do
Dir.chdir("#{PATHS::WORKFLOW_TEST}") do
sh '../../cli/target/release/clibri -s ./prot/protocol.prot -wf ./prot/protocol-ts-ts.workflow -cd ./consumer/typescript/src/consumer/ -pd ./producer/typescript/src/producer/'
end
Dir.chdir("#{PATHS::WORKFLOW_TEST}/producer/typescript") do
sh 'npm install'
sh 'npm run build'
end
Dir.chdir("#{PATHS::WORKFLOW_TEST}/consumer/typescript") do
sh 'npm install'
sh 'npm run build'
end
end
desc "Test Producer/Consumer - rust"
task :ts_test => ['ts_ts', 'ts_executor']
desc 'Test All'
task :all => ['rs_test', 'ts_test']
end
desc 'Test All'
task :all => ['cli:build', 'test:protocol:all', 'test:workflow:all', 'test:examples:create']
end
namespace :clean do
desc 'Clean Lib'
task :lib do
rm_rf("#{PATHS::LIB}/rust/target", verbose: true)
rm_rf("#{PATHS::LIB}/typescript/node_modules", verbose: true)
rm_rf("#{PATHS::LIB}/typescript/dist", verbose: true)
# rm("#{PATHS::LIB}/typescript/package-lock.json", verbose: true) unless !Dir.exist?("#{PATHS::LIB}/typescript/package-lock.json")
end
task :cli do
rm_rf("#{PATHS::CLI}/target", verbose: true)
end
task :examples do
rm_rf("#{PATHS::EXAMPLES}/producer/rust/target", verbose: true)
rm_rf("#{PATHS::EXAMPLES}/consumer/rust/target", verbose: true)
rm_rf("#{PATHS::EXAMPLES}/producer/typescript/node_modules", verbose: true)
rm_rf("#{PATHS::EXAMPLES}/producer/typescript/dist", verbose: true)
rm_rf("#{PATHS::EXAMPLES}/consumer/typescript/node_modules", verbose: true)
rm_rf("#{PATHS::EXAMPLES}/consumer/typescript/dist", verbose: true)
end
task :transport do
rm_rf("#{PATHS::TRANSPORT}/server/rust/target", verbose: true)
rm_rf("#{PATHS::TRANSPORT}/client/rust/target", verbose: true)
rm_rf("#{PATHS::TRANSPORT}/server/typescript/node_modules", verbose: true)
rm_rf("#{PATHS::TRANSPORT}/server/typescript/dist", verbose: true)
rm_rf("#{PATHS::TRANSPORT}/client/typescript/node_modules", verbose: true)
rm_rf("#{PATHS::TRANSPORT}/client/typescript/dist", verbose: true)
end
task :protocol_test do
rm_rf("#{PATHS::PROTOCOL_TEST}/rust/target", verbose: true)
rm_rf("#{PATHS::PROTOCOL_TEST}/rust/binary", verbose: true)
rm_rf("#{PATHS::PROTOCOL_TEST}/typescript/node_modules", verbose: true)
rm_rf("#{PATHS::PROTOCOL_TEST}/typescript/dist", verbose: true)
rm_rf("#{PATHS::PROTOCOL_TEST}/typescript/binary", verbose: true)
end
task :all => ['lib', 'cli', 'examples', 'transport', 'protocol_test']
end
desc 'Release CLI'
task :release do
@builder = Builder.new
@builder.build
end