aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'utils/metadata_generator.cpp')
-rw-r--r--utils/metadata_generator.cpp84
1 files changed, 2 insertions, 82 deletions
diff --git a/utils/metadata_generator.cpp b/utils/metadata_generator.cpp
index 52b4590..14602f2 100644
--- a/utils/metadata_generator.cpp
+++ b/utils/metadata_generator.cpp
@@ -22,44 +22,14 @@
/// \brief a simple utility for generating metadata
///
#include <iostream>
-#include <set>
#include <string>
#include <vector>
-#include <boost/spirit/include/karma.hpp>
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/algorithm/string/trim.hpp>
-
#include "libbash.h"
-
-static const std::vector<std::string> metadata_names = {"DEPEND", "RDEPEND", "SLOT", "SRC_URI",
- "RESTRICT", "HOMEPAGE", "LICENSE", "DESCRIPTION",
- "KEYWORDS", "INHERITED", "IUSE", "REQUIRED_USE",
- "PDEPEND", "PROVIDE", "EAPI", "PROPERTIES"};
-
-static const std::unordered_map<std::string, std::string> phases = {
- {"pkg_pretend", "ppretend"},
- {"pkg_setup", "setup"},
- {"src_unpack", "unpack"},
- {"src_prepare", "prepare"},
- {"src_configure", "configure"},
- {"src_compile", "compile"},
- {"src_test", "test"},
- {"src_install", "install"},
- {"pkg_preinst", "preinst"},
- {"pkg_postinst", "postinst"},
- {"pkg_prerm", "prerm"},
- {"pkg_postrm", "postrm"},
- {"pkg_config", "config"},
- {"pkg_info", "info"},
- {"pkg_nofetch", "nofetch"}
-};
+#include "utils/metadata.h"
int main(int argc, char** argv)
{
- using namespace boost::spirit::karma;
-
if(argc != 2)
{
std::cerr<<"Please provide your script as an argument"<<std::endl;
@@ -70,57 +40,7 @@ int main(int argc, char** argv)
std::vector<std::string> functions;
libbash::interpret(argv[1], variables, functions);
- for(auto iter_name = metadata_names.begin(); iter_name != metadata_names.end(); ++iter_name)
- {
- auto iter_value = variables.find(*iter_name);
- std::string value;
-
- if(iter_value != variables.end())
- value = iter_value->second[0];
-
- // Check if global is defined
- auto iter_global = variables.find("E_" + *iter_name);
- if(iter_global != variables.end())
- {
- boost::trim_if(iter_global->second[0], boost::is_any_of(" \t\n"));
- std::vector<std::string> splitted_global;
- boost::split(splitted_global,
- iter_global->second[0],
- boost::is_any_of(" \t\n"),
- boost::token_compress_on);
-
- // Append the global value to 'value' if it doesn't cause duplication
- for(auto iter_splitted_global = splitted_global.begin();
- iter_splitted_global != splitted_global.end();
- ++iter_splitted_global)
- {
- if(value.find(*iter_splitted_global) == std::string::npos)
- value += " " + *iter_splitted_global;
- }
- }
-
- boost::trim_if(value, boost::is_any_of(" \t\n"));
-
- std::vector<std::string> splitted_value;
- boost::split(splitted_value,
- value,
- boost::is_any_of(" \t\n"),
- boost::token_compress_on);
- std::cout << format(string % ' ', splitted_value) << std::endl;
- }
-
- // Print defined phases
- std::set<std::string> sorted_phases;
- for(auto iter = functions.begin(); iter != functions.end(); ++iter)
- {
- auto iter_phase = phases.find(*iter);
- if(iter_phase != phases.end())
- sorted_phases.insert(iter_phase->second);
- }
- std::cout << format(string % ' ', sorted_phases) << std::endl;
-
- // Print empty lines
- std::cout << std::endl << std::endl << std::endl << std::endl << std::endl;
+ write_metadata(std::cout, variables, functions);
return EXIT_SUCCESS;
}