summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc129
1 files changed, 41 insertions, 88 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index 0bcbad5..1174421 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -4,7 +4,6 @@
#include <iostream>
#include <utility>
#include <list>
-#include <chrono>
#include <thread>
#include <memory>
#include <algorithm>
@@ -14,7 +13,6 @@
#include <fstream>
#include <cstdlib>
#include <set>
-#include <future>
#include <getoptpp/getoptpp.hpp>
@@ -23,9 +21,7 @@
#include "configure.h"
#include "rebuild.h"
#include "tasks.h"
-
-using namespace std::chrono_literals;
-
+#include "build.h"
int main(int argc, char* argv[])
{
if(argc > 1 && std::string(argv[1]) == "configure")
@@ -53,7 +49,7 @@ int main(int argc, char* argv[])
int key{128};
opt.add("jobs", required_argument, 'j',
- "Number of parallel jobs. (default: cpucount * 2 - 1 )",
+ "Number of parallel jobs. (default: cpucount * 2 - 1)",
[&]() {
try
{
@@ -135,7 +131,17 @@ int main(int argc, char* argv[])
opt.add("help", no_argument, 'h',
"Print this help text.",
[&]() {
- std::cout << "usage stuff\n";
+ std::cout << "Usage: " << argv[0] << " [options] [target] ...\n";
+ std::cout <<
+R"_( where target can be either:
+ configure - run configuration step (cannot be used with other targets).
+ clean - clean all generated files.
+ all - build all targets (default)
+ or the name of a target which will be built along with its dependencies.
+ Use '-l' to see a list of possible target names.
+
+Options:
+)_";
opt.help();
exit(0);
return 0;
@@ -186,11 +192,11 @@ int main(int argc, char* argv[])
std::filesystem::path builddir(settings.builddir);
std::filesystem::create_directories(builddir);
- auto tasks = getTasks(settings);
+ auto all_tasks = getTasks(settings);
if(list_targets)
{
- for(const auto& task : tasks)
+ for(const auto& task : all_tasks)
{
if(task->targetType() != TargetType::Object)
{
@@ -205,7 +211,7 @@ int main(int argc, char* argv[])
std::ofstream istr(compilation_database);
istr << "[";
bool first{true};
- for(auto task : tasks)
+ for(auto task : all_tasks)
{
auto s = task->toJSON();
if(!s.empty())
@@ -241,118 +247,65 @@ int main(int argc, char* argv[])
return 0;
}
- for(auto task : tasks)
+ for(auto task : all_tasks)
{
- if(task->registerDepTasks(tasks))
+ if(task->registerDepTasks(all_tasks))
{
return 1;
}
}
- std::list<std::shared_ptr<Task>> dirtyTasks;
- for(auto task : tasks)
+ bool build_all{true};
+ for(auto const &arg : opt.arguments())
{
- if(task->dirty())
+ if(arg == "configure")
{
- dirtyTasks.push_back(task);
+ std::cerr << "The 'configure' target must be the first argument.\n";
+ return 1;
}
- }
- for(auto const &arg : opt.arguments())
- {
if(arg == "clean")
{
+ build_all = false;
+
std::cout << "Cleaning\n";
- for(auto& task : tasks)
+ for(auto& task : all_tasks)
{
if(task->clean() != 0)
{
return 1;
}
}
-
- return 0;
}
-
- if(arg == "configure")
- {
- std::cerr << "The 'configure' target must be the first argument.\n";
- return 1;
- }
- }
-
- if(dirtyTasks.empty())
- {
- return 0;
- }
-
- std::cout << "Building\n";
- std::list<std::future<int>> processes;
-
- // Start all tasks
- bool done{false};
- while(!done)
- {
- bool started_one{false};
- while(processes.size() < settings.parallel_processes)
+ else
{
- if(dirtyTasks.empty())
- {
- done = true;
- break;
- }
+ build_all = false;
- auto task = getNextTask(tasks, dirtyTasks);
- if(task == nullptr)
+ if(arg == "all")
{
- break;
- //return 1;
+ auto ret = build(settings, "all", all_tasks, all_tasks);
+ if(ret != 0)
+ {
+ return ret;
+ }
}
-
- processes.emplace_back(
- std::async(std::launch::async,
- [task]()
- {
- return task->run();
- }));
- started_one = true;
- std::this_thread::sleep_for(2ms);
- }
-
- for(auto process = processes.begin();
- process != processes.end();
- ++process)
- {
- if(process->valid())
+ else
{
- if(process->get() != 0)
+ auto ret = build(settings, arg, all_tasks);
+ if(ret != 0)
{
- return 1;
+ return ret;
}
- processes.erase(process);
- break;
}
}
-
- if(started_one)
- {
- std::this_thread::sleep_for(2ms);
- }
- else
- {
- std::this_thread::sleep_for(200ms);
- }
}
- for(auto process = processes.begin();
- process != processes.end();
- ++process)
+ if(build_all)
{
- process->wait();
- auto ret = process->get();
+ auto ret = build(settings, "all", all_tasks, all_tasks);
if(ret != 0)
{
- return 1;
+ return ret;
}
}