Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
831b9bf2c7 | ||
|
|
031395bb57 | ||
|
|
e3aeb7f4d7 | ||
|
|
6aa5037234 | ||
|
|
0d8f661fd4 | ||
|
|
e5ca8776a9 | ||
|
|
2dde39a0ec |
No files matched your search
@@ -243,6 +243,17 @@ http://rubydoc.info/github/holtrop/rscons/frames.
|
||||
|
||||
## Release Notes
|
||||
|
||||
### v1.3.0
|
||||
|
||||
- change Environment#execute() options parameter to accept the following options keys:
|
||||
- :env to pass an environment Hash to Kernel#system
|
||||
- :options to pass an options Hash to Kernel#system
|
||||
|
||||
### v1.2.0
|
||||
|
||||
- add :clone option to Environment#clone to control exactly which Environment attributes are cloned
|
||||
- allow nil to be passed in to Environment#build_root=
|
||||
|
||||
### v1.1.0
|
||||
|
||||
- Change Cache#up_to_date?() and #register_build() to accept a single target
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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 Rscons::Builders::Library < Rscons::Builder
|
||||
def default_variables(env)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.
|
||||
class Object < Builder
|
||||
KNOWN_SUFFIXES = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.
|
||||
class Rscons::Builders::Program < Rscons::Builder
|
||||
def default_variables(env)
|
||||
|
||||
+49
-15
@@ -2,7 +2,7 @@ require 'set'
|
||||
require 'fileutils'
|
||||
|
||||
module Rscons
|
||||
# The Environment class is the main programmatic interface to RScons. It
|
||||
# The Environment class is the main programmatic interface to Rscons. It
|
||||
# contains a collection of construction variables, options, builders, and
|
||||
# rules for building targets.
|
||||
class Environment
|
||||
@@ -15,7 +15,8 @@ module Rscons
|
||||
# String or +nil+
|
||||
attr_reader :build_root
|
||||
def build_root=(build_root)
|
||||
@build_root = build_root.gsub('\\', '/')
|
||||
@build_root = build_root
|
||||
@build_root.gsub!('\\', '/') if @build_root
|
||||
end
|
||||
|
||||
# Create an Environment object.
|
||||
@@ -50,24 +51,53 @@ module Rscons
|
||||
end
|
||||
|
||||
# Make a copy of the Environment object.
|
||||
# The cloned environment will contain a copy of all environment options,
|
||||
# construction variables, and builders (unless :exclude_builders => true is
|
||||
# passed as an option). It will not contain a copy of the targets, build
|
||||
# hooks, build directories, or the build root. If a block is given, the
|
||||
# Environment object is yielded to the block and when the block returns,
|
||||
# the {#process} method is automatically called. The possible options keys
|
||||
# match those documented in the #initialize method.
|
||||
#
|
||||
# By default, a cloned environment will contain a copy of all environment
|
||||
# options, construction variables, and builders, but not a copy of the
|
||||
# targets, build hooks, build directories, or the build root.
|
||||
#
|
||||
# Exactly which items are cloned are controllable via the optional :clone
|
||||
# parameter, which can be :none, :all, or a set or array of any of the
|
||||
# following:
|
||||
# - :variables to clone construction variables (on by default)
|
||||
# - :builders to clone the builders (on by default)
|
||||
# - :build_root to clone the build root (off by default)
|
||||
# - :build_dirs to clone the build directories (off by default)
|
||||
# - :build_hooks to clone the build hooks (off by default)
|
||||
#
|
||||
# If a block is given, the Environment object is yielded to the block and
|
||||
# when the block returns, the {#process} method is automatically called.
|
||||
#
|
||||
# Any options that #initialize receives can also be specified here.
|
||||
#
|
||||
# @return a new {Environment} object.
|
||||
def clone(options = {})
|
||||
clone = options[:clone] || Set[:variables, :builders]
|
||||
clone = Set[:variables, :builders, :build_root, :build_dirs, :build_hooks] if clone == :all
|
||||
clone = Set[] if clone == :none
|
||||
clone = Set.new(clone) if clone.is_a?(Array)
|
||||
clone.delete(:builders) if options[:exclude_builders]
|
||||
env = self.class.new(
|
||||
echo: options[:echo] || @echo,
|
||||
build_root: options[:build_root],
|
||||
exclude_builders: true)
|
||||
unless options[:exclude_builders]
|
||||
if clone.include?(:builders)
|
||||
@builders.each do |builder_name, builder|
|
||||
env.add_builder(builder)
|
||||
end
|
||||
end
|
||||
env.append(@varset.clone)
|
||||
env.append(@varset.clone) if clone.include?(:variables)
|
||||
env.build_root = @build_root if clone.include?(:build_root)
|
||||
if clone.include?(:build_dirs)
|
||||
@build_dirs.each do |src_dir, obj_dir|
|
||||
env.build_dir(src_dir, obj_dir)
|
||||
end
|
||||
end
|
||||
if clone.include?(:build_hooks)
|
||||
@build_hooks.each do |build_hook_block|
|
||||
env.add_build_hook(&build_hook_block)
|
||||
end
|
||||
end
|
||||
|
||||
if block_given?
|
||||
yield env
|
||||
@@ -194,7 +224,9 @@ module Rscons
|
||||
# @param short_desc [String] Message to print if the Environment's echo
|
||||
# mode is set to :short
|
||||
# @param command [Array] The command to execute.
|
||||
# @param options [Hash] Optional options to pass to Kernel#system.
|
||||
# @param options [Hash] Optional options, possible keys:
|
||||
# - :env - environment Hash to pass to Kernel#system.
|
||||
# - :options - options Hash to pass to Kernel#system.
|
||||
def execute(short_desc, command, options = {})
|
||||
print_command = proc do
|
||||
puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ')
|
||||
@@ -204,7 +236,9 @@ module Rscons
|
||||
elsif @echo == :short
|
||||
puts short_desc
|
||||
end
|
||||
system(*command, options).tap do |result|
|
||||
env_args = options[:env] ? [options[:env]] : []
|
||||
options_args = options[:options] ? [options[:options]] : []
|
||||
system(*env_args, *command, *options_args).tap do |result|
|
||||
unless result or @echo == :command
|
||||
$stdout.write "Failed command was: "
|
||||
print_command.call
|
||||
@@ -246,7 +280,7 @@ module Rscons
|
||||
|
||||
# Build a list of source files into files containing one of the suffixes
|
||||
# given by suffixes.
|
||||
# This method is used internally by RScons builders.
|
||||
# This method is used internally by Rscons builders.
|
||||
# @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.
|
||||
@@ -294,7 +328,7 @@ module Rscons
|
||||
end
|
||||
|
||||
# Parse dependencies for a given target from a Makefile.
|
||||
# This method is used internally by RScons builders.
|
||||
# This method is used internally by Rscons builders.
|
||||
# @param mf_fname [String] File name of the Makefile to read.
|
||||
# @param target [String] Name of the target to gather dependencies for.
|
||||
def self.parse_makefile_deps(mf_fname, target)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module Rscons
|
||||
# gem version
|
||||
VERSION = "1.1.0"
|
||||
VERSION = "1.3.0"
|
||||
end
|
||||
@@ -298,6 +298,29 @@ EOF
|
||||
]
|
||||
end
|
||||
|
||||
it 'allows cloning all attributes of an Environment object' do
|
||||
test_dir('clone_env')
|
||||
|
||||
env1 = Rscons::Environment.new(echo: :command) do |env|
|
||||
env.build_dir('src', 'build')
|
||||
env['CFLAGS'] = '-O2'
|
||||
env.add_build_hook do |build_op|
|
||||
build_op[:vars]['CPPFLAGS'] = '-DSTRING="Hello"'
|
||||
end
|
||||
env.Program('program', Dir['src/*.c'])
|
||||
end
|
||||
|
||||
env2 = env1.clone(clone: :all) do |env|
|
||||
env.Program('program2', Dir['src/*.c'])
|
||||
end
|
||||
|
||||
lines.should == [
|
||||
%q{gcc -c -o build/program.o -MMD -MF build/program.mf -DSTRING="Hello" -O2 src/program.c},
|
||||
%q{gcc -o program build/program.o},
|
||||
%q{gcc -o program2 build/program.o},
|
||||
]
|
||||
end
|
||||
|
||||
it 'builds a C++ program with one source file' do
|
||||
test_dir('simple_cc')
|
||||
Rscons::Environment.new do |env|
|
||||
|
||||
@@ -219,7 +219,7 @@ module Rscons
|
||||
it "prints the short description and executes the command" do
|
||||
env = Environment.new(echo: :short)
|
||||
env.should_receive(:puts).with("short desc")
|
||||
env.should_receive(:system).with("a", "command", {}).and_return(true)
|
||||
env.should_receive(:system).with("a", "command").and_return(true)
|
||||
env.execute("short desc", ["a", "command"])
|
||||
end
|
||||
end
|
||||
@@ -228,7 +228,7 @@ module Rscons
|
||||
it "prints the short description, executes the command, and prints the failed command line" do
|
||||
env = Environment.new(echo: :short)
|
||||
env.should_receive(:puts).with("short desc")
|
||||
env.should_receive(:system).with("a", "command", {}).and_return(false)
|
||||
env.should_receive(:system).with("a", "command").and_return(false)
|
||||
$stdout.should_receive(:write).with("Failed command was: ")
|
||||
env.should_receive(:puts).with("a command")
|
||||
env.execute("short desc", ["a", "command"])
|
||||
@@ -240,8 +240,8 @@ module Rscons
|
||||
it "prints the command executed and executes the command" do
|
||||
env = Environment.new(echo: :command)
|
||||
env.should_receive(:puts).with("a command '--arg=val with spaces'")
|
||||
env.should_receive(:system).with("a", "command", "--arg=val with spaces", opt: :val).and_return(false)
|
||||
env.execute("short desc", ["a", "command", "--arg=val with spaces"], opt: :val)
|
||||
env.should_receive(:system).with({modified: :environment}, "a", "command", "--arg=val with spaces", {opt: :val}).and_return(false)
|
||||
env.execute("short desc", ["a", "command", "--arg=val with spaces"], env: {modified: :environment}, options: {opt: :val})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user