summaryrefslogtreecommitdiff
path: root/ctor.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2022-05-27 09:34:50 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2022-05-27 09:34:50 +0200
commit6f42f40b47bcec1d4263767a03547d9ab203fc93 (patch)
treebb8547f187243256ef960b1d392c45d1da32e91e /ctor.cc
parent025396cded105cac80a19e715d5011723a888b23 (diff)
Use built-in execute command for moc creation. And RAII for path changing.HEADmaster
Diffstat (limited to 'ctor.cc')
-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);
}
}