10#define MAYAFLUX_REFLECT_POPEN _popen
11#define MAYAFLUX_REFLECT_PCLOSE _pclose
12#define MAYAFLUX_REFLECT_QUIET " 2>nul"
14#define MAYAFLUX_REFLECT_POPEN popen
15#define MAYAFLUX_REFLECT_PCLOSE pclose
16#define MAYAFLUX_REFLECT_QUIET " 2>/dev/null"
23 std::string clang_resource_dir()
25 std::string command =
"clang -print-resource-dir";
28 if (pipe ==
nullptr) {
32 std::array<char, 256> buffer {};
33 while (std::fgets(buffer.data(),
static_cast<int>(buffer.size()), pipe) !=
nullptr) {
34 output += buffer.data();
37 while (!output.empty() && std::isspace(
static_cast<unsigned char>(output.back())) != 0) {
43 std::string escaped(std::string_view text)
46 out.reserve(text.size());
47 for (
const char c : text) {
48 if (c ==
' ' || c ==
'\t' || c ==
'#') {
50 }
else if (c ==
'$') {
62 if (!configured.empty() && llvm::sys::fs::is_directory(configured)) {
65 std::string found = clang_resource_dir();
66 if (found.empty() || !llvm::sys::fs::is_directory(found)) {
72bool write_depfile(
const std::filesystem::path& path,
const std::string& target,
73 const std::vector<std::filesystem::path>& dependencies, std::string& error)
75 std::string text = escaped(std::filesystem::path(target).generic_string()) +
":";
76 for (
const auto& dependency : dependencies) {
77 text +=
" \\\n " + escaped(dependency.generic_string());
82 if (path.has_parent_path()) {
83 std::filesystem::create_directories(path.parent_path(), code);
85 error =
"cannot create " + path.parent_path().string();
92bool write_generated(
const std::filesystem::path& path,
const std::string& content, std::string& error)
98 std::filesystem::last_write_time(path, std::filesystem::file_time_type::clock::now(), code);
100 error =
"cannot update the timestamp of " + path.string();
106std::vector<std::filesystem::path>
without_sidecars(std::vector<std::filesystem::path> dependencies)
108 std::erase_if(dependencies, [](
const std::filesystem::path& path) {
109 const std::string name = path.filename().string();
110 return name.ends_with(
".describe.hpp") || name.ends_with(
".signatures.hpp");
#define MAYAFLUX_REFLECT_QUIET
#define MAYAFLUX_REFLECT_PCLOSE
#define MAYAFLUX_REFLECT_POPEN