mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
For PR495:
Change interface to Path class: readable -> canRead writable -> canWrite executable -> canExecute More (incremental) changes coming to close 495. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22345 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8d4b9eddc0
commit
c7f083297c
@ -241,6 +241,14 @@ namespace sys {
|
|||||||
/// @brief Determines if the path name references a directory.
|
/// @brief Determines if the path name references a directory.
|
||||||
bool isDirectory() const;
|
bool isDirectory() const;
|
||||||
|
|
||||||
|
/// This function determines if the path refers to a hidden file. The
|
||||||
|
/// notion of hidden files is defined by the underlying system. The
|
||||||
|
/// system may not support hidden files in which case this function always
|
||||||
|
/// returns false on such systems. Hidden files have the "hidden"
|
||||||
|
/// attribute set on Win32. On Unix, hidden files start with a period.
|
||||||
|
/// @brief Determines if the path name references a hidden file.
|
||||||
|
bool isHidden() const;
|
||||||
|
|
||||||
/// This function determines if the path name in this object references
|
/// This function determines if the path name in this object references
|
||||||
/// the root (top level directory) of the file system. The details of what
|
/// the root (top level directory) of the file system. The details of what
|
||||||
/// is considered the "root" may vary from system to system so this method
|
/// is considered the "root" may vary from system to system so this method
|
||||||
@ -303,7 +311,7 @@ namespace sys {
|
|||||||
/// @returns true if the pathname references a readable file.
|
/// @returns true if the pathname references a readable file.
|
||||||
/// @brief Determines if the path is a readable file or directory
|
/// @brief Determines if the path is a readable file or directory
|
||||||
/// in the file system.
|
/// in the file system.
|
||||||
bool readable() const;
|
bool canRead() const;
|
||||||
|
|
||||||
/// This function determines if the path name references a writable file
|
/// This function determines if the path name references a writable file
|
||||||
/// or directory in the file system. Unlike isFile and isDirectory, this
|
/// or directory in the file system. Unlike isFile and isDirectory, this
|
||||||
@ -312,7 +320,7 @@ namespace sys {
|
|||||||
/// @returns true if the pathname references a writable file.
|
/// @returns true if the pathname references a writable file.
|
||||||
/// @brief Determines if the path is a writable file or directory
|
/// @brief Determines if the path is a writable file or directory
|
||||||
/// in the file system.
|
/// in the file system.
|
||||||
bool writable() const;
|
bool canWrite() const;
|
||||||
|
|
||||||
/// This function determines if the path name references an executable
|
/// This function determines if the path name references an executable
|
||||||
/// file in the file system. Unlike isFile and isDirectory, this
|
/// file in the file system. Unlike isFile and isDirectory, this
|
||||||
@ -321,7 +329,7 @@ namespace sys {
|
|||||||
/// @returns true if the pathname references an executable file.
|
/// @returns true if the pathname references an executable file.
|
||||||
/// @brief Determines if the path is an executable file in the file
|
/// @brief Determines if the path is an executable file in the file
|
||||||
/// system.
|
/// system.
|
||||||
bool executable() const;
|
bool canExecute() const;
|
||||||
|
|
||||||
/// This function returns the current contents of the path as a
|
/// This function returns the current contents of the path as a
|
||||||
/// std::string. This allows the underlying path string to be manipulated
|
/// std::string. This allows the underlying path string to be manipulated
|
||||||
|
@ -174,7 +174,7 @@ SourceFile &SourceFileInfo::getSourceText() const {
|
|||||||
if (!Directory.empty())
|
if (!Directory.empty())
|
||||||
tmpPath.setDirectory(Directory);
|
tmpPath.setDirectory(Directory);
|
||||||
tmpPath.appendFile(BaseName);
|
tmpPath.appendFile(BaseName);
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
SourceText = new SourceFile(tmpPath.toString(), Descriptor);
|
SourceText = new SourceFile(tmpPath.toString(), Descriptor);
|
||||||
else
|
else
|
||||||
SourceText = new SourceFile(BaseName, Descriptor);
|
SourceText = new SourceFile(BaseName, Descriptor);
|
||||||
|
@ -118,7 +118,7 @@ bool Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
|
|||||||
///
|
///
|
||||||
bool Linker::LinkInFile(const sys::Path &File) {
|
bool Linker::LinkInFile(const sys::Path &File) {
|
||||||
// Make sure we can at least read the file
|
// Make sure we can at least read the file
|
||||||
if (!File.readable())
|
if (!File.canRead())
|
||||||
return error("Cannot find linker input '" + File.toString() + "'");
|
return error("Cannot find linker input '" + File.toString() + "'");
|
||||||
|
|
||||||
// A user may specify an ar archive without -l, perhaps because it
|
// A user may specify an ar archive without -l, perhaps because it
|
||||||
|
@ -153,7 +153,7 @@ Linker::FindLib(const std::string &Filename)
|
|||||||
{
|
{
|
||||||
// Determine if the pathname can be found as it stands.
|
// Determine if the pathname can be found as it stands.
|
||||||
sys::Path FilePath(Filename);
|
sys::Path FilePath(Filename);
|
||||||
if (FilePath.readable() &&
|
if (FilePath.canRead() &&
|
||||||
(FilePath.isArchive() || FilePath.isDynamicLibrary()))
|
(FilePath.isArchive() || FilePath.isDynamicLibrary()))
|
||||||
return FilePath;
|
return FilePath;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ sys::Path llvm::FindExecutable(const std::string &ExeName,
|
|||||||
Result.elideFile();
|
Result.elideFile();
|
||||||
if (!Result.isEmpty()) {
|
if (!Result.isEmpty()) {
|
||||||
Result.appendFile(ExeName);
|
Result.appendFile(ExeName);
|
||||||
if (Result.executable())
|
if (Result.canExecute())
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ sys::IdentifyFileType(const char*magic, unsigned length) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isArchive() const {
|
Path::isArchive() const {
|
||||||
if (readable())
|
if (canRead())
|
||||||
return hasMagicNumber("!<arch>\012");
|
return hasMagicNumber("!<arch>\012");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isDynamicLibrary() const {
|
Path::isDynamicLibrary() const {
|
||||||
if (readable())
|
if (canRead())
|
||||||
return hasMagicNumber("\177ELF");
|
return hasMagicNumber("\177ELF");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -168,14 +168,14 @@ static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
|
|||||||
while( delim != 0 ) {
|
while( delim != 0 ) {
|
||||||
std::string tmp(at, size_t(delim-at));
|
std::string tmp(at, size_t(delim-at));
|
||||||
if (tmpPath.setDirectory(tmp))
|
if (tmpPath.setDirectory(tmp))
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
Paths.push_back(tmpPath);
|
Paths.push_back(tmpPath);
|
||||||
at = delim + 1;
|
at = delim + 1;
|
||||||
delim = strchr(at, ':');
|
delim = strchr(at, ':');
|
||||||
}
|
}
|
||||||
if (*at != 0)
|
if (*at != 0)
|
||||||
if (tmpPath.setDirectory(std::string(at)))
|
if (tmpPath.setDirectory(std::string(at)))
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
Paths.push_back(tmpPath);
|
Paths.push_back(tmpPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
|
|||||||
{
|
{
|
||||||
Path tmpPath;
|
Path tmpPath;
|
||||||
if (tmpPath.setDirectory(LLVM_LIBDIR))
|
if (tmpPath.setDirectory(LLVM_LIBDIR))
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
Paths.push_back(tmpPath);
|
Paths.push_back(tmpPath);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -305,17 +305,17 @@ Path::exists() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::readable() const {
|
Path::canRead() const {
|
||||||
return 0 == access(path.c_str(), F_OK | R_OK );
|
return 0 == access(path.c_str(), F_OK | R_OK );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::writable() const {
|
Path::canWrite() const {
|
||||||
return 0 == access(path.c_str(), F_OK | W_OK );
|
return 0 == access(path.c_str(), F_OK | W_OK );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::executable() const {
|
Path::canExecute() const {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int r = stat(path.c_str(), &st);
|
int r = stat(path.c_str(), &st);
|
||||||
if (r != 0 || !S_ISREG(st.st_mode))
|
if (r != 0 || !S_ISREG(st.st_mode))
|
||||||
|
@ -46,7 +46,7 @@ Program::FindProgramByName(const std::string& progName) {
|
|||||||
return Path();
|
return Path();
|
||||||
// FIXME: have to check for absolute filename - we cannot assume anything
|
// FIXME: have to check for absolute filename - we cannot assume anything
|
||||||
// about "." being in $PATH
|
// about "." being in $PATH
|
||||||
if (temp.executable()) // already executable as is
|
if (temp.canExecute()) // already executable as is
|
||||||
return temp;
|
return temp;
|
||||||
|
|
||||||
// At this point, the file name is valid and its not executable
|
// At this point, the file name is valid and its not executable
|
||||||
@ -66,7 +66,7 @@ Program::FindProgramByName(const std::string& progName) {
|
|||||||
Path FilePath;
|
Path FilePath;
|
||||||
if (FilePath.setDirectory(std::string(PathStr,Colon))) {
|
if (FilePath.setDirectory(std::string(PathStr,Colon))) {
|
||||||
FilePath.appendFile(progName);
|
FilePath.appendFile(progName);
|
||||||
if (FilePath.executable())
|
if (FilePath.canExecute())
|
||||||
return FilePath; // Found the executable!
|
return FilePath; // Found the executable!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ Program::ExecuteAndWait(const Path& path,
|
|||||||
const Path** redirects,
|
const Path** redirects,
|
||||||
unsigned secondsToWait
|
unsigned secondsToWait
|
||||||
) {
|
) {
|
||||||
if (!path.executable())
|
if (!path.canExecute())
|
||||||
throw path.toString() + " is not executable";
|
throw path.toString() + " is not executable";
|
||||||
|
|
||||||
#ifdef HAVE_SYS_WAIT_H
|
#ifdef HAVE_SYS_WAIT_H
|
||||||
|
@ -139,14 +139,14 @@ static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
|
|||||||
while( delim != 0 ) {
|
while( delim != 0 ) {
|
||||||
std::string tmp(at, size_t(delim-at));
|
std::string tmp(at, size_t(delim-at));
|
||||||
if (tmpPath.setDirectory(tmp))
|
if (tmpPath.setDirectory(tmp))
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
Paths.push_back(tmpPath);
|
Paths.push_back(tmpPath);
|
||||||
at = delim + 1;
|
at = delim + 1;
|
||||||
delim = strchr(at, ';');
|
delim = strchr(at, ';');
|
||||||
}
|
}
|
||||||
if (*at != 0)
|
if (*at != 0)
|
||||||
if (tmpPath.setDirectory(std::string(at)))
|
if (tmpPath.setDirectory(std::string(at)))
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
Paths.push_back(tmpPath);
|
Paths.push_back(tmpPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
|
|||||||
{
|
{
|
||||||
Path tmpPath;
|
Path tmpPath;
|
||||||
if (tmpPath.setDirectory(LLVM_LIBDIR))
|
if (tmpPath.setDirectory(LLVM_LIBDIR))
|
||||||
if (tmpPath.readable())
|
if (tmpPath.canRead())
|
||||||
Paths.push_back(tmpPath);
|
Paths.push_back(tmpPath);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -237,21 +237,21 @@ Path::exists() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::readable() const {
|
Path::canRead() const {
|
||||||
// FIXME: take security attributes into account.
|
// FIXME: take security attributes into account.
|
||||||
DWORD attr = GetFileAttributes(path.c_str());
|
DWORD attr = GetFileAttributes(path.c_str());
|
||||||
return attr != INVALID_FILE_ATTRIBUTES;
|
return attr != INVALID_FILE_ATTRIBUTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::writable() const {
|
Path::canWrite() const {
|
||||||
// FIXME: take security attributes into account.
|
// FIXME: take security attributes into account.
|
||||||
DWORD attr = GetFileAttributes(path.c_str());
|
DWORD attr = GetFileAttributes(path.c_str());
|
||||||
return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY);
|
return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::executable() const {
|
Path::canExecute() const {
|
||||||
// FIXME: take security attributes into account.
|
// FIXME: take security attributes into account.
|
||||||
DWORD attr = GetFileAttributes(path.c_str());
|
DWORD attr = GetFileAttributes(path.c_str());
|
||||||
return attr != INVALID_FILE_ATTRIBUTES;
|
return attr != INVALID_FILE_ATTRIBUTES;
|
||||||
|
@ -119,7 +119,7 @@ void DumpSymbolNamesFromModule (Module *M) {
|
|||||||
void DumpSymbolNamesFromFile (std::string &Filename) {
|
void DumpSymbolNamesFromFile (std::string &Filename) {
|
||||||
std::string ErrorMessage;
|
std::string ErrorMessage;
|
||||||
sys::Path aPath(Filename);
|
sys::Path aPath(Filename);
|
||||||
if (Filename != "-" && !aPath.readable()) {
|
if (Filename != "-" && !aPath.canRead()) {
|
||||||
std::cerr << ToolName << ": " << Filename << ": " << strerror (errno)
|
std::cerr << ToolName << ": " << Filename << ": " << strerror (errno)
|
||||||
<< "\n";
|
<< "\n";
|
||||||
return;
|
return;
|
||||||
|
@ -187,7 +187,7 @@ private:
|
|||||||
|
|
||||||
void cleanup() {
|
void cleanup() {
|
||||||
if (!isSet(KEEP_TEMPS_FLAG)) {
|
if (!isSet(KEEP_TEMPS_FLAG)) {
|
||||||
if (TempDir.isDirectory() && TempDir.writable())
|
if (TempDir.isDirectory() && TempDir.canWrite())
|
||||||
TempDir.destroyDirectory(/*remove_contents=*/true);
|
TempDir.destroyDirectory(/*remove_contents=*/true);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Temporary files are in " << TempDir << "\n";
|
std::cout << "Temporary files are in " << TempDir << "\n";
|
||||||
@ -415,7 +415,7 @@ private:
|
|||||||
if (progpath.isEmpty())
|
if (progpath.isEmpty())
|
||||||
throw std::string("Can't find program '" +
|
throw std::string("Can't find program '" +
|
||||||
action->program.toString()+"'");
|
action->program.toString()+"'");
|
||||||
else if (progpath.executable())
|
else if (progpath.canExecute())
|
||||||
action->program = progpath;
|
action->program = progpath;
|
||||||
else
|
else
|
||||||
throw std::string("Program '"+action->program.toString()+
|
throw std::string("Program '"+action->program.toString()+
|
||||||
@ -449,32 +449,32 @@ private:
|
|||||||
bool native = false) {
|
bool native = false) {
|
||||||
sys::Path fullpath;
|
sys::Path fullpath;
|
||||||
fullpath.setFile(link_item);
|
fullpath.setFile(link_item);
|
||||||
if (fullpath.readable())
|
if (fullpath.canRead())
|
||||||
return fullpath;
|
return fullpath;
|
||||||
for (PathVector::iterator PI = LibraryPaths.begin(),
|
for (PathVector::iterator PI = LibraryPaths.begin(),
|
||||||
PE = LibraryPaths.end(); PI != PE; ++PI) {
|
PE = LibraryPaths.end(); PI != PE; ++PI) {
|
||||||
fullpath.setDirectory(PI->toString());
|
fullpath.setDirectory(PI->toString());
|
||||||
fullpath.appendFile(link_item);
|
fullpath.appendFile(link_item);
|
||||||
if (fullpath.readable())
|
if (fullpath.canRead())
|
||||||
return fullpath;
|
return fullpath;
|
||||||
if (native) {
|
if (native) {
|
||||||
fullpath.appendSuffix("a");
|
fullpath.appendSuffix("a");
|
||||||
} else {
|
} else {
|
||||||
fullpath.appendSuffix("bc");
|
fullpath.appendSuffix("bc");
|
||||||
if (fullpath.readable())
|
if (fullpath.canRead())
|
||||||
return fullpath;
|
return fullpath;
|
||||||
fullpath.elideSuffix();
|
fullpath.elideSuffix();
|
||||||
fullpath.appendSuffix("o");
|
fullpath.appendSuffix("o");
|
||||||
if (fullpath.readable())
|
if (fullpath.canRead())
|
||||||
return fullpath;
|
return fullpath;
|
||||||
fullpath = *PI;
|
fullpath = *PI;
|
||||||
fullpath.appendFile(std::string("lib") + link_item);
|
fullpath.appendFile(std::string("lib") + link_item);
|
||||||
fullpath.appendSuffix("a");
|
fullpath.appendSuffix("a");
|
||||||
if (fullpath.readable())
|
if (fullpath.canRead())
|
||||||
return fullpath;
|
return fullpath;
|
||||||
fullpath.elideSuffix();
|
fullpath.elideSuffix();
|
||||||
fullpath.appendSuffix("so");
|
fullpath.appendSuffix("so");
|
||||||
if (fullpath.readable())
|
if (fullpath.canRead())
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,7 +494,7 @@ private:
|
|||||||
// First, see if the unadorned file name is not readable. If so,
|
// First, see if the unadorned file name is not readable. If so,
|
||||||
// we must track down the file in the lib search path.
|
// we must track down the file in the lib search path.
|
||||||
sys::Path fullpath;
|
sys::Path fullpath;
|
||||||
if (!link_item.readable()) {
|
if (!link_item.canRead()) {
|
||||||
// look for the library using the -L arguments specified
|
// look for the library using the -L arguments specified
|
||||||
// on the command line.
|
// on the command line.
|
||||||
fullpath = GetPathForLinkageItem(link_item.toString());
|
fullpath = GetPathForLinkageItem(link_item.toString());
|
||||||
|
@ -549,7 +549,7 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
|
|||||||
if (conf) {
|
if (conf) {
|
||||||
confFile.setDirectory(conf);
|
confFile.setDirectory(conf);
|
||||||
confFile.appendFile(ftype);
|
confFile.appendFile(ftype);
|
||||||
if (!confFile.readable())
|
if (!confFile.canRead())
|
||||||
throw std::string("Configuration file for '") + ftype +
|
throw std::string("Configuration file for '") + ftype +
|
||||||
"' is not available.";
|
"' is not available.";
|
||||||
} else {
|
} else {
|
||||||
@ -559,18 +559,18 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
|
|||||||
confFile.appendDirectory(".llvm");
|
confFile.appendDirectory(".llvm");
|
||||||
confFile.appendDirectory("etc");
|
confFile.appendDirectory("etc");
|
||||||
confFile.appendFile(ftype);
|
confFile.appendFile(ftype);
|
||||||
if (!confFile.readable())
|
if (!confFile.canRead())
|
||||||
confFile.clear();
|
confFile.clear();
|
||||||
}
|
}
|
||||||
if (confFile.isEmpty()) {
|
if (confFile.isEmpty()) {
|
||||||
// Okay, try the LLVM installation directory
|
// Okay, try the LLVM installation directory
|
||||||
confFile = sys::Path::GetLLVMConfigDir();
|
confFile = sys::Path::GetLLVMConfigDir();
|
||||||
confFile.appendFile(ftype);
|
confFile.appendFile(ftype);
|
||||||
if (!confFile.readable()) {
|
if (!confFile.canRead()) {
|
||||||
// Okay, try the "standard" place
|
// Okay, try the "standard" place
|
||||||
confFile = sys::Path::GetLLVMDefaultConfigDir();
|
confFile = sys::Path::GetLLVMDefaultConfigDir();
|
||||||
confFile.appendFile(ftype);
|
confFile.appendFile(ftype);
|
||||||
if (!confFile.readable()) {
|
if (!confFile.canRead()) {
|
||||||
throw std::string("Configuration file for '") + ftype +
|
throw std::string("Configuration file for '") + ftype +
|
||||||
"' is not available.";
|
"' is not available.";
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
|
|||||||
} else {
|
} else {
|
||||||
confFile = configDir;
|
confFile = configDir;
|
||||||
confFile.appendFile(ftype);
|
confFile.appendFile(ftype);
|
||||||
if (!confFile.readable())
|
if (!confFile.canRead())
|
||||||
throw std::string("Configuration file for '") + ftype +
|
throw std::string("Configuration file for '") + ftype +
|
||||||
"' is not available.";
|
"' is not available.";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user