Skip to content
Snippets Groups Projects
Commit 8bbd72e1 authored by Lars Bilke's avatar Lars Bilke Committed by Dmitri Naumov
Browse files

[ogs] Fix xml includes in combination with patches

parent 6cc1fea9
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,7 @@
#include "InfoLib/GitInfo.h"
#include "NumLib/NumericsConfig.h"
#include "ProcessLib/TimeLoop.h"
#include "filesystem.h"
#ifdef OGS_USE_PYTHON
#include "ogs_embedded_python.h"
......@@ -193,6 +194,7 @@ int main(int argc, char* argv[])
std::string prj_file = project_arg.getValue();
auto patch_files = xml_patch_files.getValue();
std::string includepath = "";
if (BaseLib::getFileExtension(prj_file) == ".xml")
{
if (!patch_files.empty())
......@@ -223,6 +225,8 @@ int main(int argc, char* argv[])
if (!patch_files.empty())
{
includepath =
fs::canonical(fs::path(prj_file)).parent_path().string();
std::string current_prj_file = prj_file;
std::string current_prj_file_base =
BaseLib::extractBaseNameWithoutExtension(current_prj_file);
......@@ -290,8 +294,9 @@ int main(int argc, char* argv[])
prj_file = project_arg.getValue();
}
auto project_config = BaseLib::makeConfigTree(
prj_file, !nonfatal_arg.getValue(), "OpenGeoSysProject");
auto project_config =
BaseLib::makeConfigTree(prj_file, !nonfatal_arg.getValue(),
"OpenGeoSysProject", includepath);
BaseLib::setProjectDirectory(
BaseLib::extractPath(project_arg.getValue()));
......
......@@ -111,7 +111,8 @@ void replace_includes(
ConfigTreeTopLevel makeConfigTree(const std::string& filepath,
const bool be_ruthless,
const std::string& toplevel_tag)
const std::string& toplevel_tag,
std::string includepath)
{
ConfigTree::PTree ptree;
......@@ -125,7 +126,11 @@ ConfigTreeTopLevel makeConfigTree(const std::string& filepath,
if (toplevel_tag == "OpenGeoSysProject")
{
traverse(ptree, fs::path(filepath).parent_path(), replace_includes);
if (includepath == "")
{
includepath = fs::path(filepath).parent_path().string();
}
traverse(ptree, fs::path(includepath), replace_includes);
}
}
catch (boost::property_tree::xml_parser_error const& e)
......
......@@ -69,6 +69,7 @@ private:
* \param be_ruthless see ConfigTreeTopLevel::ConfigTreeTopLevel()
* \param toplevel_tag name of the outermost tag in the XML file. The returned ConfigTree is rooted
* one level below that tag.
* \param includepath optional path in which relative include file path will be resolved.
*
* The parameter \c toplevel_tag is provided for compatibility with our existing configuration
* files whose toplevel tags are written in camel case, which conflicts with the naming rules of
......@@ -87,6 +88,6 @@ private:
*/
ConfigTreeTopLevel
makeConfigTree(std::string const& filepath, bool const be_ruthless,
std::string const& toplevel_tag);
std::string const& toplevel_tag, std::string includepath = "");
} // namespace BaseLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment