rscons 1.11.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e16961355b842e34ba268c6aafc6e4a0cee8987
4
- data.tar.gz: 9781c3c0b03f4261d2a565262087450ca3f2b9fa
3
+ metadata.gz: b20b9e60cf3744f02e69d2abfcc87453225b2085
4
+ data.tar.gz: d491f89527d60984f9ded839f065a58b3d29b9fc
5
5
  SHA512:
6
- metadata.gz: d0df2cb0f31ebb5e3f9002316322baa11cd050d238d9621e5a402a8b29259677ce31a4bf357763ebbd3ef97e3a1f25a7571290feea9a988296f7d18f698e3d91
7
- data.tar.gz: 9a1af1c958361f39f5d22bb7c8974d2d2aaf498bb076906da8960ee45de8fec385540b25b146b7f21c457b1f10f3fdacfbf9907a93a073c02bd200d5db60a67b
6
+ metadata.gz: 58a410427a682e312203153d088aee392c74a68ddf50061896898327f43077fbf046310c25109bf3a6f5c192d03e79529e26175f32c8f1e23579d159c7633e71
7
+ data.tar.gz: 6520c5177851e0b238398ba2321a26383b00ba9ba8b7b2468de54d5212730745ffbacfa1624cf1a0c878604caaeb5789f595c08ea73432512137ed43686de0ea
data/lib/rscons.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require_relative "rscons/ansi"
1
2
  require_relative "rscons/build_target"
2
3
  require_relative "rscons/builder"
3
4
  require_relative "rscons/cache"
@@ -50,6 +51,10 @@ module Rscons
50
51
  # The number of threads to use when scheduling subprocesses.
51
52
  attr_accessor :n_threads
52
53
 
54
+ # @return [Boolean]
55
+ # Whether to output ANSI color escape sequences.
56
+ attr_accessor :do_ansi_color
57
+
53
58
  # Remove all generated files.
54
59
  #
55
60
  # @return [void]
@@ -0,0 +1,52 @@
1
+ module Rscons
2
+ module Ansi
3
+ class << self
4
+
5
+ # Write a message to an IO with ANSI escape codes.
6
+ #
7
+ # @param io [IO]
8
+ # The IO to write to.
9
+ # @param message [Array<String, Symbol>]
10
+ # Strings to be printed, with Symbols representing ANSI escape codes.
11
+ #
12
+ # @return [void]
13
+ def write(io, *message)
14
+ do_color = Rscons.do_ansi_color
15
+ if do_color.nil?
16
+ do_color = do_ansi?(io)
17
+ end
18
+ out = ""
19
+ message.each do |m|
20
+ if m.is_a?(String)
21
+ out += m
22
+ elsif do_color
23
+ case m
24
+ when :red
25
+ out += "\e[0;31m"
26
+ when :cyan
27
+ out += "\e[0;36m"
28
+ when :reset
29
+ out += "\e[0m"
30
+ end
31
+ end
32
+ end
33
+ io.write(out)
34
+ end
35
+
36
+ private
37
+
38
+ # Determine whether to output ANSI color escape codes.
39
+ #
40
+ # @return [Boolean]
41
+ # Whether to output ANSI color escape codes.
42
+ def do_ansi?(io)
43
+ if RUBY_PLATFORM =~ /mingw/
44
+ (ENV["TERM"] == "xterm") && %w[fifo characterSpecial].include?(io.stat.ftype)
45
+ else
46
+ io.tty?
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -17,10 +17,11 @@ module Rscons
17
17
  if File.directory?(target)
18
18
  target
19
19
  elsif File.exists?(target)
20
- $stderr.puts "Error: `#{target}' already exists and is not a directory"
20
+ Ansi.write($stderr, :red, "Error: `#{target}' already exists and is not a directory", :reset, "\n")
21
21
  false
22
22
  else
23
- puts "Directory #{target}"
23
+ desc = "Directory #{target}"
24
+ env.print_builder_run_message(desc, desc)
24
25
  cache.mkdir_p(target)
25
26
  target
26
27
  end
@@ -43,7 +43,8 @@ module Rscons
43
43
  # Check the cache and copy if necessary
44
44
  unless cache.up_to_date?(dest, :Copy, [src], env)
45
45
  unless printed_message
46
- puts "#{name} #{target}"
46
+ desc = "#{name} #{target}"
47
+ env.print_builder_run_message(desc, desc)
47
48
  printed_message = true
48
49
  end
49
50
  cache.mkdir_p(File.dirname(dest))
data/lib/rscons/cli.rb CHANGED
@@ -39,6 +39,15 @@ module Rscons
39
39
  Rscons.n_threads = n_threads.to_i
40
40
  end
41
41
 
42
+ opts.on("-r", "--color MODE", "Set color mode (off, auto, force)") do |color_mode|
43
+ case color_mode
44
+ when "off"
45
+ Rscons.do_ansi_color = false
46
+ when "force"
47
+ Rscons.do_ansi_color = true
48
+ end
49
+ end
50
+
42
51
  opts.on_tail("--version", "Show version") do
43
52
  puts "Rscons version #{Rscons::VERSION}"
44
53
  exit 0
@@ -70,7 +79,6 @@ module Rscons
70
79
  begin
71
80
  load rsconsfile
72
81
  rescue Rscons::BuildError => e
73
- $stderr.puts e.message
74
82
  exit 1
75
83
  end
76
84
 
@@ -118,6 +118,7 @@ module Rscons
118
118
  env.add_post_build_hook(&build_hook_block)
119
119
  end
120
120
  end
121
+ env.instance_variable_set(:@n_threads, @n_threads)
121
122
 
122
123
  if block_given?
123
124
  yield env
@@ -302,13 +303,19 @@ module Rscons
302
303
  # @return [void]
303
304
  def process
304
305
  cache = Cache.instance
306
+ failure = nil
305
307
  begin
306
308
  while @job_set.size > 0 or @threaded_commands.size > 0
307
309
 
308
- targets_still_building = @threaded_commands.map do |tc|
309
- tc.build_operation[:target]
310
+ if failure
311
+ @job_set.clear!
312
+ job = nil
313
+ else
314
+ targets_still_building = @threaded_commands.map do |tc|
315
+ tc.build_operation[:target]
316
+ end
317
+ job = @job_set.get_next_job_to_run(targets_still_building)
310
318
  end
311
- job = @job_set.get_next_job_to_run(targets_still_building)
312
319
 
313
320
  # TODO: have Cache determine when checksums may be invalid based on
314
321
  # file size and/or timestamp.
@@ -323,7 +330,9 @@ module Rscons
323
330
  allow_delayed_execution: true,
324
331
  setup_info: job[:setup_info])
325
332
  unless result
326
- raise BuildError.new("Failed to build #{job[:target]}")
333
+ failure = "Failed to build #{job[:target]}"
334
+ Ansi.write($stderr, :red, failure, :reset, "\n")
335
+ next
327
336
  end
328
337
  end
329
338
 
@@ -349,9 +358,11 @@ module Rscons
349
358
  end
350
359
  else
351
360
  unless @echo == :command
352
- $stdout.puts "Failed command was: #{command_to_s(tc.command)}"
361
+ print_failed_command(tc.command)
353
362
  end
354
- raise BuildError.new("Failed to build #{tc.build_operation[:target]}")
363
+ failure = "Failed to build #{tc.build_operation[:target]}"
364
+ Ansi.write($stderr, :red, failure, :reset, "\n")
365
+ break
355
366
  end
356
367
  end
357
368
 
@@ -359,6 +370,9 @@ module Rscons
359
370
  ensure
360
371
  cache.write
361
372
  end
373
+ if failure
374
+ raise BuildError.new(failure)
375
+ end
362
376
  end
363
377
 
364
378
  # Clear all targets registered for the Environment.
@@ -398,16 +412,12 @@ module Rscons
398
412
  #
399
413
  # @return [true,false,nil] Return value from Kernel.system().
400
414
  def execute(short_desc, command, options = {})
401
- if @echo == :command
402
- puts command_to_s(command)
403
- elsif @echo == :short
404
- puts short_desc
405
- end
415
+ print_builder_run_message(short_desc, command)
406
416
  env_args = options[:env] ? [options[:env]] : []
407
417
  options_args = options[:options] ? [options[:options]] : []
408
418
  system(*env_args, *Rscons.command_executer, *command, *options_args).tap do |result|
409
419
  unless result or @echo == :command
410
- $stdout.puts "Failed command was: #{command_to_s(command)}"
420
+ print_failed_command(command)
411
421
  end
412
422
  end
413
423
  end
@@ -451,6 +461,7 @@ module Rscons
451
461
  user_deps = user_deps.map {|ud| expand_varref(ud)}
452
462
  @user_deps[target] ||= []
453
463
  @user_deps[target] = (@user_deps[target] + user_deps).uniq
464
+ build_after(target, user_deps)
454
465
  end
455
466
 
456
467
  # Manually record the given target(s) as needing to be built after the
@@ -642,7 +653,7 @@ module Rscons
642
653
  call_build_hooks[:post]
643
654
  else
644
655
  unless @echo == :command
645
- $stdout.puts "Failed command was: #{command_to_s(tc.command)}"
656
+ print_failed_command(tc.command)
646
657
  end
647
658
  end
648
659
  end
@@ -829,7 +840,7 @@ module Rscons
829
840
  varset_hash = @varset.to_h
830
841
  varset_hash.keys.sort_by(&:to_s).each do |var|
831
842
  var_str = var.is_a?(Symbol) ? var.inspect : var
832
- puts "#{var_str} => #{varset_hash[var].inspect}"
843
+ Ansi.write($stdout, :cyan, var_str, :reset, " => #{varset_hash[var].inspect}\n")
833
844
  end
834
845
  end
835
846
 
@@ -842,6 +853,34 @@ module Rscons
842
853
  @n_threads || Rscons.n_threads
843
854
  end
844
855
 
856
+ # Print the builder run message, depending on the Environment's echo mode.
857
+ #
858
+ # @param short_description [String]
859
+ # Builder short description, printed if the echo mode is :short.
860
+ # @param command [Array<String>]
861
+ # Builder command, printed if the echo mode is :command.
862
+ #
863
+ # @return [void]
864
+ def print_builder_run_message(short_description, command)
865
+ case @echo
866
+ when :command
867
+ message = command_to_s(command) if command
868
+ when :short
869
+ message = short_description if short_description
870
+ end
871
+ Ansi.write($stdout, :cyan, message, :reset, "\n") if message
872
+ end
873
+
874
+ # Print a failed command.
875
+ #
876
+ # @param command [Array<String>]
877
+ # Builder command.
878
+ #
879
+ # @return [void]
880
+ def print_failed_command(command)
881
+ Ansi.write($stdout, :red, "Failed command was: #{command_to_s(command)}", :reset, "\n")
882
+ end
883
+
845
884
  private
846
885
 
847
886
  # Add a build target.
@@ -874,13 +913,7 @@ module Rscons
874
913
  #
875
914
  # @return [void]
876
915
  def start_threaded_command(tc)
877
- if @echo == :command
878
- puts command_to_s(tc.command)
879
- elsif @echo == :short
880
- if tc.short_description
881
- puts tc.short_description
882
- end
883
- end
916
+ print_builder_run_message(tc.short_description, tc.command)
884
917
 
885
918
  env_args = tc.system_env ? [tc.system_env] : []
886
919
  options_args = tc.system_options ? [tc.system_options] : []
@@ -1,4 +1,4 @@
1
1
  module Rscons
2
2
  # gem version
3
- VERSION = "1.11.1"
3
+ VERSION = "1.12.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Holtrop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-14 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -119,6 +119,7 @@ files:
119
119
  - LICENSE.txt
120
120
  - bin/rscons
121
121
  - lib/rscons.rb
122
+ - lib/rscons/ansi.rb
122
123
  - lib/rscons/build_target.rb
123
124
  - lib/rscons/builder.rb
124
125
  - lib/rscons/builders/cfile.rb