From deaf03de9cb68dee8550a2f4a59ff016cb9afaed Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 13 Jun 2023 19:46:11 -0300 Subject: [PATCH] Implemented 'generate only these targets' --- TODO.md | 3 +-- spec/croupier_spec.cr | 13 +++++++++++++ src/croupier.cr | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 16f99a9..5fc3dc7 100644 --- a/TODO.md +++ b/TODO.md @@ -2,5 +2,4 @@ Thinks it may make sense to add: * Tasks without file output * Tasks with more than one output -* Run only tasks needed to produce specific outputs -* Run only listed tasks +* ~~Run only tasks needed to produce specific outputs~~ diff --git a/spec/croupier_spec.cr b/spec/croupier_spec.cr index fa43b22..e23533b 100644 --- a/spec/croupier_spec.cr +++ b/spec/croupier_spec.cr @@ -382,6 +382,19 @@ describe Croupier::Task do end end + it "should run only required tasks to produce specified outputs" do + with_tasks do + Dir.cd "spec/files" do + Croupier::Task.run_tasks(["output4", "output5"]) + File.exists?("output1").should be_false + File.exists?("output2").should be_false + File.exists?("output3").should be_true # Required for output4 + File.exists?("output4").should be_true # Required + File.exists?("output5").should be_true # Required + end + end + end + it "should fail if asked for dependencies of an unknown output" do with_tasks do Dir.cd "spec/files" do diff --git a/src/croupier.cr b/src/croupier.cr index f2d67fa..b0aa06d 100644 --- a/src/croupier.cr +++ b/src/croupier.cr @@ -160,7 +160,7 @@ module Croupier end # Run the tasks needed to create or update the requested targets - def self.run_tasks(targets : Array(String)) + def self.run_tasks(targets : Array(String), run_all : Bool = false) mark_stale_inputs tasks = dependencies(targets) _run_tasks(tasks, run_all) @@ -174,7 +174,7 @@ module Croupier _, tasks = Task.sorted_task_graph _run_tasks(tasks, run_all) end - + # Helper to run tasks def self._run_tasks(tasks, run_all : Bool = false) tasks.each do |task|