Skip to content

Commit

Permalink
Windows needs help converting a path to a string
Browse files Browse the repository at this point in the history
Msbuild requires that .string() on std::filesystem::path be called in a
variety of places, whereas Clang and GCC don't have a problem going
from a std::filesystem::path to a Poco::Path via a string.
  • Loading branch information
jclarkeSTFC committed Feb 12, 2025
1 parent b55c5d9 commit 3cbfb29
Show file tree
Hide file tree
Showing 39 changed files with 74 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Framework/API/src/FileProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ std::string createDirectory(const std::filesystem::path &path) {
}

if (!stempath.string().empty()) {
Poco::File stem(stempath);
Poco::File stem(stempath.string());
if (!stem.exists()) {
try {
stem.createDirectories();
Expand Down
2 changes: 1 addition & 1 deletion Framework/API/src/GroupingLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::shared_ptr<Grouping> GroupingLoader::getGroupingFromIDF() const {
const std::string groupingFile = groupingFiles[0];

// Get search directory for XML instrument definition files (IDFs)
std::string directoryName = Kernel::ConfigService::Instance().getInstrumentDirectory();
std::string directoryName = Kernel::ConfigService::Instance().getInstrumentDirectory().string();

loadGroupingFromXML(directoryName + groupingFile, *loadedGrouping);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Framework/API/src/InstrumentFileFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ std::string InstrumentFileFinder::lookupIPF(const std::filesystem::path &dir, st
prefix = filename;
}

Poco::Path directoryPath(dir);
Poco::Path directoryPath(dir.string());
directoryPath.makeDirectory();

// Assemble parameter file name
Expand Down Expand Up @@ -227,7 +227,7 @@ InstrumentFileFinder::getResourceFilenames(const std::string &prefix, const std:
for (const auto &directoryName : directoryNames) {
// Iterate over the directories from user ->etc ->install, and find the
// first beat file
for (Poco::DirectoryIterator dir_itr(directoryName); dir_itr != end_iter; ++dir_itr) {
for (Poco::DirectoryIterator dir_itr(directoryName.string()); dir_itr != end_iter; ++dir_itr) {

const auto &filePath = dir_itr.path();
if (!filePath.isFile())
Expand Down
4 changes: 2 additions & 2 deletions Framework/API/test/FilePropertyTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ class FilePropertyTest : public CxxTest::TestSuite {

void testDirectoryPasses() {
std::filesystem::path TestDir(ConfigService::Instance().getDirectoryOfExecutable() / "MyTestFolder");
Poco::File dir(TestDir);
Poco::File dir(TestDir.string());
dir.createDirectory();

FileProperty fp("SavePath", "", FileProperty::Directory);
TS_ASSERT_EQUALS(fp.isDirectoryProperty(), true);

// The directory exists, so no failure
std::string msg = fp.setValue(TestDir);
std::string msg = fp.setValue(TestDir.string());
TS_ASSERT_EQUALS(msg, "");

dir.remove(); // clean up your folder
Expand Down
2 changes: 1 addition & 1 deletion Framework/API/test/GroupingLoaderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GroupingLoaderTest : public CxxTest::TestSuite {
void test_loadGroupingFromXML() {
Grouping g;

TS_ASSERT_THROWS_NOTHING(GroupingLoader::loadGroupingFromXML(m_testDataDir / "MUSRGrouping.xml", g));
TS_ASSERT_THROWS_NOTHING(GroupingLoader::loadGroupingFromXML((m_testDataDir / "MUSRGrouping.xml").string(), g));

TS_ASSERT_EQUALS(g.groupNames.size(), 2);
TS_ASSERT_EQUALS(g.groupNames[0], "fwd");
Expand Down
2 changes: 1 addition & 1 deletion Framework/Algorithms/src/ClearCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ClearCache::exec() {

// get the instrument directories
auto instrumentDirs = Mantid::Kernel::ConfigService::Instance().getInstrumentDirectories();
Poco::Path localPath(instrumentDirs[0]);
Poco::Path localPath(instrumentDirs[0].string());
localPath.makeDirectory();

if (clearAlgCache) {
Expand Down
6 changes: 3 additions & 3 deletions Framework/Algorithms/test/ClearCacheTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ClearCacheTest : public CxxTest::TestSuite {
}

void createDirectory(const std::filesystem::path &path) {
Poco::File file(path);
Poco::File file(path.string());
if (file.createDirectory()) {
m_directoriesToRemove.emplace_back(file);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ class ClearCacheTest : public CxxTest::TestSuite {
localPath = localPath.parent_path();
}
// create a file in the directory
Poco::File testFile(localPath / "test_exec_DownloadInstrument_Cache.xml");
Poco::File testFile((localPath / "test_exec_DownloadInstrument_Cache.xml").string());
testFile.createFile();

TS_ASSERT_THROWS_NOTHING(alg.initialize())
Expand All @@ -138,7 +138,7 @@ class ClearCacheTest : public CxxTest::TestSuite {
}

// create a file in the directory
Poco::File testFile(localPath / "geometryCache" / "test_exec_Geometry_Cache.vtp");
Poco::File testFile((localPath / "geometryCache" / "test_exec_Geometry_Cache.vtp").string());
testFile.createFile();

TS_ASSERT_THROWS_NOTHING(alg.initialize())
Expand Down
4 changes: 2 additions & 2 deletions Framework/Algorithms/test/ConvertUnitsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void setup_WS(std::string &inputSpace) {
loader.initialize();
// Path to test input file assumes Test directory checked out from SVN
const std::filesystem::path inputFile = ConfigService::Instance().getInstrumentDirectory() / "HET_Definition_old.xml";
loader.setPropertyValue("Filename", inputFile);
loader.setPropertyValue("Filename", inputFile.string());
loader.setPropertyValue("Workspace", inputSpace);
loader.setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false));
loader.execute();
Expand Down Expand Up @@ -106,7 +106,7 @@ void setup_Points_WS(std::string &inputSpace) {
loader.initialize();
// Path to test input file assumes Test directory checked out from SVN
const std::filesystem::path inputFile = ConfigService::Instance().getInstrumentDirectory() / "HET_Definition_old.xml";
loader.setPropertyValue("Filename", inputFile);
loader.setPropertyValue("Filename", inputFile.string());
loader.setPropertyValue("Workspace", inputSpace);
loader.setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false));
loader.execute();
Expand Down
1 change: 1 addition & 0 deletions Framework/Crystal/test/CentroidPeaksTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "MantidFrameworkTestHelpers/FacilityHelper.h"
#include "MantidFrameworkTestHelpers/WorkspaceCreationHelper.h"
#include "MantidHistogramData/LinearGenerator.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/OptionalBool.h"
#include "MantidKernel/Timer.h"
#include <cmath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bool LoadEventNexus::runLoadInstrument(const std::string &nexusfilename, T local
API::InstrumentFileFinder::getInstrumentFilename(instrument, localWorkspace->getWorkspaceStartDate());
} catch (Kernel::Exception::NotFoundError &) {
if (instFilename.empty()) {
Poco::Path directory(Kernel::ConfigService::Instance().getInstrumentDirectory());
Poco::Path directory(Kernel::ConfigService::Instance().getInstrumentDirectory().string());
Poco::Path file(instrument + "_Definition.xml");
Poco::Path fullPath(directory, file);
instFilename = fullPath.toString();
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/DownloadInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ DownloadInstrument::StringToStringMap DownloadInstrument::processRepository() {

// get the date of the local github.json file if it exists
std::filesystem::path gitHubJson(localPath / "github.json");
Poco::File gitHubJsonFile(gitHubJson);
Poco::File gitHubJsonFile(gitHubJson.string());
Poco::DateTime gitHubJsonDate(1900, 1, 1);
bool forceUpdate = this->getProperty("ForceUpdate");
if ((!forceUpdate) && gitHubJsonFile.exists() && gitHubJsonFile.isFile()) {
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadFITS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void LoadFITS::doLoadFiles(const std::vector<std::string> &paths, const std::str
// files
try {
auto loadInst = createChildAlgorithm("LoadInstrument");
std::string directoryName = Kernel::ConfigService::Instance().getInstrumentDirectory();
std::string directoryName = Kernel::ConfigService::Instance().getInstrumentDirectory().string();
directoryName = directoryName + "/IMAT_Definition.xml";
loadInst->setPropertyValue("Filename", directoryName);
loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", std::dynamic_pointer_cast<MatrixWorkspace>(imgWS));
Expand Down
4 changes: 2 additions & 2 deletions Framework/DataHandling/src/LoadIDFFromNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ std::string LoadIDFFromNexus::getParameterCorrectionFile(const std::string &inst
// find the first appropriate file
std::filesystem::path iPath(directoryName / "embedded_instrument_corrections"); // Go to correction file subfolder
// First see if the directory exists
Poco::File ipDir(iPath);
Poco::File ipDir(iPath.string());
if (ipDir.exists() && ipDir.isDirectory()) {
iPath /= instName + "_Parameter_Corrections.xml"; // Append file name to pathname
Poco::File ipFile(iPath);
Poco::File ipFile(iPath.string());
if (ipFile.exists() && ipFile.isFile()) {
return ipFile.path(); // Return first found
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadILLDiffraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void LoadILLDiffraction::moveTwoThetaZero(double twoTheta0Read) {
*/
std::string LoadILLDiffraction::getInstrumentFilePath(const std::string &instName) const {

Poco::Path directory(ConfigService::Instance().getInstrumentDirectory());
Poco::Path directory(ConfigService::Instance().getInstrumentDirectory().string());
Poco::Path file(instName + "_Definition.xml");
Poco::Path fullPath(directory, file);
return fullPath.toString();
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadILLSANS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ void LoadILLSANS::createEmptyWorkspace(const size_t numberOfHistograms, const si
*/
std::string LoadILLSANS::getInstrumentFilePath(const std::string &instName) const {

Poco::Path directory(ConfigService::Instance().getInstrumentDirectory());
Poco::Path directory(ConfigService::Instance().getInstrumentDirectory().string());
Poco::Path file(instName + "_Definition.xml");
Poco::Path fullPath(directory, file);
return fullPath.toString();
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadNXcanSAS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ std::string extractIdfFileOnCurrentSystem(const std::string &idf) {
Mantid::Kernel::ConfigService::Instance().getInstrumentDirectories();
Poco::DirectoryIterator end_iter;
for (const auto &directoryName : directoryNames) {
for (Poco::DirectoryIterator dir_itr(directoryName); dir_itr != end_iter; ++dir_itr) {
for (Poco::DirectoryIterator dir_itr(directoryName.string()); dir_itr != end_iter; ++dir_itr) {
if (Poco::File(dir_itr->path()).isFile()) {
if (fileName == Poco::Path(dir_itr->path()).getFileName()) {
return Poco::Path(dir_itr->path()).absolute().toString();
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/SampleEnvironmentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ SampleEnvironmentSpec_uptr SampleEnvironmentSpecFileFinder::find(const std::stri
// check for the instrument environment, then facility environment
for (const auto &rel_path : {relpath_instr, relpath_facil}) {
for (const auto &prefixStr : m_rootDirs) {
Path prefix(prefixStr);
Path prefix(prefixStr.string());
// Ensure the path is a directory (note that this does not create it!)
prefix.makeDirectory();
File fullpath(Poco::Path(prefix, rel_path));
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/SetSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ SetSample::setSampleEnvironmentFromFile(API::ExperimentInfo &exptInfo, const Ker
const auto &instDirs = config.getInstrumentDirectories();
std::vector<std::filesystem::path> environDirs(instDirs);
for (auto &direc : environDirs) {
direc = Poco::Path(direc).append("sampleenvironments").toString();
direc = Poco::Path(direc.string()).append("sampleenvironments").toString();
}
auto finder = std::make_unique<SampleEnvironmentSpecFileFinder>(environDirs);
SampleEnvironmentFactory factory(std::move(finder));
Expand Down
4 changes: 2 additions & 2 deletions Framework/DataHandling/test/DownloadInstrumentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class DownloadInstrumentTest : public CxxTest::TestSuite {
static void destroySuite(DownloadInstrumentTest *suite) { delete suite; }

void createDirectory(const std::filesystem::path &path) {
Poco::File file(path);
Poco::File file(path.string());
if (file.createDirectory()) {
m_directoriesToRemove.emplace_back(file);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ class DownloadInstrumentTest : public CxxTest::TestSuite {

TSM_ASSERT_EQUALS("The expected number of files downloaded was wrong.", runDownloadInstrument(), 2);

Poco::File orphanedFile(orphanedFilePath);
Poco::File orphanedFile(orphanedFilePath.string());
TSM_ASSERT("The orphaned file was not deleted", orphanedFile.exists() == false);
}

Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/test/LoadInstrumentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class LoadInstrumentTest : public CxxTest::TestSuite {
auto runAlg = [&generateFiles, &loader, &ws2D](const std::string &name, const std::string &expected) {
auto filePath = generateFiles(name);

loader.setPropertyValue("Filename", filePath);
loader.setPropertyValue("Filename", filePath.string());
loader.setProperty("RewriteSpectraMap", OptionalBool(true));
loader.setProperty("Workspace", ws2D);

Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/test/LoadRaw3Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class LoadRaw3Test : public CxxTest::TestSuite {
std::ofstream file(rawFilePath);
file << "data goes here";

std::string adsFileName = rawFilePath + ":checksum";
std::string adsFileName = rawFilePath.string() + ":checksum";
std::ofstream adsFile(adsFileName);
adsFile << "ad0bc56c4c556fa368565000f01e77f7 *fakeRawFile.log" << std::endl;
adsFile << "d5ace6dc7ac6c4365d48ee1f2906c6f4 *fakeRawFile.nxs" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class SampleEnvironmentSpecFileFinderTest : public CxxTest::TestSuite {
" </containers>"
" </components>"
"</environmentspec>";
Poco::File envFile(testDirec / (m_envName + ".xml"));
Poco::File envFile((testDirec / (m_envName + ".xml")).string());
std::ofstream goodStream(envFile.path(), std::ios_base::out);
goodStream << xml;
goodStream.close();
// Bad file
envFile = testDirec / (m_badName + ".xml");
envFile = (testDirec / (m_badName + ".xml")).string();
std::ofstream badStream(envFile.path(), std::ios_base::out);
const std::string wrongContent = "<garbage>";
badStream << wrongContent;
Expand All @@ -72,7 +72,7 @@ class SampleEnvironmentSpecFileFinderTest : public CxxTest::TestSuite {

~SampleEnvironmentSpecFileFinderTest() {
try {
Poco::File(m_testRoot).remove(true);
Poco::File(m_testRoot.string()).remove(true);
} catch (...) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ InstrumentDefinitionParser::CachingOption InstrumentDefinitionParser::setupGeome
// temporary
// directory.
IDFObject_const_sptr fallBackCache = std::make_shared<const IDFObject>(
Poco::Path(ConfigService::Instance().getTempDir()).append(this->getMangledName() + ".vtp").toString());
Poco::Path(ConfigService::Instance().getTempDir().string()).append(this->getMangledName() + ".vtp").toString());
CachingOption cachingOption = NoneApplied;
if (m_cacheFile->exists()) {
applyCache(m_cacheFile);
Expand Down Expand Up @@ -2964,7 +2964,7 @@ const std::string InstrumentDefinitionParser::createVTPFileName() {
std::string retVal;
std::string filename = getMangledName();
if (!filename.empty()) {
Poco::Path path(ConfigService::Instance().getVTPFileDirectory());
Poco::Path path(ConfigService::Instance().getVTPFileDirectory().string());
path.makeDirectory();
path.append(filename + ".vtp");
retVal = path.toString();
Expand Down
8 changes: 4 additions & 4 deletions Framework/Geometry/test/IDFObjectTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IDFObjectTest : public CxxTest::TestSuite {
void testExists() {
const std::filesystem::path filename =
ConfigService::Instance().getInstrumentDirectory() / "unit_testing/IDF_for_UNIT_TESTING.xml";
IDFObject obj(filename);
IDFObject obj(filename.string());
TS_ASSERT(obj.exists());
}

Expand All @@ -59,22 +59,22 @@ class IDFObjectTest : public CxxTest::TestSuite {
void testGetFullPath() {
const std::filesystem::path filename =
ConfigService::Instance().getInstrumentDirectory() / "unit_testing/IDF_for_UNIT_TESTING.xml";
IDFObject obj(filename);
IDFObject obj(filename.string());
TS_ASSERT_EQUALS(filename.string(), obj.getFileFullPath().toString());
}

void testGetExtension() {
const std::filesystem::path filename =
ConfigService::Instance().getInstrumentDirectory() / "unit_testing/IDF_for_UNIT_TESTING.xml";
IDFObject obj(filename);
IDFObject obj(filename.string());
TS_ASSERT_EQUALS(".xml", obj.getExtension());
}

void testGetFileNameOnly() {
const std::string filenameonly = "IDF_for_UNIT_TESTING.xml";
const std::filesystem::path filename =
ConfigService::Instance().getInstrumentDirectory() / "unit_testing" / filenameonly;
IDFObject obj(filename);
IDFObject obj(filename.string());
TS_ASSERT_EQUALS(filenameonly, obj.getFileNameOnly());
}

Expand Down
Loading

0 comments on commit 3cbfb29

Please sign in to comment.