mirror of
https://github.com/trabucayre/openFPGALoader.git
synced 2026-09-01 02:28:53 +02:00
msys2: Fix absolute windows paths
- Ensure path DATA_DIR isn't made absolute during compilation - Use cygpath to create absolute path at runtime
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
* Copyright (C) 2022 Greg Davill <[email protected]>
|
||||
*/
|
||||
|
||||
#if defined (_WIN64) || defined (_WIN32)
|
||||
#include "pathHelper.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <regex>
|
||||
|
||||
std::string PathHelper::absolutePath(std::string input_path) {
|
||||
|
||||
/* Attempt to execute cygpath */
|
||||
std::string cmd = std::string("cygpath -m " + input_path);
|
||||
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
|
||||
if (!pipe) {
|
||||
/* If cygpath fails to run, return original path */
|
||||
return input_path;
|
||||
}
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
/* Trim trailing newline */
|
||||
static const std::regex tws{"[[:space:]]*$", std::regex_constants::extended};
|
||||
return std::regex_replace(result, tws, "");
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user