Support subsidiary Rsconscript files - close #125

This commit is contained in:
Josh Holtrop 2021-10-22 13:58:19 -04:00
parent 28a245f0ab
commit d1a35501ef
8 changed files with 110 additions and 4 deletions

View File

@ -0,0 +1,10 @@
configure do
rscons "sub/Rsconscript"
rscons "sub/Rsconscript2", "configure"
puts "top configure"
end
build do
rscons "sub/Rsconscript2", "build"
puts "top build"
end

View File

@ -0,0 +1,9 @@
configure do
rscons "sub/Rsconscript_fail"
puts "top configure"
end
build do
rscons "sub/Rsconscript2", "build"
puts "top build"
end

View File

@ -0,0 +1,7 @@
configure do
puts "sub Rsconscript configure"
end
build do
puts "sub Rsconscript build"
end

View File

@ -0,0 +1,7 @@
configure do
puts "sub Rsconscript2 configure"
end
build do
puts "sub Rsconscript2 build"
end

View File

@ -0,0 +1,8 @@
configure do
puts "sub Rsconscript configure"
check_program "foobarfailure"
end
build do
puts "sub Rsconscript build"
end

View File

@ -193,7 +193,10 @@ module Rscons
co = ConfigureOp.new(options)
begin
@script.configure(co)
rescue RsconsError
rescue RsconsError => e
if e.message and e.message != ""
$stderr.puts e.message
end
Ansi.write($stderr, :red, "Configuration failed", :reset, "\n")
rv = 1
end

View File

@ -3,8 +3,33 @@ module Rscons
# The Script class encapsulates the state of a build script.
class Script
# DSL available to the Rsconscript.
class Dsl
# Global DSL methods.
class GlobalDsl
# Invoke rscons in a subprocess for a subsidiary Rsconscript file.
#
# @param script_path [String]
# Path to subsidiary Rsconscript to execute.
# @param args[Array<String>]
# Arguments to pass to rscons subprocess.
def rscons(script_path, *args)
script_path = File.expand_path(script_path)
me = File.expand_path($0)
command = [me, "-f", script_path, *args]
if ENV["specs"] and not ENV["dist_specs"] # specs
command = ["ruby", $LOAD_PATH.map {|p| ["-I", p]}, command].flatten # specs
end # specs
dir = File.dirname(script_path)
result = system(*command, chdir: dir)
unless result
raise RsconsError.new("Failed command: " + command.join(" "))
end
end
end
# Top-level DSL available to the Rsconscript.
class Dsl < GlobalDsl
# Create a Dsl.
def initialize(script)
@script = script
@ -59,7 +84,7 @@ module Rscons
end
# DSL available to the 'configure' block.
class ConfigureDsl
class ConfigureDsl < GlobalDsl
# Create a ConfigureDsl.
#
# @param configure_op [ConfigureOp]

View File

@ -2582,4 +2582,41 @@ EOF
end
end
context "with subsidiary scripts" do
it "executes the subsidiary script from configure block" do
test_dir "subsidiary"
result = run_rscons(op: %W[configure])
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{sub Rsconscript configure},
%r{sub Rsconscript build},
%r{sub Rsconscript2 configure},
%r{top configure},
])
end
it "executes the subsidiary script from build block" do
test_dir "subsidiary"
result = run_rscons(op: %W[configure])
expect(result.stderr).to eq ""
result = run_rscons(op: %W[build])
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{sub Rsconscript2 build},
%r{top build},
])
end
it "terminates execution when a subsidiary script fails" do
test_dir "subsidiary"
result = run_rscons(rsconscript: "Rsconscript_fail", op: %W[configure])
expect(result.stderr).to_not eq ""
expect(result.status).to_not eq 0
expect(result.stdout).to_not match /top configure/
end
end
end