summaryrefslogtreecommitdiff
path: root/src/build.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/build.cc')
-rw-r--r--src/build.cc89
1 files changed, 59 insertions, 30 deletions
diff --git a/src/build.cc b/src/build.cc
index ea65656..5995fb7 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -38,7 +38,7 @@ int build(const ctor::settings& settings,
// Dry-run returns number of dirty tasks but otherwise does nothing.
if(dryrun)
{
- return dirtyTasks.size();
+ return static_cast<int>(dirtyTasks.size());
}
if(dirtyTasks.empty())
@@ -65,7 +65,7 @@ int build(const ctor::settings& settings,
break;
}
- auto task = getNextTask(all_tasks, dirtyTasks);
+ auto task = getNextTask(settings, all_tasks, dirtyTasks);
if(task == nullptr)
{
if(processes.empty() && !dirtyTasks.empty())
@@ -114,17 +114,15 @@ int build(const ctor::settings& settings,
}
}
- for(auto process = processes.begin();
- process != processes.end();
- ++process)
+ for(auto& process : processes)
{
- if(process->valid() == false)
+ if(process.valid() == false)
{
continue;
}
- process->wait();
- auto ret = process->get();
- if(ret != 0)
+ process.wait();
+ auto ret = process.get();
+ if (ret != 0)
{
return ret;
}
@@ -133,29 +131,46 @@ int build(const ctor::settings& settings,
return 0;
}
-namespace
-{
-std::vector<std::shared_ptr<Task>> getDepTasks(std::shared_ptr<Task> task)
+std::vector<std::shared_ptr<Task>> getDepTasks(std::shared_ptr<Task> task,
+ std::vector<std::shared_ptr<Task>> trace)
{
std::vector<std::shared_ptr<Task>> tasks;
tasks.push_back(task);
+ trace.push_back(task);
auto deps = task->getDependsTasks();
for(const auto& dep : deps)
{
- auto depSet = getDepTasks(dep);
- for(const auto& dep : depSet)
+ if(std::find(trace.begin(), trace.end(), dep) != trace.end())
{
- if(std::find(tasks.begin(), tasks.end(), dep) == tasks.end())
+ trace.push_back(dep);
+ std::cerr << "Error: Cyclic dependency detected: ";
+ bool first{true};
+ for(auto t : trace)
{
- tasks.push_back(dep);
+ if(!first)
+ {
+ std::cerr << " -> ";
+ }
+
+ first = false;
+ std::cerr << t->target();
+ }
+ std::cerr << '\n';
+ throw 1;
+ }
+ auto depSet = getDepTasks(dep, trace);
+ for(const auto& dep_inner : depSet)
+ {
+ if(std::find(tasks.begin(), tasks.end(), dep_inner) == tasks.end())
+ {
+ tasks.push_back(dep_inner);
}
}
}
return tasks;
}
-}
int build(const ctor::settings& settings,
const std::string& name,
@@ -169,20 +184,27 @@ int build(const ctor::settings& settings,
{
task_found = true;
- auto depSet = getDepTasks(task);
- std::vector<std::shared_ptr<Task>> ts;
- for(const auto& task : depSet)
+ try
{
- if(std::find(ts.begin(), ts.end(), task) == ts.end())
+ auto depSet = getDepTasks(task);
+ std::vector<std::shared_ptr<Task>> ts;
+ for(const auto& task_inner : depSet)
{
- ts.push_back(task);
+ if(std::find(ts.begin(), ts.end(), task_inner) == ts.end())
+ {
+ ts.push_back(task_inner);
+ }
}
- }
- auto ret = build(settings, name, ts, all_tasks, dryrun);
- if(ret != 0)
+ auto ret = build(settings, name, ts, all_tasks, dryrun);
+ if(ret != 0)
+ {
+ return ret;
+ }
+ }
+ catch(...)
{
- return ret;
+ return 1; // cycle detected
}
break;
@@ -216,14 +238,21 @@ int build(const ctor::settings& settings,
{
task_found = true;
- auto depSet = getDepTasks(task);
- for(const auto& task : depSet)
+ try
{
- if(std::find(ts.begin(), ts.end(), task) == ts.end())
+ auto depSet = getDepTasks(task);
+ for(const auto& task_inner : depSet)
{
- ts.push_back(task);
+ if(std::find(ts.begin(), ts.end(), task_inner) == ts.end())
+ {
+ ts.push_back(task_inner);
+ }
}
}
+ catch(...)
+ {
+ return 1; // cycle detected
+ }
}
}
}