From 3174d0646b5f1a3d21a0661d8e87fc8380d73da9 Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Thu, 21 Apr 2011 16:53:03 +0800 Subject: Core: support DEFINED_PHASES for metadata generation We need to retrieve names of defined functions in order to generate DEFINED_PHASES. The public API is modified a bit to support it. A custom test is added for metadata generation. --- utils/metadata_generator.cpp | 47 +++++++++++++++++++++++++++++++++++++++----- utils/variable_printer.cpp | 3 ++- 2 files changed, 44 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/metadata_generator.cpp b/utils/metadata_generator.cpp index 9f5215d..57facb1 100644 --- a/utils/metadata_generator.cpp +++ b/utils/metadata_generator.cpp @@ -22,15 +22,36 @@ /// \brief a simple utility for generating metadata /// #include +#include #include #include +#include + #include "libbash.h" -static std::vector metadata_names = {"DEPEND", "RDEPEND", "SLOT", "SRC_URI", - "RESTRICT", "HOMEPAGE", "LICENSE", "DESCRIPTION", - "KEYWORDS", "INHERITED", "IUSE", "REQUIRED_USE", - "PDEPEND", "PROVIDE", "EAPI", "PROPERTIES", "DEFINED_PHASES"}; +static const std::vector 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 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"} +}; int main(int argc, char** argv) { @@ -41,7 +62,8 @@ int main(int argc, char** argv) } std::unordered_map> variables; - libbash::interpret(argv[1], variables); + std::vector functions; + libbash::interpret(argv[1], variables, functions); for(auto iter_name = metadata_names.begin(); iter_name != metadata_names.end(); ++iter_name) { @@ -52,5 +74,20 @@ int main(int argc, char** argv) std::cout << std::endl; } + // Print defined phases + std::set 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); + } + + using namespace boost::spirit::karma; + std::cout << format(string % ' ', sorted_phases) << std::endl; + + // Print empty lines + std::cout << std::endl << std::endl << std::endl << std::endl << std::endl; + return EXIT_SUCCESS; } diff --git a/utils/variable_printer.cpp b/utils/variable_printer.cpp index ed4aa69..192b3db 100644 --- a/utils/variable_printer.cpp +++ b/utils/variable_printer.cpp @@ -41,7 +41,8 @@ int main(int argc, char** argv) } std::unordered_map> variables; - libbash::interpret(argv[1], variables); + std::vector functions; + libbash::interpret(argv[1], variables, functions); std::map> sorted(variables.begin(), variables.end()); // Currently we don't need internal variables -- cgit v1.2.3-65-gdbad