rubu 0.0.2 → 0.0.3

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.
@@ -220,12 +220,12 @@
220
220
  <pre class="lines">
221
221
 
222
222
 
223
- 432
224
- 433
225
- 434</pre>
223
+ 438
224
+ 439
225
+ 440</pre>
226
226
  </td>
227
227
  <td>
228
- <pre class="code"><span class="info file"># File 'lib/rubu.rb', line 432</span>
228
+ <pre class="code"><span class="info file"># File 'lib/rubu.rb', line 438</span>
229
229
 
230
230
  <span class='kw'>def</span> <span class='const'>Var</span><span class='period'>.</span><span class='op'>[]</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
231
231
  <span class='cvar'>@@var</span><span class='lbracket'>[</span> <span class='id identifier rubyid_key'>key</span> <span class='rbracket'>]</span>
@@ -261,12 +261,12 @@
261
261
  <pre class="lines">
262
262
 
263
263
 
264
- 427
265
- 428
266
- 429</pre>
264
+ 433
265
+ 434
266
+ 435</pre>
267
267
  </td>
268
268
  <td>
269
- <pre class="code"><span class="info file"># File 'lib/rubu.rb', line 427</span>
269
+ <pre class="code"><span class="info file"># File 'lib/rubu.rb', line 433</span>
270
270
 
271
271
  <span class='kw'>def</span> <span class='const'>Var</span><span class='period'>.</span><span class='op'>[]=</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span> <span class='rparen'>)</span>
272
272
  <span class='cvar'>@@var</span><span class='lbracket'>[</span> <span class='id identifier rubyid_key'>key</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_val'>val</span>
@@ -281,7 +281,7 @@
281
281
  </div>
282
282
 
283
283
  <div id="footer">
284
- Generated on Sun Jul 1 17:48:17 2018 by
284
+ Generated on Sun Jul 8 19:50:19 2018 by
285
285
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
286
286
  0.8.7.6 (ruby-2.3.3).
287
287
  </div>
@@ -175,7 +175,7 @@
175
175
  </div>
176
176
 
177
177
  <div id="footer">
178
- Generated on Sun Jul 1 17:48:17 2018 by
178
+ Generated on Sun Jul 8 19:50:20 2018 by
179
179
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
180
180
  0.8.7.6 (ruby-2.3.3).
181
181
  </div>
@@ -296,7 +296,7 @@
296
296
  </div>
297
297
 
298
298
  <div id="footer">
299
- Generated on Sun Jul 1 17:48:17 2018 by
299
+ Generated on Sun Jul 8 19:50:19 2018 by
300
300
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
301
301
  0.8.7.6 (ruby-2.3.3).
302
302
  </div>
@@ -63,7 +63,10 @@
63
63
 
64
64
  <div id="content"><div id='filecontents'>
65
65
  <h1 id="label-Version+history">Version history</h1>
66
- <dl class="rdoc-list label-list"><dt>0.0.2
66
+ <dl class="rdoc-list label-list"><dt>0.0.3
67
+ <dd>
68
+ <p>Force update option. Auto-update example.</p>
69
+ </dd><dt>0.0.2
67
70
  <dd>
68
71
  <p>Documentation updates. Some name changes to Rubu classes.</p>
69
72
  </dd><dt>0.0.1
@@ -73,7 +76,7 @@
73
76
  </div></div>
74
77
 
75
78
  <div id="footer">
76
- Generated on Sun Jul 1 17:48:17 2018 by
79
+ Generated on Sun Jul 8 19:50:19 2018 by
77
80
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
78
81
  0.8.7.6 (ruby-2.3.3).
79
82
  </div>
@@ -118,6 +118,31 @@ script. File generation is part of the build program.</p>
118
118
 
119
119
  <p>There are comments which highlight purpose of the build program content.</p>
120
120
 
121
+ <p>Sometimes it is useful to run <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> automatically whenever a file changes.
122
+ Linux provides a facility called <strong>inotify</strong>, which can be
123
+ used in Ruby through “rb-inotify” gem. Automatic update example program is
124
+ in:</p>
125
+
126
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_example'>example</span><span class='op'>/</span><span class='id identifier rubyid_up'>up</span><span class='op'>-</span><span class='id identifier rubyid_to'>to</span><span class='op'>-</span><span class='id identifier rubyid_date'>date</span>
127
+ </code></pre>
128
+
129
+ <p>This program runs <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> each time there is a change in “src” or in “bin”
130
+ directory. It compiles and generates C files if necessary. If there are new
131
+ compilation requirements coming, before all previous have been completed,
132
+ it will continue compilation. When all compilations are done (i.e. none
133
+ pending), it will call <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> to perform linking. “up-to-date” displays
134
+ status messages in red and green on the screen. If it is started with “-v”
135
+ option the compile commands are visible, and if it is started with “-d”
136
+ option, there is extra delay in compilation command.</p>
137
+
138
+ <pre class="code ruby"><code class="ruby">cd example
139
+ up-to-date -v -d</code></pre>
140
+
141
+ <p>This is useful if you want to play around with the pending compilation
142
+ processes when new changes are coming in. You can make (dummy) changes to
143
+ “hello_world.c” (for example), and follow the updates in the terminal where
144
+ you started “up-to-date”.</p>
145
+
121
146
  <h2 id="label-Concepts">Concepts</h2>
122
147
 
123
148
  <p><span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> Build Program, RBP, is a Ruby program that uses the <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> library.
@@ -371,7 +396,7 @@ refer to the source, i.e. the only existing source, you can use the
371
396
  </div></div>
372
397
 
373
398
  <div id="footer">
374
- Generated on Sun Jul 1 17:48:17 2018 by
399
+ Generated on Sun Jul 8 19:50:19 2018 by
375
400
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
376
401
  0.8.7.6 (ruby-2.3.3).
377
402
  </div>
@@ -118,6 +118,31 @@ script. File generation is part of the build program.</p>
118
118
 
119
119
  <p>There are comments which highlight purpose of the build program content.</p>
120
120
 
121
+ <p>Sometimes it is useful to run <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> automatically whenever a file changes.
122
+ Linux provides a facility called <strong>inotify</strong>, which can be
123
+ used in Ruby through “rb-inotify” gem. Automatic update example program is
124
+ in:</p>
125
+
126
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_example'>example</span><span class='op'>/</span><span class='id identifier rubyid_up'>up</span><span class='op'>-</span><span class='id identifier rubyid_to'>to</span><span class='op'>-</span><span class='id identifier rubyid_date'>date</span>
127
+ </code></pre>
128
+
129
+ <p>This program runs <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> each time there is a change in “src” or in “bin”
130
+ directory. It compiles and generates C files if necessary. If there are new
131
+ compilation requirements coming, before all previous have been completed,
132
+ it will continue compilation. When all compilations are done (i.e. none
133
+ pending), it will call <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> to perform linking. “up-to-date” displays
134
+ status messages in red and green on the screen. If it is started with “-v”
135
+ option the compile commands are visible, and if it is started with “-d”
136
+ option, there is extra delay in compilation command.</p>
137
+
138
+ <pre class="code ruby"><code class="ruby">cd example
139
+ up-to-date -v -d</code></pre>
140
+
141
+ <p>This is useful if you want to play around with the pending compilation
142
+ processes when new changes are coming in. You can make (dummy) changes to
143
+ “hello_world.c” (for example), and follow the updates in the terminal where
144
+ you started “up-to-date”.</p>
145
+
121
146
  <h2 id="label-Concepts">Concepts</h2>
122
147
 
123
148
  <p><span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> Build Program, RBP, is a Ruby program that uses the <span class='object_link'><a href="Rubu.html" title="Rubu (class)">Rubu</a></span> library.
@@ -371,7 +396,7 @@ refer to the source, i.e. the only existing source, you can use the
371
396
  </div></div>
372
397
 
373
398
  <div id="footer">
374
- Generated on Sun Jul 1 17:48:17 2018 by
399
+ Generated on Sun Jul 8 19:50:19 2018 by
375
400
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
376
401
  0.8.7.6 (ruby-2.3.3).
377
402
  </div>
@@ -105,7 +105,7 @@
105
105
  </div>
106
106
 
107
107
  <div id="footer">
108
- Generated on Sun Jul 1 17:48:17 2018 by
108
+ Generated on Sun Jul 8 19:50:19 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>
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- IO.write( 'build/world.c', "\
3
+ unless Dir.exist? 'gen_cee'
4
+ Dir.mkdir 'gen_cee'
5
+ end
6
+
7
+ IO.write( 'gen_cee/world.c', "\
4
8
  #include <stdio.h>
5
9
 
6
10
  void print_world( void )
@@ -24,6 +24,7 @@ Spec.command( 'rubu_example', 'Tero Isannainen', '2018',
24
24
  # Set trail related options.
25
25
  Var[ :bin_dir ] = 'bin'
26
26
  Var[ :source_dir ] = 'src'
27
+ Var[ :gen_dir ] = 'gen_cee'
27
28
  Var[ :build_dir ] = 'build'
28
29
  Var[ :exe_name ] = 'build/hello'
29
30
 
@@ -35,6 +36,11 @@ if Opt['verbose'].given
35
36
  Order[ :verbose ] = true
36
37
  end
37
38
 
39
+ # Force serial execution.
40
+ if Opt[ 'serial' ].given
41
+ Order[ :serial ] = true
42
+ end
43
+
38
44
  # Read setup files and apply Como command line arguments to Var space.
39
45
  Trail.setup( :como => 'conf' )
40
46
 
@@ -44,7 +50,7 @@ Trail.setup( :como => 'conf' )
44
50
 
45
51
  # Generator file and the target.
46
52
  gen_file = Mark.path( "#{Var[:bin_dir]}/gen_world" )
47
- gen_cee_file = Mark.path( "#{Var[:build_dir]}/world.c" )
53
+ gen_cee_file = Mark.path( "#{Var[:gen_dir]}/world.c" )
48
54
 
49
55
  # Collect "normal" C files.
50
56
  cee_files = Mark.glob( "#{Var[:source_dir]}/*.c" )
@@ -74,6 +80,13 @@ class GenWorld < Step
74
80
  end
75
81
  end
76
82
 
83
+ # Code generator with generated file content dependency.
84
+ class GenGreenWorld < StepMark
85
+ def step
86
+ shrun "bin/gen_world"
87
+ end
88
+ end
89
+
77
90
 
78
91
  # Typical C compilation with GCC, from source to object.
79
92
  class GccCompileFile < StepAged
@@ -135,6 +148,12 @@ Walk.form 'gen-cee' do
135
148
  GenWorld.use( gen_file, gen_cee_file )
136
149
  end
137
150
 
151
+ # Serial trail for code generation (with filtered updates).
152
+ Walk.form 'gen-cee-green' do
153
+ # Create GenGreenWorld build and register it to 'gen-cee-green'.
154
+ GenGreenWorld.use( gen_file, gen_cee_file )
155
+ end
156
+
138
157
  # Parallel compilation of all C files.
139
158
  Fork.form 'compile-cee' do
140
159
  # Create set of GCC builds by joining 'all_cee_files' and
@@ -142,6 +161,11 @@ Fork.form 'compile-cee' do
142
161
  GccCompileFile.usezip( all_cee_files, obj_files )
143
162
  end
144
163
 
164
+ # Link executable.
165
+ Walk.form 'link' do
166
+ GccLinkExe.use( obj_files, exe_file )
167
+ end
168
+
145
169
  # Default trail, i.e. generate, compile, link to executable.
146
170
  Walk.form 'default' do
147
171
  # Reference 'gen-cee' trail.
@@ -149,7 +173,15 @@ Walk.form 'default' do
149
173
  # Reference 'compile-cee' trail.
150
174
  pick 'compile-cee'
151
175
  # Create GCC link build and register it.
152
- GccLinkExe.use( obj_files, exe_file )
176
+ pick 'link'
177
+ end
178
+
179
+ # Trail for 'up-to-date' script (see: example dir).
180
+ Walk.form 'up-to-date' do
181
+ # Reference 'gen-cee-green' trail.
182
+ pick 'gen-cee-green'
183
+ # Reference 'compile-cee' trail.
184
+ pick 'compile-cee'
153
185
  end
154
186
 
155
187
  # Cleaner trail.
@@ -169,8 +201,4 @@ else
169
201
  trails = [ 'default' ]
170
202
  end
171
203
 
172
- if Opt[ 'serial' ].given
173
- Order[ :serial ] = true
174
- end
175
-
176
204
  Trail.run( trails )
Binary file
Binary file
File without changes
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'como'
4
+ include Como
5
+ require 'rb-inotify'
6
+
7
+ Spec.command( 'up-to-date', 'Tero Isannainen', '2018',
8
+ [
9
+ [ :switch, 'demo', '-d', "Demo mode (with slow compile)." ],
10
+ [ :switch, 'verbose', '-v', "Verbose rubu." ],
11
+ ] )
12
+
13
+ # Locks for sync.
14
+ @lock = Mutex.new
15
+ @comp = ConditionVariable.new
16
+ @link = ConditionVariable.new
17
+
18
+ # Number of pending compiles.
19
+ @comps = 0
20
+
21
+ ths = []
22
+
23
+
24
+ NOC = "\e[0m"
25
+ RED = "\e[31m"
26
+ GREEN = "\e[32m"
27
+
28
+
29
+ def start_comp
30
+ puts RED + "PENDING..." + NOC
31
+ @lock.synchronize do
32
+ @comps += 1
33
+ @comp.signal
34
+ end
35
+ end
36
+
37
+
38
+ # Check file changes.
39
+ th = Thread.new do
40
+ notify = INotify::Notifier.new
41
+
42
+ notify.watch( "./src", :modify ) do |event|
43
+ start_comp
44
+ end
45
+
46
+ notify.watch( "./bin", :modify ) do |event|
47
+ start_comp
48
+ end
49
+
50
+ notify.run
51
+ end
52
+ ths.push th
53
+
54
+
55
+ # Compile files.
56
+ do_comp = false
57
+ th = Thread.new do
58
+
59
+ loop do
60
+
61
+ @lock.synchronize do
62
+ @comp.wait( @lock )
63
+ end
64
+
65
+ loop do
66
+
67
+ # Check for complation need.
68
+ @lock.synchronize do
69
+ if @comps >= 1
70
+ do_comp = true
71
+ else
72
+ do_comp = false
73
+ end
74
+ end
75
+
76
+ # Compline and signal linking if no pending compiles left.
77
+ if do_comp
78
+
79
+ verbose = ''
80
+ if Opt['verbose'].given
81
+ verbose = ' -v'
82
+ end
83
+
84
+ cmd = "bin/rubu_example #{verbose} up-to-date"
85
+
86
+ if Opt['demo'].given
87
+ cmd += "; sleep 3"
88
+ end
89
+
90
+ system cmd
91
+
92
+ @lock.synchronize do
93
+ @comps -= 1
94
+ if @comps == 0
95
+ @link.signal
96
+ end
97
+ end
98
+ else
99
+ break
100
+ end
101
+
102
+ end
103
+ end
104
+ end
105
+ ths.push th
106
+
107
+
108
+ # Link files.
109
+ th = Thread.new do
110
+ loop do
111
+ @lock.synchronize do
112
+ @link.wait( @lock )
113
+
114
+ verbose = ''
115
+ if Opt['verbose'].given
116
+ verbose = ' -v'
117
+ end
118
+
119
+ system "bin/rubu_example #{verbose} link"
120
+
121
+ puts GREEN + "READY!" + NOC
122
+ end
123
+ end
124
+ end
125
+ ths.push th
126
+
127
+ ths.each{|i| i.join}
@@ -389,6 +389,12 @@ module Rubu
389
389
 
390
390
 
391
391
  # Configuration space for Rubu.
392
+ #
393
+ # Options:
394
+ # * serial - Force parallel executions to serial.
395
+ # * parmax - Limit the number of parallel executions.
396
+ # * verbose - Show command executions.
397
+ # * force - Force Step updates.
392
398
  class Order
393
399
 
394
400
  @@order = {}
@@ -573,6 +579,7 @@ module Rubu
573
579
  def mark_update?
574
580
 
575
581
  unless date_update?
582
+ target.skip = true
576
583
  return false
577
584
  end
578
585
 
@@ -667,7 +674,7 @@ module Rubu
667
674
  class StepAged < Step
668
675
  # Update if Step source is newer than target.
669
676
  def update?
670
- date_update?
677
+ Order[ :force ] || date_update?
671
678
  end
672
679
  end
673
680
 
@@ -675,9 +682,9 @@ module Rubu
675
682
  # Mark (checksum) based Step.
676
683
  class StepMark < Step
677
684
  # Update if target generated from Step source is different
678
- # from old target.
685
+ # from old target in addition of being newer.
679
686
  def update?
680
- mark_update?
687
+ Order[ :force ] || mark_update?
681
688
  end
682
689
  end
683
690