Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
338a49ba9c | ||
|
|
c23bb8c5e0 | ||
|
|
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
|
||||
@@ -28,6 +28,12 @@ module Rscons
|
||||
'CXXSUFFIX' => '.cc',
|
||||
'CXXDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'],
|
||||
'CXXCOM' =>['$CXX', '-c', '-o', '$_TARGET', '$CXXDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CXXFLAGS', '$_SOURCES'],
|
||||
|
||||
'DC' => 'gdc',
|
||||
'DFLAGS' => [],
|
||||
'DSUFFIX' => '.d',
|
||||
'D_IMPORT_PATH' => [],
|
||||
'DCCOM' => ['$DC', '-c', '-o', '$_TARGET', '-I$[D_IMPORT_PATH]', '$DFLAGS', '$_SOURCES'],
|
||||
}
|
||||
end
|
||||
|
||||
@@ -35,7 +41,8 @@ module Rscons
|
||||
target.has_suffix?(env['OBJSUFFIX']) and (
|
||||
source.has_suffix?(env['ASSUFFIX']) or
|
||||
source.has_suffix?(env['CSUFFIX']) or
|
||||
source.has_suffix?(env['CXXSUFFIX']))
|
||||
source.has_suffix?(env['CXXSUFFIX']) or
|
||||
source.has_suffix?(env['DSUFFIX']))
|
||||
end
|
||||
|
||||
def run(target, sources, cache, env, vars = {})
|
||||
@@ -50,6 +57,8 @@ module Rscons
|
||||
'CC'
|
||||
elsif sources.first.has_suffix?(env['CXXSUFFIX'])
|
||||
'CXX'
|
||||
elsif sources.first.has_suffix?(env['DSUFFIX'])
|
||||
'DC'
|
||||
else
|
||||
raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||
end
|
||||
|
||||
@@ -18,14 +18,19 @@ module Rscons
|
||||
# build sources to linkable objects
|
||||
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
||||
if objects
|
||||
use_cxx = sources.map do |s|
|
||||
s.has_suffix?(env['CXXSUFFIX'])
|
||||
end.any?
|
||||
ld_alt = use_cxx ? env['CXX'] : env['CC']
|
||||
ld = if env["LD"]
|
||||
env["LD"]
|
||||
elsif sources.find {|s| s.has_suffix?(env["DSUFFIX"])}
|
||||
env["DC"]
|
||||
elsif sources.find {|s| s.has_suffix?(env["CXXSUFFIX"])}
|
||||
env["CXX"]
|
||||
else
|
||||
env["CC"]
|
||||
end
|
||||
vars = vars.merge({
|
||||
'_TARGET' => target,
|
||||
'_SOURCES' => objects,
|
||||
'LD' => env['LD'] || ld_alt,
|
||||
'LD' => ld,
|
||||
})
|
||||
command = env.build_command(env['LDCOM'], vars)
|
||||
standard_build("LD #{target}", target, command, objects, env, cache)
|
||||
|
||||
@@ -22,6 +22,7 @@ module Rscons
|
||||
@targets = {}
|
||||
@builders = {}
|
||||
@build_dirs = []
|
||||
@tweakers = []
|
||||
@varset[:exclude_builders] ||= []
|
||||
unless @varset[:exclude_builders] == :all
|
||||
exclude_builders = Set.new(@varset[:exclude_builders] || [])
|
||||
@@ -45,7 +46,7 @@ module Rscons
|
||||
# Make a copy of the Environment object.
|
||||
# The cloned environment will contain a copy of all environment options,
|
||||
# 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
|
||||
# when the block returns, the {#process} method is automatically called.
|
||||
def clone(variables = {})
|
||||
@@ -74,6 +75,11 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Add a tweaker block to the Environment.
|
||||
def add_tweaker(&block)
|
||||
@tweakers << block
|
||||
end
|
||||
|
||||
# Specify a build directory for this Environment.
|
||||
# Source files from src_dir will produce object files under obj_dir.
|
||||
def build_dir(src_dir, obj_dir)
|
||||
@@ -136,11 +142,11 @@ module Rscons
|
||||
if @targets[target][:source].map do |src|
|
||||
targets_processed.include?(src) or not @targets.include?(src) or process_target.call(src)
|
||||
end.all?
|
||||
@targets[target][:builder].run(target,
|
||||
@targets[target][:source],
|
||||
cache,
|
||||
self,
|
||||
@targets[target][:vars] || {})
|
||||
run_builder(@targets[target][:builder],
|
||||
target,
|
||||
@targets[target][:source],
|
||||
cache,
|
||||
@targets[target][:vars] || {})
|
||||
else
|
||||
false
|
||||
end
|
||||
@@ -238,6 +244,7 @@ module Rscons
|
||||
# @param sources [Array] List of source files to build.
|
||||
# @param suffixes [Array] List of suffixes to try to convert source files into.
|
||||
# @param cache [Cache] The Cache.
|
||||
# @param vars [Hash] Extra variables to pass to the builder.
|
||||
# Return a list of the converted file names.
|
||||
def build_sources(sources, suffixes, cache, vars = {})
|
||||
sources.map do |source|
|
||||
@@ -249,7 +256,7 @@ module Rscons
|
||||
converted_fname = get_build_fname(source, suffix)
|
||||
builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
|
||||
if builder
|
||||
converted = builder.run(converted_fname, [source], cache, self, vars)
|
||||
converted = run_builder(builder, converted_fname, [source], cache, vars)
|
||||
return nil unless converted
|
||||
break
|
||||
end
|
||||
@@ -258,5 +265,26 @@ module Rscons
|
||||
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
|
||||
@@ -44,7 +44,7 @@ module Rscons
|
||||
# @param values [VarSet, Hash] New set of variables.
|
||||
def append(values)
|
||||
values = values.vars if values.is_a?(VarSet)
|
||||
@vars.merge!(values)
|
||||
@vars.merge!(Marshal.load(Marshal.dump(values)))
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module Rscons
|
||||
# gem version
|
||||
VERSION = "0.0.12"
|
||||
VERSION = "0.0.14"
|
||||
end
|
||||
@@ -11,10 +11,10 @@ describe Rscons do
|
||||
FileUtils.rm_rf('build_tests_run')
|
||||
end
|
||||
|
||||
def build_testdir
|
||||
if File.exists?("build.rb")
|
||||
build_rb = File.read("build.rb")
|
||||
File.open("build.rb", "w") do |fh|
|
||||
def build_testdir(build_script = "build.rb")
|
||||
if File.exists?(build_script)
|
||||
build_rb = File.read(build_script)
|
||||
File.open(build_script, "w") do |fh|
|
||||
fh.puts(<<EOF + build_rb)
|
||||
require "simplecov"
|
||||
|
||||
@@ -27,7 +27,7 @@ end
|
||||
require "rscons"
|
||||
EOF
|
||||
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|
|
||||
line =~ /^Coverage report/
|
||||
end
|
||||
@@ -35,11 +35,11 @@ EOF
|
||||
end
|
||||
end
|
||||
|
||||
def test_dir(build_test_directory)
|
||||
def test_dir(build_test_directory, build_script = "build.rb")
|
||||
@build_test_name = build_test_directory
|
||||
FileUtils.cp_r("build_tests/#{build_test_directory}", 'build_tests_run')
|
||||
Dir.chdir("build_tests_run")
|
||||
build_testdir
|
||||
build_testdir(build_script)
|
||||
end
|
||||
|
||||
def file_sub(fname)
|
||||
@@ -207,4 +207,14 @@ EOF
|
||||
File.exists?('library').should be_true
|
||||
`ar t lib.a`.should == "one.o\ntwo.o\n"
|
||||
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
|
||||
Reference in new issue
Block a user