logic: Fixed FilePath to not expand environment variables in constructor

This commit is contained in:
Eberhard Graether
2016-04-19 00:13:02 +02:00
parent a57f24b2b2
commit 7cd38f8e56
13 changed files with 92 additions and 73 deletions
+2 -2
View File
@@ -198,7 +198,7 @@ Parser::Arguments Project::getParserArguments() const
utility::append(args.systemHeaderSearchPaths, projSettings->getAbsoluteHeaderSearchPaths());
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPaths());
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded());
// Add all subdirectories of the header search paths
if (projSettings->getUseSourcePathsForHeaderSearch())
@@ -215,7 +215,7 @@ Parser::Arguments Project::getParserArguments() const
}
utility::append(args.frameworkSearchPaths, projSettings->getAbsoluteFrameworkSearchPaths());
utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPaths());
utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
args.language = projSettings->getLanguage();
args.languageStandard = projSettings->getStandard();
+1 -2
View File
@@ -431,7 +431,7 @@ Id ParserClientImpl::onCommentParsed(const ParseLocation& location) // TODO: mov
{
log("comment", "no name", location);
Id fileNodeId = addFile(location.filePath.str());
addFile(location.filePath.str());
addCommentLocation(location);
return 0;
@@ -475,7 +475,6 @@ Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nam
}
Id parentNodeId = 0;
bool nodeMayExist = true;
NameHierarchy currentNameHierarchy;
for (size_t i = 0; i < nameHierarchy.size(); i++)
+14
View File
@@ -28,6 +28,13 @@ std::vector<FilePath> ApplicationSettings::getHeaderSearchPaths() const
return getPathValues("source/header_search_paths/header_search_path");
}
std::vector<FilePath> ApplicationSettings::getHeaderSearchPathsExpanded() const
{
std::vector<FilePath> paths = getPathValues("source/header_search_paths/header_search_path");
expandPaths(paths);
return paths;
}
bool ApplicationSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
{
return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths);
@@ -38,6 +45,13 @@ std::vector<FilePath> ApplicationSettings::getFrameworkSearchPaths() const
return getPathValues("source/framework_search_paths/framework_search_path");
}
std::vector<FilePath> ApplicationSettings::getFrameworkSearchPathsExpanded() const
{
std::vector<FilePath> paths = getPathValues("source/framework_search_paths/framework_search_path");
expandPaths(paths);
return paths;
}
bool ApplicationSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
{
return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths);
+2
View File
@@ -16,9 +16,11 @@ public:
// source
std::vector<FilePath> getHeaderSearchPaths() const;
std::vector<FilePath> getHeaderSearchPathsExpanded() const;
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPathsExpanded() const;
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
std::vector<std::string> getCompilerFlags() const;
+3 -1
View File
@@ -93,6 +93,7 @@ std::vector<FilePath> ProjectSettings::getSourcePaths() const
std::vector<FilePath> ProjectSettings::getAbsoluteSourcePaths() const
{
std::vector<FilePath> paths = getSourcePaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
@@ -110,6 +111,7 @@ std::vector<FilePath> ProjectSettings::getHeaderSearchPaths() const
std::vector<FilePath> ProjectSettings::getAbsoluteHeaderSearchPaths() const
{
std::vector<FilePath> paths = getHeaderSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
@@ -127,6 +129,7 @@ std::vector<FilePath> ProjectSettings::getFrameworkSearchPaths() const
std::vector<FilePath> ProjectSettings::getAbsoluteFrameworkSearchPaths() const
{
std::vector<FilePath> paths = getFrameworkSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
@@ -242,7 +245,6 @@ void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& paths) const
FilePath basePath = getFilePath().parentDirectory();
for (size_t i = 0; i < paths.size(); i++)
{
paths[i] = paths[i].expandEnvironmentVariables();
if (!paths[i].isAbsolute())
{
paths[i] = basePath.concat(paths[i]).canonical();
+8
View File
@@ -102,6 +102,14 @@ std::vector<FilePath> Settings::getPathValues(const std::string& key) const
return paths;
}
void Settings::expandPaths(std::vector<FilePath>& paths) const
{
for (FilePath& path : paths)
{
path = path.expandEnvironmentVariables();
}
}
bool Settings::setPathValues(const std::string& key, const std::vector<FilePath>& paths)
{
std::vector<std::string> values;
+1
View File
@@ -34,6 +34,7 @@ protected:
std::vector<T> getValues(const std::string& key, std::vector<T> defaultValues) const;
std::vector<FilePath> getPathValues(const std::string& key) const;
void expandPaths(std::vector<FilePath>& paths) const;
template<typename T>
bool setValue(const std::string& key, T value);
+2 -8
View File
@@ -26,14 +26,8 @@ void FileManager::setPaths(
std::vector<std::string> sourceExtensions,
std::vector<std::string> includeExtensions
){
for ( FilePath path : sourcePaths )
{
m_sourcePaths.push_back(path.expandEnvironmentVariables());
}
for ( FilePath path : headerPaths )
{
m_headerPaths.push_back(path.expandEnvironmentVariables());
}
m_sourcePaths = sourcePaths;
m_headerPaths = headerPaths;
m_sourceExtensions = sourceExtensions;
m_includeExtensions = includeExtensions;
}
+20 -24
View File
@@ -1,32 +1,34 @@
#include "utility/file/FilePath.h"
#include <regex>
#include "utility/logging/logging.h"
FilePath::FilePath()
: m_exists(false)
, m_checkedExists(false)
{
}
FilePath::FilePath(const char* filePath)
: m_path(filePath)
, m_exists(false)
, m_checkedExists(false)
{
init();
}
FilePath::FilePath(const std::string& filePath)
: m_path(filePath)
, m_exists(false)
, m_checkedExists(false)
{
init();
}
FilePath::FilePath(const boost::filesystem::path& filePath)
: m_path(filePath)
, m_exists(false)
, m_checkedExists(false)
{
init();
}
boost::filesystem::path FilePath::path() const
@@ -41,6 +43,12 @@ bool FilePath::empty() const
bool FilePath::exists() const
{
if (!m_checkedExists)
{
m_exists = boost::filesystem::exists(m_path);
m_checkedExists = true;
}
return m_exists;
}
@@ -103,25 +111,22 @@ FilePath FilePath::canonical() const
FilePath FilePath::expandEnvironmentVariables() const
{
return FilePath(expandEnvironmentVariables(str()));
}
std::string text = str();
std::string FilePath::expandEnvironmentVariables(const std::string& path) const
{
std::string text = path;
static std::regex env( "\\$\\{([^}]+)\\}|%([0-9A-Za-z\\/]*)%" );
static std::regex env("\\$\\{([^}]+)\\}|%([0-9A-Za-z\\/]*)%");
std::smatch match;
while ( std::regex_search( text, match, env ) ) {
const char * s = getenv( match[1].str().c_str() );
while (std::regex_search(text, match, env))
{
const char * s = getenv(match[1].str().c_str());
if (s == nullptr)
{
LOG_ERROR(match[1].str() + " is no a environment variable");
return path;
return FilePath();
}
text.replace( match[0].first, match[0].second, s);
}
return text;
return FilePath(text);
}
FilePath FilePath::relativeTo(const FilePath& other) const
@@ -188,7 +193,7 @@ FilePath FilePath::withoutExtension() const
return FilePath(boost::filesystem::path(m_path).replace_extension());
}
FilePath FilePath::replaceExtension(const std::string& extension)
FilePath FilePath::replaceExtension(const std::string& extension) const
{
return FilePath(boost::filesystem::path(m_path).replace_extension(extension));
}
@@ -225,12 +230,3 @@ bool FilePath::operator<(const FilePath& other) const
{
return m_path.compare(other.m_path) < 0;
}
void FilePath::init()
{
boost::filesystem::path p(expandEnvironmentVariables(m_path.generic_string()));
if (boost::filesystem::exists(p))
{
m_exists = true;
}
}
+4 -5
View File
@@ -27,14 +27,13 @@ public:
FilePath relativeTo(const FilePath& other) const;
FilePath concat(const FilePath& other) const;
FilePath expandEnvironmentVariables() const;
std::string expandEnvironmentVariables(const std::string & path) const;
std::string str() const;
std::string fileName() const;
std::string extension() const;
FilePath withoutExtension() const;
FilePath replaceExtension(const std::string& extension);
FilePath replaceExtension(const std::string& extension) const;
bool hasExtension(const std::vector<std::string>& extensions) const;
bool operator==(const FilePath& other) const;
@@ -42,10 +41,10 @@ public:
bool operator<(const FilePath& other) const;
private:
void init();
boost::filesystem::path m_path;
bool m_exists;
mutable bool m_exists;
mutable bool m_checkedExists;
};
#endif // FILE_PATH_H
@@ -92,6 +92,34 @@ QSize QtProjectWizzardContentPaths::preferredWindowSize() const
return QSize(750, 500);
}
bool QtProjectWizzardContentPaths::check()
{
QString missingPaths;
for (FilePath f : m_list->getList())
{
f = f.expandEnvironmentVariables();
if (!f.exists())
{
if (!missingPaths.isEmpty())
{
missingPaths.append("\n");
}
missingPaths.append(f.str().c_str());
}
if (!missingPaths.isEmpty())
{
QMessageBox msgBox;
msgBox.setText("These paths do not exist:\n" + missingPaths);
msgBox.exec();
return false;
}
}
return true;
}
void QtProjectWizzardContentPaths::setInfo(const QString& title, const QString& description, const QString& help)
{
m_titleString = title;
@@ -208,27 +236,8 @@ bool QtProjectWizzardContentPathsSource::check()
msgBox.exec();
return false;
}
QString missingPaths;
for(FilePath f : m_list->getList())
{
if(!f.exists())
{
if(!missingPaths.isEmpty())
{
missingPaths.append("\n");
}
missingPaths.append(f.expandEnvironmentVariables().str().c_str());
}
if(!missingPaths.isEmpty())
{
QMessageBox msgBox;
msgBox.setText("The following paths do not exist:\n" + missingPaths );
msgBox.exec();
return false;
}
}
return true;
return QtProjectWizzardContentPaths::check();
}
QStringList QtProjectWizzardContentPathsSource::getFileNames() const
@@ -309,11 +318,6 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader(
);
}
bool QtProjectWizzardContentPathsCDBHeader::check()
{
return true;
}
QStringList QtProjectWizzardContentPathsCDBHeader::getFileNames() const
{
return getSourceFileNames(true);
@@ -26,6 +26,8 @@ public:
virtual QSize preferredWindowSize() const override;
virtual bool check() override;
protected:
void setInfo(const QString& title, const QString& description, const QString& help);
void setTitleString(const QString& title);
@@ -86,8 +88,6 @@ public:
QtProjectWizzardContentPathsCDBHeader(ProjectSettings* settings, QtProjectWizzardWindow* window);
// QtProjectWizzardContent implementation
virtual bool check() override;
virtual QStringList getFileNames() const override;
virtual QString getFileNamesTitle() const override;
virtual QString getFileNamesDescription() const override;
@@ -991,10 +991,10 @@ bool ASTVisitor::VisitTypeLoc(clang::TypeLoc tl)
///////////////////////////////////////////////////////////////////////////////
// Reference recording
static inline bool isNamedDeclUnnamed(clang::NamedDecl *d)
{
return d->getDeclName().isIdentifier() && d->getIdentifier() == NULL;
}
// static inline bool isNamedDeclUnnamed(clang::NamedDecl *d)
// {
// return d->getDeclName().isIdentifier() && d->getIdentifier() == NULL;
// }
ParseLocation ASTVisitor::getDeclRefRange(clang::NamedDecl *decl, clang::SourceLocation loc)
{