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:
Greg Davill 2022-10-22 19:23:23 +10:30
parent 077f335dbd
commit 74ac8bba24
No known key found for this signature in database
GPG Key ID: CAFD6B08836425EC
6 changed files with 64 additions and 1 deletions

View File

@ -111,6 +111,7 @@ set(OPENFPGALOADER_SOURCE
src/jlink.cpp
src/lattice.cpp
src/progressBar.cpp
src/pathHelper.cpp
src/fsparser.cpp
src/mcsParser.cpp
src/ftdispi.cpp
@ -138,6 +139,7 @@ set(OPENFPGALOADER_HEADERS
src/ice40.hpp
src/ihexParser.hpp
src/progressBar.hpp
src/pathHelper.hpp
src/rawParser.hpp
src/usbBlaster.hpp
src/bitparser.hpp

View File

@ -27,7 +27,7 @@ build() {
-G "MSYS Makefiles" \
-DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
../../../..
cmake --build .
MSYS2_ARG_CONV_EXCL="-DDATA_DIR=" cmake --build .
}
check() {

View File

@ -13,6 +13,7 @@
#include "device.hpp"
#include "epcq.hpp"
#include "progressBar.hpp"
#include "pathHelper.hpp"
#include "rawParser.hpp"
#define IDCODE 6
@ -181,6 +182,11 @@ bool Altera::load_bridge()
bitname += _device_package + ".rbf";
#endif
#if defined (_WIN64) || defined (_WIN32)
/* Convert relative path embedded at compile time to an absolute path */
bitname = PathHelper::absolutePath(bitname);
#endif
std::cout << "use: " << bitname << std::endl;
/* first: load spi over jtag */

36
src/pathHelper.cpp Normal file
View File

@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2022 Greg Davill <greg.davill@gmail.com>
*/
#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

13
src/pathHelper.hpp Normal file
View File

@ -0,0 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2022 Greg Davill <greg.davill@gmail.com>
*/
#if defined (_WIN64) || defined (_WIN32)
#include <string>
class PathHelper{
public:
static std::string absolutePath(std::string input_path);
};
#endif

View File

@ -24,6 +24,7 @@
#include "xilinxMapParser.hpp"
#include "part.hpp"
#include "progressBar.hpp"
#include "pathHelper.hpp"
Xilinx::Xilinx(Jtag *jtag, const std::string &filename,
const std::string &file_type,
@ -323,6 +324,11 @@ bool Xilinx::load_bridge()
std::string bitname = DATA_DIR "/openFPGALoader/spiOverJtag_";
bitname += _device_package + ".bit.gz";
#if defined (_WIN64) || defined (_WIN32)
/* Convert relative path embedded at compile time to an absolute path */
bitname = PathHelper::absolutePath(bitname);
#endif
std::cout << "use: " << bitname << std::endl;
/* first: load spi over jtag */