Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af0679708c | ||
|
|
4b0d0c3957 | ||
|
|
202f10b86f | ||
|
|
1d47db3144 | ||
|
|
f7b7a4fefa | ||
|
|
00b038ef50 | ||
|
|
98f8f38715 | ||
|
|
2ffb5d525a | ||
|
|
fa7d17675b | ||
|
|
b43c473762 | ||
|
|
f278b211f7 | ||
|
|
c897bcf06e | ||
|
|
7c89dddbd6 | ||
|
|
c07d9f86a6 | ||
|
|
ff26da8865 | ||
|
|
5ff555cf6a | ||
|
|
e3aadc562f | ||
|
|
7ff2ec1f1a | ||
|
|
5362f761e6 | ||
|
|
cdb3352b4e | ||
|
|
08bc390d40 | ||
|
|
f8af0630b0 | ||
|
|
1868193b54 | ||
|
|
8976d7dea2 | ||
|
|
295324eafd | ||
|
|
7330e74ab8 | ||
|
|
a28cef9eb7 | ||
|
|
e667046da8 | ||
|
|
539a49fe90 | ||
|
|
7681c7584f | ||
|
|
8fcbd39057 | ||
|
|
d0bbc78751 | ||
|
|
7249e57951 | ||
|
|
d01913641f | ||
|
|
d5be569cd5 | ||
|
|
4d7ed373e7 | ||
|
|
72558391a2 | ||
|
|
d01767981c |
No files matched your search
@@ -27,7 +27,7 @@ called from your Rakefile.
|
|||||||
### Example: Building a C Program
|
### Example: Building a C Program
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
RScons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env["CFLAGS"] << "-Wall"
|
env["CFLAGS"] << "-Wall"
|
||||||
env.Program("program", Dir["**/*.c"])
|
env.Program("program", Dir["**/*.c"])
|
||||||
end
|
end
|
||||||
@@ -36,7 +36,7 @@ end
|
|||||||
### Example: Building a D Program
|
### Example: Building a D Program
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
RScons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env["DFLAGS"] << "-Wall"
|
env["DFLAGS"] << "-Wall"
|
||||||
env.Program("program", Dir["**/*.d"])
|
env.Program("program", Dir["**/*.d"])
|
||||||
end
|
end
|
||||||
@@ -45,7 +45,7 @@ end
|
|||||||
### Example: Cloning an Environment
|
### Example: Cloning an Environment
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
main_env = RScons::Environment.new do |env|
|
main_env = Rscons::Environment.new do |env|
|
||||||
# Store object files from sources under "src" in "build/main"
|
# Store object files from sources under "src" in "build/main"
|
||||||
env.build_dir("src", "build/main")
|
env.build_dir("src", "build/main")
|
||||||
env["CFLAGS"] = ["-DSOME_DEFINE", "-O3"]
|
env["CFLAGS"] = ["-DSOME_DEFINE", "-O3"]
|
||||||
@@ -64,23 +64,96 @@ end
|
|||||||
|
|
||||||
### Example: Custom Builder
|
### Example: Custom Builder
|
||||||
|
|
||||||
|
Custom builders are implemented as classes which extend from `Rscons::Builder`.
|
||||||
|
The builder must have a `run` method which is called to invoke the builder.
|
||||||
|
The `run` method should return the name of the target built on success, and
|
||||||
|
`false` on failure.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class GenerateFoo < Rscons::Builder
|
class GenerateFoo < Rscons::Builder
|
||||||
def run(target, sources, cache, env, vars)
|
def run(target, sources, cache, env, vars)
|
||||||
|
cache.mkdir_p(File.dirname(target))
|
||||||
File.open(target, "w") do |fh|
|
File.open(target, "w") do |fh|
|
||||||
fh.puts <<EOF
|
fh.puts <<EOF
|
||||||
#define GENERATED 42
|
#define GENERATED 42
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(GenerateFoo.new)
|
||||||
env.GenerateFoo("foo.h", [])
|
env.GenerateFoo("foo.h", [])
|
||||||
env.Program("a.out", Dir["*.c"])
|
env.Program("a.out", Dir["*.c"])
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Example: Custom Builder That Only Regenerates When Necessary
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class CmdBuilder < Rscons::Builder
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
cmd = ["cmd", "-i", sources.first, "-o", target]
|
||||||
|
unless cache.up_to_date?(target, cmd, sources, env)
|
||||||
|
cache.mkdir_p(File.dirname(target))
|
||||||
|
system(cmd)
|
||||||
|
cache.register_build(target, cmd, sources, env)
|
||||||
|
end
|
||||||
|
target
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(CmdBuilder.new)
|
||||||
|
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
||||||
|
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()
|
||||||
|
|
||||||
|
The `standard_build` method from the `Rscons::Builder` base class can be used
|
||||||
|
when the builder needs to execute a system command to produce the target file.
|
||||||
|
The `standard_build` method will return the correct value so its return value
|
||||||
|
can be used as the return value from the `run` method.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class CmdBuilder < Rscons::Builder
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
cmd = ["cmd", "-i", sources.first, "-o", target]
|
||||||
|
standard_build("CmdBld #{target}", target, cmd, sources, env, cache)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.add_builder(CmdBuilder.new)
|
||||||
|
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Example: Using different compilation flags for some sources
|
### Example: Using different compilation flags for some sources
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@@ -96,6 +169,19 @@ Rscons::Environment.new do |env|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Each build hook block will be invoked for every build operation, so the block
|
||||||
|
should test the target or sources if its action should only apply to some
|
||||||
|
subset of build targets or source files.
|
||||||
|
|
||||||
|
The `build_op` parameter to the build hook block is a Hash describing the
|
||||||
|
build operation with the following keys:
|
||||||
|
* `:builder` - `Builder` instance in use
|
||||||
|
* `:target` - `String` name of the target file
|
||||||
|
* `:sources` - `Array` of the source files
|
||||||
|
* `:vars` - `Rscons::VarSet` containing the construction variables to use
|
||||||
|
The build hook can overwrite entries in `build_op[:vars]` to alter the
|
||||||
|
construction variables in use for this specific build operation.
|
||||||
|
|
||||||
### Example: Creating a static library
|
### Example: Creating a static library
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@@ -114,8 +200,8 @@ Rscons ships with a number of default builders:
|
|||||||
* Object, which compiles source files to produce an object file
|
* Object, which compiles source files to produce an object file
|
||||||
* Program, which links object files to produce an executable
|
* Program, which links object files to produce an executable
|
||||||
|
|
||||||
If you want to create an Environment that does not contain any (or select)
|
If you want to create an Environment that does not contain any builders,
|
||||||
builders, you can use the `exclude_builders` key to the Environment constructor.
|
you can use the `exclude_builders` key to the Environment constructor.
|
||||||
|
|
||||||
### Managing Environments
|
### Managing Environments
|
||||||
|
|
||||||
@@ -123,13 +209,14 @@ An Rscons::Environment consists of:
|
|||||||
|
|
||||||
* a collection of construction variables
|
* a collection of construction variables
|
||||||
* a collection of builders
|
* a collection of builders
|
||||||
* a mapping of build directories
|
* a mapping of build directories from source directories
|
||||||
|
* a default build root to apply if no build directories are matched
|
||||||
* a collection of targets to build
|
* a collection of targets to build
|
||||||
* a collection of build hooks
|
* a collection of build hooks
|
||||||
|
|
||||||
When cloning an environment, the construction variables, builders, and build
|
When cloning an environment, the construction variables and builders are
|
||||||
directories are cloned, but the new environment does not inherit any of the
|
cloned, but the new environment does not inherit any of the targets, build
|
||||||
targets or build hooks from the source environment.
|
hooks, build directories, or the build root from the source environment.
|
||||||
|
|
||||||
Cloned environments contain "deep copies" of construction variables.
|
Cloned environments contain "deep copies" of construction variables.
|
||||||
For example, in:
|
For example, in:
|
||||||
@@ -143,12 +230,23 @@ cloned_env["CPPPATH"] << "three"
|
|||||||
|
|
||||||
`base_env["CPPPATH"]` will not include "three".
|
`base_env["CPPPATH"]` will not include "three".
|
||||||
|
|
||||||
### Construction Variables
|
### Construction Variable Naming
|
||||||
|
|
||||||
The default construction variables that Rscons uses are named using uppercase
|
* uppercase strings - the default construction variables that Rscons uses
|
||||||
strings.
|
* lowercase symbols - Rscons options
|
||||||
Rscons options are lowercase symbols.
|
* lowercase strings - reserved as user-defined construction variables
|
||||||
Lowercase strings are reserved as user-defined construction variables.
|
|
||||||
|
### API documentation
|
||||||
|
|
||||||
|
Documentation for the complete Rscons API can be found at
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
+25
-16
@@ -1,27 +1,23 @@
|
|||||||
require "rscons/builder"
|
require_relative "rscons/builder"
|
||||||
require "rscons/cache"
|
require_relative "rscons/cache"
|
||||||
require "rscons/environment"
|
require_relative "rscons/environment"
|
||||||
require "rscons/varset"
|
require_relative "rscons/varset"
|
||||||
require "rscons/version"
|
require_relative "rscons/version"
|
||||||
|
|
||||||
require "rscons/monkey/module"
|
|
||||||
require "rscons/monkey/string"
|
|
||||||
|
|
||||||
# default builders
|
# default builders
|
||||||
require "rscons/builders/library"
|
require_relative "rscons/builders/library"
|
||||||
require "rscons/builders/object"
|
require_relative "rscons/builders/object"
|
||||||
require "rscons/builders/program"
|
require_relative "rscons/builders/program"
|
||||||
|
|
||||||
# Namespace module for rscons classes
|
# Namespace module for rscons classes
|
||||||
module Rscons
|
module Rscons
|
||||||
DEFAULT_BUILDERS = [
|
DEFAULT_BUILDERS = [
|
||||||
Library,
|
:Library,
|
||||||
Object,
|
:Object,
|
||||||
Program,
|
:Program,
|
||||||
]
|
]
|
||||||
|
|
||||||
class BuildError < Exception
|
class BuildError < RuntimeError; end
|
||||||
end
|
|
||||||
|
|
||||||
# Remove all generated files
|
# Remove all generated files
|
||||||
def self.clean
|
def self.clean
|
||||||
@@ -39,4 +35,17 @@ module Rscons
|
|||||||
end
|
end
|
||||||
Cache.clear
|
Cache.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return whether the given path is an absolute filesystem path or not
|
||||||
|
# @param path [String] the path to examine
|
||||||
|
def self.absolute_path?(path)
|
||||||
|
path =~ %r{^(/|\w:[\\/])}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return a new path by changing the suffix in path to suffix.
|
||||||
|
# @param path [String] the path to alter
|
||||||
|
# @param suffix [String] the new filename suffix
|
||||||
|
def self.set_suffix(path, suffix)
|
||||||
|
path.sub(/\.[^.]*$/, suffix)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
+11
-2
@@ -1,8 +1,17 @@
|
|||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
|
||||||
module Rscons
|
module Rscons
|
||||||
|
# Namespace module in which to store builders for convenient grouping
|
||||||
|
module Builders; end
|
||||||
|
|
||||||
# Class to hold an object that knows how to build a certain type of file.
|
# Class to hold an object that knows how to build a certain type of file.
|
||||||
class Builder
|
class Builder
|
||||||
|
# Return the name of the builder.
|
||||||
|
# If not overridden this defaults to the last component of the class name.
|
||||||
|
def name
|
||||||
|
self.class.name.split(":").last
|
||||||
|
end
|
||||||
|
|
||||||
# Return a set of default variable values for the Environment to use
|
# Return a set of default variable values for the Environment to use
|
||||||
# unless the user overrides any.
|
# unless the user overrides any.
|
||||||
# @param env [Environment] The Environment.
|
# @param env [Environment] The Environment.
|
||||||
@@ -23,11 +32,11 @@ module Rscons
|
|||||||
# build command.
|
# build command.
|
||||||
# Return the name of the target or false on failure.
|
# Return the name of the target or false on failure.
|
||||||
def standard_build(short_cmd_string, target, command, sources, env, cache)
|
def standard_build(short_cmd_string, target, command, sources, env, cache)
|
||||||
unless cache.up_to_date?(target, command, sources)
|
unless cache.up_to_date?(target, command, sources, env)
|
||||||
cache.mkdir_p(File.dirname(target))
|
cache.mkdir_p(File.dirname(target))
|
||||||
FileUtils.rm_f(target)
|
FileUtils.rm_f(target)
|
||||||
return false unless env.execute(short_cmd_string, command)
|
return false unless env.execute(short_cmd_string, command)
|
||||||
cache.register_build(target, command, sources)
|
cache.register_build(target, command, sources, env)
|
||||||
end
|
end
|
||||||
target
|
target
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
require 'fileutils'
|
|
||||||
|
|
||||||
module Rscons
|
module Rscons
|
||||||
|
module Builders
|
||||||
# A default RScons builder that produces a static library archive.
|
# A default RScons builder that produces a static library archive.
|
||||||
class Library < Builder
|
class Rscons::Builders::Library < Rscons::Builder
|
||||||
def default_variables(env)
|
def default_variables(env)
|
||||||
{
|
{
|
||||||
'AR' => 'ar',
|
'AR' => 'ar',
|
||||||
@@ -12,7 +11,7 @@ module Rscons
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars = {})
|
def run(target, sources, cache, env, vars)
|
||||||
# build sources to linkable objects
|
# build sources to linkable objects
|
||||||
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
||||||
if objects
|
if objects
|
||||||
@@ -25,4 +24,5 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
|
module Builders
|
||||||
# A default RScons builder which knows how to produce an object file from
|
# A default RScons builder which knows how to produce an object file from
|
||||||
# various types of source files.
|
# various types of source files.
|
||||||
class Object < Builder
|
class Object < Builder
|
||||||
@@ -45,24 +46,24 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
def produces?(target, source, env)
|
def produces?(target, source, env)
|
||||||
target.has_suffix?(env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
target.end_with?(*env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||||
source.has_suffix?(env[suffix_var])
|
source.end_with?(*env[suffix_var])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars = {})
|
def run(target, sources, cache, env, vars)
|
||||||
vars = vars.merge({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => sources,
|
'_SOURCES' => sources,
|
||||||
'_DEPFILE' => target.set_suffix('.mf'),
|
'_DEPFILE' => Rscons.set_suffix(target, '.mf'),
|
||||||
})
|
})
|
||||||
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||||
sources.first.has_suffix?(env[suffix_var])
|
sources.first.end_with?(*env[suffix_var])
|
||||||
end.tap do |v|
|
end.tap do |v|
|
||||||
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||||
end.first
|
end.first
|
||||||
command = env.build_command(env["#{com_prefix}CMD"], vars)
|
command = env.build_command(env["#{com_prefix}CMD"], vars)
|
||||||
unless cache.up_to_date?(target, command, sources)
|
unless cache.up_to_date?(target, command, sources, env)
|
||||||
cache.mkdir_p(File.dirname(target))
|
cache.mkdir_p(File.dirname(target))
|
||||||
FileUtils.rm_f(target)
|
FileUtils.rm_f(target)
|
||||||
return false unless env.execute("#{com_prefix} #{target}", command)
|
return false unless env.execute("#{com_prefix} #{target}", command)
|
||||||
@@ -71,9 +72,10 @@ module Rscons
|
|||||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
||||||
FileUtils.rm_f(vars['_DEPFILE'])
|
FileUtils.rm_f(vars['_DEPFILE'])
|
||||||
end
|
end
|
||||||
cache.register_build(target, command, deps.uniq)
|
cache.register_build(target, command, deps.uniq, env)
|
||||||
end
|
end
|
||||||
target
|
target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
|
module Builders
|
||||||
# A default RScons builder that knows how to link object files into an
|
# A default RScons builder that knows how to link object files into an
|
||||||
# executable program.
|
# executable program.
|
||||||
class Program < Builder
|
class Rscons::Builders::Program < Rscons::Builder
|
||||||
def default_variables(env)
|
def default_variables(env)
|
||||||
{
|
{
|
||||||
'LD' => nil,
|
'LD' => nil,
|
||||||
@@ -14,14 +15,15 @@ module Rscons
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars = {})
|
def run(target, sources, cache, env, vars)
|
||||||
# build sources to linkable objects
|
# build sources to linkable objects
|
||||||
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
||||||
|
return false unless objects
|
||||||
ld = if env["LD"]
|
ld = if env["LD"]
|
||||||
env["LD"]
|
env["LD"]
|
||||||
elsif sources.find {|s| s.has_suffix?(env["DSUFFIX"])}
|
elsif sources.find {|s| s.end_with?(*env["DSUFFIX"])}
|
||||||
env["DC"]
|
env["DC"]
|
||||||
elsif sources.find {|s| s.has_suffix?(env["CXXSUFFIX"])}
|
elsif sources.find {|s| s.end_with?(*env["CXXSUFFIX"])}
|
||||||
env["CXX"]
|
env["CXX"]
|
||||||
else
|
else
|
||||||
env["CC"]
|
env["CC"]
|
||||||
@@ -35,4 +37,5 @@ module Rscons
|
|||||||
standard_build("LD #{target}", target, command, objects, env, cache)
|
standard_build("LD #{target}", target, command, objects, env, cache)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
+47
-20
@@ -18,9 +18,15 @@ module Rscons
|
|||||||
# {
|
# {
|
||||||
# 'fname' => 'program.o',
|
# 'fname' => 'program.o',
|
||||||
# 'checksum' => '87654321',
|
# 'checksum' => '87654321',
|
||||||
# }
|
# },
|
||||||
# ],
|
# ],
|
||||||
# }
|
# 'user_deps' => [
|
||||||
|
# {
|
||||||
|
# 'fname' => 'lscript.ld',
|
||||||
|
# 'checksum' => '77551133',
|
||||||
|
# },
|
||||||
|
# ],
|
||||||
|
# },
|
||||||
# 'program.o' => {
|
# 'program.o' => {
|
||||||
# 'checksum' => '87654321',
|
# 'checksum' => '87654321',
|
||||||
# 'command' => ['gcc', '-c', '-o', 'program.o', 'program.c'],
|
# 'command' => ['gcc', '-c', '-o', 'program.o', 'program.c'],
|
||||||
@@ -32,15 +38,16 @@ module Rscons
|
|||||||
# {
|
# {
|
||||||
# 'fname' => 'program.h',
|
# 'fname' => 'program.h',
|
||||||
# 'checksum' => '7979764643',
|
# 'checksum' => '7979764643',
|
||||||
|
# },
|
||||||
|
# ],
|
||||||
|
# 'user_deps' => [],
|
||||||
# }
|
# }
|
||||||
# ]
|
# },
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# directories: {
|
# directories: {
|
||||||
# 'build' => true,
|
# 'build' => true,
|
||||||
# 'build/one' => true,
|
# 'build/one' => true,
|
||||||
# 'build/two' => true,
|
# 'build/two' => true,
|
||||||
# }
|
# },
|
||||||
# }
|
# }
|
||||||
class Cache
|
class Cache
|
||||||
#### Constants
|
#### Constants
|
||||||
@@ -78,15 +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 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
|
||||||
@@ -96,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, 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)
|
||||||
|
|
||||||
@@ -109,28 +119,38 @@ module Rscons
|
|||||||
# command used to build target must be identical
|
# command used to build target must be identical
|
||||||
return false unless @cache[:targets][target][:command] == command
|
return false unless @cache[:targets][target][:command] == command
|
||||||
|
|
||||||
cached_deps = @cache[:targets][target][:deps].map { |dc| dc[:fname] }
|
cached_deps = @cache[:targets][target][:deps] || []
|
||||||
|
cached_deps_fnames = cached_deps.map { |dc| dc[:fname] }
|
||||||
if options[:strict_deps]
|
if options[:strict_deps]
|
||||||
# depedencies passed in must exactly equal those in the cache
|
# depedencies passed in must exactly equal those in the cache
|
||||||
return false unless deps == cached_deps
|
return false unless deps == cached_deps_fnames
|
||||||
else
|
else
|
||||||
# all dependencies passed in must exist in cache (but cache may have more)
|
# all dependencies passed in must exist in cache (but cache may have more)
|
||||||
return false unless (Set.new(deps) - Set.new(cached_deps)).empty?
|
return false unless (Set.new(deps) - Set.new(cached_deps_fnames)).empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# set of user dependencies must match
|
||||||
|
user_deps = env.get_user_deps(target) || []
|
||||||
|
cached_user_deps = @cache[:targets][target][:user_deps] || []
|
||||||
|
cached_user_deps_fnames = cached_user_deps.map { |dc| dc[:fname] }
|
||||||
|
return false unless user_deps == cached_user_deps_fnames
|
||||||
|
|
||||||
# all cached dependencies must have their checksums match
|
# all cached dependencies must have their checksums match
|
||||||
@cache[:targets][target][: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.
|
||||||
def register_build(target, command, deps)
|
# @param env [Environment] The Rscons::Environment.
|
||||||
|
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),
|
||||||
@@ -139,8 +159,15 @@ module Rscons
|
|||||||
fname: dep.encode(__ENCODING__),
|
fname: dep.encode(__ENCODING__),
|
||||||
checksum: lookup_checksum(dep),
|
checksum: lookup_checksum(dep),
|
||||||
}
|
}
|
||||||
end
|
end,
|
||||||
|
user_deps: (env.get_user_deps(target) || []).map do |dep|
|
||||||
|
{
|
||||||
|
fname: dep.encode(__ENCODING__),
|
||||||
|
checksum: lookup_checksum(dep),
|
||||||
}
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a list of targets that have been built
|
# Return a list of targets that have been built
|
||||||
|
|||||||
+74
-31
@@ -9,30 +9,39 @@ module Rscons
|
|||||||
# Hash of +{"builder_name" => builder_object}+ pairs.
|
# Hash of +{"builder_name" => builder_object}+ pairs.
|
||||||
attr_reader :builders
|
attr_reader :builders
|
||||||
|
|
||||||
|
# :command, :short, or :off
|
||||||
|
attr_accessor :echo
|
||||||
|
|
||||||
|
# String or +nil+
|
||||||
|
attr_reader :build_root
|
||||||
|
def build_root=(build_root)
|
||||||
|
@build_root = build_root.gsub('\\', '/')
|
||||||
|
end
|
||||||
|
|
||||||
# Create an Environment object.
|
# Create an Environment object.
|
||||||
# @param variables [Hash]
|
# @param options [Hash]
|
||||||
# The variables hash can contain construction variables, which are
|
# Possible options keys:
|
||||||
# uppercase strings (such as "CC" or "LDFLAGS"), user variables, which
|
# :echo => :command, :short, or :off (default :short)
|
||||||
# are lowercase strings (such as "sources"), and RScons options, which
|
# :build_root => String specifying build root directory (default nil)
|
||||||
# are lowercase symbols (such as :echo).
|
# :exclude_builders => true 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(variables = {})
|
def initialize(options = {})
|
||||||
@varset = VarSet.new(variables)
|
@varset = VarSet.new
|
||||||
@targets = {}
|
@targets = {}
|
||||||
|
@user_deps = {}
|
||||||
@builders = {}
|
@builders = {}
|
||||||
@build_dirs = []
|
@build_dirs = []
|
||||||
@build_hooks = []
|
@build_hooks = []
|
||||||
@varset[:exclude_builders] ||= []
|
unless options[:exclude_builders]
|
||||||
unless @varset[:exclude_builders] == :all
|
DEFAULT_BUILDERS.each do |builder_class_name|
|
||||||
exclude_builders = Set.new(@varset[:exclude_builders] || [])
|
builder_class = Builders.const_get(builder_class_name)
|
||||||
DEFAULT_BUILDERS.each do |builder_class|
|
builder_class or raise "Could not find builder class #{builder_class_name}"
|
||||||
unless exclude_builders.include?(builder_class.short_name)
|
|
||||||
add_builder(builder_class.new)
|
add_builder(builder_class.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
@echo = options[:echo] || :short
|
||||||
@varset[:echo] ||= :short
|
@build_root = options[:build_root]
|
||||||
|
|
||||||
if block_given?
|
if block_given?
|
||||||
yield self
|
yield self
|
||||||
@@ -42,17 +51,23 @@ 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, and builders (unless :exclude_builders => true is
|
||||||
# contain a copy of the targets or build hooks.
|
# passed as an option). It will not contain a copy of the targets, build
|
||||||
# If a block is given, the Environment object is yielded to the block and
|
# hooks, build directories, or the build root. If a block is given, the
|
||||||
# when the block returns, the {#process} method is automatically called.
|
# Environment object is yielded to the block and when the block returns,
|
||||||
def clone(variables = {})
|
# the {#process} method is automatically called. The possible options keys
|
||||||
env = Environment.new()
|
# match those documented in the #initialize method.
|
||||||
|
def clone(options = {})
|
||||||
|
env = self.class.new(
|
||||||
|
echo: options[:echo] || @echo,
|
||||||
|
build_root: options[:build_root],
|
||||||
|
exclude_builders: true)
|
||||||
|
unless options[:exclude_builders]
|
||||||
@builders.each do |builder_name, builder|
|
@builders.each do |builder_name, builder|
|
||||||
env.add_builder(builder)
|
env.add_builder(builder)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
env.append(@varset.clone)
|
env.append(@varset.clone)
|
||||||
env.append(variables)
|
|
||||||
|
|
||||||
if block_given?
|
if block_given?
|
||||||
yield env
|
yield env
|
||||||
@@ -63,7 +78,7 @@ module Rscons
|
|||||||
|
|
||||||
# Add a {Builder} object to the Environment.
|
# Add a {Builder} object to the Environment.
|
||||||
def add_builder(builder)
|
def add_builder(builder)
|
||||||
@builders[builder.class.short_name] = builder
|
@builders[builder.name] = builder
|
||||||
var_defs = builder.default_variables(self)
|
var_defs = builder.default_variables(self)
|
||||||
if var_defs
|
if var_defs
|
||||||
var_defs.each_pair do |var, val|
|
var_defs.each_pair do |var, val|
|
||||||
@@ -87,15 +102,20 @@ module Rscons
|
|||||||
# Return the file name to be built from source_fname with suffix suffix.
|
# Return the file name to be built from source_fname with suffix suffix.
|
||||||
# This method takes into account the Environment's build directories.
|
# This method takes into account the Environment's build directories.
|
||||||
def get_build_fname(source_fname, suffix)
|
def get_build_fname(source_fname, suffix)
|
||||||
build_fname = source_fname.set_suffix(suffix).gsub('\\', '/')
|
build_fname = Rscons.set_suffix(source_fname, suffix).gsub('\\', '/')
|
||||||
@build_dirs.each do |src_dir, obj_dir|
|
found_match = @build_dirs.find do |src_dir, obj_dir|
|
||||||
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!(%r{^#{src_dir}/}, "#{obj_dir}/")
|
build_fname.sub!(%r{^#{src_dir}/}, "#{obj_dir}/")
|
||||||
end
|
end
|
||||||
build_fname.gsub!('\\', '/')
|
|
||||||
end
|
end
|
||||||
|
if @build_root and not found_match
|
||||||
|
unless Rscons.absolute_path?(source_fname) or build_fname.start_with?("#{@build_root}/")
|
||||||
|
build_fname = "#{@build_root}/#{build_fname}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
build_fname.gsub!('\\', '/')
|
||||||
build_fname
|
build_fname
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -148,6 +168,11 @@ module Rscons
|
|||||||
cache.write
|
cache.write
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clear all targets registered for the Environment.
|
||||||
|
def clear_targets
|
||||||
|
@targets = {}
|
||||||
|
end
|
||||||
|
|
||||||
# Build a command line from the given template, resolving references to
|
# Build a command line from the given template, resolving references to
|
||||||
# variables using the Environment's construction variables and any extra
|
# variables using the Environment's construction variables and any extra
|
||||||
# variables specified.
|
# variables specified.
|
||||||
@@ -160,8 +185,13 @@ module Rscons
|
|||||||
@varset.merge(extra_vars).expand_varref(command_template)
|
@varset.merge(extra_vars).expand_varref(command_template)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Expand a construction variable reference (String or Array)
|
||||||
|
def expand_varref(varref)
|
||||||
|
@varset.expand_varref(varref)
|
||||||
|
end
|
||||||
|
|
||||||
# Execute a builder command
|
# Execute a builder command
|
||||||
# @param short_desc [String] Message to print if the Environment's :echo
|
# @param short_desc [String] Message to print if the Environment's echo
|
||||||
# mode is set to :short
|
# mode is set to :short
|
||||||
# @param command [Array] The command to execute.
|
# @param command [Array] The command to execute.
|
||||||
# @param options [Hash] Optional options to pass to Kernel#system.
|
# @param options [Hash] Optional options to pass to Kernel#system.
|
||||||
@@ -169,13 +199,13 @@ module Rscons
|
|||||||
print_command = proc do
|
print_command = proc do
|
||||||
puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ')
|
puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ')
|
||||||
end
|
end
|
||||||
if @varset[:echo] == :command
|
if @echo == :command
|
||||||
print_command.call
|
print_command.call
|
||||||
elsif @varset[:echo] == :short
|
elsif @echo == :short
|
||||||
puts short_desc
|
puts short_desc
|
||||||
end
|
end
|
||||||
system(*command, options).tap do |result|
|
system(*command, options).tap do |result|
|
||||||
unless result or @varset[:echo] == :command
|
unless result or @echo == :command
|
||||||
$stdout.write "Failed command was: "
|
$stdout.write "Failed command was: "
|
||||||
print_command.call
|
print_command.call
|
||||||
end
|
end
|
||||||
@@ -201,6 +231,19 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Manually record a given target as depending on the specified
|
||||||
|
# dependency files.
|
||||||
|
def depends(target, *user_deps)
|
||||||
|
@user_deps[target] ||= []
|
||||||
|
@user_deps[target] = (@user_deps[target] + user_deps).uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return the list of user dependencies for a given target, or +nil+ for
|
||||||
|
# none.
|
||||||
|
def get_user_deps(target)
|
||||||
|
@user_deps[target]
|
||||||
|
end
|
||||||
|
|
||||||
# Build a list of source files into files containing one of the suffixes
|
# Build a list of source files into files containing one of the suffixes
|
||||||
# given by suffixes.
|
# given by suffixes.
|
||||||
# This method is used internally by RScons builders.
|
# This method is used internally by RScons builders.
|
||||||
@@ -209,9 +252,9 @@ module Rscons
|
|||||||
# @param cache [Cache] The Cache.
|
# @param cache [Cache] The Cache.
|
||||||
# @param vars [Hash] Extra variables to pass to the builder.
|
# @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|
|
||||||
if source.has_suffix?(suffixes)
|
if source.end_with?(*suffixes)
|
||||||
source
|
source
|
||||||
else
|
else
|
||||||
converted = nil
|
converted = nil
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
# Standard Ruby Module class.
|
|
||||||
class Module
|
|
||||||
# @return the base module name (not the fully qualified name)
|
|
||||||
def short_name
|
|
||||||
name.split(':').last
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# Standard Ruby String class.
|
|
||||||
class String
|
|
||||||
# Check if the given string ends with any of the supplied suffixes
|
|
||||||
# @param suffix [String, Array] The suffix to look for.
|
|
||||||
# @return a true value if the string ends with one of the suffixes given.
|
|
||||||
def has_suffix?(suffix)
|
|
||||||
if suffix
|
|
||||||
suffix = [suffix] if suffix.is_a?(String)
|
|
||||||
suffix = suffix.flatten
|
|
||||||
suffix.find {|s| self.end_with?(s)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return a new string with the suffix (dot character and extension) changed
|
|
||||||
# to the given suffix.
|
|
||||||
# @param suffix [String] The new suffix.
|
|
||||||
def set_suffix(suffix = '')
|
|
||||||
sub(/\.[^.]*$/, suffix)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
+3
-15
@@ -17,20 +17,8 @@ module Rscons
|
|||||||
|
|
||||||
# Access the value of variable as a particular type
|
# Access the value of variable as a particular type
|
||||||
# @param key [String, Symbol] The variable name.
|
# @param key [String, Symbol] The variable name.
|
||||||
# @param type [Symbol, nil] Optional specification of the type desired.
|
def [](key)
|
||||||
# If the variable is a String and type is :array, a 1-element array with
|
@vars[key]
|
||||||
# the variable value will be returned. If the variable is an Array and
|
|
||||||
# type is :string, the first element from the variable value will be
|
|
||||||
# returned.
|
|
||||||
def [](key, type = nil)
|
|
||||||
val = @vars[key]
|
|
||||||
if type == :array and not val.is_a?(Array)
|
|
||||||
[val]
|
|
||||||
elsif type == :scalar and val.is_a?(Array)
|
|
||||||
val.first
|
|
||||||
else
|
|
||||||
val
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Assign a value to a variable.
|
# Assign a value to a variable.
|
||||||
@@ -72,7 +60,7 @@ module Rscons
|
|||||||
elsif varval.is_a?(Array)
|
elsif varval.is_a?(Array)
|
||||||
varval.map {|vv| expand_varref("#{prefix}#{vv}#{suffix}")}.flatten
|
varval.map {|vv| expand_varref("#{prefix}#{vv}#{suffix}")}.flatten
|
||||||
else
|
else
|
||||||
raise "I do not know how to expand a variable reference to a #{varval.class.name}"
|
raise "I do not know how to expand a variable reference to a #{varval.class.name} (from #{varname.inspect} => #{@vars[varname].inspect})"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
varref
|
varref
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
# gem version
|
# gem version
|
||||||
VERSION = "0.1.0"
|
VERSION = "1.1.0"
|
||||||
end
|
end
|
||||||
@@ -158,6 +158,28 @@ describe Rscons do
|
|||||||
File.exists?('build_two/two.o').should be_true
|
File.exists?('build_two/two.o').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'uses build directories before build root' do
|
||||||
|
test_dir('build_dir')
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.append('CPPPATH' => Dir['src/**/*/'])
|
||||||
|
env.build_dir("src", "build")
|
||||||
|
env.build_root = "build_root"
|
||||||
|
env.Program('build_dir', Dir['src/**/*.c'])
|
||||||
|
end
|
||||||
|
lines.should == ["CC build/one/one.o", "CC build/two/two.o", "LD build_dir"]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses build_root if no build directories match' do
|
||||||
|
test_dir('build_dir')
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.append('CPPPATH' => Dir['src/**/*/'])
|
||||||
|
env.build_dir("src2", "build")
|
||||||
|
env.build_root = "build_root"
|
||||||
|
env.Program('build_dir', Dir['src/**/*.c'])
|
||||||
|
end
|
||||||
|
lines.should == ["CC build_root/src/one/one.o", "CC build_root/src/two/two.o", "LD build_dir"]
|
||||||
|
end
|
||||||
|
|
||||||
it 'cleans built files' do
|
it 'cleans built files' do
|
||||||
test_dir('build_dir')
|
test_dir('build_dir')
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
@@ -198,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, 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
|
||||||
@@ -219,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')
|
||||||
|
|
||||||
@@ -229,7 +284,8 @@ EOF
|
|||||||
env.Program('program-debug', Dir['src/*.c'])
|
env.Program('program-debug', Dir['src/*.c'])
|
||||||
end
|
end
|
||||||
|
|
||||||
release = debug.clone('CPPFLAGS' => '-DSTRING="Release Version"') do |env|
|
release = debug.clone do |env|
|
||||||
|
env["CPPFLAGS"] = '-DSTRING="Release Version"'
|
||||||
env.build_dir('src', 'release')
|
env.build_dir('src', 'release')
|
||||||
env.Program('program-release', Dir['src/*.c'])
|
env.Program('program-release', Dir['src/*.c'])
|
||||||
end
|
end
|
||||||
@@ -305,6 +361,37 @@ EOF
|
|||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'rebuilds when user-specified dependencies change' do
|
||||||
|
test_dir('simple')
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Program('simple', Dir['*.c'])
|
||||||
|
File.open("file.ld", "w") do |fh|
|
||||||
|
fh.puts("foo")
|
||||||
|
end
|
||||||
|
env.depends('simple', 'file.ld')
|
||||||
|
end
|
||||||
|
lines.should == ["CC simple.o", "LD simple"]
|
||||||
|
File.exists?('simple.o').should be_true
|
||||||
|
`./simple`.should == "This is a simple C program\n"
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Program('simple', Dir['*.c'])
|
||||||
|
File.open("file.ld", "w") do |fh|
|
||||||
|
fh.puts("bar")
|
||||||
|
end
|
||||||
|
env.depends('simple', 'file.ld')
|
||||||
|
end
|
||||||
|
lines.should == ["LD simple"]
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Program('simple', Dir['*.c'])
|
||||||
|
File.unlink("file.ld")
|
||||||
|
end
|
||||||
|
lines.should == ["LD simple"]
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Program('simple', Dir['*.c'])
|
||||||
|
end
|
||||||
|
lines.should == []
|
||||||
|
end
|
||||||
|
|
||||||
unless ENV["omit_gdc_tests"]
|
unless ENV["omit_gdc_tests"]
|
||||||
it "supports building D sources" do
|
it "supports building D sources" do
|
||||||
test_dir("d")
|
test_dir("d")
|
||||||
|
|||||||
+62
-12
@@ -38,14 +38,19 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#up_to_date?" do
|
describe "#up_to_date?" do
|
||||||
|
empty_env = "env"
|
||||||
|
before do
|
||||||
|
empty_env.stub(:get_user_deps) { nil }
|
||||||
|
end
|
||||||
|
|
||||||
it "returns false when target file does not exist" do
|
it "returns false when target file does not exist" do
|
||||||
File.should_receive(:exists?).with("target").and_return(false)
|
File.should_receive(:exists?).with("target").and_return(false)
|
||||||
build_from({}).up_to_date?("target", "command", []).should be_false
|
build_from({}).up_to_date?("target", "command", [], empty_env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when target is not registered in the cache" do
|
it "returns false when target is not registered in the cache" do
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
build_from({}).up_to_date?("target", "command", []).should be_false
|
build_from({}).up_to_date?("target", "command", [], empty_env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when the target's checksum does not match" do
|
it "returns false when the target's checksum does not match" do
|
||||||
@@ -53,7 +58,7 @@ module Rscons
|
|||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("def")
|
cache.should_receive(:calculate_checksum).with("target").and_return("def")
|
||||||
cache.up_to_date?("target", "command", []).should be_false
|
cache.up_to_date?("target", "command", [], empty_env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when the build command has changed" do
|
it "returns false when the build command has changed" do
|
||||||
@@ -61,7 +66,7 @@ module Rscons
|
|||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.up_to_date?("target", "command", []).should be_false
|
cache.up_to_date?("target", "command", [], empty_env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when there is a new dependency" do
|
it "returns false when there is a new dependency" do
|
||||||
@@ -71,7 +76,7 @@ module Rscons
|
|||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.up_to_date?("target", "command", ["dep.1", "dep.2"]).should be_false
|
cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when a dependency's checksum has changed" do
|
it "returns false when a dependency's checksum has changed" do
|
||||||
@@ -82,13 +87,14 @@ module Rscons
|
|||||||
{fname: "dep.2",
|
{fname: "dep.2",
|
||||||
checksum: "dep.2.chk"},
|
checksum: "dep.2.chk"},
|
||||||
{fname: "extra.dep",
|
{fname: "extra.dep",
|
||||||
checksum: "extra.dep.chk"}]}}}
|
checksum: "extra.dep.chk"}],
|
||||||
|
user_deps: []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.changed")
|
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.changed")
|
||||||
cache.up_to_date?("target", "command", ["dep.1", "dep.2"]).should be_false
|
cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false with strict_deps=true when cache has an extra dependency" do
|
it "returns false with strict_deps=true when cache has an extra dependency" do
|
||||||
@@ -99,11 +105,48 @@ module Rscons
|
|||||||
{fname: "dep.2",
|
{fname: "dep.2",
|
||||||
checksum: "dep.2.chk"},
|
checksum: "dep.2.chk"},
|
||||||
{fname: "extra.dep",
|
{fname: "extra.dep",
|
||||||
checksum: "extra.dep.chk"}]}}}
|
checksum: "extra.dep.chk"}],
|
||||||
|
user_deps: []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.up_to_date?("target", "command", ["dep.1", "dep.2"], strict_deps: true).should be_false
|
cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env, strict_deps: true).should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when there is a new user dependency" do
|
||||||
|
_cache = {targets: {"target" => {checksum: "abc",
|
||||||
|
command: "command",
|
||||||
|
deps: [{fname: "dep.1"}],
|
||||||
|
user_deps: []}}}
|
||||||
|
cache = build_from(_cache)
|
||||||
|
env = "env"
|
||||||
|
env.should_receive(:get_user_deps).with("target").and_return(["file.ld"])
|
||||||
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
|
cache.up_to_date?("target", "command", ["dep.1"], env).should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when a user dependency checksum has changed" do
|
||||||
|
_cache = {targets: {"target" => {checksum: "abc",
|
||||||
|
command: "command",
|
||||||
|
deps: [{fname: "dep.1",
|
||||||
|
checksum: "dep.1.chk"},
|
||||||
|
{fname: "dep.2",
|
||||||
|
checksum: "dep.2.chk"},
|
||||||
|
{fname: "extra.dep",
|
||||||
|
checksum: "extra.dep.chk"}],
|
||||||
|
user_deps: [{fname: "user.dep",
|
||||||
|
checksum: "user.dep.chk"}]}}}
|
||||||
|
cache = build_from(_cache)
|
||||||
|
env = "env"
|
||||||
|
env.should_receive(:get_user_deps).with("target").and_return(["user.dep"])
|
||||||
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
|
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||||
|
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
||||||
|
cache.should_receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
||||||
|
cache.should_receive(:calculate_checksum).with("user.dep").and_return("INCORRECT")
|
||||||
|
cache.up_to_date?("target", "command", ["dep.1", "dep.2"], env).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns true when no condition for false is met" do
|
it "returns true when no condition for false is met" do
|
||||||
@@ -114,14 +157,15 @@ module Rscons
|
|||||||
{fname: "dep.2",
|
{fname: "dep.2",
|
||||||
checksum: "dep.2.chk"},
|
checksum: "dep.2.chk"},
|
||||||
{fname: "extra.dep",
|
{fname: "extra.dep",
|
||||||
checksum: "extra.dep.chk"}]}}}
|
checksum: "extra.dep.chk"}],
|
||||||
|
user_deps: []}}}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
File.should_receive(:exists?).with("target").and_return(true)
|
File.should_receive(:exists?).with("target").and_return(true)
|
||||||
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
cache.should_receive(:calculate_checksum).with("target").and_return("abc")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
cache.should_receive(:calculate_checksum).with("dep.1").and_return("dep.1.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
cache.should_receive(:calculate_checksum).with("dep.2").and_return("dep.2.chk")
|
||||||
cache.should_receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
cache.should_receive(:calculate_checksum).with("extra.dep").and_return("extra.dep.chk")
|
||||||
cache.up_to_date?("target", "command", ["dep.1", "dep.2"]).should be_true
|
cache.up_to_date?("target", "command", ["dep.1", "dep.2"], empty_env).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -129,10 +173,13 @@ module Rscons
|
|||||||
it "stores the given information in the cache" do
|
it "stores the given information in the cache" do
|
||||||
_cache = {}
|
_cache = {}
|
||||||
cache = build_from(_cache)
|
cache = build_from(_cache)
|
||||||
|
env = "env"
|
||||||
|
env.should_receive(:get_user_deps).with("the target").and_return(["user.dep"])
|
||||||
cache.should_receive(:calculate_checksum).with("the target").and_return("the checksum")
|
cache.should_receive(:calculate_checksum).with("the target").and_return("the checksum")
|
||||||
cache.should_receive(:calculate_checksum).with("dep 1").and_return("dep 1 checksum")
|
cache.should_receive(:calculate_checksum).with("dep 1").and_return("dep 1 checksum")
|
||||||
cache.should_receive(:calculate_checksum).with("dep 2").and_return("dep 2 checksum")
|
cache.should_receive(:calculate_checksum).with("dep 2").and_return("dep 2 checksum")
|
||||||
cache.register_build("the target", "the command", ["dep 1", "dep 2"])
|
cache.should_receive(:calculate_checksum).with("user.dep").and_return("user.dep checksum")
|
||||||
|
cache.register_build("the target", "the command", ["dep 1", "dep 2"], env)
|
||||||
cached_target = cache.instance_variable_get(:@cache)[:targets]["the target"]
|
cached_target = cache.instance_variable_get(:@cache)[:targets]["the target"]
|
||||||
cached_target.should_not be_nil
|
cached_target.should_not be_nil
|
||||||
cached_target[:command].should == "the command"
|
cached_target[:command].should == "the command"
|
||||||
@@ -141,6 +188,9 @@ module Rscons
|
|||||||
{fname: "dep 1", checksum: "dep 1 checksum"},
|
{fname: "dep 1", checksum: "dep 1 checksum"},
|
||||||
{fname: "dep 2", checksum: "dep 2 checksum"},
|
{fname: "dep 2", checksum: "dep 2 checksum"},
|
||||||
]
|
]
|
||||||
|
cached_target[:user_deps].should == [
|
||||||
|
{fname: "user.dep", checksum: "user.dep checksum"},
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
describe Environment do
|
describe Environment do
|
||||||
describe "#initialize" do
|
describe "#initialize" do
|
||||||
it "stores the construction variables passed in" do
|
|
||||||
env = Environment.new("CFLAGS" => ["-g"], "CPPPATH" => ["dir"])
|
|
||||||
env["CFLAGS"].should == ["-g"]
|
|
||||||
env["CPPPATH"].should == ["dir"]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "adds the default builders when they are not excluded" do
|
it "adds the default builders when they are not excluded" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
env.builders.size.should be > 0
|
env.builders.size.should be > 0
|
||||||
@@ -17,18 +11,10 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "excludes the default builders with exclude_builders: :all" do
|
it "excludes the default builders with exclude_builders: :all" do
|
||||||
env = Environment.new(exclude_builders: :all)
|
env = Environment.new(exclude_builders: true)
|
||||||
env.builders.size.should == 0
|
env.builders.size.should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "excludes the named builders" do
|
|
||||||
env = Environment.new(exclude_builders: ["Library"])
|
|
||||||
env.builders.size.should be > 0
|
|
||||||
env.builders.find {|name, builder| name == "Object"}.should_not be_nil
|
|
||||||
env.builders.find {|name, builder| name == "Program"}.should_not be_nil
|
|
||||||
env.builders.find {|name, builder| name == "Library"}.should be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when a block is given" do
|
context "when a block is given" do
|
||||||
it "yields self and invokes #process()" do
|
it "yields self and invokes #process()" do
|
||||||
env = Environment.new do |env|
|
env = Environment.new do |env|
|
||||||
@@ -60,9 +46,9 @@ module Rscons
|
|||||||
|
|
||||||
describe "#add_builder" do
|
describe "#add_builder" do
|
||||||
it "adds the builder to the list of builders" do
|
it "adds the builder to the list of builders" do
|
||||||
env = Environment.new(exclude_builders: :all)
|
env = Environment.new(exclude_builders: true)
|
||||||
env.builders.keys.should == []
|
env.builders.keys.should == []
|
||||||
env.add_builder(Rscons::Object.new)
|
env.add_builder(Rscons::Builders::Object.new)
|
||||||
env.builders.keys.should == ["Object"]
|
env.builders.keys.should == ["Object"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -75,6 +61,18 @@ module Rscons
|
|||||||
env.get_build_fname("src\\dir\\other.d", ".a").should == "src/dir/other.a"
|
env.get_build_fname("src\\dir\\other.d", ".a").should == "src/dir/other.a"
|
||||||
env.get_build_fname("source.cc", ".o").should == "source.o"
|
env.get_build_fname("source.cc", ".o").should == "source.o"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with a build_root" do
|
||||||
|
it "uses the build_root unless the path is absolute" do
|
||||||
|
env = Environment.new
|
||||||
|
env.build_root = "build/proj"
|
||||||
|
env.get_build_fname("src/dir/file.c", ".o").should == "build/proj/src/dir/file.o"
|
||||||
|
env.get_build_fname("/some/lib.c", ".a").should == "/some/lib.a"
|
||||||
|
env.get_build_fname("C:\\abspath\\mod.cc", ".o").should == "C:/abspath/mod.o"
|
||||||
|
env.get_build_fname("build\\proj\\generated.c", ".o").should == "build/proj/generated.o"
|
||||||
|
env.get_build_fname("build/proj.XX", ".yy").should == "build/proj/build/proj.yy"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with build directories" do
|
context "with build directories" do
|
||||||
@@ -87,19 +85,36 @@ module Rscons
|
|||||||
env.get_build_fname("libs/otherlib/otherlib.cc", ".o").should == "build/libs/otherlib/otherlib.o"
|
env.get_build_fname("libs/otherlib/otherlib.cc", ".o").should == "build/libs/otherlib/otherlib.o"
|
||||||
env.get_build_fname("other_directory/o.d", ".a").should == "other_directory/o.a"
|
env.get_build_fname("other_directory/o.d", ".a").should == "other_directory/o.a"
|
||||||
end
|
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"
|
||||||
|
|
||||||
|
env.get_build_fname("src/input.cc", ".o").should == "bld/input.o"
|
||||||
|
env.get_build_fname("libs/lib1/some/file.c", ".o").should == "build/libs/lib1/some/file.o"
|
||||||
|
env.get_build_fname("libs/otherlib/otherlib.cc", ".o").should == "build/libs/otherlib/otherlib.o"
|
||||||
|
env.get_build_fname("other_directory/o.d", ".a").should == "bldit/other_directory/o.a"
|
||||||
|
env.get_build_fname("bldit/some/mod.d", ".a").should == "bldit/some/mod.a"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#[]" do
|
describe "#[]" do
|
||||||
it "allows reading construction variables" do
|
it "allows reading construction variables" do
|
||||||
env = Environment.new("CFLAGS" => ["-g", "-Wall"])
|
env = Environment.new
|
||||||
|
env["CFLAGS"] = ["-g", "-Wall"]
|
||||||
env["CFLAGS"].should == ["-g", "-Wall"]
|
env["CFLAGS"].should == ["-g", "-Wall"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#[]=" do
|
describe "#[]=" do
|
||||||
it "allows writing construction variables" do
|
it "allows writing construction variables" do
|
||||||
env = Environment.new("CFLAGS" => ["-g", "-Wall"])
|
env = Environment.new
|
||||||
|
env["CFLAGS"] = ["-g", "-Wall"]
|
||||||
env["CFLAGS"] -= ["-g"]
|
env["CFLAGS"] -= ["-g"]
|
||||||
env["CFLAGS"] += ["-O3"]
|
env["CFLAGS"] += ["-O3"]
|
||||||
env["CFLAGS"].should == ["-Wall", "-O3"]
|
env["CFLAGS"].should == ["-Wall", "-O3"]
|
||||||
@@ -110,7 +125,9 @@ module Rscons
|
|||||||
|
|
||||||
describe "#append" do
|
describe "#append" do
|
||||||
it "allows adding many construction variables at once" do
|
it "allows adding many construction variables at once" do
|
||||||
env = Environment.new("CFLAGS" => ["-g"], "CPPPATH" => ["inc"])
|
env = Environment.new
|
||||||
|
env["CFLAGS"] = ["-g"]
|
||||||
|
env["CPPPATH"] = ["inc"]
|
||||||
env.append("CFLAGS" => ["-Wall"], "CPPPATH" => ["include"])
|
env.append("CFLAGS" => ["-Wall"], "CPPPATH" => ["include"])
|
||||||
env["CFLAGS"].should == ["-Wall"]
|
env["CFLAGS"].should == ["-Wall"]
|
||||||
env["CPPPATH"].should == ["include"]
|
env["CPPPATH"].should == ["include"]
|
||||||
@@ -158,6 +175,18 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#clear_targets" do
|
||||||
|
it "resets @targets to an empty hash" do
|
||||||
|
env = Environment.new
|
||||||
|
env.Program("a.out", "main.o")
|
||||||
|
expect(env.instance_variable_get(:@targets).keys).to eq(["a.out"])
|
||||||
|
|
||||||
|
env.clear_targets
|
||||||
|
|
||||||
|
expect(env.instance_variable_get(:@targets).keys).to eq([])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#build_command" do
|
describe "#build_command" do
|
||||||
it "returns a command based on the variables in the Environment" do
|
it "returns a command based on the variables in the Environment" do
|
||||||
env = Environment.new
|
env = Environment.new
|
||||||
@@ -170,6 +199,20 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#expand_varref" do
|
||||||
|
it "returns the fully expanded variable reference" do
|
||||||
|
env = Environment.new
|
||||||
|
env["path"] = ["dir1", "dir2"]
|
||||||
|
env["flags"] = ["-x", "-y", "${specialflag}"]
|
||||||
|
env["specialflag"] = "-z"
|
||||||
|
env.expand_varref(["-p${path}", "${flags}"]).should == ["-pdir1", "-pdir2", "-x", "-y", "-z"]
|
||||||
|
env.expand_varref("foo").should == "foo"
|
||||||
|
expect {env.expand_varref("${foo}")}.to raise_error /expand.a.variable.reference/
|
||||||
|
env.expand_varref("${specialflag}").should == "-z"
|
||||||
|
env.expand_varref("${path}").should == ["dir1", "dir2"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#execute" do
|
describe "#execute" do
|
||||||
context "with echo: :short" do
|
context "with echo: :short" do
|
||||||
context "with no errors" do
|
context "with no errors" do
|
||||||
@@ -228,6 +271,20 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#depends" do
|
||||||
|
it "records the given dependencies in @user_deps" do
|
||||||
|
env = Environment.new
|
||||||
|
env.depends("foo", "bar", "baz")
|
||||||
|
env.instance_variable_get(:@user_deps).should == {"foo" => ["bar", "baz"]}
|
||||||
|
end
|
||||||
|
it "records user dependencies only once" do
|
||||||
|
env = Environment.new
|
||||||
|
env.instance_variable_set(:@user_deps, {"foo" => ["bar"]})
|
||||||
|
env.depends("foo", "bar", "baz")
|
||||||
|
env.instance_variable_get(:@user_deps).should == {"foo" => ["bar", "baz"]}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#build_sources" do
|
describe "#build_sources" do
|
||||||
class ABuilder < Builder
|
class ABuilder < Builder
|
||||||
def produces?(target, source, env)
|
def produces?(target, source, env)
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -30,12 +30,6 @@ module Rscons
|
|||||||
v["qax"].should == [3, 6]
|
v["qax"].should == [3, 6]
|
||||||
v["qux"].should == {a: :b}
|
v["qux"].should == {a: :b}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe :[]= do
|
describe :[]= do
|
||||||
|
|||||||
Reference in new issue
Block a user