rubu 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +236 -8
- data/doc/Array.html +103 -38
- data/doc/Rubu.html +2 -2
- data/doc/Rubu/AgedStep.html +275 -0
- data/doc/Rubu/AlwaysStep.html +275 -0
- data/doc/Rubu/Fork.html +20 -20
- data/doc/Rubu/Info.html +39 -13
- data/doc/Rubu/Mark.html +318 -110
- data/doc/Rubu/MarkStep.html +275 -0
- data/doc/Rubu/Move.html +937 -0
- data/doc/Rubu/MoveStyles.html +403 -0
- data/doc/Rubu/Order.html +39 -13
- data/doc/Rubu/RubyCommand.html +39 -26
- data/doc/Rubu/ShellCommand.html +37 -24
- data/doc/Rubu/State.html +135 -38
- data/doc/Rubu/Step.html +1859 -0
- data/doc/Rubu/StepAged.html +279 -0
- data/doc/Rubu/StepAlways.html +279 -0
- data/doc/Rubu/StepMark.html +279 -0
- data/doc/Rubu/Trail.html +1022 -0
- data/doc/Rubu/TrailRun.html +377 -0
- data/doc/Rubu/Var.html +39 -13
- data/doc/Rubu/Walk.html +16 -16
- data/doc/_index.html +51 -59
- data/doc/class_list.html +1 -1
- data/doc/file.CHANGELOG.html +5 -2
- data/doc/file.README.html +255 -8
- data/doc/index.html +255 -8
- data/doc/method_list.html +88 -88
- data/doc/top-level-namespace.html +1 -1
- data/example/bin/rubu_example +49 -51
- data/example/build/hello +0 -0
- data/example/build/hello_world.o +0 -0
- data/example/build/world.c +6 -0
- data/example/build/world.o +0 -0
- data/lib/rubu.rb +168 -85
- data/lib/version.rb +1 -1
- metadata +17 -2
@@ -105,7 +105,7 @@
|
|
105
105
|
</div>
|
106
106
|
|
107
107
|
<div id="footer">
|
108
|
-
Generated on
|
108
|
+
Generated on Sun Jul 1 17:48:17 2018 by
|
109
109
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
110
|
0.8.7.6 (ruby-2.3.3).
|
111
111
|
</div>
|
data/example/bin/rubu_example
CHANGED
@@ -13,7 +13,7 @@ Spec.command( 'rubu_example', 'Tero Isannainen', '2018',
|
|
13
13
|
[ :opt_multi, 'conf', '-c', "Configuration option." ],
|
14
14
|
[ :switch, 'verbose', '-v', "Verbose." ],
|
15
15
|
[ :switch, 'serial', '-s', "Serial execution." ],
|
16
|
-
[ :default, nil, nil, "
|
16
|
+
[ :default, nil, nil, "Trail(s) to execute." ],
|
17
17
|
] )
|
18
18
|
|
19
19
|
|
@@ -21,7 +21,7 @@ Spec.command( 'rubu_example', 'Tero Isannainen', '2018',
|
|
21
21
|
# ------------------------------------------------------------
|
22
22
|
# Build specific definitions:
|
23
23
|
|
24
|
-
# Set
|
24
|
+
# Set trail related options.
|
25
25
|
Var[ :bin_dir ] = 'bin'
|
26
26
|
Var[ :source_dir ] = 'src'
|
27
27
|
Var[ :build_dir ] = 'build'
|
@@ -36,7 +36,31 @@ if Opt['verbose'].given
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Read setup files and apply Como command line arguments to Var space.
|
39
|
-
|
39
|
+
Trail.setup( :como => 'conf' )
|
40
|
+
|
41
|
+
|
42
|
+
# ------------------------------------------------------------
|
43
|
+
# Collect sources and create targets:
|
44
|
+
|
45
|
+
# Generator file and the target.
|
46
|
+
gen_file = Mark.path( "#{Var[:bin_dir]}/gen_world" )
|
47
|
+
gen_cee_file = Mark.path( "#{Var[:build_dir]}/world.c" )
|
48
|
+
|
49
|
+
# Collect "normal" C files.
|
50
|
+
cee_files = Mark.glob( "#{Var[:source_dir]}/*.c" )
|
51
|
+
|
52
|
+
# Create complete list of all C files.
|
53
|
+
all_cee_files = [ gen_cee_file ] + cee_files
|
54
|
+
|
55
|
+
# Convert C files to corresponding Object files.
|
56
|
+
obj_files = all_cee_files.peer( Var[ :build_dir ], '.o' )
|
57
|
+
|
58
|
+
# Specify executable file.
|
59
|
+
exe_file = Mark.path( Var[ :exe_name ] )
|
60
|
+
|
61
|
+
|
62
|
+
# Generate execution time information to Info. Used by CleanObjects.
|
63
|
+
Info[ :gen_files ] = [ gen_cee_file ]
|
40
64
|
|
41
65
|
|
42
66
|
|
@@ -44,15 +68,15 @@ Flow.setup( :como => 'conf' )
|
|
44
68
|
# Build Commands:
|
45
69
|
|
46
70
|
# Code generator with generated file dependency.
|
47
|
-
class GenWorld <
|
48
|
-
def
|
71
|
+
class GenWorld < Step
|
72
|
+
def step
|
49
73
|
shrun "bin/gen_world"
|
50
74
|
end
|
51
75
|
end
|
52
76
|
|
53
77
|
|
54
78
|
# Typical C compilation with GCC, from source to object.
|
55
|
-
class GccCompileFile <
|
79
|
+
class GccCompileFile < StepAged
|
56
80
|
|
57
81
|
def setup
|
58
82
|
@cmd = "gcc -Wall -I #{Var[:source_dir]} -c #{source.rpath} -o #{target.rpath}"
|
@@ -65,36 +89,36 @@ class GccCompileFile < DateBuild
|
|
65
89
|
end
|
66
90
|
end
|
67
91
|
|
68
|
-
def
|
92
|
+
def step
|
69
93
|
shrun @cmd
|
70
94
|
end
|
71
95
|
end
|
72
96
|
|
73
97
|
|
74
98
|
# GCC linking.
|
75
|
-
class GccLinkExe <
|
99
|
+
class GccLinkExe < StepAged
|
76
100
|
|
77
101
|
def setup
|
78
102
|
@cmd = "gcc #{sources.rpath} -o #{target.rpath}"
|
79
103
|
end
|
80
104
|
|
81
|
-
def
|
105
|
+
def step
|
82
106
|
shrun @cmd
|
83
107
|
end
|
84
108
|
end
|
85
109
|
|
86
110
|
|
87
111
|
# Cleaning.
|
88
|
-
class CleanObjects <
|
112
|
+
class CleanObjects < Step
|
89
113
|
|
90
|
-
def
|
114
|
+
def step
|
91
115
|
# Multiple jobs are grouped with walk (serial execution).
|
92
116
|
walk do
|
93
|
-
|
94
|
-
|
117
|
+
shuse "rm -f #{Info[ :gen_files ].rpath}"
|
118
|
+
shuse "rm -f #{Var[ :build_dir ]}/*.o"
|
95
119
|
|
96
120
|
# Use Ruby for deleting the exe as an example.
|
97
|
-
|
121
|
+
rbuse "rm -f #{Var[ :exe_name ]}" do
|
98
122
|
FileUtils.rm_f Var[ :exe_name ]
|
99
123
|
end
|
100
124
|
end
|
@@ -102,36 +126,10 @@ class CleanObjects < Build
|
|
102
126
|
end
|
103
127
|
|
104
128
|
|
105
|
-
|
106
|
-
# ------------------------------------------------------------
|
107
|
-
# Collect sources and create targets:
|
108
|
-
|
109
|
-
# Generator file and the target.
|
110
|
-
gen_file = Mark.path( "#{Var[:bin_dir]}/gen_world" )
|
111
|
-
gen_cee_file = Mark.path( "#{Var[:build_dir]}/world.c" )
|
112
|
-
|
113
|
-
# Collect "normal" C files.
|
114
|
-
cee_files = Mark.glob( "#{Var[:source_dir]}/*.c" )
|
115
|
-
|
116
|
-
# Create list of all C files.
|
117
|
-
all_cee_files = [ gen_cee_file ] + cee_files
|
118
|
-
|
119
|
-
# Convert C files to corresponding Object files.
|
120
|
-
obj_files = all_cee_files.peer( Var[ :build_dir ], '.o' )
|
121
|
-
|
122
|
-
# Specify executable file.
|
123
|
-
exe_file = Mark.path( Var[ :exe_name ] )
|
124
|
-
|
125
|
-
|
126
|
-
# Generate execution time information to Info. Used by CleanObjects.
|
127
|
-
Info[ :gen_files ] = [ gen_cee_file ]
|
128
|
-
|
129
|
-
|
130
|
-
|
131
129
|
# ------------------------------------------------------------
|
132
|
-
# Define
|
130
|
+
# Define trails:
|
133
131
|
|
134
|
-
# Serial
|
132
|
+
# Serial trail for code generation.
|
135
133
|
Walk.form 'gen-cee' do
|
136
134
|
# Create GenWorld build and register it to 'gen-cee'.
|
137
135
|
GenWorld.use( gen_file, gen_cee_file )
|
@@ -144,17 +142,17 @@ Fork.form 'compile-cee' do
|
|
144
142
|
GccCompileFile.usezip( all_cee_files, obj_files )
|
145
143
|
end
|
146
144
|
|
147
|
-
# Default
|
145
|
+
# Default trail, i.e. generate, compile, link to executable.
|
148
146
|
Walk.form 'default' do
|
149
|
-
# Reference 'gen-cee'
|
147
|
+
# Reference 'gen-cee' trail.
|
150
148
|
pick 'gen-cee'
|
151
|
-
# Reference 'compile-cee'
|
149
|
+
# Reference 'compile-cee' trail.
|
152
150
|
pick 'compile-cee'
|
153
151
|
# Create GCC link build and register it.
|
154
152
|
GccLinkExe.use( obj_files, exe_file )
|
155
153
|
end
|
156
154
|
|
157
|
-
# Cleaner
|
155
|
+
# Cleaner trail.
|
158
156
|
Walk.form 'clean' do
|
159
157
|
CleanObjects.use
|
160
158
|
end
|
@@ -162,17 +160,17 @@ end
|
|
162
160
|
|
163
161
|
|
164
162
|
# ------------------------------------------------------------
|
165
|
-
# Run selected
|
163
|
+
# Run selected trails:
|
166
164
|
|
167
|
-
|
165
|
+
trails = nil
|
168
166
|
if Opt[ nil ].given
|
169
|
-
|
167
|
+
trails = Opt[ nil ].value
|
170
168
|
else
|
171
|
-
|
169
|
+
trails = [ 'default' ]
|
172
170
|
end
|
173
171
|
|
174
172
|
if Opt[ 'serial' ].given
|
175
173
|
Order[ :serial ] = true
|
176
174
|
end
|
177
175
|
|
178
|
-
|
176
|
+
Trail.run( trails )
|
data/example/build/hello
ADDED
Binary file
|
Binary file
|
Binary file
|
data/lib/rubu.rb
CHANGED
@@ -5,27 +5,39 @@ require 'digest/md5'
|
|
5
5
|
|
6
6
|
module Rubu
|
7
7
|
|
8
|
+
# Persistent state of Rubu.
|
9
|
+
#
|
10
|
+
# State maintains YAML based state file (if in use). The file
|
11
|
+
# include MD5 checksums of file content.
|
8
12
|
class State
|
9
13
|
|
10
14
|
@@md5 = {}
|
11
15
|
@@state_file = ".rubu_state.yml"
|
12
16
|
|
17
|
+
# Save state.
|
13
18
|
def State.save
|
14
19
|
if @@md5.any?
|
15
20
|
IO.write( @@state_file, YAML.dump( @@md5 ) )
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
24
|
+
# Load state.
|
19
25
|
def State.load
|
20
26
|
if File.exist?( @@state_file )
|
21
27
|
@@md5 = YAML.load_file( @@state_file )
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
31
|
+
# Generate MD5 checksum for file.
|
32
|
+
#
|
33
|
+
# @param file File.
|
25
34
|
def State.md5_gen( file )
|
26
35
|
Digest::MD5.hexdigest( File.read( file ) )
|
27
36
|
end
|
28
37
|
|
38
|
+
# Check for existing checksum and update it if needed.
|
39
|
+
#
|
40
|
+
# @param file File.
|
29
41
|
def State.md5_check_and_update?( file )
|
30
42
|
if @@md5[ file ]
|
31
43
|
md5 = State.md5_gen( file )
|
@@ -43,8 +55,8 @@ module Rubu
|
|
43
55
|
end
|
44
56
|
|
45
57
|
|
46
|
-
#
|
47
|
-
class
|
58
|
+
# Move is the action in Step.
|
59
|
+
class Move
|
48
60
|
|
49
61
|
@@host = []
|
50
62
|
|
@@ -68,23 +80,18 @@ module Rubu
|
|
68
80
|
@subs = []
|
69
81
|
end
|
70
82
|
|
71
|
-
# Register
|
83
|
+
# Register Move to host (upper level).
|
72
84
|
def use
|
73
85
|
host.subs.push( self ) if host
|
74
86
|
self
|
75
87
|
end
|
76
88
|
|
77
|
-
#
|
78
|
-
def pick( flow )
|
79
|
-
Flow[ flow ].use
|
80
|
-
end
|
81
|
-
|
82
|
-
# Push host.
|
89
|
+
# Push host as current to host stack.
|
83
90
|
def host_in
|
84
91
|
@@host.push self
|
85
92
|
end
|
86
93
|
|
87
|
-
# Pop host.
|
94
|
+
# Pop host from host stack.
|
88
95
|
def host_out
|
89
96
|
@@host.pop
|
90
97
|
end
|
@@ -110,13 +117,14 @@ module Rubu
|
|
110
117
|
|
111
118
|
|
112
119
|
# Shell based command.
|
113
|
-
class ShellCommand <
|
120
|
+
class ShellCommand < Move
|
114
121
|
|
115
122
|
def initialize( cmd )
|
116
123
|
super()
|
117
124
|
@cmd = cmd
|
118
125
|
end
|
119
126
|
|
127
|
+
# Execution content.
|
120
128
|
def run
|
121
129
|
begin
|
122
130
|
stdout, stderr, status = Open3.capture3( @cmd )
|
@@ -145,7 +153,7 @@ module Rubu
|
|
145
153
|
|
146
154
|
|
147
155
|
# Ruby based command.
|
148
|
-
class RubyCommand <
|
156
|
+
class RubyCommand < Move
|
149
157
|
|
150
158
|
def initialize( desc = nil, &cmd )
|
151
159
|
super()
|
@@ -153,6 +161,7 @@ module Rubu
|
|
153
161
|
@cmd = cmd
|
154
162
|
end
|
155
163
|
|
164
|
+
# Execution content.
|
156
165
|
def run
|
157
166
|
begin
|
158
167
|
ret = instance_eval( &@cmd )
|
@@ -170,9 +179,10 @@ module Rubu
|
|
170
179
|
end
|
171
180
|
|
172
181
|
|
173
|
-
#
|
174
|
-
module
|
182
|
+
# Trail/Step execution styles.
|
183
|
+
module MoveStyles
|
175
184
|
|
185
|
+
# Run @subs in sequence.
|
176
186
|
def serial_run
|
177
187
|
@subs.each do |sub|
|
178
188
|
sub.run
|
@@ -186,6 +196,7 @@ module Rubu
|
|
186
196
|
self
|
187
197
|
end
|
188
198
|
|
199
|
+
# Run @subs in parallel (unless serial is forced).
|
189
200
|
def parallel_run
|
190
201
|
|
191
202
|
if Order[ :serial ]
|
@@ -252,11 +263,27 @@ module Rubu
|
|
252
263
|
end
|
253
264
|
|
254
265
|
|
255
|
-
# Source or Target file for
|
266
|
+
# Source or Target file for Step commands. Rubu handles only
|
256
267
|
# Marks, and hence bare file names are not usable.
|
268
|
+
#
|
269
|
+
# Mark includes both relative and absolute paths for the file.
|
257
270
|
class Mark
|
258
271
|
|
272
|
+
# Convert file path to Mark.
|
273
|
+
#
|
274
|
+
# @param file_path Relative or absolute path of file.
|
275
|
+
def Mark.path( file_path )
|
276
|
+
path = File.absolute_path( file_path )
|
277
|
+
dir = File.dirname( path ).split( '/' )
|
278
|
+
rdir = dir - Dir.pwd.split( '/' )
|
279
|
+
ext = File.extname( path )
|
280
|
+
base = File.basename( path, ext )
|
281
|
+
Mark.new( rdir, base, ext )
|
282
|
+
end
|
283
|
+
|
259
284
|
# Convert a list of file names to Marks.
|
285
|
+
#
|
286
|
+
# @param files List of files to convert to Marks.
|
260
287
|
def Mark.list( files )
|
261
288
|
unless files.kind_of? Array
|
262
289
|
files = [ files ]
|
@@ -264,21 +291,14 @@ module Rubu
|
|
264
291
|
files.map{ |file| Mark.path( file ) }
|
265
292
|
end
|
266
293
|
|
267
|
-
# Convert a list of file names matched with pattern to
|
294
|
+
# Convert a list of file names matched with glob pattern to
|
295
|
+
# Marks.
|
296
|
+
#
|
297
|
+
# @param pattern Glob pattern.
|
268
298
|
def Mark.glob( pattern )
|
269
299
|
Mark.list( Dir.glob( pattern ) )
|
270
300
|
end
|
271
301
|
|
272
|
-
# Convert file path to Mark.
|
273
|
-
def Mark.path( file_path )
|
274
|
-
path = File.absolute_path( file_path )
|
275
|
-
dir = File.dirname( path ).split( '/' )
|
276
|
-
rdir = dir - Dir.pwd.split( '/' )
|
277
|
-
ext = File.extname( path )
|
278
|
-
base = File.basename( path, ext )
|
279
|
-
Mark.new( rdir, base, ext )
|
280
|
-
end
|
281
|
-
|
282
302
|
|
283
303
|
# Absolute directory.
|
284
304
|
attr_reader :dir
|
@@ -292,10 +312,15 @@ module Rubu
|
|
292
312
|
# File extension.
|
293
313
|
attr_reader :ext
|
294
314
|
|
295
|
-
# Skip file.
|
315
|
+
# Skip file in Step.
|
296
316
|
attr_accessor :skip
|
297
317
|
|
298
318
|
|
319
|
+
# Create Mark object.
|
320
|
+
#
|
321
|
+
# @param rdir Relative file path.
|
322
|
+
# @param base Basename of file.
|
323
|
+
# @param ext File extension (suffix).
|
299
324
|
def initialize( rdir, base, ext )
|
300
325
|
if rdir.kind_of? Array
|
301
326
|
@dir = File.absolute_path( rdir.join( '/' ) ).split( '/' )
|
@@ -310,35 +335,41 @@ module Rubu
|
|
310
335
|
@skip = false
|
311
336
|
end
|
312
337
|
|
313
|
-
# Get options.
|
338
|
+
# Get options with key.
|
314
339
|
def []( key )
|
315
340
|
@opt[ key ]
|
316
341
|
end
|
317
342
|
|
318
|
-
# Set
|
343
|
+
# Set option.
|
319
344
|
def []=( key, val )
|
320
345
|
@opt[ key ] = val
|
321
346
|
end
|
322
347
|
|
323
|
-
# Set
|
348
|
+
# Set option.
|
324
349
|
def set_opt( key, val )
|
325
350
|
@opt[ key ] = val
|
326
351
|
self
|
327
352
|
end
|
328
353
|
|
329
354
|
# Return absolute path.
|
330
|
-
|
331
|
-
|
355
|
+
#
|
356
|
+
# @param ext Use this extensions instead, if given.
|
357
|
+
def path( ext = @ext )
|
332
358
|
"#{@dir.join('/')}/#{@base}#{ext}"
|
333
359
|
end
|
334
360
|
|
335
361
|
# Return relative path.
|
336
|
-
|
337
|
-
|
362
|
+
#
|
363
|
+
# @param ext Use this extensions instead, if given.
|
364
|
+
def rpath( ext = @ext )
|
338
365
|
"#{@rdir.join('/')}/#{@base}#{ext}"
|
339
366
|
end
|
340
367
|
|
341
368
|
# Return peer of Mark.
|
369
|
+
#
|
370
|
+
# @param rdir Relative path of peer.
|
371
|
+
# @param ext Extension of peer.
|
372
|
+
# @param base Optional basename of peer (use original if not given).
|
342
373
|
def peer( rdir, ext, base = nil )
|
343
374
|
base ||= @base
|
344
375
|
Mark.new( rdir, base, ext )
|
@@ -349,7 +380,7 @@ module Rubu
|
|
349
380
|
File.exist?( path )
|
350
381
|
end
|
351
382
|
|
352
|
-
# Mark
|
383
|
+
# Mark update time.
|
353
384
|
def time
|
354
385
|
File.stat( path ).mtime
|
355
386
|
end
|
@@ -362,10 +393,12 @@ module Rubu
|
|
362
393
|
|
363
394
|
@@order = {}
|
364
395
|
|
396
|
+
# Set Order entry value.
|
365
397
|
def Order.[]=( key, val )
|
366
398
|
@@order[ key ] = val
|
367
399
|
end
|
368
400
|
|
401
|
+
# Get Order entry value.
|
369
402
|
def Order.[]( key )
|
370
403
|
@@order[ key ]
|
371
404
|
end
|
@@ -373,7 +406,7 @@ module Rubu
|
|
373
406
|
|
374
407
|
# Order defaults:
|
375
408
|
|
376
|
-
# Force serial
|
409
|
+
# Force serial trail.
|
377
410
|
Order[ :serial ] = false
|
378
411
|
|
379
412
|
# Maximun parallel runs (0 for no limit).
|
@@ -390,10 +423,12 @@ module Rubu
|
|
390
423
|
|
391
424
|
@@var = {}
|
392
425
|
|
426
|
+
# Set Var entry value.
|
393
427
|
def Var.[]=( key, val )
|
394
428
|
@@var[ key ] = val
|
395
429
|
end
|
396
430
|
|
431
|
+
# Get Var entry value.
|
397
432
|
def Var.[]( key )
|
398
433
|
@@var[ key ]
|
399
434
|
end
|
@@ -406,10 +441,12 @@ module Rubu
|
|
406
441
|
|
407
442
|
@@info = {}
|
408
443
|
|
444
|
+
# Set Info entry value.
|
409
445
|
def Info.[]=( key, val )
|
410
446
|
@@info[ key ] = val
|
411
447
|
end
|
412
448
|
|
449
|
+
# Get Info entry value.
|
413
450
|
def Info.[]( key )
|
414
451
|
@@info[ key ]
|
415
452
|
end
|
@@ -417,18 +454,24 @@ module Rubu
|
|
417
454
|
end
|
418
455
|
|
419
456
|
|
420
|
-
#
|
457
|
+
# Step in Trail. Step takes one or more sources, and turns
|
421
458
|
# them into one or more targets.
|
422
|
-
class
|
459
|
+
class Step < Move
|
423
460
|
|
424
|
-
include
|
461
|
+
include MoveStyles
|
425
462
|
|
426
|
-
# Create
|
463
|
+
# Create Move and register.
|
464
|
+
#
|
465
|
+
# @param sources One or more sources.
|
466
|
+
# @param targets One or more targets.
|
427
467
|
def self.use( sources = [], targets = [] )
|
428
468
|
self.new( sources, targets ).use
|
429
469
|
end
|
430
470
|
|
431
471
|
# Combine list of sources and targets to source/target pairs.
|
472
|
+
#
|
473
|
+
# @param sources List of sources.
|
474
|
+
# @param targets List of targets.
|
432
475
|
def self.zip( sources, targets )
|
433
476
|
sources.zip( targets ).map do |pair|
|
434
477
|
self.new( *pair )
|
@@ -437,6 +480,9 @@ module Rubu
|
|
437
480
|
|
438
481
|
# Combine list of sources and targets to source/target pairs
|
439
482
|
# and register.
|
483
|
+
#
|
484
|
+
# @param sources List of sources.
|
485
|
+
# @param targets List of targets.
|
440
486
|
def self.usezip( sources, targets )
|
441
487
|
sources.zip( targets ).map do |pair|
|
442
488
|
self.new( *pair ).use
|
@@ -447,6 +493,10 @@ module Rubu
|
|
447
493
|
attr_reader :sources
|
448
494
|
attr_reader :targets
|
449
495
|
|
496
|
+
# Create Step object.
|
497
|
+
#
|
498
|
+
# @param sources One or more sources.
|
499
|
+
# @param targets One or more targets.
|
450
500
|
def initialize( sources = [], targets = [] )
|
451
501
|
super()
|
452
502
|
|
@@ -466,15 +516,16 @@ module Rubu
|
|
466
516
|
end
|
467
517
|
|
468
518
|
|
469
|
-
#
|
519
|
+
# Setup variables for Step. Should be defined again in derived
|
520
|
+
# classes.
|
470
521
|
def setup
|
471
522
|
end
|
472
523
|
|
473
524
|
|
474
|
-
# Run
|
525
|
+
# Run Step and capture status.
|
475
526
|
def run
|
476
527
|
if update?
|
477
|
-
|
528
|
+
step
|
478
529
|
else
|
479
530
|
@status = :success
|
480
531
|
end
|
@@ -482,7 +533,7 @@ module Rubu
|
|
482
533
|
end
|
483
534
|
|
484
535
|
|
485
|
-
# Default update.
|
536
|
+
# Default update. Should be defined again in derived classes.
|
486
537
|
def update?
|
487
538
|
true
|
488
539
|
end
|
@@ -532,7 +583,7 @@ module Rubu
|
|
532
583
|
|
533
584
|
old_verbose = Order[ :verbose ]
|
534
585
|
Order[ :verbose ] = false
|
535
|
-
|
586
|
+
step
|
536
587
|
Order[ :verbose ] = old_verbose
|
537
588
|
|
538
589
|
unless target.exist?
|
@@ -549,12 +600,12 @@ module Rubu
|
|
549
600
|
end
|
550
601
|
|
551
602
|
|
552
|
-
# Main (first) source file.
|
603
|
+
# Main/only (first) source file.
|
553
604
|
def source
|
554
605
|
@sources[0]
|
555
606
|
end
|
556
607
|
|
557
|
-
# Main (first) target file.
|
608
|
+
# Main/only (first) target file.
|
558
609
|
def target
|
559
610
|
@targets[0]
|
560
611
|
end
|
@@ -565,23 +616,27 @@ module Rubu
|
|
565
616
|
end
|
566
617
|
|
567
618
|
# Define and register Shell command.
|
568
|
-
def
|
619
|
+
def shuse( cmd )
|
569
620
|
sh = ShellCommand.new( cmd )
|
570
621
|
sh.use
|
571
622
|
end
|
572
623
|
|
573
624
|
# Define and run Ruby command.
|
625
|
+
#
|
626
|
+
# @param desc Optional description for :verbose mode.
|
574
627
|
def rbrun( desc = nil, &cmd )
|
575
628
|
RubyCommand.new( desc, &cmd ).run
|
576
629
|
end
|
577
630
|
|
578
631
|
# Define and register Ruby command.
|
579
|
-
|
632
|
+
#
|
633
|
+
# @param desc Optional description for :verbose mode.
|
634
|
+
def rbuse( desc = nil, &cmd )
|
580
635
|
rb = RubyCommand.new( desc, &cmd )
|
581
636
|
rb.use
|
582
637
|
end
|
583
638
|
|
584
|
-
# Execute commands (
|
639
|
+
# Execute commands (from block) in parallel.
|
585
640
|
def fork( &blk )
|
586
641
|
host_in
|
587
642
|
instance_eval &blk
|
@@ -589,7 +644,7 @@ module Rubu
|
|
589
644
|
parallel_run
|
590
645
|
end
|
591
646
|
|
592
|
-
# Execute commands (
|
647
|
+
# Execute commands (from block) in sequence.
|
593
648
|
def walk( &blk )
|
594
649
|
host_in
|
595
650
|
instance_eval &blk
|
@@ -599,54 +654,59 @@ module Rubu
|
|
599
654
|
end
|
600
655
|
|
601
656
|
|
602
|
-
#
|
603
|
-
class
|
657
|
+
# Unconditional Step.
|
658
|
+
class StepAlways < Step
|
659
|
+
# Update without conditions.
|
604
660
|
def update?
|
605
661
|
true
|
606
662
|
end
|
607
663
|
end
|
608
664
|
|
609
665
|
|
610
|
-
# Date based
|
611
|
-
class
|
666
|
+
# Date based Step.
|
667
|
+
class StepAged < Step
|
668
|
+
# Update if Step source is newer than target.
|
612
669
|
def update?
|
613
670
|
date_update?
|
614
671
|
end
|
615
672
|
end
|
616
673
|
|
617
674
|
|
618
|
-
# Mark based
|
619
|
-
class
|
675
|
+
# Mark (checksum) based Step.
|
676
|
+
class StepMark < Step
|
677
|
+
# Update if target generated from Step source is different
|
678
|
+
# from old target.
|
620
679
|
def update?
|
621
680
|
mark_update?
|
622
681
|
end
|
623
682
|
end
|
624
683
|
|
625
684
|
|
626
|
-
#
|
627
|
-
|
628
|
-
class Flow < Action
|
685
|
+
# Trail with name. Trail is a collection of Steps and/or Trails.
|
686
|
+
class Trail < Move
|
629
687
|
|
630
|
-
include
|
688
|
+
include MoveStyles
|
631
689
|
|
632
|
-
#
|
633
|
-
@@
|
690
|
+
# Trail hash.
|
691
|
+
@@trails = {}
|
634
692
|
|
635
693
|
|
636
|
-
# Replacement for new method.
|
694
|
+
# Replacement (alias) for new method.
|
637
695
|
def self.form( name = nil, &blk )
|
638
696
|
self.new( name, &blk )
|
639
697
|
end
|
640
698
|
|
641
699
|
|
642
|
-
# Reference
|
700
|
+
# Reference Trail by name.
|
643
701
|
def self.[]( name )
|
644
|
-
@@
|
702
|
+
@@trails[ name ]
|
645
703
|
end
|
646
704
|
|
647
705
|
|
648
706
|
attr_reader :name
|
649
707
|
|
708
|
+
# Create Trail object. Named Trails are registered and can be
|
709
|
+
# referenced later.
|
650
710
|
def initialize( name = nil, &blk )
|
651
711
|
super()
|
652
712
|
@name = name
|
@@ -654,20 +714,28 @@ module Rubu
|
|
654
714
|
instance_eval &blk
|
655
715
|
host_out
|
656
716
|
if @name
|
657
|
-
@@
|
717
|
+
@@trails[ @name ] = self
|
658
718
|
end
|
659
719
|
end
|
660
720
|
|
661
|
-
|
721
|
+
|
722
|
+
# Take trail into use.
|
723
|
+
def pick( trail )
|
724
|
+
Trail[ trail ].use
|
725
|
+
end
|
726
|
+
|
727
|
+
|
728
|
+
# Default run style for Trail.
|
662
729
|
def run
|
663
730
|
serial_run
|
664
731
|
end
|
665
732
|
|
666
|
-
|
733
|
+
# Load a setup file.
|
734
|
+
def Trail.load_setup( setup_file )
|
667
735
|
|
668
|
-
if File.exist?
|
736
|
+
if File.exist? setup_file
|
669
737
|
|
670
|
-
conf = YAML.load_file(
|
738
|
+
conf = YAML.load_file( setup_file )
|
671
739
|
|
672
740
|
conf.each do |k,v|
|
673
741
|
|
@@ -686,12 +754,16 @@ module Rubu
|
|
686
754
|
end
|
687
755
|
end
|
688
756
|
|
689
|
-
# Apply configuration options if any.
|
690
|
-
def Flow.setup( spec )
|
691
757
|
|
692
|
-
|
693
|
-
|
694
|
-
|
758
|
+
# Apply configuration options and command parameters, if any,
|
759
|
+
# to Rubu.
|
760
|
+
#
|
761
|
+
# @param spec Hash of options for setup.
|
762
|
+
def Trail.setup( spec )
|
763
|
+
|
764
|
+
Trail.load_setup( "#{ENV['HOME']}/.rubu.yml" )
|
765
|
+
Trail.load_setup( ENV['RUBU_CONF'] ) if ENV['RUBU_CONF']
|
766
|
+
Trail.load_setup( ".rubu.yml" )
|
695
767
|
|
696
768
|
State.load
|
697
769
|
|
@@ -713,14 +785,20 @@ module Rubu
|
|
713
785
|
|
714
786
|
end
|
715
787
|
|
716
|
-
# Run selected
|
717
|
-
|
788
|
+
# Run selected trail(s).
|
789
|
+
#
|
790
|
+
# @param trails List of Trails to run.
|
791
|
+
def Trail.run( trails = 'default' )
|
792
|
+
|
793
|
+
unless trails.kind_of? Array
|
794
|
+
trails = [ trails ]
|
795
|
+
end
|
718
796
|
|
719
|
-
|
797
|
+
trails.each do |name|
|
720
798
|
|
721
799
|
begin
|
722
800
|
|
723
|
-
ret =
|
801
|
+
ret = Trail[ name ].run
|
724
802
|
if ret.status == :error
|
725
803
|
STDERR.puts "Rubu FAILURE..."
|
726
804
|
exit false
|
@@ -728,7 +806,7 @@ module Rubu
|
|
728
806
|
|
729
807
|
rescue
|
730
808
|
|
731
|
-
STDERR.puts "Broken
|
809
|
+
STDERR.puts "Broken trail: \"#{name}\"..."
|
732
810
|
exit false
|
733
811
|
|
734
812
|
end
|
@@ -743,12 +821,12 @@ module Rubu
|
|
743
821
|
end
|
744
822
|
|
745
823
|
|
746
|
-
# Serial
|
747
|
-
class Walk <
|
824
|
+
# Serial Trail.
|
825
|
+
class Walk < Trail; end
|
748
826
|
|
749
827
|
|
750
|
-
# Parallel
|
751
|
-
class Fork <
|
828
|
+
# Parallel Trail.
|
829
|
+
class Fork < Trail
|
752
830
|
def run
|
753
831
|
parallel_run
|
754
832
|
end
|
@@ -760,12 +838,14 @@ end
|
|
760
838
|
# Array class extension to support common Mark operations.
|
761
839
|
class Array
|
762
840
|
|
841
|
+
# Array version of Move#use.
|
763
842
|
def use
|
764
843
|
self.each do |item|
|
765
844
|
item.use
|
766
845
|
end
|
767
846
|
end
|
768
847
|
|
848
|
+
# Array version of Mark#set_opt.
|
769
849
|
def set_opt( key, val )
|
770
850
|
self.each do |item|
|
771
851
|
item.set_opt( key, val )
|
@@ -773,16 +853,19 @@ class Array
|
|
773
853
|
self
|
774
854
|
end
|
775
855
|
|
856
|
+
# Array version of Mark#peer.
|
776
857
|
def peer( rdir, ext, base = nil )
|
777
858
|
self.map do |item|
|
778
859
|
item.peer( rdir, ext, base )
|
779
860
|
end
|
780
861
|
end
|
781
862
|
|
863
|
+
# Array version of Mark#path.
|
782
864
|
def path( joiner = ' ' )
|
783
865
|
self.map{ |item| item.path }.join( joiner )
|
784
866
|
end
|
785
867
|
|
868
|
+
# Array version of Mark#rpath.
|
786
869
|
def rpath( joiner = ' ' )
|
787
870
|
self.map{ |item| item.rpath }.join( joiner )
|
788
871
|
end
|