Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31abeed3d5 | ||
|
|
446fef931f | ||
|
|
4a2997feec | ||
|
|
013995bbc0 |
No files matched your search
@@ -0,0 +1,12 @@
|
|||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.append('CPPPATH' => Dir['src/**/*/'])
|
||||||
|
env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/')
|
||||||
|
env.add_tweaker do |build_op|
|
||||||
|
if build_op[:target] =~ %r{build_one/.*\.o}
|
||||||
|
build_op[:vars]["CFLAGS"] << "-O1"
|
||||||
|
elsif build_op[:target] =~ %r{build_two/.*\.o}
|
||||||
|
build_op[:vars]["CFLAGS"] << "-O2"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
env.Program('tweaker', Dir['src/**/*.c'])
|
||||||
|
end
|
||||||
@@ -22,6 +22,7 @@ module Rscons
|
|||||||
@targets = {}
|
@targets = {}
|
||||||
@builders = {}
|
@builders = {}
|
||||||
@build_dirs = []
|
@build_dirs = []
|
||||||
|
@tweakers = []
|
||||||
@varset[:exclude_builders] ||= []
|
@varset[:exclude_builders] ||= []
|
||||||
unless @varset[:exclude_builders] == :all
|
unless @varset[:exclude_builders] == :all
|
||||||
exclude_builders = Set.new(@varset[:exclude_builders] || [])
|
exclude_builders = Set.new(@varset[:exclude_builders] || [])
|
||||||
@@ -45,7 +46,7 @@ module Rscons
|
|||||||
# Make a copy of the Environment object.
|
# Make a copy of the Environment object.
|
||||||
# The cloned environment will contain a copy of all environment options,
|
# The cloned environment will contain a copy of all environment options,
|
||||||
# construction variables, builders, and build directories. It will not
|
# construction variables, builders, and build directories. It will not
|
||||||
# contain a copy of the targets.
|
# contain a copy of the targets or tweakers.
|
||||||
# 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 clone(variables = {})
|
def clone(variables = {})
|
||||||
@@ -74,6 +75,11 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add a tweaker block to the Environment.
|
||||||
|
def add_tweaker(&block)
|
||||||
|
@tweakers << block
|
||||||
|
end
|
||||||
|
|
||||||
# Specify a build directory for this Environment.
|
# Specify a build directory for this Environment.
|
||||||
# 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)
|
||||||
@@ -136,10 +142,10 @@ module Rscons
|
|||||||
if @targets[target][:source].map do |src|
|
if @targets[target][:source].map do |src|
|
||||||
targets_processed.include?(src) or not @targets.include?(src) or process_target.call(src)
|
targets_processed.include?(src) or not @targets.include?(src) or process_target.call(src)
|
||||||
end.all?
|
end.all?
|
||||||
@targets[target][:builder].run(target,
|
run_builder(@targets[target][:builder],
|
||||||
|
target,
|
||||||
@targets[target][:source],
|
@targets[target][:source],
|
||||||
cache,
|
cache,
|
||||||
self,
|
|
||||||
@targets[target][:vars] || {})
|
@targets[target][:vars] || {})
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
@@ -238,6 +244,7 @@ module Rscons
|
|||||||
# @param sources [Array] List of source files to build.
|
# @param sources [Array] List of source files to build.
|
||||||
# @param suffixes [Array] List of suffixes to try to convert source files into.
|
# @param suffixes [Array] List of suffixes to try to convert source files into.
|
||||||
# @param cache [Cache] The Cache.
|
# @param cache [Cache] The Cache.
|
||||||
|
# @param vars [Hash] Extra variables to pass to the builder.
|
||||||
# Return a list of the converted file names.
|
# Return a list of the converted file names.
|
||||||
def build_sources(sources, suffixes, cache, vars = {})
|
def build_sources(sources, suffixes, cache, vars = {})
|
||||||
sources.map do |source|
|
sources.map do |source|
|
||||||
@@ -249,7 +256,7 @@ module Rscons
|
|||||||
converted_fname = get_build_fname(source, suffix)
|
converted_fname = get_build_fname(source, suffix)
|
||||||
builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
|
builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
|
||||||
if builder
|
if builder
|
||||||
converted = builder.run(converted_fname, [source], cache, self, vars)
|
converted = run_builder(builder, converted_fname, [source], cache, vars)
|
||||||
return nil unless converted
|
return nil unless converted
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -258,5 +265,26 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Invoke a builder to build the given target based on the given sources.
|
||||||
|
# @param builder [Builder] The Builder to use.
|
||||||
|
# @param target [String] The target output file.
|
||||||
|
# @param sources [Array] List of source files.
|
||||||
|
# @param cache [Cache] The Cache.
|
||||||
|
# @param vars [Hash] Extra variables to pass to the builder.
|
||||||
|
# Return the result of the builder's run() method.
|
||||||
|
def run_builder(builder, target, sources, cache, vars)
|
||||||
|
vars = @varset.merge(vars)
|
||||||
|
@tweakers.each do |tweaker_block|
|
||||||
|
build_operation = {
|
||||||
|
builder: builder,
|
||||||
|
target: target,
|
||||||
|
sources: sources,
|
||||||
|
vars: vars,
|
||||||
|
}
|
||||||
|
tweaker_block.call(build_operation)
|
||||||
|
end
|
||||||
|
builder.run(target, sources, cache, self, vars)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -44,7 +44,7 @@ module Rscons
|
|||||||
# @param values [VarSet, Hash] New set of variables.
|
# @param values [VarSet, Hash] New set of variables.
|
||||||
def append(values)
|
def append(values)
|
||||||
values = values.vars if values.is_a?(VarSet)
|
values = values.vars if values.is_a?(VarSet)
|
||||||
@vars.merge!(values)
|
@vars.merge!(Marshal.load(Marshal.dump(values)))
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
# gem version
|
# gem version
|
||||||
VERSION = "0.0.12"
|
VERSION = "0.0.13"
|
||||||
end
|
end
|
||||||
@@ -11,10 +11,10 @@ describe Rscons do
|
|||||||
FileUtils.rm_rf('build_tests_run')
|
FileUtils.rm_rf('build_tests_run')
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_testdir
|
def build_testdir(build_script = "build.rb")
|
||||||
if File.exists?("build.rb")
|
if File.exists?(build_script)
|
||||||
build_rb = File.read("build.rb")
|
build_rb = File.read(build_script)
|
||||||
File.open("build.rb", "w") do |fh|
|
File.open(build_script, "w") do |fh|
|
||||||
fh.puts(<<EOF + build_rb)
|
fh.puts(<<EOF + build_rb)
|
||||||
require "simplecov"
|
require "simplecov"
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ end
|
|||||||
require "rscons"
|
require "rscons"
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
IO.popen(%{ruby -I #{@owd}/lib build.rb}) do |io|
|
IO.popen(%{ruby -I #{@owd}/lib #{build_script}}) do |io|
|
||||||
io.readlines.reject do |line|
|
io.readlines.reject do |line|
|
||||||
line =~ /^Coverage report/
|
line =~ /^Coverage report/
|
||||||
end
|
end
|
||||||
@@ -35,11 +35,11 @@ EOF
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dir(build_test_directory)
|
def test_dir(build_test_directory, build_script = "build.rb")
|
||||||
@build_test_name = 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(build_script)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_sub(fname)
|
def file_sub(fname)
|
||||||
@@ -207,4 +207,14 @@ EOF
|
|||||||
File.exists?('library').should be_true
|
File.exists?('library').should be_true
|
||||||
`ar t lib.a`.should == "one.o\ntwo.o\n"
|
`ar t lib.a`.should == "one.o\ntwo.o\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'supports tweakers to override construction variables' do
|
||||||
|
lines = test_dir("build_dir", "tweaker_build.rb")
|
||||||
|
`./tweaker`.should == "Hello from two()\n"
|
||||||
|
lines.should =~ [
|
||||||
|
'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 -o tweaker build_one/one.o build_two/two.o',
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user