Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af0679708c | ||
|
|
4b0d0c3957 | ||
|
|
202f10b86f | ||
|
|
1d47db3144 |
No files matched your search
@@ -110,6 +110,29 @@ Rscons::Environment.new do |env|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Example: Custom Builder That Generates Multiple Output Files
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class CModuleGenerator < Rscons::Builder
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
c_fname = target
|
||||||
|
h_fname = target.sub(/\.c$/, ".h")
|
||||||
|
cmd = ["generate_c_and_h", sources.first, c_fname, h_fname]
|
||||||
|
unless cache.up_to_date?([c_fname, h_fname], cmd, sources, env)
|
||||||
|
cache.mkdir_p(File.dirname(target))
|
||||||
|
system(cmd)
|
||||||
|
cache.register_build([c_fname, h_fname], cmd, sources, env)
|
||||||
|
end
|
||||||
|
target
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(CModuleGenerator.new)
|
||||||
|
env.CModuleGenerator("build/foo.c", "foo_gen.cfg")
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Example: Custom Builder Using Builder#standard_build()
|
### Example: Custom Builder Using Builder#standard_build()
|
||||||
|
|
||||||
The `standard_build` method from the `Rscons::Builder` base class can be used
|
The `standard_build` method from the `Rscons::Builder` base class can be used
|
||||||
@@ -218,6 +241,13 @@ cloned_env["CPPPATH"] << "three"
|
|||||||
Documentation for the complete Rscons API can be found at
|
Documentation for the complete Rscons API can be found at
|
||||||
http://rubydoc.info/github/holtrop/rscons/frames.
|
http://rubydoc.info/github/holtrop/rscons/frames.
|
||||||
|
|
||||||
|
## Release Notes
|
||||||
|
|
||||||
|
### v1.1.0
|
||||||
|
|
||||||
|
- Change Cache#up_to_date?() and #register_build() to accept a single target
|
||||||
|
file or an array of target file names
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork it
|
1. Fork it
|
||||||
|
|||||||
+14
-9
@@ -85,16 +85,17 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if a target is up to date
|
# Check if target(s) are up to date
|
||||||
# @param target [String] The name of the target file.
|
# @param targets [String, Array] The name(s) of the target file(s).
|
||||||
# @param command [Array] The command used to build the target.
|
# @param command [String, Array] The command used to build the target.
|
||||||
# @param deps [Array] List of the target's dependency files.
|
# @param deps [Array] List of the target's dependency files.
|
||||||
# @param env [Environment] The Rscons::Environment.
|
# @param env [Environment] The Rscons::Environment.
|
||||||
# @param options [Hash] Optional options. Can contain the following keys:
|
# @param options [Hash] Optional options. Can contain the following keys:
|
||||||
# :strict_deps::
|
# :strict_deps::
|
||||||
# Only consider a target up to date if its list of dependencies is
|
# Only consider a target up to date if its list of dependencies is
|
||||||
# exactly equal (including order) to the cached list of dependencies
|
# exactly equal (including order) to the cached list of dependencies
|
||||||
# @return true value if the target is up to date, meaning that:
|
# @return true if the targets are all up to date, meaning that,
|
||||||
|
# for each target:
|
||||||
# - the target exists on disk
|
# - the target exists on disk
|
||||||
# - the cache has information for the target
|
# - the cache has information for the target
|
||||||
# - the target's checksum matches its checksum when it was last built
|
# - the target's checksum matches its checksum when it was last built
|
||||||
@@ -104,7 +105,8 @@ module Rscons
|
|||||||
# exactly equal to those cached
|
# exactly equal to those cached
|
||||||
# - each cached dependency file's current checksum matches the checksum
|
# - each cached dependency file's current checksum matches the checksum
|
||||||
# stored in the cache file
|
# stored in the cache file
|
||||||
def up_to_date?(target, command, deps, env, options = {})
|
def up_to_date?(targets, command, deps, env, options = {})
|
||||||
|
Array(targets).each do |target|
|
||||||
# target file must exist on disk
|
# target file must exist on disk
|
||||||
return false unless File.exists?(target)
|
return false unless File.exists?(target)
|
||||||
|
|
||||||
@@ -137,16 +139,18 @@ module Rscons
|
|||||||
(cached_deps + cached_user_deps).each do |dep_cache|
|
(cached_deps + cached_user_deps).each do |dep_cache|
|
||||||
return false unless dep_cache[:checksum] == lookup_checksum(dep_cache[:fname])
|
return false unless dep_cache[:checksum] == lookup_checksum(dep_cache[:fname])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store cache information about a target built by a builder
|
# Store cache information about target(s) built by a builder
|
||||||
# @param target [String] The name of the target.
|
# @param targets [String, Array] The name of the target(s) built.
|
||||||
# @param command [Array] The command used to build the target.
|
# @param command [String, 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.
|
||||||
# @param env [Environment] The Rscons::Environment.
|
# @param env [Environment] The Rscons::Environment.
|
||||||
def register_build(target, command, deps, env)
|
def register_build(targets, command, deps, env)
|
||||||
|
Array(targets).each do |target|
|
||||||
@cache[:targets][target.encode(__ENCODING__)] = {
|
@cache[:targets][target.encode(__ENCODING__)] = {
|
||||||
command: command,
|
command: command,
|
||||||
checksum: calculate_checksum(target),
|
checksum: calculate_checksum(target),
|
||||||
@@ -164,6 +168,7 @@ module Rscons
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return a list of targets that have been built
|
# Return a list of targets that have been built
|
||||||
def targets
|
def targets
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
# gem version
|
# gem version
|
||||||
VERSION = "1.0.0"
|
VERSION = "1.1.0"
|
||||||
end
|
end
|
||||||
@@ -220,7 +220,7 @@ describe Rscons do
|
|||||||
it 'allows Ruby classes as custom builders to be used to construct files' do
|
it 'allows Ruby classes as custom builders to be used to construct files' do
|
||||||
test_dir('custom_builder')
|
test_dir('custom_builder')
|
||||||
class MySource < Rscons::Builder
|
class MySource < Rscons::Builder
|
||||||
def run(target, sources, user_deps, cache, env, vars = {})
|
def run(target, sources, cache, env, vars)
|
||||||
File.open(target, 'w') do |fh|
|
File.open(target, 'w') do |fh|
|
||||||
fh.puts <<EOF
|
fh.puts <<EOF
|
||||||
#define THE_VALUE 5678
|
#define THE_VALUE 5678
|
||||||
@@ -241,6 +241,39 @@ EOF
|
|||||||
`./program`.should == "The value is 5678\n"
|
`./program`.should == "The value is 5678\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'supports custom builders with multiple targets' do
|
||||||
|
test_dir('custom_builder')
|
||||||
|
class CHGen < Rscons::Builder
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
c_fname = target
|
||||||
|
h_fname = target.sub(/\.c$/, ".h")
|
||||||
|
unless cache.up_to_date?([c_fname, h_fname], "", sources, env)
|
||||||
|
puts "CHGen #{c_fname}"
|
||||||
|
File.open(c_fname, "w") {|fh| fh.puts "int THE_VALUE = 42;"}
|
||||||
|
File.open(h_fname, "w") {|fh| fh.puts "extern int THE_VALUE;"}
|
||||||
|
cache.register_build([c_fname, h_fname], "", sources, env)
|
||||||
|
end
|
||||||
|
target
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
env = Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(CHGen.new)
|
||||||
|
env.CHGen("inc.c", ["program.c"])
|
||||||
|
env.Program("program", Dir["*.c"] + ["inc.c"])
|
||||||
|
end
|
||||||
|
|
||||||
|
lines.should == ["CHGen inc.c", "CC program.o", "CC inc.o", "LD program"]
|
||||||
|
File.exists?("inc.c").should be_true
|
||||||
|
File.exists?("inc.h").should be_true
|
||||||
|
`./program`.should == "The value is 42\n"
|
||||||
|
|
||||||
|
File.open("inc.c", "w") {|fh| fh.puts "int THE_VALUE = 33;"}
|
||||||
|
env.process
|
||||||
|
lines.should == ["CHGen inc.c"]
|
||||||
|
`./program`.should == "The value is 42\n"
|
||||||
|
end
|
||||||
|
|
||||||
it 'allows cloning Environment objects' do
|
it 'allows cloning Environment objects' do
|
||||||
test_dir('clone_env')
|
test_dir('clone_env')
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user