Rework builder interface to only use #run method - close #91

The builder's #run method will be called repeatedly until it returns
true or false. The Builder#wait_for method can be used to cause a
builder to wait for a Thread, Command, or another Builder.
This commit is contained in:
josh committed 2019-02-17 22:08:39 -05:00
1 parent 8426a54a57
commit b882f8de99
38 files changed
+580 -665

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ class MySource < Rscons::Builder
#define THE_VALUE 5678
EOF
end
@target
true
end
end
+1 -1
View File
@@ -5,7 +5,7 @@ class MySource < Rscons::Builder
#define THE_VALUE 678
EOF
end
@target
true
end
end
+1 -1
View File
@@ -5,7 +5,7 @@ class MySource < Rscons::Builder
#define THE_VALUE #{@env.expand_varref("${the_value}")}
EOF
end
@target
true
end
end
@@ -0,0 +1,8 @@
build do
Environment.new do |env|
env.add_builder(:MyBuilder) do |options|
"hi"
end
env.MyBuilder("foo")
end
end
@@ -0,0 +1,8 @@
build do
Environment.new do |env|
env.add_builder(:MyBuilder) do |options|
wait_for(1)
end
env.MyBuilder("foo")
end
end
@@ -8,7 +8,7 @@ class CHGen < Rscons::Builder
File.open(h_fname, "w") {|fh| fh.puts "extern int THE_VALUE;"}
@cache.register_build([c_fname, h_fname], "", @sources, @env)
end
@target
true
end
end
@@ -0,0 +1,21 @@
class MyBuilder < Rscons::Builder
def run(options)
if @thread
true
else
@env.print_builder_run_message("#{name} #{target}", nil)
@thread = Thread.new do
sleep 2
FileUtils.touch(@target)
end
wait_for(@thread)
end
end
end
build do
Environment.new do |env|
env.add_builder(MyBuilder)
env.MyBuilder("foo")
end
end
+1 -1
View File
@@ -10,7 +10,7 @@ build do
end
@cache.register_build(@target, :JsonToYaml, @sources, @env)
end
@target
true
end
env.JsonToYaml('foo.yml', 'foo.json')
end
+1 -1
View File
@@ -1,6 +1,6 @@
class TestBuilder < Rscons::Builder
def run(options)
target
true
end
end
build do
+22 -22
View File
@@ -1,30 +1,30 @@
class DebugBuilder < Rscons::Builder
def run(options)
command = %W[gcc -c -o #{@target} #{@sources.first}]
if Rscons.vars["command_change"]
command += %w[-Wall]
end
if Rscons.vars["new_dep"]
@sources += ["extra"]
end
if Rscons.vars["strict_deps1"]
@sources += ["extra"]
strict_deps = true
end
if Rscons.vars["strict_deps2"]
@sources = ["extra"] + @sources
strict_deps = true
end
if @cache.up_to_date?(@target, command, @sources, @env, debug: true, strict_deps: strict_deps)
@target
if @command
finalize_command
else
ThreadedCommand.new(command, short_description: "#{name} #{@target}")
@command = %W[gcc -c -o #{@target} #{@sources.first}]
if Rscons.vars["command_change"]
@command += %w[-Wall]
end
if Rscons.vars["new_dep"]
@sources += ["extra"]
end
if Rscons.vars["strict_deps1"]
@sources += ["extra"]
strict_deps = true
end
if Rscons.vars["strict_deps2"]
@sources = ["extra"] + @sources
strict_deps = true
end
if @cache.up_to_date?(@target, @command, @sources, @env, debug: true, strict_deps: strict_deps)
true
else
register_command("#{name} #{target}", @command)
end
end
end
def finalize(options)
standard_finalize(options)
end
end
build do
+1 -1
View File
@@ -9,7 +9,7 @@ class TestBuilder < Rscons::Builder
@env.print_builder_run_message(msg, msg)
@cache.register_build(@target, command, @sources, @env)
end
@target
true
end
end
+1 -1
View File
@@ -5,7 +5,7 @@ build do
puts "Checker #{@sources.first}" if @env.echo != :off
@cache.register_build(@target, :Checker, @sources, @env)
end
@target
true
end
env.Program("simple.exe", "simple.c")
env.Checker(:checker, "simple.exe")
+7 -8
View File
@@ -1,12 +1,11 @@
class ThreadedTestBuilder < Rscons::Builder
def run(options)
command = ["ruby", "-e", %[sleep 1]]
Rscons::ThreadedCommand.new(
command,
short_description: "ThreadedTestBuilder #{@target}")
end
def finalize(options)
true
if @command
true
else
@command = ["ruby", "-e", %[sleep 1]]
register_command("ThreadedTestBuilder #{@target}", @command)
end
end
end
@@ -14,7 +13,7 @@ class NonThreadedTestBuilder < Rscons::Builder
def run(options)
puts "NonThreadedTestBuilder #{@target}"
sleep 1
@target
true
end
end
+9 -9
View File
@@ -1,15 +1,15 @@
class TestBuilder < Rscons::Builder
def run(options)
if @target == "two"
return false unless File.exists?("one")
if @command
true
else
if @target == "two"
return false unless File.exists?("one")
end
wait_time = @env.expand_varref("${wait_time}", @vars)
@command = ["ruby", "-e", "require 'fileutils'; sleep #{wait_time}; FileUtils.touch('#{@target}');"]
register_command("TestBuilder", @command)
end
wait_time = @env.expand_varref("${wait_time}", @vars)
command = ["ruby", "-e", "require 'fileutils'; sleep #{wait_time}; FileUtils.touch('#{@target}');"]
standard_threaded_build("TestBuilder", @target, command, [], @env, @cache)
end
def finalize(options)
standard_finalize(options)
end
end
@@ -1,12 +1,13 @@
class Fail < Rscons::Builder
def run(options)
wait_time = @env.expand_varref("${wait_time}", @vars)
ruby_command = %[sleep #{wait_time}; exit 2]
command = %W[ruby -e #{ruby_command}]
standard_threaded_build("Fail #{@target}", @target, command, [], @env, @cache)
end
def finalize(options)
standard_finalize(options)
if @command
finalize_command
else
wait_time = @env.expand_varref("${wait_time}", @vars)
ruby_command = %[sleep #{wait_time}; exit 2]
@command = %W[ruby -e #{ruby_command}]
register_command("Fail #{@target}", @command)
end
end
end
+8 -8
View File
@@ -1,16 +1,16 @@
class StrictBuilder < Rscons::Builder
def run(options)
command = %W[gcc -o #{@target}] + @sources.sort
if @cache.up_to_date?(@target, command, @sources, @env, strict_deps: true)
@target
if @command
finalize_command
else
ThreadedCommand.new(command, short_description: "#{name} #{@target}")
@command = %W[gcc -o #{@target}] + @sources.sort
if @cache.up_to_date?(@target, @command, @sources, @env, strict_deps: true)
true
else
register_command("#{name} #{@target}", @command)
end
end
end
def finalize(options)
standard_finalize(options)
end
end
build do
+1 -1
View File
@@ -1,7 +1,7 @@
class MyBuilder < Rscons::Builder
def run(options)
@env.print_builder_run_message("MyBuilder #{@target}", "MyBuilder #{@target} command")
@target
true
end
end