implement autoconf - close #63, close #68, closes #67

This commit is contained in:
Josh Holtrop 2018-12-03 22:23:42 -05:00
parent ba69f05e99
commit 7c7ee142e0
8 changed files with 139 additions and 118 deletions

View File

@ -0,0 +1,3 @@
configure do
check_c_compiler "nope.nope"
end

View File

@ -0,0 +1 @@
autoconf false

View File

@ -35,8 +35,18 @@ module Rscons
@script = script @script = script
case operation case operation
when "build" when "build"
# TODO unless Cache.instance.configuration_data["configured"]
0 if @script.autoconf
rv = configure(operation_options)
if rv != 0
return rv
end
else
$stderr.puts "Project must be configured first, and autoconf is disabled"
return 1
end
end
build(operation_options)
when "clean" when "clean"
clean clean
when "configure" when "configure"
@ -49,9 +59,29 @@ module Rscons
private private
# Build the project.
#
# @param options [Hash]
# Options.
#
# @return [Integer]
# Exit code.
def build(options)
begin
Environment.environments.each do |env|
env.process
end
0
rescue BuildError => be
$stderr.puts be
1
end
end
# Remove all generated files. # Remove all generated files.
# #
# @return [void] # @return [Integer]
# Exit code.
def clean def clean
cache = Cache.instance cache = Cache.instance
# remove all built files # remove all built files
@ -74,7 +104,8 @@ module Rscons
# @param options [Hash] # @param options [Hash]
# Options. # Options.
# #
# @return [void] # @return [Integer]
# Exit code.
def configure(options) def configure(options)
# Default options. # Default options.
options[:build_dir] ||= "build" options[:build_dir] ||= "build"
@ -98,7 +129,7 @@ module Rscons
co.close co.close
cache.configuration_data["build_dir"] = options[:build_dir] cache.configuration_data["build_dir"] = options[:build_dir]
cache.configuration_data["prefix"] = options[:prefix] cache.configuration_data["prefix"] = options[:prefix]
cache.set_configured(rv == 0) cache.configuration_data["configured"] = rv == 0
cache.write! cache.write!
rv rv
end end

View File

@ -85,25 +85,6 @@ module Rscons
@lookup_checksums = {} @lookup_checksums = {}
end end
# Return whether the project has been configured.
#
# @return [Boolean]
# Whether the project has been configured.
def configured?
@cache["configured"]
end
# Set whether the project has been configured.
#
# @param configured [Boolean]
# Whether the project has been configured.
#
# @return [void]
def set_configured(configured)
@cache["configured"] = configured
@dirty = true
end
# Access configuration data. # Access configuration data.
def configuration_data def configuration_data
@cache["configuration_data"] @cache["configuration_data"]

View File

@ -122,7 +122,7 @@ module Rscons
exit 0 exit 0
end end
operation_options = parse_operation_args(operation, argv) operation_options = parse_operation_args(operation, argv) || {}
exit Rscons.application.run(operation, script, operation_options) exit Rscons.application.run(operation, script, operation_options)
end end

View File

@ -10,6 +10,11 @@ module Rscons
class Environment class Environment
class << self class << self
# @return [Array<Environment>]
# All Environments.
attr_reader :environments
# Get an ID for a new Environment. This is a monotonically increasing # Get an ID for a new Environment. This is a monotonically increasing
# integer. # integer.
# #
@ -20,6 +25,12 @@ module Rscons
@id += 1 @id += 1
@id @id
end end
# Register an Environment.
def register(env)
@environments ||= []
@environments << env
end
end end
# @return [Hash] Set of !{"builder_name" => builder_object} pairs. # @return [Hash] Set of !{"builder_name" => builder_object} pairs.
@ -49,6 +60,7 @@ module Rscons
# when the block returns, the {#process} method is automatically called. # when the block returns, the {#process} method is automatically called.
def initialize(options = {}) def initialize(options = {})
@id = self.class.get_id @id = self.class.get_id
self.class.register(self)
@threaded_commands = Set.new @threaded_commands = Set.new
@registered_build_dependencies = {} @registered_build_dependencies = {}
@side_effects = {} @side_effects = {}
@ -72,7 +84,6 @@ module Rscons
if block_given? if block_given?
yield self yield self
self.process
end end
end end
@ -128,7 +139,6 @@ module Rscons
if block_given? if block_given?
yield env yield env
env.process
end end
env env
end end

View File

@ -177,7 +177,7 @@ EOF
test_dir('simple') test_dir('simple')
result = run_rscons(rsconscript: "command.rb") result = run_rscons(rsconscript: "command.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
'gcc -c -o build/e.1/simple.o -MMD -MF build/e.1/simple.mf simple.c', 'gcc -c -o build/e.1/simple.o -MMD -MF build/e.1/simple.mf simple.c',
"gcc -o simple.exe build/e.1/simple.o", "gcc -o simple.exe build/e.1/simple.o",
] ]
@ -187,7 +187,7 @@ EOF
test_dir('header') test_dir('header')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
'CC build/e.1/header.o', 'CC build/e.1/header.o',
"LD header.exe", "LD header.exe",
] ]
@ -216,7 +216,7 @@ EOF
test_dir('header') test_dir('header')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
'CC build/e.1/header.o', 'CC build/e.1/header.o',
"LD header.exe", "LD header.exe",
] ]
@ -230,7 +230,7 @@ EOF
test_dir('header') test_dir('header')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
'CC build/e.1/header.o', 'CC build/e.1/header.o',
"LD header.exe", "LD header.exe",
] ]
@ -246,13 +246,13 @@ EOF
test_dir('simple') test_dir('simple')
result = run_rscons(rsconscript: "command.rb") result = run_rscons(rsconscript: "command.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
'gcc -c -o build/e.1/simple.o -MMD -MF build/e.1/simple.mf simple.c', 'gcc -c -o build/e.1/simple.o -MMD -MF build/e.1/simple.mf simple.c',
"gcc -o simple.exe build/e.1/simple.o", "gcc -o simple.exe build/e.1/simple.o",
] ]
result = run_rscons(rsconscript: "link_flag_change.rb") result = run_rscons(rsconscript: "link_flag_change.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"gcc -o simple.exe build/e.1/simple.o -Llibdir", "gcc -o simple.exe build/e.1/simple.o -Llibdir",
] ]
end end
@ -279,7 +279,7 @@ EOF
test_dir('build_dir') test_dir('build_dir')
result = run_rscons(rsconscript: "build_dirs_and_root.rb") result = run_rscons(rsconscript: "build_dirs_and_root.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
"CC build/one/one.o", "CC build/one/one.o",
"CC build/two/two.o", "CC build/two/two.o",
"LD build_dir.exe", "LD build_dir.exe",
@ -290,7 +290,7 @@ EOF
test_dir('build_dir') test_dir('build_dir')
result = run_rscons(rsconscript: "no_match_build_dir.rb") result = run_rscons(rsconscript: "no_match_build_dir.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
"CC build/e.1/src/one/one.o", "CC build/e.1/src/one/one.o",
"CC build/e.1/src/two/two.o", "CC build/e.1/src/two/two.o",
"LD build_dir.exe", "LD build_dir.exe",
@ -301,7 +301,7 @@ EOF
test_dir('build_dir') test_dir('build_dir')
result = run_rscons(rsconscript: "carat.rb") result = run_rscons(rsconscript: "carat.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
%q{gcc -c -o build/e.1/one.o -MMD -MF build/e.1/one.mf -Isrc -Isrc/one -Isrc/two build/e.1/one.c}, %q{gcc -c -o build/e.1/one.o -MMD -MF build/e.1/one.mf -Isrc -Isrc/one -Isrc/two build/e.1/one.c},
%q{gcc -c -o build/e.1/src/two/two.o -MMD -MF build/e.1/src/two/two.mf -Isrc -Isrc/one -Isrc/two src/two/two.c}, %q{gcc -c -o build/e.1/src/two/two.o -MMD -MF build/e.1/src/two/two.mf -Isrc -Isrc/one -Isrc/two src/two/two.c},
%Q{gcc -o build_dir.exe build/e.1/src/two/two.o build/e.1/one.o}, %Q{gcc -o build_dir.exe build/e.1/src/two/two.o build/e.1/one.o},
@ -353,7 +353,7 @@ EOF
test_dir('custom_builder') test_dir('custom_builder')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["CC build/e.1/program.o", "LD program.exe"] expect(lines(result.stdout)).to include *["CC build/e.1/program.o", "LD program.exe"]
expect(File.exists?('inc.h')).to be_truthy expect(File.exists?('inc.h')).to be_truthy
expect(`./program.exe`).to eq "The value is 5678\n" expect(`./program.exe`).to eq "The value is 5678\n"
end end
@ -363,9 +363,7 @@ EOF
result = run_rscons(rsconscript: "multiple_targets.rb") result = run_rscons(rsconscript: "multiple_targets.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
slines = lines(result.stdout) slines = lines(result.stdout)
expect(slines[0]).to eq("CHGen inc.c") expect(slines).to include("CHGen inc.c", "CC build/e.1/program.o", "CC build/e.1/inc.o", "LD program.exe")
expect(Set[*slines[1..2]]).to eq(Set["CC build/e.1/program.o", "CC build/e.1/inc.o"])
expect(slines[3]).to eq("LD program.exe")
expect(File.exists?("inc.c")).to be_truthy expect(File.exists?("inc.c")).to be_truthy
expect(File.exists?("inc.h")).to be_truthy expect(File.exists?("inc.h")).to be_truthy
expect(`./program.exe`).to eq "The value is 42\n" expect(`./program.exe`).to eq "The value is 42\n"
@ -373,7 +371,7 @@ EOF
File.open("inc.c", "w") {|fh| fh.puts "int THE_VALUE = 33;"} File.open("inc.c", "w") {|fh| fh.puts "int THE_VALUE = 33;"}
result = run_rscons(rsconscript: "multiple_targets.rb") result = run_rscons(rsconscript: "multiple_targets.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["CHGen inc.c"] expect(lines(result.stdout)).to include *["CHGen inc.c"]
expect(`./program.exe`).to eq "The value is 42\n" expect(`./program.exe`).to eq "The value is 42\n"
end end
@ -381,7 +379,7 @@ EOF
test_dir('clone_env') test_dir('clone_env')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
%q{gcc -c -o debug/program.o -MMD -MF debug/program.mf '-DSTRING="Debug Version"' -O2 src/program.c}, %q{gcc -c -o debug/program.o -MMD -MF debug/program.mf '-DSTRING="Debug Version"' -O2 src/program.c},
%Q{gcc -o program-debug.exe debug/program.o}, %Q{gcc -o program-debug.exe debug/program.o},
%q{gcc -c -o release/program.o -MMD -MF release/program.mf '-DSTRING="Release Version"' -O2 src/program.c}, %q{gcc -c -o release/program.o -MMD -MF release/program.mf '-DSTRING="Release Version"' -O2 src/program.c},
@ -393,7 +391,7 @@ EOF
test_dir('clone_env') test_dir('clone_env')
result = run_rscons(rsconscript: "clone_all.rb") result = run_rscons(rsconscript: "clone_all.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
%q{gcc -c -o build/program.o -MMD -MF build/program.mf -DSTRING="Hello" -O2 src/program.c}, %q{gcc -c -o build/program.o -MMD -MF build/program.mf -DSTRING="Hello" -O2 src/program.c},
%q{post build/program.o}, %q{post build/program.o},
%Q{gcc -o program.exe build/program.o}, %Q{gcc -o program.exe build/program.o},
@ -416,7 +414,7 @@ EOF
test_dir('two_sources') test_dir('two_sources')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
'gcc -c -o one.o -MMD -MF one.mf -DONE one.c', 'gcc -c -o one.o -MMD -MF one.mf -DONE one.c',
'gcc -c -o build/e.1/two.o -MMD -MF build/e.1/two.mf two.c', 'gcc -c -o build/e.1/two.o -MMD -MF build/e.1/two.mf two.c',
"gcc -o two_sources.exe one.o build/e.1/two.o", "gcc -o two_sources.exe one.o build/e.1/two.o",
@ -429,7 +427,7 @@ EOF
test_dir('library') test_dir('library')
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
'gcc -c -o build/e.1/one.o -MMD -MF build/e.1/one.mf -Dmake_lib one.c', 'gcc -c -o build/e.1/one.o -MMD -MF build/e.1/one.mf -Dmake_lib one.c',
'gcc -c -o build/e.1/two.o -MMD -MF build/e.1/two.mf -Dmake_lib two.c', 'gcc -c -o build/e.1/two.o -MMD -MF build/e.1/two.mf -Dmake_lib two.c',
'ar rcs lib.a build/e.1/one.o build/e.1/two.o', 'ar rcs lib.a build/e.1/one.o build/e.1/two.o',
@ -444,7 +442,7 @@ EOF
test_dir("build_dir") test_dir("build_dir")
result = run_rscons(rsconscript: "build_hooks.rb") result = run_rscons(rsconscript: "build_hooks.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -Isrc/one -Isrc/two -O1 src/one/one.c', 'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -Isrc/one -Isrc/two -O1 src/one/one.c',
'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -Isrc/one -Isrc/two -O2 src/two/two.c', 'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -Isrc/one -Isrc/two -O2 src/two/two.c',
'gcc -o build_hook.exe build_one/one.o build_two/two.o', 'gcc -o build_hook.exe build_one/one.o build_two/two.o',
@ -458,19 +456,19 @@ EOF
File.open("program.ld", "w") {|fh| fh.puts("1")} File.open("program.ld", "w") {|fh| fh.puts("1")}
result = run_rscons(rsconscript: "user_dependencies.rb") result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["CC build/e.1/simple.o", "LD simple.exe"] expect(lines(result.stdout)).to include *["CC build/e.1/simple.o", "LD simple.exe"]
expect(File.exists?('build/e.1/simple.o')).to be_truthy expect(File.exists?('build/e.1/simple.o')).to be_truthy
expect(`./simple.exe`).to eq "This is a simple C program\n" expect(`./simple.exe`).to eq "This is a simple C program\n"
File.open("program.ld", "w") {|fh| fh.puts("2")} File.open("program.ld", "w") {|fh| fh.puts("2")}
result = run_rscons(rsconscript: "user_dependencies.rb") result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq(["LD simple.exe"]) expect(lines(result.stdout)).to include *["LD simple.exe"]
File.unlink("program.ld") File.unlink("program.ld")
result = run_rscons(rsconscript: "user_dependencies.rb") result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["LD simple.exe"] expect(lines(result.stdout)).to include *["LD simple.exe"]
result = run_rscons(rsconscript: "user_dependencies.rb") result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
@ -485,7 +483,7 @@ EOF
slines = lines(result.stdout) slines = lines(result.stdout)
expect(slines).to include("gdc -c -o build/e.1/main.o -MMD -MF build/e.1/main.mf main.d") expect(slines).to include("gdc -c -o build/e.1/main.o -MMD -MF build/e.1/main.mf main.d")
expect(slines).to include("gdc -c -o build/e.1/mod.o -MMD -MF build/e.1/mod.mf mod.d") expect(slines).to include("gdc -c -o build/e.1/mod.o -MMD -MF build/e.1/mod.mf mod.d")
expect(slines.last).to eq("gdc -o hello-d.exe build/e.1/main.o build/e.1/mod.o") expect(slines).to include("gdc -o hello-d.exe build/e.1/main.o build/e.1/mod.o")
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!" expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
end end
@ -496,7 +494,7 @@ EOF
slines = lines(result.stdout) slines = lines(result.stdout)
expect(slines).to include("gdc -c -o build/e.1/main.o -MMD -MF build/e.1/main.mf main.d") expect(slines).to include("gdc -c -o build/e.1/main.o -MMD -MF build/e.1/main.mf main.d")
expect(slines).to include("gdc -c -o build/e.1/mod.o -MMD -MF build/e.1/mod.mf mod.d") expect(slines).to include("gdc -c -o build/e.1/mod.o -MMD -MF build/e.1/mod.mf mod.d")
expect(slines.last).to eq("gdc -o hello-d.exe build/e.1/main.o build/e.1/mod.o") expect(slines).to include("gdc -o hello-d.exe build/e.1/main.o build/e.1/mod.o")
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!" expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 42!"
fcontents = File.read("mod.d", mode: "rb").sub("42", "33") fcontents = File.read("mod.d", mode: "rb").sub("42", "33")
File.open("mod.d", "wb") {|fh| fh.write(fcontents)} File.open("mod.d", "wb") {|fh| fh.write(fcontents)}
@ -505,7 +503,7 @@ EOF
slines = lines(result.stdout) slines = lines(result.stdout)
expect(slines).to include("gdc -c -o build/e.1/main.o -MMD -MF build/e.1/main.mf main.d") expect(slines).to include("gdc -c -o build/e.1/main.o -MMD -MF build/e.1/main.mf main.d")
expect(slines).to include("gdc -c -o build/e.1/mod.o -MMD -MF build/e.1/mod.mf mod.d") expect(slines).to include("gdc -c -o build/e.1/mod.o -MMD -MF build/e.1/mod.mf mod.d")
expect(slines.last).to eq("gdc -o hello-d.exe build/e.1/main.o build/e.1/mod.o") expect(slines).to include("gdc -o hello-d.exe build/e.1/main.o build/e.1/mod.o")
expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 33!" expect(`./hello-d.exe`.rstrip).to eq "Hello from D, value is 33!"
end end
@ -566,7 +564,7 @@ EOF
test_dir('custom_builder') test_dir('custom_builder')
result = run_rscons(rsconscript: "cvar_expansion.rb") result = run_rscons(rsconscript: "cvar_expansion.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["CC build/e.1/program.o", "LD program.exe"] expect(lines(result.stdout)).to include *["CC build/e.1/program.o", "LD program.exe"]
expect(File.exists?('inc.h')).to be_truthy expect(File.exists?('inc.h')).to be_truthy
expect(`./program.exe`).to eq "The value is 678\n" expect(`./program.exe`).to eq "The value is 678\n"
end end
@ -629,7 +627,7 @@ EOF
test_dir("two_sources") test_dir("two_sources")
result = run_rscons(rsconscript: "assuffix.rb") result = run_rscons(rsconscript: "assuffix.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
"CC one.ssss", "CC one.ssss",
"CC two.sss", "CC two.sss",
"AS build/e.1/one.o", "AS build/e.1/one.o",
@ -655,7 +653,7 @@ EOF
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to eq("Preprocess pp\n") expect(lines(result.stdout)).to include "Preprocess pp"
expect(File.read("pp")).to match(%r{xyz42abc}m) expect(File.read("pp")).to match(%r{xyz42abc}m)
result = run_rscons result = run_rscons
@ -667,7 +665,7 @@ EOF
end end
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to eq("Preprocess pp\n") expect(lines(result.stdout)).to include "Preprocess pp"
expect(File.read("pp")).to match(%r{abc88xyz}m) expect(File.read("pp")).to match(%r{abc88xyz}m)
end end
@ -684,10 +682,10 @@ EOF
result = run_rscons(rsconscript: "multiple_targets_same_name.rb") result = run_rscons(rsconscript: "multiple_targets_same_name.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(File.exists?("one.o")).to be_truthy expect(File.exists?("one.o")).to be_truthy
expect(lines(result.stdout)).to eq([ expect(lines(result.stdout)).to include *[
"CC one.o", "CC one.o",
"CC one.o", "CC one.o",
]) ]
end end
it "expands target and source paths when builders are registered in build hooks" do it "expands target and source paths when builders are registered in build hooks" do
@ -696,10 +694,10 @@ EOF
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(File.exists?("one.o")).to be_truthy expect(File.exists?("one.o")).to be_truthy
expect(File.exists?("two.o")).to be_truthy expect(File.exists?("two.o")).to be_truthy
expect(lines(result.stdout)).to eq([ expect(lines(result.stdout)).to include *[
"CC one.o", "CC one.o",
"CC two.o", "CC two.o",
]) ]
end end
it "does not re-run previously successful builders if one fails" do it "does not re-run previously successful builders if one fails" do
@ -717,7 +715,7 @@ EOF
result = run_rscons(rsconscript: "cache_successful_builds_when_one_fails.rb", result = run_rscons(rsconscript: "cache_successful_builds_when_one_fails.rb",
rscons_args: %w[-j1]) rscons_args: %w[-j1])
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC two.o", "CC two.o",
] ]
end end
@ -726,7 +724,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "progsuffix.rb") result = run_rscons(rsconscript: "progsuffix.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.out", "LD simple.out",
] ]
@ -736,7 +734,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "progsuffix2.rb") result = run_rscons(rsconscript: "progsuffix2.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.out", "LD simple.out",
] ]
@ -746,7 +744,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "progsuffix3.rb") result = run_rscons(rsconscript: "progsuffix3.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.xyz", "LD simple.xyz",
] ]
@ -757,8 +755,8 @@ EOF
result = run_rscons(rsconscript: "absolute_source_path.rb") result = run_rscons(rsconscript: "absolute_source_path.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
slines = lines(result.stdout) slines = lines(result.stdout)
expect(slines[0]).to match(%r{^CC build/e.1/.*/abs\.o$}) expect(slines).to include a_string_matching %r{^CC build/e.1/.*/abs\.o$}
expect(slines[1]).to eq "LD abs.exe" expect(slines).to include "LD abs.exe"
end end
it "creates shared libraries" do it "creates shared libraries" do
@ -839,7 +837,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "clone_n_threads.rb") result = run_rscons(rsconscript: "clone_n_threads.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["165"] expect(lines(result.stdout)).to include *["165"]
end end
it "prints a builder's short description with 'command' echo mode if there is no command" do it "prints a builder's short description with 'command' echo mode if there is no command" do
@ -847,7 +845,7 @@ EOF
result = run_rscons(rsconscript: "echo_command_ruby_builder.rb") result = run_rscons(rsconscript: "echo_command_ruby_builder.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Install inst.exe"] expect(lines(result.stdout)).to include *["Install inst.exe"]
end end
it "supports a string for a builder's echoed 'command' with Environment#print_builder_run_message" do it "supports a string for a builder's echoed 'command' with Environment#print_builder_run_message" do
@ -855,7 +853,7 @@ EOF
result = run_rscons(rsconscript: "echo_command_string.rb") result = run_rscons(rsconscript: "echo_command_string.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["MyBuilder foo command"] expect(lines(result.stdout)).to include *["MyBuilder foo command"]
end end
context "colored output" do context "colored output" do
@ -886,7 +884,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "run_builder.rb") result = run_rscons(rsconscript: "run_builder.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC simple.o", "CC simple.o",
"LD simple.exe", "LD simple.exe",
] ]
@ -896,7 +894,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "build_sources.rb") result = run_rscons(rsconscript: "build_sources.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC simple.o", "CC simple.o",
"CC build/e.1/two.o", "CC build/e.1/two.o",
"MyProgram simple.exe", "MyProgram simple.exe",
@ -932,7 +930,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "standard_build.rb") result = run_rscons(rsconscript: "standard_build.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["MyCommand simple.o"] expect(lines(result.stdout)).to include *["MyCommand simple.o"]
end end
it "supports the old 3-parameter signature to Builder#produces?" do it "supports the old 3-parameter signature to Builder#produces?" do
@ -945,7 +943,7 @@ EOF
test_dir("build_dir") test_dir("build_dir")
result = run_rscons(rsconscript: "backward_compatible_build_hooks.rb") result = run_rscons(rsconscript: "backward_compatible_build_hooks.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
'gcc -c -o one.o -MMD -MF one.mf -Isrc -Isrc/one -Isrc/two -O1 src/two/two.c', 'gcc -c -o one.o -MMD -MF one.mf -Isrc -Isrc/one -Isrc/two -O1 src/two/two.c',
'gcc -c -o two.o -MMD -MF two.mf -Isrc -Isrc/one -Isrc/two -O2 src/two/two.c' 'gcc -c -o two.o -MMD -MF two.mf -Isrc -Isrc/one -Isrc/two -O2 src/two/two.c'
] ]
@ -960,7 +958,7 @@ EOF
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
"LEX lexer.c", "LEX lexer.c",
"YACC parser.c", "YACC parser.c",
] ]
@ -984,7 +982,7 @@ EOF
result = run_rscons(rsconscript: "command_builder.rb") result = run_rscons(rsconscript: "command_builder.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["BuildIt simple.exe"] expect(lines(result.stdout)).to include *["BuildIt simple.exe"]
expect(`./simple.exe`).to eq "This is a simple C program\n" expect(`./simple.exe`).to eq "This is a simple C program\n"
result = run_rscons(rsconscript: "command_builder.rb") result = run_rscons(rsconscript: "command_builder.rb")
@ -997,7 +995,7 @@ EOF
result = run_rscons(rsconscript: "command_redirect.rb") result = run_rscons(rsconscript: "command_redirect.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC simple.o", "CC simple.o",
"My Disassemble simple.txt", "My Disassemble simple.txt",
] ]
@ -1010,7 +1008,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "directory.rb") result = run_rscons(rsconscript: "directory.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq(["Directory teh_dir"]) expect(lines(result.stdout)).to include *["Directory teh_dir"]
expect(File.directory?("teh_dir")).to be_truthy expect(File.directory?("teh_dir")).to be_truthy
end end
@ -1019,7 +1017,7 @@ EOF
FileUtils.mkdir("teh_dir") FileUtils.mkdir("teh_dir")
result = run_rscons(rsconscript: "directory.rb") result = run_rscons(rsconscript: "directory.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to eq "" expect(lines(result.stdout)).to_not include a_string_matching /Directory/
expect(File.directory?("teh_dir")).to be_truthy expect(File.directory?("teh_dir")).to be_truthy
end end
@ -1037,7 +1035,7 @@ EOF
result = run_rscons(rsconscript: "install.rb") result = run_rscons(rsconscript: "install.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Install inst.exe"] expect(lines(result.stdout)).to include *["Install inst.exe"]
result = run_rscons(rsconscript: "install.rb") result = run_rscons(rsconscript: "install.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
@ -1049,7 +1047,7 @@ EOF
FileUtils.rm("inst.exe") FileUtils.rm("inst.exe")
result = run_rscons(rsconscript: "install.rb") result = run_rscons(rsconscript: "install.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Install inst.exe"] expect(lines(result.stdout)).to include *["Install inst.exe"]
end end
it "operates the same as a Copy builder" do it "operates the same as a Copy builder" do
@ -1057,7 +1055,7 @@ EOF
result = run_rscons(rsconscript: "copy.rb") result = run_rscons(rsconscript: "copy.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Copy inst.exe"] expect(lines(result.stdout)).to include *["Copy inst.exe"]
result = run_rscons(rsconscript: "copy.rb") result = run_rscons(rsconscript: "copy.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
@ -1069,7 +1067,7 @@ EOF
FileUtils.rm("inst.exe") FileUtils.rm("inst.exe")
result = run_rscons(rsconscript: "copy.rb") result = run_rscons(rsconscript: "copy.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Copy inst.exe"] expect(lines(result.stdout)).to include *["Copy inst.exe"]
end end
it "copies a file to the target directory name" do it "copies a file to the target directory name" do
@ -1115,11 +1113,11 @@ EOF
result = run_rscons(rsconscript: "phony_target.rb") result = run_rscons(rsconscript: "phony_target.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq([ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.exe", "LD simple.exe",
"Checker simple.exe", "Checker simple.exe",
]) ]
result = run_rscons(rsconscript: "phony_target.rb") result = run_rscons(rsconscript: "phony_target.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
@ -1132,9 +1130,9 @@ EOF
end end
result = run_rscons(rsconscript: "phony_target2.rb") result = run_rscons(rsconscript: "phony_target2.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq([ expect(lines(result.stdout)).to include *[
"Checker simple.exe", "Checker simple.exe",
]) ]
end end
end end
@ -1143,7 +1141,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "clear_targets.rb") result = run_rscons(rsconscript: "clear_targets.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to eq "" expect(lines(result.stdout)).to_not include a_string_matching %r{LD}
end end
end end
@ -1205,14 +1203,14 @@ EOF
result = run_rscons result = run_rscons
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.exe", "LD simple.exe",
] ]
result = run_rscons(rsconscript: "cache_command_change.rb") result = run_rscons(rsconscript: "cache_command_change.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"LD simple.exe", "LD simple.exe",
] ]
end end
@ -1222,14 +1220,14 @@ EOF
result = run_rscons(rsconscript: "cache_new_dep1.rb") result = run_rscons(rsconscript: "cache_new_dep1.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC simple.o", "CC simple.o",
"LD simple.exe", "LD simple.exe",
] ]
result = run_rscons(rsconscript: "cache_new_dep2.rb") result = run_rscons(rsconscript: "cache_new_dep2.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"LD simple.exe", "LD simple.exe",
] ]
end end
@ -1239,14 +1237,14 @@ EOF
result = run_rscons(rsconscript: "cache_dep_checksum_change.rb") result = run_rscons(rsconscript: "cache_dep_checksum_change.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Copy simple.copy"] expect(lines(result.stdout)).to include *["Copy simple.copy"]
File.open("simple.c", "wb") do |fh| File.open("simple.c", "wb") do |fh|
fh.write("hi") fh.write("hi")
end end
result = run_rscons(rsconscript: "cache_dep_checksum_change.rb") result = run_rscons(rsconscript: "cache_dep_checksum_change.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Copy simple.copy"] expect(lines(result.stdout)).to include *["Copy simple.copy"]
end end
it "forces a rebuild with strict_deps=true when dependency order changes" do it "forces a rebuild with strict_deps=true when dependency order changes" do
@ -1278,7 +1276,7 @@ EOF
File.open("user_deps", "wb") {|fh| fh.write("")} File.open("user_deps", "wb") {|fh| fh.write("")}
result = run_rscons(rsconscript: "cache_user_dep.rb") result = run_rscons(rsconscript: "cache_user_dep.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.exe", "LD simple.exe",
] ]
@ -1286,7 +1284,7 @@ EOF
File.open("user_deps", "wb") {|fh| fh.write("foo")} File.open("user_deps", "wb") {|fh| fh.write("foo")}
result = run_rscons(rsconscript: "cache_user_dep.rb") result = run_rscons(rsconscript: "cache_user_dep.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"LD simple.exe", "LD simple.exe",
] ]
end end
@ -1298,7 +1296,7 @@ EOF
File.open("user_deps", "wb") {|fh| fh.write("foo")} File.open("user_deps", "wb") {|fh| fh.write("foo")}
result = run_rscons(rsconscript: "cache_user_dep.rb") result = run_rscons(rsconscript: "cache_user_dep.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"CC build/e.1/simple.o", "CC build/e.1/simple.o",
"LD simple.exe", "LD simple.exe",
] ]
@ -1310,7 +1308,7 @@ EOF
File.open("foo", "wb") {|fh| fh.write("hi2")} File.open("foo", "wb") {|fh| fh.write("hi2")}
result = run_rscons(rsconscript: "cache_user_dep.rb") result = run_rscons(rsconscript: "cache_user_dep.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"LD simple.exe", "LD simple.exe",
] ]
end end
@ -1319,7 +1317,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "cache_varset.rb") result = run_rscons(rsconscript: "cache_varset.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"TestBuilder foo", "TestBuilder foo",
] ]
result = run_rscons(rsconscript: "cache_varset.rb") result = run_rscons(rsconscript: "cache_varset.rb")
@ -1410,7 +1408,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "override_cccmd.rb") result = run_rscons(rsconscript: "override_cccmd.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"gcc -c -o simple.o -Dfoobar simple.c", "gcc -c -o simple.o -Dfoobar simple.c",
] ]
end end
@ -1419,7 +1417,7 @@ EOF
test_dir("simple") test_dir("simple")
result = run_rscons(rsconscript: "override_depfilesuffix.rb") result = run_rscons(rsconscript: "override_depfilesuffix.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq [ expect(lines(result.stdout)).to include *[
"gcc -c -o simple.o -MMD -MF simple.deppy simple.c", "gcc -c -o simple.o -MMD -MF simple.deppy simple.c",
] ]
end end
@ -1469,7 +1467,7 @@ EOF
start_time = Time.new start_time = Time.new
result = run_rscons(rsconscript: "threading.rb", rscons_args: %w[-j 4]) result = run_rscons(rsconscript: "threading.rb", rscons_args: %w[-j 4])
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[ expect(lines(result.stdout)).to include *[
"ThreadedTestBuilder a", "ThreadedTestBuilder a",
"ThreadedTestBuilder b", "ThreadedTestBuilder b",
"ThreadedTestBuilder c", "ThreadedTestBuilder c",
@ -1922,6 +1920,20 @@ EOF
expect(result.status).to eq 0 expect(result.status).to eq 0
expect(result.stdout).to match /gcc.*-o.*\.o.*-DHAVE_MATH_H\s.*-DHAVE_STDIO_H/ expect(result.stdout).to match /gcc.*-o.*\.o.*-DHAVE_MATH_H\s.*-DHAVE_STDIO_H/
end end
it "exits with an error if the project is not configured and a build is requested and autoconf is false" do
test_dir "configure"
result = run_rscons(rsconscript: "autoconf_false.rb")
expect(result.stderr).to match /Project must be configured first, and autoconf is disabled/
expect(result.status).to_not eq 0
end
it "exits with an error if configuration fails during autoconf" do
test_dir "configure"
result = run_rscons(rsconscript: "autoconf_fail.rb")
expect(result.stdout).to match /Checking for C compiler\.\.\. not found/
expect(result.status).to_not eq 0
end
end end
end end

View File

@ -14,14 +14,6 @@ module Rscons
env = Environment.new(exclude_builders: true) env = Environment.new(exclude_builders: true)
expect(env.builders.size).to eq 0 expect(env.builders.size).to eq 0
end end
context "when a block is given" do
it "yields self and invokes #process()" do
env = Environment.new do |env|
expect(env).to receive(:process)
end
end
end
end end
describe "#clone" do describe "#clone" do
@ -54,15 +46,6 @@ module Rscons
expect(env2["Hash"]).to eq({"a" => "b"}) expect(env2["Hash"]).to eq({"a" => "b"})
expect(env2["Integer"]).to eq(1234) expect(env2["Integer"]).to eq(1234)
end end
context "when a block is given" do
it "yields self and invokes #process()" do
env = Environment.new
env.clone do |env2|
expect(env2).to receive(:process)
end
end
end
end end
describe "#add_builder" do describe "#add_builder" do