diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-27 09:34:50 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-27 09:34:50 +0200 |
commit | 6f42f40b47bcec1d4263767a03547d9ab203fc93 (patch) | |
tree | bb8547f187243256ef960b1d392c45d1da32e91e | |
parent | 025396cded105cac80a19e715d5011723a888b23 (diff) |
-rw-r--r-- | ctor.cc | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -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); } } |