[flang][windows] Support platform-specific path separator.

Remove the assumption that the path separator is `/`. Use functions from `llvm::sys::path` instead.

Reviewed By: isuruf, klausler

Differential Revision: https://reviews.llvm.org/D89369
This commit is contained in:
Michael Kruse 2020-10-23 09:50:30 -05:00
parent e92eeaf3c2
commit b57937861f
2 changed files with 10 additions and 7 deletions

View File

@ -11,6 +11,7 @@
#include "flang/Parser/char-buffer.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <memory>
@ -50,21 +51,23 @@ void SourceFile::IdentifyPayload() {
}
std::string DirectoryName(std::string path) {
auto lastSlash{path.rfind("/")};
return lastSlash == std::string::npos ? path : path.substr(0, lastSlash);
llvm::SmallString<128> pathBuf{path};
llvm::sys::path::remove_filename(pathBuf);
return pathBuf.str().str();
}
std::string LocateSourceFile(
std::string name, const std::vector<std::string> &searchPath) {
if (name.empty() || name == "-" || name[0] == '/') {
if (name.empty() || name == "-" || llvm::sys::path::is_absolute(name)) {
return name;
}
for (const std::string &dir : searchPath) {
std::string path{dir + '/' + name};
llvm::SmallString<128> path{dir};
llvm::sys::path::append(path, name);
bool isDir{false};
auto er = llvm::sys::fs::is_directory(path, isDir);
if (!er && !isDir) {
return path;
return path.str().str();
}
}
return name;

View File

@ -10,5 +10,5 @@ ENDPROGRAM
! RUN: %f18 -fparse-only %S/Inputs/getsymbols02-a.f90
! RUN: %f18 -fparse-only %S/Inputs/getsymbols02-b.f90
! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s
! CHECK: callget5: ./mm2b.mod,
! CHECK: get5: ./mm2a.mod,
! CHECK: callget5: .{{[/\\]}}mm2b.mod,
! CHECK: get5: .{{[/\\]}}mm2a.mod,