summaryrefslogtreecommitdiff
path: root/src/rebuild.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-10-14 22:19:26 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-10-14 22:19:26 +0200
commitc0eacf8e85003844b95e71b9004fa464d4586a38 (patch)
treea407dc8ec3830cb01faf3d5153c8741f9b19e1c1 /src/rebuild.cc
parent87aad8c76eb2371720c9aceef7516ecb0859ecdf (diff)
Use dependency system and build system for compiling ctor on config changes.
Diffstat (limited to 'src/rebuild.cc')
-rw-r--r--src/rebuild.cc110
1 files changed, 49 insertions, 61 deletions
diff --git a/src/rebuild.cc b/src/rebuild.cc
index 7c90fca..e017d92 100644
--- a/src/rebuild.cc
+++ b/src/rebuild.cc
@@ -7,10 +7,11 @@
#include <filesystem>
#include <algorithm>
-#include "execute.h"
#include "configure.h"
#include "settings.h"
#include "libctor.h"
+#include "tasks.h"
+#include "build.h"
std::array<BuildConfigurationEntry, 1024> configFiles;
std::size_t numConfigFiles{0};
@@ -57,100 +58,87 @@ int unreg(const char* location)
return found;
}
-void recompileCheck(const Settings& settings, int argc, char* argv[],
+namespace
+{
+bool contains(const std::vector<Source>& sources, const std::string& file)
+{
+ for(const auto& source : sources)
+ {
+ if(source.file == file)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+}
+
+void recompileCheck(const Settings& global_settings, int argc, char* argv[],
bool force, bool relaunch_allowed)
{
using namespace std::string_literals;
- bool dirty{force};
+ if(global_settings.verbose > 1)
+ {
+ std::cout << "Recompile check (" << numConfigFiles << "):\n";
+ }
- std::vector<std::string> args;
- args.push_back("-s");
- args.push_back("-O3");
- args.push_back("-std=c++17");
+ BuildConfiguration config;
+ config.name = "ctor";
+ config.cxxflags = std::vector<std::string>({ "-s", "-O3", "-std=c++17" });
if(hasConfiguration(cfg::ctor_includedir))
{
- args.push_back("-I"s + getConfiguration(cfg::ctor_includedir));
+ config.cxxflags.push_back("-I"s + getConfiguration(cfg::ctor_includedir));
}
if(hasConfiguration(cfg::ctor_libdir))
{
- args.push_back("-L"s + getConfiguration(cfg::ctor_libdir));
+ config.ldflags.push_back("-L"s + getConfiguration(cfg::ctor_libdir));
}
- args.push_back("-lctor");
- args.push_back("-pthread");
+ config.ldflags.push_back("-lctor");
+ config.ldflags.push_back("-pthread");
- std::filesystem::path binFile(argv[0]);
- if(std::filesystem::exists(configurationFile))
- {
- args.push_back(configurationFile.string());
+ Settings settings{global_settings};
+ settings.verbose = -1; // Make check completely silent.
+ settings.builddir += "/ctor"; // override builddir to use ctor subdir
- if(std::filesystem::last_write_time(binFile) <=
- std::filesystem::last_write_time(configurationFile))
- {
- dirty = true;
- }
-
- const auto& c = configuration();
- if(&c == &default_configuration)
- {
- // configuration.cc exists, but currently compiled with the default one.
- dirty = true;
- }
+ {
+ std::filesystem::path buildfile = settings.builddir;
+ std::filesystem::path currentfile = argv[0];
+ config.target = std::filesystem::relative(currentfile, buildfile).string();
}
- if(settings.verbose > 1)
+ if(std::filesystem::exists(configurationFile))
{
- std::cout << "Recompile check (" << numConfigFiles << "):\n";
+ config.sources.push_back(configurationFile.string());
}
for(std::size_t i = 0; i < numConfigFiles; ++i)
{
std::string location = configFiles[i].file;
- if(settings.verbose > 1)
+ if(global_settings.verbose > 1)
{
std::cout << " - " << location << "\n";
}
- std::filesystem::path configFile(location);
- if(std::filesystem::last_write_time(binFile) <=
- std::filesystem::last_write_time(configFile))
- {
- dirty = true;
- }
- // Support adding multiple config functions from the same file
- if(std::find(args.begin(), args.end(), location) == std::end(args))
+ // Ensure that files containing multiple configurations are only added once.
+ if(!contains(config.sources, location))
{
- args.push_back(location);
+ config.sources.push_back(location);
}
}
- args.push_back("-o");
- args.push_back(binFile.string());
+ auto tasks = taskFactory({config}, settings, {});
- if(dirty)
+ for(auto task : tasks)
{
- std::cout << "Rebuilding config\n";
- auto tool = getConfiguration(cfg::build_cxx, "/usr/bin/g++");
- auto ret = execute(tool, args, settings.verbose > 0);
- if(ret != 0)
+ if(task->registerDepTasks(tasks))
{
- std::cerr << "Failed: ." << ret << "\n";
- exit(1);
- }
- else
- {
- if(relaunch_allowed)
- {
- std::cout << "Re-launch\n";
- std::vector<std::string> args;
- for(int i = 1; i < argc; ++i)
- {
- args.push_back(argv[i]);
- }
- exit(execute(argv[0], args, settings.verbose > 0));
- }
+ return;
}
}
+
+ build(settings, "ctor", tasks);
}