set Environment build root automatically - close #64
This commit is contained in:
parent
49116e6b59
commit
7a90325b67
@ -1,6 +1,5 @@
|
|||||||
env = Rscons::Environment.new do |env|
|
env = Rscons::Environment.new do |env|
|
||||||
env.append('CPPPATH' => Rscons.glob('src/**/*/'))
|
env.append('CPPPATH' => Rscons.glob('src/**/*/'))
|
||||||
env.build_dir("src", "build")
|
env.build_dir("src", "build")
|
||||||
env.build_root = "build_root"
|
|
||||||
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
Rscons::Environment.new(echo: :command) do |env|
|
Rscons::Environment.new(echo: :command) do |env|
|
||||||
env.append('CPPPATH' => Rscons.glob('src/**').sort)
|
env.append('CPPPATH' => Rscons.glob('src/**').sort)
|
||||||
env.build_root = "build_root"
|
|
||||||
FileUtils.mkdir_p(env.build_root)
|
FileUtils.mkdir_p(env.build_root)
|
||||||
FileUtils.mv("src/one/one.c", "build_root")
|
FileUtils.mv("src/one/one.c", env.build_root)
|
||||||
env.Object("^/one.o", "^/one.c")
|
env.Object("^/one.o", "^/one.c")
|
||||||
env.Program("build_dir.exe", Rscons.glob('src/**/*.c') + ["^/one.o"])
|
env.Program("build_dir.exe", Rscons.glob('src/**/*.c') + ["^/one.o"])
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env.append('CPPPATH' => Rscons.glob('src/**'))
|
env.append('CPPPATH' => Rscons.glob('src/**'))
|
||||||
env.build_dir("src2", "build")
|
env.build_dir("src2", "build")
|
||||||
env.build_root = "build_root"
|
|
||||||
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env.build_root = "build"
|
|
||||||
tempdir = ENV["TEMP"] || ENV["TMP"] || "/tmp"
|
tempdir = ENV["TEMP"] || ENV["TMP"] || "/tmp"
|
||||||
source_file = File.join(tempdir, "abs.c")
|
source_file = File.join(tempdir, "abs.c")
|
||||||
File.open(source_file, "w") do |fh|
|
File.open(source_file, "w") do |fh|
|
||||||
|
@ -4,7 +4,6 @@ class TestBuilder < Rscons::Builder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env.build_root = "build"
|
|
||||||
env.add_builder(TestBuilder.new)
|
env.add_builder(TestBuilder.new)
|
||||||
env.TestBuilder("file")
|
env.TestBuilder("file")
|
||||||
end
|
end
|
@ -8,6 +8,20 @@ module Rscons
|
|||||||
# contains a collection of construction variables, options, builders, and
|
# contains a collection of construction variables, options, builders, and
|
||||||
# rules for building targets.
|
# rules for building targets.
|
||||||
class Environment
|
class Environment
|
||||||
|
|
||||||
|
class << self
|
||||||
|
# Get an ID for a new Environment. This is a monotonically increasing
|
||||||
|
# integer.
|
||||||
|
#
|
||||||
|
# @return [Integer]
|
||||||
|
# Environment ID.
|
||||||
|
def get_id
|
||||||
|
@id ||= 0
|
||||||
|
@id += 1
|
||||||
|
@id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# @return [Hash] Set of !{"builder_name" => builder_object} pairs.
|
# @return [Hash] Set of !{"builder_name" => builder_object} pairs.
|
||||||
attr_reader :builders
|
attr_reader :builders
|
||||||
|
|
||||||
@ -23,27 +37,18 @@ module Rscons
|
|||||||
# used.
|
# used.
|
||||||
attr_writer :n_threads
|
attr_writer :n_threads
|
||||||
|
|
||||||
# Set the build root.
|
|
||||||
#
|
|
||||||
# @param build_root [String] The build root.
|
|
||||||
def build_root=(build_root)
|
|
||||||
raise "build_root must be non-nil" unless build_root
|
|
||||||
@build_root = build_root.gsub("\\", "/")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Create an Environment object.
|
# Create an Environment object.
|
||||||
#
|
#
|
||||||
# @param options [Hash]
|
# @param options [Hash]
|
||||||
# @option options [Symbol] :echo
|
# @option options [Symbol] :echo
|
||||||
# :command, :short, or :off (default :short)
|
# :command, :short, or :off (default :short)
|
||||||
# @option options [String] :build_root
|
|
||||||
# Build root directory (default "build")
|
|
||||||
# @option options [Boolean] :exclude_builders
|
# @option options [Boolean] :exclude_builders
|
||||||
# Whether to omit adding default builders (default false)
|
# Whether to omit adding default builders (default false)
|
||||||
#
|
#
|
||||||
# If a block is given, the Environment object is yielded to the block and
|
# If a block is given, the Environment object is yielded to the block and
|
||||||
# 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
|
||||||
@threaded_commands = Set.new
|
@threaded_commands = Set.new
|
||||||
@registered_build_dependencies = {}
|
@registered_build_dependencies = {}
|
||||||
@side_effects = {}
|
@side_effects = {}
|
||||||
@ -61,7 +66,8 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
@echo = options[:echo] || :short
|
@echo = options[:echo] || :short
|
||||||
@build_root = options[:build_root] || "build"
|
# TODO: remove the || "build" below when autoconf is turned on for build test specs
|
||||||
|
@build_root = "#{Cache.instance.configuration_data["build_dir"] || "build"}/e.#{@id}"
|
||||||
load_configuration_data!
|
load_configuration_data!
|
||||||
|
|
||||||
if block_given?
|
if block_given?
|
||||||
@ -81,7 +87,6 @@ module Rscons
|
|||||||
# following:
|
# following:
|
||||||
# - :variables to clone construction variables (on by default)
|
# - :variables to clone construction variables (on by default)
|
||||||
# - :builders to clone the builders (on by default)
|
# - :builders to clone the builders (on by default)
|
||||||
# - :build_root to clone the build root (on by default)
|
|
||||||
# - :build_dirs to clone the build directories (on by default)
|
# - :build_dirs to clone the build directories (on by default)
|
||||||
# - :build_hooks to clone the build hooks (on by default)
|
# - :build_hooks to clone the build hooks (on by default)
|
||||||
#
|
#
|
||||||
@ -93,13 +98,12 @@ module Rscons
|
|||||||
# @return [Environment] The newly created {Environment} object.
|
# @return [Environment] The newly created {Environment} object.
|
||||||
def clone(options = {})
|
def clone(options = {})
|
||||||
clone = options[:clone] || :all
|
clone = options[:clone] || :all
|
||||||
clone = Set[:variables, :builders, :build_root, :build_dirs, :build_hooks] if clone == :all
|
clone = Set[:variables, :builders, :build_dirs, :build_hooks] if clone == :all
|
||||||
clone = Set[] if clone == :none
|
clone = Set[] if clone == :none
|
||||||
clone = Set.new(clone) if clone.is_a?(Array)
|
clone = Set.new(clone) if clone.is_a?(Array)
|
||||||
clone.delete(:builders) if options[:exclude_builders]
|
clone.delete(:builders) if options[:exclude_builders]
|
||||||
env = self.class.new(
|
env = self.class.new(
|
||||||
echo: options[:echo] || @echo,
|
echo: options[:echo] || @echo,
|
||||||
build_root: options[:build_root],
|
|
||||||
exclude_builders: true)
|
exclude_builders: true)
|
||||||
if clone.include?(:builders)
|
if clone.include?(:builders)
|
||||||
@builders.each do |builder_name, builder|
|
@builders.each do |builder_name, builder|
|
||||||
@ -107,7 +111,6 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
env.append(@varset) if clone.include?(:variables)
|
env.append(@varset) if clone.include?(:variables)
|
||||||
env.build_root = @build_root if clone.include?(:build_root)
|
|
||||||
if clone.include?(:build_dirs)
|
if clone.include?(:build_dirs)
|
||||||
@build_dirs.reverse.each do |src_dir, obj_dir|
|
@build_dirs.reverse.each do |src_dir, obj_dir|
|
||||||
env.build_dir(src_dir, obj_dir)
|
env.build_dir(src_dir, obj_dir)
|
||||||
@ -1126,5 +1129,6 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -160,7 +160,7 @@ EOF
|
|||||||
test_dir('simple')
|
test_dir('simple')
|
||||||
result = run_rscons
|
result = run_rscons
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(File.exists?('build/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"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -169,8 +169,8 @@ EOF
|
|||||||
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 eq [
|
||||||
'gcc -c -o build/simple.o -MMD -MF build/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/simple.o",
|
"gcc -o simple.exe build/e.1/simple.o",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ 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 eq [
|
||||||
'CC build/header.o',
|
'CC build/e.1/header.o',
|
||||||
"LD header.exe",
|
"LD header.exe",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@ -188,7 +188,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(File.exists?('build/header.o')).to be_truthy
|
expect(File.exists?('build/e.1/header.o')).to be_truthy
|
||||||
expect(`./header.exe`).to eq "The value is 2\n"
|
expect(`./header.exe`).to eq "The value is 2\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ 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 eq [
|
||||||
'CC build/header.o',
|
'CC build/e.1/header.o',
|
||||||
"LD header.exe",
|
"LD header.exe",
|
||||||
]
|
]
|
||||||
expect(`./header.exe`).to eq "The value is 2\n"
|
expect(`./header.exe`).to eq "The value is 2\n"
|
||||||
@ -222,7 +222,7 @@ 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 eq [
|
||||||
'CC build/header.o',
|
'CC build/e.1/header.o',
|
||||||
"LD header.exe",
|
"LD header.exe",
|
||||||
]
|
]
|
||||||
expect(`./header.exe`).to eq "The value is 2\n"
|
expect(`./header.exe`).to eq "The value is 2\n"
|
||||||
@ -238,13 +238,13 @@ EOF
|
|||||||
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 eq [
|
||||||
'gcc -c -o build/simple.o -MMD -MF build/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/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 eq [
|
||||||
"gcc -o simple.exe build/simple.o -Llibdir",
|
"gcc -o simple.exe build/e.1/simple.o -Llibdir",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -282,8 +282,8 @@ EOF
|
|||||||
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(Set[*lines(result.stdout)]).to eq Set[
|
||||||
"CC build_root/src/one/one.o",
|
"CC build/e.1/src/one/one.o",
|
||||||
"CC build_root/src/two/two.o",
|
"CC build/e.1/src/two/two.o",
|
||||||
"LD build_dir.exe",
|
"LD build_dir.exe",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@ -293,9 +293,9 @@ EOF
|
|||||||
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(Set[*lines(result.stdout)]).to eq Set[
|
||||||
%q{gcc -c -o build_root/one.o -MMD -MF build_root/one.mf -Isrc -Isrc/one -Isrc/two build_root/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_root/src/two/two.o -MMD -MF build_root/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_root/src/two/two.o build_root/one.o},
|
%Q{gcc -o build_dir.exe build/e.1/src/two/two.o build/e.1/one.o},
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -344,7 +344,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/program.o", "LD program.exe"]
|
expect(lines(result.stdout)).to eq ["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
|
||||||
@ -355,7 +355,7 @@ EOF
|
|||||||
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[0]).to eq("CHGen inc.c")
|
||||||
expect(Set[*slines[1..2]]).to eq(Set["CC build/program.o", "CC build/inc.o"])
|
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(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
|
||||||
@ -399,7 +399,7 @@ EOF
|
|||||||
test_dir('simple_cc')
|
test_dir('simple_cc')
|
||||||
result = run_rscons
|
result = run_rscons
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(File.exists?('build/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"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -409,8 +409,8 @@ EOF
|
|||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(Set[*lines(result.stdout)]).to eq Set[
|
expect(Set[*lines(result.stdout)]).to eq Set[
|
||||||
'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/two.o -MMD -MF build/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/two.o",
|
"gcc -o two_sources.exe one.o build/e.1/two.o",
|
||||||
]
|
]
|
||||||
expect(File.exists?("two_sources.exe")).to be_truthy
|
expect(File.exists?("two_sources.exe")).to be_truthy
|
||||||
expect(`./two_sources.exe`).to eq "This is a C program with two sources.\n"
|
expect(`./two_sources.exe`).to eq "This is a C program with two sources.\n"
|
||||||
@ -421,11 +421,11 @@ 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(Set[*lines(result.stdout)]).to eq Set[
|
||||||
'gcc -c -o build/one.o -MMD -MF build/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/two.o -MMD -MF build/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/one.o build/two.o',
|
'ar rcs lib.a build/e.1/one.o build/e.1/two.o',
|
||||||
'gcc -c -o build/three.o -MMD -MF build/three.mf three.c',
|
'gcc -c -o build/e.1/three.o -MMD -MF build/e.1/three.mf three.c',
|
||||||
"gcc -o library.exe lib.a build/three.o",
|
"gcc -o library.exe lib.a build/e.1/three.o",
|
||||||
]
|
]
|
||||||
expect(File.exists?("library.exe")).to be_truthy
|
expect(File.exists?("library.exe")).to be_truthy
|
||||||
expect(`ar t lib.a`).to eq "one.o\ntwo.o\n"
|
expect(`ar t lib.a`).to eq "one.o\ntwo.o\n"
|
||||||
@ -449,8 +449,8 @@ 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/simple.o", "LD simple.exe"]
|
expect(lines(result.stdout)).to eq ["CC build/e.1/simple.o", "LD simple.exe"]
|
||||||
expect(File.exists?('build/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")}
|
||||||
@ -474,9 +474,9 @@ EOF
|
|||||||
result = run_rscons
|
result = run_rscons
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
slines = lines(result.stdout)
|
slines = lines(result.stdout)
|
||||||
expect(slines).to include("gdc -c -o build/main.o -MMD -MF build/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/mod.o -MMD -MF build/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/main.o build/mod.o")
|
expect(slines.last).to eq("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
|
||||||
|
|
||||||
@ -485,18 +485,18 @@ EOF
|
|||||||
result = run_rscons
|
result = run_rscons
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
slines = lines(result.stdout)
|
slines = lines(result.stdout)
|
||||||
expect(slines).to include("gdc -c -o build/main.o -MMD -MF build/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/mod.o -MMD -MF build/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/main.o build/mod.o")
|
expect(slines.last).to eq("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)}
|
||||||
result = run_rscons
|
result = run_rscons
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
slines = lines(result.stdout)
|
slines = lines(result.stdout)
|
||||||
expect(slines).to include("gdc -c -o build/main.o -MMD -MF build/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/mod.o -MMD -MF build/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/main.o build/mod.o")
|
expect(slines.last).to eq("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
|
||||||
|
|
||||||
@ -547,9 +547,9 @@ EOF
|
|||||||
expect(`./simple.exe`).to eq "This is a simple C++ program\n"
|
expect(`./simple.exe`).to eq "This is a simple C++ program\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports invoking builders with no sources and a build_root defined" do
|
it "supports invoking builders with no sources" do
|
||||||
test_dir("simple")
|
test_dir("simple")
|
||||||
result = run_rscons(rsconscript: "build_root_builder_no_sources.rb")
|
result = run_rscons(rsconscript: "builder_no_sources.rb")
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -557,7 +557,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/program.o", "LD program.exe"]
|
expect(lines(result.stdout)).to eq ["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
|
||||||
@ -573,8 +573,8 @@ EOF
|
|||||||
test_dir("simple")
|
test_dir("simple")
|
||||||
result = run_rscons(rsconscript: "register_target_in_build_hook.rb")
|
result = run_rscons(rsconscript: "register_target_in_build_hook.rb")
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(File.exists?("build/simple.o")).to be_truthy
|
expect(File.exists?("build/e.1/simple.o")).to be_truthy
|
||||||
expect(File.exists?("build/simple.o.txt")).to be_truthy
|
expect(File.exists?("build/e.1/simple.o.txt")).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"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -583,8 +583,8 @@ EOF
|
|||||||
File.open("other.cccc", "w") {|fh| fh.puts}
|
File.open("other.cccc", "w") {|fh| fh.puts}
|
||||||
result = run_rscons(rsconscript: "cxxsuffix.rb")
|
result = run_rscons(rsconscript: "cxxsuffix.rb")
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(File.exists?("build/simple.o")).to be_truthy
|
expect(File.exists?("build/e.1/simple.o")).to be_truthy
|
||||||
expect(File.exists?("build/other.o")).to be_truthy
|
expect(File.exists?("build/e.1/other.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"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -593,8 +593,8 @@ EOF
|
|||||||
FileUtils.mv("src/one/one.c", "src/one/one.yargh")
|
FileUtils.mv("src/one/one.c", "src/one/one.yargh")
|
||||||
result = run_rscons(rsconscript: "csuffix.rb")
|
result = run_rscons(rsconscript: "csuffix.rb")
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(File.exists?("build/src/one/one.o")).to be_truthy
|
expect(File.exists?("build/e.1/src/one/one.o")).to be_truthy
|
||||||
expect(File.exists?("build/src/two/two.o")).to be_truthy
|
expect(File.exists?("build/e.1/src/two/two.o")).to be_truthy
|
||||||
expect(`./build_dir.exe`).to eq "Hello from two()\n"
|
expect(`./build_dir.exe`).to eq "Hello from two()\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -623,8 +623,8 @@ EOF
|
|||||||
expect(Set[*lines(result.stdout)]).to eq Set[
|
expect(Set[*lines(result.stdout)]).to eq Set[
|
||||||
"CC one.ssss",
|
"CC one.ssss",
|
||||||
"CC two.sss",
|
"CC two.sss",
|
||||||
"AS build/one.o",
|
"AS build/e.1/one.o",
|
||||||
"AS build/two.o",
|
"AS build/e.1/two.o",
|
||||||
"LD two_sources.exe",
|
"LD two_sources.exe",
|
||||||
]
|
]
|
||||||
expect(File.exists?("two_sources.exe")).to be_truthy
|
expect(File.exists?("two_sources.exe")).to be_truthy
|
||||||
@ -666,7 +666,7 @@ EOF
|
|||||||
test_dir("simple")
|
test_dir("simple")
|
||||||
result = run_rscons(rsconscript: "cvar_array.rb")
|
result = run_rscons(rsconscript: "cvar_array.rb")
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(File.exists?("build/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"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -718,7 +718,7 @@ EOF
|
|||||||
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 eq [
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.out",
|
"LD simple.out",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@ -728,7 +728,7 @@ EOF
|
|||||||
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 eq [
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.out",
|
"LD simple.out",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@ -738,7 +738,7 @@ EOF
|
|||||||
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 eq [
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.xyz",
|
"LD simple.xyz",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@ -748,7 +748,7 @@ 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/.*/abs\.o$})
|
expect(slines[0]).to match(%r{^CC build/e.1/.*/abs\.o$})
|
||||||
expect(slines[1]).to eq "LD abs.exe"
|
expect(slines[1]).to eq "LD abs.exe"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -889,7 +889,7 @@ EOF
|
|||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(lines(result.stdout)).to eq [
|
expect(lines(result.stdout)).to eq [
|
||||||
"CC simple.o",
|
"CC simple.o",
|
||||||
"CC build/two.o",
|
"CC build/e.1/two.o",
|
||||||
"MyProgram simple.exe",
|
"MyProgram simple.exe",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
@ -1107,7 +1107,7 @@ 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 eq([
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.exe",
|
"LD simple.exe",
|
||||||
"Checker simple.exe",
|
"Checker simple.exe",
|
||||||
])
|
])
|
||||||
@ -1197,7 +1197,7 @@ 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 eq [
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.exe",
|
"LD simple.exe",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1270,7 +1270,7 @@ EOF
|
|||||||
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 eq [
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.exe",
|
"LD simple.exe",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1290,7 +1290,7 @@ EOF
|
|||||||
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 eq [
|
||||||
"CC build/simple.o",
|
"CC build/e.1/simple.o",
|
||||||
"LD simple.exe",
|
"LD simple.exe",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1435,7 +1435,7 @@ EOF
|
|||||||
test_dir("library")
|
test_dir("library")
|
||||||
result = run_rscons(rsconscript: "override_arcmd.rb")
|
result = run_rscons(rsconscript: "override_arcmd.rb")
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
expect(lines(result.stdout)).to include "ar rcf lib.a build/one.o build/three.o build/two.o"
|
expect(lines(result.stdout)).to include "ar rcf lib.a build/e.1/one.o build/e.1/three.o build/e.1/two.o"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,57 +81,6 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#get_build_fname" do
|
|
||||||
context "with no build directories" do
|
|
||||||
it "returns the name of the source file with suffix changed" do
|
|
||||||
env = Environment.new
|
|
||||||
expect(env.get_build_fname("src/dir/file.c", ".o")).to eq "build/src/dir/file.o"
|
|
||||||
expect(env.get_build_fname("src\\dir\\other.d", ".a")).to eq "build/src/dir/other.a"
|
|
||||||
expect(env.get_build_fname("source.cc", ".o")).to eq "build/source.o"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with a build_root" do
|
|
||||||
it "uses the build_root" do
|
|
||||||
stub_const("RUBY_PLATFORM", "mingw")
|
|
||||||
env = Environment.new
|
|
||||||
env.build_root = "build/proj"
|
|
||||||
expect(env.get_build_fname("src/dir/file.c", ".o")).to eq "build/proj/src/dir/file.o"
|
|
||||||
expect(env.get_build_fname("/some/lib.c", ".a")).to eq "build/proj/_/some/lib.a"
|
|
||||||
expect(env.get_build_fname("C:\\abspath\\mod.cc", ".o")).to eq "build/proj/_C/abspath/mod.o"
|
|
||||||
expect(env.get_build_fname("build\\proj\\generated.c", ".o")).to eq "build/proj/generated.o"
|
|
||||||
expect(env.get_build_fname("build/proj.XX", ".yy")).to eq "build/proj/build/proj.yy"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with build directories" do
|
|
||||||
it "uses the build directories to create the output file name" do
|
|
||||||
env = Environment.new
|
|
||||||
env.build_dir("src", "bld")
|
|
||||||
env.build_dir(%r{^libs/([^/]+)}, 'build/libs/\1')
|
|
||||||
expect(env.get_build_fname("src/input.cc", ".o")).to eq "bld/input.o"
|
|
||||||
expect(env.get_build_fname("libs/lib1/some/file.c", ".o")).to eq "build/libs/lib1/some/file.o"
|
|
||||||
expect(env.get_build_fname("libs/otherlib/otherlib.cc", ".o")).to eq "build/libs/otherlib/otherlib.o"
|
|
||||||
expect(env.get_build_fname("other_directory/o.d", ".a")).to eq "build/other_directory/o.a"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with a build_root" do
|
|
||||||
it "uses the build_root unless a build directory matches or the path is absolute" do
|
|
||||||
env = Environment.new
|
|
||||||
env.build_dir("src", "bld")
|
|
||||||
env.build_dir(%r{^libs/([^/]+)}, 'build/libs/\1')
|
|
||||||
env.build_root = "bldit"
|
|
||||||
|
|
||||||
expect(env.get_build_fname("src/input.cc", ".o")).to eq "bld/input.o"
|
|
||||||
expect(env.get_build_fname("libs/lib1/some/file.c", ".o")).to eq "build/libs/lib1/some/file.o"
|
|
||||||
expect(env.get_build_fname("libs/otherlib/otherlib.cc", ".o")).to eq "build/libs/otherlib/otherlib.o"
|
|
||||||
expect(env.get_build_fname("other_directory/o.d", ".a")).to eq "bldit/other_directory/o.a"
|
|
||||||
expect(env.get_build_fname("bldit/some/mod.d", ".a")).to eq "bldit/some/mod.a"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#[]" do
|
describe "#[]" do
|
||||||
it "allows reading construction variables" do
|
it "allows reading construction variables" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
|
Loading…
x
Reference in New Issue
Block a user