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 
26 #include "DependenciesGenerator.h"
27 
31 #include <filesystem>
32 #include <fstream>
33 
34 
35 using namespace ScenarioManager;
36 using namespace Parser;
37 using namespace Data_Structure;
38 using namespace armarx;
39 
40 std::map<std::string, DependencyTree> DependenciesGenerator::cachedTrees;
41 
43 {
44 }
45 
47 {
48  if (cachedTrees.count(packageName))
49  {
50  return cachedTrees[packageName];
51  }
52  CMakePackageFinder parser = CMakePackageFinderCache::GlobalCache.findPackage(packageName);
53 
54  std::vector<std::string> dependencies = parser.getDependencies();
55  std::vector<std::string> depsConcat = dependencies;
56 
57  if (!dependencies.empty() && !dependencies.at(0).empty())
58  {
59  for (auto package : dependencies)
60  {
61  std::vector<std::string> deps = getDependencieTree(package);
62  for (auto dep : deps)
63  {
64  if (std::find(depsConcat.begin(), depsConcat.end(), dep) == depsConcat.end())
65  {
66  depsConcat.push_back(dep);
67  }
68  }
69  }
70  }
71  else
72  {
73  ARMARX_DEBUG << "The package `" << packageName << "` does not have any dependencies.";
74 
75  dependencies.clear();
76  dependencies.push_back(packageName);
77  cachedTrees[packageName] = dependencies;
78  return dependencies;
79  }
80 
81  depsConcat.push_back(packageName);
82 
83  cachedTrees[packageName] = depsConcat;
84 
85  return depsConcat;
86 }
87 
89 {
90  if (package.get() == nullptr)
91  {
92  ARMARX_WARNING_S << "Unable to generate Dependencies cfg for unknown package";
93  }
94  std::filesystem::path cacheFolderPath = std::filesystem::path(ArmarXDataPath::GetCachePath()) / "ComponentFiles";
95 
96  if (!std::filesystem::exists(cacheFolderPath))
97  {
98  std::filesystem::create_directories(cacheFolderPath);
99  // return value of create_directories is buggy ?! check again
100  if (!std::filesystem::exists(cacheFolderPath))
101  {
102  ARMARX_ERROR_S << "Could not create Cache folder for ScenarioManagerPlugin at " << cacheFolderPath.string();
103  }
104  }
105 
106  std::filesystem::path cacheFilePath = cacheFolderPath / std::filesystem::path("./" + package->getName() + ".dependencies.cfg");
107 
108  std::ofstream out(cacheFilePath.string());
109 
110  out << "ArmarX.ProjectName=" << package->getName() << std::endl;
111 
112  DependencyTree deps = getDependencieTree(package->getName());
113  std::string dataPaths = "";
114  std::string depsString = "";
115 
116  size_t pos = 0;
117  for (auto dep : deps)
118  {
119  CMakePackageFinder pFinder = CMakePackageFinderCache::GlobalCache.findPackage(dep);
120  dataPaths += pFinder.getDataDir();
121  depsString += dep;
122 
123  if (pos != deps.size() - 1)
124  {
125  dataPaths += ";";
126  depsString += ";";
127  }
128 
129  ++pos;
130  }
131 
132  out << "ArmarX.ProjectDatapath=" << dataPaths << std::endl;
133  out << "ArmarX.ProjectDependencies=" << depsString << std::endl;
134 
135  out.close();
136 }
ScenarioManager::Parser::DependenciesGenerator::generateDependenciesCfg
void generateDependenciesCfg(ScenarioManager::Data_Structure::PackagePtr package)
Definition: DependenciesGenerator.cpp:88
ScenarioManager::Parser::DependenciesGenerator::getDependencieTree
static DependencyTree getDependencieTree(std::string packageName)
Definition: DependenciesGenerator.cpp:46
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
ScenarioManager::Data_Structure::PackagePtr
std::shared_ptr< Package > PackagePtr
Definition: Package.h:121
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
DependenciesGenerator.h
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
ScenarioManager::Parser::DependenciesGenerator::DependenciesGenerator
DependenciesGenerator()
Definition: DependenciesGenerator.cpp:42
CMakePackageFinder.h
IceStorm::parser
Parser * parser
Definition: Parser.cpp:33
ScenarioManager
Definition: Application.cpp:166
ScenarioManager::Parser::DependencyTree
std::vector< std::string > DependencyTree
Definition: DependenciesGenerator.h:36
Logging.h
ArmarXDataPath.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28