logic: fixed relative project settings paths
* when specifying relative paths in project settings these stay relative when saving and loading them now.
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
<source_extensions>.c</source_extensions>
|
<source_extensions>.c</source_extensions>
|
||||||
</extensions>
|
</extensions>
|
||||||
<source_paths>
|
<source_paths>
|
||||||
<source_path>/Users/ebsi/Documents/Coati/bin/app/data/projects/tictactoe/src</source_path>
|
<source_path>./src</source_path>
|
||||||
</source_paths>
|
</source_paths>
|
||||||
<use_source_paths_for_header_search>0</use_source_paths_for_header_search>
|
<use_source_paths_for_header_search>0</use_source_paths_for_header_search>
|
||||||
</source>
|
</source>
|
||||||
|
|||||||
+4
-4
@@ -168,7 +168,7 @@ void Project::updateFileManager()
|
|||||||
{
|
{
|
||||||
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
||||||
|
|
||||||
std::vector<FilePath> sourcePaths = projSettings->getSourcePaths();
|
std::vector<FilePath> sourcePaths = projSettings->getAbsoluteSourcePaths();
|
||||||
std::vector<FilePath> headerPaths;
|
std::vector<FilePath> headerPaths;
|
||||||
|
|
||||||
if (projSettings->getCompilationDatabasePath().exists())
|
if (projSettings->getCompilationDatabasePath().exists())
|
||||||
@@ -196,7 +196,7 @@ Parser::Arguments Project::getParserArguments() const
|
|||||||
// Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
|
// Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
|
||||||
utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths());
|
utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths());
|
||||||
|
|
||||||
utility::append(args.systemHeaderSearchPaths, projSettings->getHeaderSearchPaths());
|
utility::append(args.systemHeaderSearchPaths, projSettings->getAbsoluteHeaderSearchPaths());
|
||||||
|
|
||||||
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPaths());
|
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPaths());
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ Parser::Arguments Project::getParserArguments() const
|
|||||||
if (projSettings->getUseSourcePathsForHeaderSearch())
|
if (projSettings->getUseSourcePathsForHeaderSearch())
|
||||||
{
|
{
|
||||||
std::vector<FilePath> headerSearchSubPaths;
|
std::vector<FilePath> headerSearchSubPaths;
|
||||||
for (FilePath p : projSettings->getHeaderSearchPaths())
|
for (FilePath p : projSettings->getAbsoluteHeaderSearchPaths())
|
||||||
{
|
{
|
||||||
std::vector<FilePath> tempPaths = FileSystem::getSubDirectories(p);
|
std::vector<FilePath> tempPaths = FileSystem::getSubDirectories(p);
|
||||||
headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() );
|
headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() );
|
||||||
@@ -214,7 +214,7 @@ Parser::Arguments Project::getParserArguments() const
|
|||||||
utility::append(args.systemHeaderSearchPaths, headerSearchSubPaths);
|
utility::append(args.systemHeaderSearchPaths, headerSearchSubPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
utility::append(args.frameworkSearchPaths, projSettings->getFrameworkSearchPaths());
|
utility::append(args.frameworkSearchPaths, projSettings->getAbsoluteFrameworkSearchPaths());
|
||||||
utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPaths());
|
utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPaths());
|
||||||
|
|
||||||
args.language = projSettings->getLanguage();
|
args.language = projSettings->getLanguage();
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ void ProjectSettings::save(const FilePath& filePath)
|
|||||||
m_projectName = "";
|
m_projectName = "";
|
||||||
m_projectFileLocation = "";
|
m_projectFileLocation = "";
|
||||||
|
|
||||||
moveRelativePathValues("source/source_paths/source_path", filePath);
|
|
||||||
moveRelativePathValues("source/header_search_paths/header_search_path", filePath);
|
|
||||||
moveRelativePathValues("source/framework_search_paths/framework_search_path", filePath);
|
|
||||||
|
|
||||||
Settings::save(filePath);
|
Settings::save(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +87,14 @@ bool ProjectSettings::setStandard(const std::string& standard)
|
|||||||
|
|
||||||
std::vector<FilePath> ProjectSettings::getSourcePaths() const
|
std::vector<FilePath> ProjectSettings::getSourcePaths() const
|
||||||
{
|
{
|
||||||
return getRelativePathValues("source/source_paths/source_path");
|
return getPathValues("source/source_paths/source_path");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<FilePath> ProjectSettings::getAbsoluteSourcePaths() const
|
||||||
|
{
|
||||||
|
std::vector<FilePath> paths = getSourcePaths();
|
||||||
|
makePathsAbsolute(paths);
|
||||||
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
|
bool ProjectSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
|
||||||
@@ -101,7 +104,14 @@ bool ProjectSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
|
|||||||
|
|
||||||
std::vector<FilePath> ProjectSettings::getHeaderSearchPaths() const
|
std::vector<FilePath> ProjectSettings::getHeaderSearchPaths() const
|
||||||
{
|
{
|
||||||
return getRelativePathValues("source/header_search_paths/header_search_path");
|
return getPathValues("source/header_search_paths/header_search_path");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<FilePath> ProjectSettings::getAbsoluteHeaderSearchPaths() const
|
||||||
|
{
|
||||||
|
std::vector<FilePath> paths = getHeaderSearchPaths();
|
||||||
|
makePathsAbsolute(paths);
|
||||||
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
|
bool ProjectSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
|
||||||
@@ -111,7 +121,14 @@ bool ProjectSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSe
|
|||||||
|
|
||||||
std::vector<FilePath> ProjectSettings::getFrameworkSearchPaths() const
|
std::vector<FilePath> ProjectSettings::getFrameworkSearchPaths() const
|
||||||
{
|
{
|
||||||
return getRelativePathValues("source/framework_search_paths/framework_search_path");
|
return getPathValues("source/framework_search_paths/framework_search_path");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<FilePath> ProjectSettings::getAbsoluteFrameworkSearchPaths() const
|
||||||
|
{
|
||||||
|
std::vector<FilePath> paths = getFrameworkSearchPaths();
|
||||||
|
makePathsAbsolute(paths);
|
||||||
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
|
bool ProjectSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
|
||||||
@@ -219,3 +236,15 @@ void ProjectSettings::setProjectFileLocation(const std::string& location)
|
|||||||
{
|
{
|
||||||
m_projectFileLocation = location;
|
m_projectFileLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& paths) const
|
||||||
|
{
|
||||||
|
FilePath basePath = getFilePath().parentDirectory();
|
||||||
|
for (size_t i = 0; i < paths.size(); i++)
|
||||||
|
{
|
||||||
|
if (!paths[i].isAbsolute())
|
||||||
|
{
|
||||||
|
paths[i] = basePath.concat(paths[i]).canonical();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,12 +30,15 @@ public:
|
|||||||
|
|
||||||
// source
|
// source
|
||||||
std::vector<FilePath> getSourcePaths() const;
|
std::vector<FilePath> getSourcePaths() const;
|
||||||
|
std::vector<FilePath> ProjectSettings::getAbsoluteSourcePaths() const;
|
||||||
bool setSourcePaths(const std::vector<FilePath>& sourcePaths);
|
bool setSourcePaths(const std::vector<FilePath>& sourcePaths);
|
||||||
|
|
||||||
std::vector<FilePath> getHeaderSearchPaths() const;
|
std::vector<FilePath> getHeaderSearchPaths() const;
|
||||||
|
std::vector<FilePath> getAbsoluteHeaderSearchPaths() const;
|
||||||
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
|
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
|
||||||
|
|
||||||
std::vector<FilePath> getFrameworkSearchPaths() const;
|
std::vector<FilePath> getFrameworkSearchPaths() const;
|
||||||
|
std::vector<FilePath> getAbsoluteFrameworkSearchPaths() const;
|
||||||
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
|
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
|
||||||
|
|
||||||
std::vector<std::string> getCompilerFlags() const;
|
std::vector<std::string> getCompilerFlags() const;
|
||||||
@@ -68,6 +71,8 @@ public:
|
|||||||
void setProjectFileLocation(const std::string& location);
|
void setProjectFileLocation(const std::string& location);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void makePathsAbsolute(std::vector<FilePath>& paths) const;
|
||||||
|
|
||||||
std::string m_projectName;
|
std::string m_projectName;
|
||||||
std::string m_projectFileLocation;
|
std::string m_projectFileLocation;
|
||||||
|
|
||||||
|
|||||||
@@ -102,25 +102,6 @@ std::vector<FilePath> Settings::getPathValues(const std::string& key) const
|
|||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FilePath> Settings::getRelativePathValues(const std::string& key) const
|
|
||||||
{
|
|
||||||
std::vector<std::string> values;
|
|
||||||
values = getValues(key, values);
|
|
||||||
|
|
||||||
std::vector<FilePath> paths;
|
|
||||||
for (const std::string& path : values)
|
|
||||||
{
|
|
||||||
FilePath filePath(path);
|
|
||||||
if (!filePath.isAbsolute())
|
|
||||||
{
|
|
||||||
filePath = m_filePath.parentDirectory().concat(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
paths.push_back(filePath.canonical());
|
|
||||||
}
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Settings::setPathValues(const std::string& key, const std::vector<FilePath>& paths)
|
bool Settings::setPathValues(const std::string& key, const std::vector<FilePath>& paths)
|
||||||
{
|
{
|
||||||
std::vector<std::string> values;
|
std::vector<std::string> values;
|
||||||
@@ -132,28 +113,6 @@ bool Settings::setPathValues(const std::string& key, const std::vector<FilePath>
|
|||||||
return setValues(key, values);
|
return setValues(key, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::moveRelativePathValues(const std::string& key, const FilePath& filePath)
|
|
||||||
{
|
|
||||||
std::vector<std::string> values;
|
|
||||||
values = getValues(key, values);
|
|
||||||
|
|
||||||
FilePath oldPath = m_filePath.absolute();
|
|
||||||
FilePath newPath = filePath.absolute();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < values.size(); i++)
|
|
||||||
{
|
|
||||||
FilePath path(values[i]);
|
|
||||||
if (!path.isAbsolute())
|
|
||||||
{
|
|
||||||
path = oldPath.parentDirectory().concat(path);
|
|
||||||
path = path.canonical().relativeTo(newPath);
|
|
||||||
values[i] = path.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return setValues(key, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Settings::isValueDefined(const std::string& key) const
|
bool Settings::isValueDefined(const std::string& key) const
|
||||||
{
|
{
|
||||||
return m_config->isValueDefined(key);
|
return m_config->isValueDefined(key);
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ protected:
|
|||||||
std::vector<T> getValues(const std::string& key, std::vector<T> defaultValues) const;
|
std::vector<T> getValues(const std::string& key, std::vector<T> defaultValues) const;
|
||||||
|
|
||||||
std::vector<FilePath> getPathValues(const std::string& key) const;
|
std::vector<FilePath> getPathValues(const std::string& key) const;
|
||||||
std::vector<FilePath> getRelativePathValues(const std::string& key) const;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool setValue(const std::string& key, T value);
|
bool setValue(const std::string& key, T value);
|
||||||
@@ -43,7 +42,6 @@ protected:
|
|||||||
bool setValues(const std::string& key, std::vector<T> values);
|
bool setValues(const std::string& key, std::vector<T> values);
|
||||||
|
|
||||||
bool setPathValues(const std::string& key, const std::vector<FilePath>& paths);
|
bool setPathValues(const std::string& key, const std::vector<FilePath>& paths);
|
||||||
bool moveRelativePathValues(const std::string& key, const FilePath& filePath);
|
|
||||||
|
|
||||||
bool isValueDefined(const std::string& key) const;
|
bool isValueDefined(const std::string& key) const;
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ QString QtProjectWizzardContentPathsSource::getFileNamesDescription() const
|
|||||||
|
|
||||||
QStringList QtProjectWizzardContentPathsSource::getSourceFileNames(bool headersOnly) const
|
QStringList QtProjectWizzardContentPathsSource::getSourceFileNames(bool headersOnly) const
|
||||||
{
|
{
|
||||||
std::vector<FilePath> sourcePaths = m_settings->getSourcePaths();
|
std::vector<FilePath> sourcePaths = m_settings->getAbsoluteSourcePaths();
|
||||||
|
|
||||||
std::vector<std::string> extensions;
|
std::vector<std::string> extensions;
|
||||||
if (!headersOnly)
|
if (!headersOnly)
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public:
|
|||||||
std::vector<FilePath> paths = ProjectSettings::getInstance()->getSourcePaths();
|
std::vector<FilePath> paths = ProjectSettings::getInstance()->getSourcePaths();
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(paths.size(), 1);
|
TS_ASSERT_EQUALS(paths.size(), 1);
|
||||||
TS_ASSERT_EQUALS(paths[0].str(), "data/SettingsTestSuite/data");
|
TS_ASSERT_EQUALS(paths[0].str(), "data");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_load_header_search_paths_from_file()
|
void test_load_header_search_paths_from_file()
|
||||||
@@ -126,8 +126,8 @@ public:
|
|||||||
std::vector<FilePath> paths = ProjectSettings::getInstance()->getHeaderSearchPaths();
|
std::vector<FilePath> paths = ProjectSettings::getInstance()->getHeaderSearchPaths();
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(paths.size(), 2);
|
TS_ASSERT_EQUALS(paths.size(), 2);
|
||||||
TS_ASSERT_EQUALS(paths[0].str(), "data/SettingsTestSuite/data/");
|
TS_ASSERT_EQUALS(paths[0].str(), "data/");
|
||||||
TS_ASSERT_EQUALS(paths[1].str(), "data/SettingsTestSuite/src/");
|
TS_ASSERT_EQUALS(paths[1].str(), "src/");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user