DependenciesGenerator.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Cedric Seehausen (usdnr at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
27
28#include <filesystem>
29#include <fstream>
30
34
35
36using namespace ScenarioManager;
37using namespace Parser;
38using namespace Data_Structure;
39using namespace armarx;
40
41std::map<std::string, DependencyTree> DependenciesGenerator::cachedTrees;
42
46
49{
50 if (cachedTrees.count(packageName))
51 {
52 return cachedTrees[packageName];
53 }
54 CMakePackageFinder parser = CMakePackageFinderCache::GlobalCache.findPackage(packageName);
55
56 std::vector<std::string> dependencies = parser.getDependencies();
57 std::vector<std::string> depsConcat = dependencies;
58
59 if (!dependencies.empty() && !dependencies.at(0).empty())
60 {
61 for (auto package : dependencies)
62 {
63 std::vector<std::string> deps = getDependencieTree(package);
64 for (auto dep : deps)
65 {
66 if (std::find(depsConcat.begin(), depsConcat.end(), dep) == depsConcat.end())
67 {
68 depsConcat.push_back(dep);
69 }
70 }
71 }
72 }
73 else
74 {
75 ARMARX_DEBUG << "The package `" << packageName << "` does not have any dependencies.";
76
77 dependencies.clear();
78 dependencies.push_back(packageName);
79 cachedTrees[packageName] = dependencies;
80 return dependencies;
81 }
82
83 depsConcat.push_back(packageName);
84
85 cachedTrees[packageName] = depsConcat;
86
87 return depsConcat;
88}
89
90void
92{
93 if (package.get() == nullptr)
94 {
95 ARMARX_WARNING_S << "Unable to generate Dependencies cfg for unknown package";
96 }
97 std::filesystem::path cacheFolderPath =
98 std::filesystem::path(ArmarXDataPath::GetCachePath()) / "ComponentFiles";
99
100 if (!std::filesystem::exists(cacheFolderPath))
101 {
102 std::filesystem::create_directories(cacheFolderPath);
103 // return value of create_directories is buggy ?! check again
104 if (!std::filesystem::exists(cacheFolderPath))
105 {
106 ARMARX_ERROR_S << "Could not create Cache folder for ScenarioManagerPlugin at "
107 << cacheFolderPath.string();
108 }
109 }
110
111 std::filesystem::path cacheFilePath =
112 cacheFolderPath / std::filesystem::path("./" + package->getName() + ".dependencies.cfg");
113
114 std::ofstream out(cacheFilePath.string());
115
116 out << "ArmarX.ProjectName=" << package->getName() << std::endl;
117
118 DependencyTree deps = getDependencieTree(package->getName());
119 std::string dataPaths = "";
120 std::string depsString = "";
121
122 size_t pos = 0;
123 for (auto dep : deps)
124 {
126 dataPaths += pFinder.getDataDir();
127 depsString += dep;
128
129 if (pos != deps.size() - 1)
130 {
131 dataPaths += ";";
132 depsString += ";";
133 }
134
135 ++pos;
136 }
137
138 out << "ArmarX.ProjectDatapath=" << dataPaths << std::endl;
139 out << "ArmarX.ProjectDependencies=" << depsString << std::endl;
140
141 out.close();
142}
void generateDependenciesCfg(ScenarioManager::Data_Structure::PackagePtr package)
static DependencyTree getDependencieTree(std::string packageName)
static std::string GetCachePath()
The base Cache directory of ArmarX.
static CMakePackageFinderCache GlobalCache
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:216
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
std::shared_ptr< Package > PackagePtr
Definition Package.h:122
std::vector< std::string > DependencyTree
This file offers overloads of toIce() and fromIce() functions for STL container types.