summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/build.cc32
-rw-r--r--src/build.h12
-rw-r--r--src/rebuild.cc7
-rw-r--r--src/task.h1
-rw-r--r--src/task_ar.cc5
-rw-r--r--src/task_ar.h1
-rw-r--r--src/task_cc.cc5
-rw-r--r--src/task_cc.h1
-rw-r--r--src/task_ld.cc5
-rw-r--r--src/task_ld.h1
-rw-r--r--src/task_so.cc5
-rw-r--r--src/task_so.h1
-rw-r--r--test/tasks_test.cc1
m---------test/uunit0
14 files changed, 65 insertions, 12 deletions
diff --git a/src/build.cc b/src/build.cc
index 2412b84..8adbc54 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -15,7 +15,8 @@ using namespace std::chrono_literals;
int build(const Settings& settings,
const std::string& name,
const std::list<std::shared_ptr<Task>>& tasks,
- const std::list<std::shared_ptr<Task>>& all_tasks)
+ const std::list<std::shared_ptr<Task>>& all_tasks,
+ bool dryrun)
{
if(settings.verbose > 1)
{
@@ -31,6 +32,12 @@ int build(const Settings& settings,
}
}
+ // Dry-run returns number of dirty tasks but otherwise does nothing.
+ if(dryrun)
+ {
+ return dirtyTasks.size();
+ }
+
if(dirtyTasks.empty())
{
if(settings.verbose > -1)
@@ -148,12 +155,19 @@ std::set<std::shared_ptr<Task>> getDepTasks(std::shared_ptr<Task> task)
int build(const Settings& settings,
const std::string& name,
- const std::list<std::shared_ptr<Task>>& all_tasks)
+ const std::list<std::shared_ptr<Task>>& all_tasks,
+ bool dryrun)
{
bool task_found{false};
for(auto task : all_tasks)
{
- if(task->name() == name || task->target() == name)
+ if(task->target() == name || // match exact target output (ex. build/foo.o)
+
+ (!task->derived() && // if non-derived task:
+ ( task->buildConfig().target == name || // match name
+ task->buildConfig().name == name ) // or target
+ )
+ )
{
task_found = true;
@@ -163,7 +177,8 @@ int build(const Settings& settings,
{
ts.push_back(task);
}
- auto ret = build(settings, name, ts, all_tasks);
+
+ auto ret = build(settings, name, ts, all_tasks, dryrun);
if(ret != 0)
{
return ret;
@@ -185,7 +200,8 @@ int build(const Settings& settings,
int build(const Settings& settings,
const std::string& name,
const std::vector<Target>& targets,
- const std::list<std::shared_ptr<Task>>& all_tasks)
+ const std::list<std::shared_ptr<Task>>& all_tasks,
+ bool dryrun)
{
bool task_found{false};
std::list<std::shared_ptr<Task>> ts;
@@ -194,8 +210,8 @@ int build(const Settings& settings,
{
for(auto task : all_tasks)
{
- if(task->name() == target.config.target ||
- task->target() == target.config.target)
+ if(!task->derived() && // only consider non-derived tasks
+ task->buildConfig().target == target.config.target)
{
task_found = true;
@@ -214,5 +230,5 @@ int build(const Settings& settings,
return 1;
}
- return build(settings, name, ts, all_tasks);
+ return build(settings, name, ts, all_tasks, dryrun);
}
diff --git a/src/build.h b/src/build.h
index 1db3f5c..7be7517 100644
--- a/src/build.h
+++ b/src/build.h
@@ -11,16 +11,22 @@
#include "settings.h"
#include "tasks.h"
+//! Dry-run returns number of dirty tasks but otherwise does nothing.
int build(const Settings& settings,
const std::string& name,
const std::list<std::shared_ptr<Task>>& tasks,
- const std::list<std::shared_ptr<Task>>& all_tasks);
+ const std::list<std::shared_ptr<Task>>& all_tasks,
+ bool dryrun = false);
+//! Dry-run returns number of dirty tasks but otherwise does nothing.
int build(const Settings& settings,
const std::string& name,
- const std::list<std::shared_ptr<Task>>& all_tasks);
+ const std::list<std::shared_ptr<Task>>& all_tasks,
+ bool dryrun = false);
+//! Dry-run returns number of dirty tasks but otherwise does nothing.
int build(const Settings& settings,
const std::string& name,
const std::vector<Target>& targets,
- const std::list<std::shared_ptr<Task>>& all_tasks);
+ const std::list<std::shared_ptr<Task>>& all_tasks,
+ bool dryrun = false);
diff --git a/src/rebuild.cc b/src/rebuild.cc
index e017d92..c1f2a4a 100644
--- a/src/rebuild.cc
+++ b/src/rebuild.cc
@@ -140,5 +140,10 @@ void recompileCheck(const Settings& global_settings, int argc, char* argv[],
}
}
- build(settings, "ctor", tasks);
+ auto dirty_tasks = build(settings, "ctor", tasks, true); // dryrun
+ if(dirty_tasks)
+ {
+ std::cout << "Rebuilding config.\n";
+ build(settings, "ctor", tasks); // run for real
+ }
}
diff --git a/src/task.h b/src/task.h
index 78dc904..7068c8a 100644
--- a/src/task.h
+++ b/src/task.h
@@ -35,6 +35,7 @@ public:
virtual int clean() = 0 ;
virtual std::vector<std::string> depends() const = 0;
virtual std::string target() const = 0;
+ virtual bool derived() const = 0;
virtual std::string toJSON() const { return {}; };
diff --git a/src/task_ar.cc b/src/task_ar.cc
index 06504f6..fdd29b1 100644
--- a/src/task_ar.cc
+++ b/src/task_ar.cc
@@ -174,6 +174,11 @@ std::string TaskAR::target() const
return targetFile.string();
}
+bool TaskAR::derived() const
+{
+ return false;
+}
+
std::string TaskAR::flagsString() const
{
std::string flagsStr;
diff --git a/src/task_ar.h b/src/task_ar.h
index f2873c7..f540fef 100644
--- a/src/task_ar.h
+++ b/src/task_ar.h
@@ -31,6 +31,7 @@ public:
std::vector<std::string> depends() const override;
std::string target() const override;
+ bool derived() const override;
private:
std::string flagsString() const;
diff --git a/src/task_cc.cc b/src/task_cc.cc
index e4bd7aa..a9be475 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -213,6 +213,11 @@ std::string TaskCC::target() const
return targetFile.string();
}
+bool TaskCC::derived() const
+{
+ return true;
+}
+
std::string TaskCC::toJSON() const
{
std::string json;
diff --git a/src/task_cc.h b/src/task_cc.h
index f5ae95d..0589ea4 100644
--- a/src/task_cc.h
+++ b/src/task_cc.h
@@ -30,6 +30,7 @@ public:
std::vector<std::string> depends() const override;
std::string target() const override;
+ bool derived() const override;
std::string toJSON() const override;
diff --git a/src/task_ld.cc b/src/task_ld.cc
index 10b8bce..52aae04 100644
--- a/src/task_ld.cc
+++ b/src/task_ld.cc
@@ -198,6 +198,11 @@ std::string TaskLD::target() const
return targetFile.string();
}
+bool TaskLD::derived() const
+{
+ return false;
+}
+
std::string TaskLD::flagsString() const
{
std::string flagsStr;
diff --git a/src/task_ld.h b/src/task_ld.h
index a86e49b..516641f 100644
--- a/src/task_ld.h
+++ b/src/task_ld.h
@@ -31,6 +31,7 @@ public:
std::vector<std::string> depends() const override;
std::string target() const override;
+ bool derived() const override;
private:
std::string flagsString() const;
diff --git a/src/task_so.cc b/src/task_so.cc
index f3e1937..96fa1a3 100644
--- a/src/task_so.cc
+++ b/src/task_so.cc
@@ -175,6 +175,11 @@ std::string TaskSO::target() const
return targetFile.string();
}
+bool TaskSO::derived() const
+{
+ return false;
+}
+
std::string TaskSO::flagsString() const
{
std::string flagsStr = compiler();
diff --git a/src/task_so.h b/src/task_so.h
index 09aa205..a249421 100644
--- a/src/task_so.h
+++ b/src/task_so.h
@@ -31,6 +31,7 @@ public:
std::vector<std::string> depends() const override;
std::string target() const override;
+ bool derived() const override;
private:
std::string flagsString() const;
diff --git a/test/tasks_test.cc b/test/tasks_test.cc
index 3c9243c..8a15fcd 100644
--- a/test/tasks_test.cc
+++ b/test/tasks_test.cc
@@ -55,6 +55,7 @@ public:
int clean() override { return 0; }
std::vector<std::string> depends() const override { return task_deps; }
std::string target() const override { return task_name; }
+ bool derived() const override { return false; }
bool dirtyInner() override { return task_dirty; }
private:
diff --git a/test/uunit b/test/uunit
-Subproject fd83de802d05a227cc00489f66ea70fccb4dda0
+Subproject bc078da645412c6b36ef59e635d6c35d11088c9