Process environments created during task execution phase

This commit is contained in:
Josh Holtrop 2022-02-27 16:55:59 -05:00
parent 29ca9b3f13
commit bb4657e465
4 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,5 @@
default do
env do |env|
env.Program('simple.exe', Dir['*.c'])
end
end

View File

@ -42,6 +42,16 @@ module Rscons
@variant_groups = [] @variant_groups = []
end end
# Return if Rscons is in the task execution phase.
#
# @api private
#
# @return [Boolean]
# If Rscons is in the task execution phase.
def task_execution_phase?
@task_execution_phase
end
# Run the application. # Run the application.
# #
# Execute user-specified tasks. # Execute user-specified tasks.
@ -77,6 +87,7 @@ module Rscons
return 0 return 0
end end
apply_task_params(tasks_and_params) apply_task_params(tasks_and_params)
@task_execution_phase = true
if tasks_and_params.empty? if tasks_and_params.empty?
check_process_environments check_process_environments
if Task.tasks["default"] if Task.tasks["default"]

View File

@ -130,13 +130,21 @@ module Rscons
# #
# If a block is given it is immediately executed and passed the newly # If a block is given it is immediately executed and passed the newly
# created Environment object as an argument. # created Environment object as an argument.
# If the Environment is created in task context, the +process+ method is
# immediately called.
# Otherwise, the Environment is not processed until the task execution
# phase.
# #
# @yield [env] # @yield [env]
# @yieldparam env [Environment] # @yieldparam env [Environment]
# The created environment. # The created environment.
def env(*args, &block) def env(*args, &block)
Rscons.application.check_configure Rscons.application.check_configure
Environment.new(*args, &block) e = Environment.new(*args, &block)
if Rscons.application.task_execution_phase?
e.process
end
e
end end
# Construct a task parameter. # Construct a task parameter.

View File

@ -195,6 +195,14 @@ EOF
expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" expect(nr(`./simple.exe`)).to eq "This is a simple C program\n"
end end
it "processes the environment when created within a task" do
test_dir("simple")
result = run_rscons(args: %w[-f env_in_task.rb])
expect(result.stderr).to eq ""
expect(File.exists?("build/e.1/simple.c.o")).to be_truthy
expect(nr(`./simple.exe`)).to eq "This is a simple C program\n"
end
it "uses the build directory specified with -b" do it "uses the build directory specified with -b" do
test_dir("simple") test_dir("simple")
result = run_rscons(args: %w[-b b]) result = run_rscons(args: %w[-b b])