Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd266c511e | ||
|
|
0f5fee359d | ||
|
|
dc6bac2895 | ||
|
|
e50aac31c9 | ||
|
|
e788f6ec25 | ||
|
|
8d893d7b72 | ||
|
|
c258dc379f | ||
|
|
0facfb274d | ||
|
|
3339cf5280 | ||
|
|
e041ea6612 | ||
|
|
ab51ddcc1b |
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env.append('CPPPATH' => Dir['src/**/*/'])
|
env.append('CPPPATH' => Dir['src/**/*/'])
|
||||||
env.build_dir('src', 'build')
|
env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/')
|
||||||
env.Program('build_dir', Dir['src/**/*.c'])
|
env.Program('build_dir', Dir['src/**/*.c'])
|
||||||
end
|
end
|
||||||
@@ -9,8 +9,7 @@ EOF
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rscons::Environment.new(echo: :short) do |env|
|
Rscons::Environment.new(echo: :short, builders: [MySource.new]) do |env|
|
||||||
env.add_builder(MySource.new)
|
|
||||||
env.MySource('inc.h', [])
|
env.MySource('inc.h', [])
|
||||||
env.Program('program', Dir['*.c'])
|
env.Program('program', Dir['*.c'])
|
||||||
end
|
end
|
||||||
@@ -32,6 +32,7 @@ module Rscons
|
|||||||
end
|
end
|
||||||
# remove all created directories if they are empty
|
# remove all created directories if they are empty
|
||||||
cache.directories.sort {|a, b| b.size <=> a.size}.each do |directory|
|
cache.directories.sort {|a, b| b.size <=> a.size}.each do |directory|
|
||||||
|
next unless File.directory?(directory)
|
||||||
if (Dir.entries(directory) - ['.', '..']).empty?
|
if (Dir.entries(directory) - ['.', '..']).empty?
|
||||||
Dir.rmdir(directory) rescue nil
|
Dir.rmdir(directory) rescue nil
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -129,12 +129,12 @@ module Rscons
|
|||||||
# @param command [Array] The command used to build the target.
|
# @param command [Array] The command used to build the target.
|
||||||
# @param deps [Array] List of dependencies for the target.
|
# @param deps [Array] List of dependencies for the target.
|
||||||
def register_build(target, command, deps)
|
def register_build(target, command, deps)
|
||||||
@cache[:targets][target] = {
|
@cache[:targets][target.encode(__ENCODING__)] = {
|
||||||
command: command,
|
command: command,
|
||||||
checksum: calculate_checksum(target),
|
checksum: calculate_checksum(target),
|
||||||
deps: deps.map do |dep|
|
deps: deps.map do |dep|
|
||||||
{
|
{
|
||||||
fname: dep,
|
fname: dep.encode(__ENCODING__),
|
||||||
checksum: lookup_checksum(dep),
|
checksum: lookup_checksum(dep),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ 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
|
||||||
# [Array] of {Builder} objects.
|
# [Hash] of {"builder_name" => builder_object} pairs.
|
||||||
attr_reader :builders
|
attr_reader :builders
|
||||||
|
|
||||||
# Create an Environment object.
|
# Create an Environment object.
|
||||||
@@ -53,7 +53,7 @@ module Rscons
|
|||||||
@builders.each do |builder_name, builder|
|
@builders.each do |builder_name, builder|
|
||||||
env.add_builder(builder)
|
env.add_builder(builder)
|
||||||
end
|
end
|
||||||
env.append(@varset)
|
env.append(@varset.clone)
|
||||||
env.append(variables)
|
env.append(variables)
|
||||||
|
|
||||||
if block_given?
|
if block_given?
|
||||||
@@ -78,7 +78,6 @@ module Rscons
|
|||||||
# Source files from src_dir will produce object files under obj_dir.
|
# Source files from src_dir will produce object files under obj_dir.
|
||||||
def build_dir(src_dir, obj_dir)
|
def build_dir(src_dir, obj_dir)
|
||||||
src_dir = src_dir.gsub('\\', '/') if src_dir.is_a?(String)
|
src_dir = src_dir.gsub('\\', '/') if src_dir.is_a?(String)
|
||||||
obj_dir = obj_dir.gsub('\\', '/')
|
|
||||||
@build_dirs << [src_dir, obj_dir]
|
@build_dirs << [src_dir, obj_dir]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ module Rscons
|
|||||||
if src_dir.is_a?(Regexp)
|
if src_dir.is_a?(Regexp)
|
||||||
build_fname.sub!(src_dir, obj_dir)
|
build_fname.sub!(src_dir, obj_dir)
|
||||||
else
|
else
|
||||||
build_fname.sub!(/^#{src_dir}\//, "#{obj_dir}/")
|
build_fname.sub!(%r{^#{src_dir}/}, "#{obj_dir}/")
|
||||||
end
|
end
|
||||||
build_fname.gsub!('\\', '/')
|
build_fname.gsub!('\\', '/')
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ module Rscons
|
|||||||
# returned.
|
# returned.
|
||||||
def [](key, type = nil)
|
def [](key, type = nil)
|
||||||
val = @vars[key]
|
val = @vars[key]
|
||||||
if type == :array and val.is_a?(String)
|
if type == :array and not val.is_a?(Array)
|
||||||
[val]
|
[val]
|
||||||
elsif type == :string and val.is_a?(Array)
|
elsif type == :scalar and val.is_a?(Array)
|
||||||
val.first
|
val.first
|
||||||
else
|
else
|
||||||
val
|
val
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
# gem version
|
# gem version
|
||||||
VERSION = "0.0.10"
|
VERSION = "0.0.12"
|
||||||
end
|
end
|
||||||
+35
-23
@@ -13,12 +13,30 @@ describe Rscons do
|
|||||||
|
|
||||||
def build_testdir
|
def build_testdir
|
||||||
if File.exists?("build.rb")
|
if File.exists?("build.rb")
|
||||||
system("ruby -I #{@owd}/lib -r rscons build.rb > build.out")
|
build_rb = File.read("build.rb")
|
||||||
|
File.open("build.rb", "w") do |fh|
|
||||||
|
fh.puts(<<EOF + build_rb)
|
||||||
|
require "simplecov"
|
||||||
|
|
||||||
|
SimpleCov.start do
|
||||||
|
root("#{@owd}")
|
||||||
|
command_name("build_test_#{@build_test_name}")
|
||||||
|
add_filter("spec")
|
||||||
|
end
|
||||||
|
|
||||||
|
require "rscons"
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
IO.popen(%{ruby -I #{@owd}/lib build.rb}) do |io|
|
||||||
|
io.readlines.reject do |line|
|
||||||
|
line =~ /^Coverage report/
|
||||||
|
end
|
||||||
|
end.map(&:strip)
|
||||||
end
|
end
|
||||||
get_build_output
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dir(build_test_directory)
|
def test_dir(build_test_directory)
|
||||||
|
@build_test_name = build_test_directory
|
||||||
FileUtils.cp_r("build_tests/#{build_test_directory}", 'build_tests_run')
|
FileUtils.cp_r("build_tests/#{build_test_directory}", 'build_tests_run')
|
||||||
Dir.chdir("build_tests_run")
|
Dir.chdir("build_tests_run")
|
||||||
build_testdir
|
build_testdir
|
||||||
@@ -35,10 +53,6 @@ describe Rscons do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_build_output
|
|
||||||
File.read('build.out').lines.map(&:strip)
|
|
||||||
end
|
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Tests
|
# Tests
|
||||||
###########################################################################
|
###########################################################################
|
||||||
@@ -116,36 +130,34 @@ describe Rscons do
|
|||||||
it 'builds object files in a different build directory' do
|
it 'builds object files in a different build directory' do
|
||||||
lines = test_dir('build_dir')
|
lines = test_dir('build_dir')
|
||||||
`./build_dir`.should == "Hello from two()\n"
|
`./build_dir`.should == "Hello from two()\n"
|
||||||
File.exists?('build/one/one.o').should be_true
|
File.exists?('build_one/one.o').should be_true
|
||||||
File.exists?('build/two/two.o').should be_true
|
File.exists?('build_two/two.o').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cleans built files' do
|
it 'cleans built files' do
|
||||||
lines = test_dir('build_dir')
|
lines = test_dir('build_dir')
|
||||||
`./build_dir`.should == "Hello from two()\n"
|
`./build_dir`.should == "Hello from two()\n"
|
||||||
File.exists?('build/one/one.o').should be_true
|
File.exists?('build_one/one.o').should be_true
|
||||||
File.exists?('build/two/two.o').should be_true
|
File.exists?('build_two/two.o').should be_true
|
||||||
Rscons.clean
|
Rscons.clean
|
||||||
File.exists?('build/one/one.o').should be_false
|
File.exists?('build_one/one.o').should be_false
|
||||||
File.exists?('build/two/two.o').should be_false
|
File.exists?('build_two/two.o').should be_false
|
||||||
File.exists?('build/one').should be_false
|
File.exists?('build_one').should be_false
|
||||||
File.exists?('build/two').should be_false
|
File.exists?('build_two').should be_false
|
||||||
File.exists?('build').should be_false
|
|
||||||
File.exists?('src/one/one.c').should be_true
|
File.exists?('src/one/one.c').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not clean created directories if other non-rscons-generated files reside there' do
|
it 'does not clean created directories if other non-rscons-generated files reside there' do
|
||||||
lines = test_dir('build_dir')
|
lines = test_dir('build_dir')
|
||||||
`./build_dir`.should == "Hello from two()\n"
|
`./build_dir`.should == "Hello from two()\n"
|
||||||
File.exists?('build/one/one.o').should be_true
|
File.exists?('build_one/one.o').should be_true
|
||||||
File.exists?('build/two/two.o').should be_true
|
File.exists?('build_two/two.o').should be_true
|
||||||
File.open('build/two/tmp', 'w') { |fh| fh.puts "dum" }
|
File.open('build_two/tmp', 'w') { |fh| fh.puts "dum" }
|
||||||
Rscons.clean
|
Rscons.clean
|
||||||
File.exists?('build/one/one.o').should be_false
|
File.exists?('build_one/one.o').should be_false
|
||||||
File.exists?('build/two/two.o').should be_false
|
File.exists?('build_two/two.o').should be_false
|
||||||
File.exists?('build/one').should be_false
|
File.exists?('build_one').should be_false
|
||||||
File.exists?('build/two').should be_true
|
File.exists?('build_two').should be_true
|
||||||
File.exists?('build').should be_true
|
|
||||||
File.exists?('src/one/one.c').should be_true
|
File.exists?('src/one/one.c').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
describe Environment do
|
describe Environment do
|
||||||
|
describe '.clone' do
|
||||||
|
it 'should create unique copies of each construction variable' do
|
||||||
|
env = Environment.new
|
||||||
|
env["CPPPATH"] << "path1"
|
||||||
|
env2 = env.clone
|
||||||
|
env2["CPPPATH"] << "path2"
|
||||||
|
env["CPPPATH"].should == ["path1"]
|
||||||
|
env2["CPPPATH"].should == ["path1", "path2"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '.parse_makefile_deps' do
|
describe '.parse_makefile_deps' do
|
||||||
it 'handles dependencies on one line' do
|
it 'handles dependencies on one line' do
|
||||||
File.should_receive(:read).with('makefile').and_return(<<EOS)
|
File.should_receive(:read).with('makefile').and_return(<<EOS)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
describe "Module#short_name" do
|
||||||
|
it "returns the inner name of the module" do
|
||||||
|
Rscons::Environment.short_name.should == "Environment"
|
||||||
|
Rscons::Object.short_name.should == "Object"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
module Rscons
|
||||||
|
describe VarSet do
|
||||||
|
describe '.initialize' do
|
||||||
|
it "initializes variables from a Hash" do
|
||||||
|
v = VarSet.new({"one" => 1, "two" => :two})
|
||||||
|
v["one"].should == 1
|
||||||
|
v["two"].should == :two
|
||||||
|
end
|
||||||
|
it "initializes variables from another VarSet" do
|
||||||
|
v = VarSet.new({"one" => 1})
|
||||||
|
v2 = VarSet.new(v)
|
||||||
|
v2["one"].should == 1
|
||||||
|
end
|
||||||
|
it "makes a deep copy of the given VarSet" do
|
||||||
|
v = VarSet.new({"array" => [1, 2, 3]})
|
||||||
|
v2 = VarSet.new(v)
|
||||||
|
v["array"] << 4
|
||||||
|
v["array"].should == [1, 2, 3, 4]
|
||||||
|
v2["array"].should == [1, 2, 3]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe :[] do
|
||||||
|
v = VarSet.new({"fuz" => "a string", "foo" => 42, "bar" => :baz,
|
||||||
|
"qax" => [3, 6], "qux" => {a: :b}})
|
||||||
|
it "allows accessing a variable with its verbatim value if type is not specified" do
|
||||||
|
v["fuz"].should == "a string"
|
||||||
|
v["foo"].should == 42
|
||||||
|
v["bar"].should == :baz
|
||||||
|
v["qax"].should == [3, 6]
|
||||||
|
v["qux"].should == {a: :b}
|
||||||
|
end
|
||||||
|
it "allows accessing a non-array converted to an array" do
|
||||||
|
v["fuz", :array].should == ["a string"]
|
||||||
|
end
|
||||||
|
it "allows accessing an array as a single value" do
|
||||||
|
v["qax", :scalar].should == 3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe :[]= do
|
||||||
|
it "allows assigning to variables" do
|
||||||
|
v = VarSet.new("CFLAGS" => ["-Wall", "-O3"])
|
||||||
|
v["CPPPATH"] = ["one", "two"]
|
||||||
|
v["CFLAGS"].should == ["-Wall", "-O3"]
|
||||||
|
v["CPPPATH"].should == ["one", "two"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.append' do
|
||||||
|
it "adds values from a Hash to the VarSet" do
|
||||||
|
v = VarSet.new("LDFLAGS" => "-lgcc")
|
||||||
|
v.append("LIBS" => "gcc", "LIBPATH" => ["mylibs"])
|
||||||
|
v.vars.keys.should =~ ["LDFLAGS", "LIBS", "LIBPATH"]
|
||||||
|
end
|
||||||
|
it "adds values from another VarSet to the VarSet" do
|
||||||
|
v = VarSet.new("CPPPATH" => ["mydir"])
|
||||||
|
v2 = VarSet.new("CFLAGS" => ["-O0"], "CPPPATH" => ["different_dir"])
|
||||||
|
v.append(v2)
|
||||||
|
v.vars.keys.should =~ ["CPPPATH", "CFLAGS"]
|
||||||
|
v["CPPPATH"].should == ["different_dir"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.merge' do
|
||||||
|
it "returns a new VarSet merged with the given Hash" do
|
||||||
|
v = VarSet.new("foo" => "yoda")
|
||||||
|
v2 = v.merge("baz" => "qux")
|
||||||
|
v.vars.keys.should == ["foo"]
|
||||||
|
v2.vars.keys.should =~ ["foo", "baz"]
|
||||||
|
end
|
||||||
|
it "returns a new VarSet merged with the given VarSet" do
|
||||||
|
v = VarSet.new("foo" => ["a", "b"], "bar" => 42)
|
||||||
|
v2 = v.merge(VarSet.new("bar" => 33, "baz" => :baz))
|
||||||
|
v2["foo"] << "c"
|
||||||
|
v["foo"].should == ["a", "b"]
|
||||||
|
v["bar"].should == 42
|
||||||
|
v2["foo"].should == ["a", "b", "c"]
|
||||||
|
v2["bar"].should == 33
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.expand_varref' do
|
||||||
|
v = VarSet.new("CFLAGS" => ["-Wall", "-O2"],
|
||||||
|
"CC" => "gcc",
|
||||||
|
"CPPPATH" => ["dir1", "dir2"],
|
||||||
|
"compiler" => "$CC",
|
||||||
|
"cmd" => ["$CC", "-c", "$CFLAGS", "-I$[CPPPATH]"])
|
||||||
|
it "expands to the string itself if the string is not a variable reference" do
|
||||||
|
v.expand_varref("CC").should == "CC"
|
||||||
|
v.expand_varref("CPPPATH").should == "CPPPATH"
|
||||||
|
v.expand_varref("str").should == "str"
|
||||||
|
end
|
||||||
|
it "expands a single variable reference beginning with a '$'" do
|
||||||
|
v.expand_varref("$CC").should == "gcc"
|
||||||
|
v.expand_varref("$CPPPATH").should == ["dir1", "dir2"]
|
||||||
|
end
|
||||||
|
it "expands a single variable reference in $[arr] notation" do
|
||||||
|
v.expand_varref("prefix$[CFLAGS]suffix").should == ["prefix-Wallsuffix", "prefix-O2suffix"]
|
||||||
|
v.expand_varref(v["cmd"]).should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
|
||||||
|
end
|
||||||
|
it "expands a variable reference recursively" do
|
||||||
|
v.expand_varref("$compiler").should == "gcc"
|
||||||
|
v.expand_varref("$cmd").should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
|
||||||
|
end
|
||||||
|
it "raises an error when array notation is applied to a non-array variable" do
|
||||||
|
expect { v.expand_varref("$[CC]") }.to raise_error /Array.expected/
|
||||||
|
end
|
||||||
|
it "raises an error when a variable reference refers to a non-existent variable" do
|
||||||
|
expect { v.expand_varref("$not_here") }.to raise_error /Could.not.find.variable..not_here/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1 +1,5 @@
|
|||||||
|
require "simplecov"
|
||||||
|
|
||||||
|
SimpleCov.start
|
||||||
|
|
||||||
require "rscons"
|
require "rscons"
|
||||||
Reference in new issue
Block a user