summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ctor.cc33
1 files changed, 28 insertions, 5 deletions
diff --git a/ctor.cc b/ctor.cc
index 2f4cb14..d4d4e28 100644
--- a/ctor.cc
+++ b/ctor.cc
@@ -3,8 +3,33 @@
#include <filesystem>
#include <iostream>
+#include <string>
+#include <vector>
+
+int execute(const std::string& command,
+ const std::vector<std::string>& args,
+ bool verbose = true);
+
namespace
{
+class PathRAII
+{
+public:
+ PathRAII(const std::filesystem::path& path)
+ {
+ pwd = std::filesystem::current_path();
+ std::filesystem::current_path(path);
+ }
+
+ ~PathRAII()
+ {
+ std::filesystem::current_path(pwd);
+ }
+
+private:
+ std::filesystem::path pwd;
+};
+
std::vector<Source> eval_mocs(const std::string& path,
const std::vector<std::pair<std::string, std::string>>& moc_list)
{
@@ -26,13 +51,11 @@ std::vector<Source> eval_mocs(const std::string& path,
std::filesystem::last_write_time(path / input) >
std::filesystem::last_write_time(path / output))
{
- std::string cmd = "cd \"" + path + "\"; moc ";
- cmd += "-o \"" + output.string() + "\" \"" + input.string() + "\"";
- std::cerr << cmd << "\n";
- auto ret = system(cmd.data());
+ PathRAII p(path);
+ auto ret = execute("/usr/bin/moc", {"-o", output.string(), input.string()});
if(ret != 0)
{
- std::cerr << "moc generation failed: " << cmd << '\n';
+ std::cerr << "moc generation failed\n";
exit(ret);
}
}