aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-04-19 17:06:22 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-04-20 21:44:28 +0800
commit2703337365c6d8b4497b6abd0e40408dfa86f84c (patch)
treec4a7cc5ceca4758474dbf72232617785c33509f3
parentBuild: separate utility programs from tests (diff)
downloadlibbash-2703337365c6d8b4497b6abd0e40408dfa86f84c.tar.gz
libbash-2703337365c6d8b4497b6abd0e40408dfa86f84c.tar.bz2
libbash-2703337365c6d8b4497b6abd0e40408dfa86f84c.zip
Utility: implement a simple metadata generator
Use static linking to avoid confusion with libtool while benchmark.
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am5
-rw-r--r--bashast/libbashWalker.g4
-rw-r--r--utils/metadata_generator.cpp56
4 files changed, 64 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 76473ca..10b4131 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ Makefile
autom4te.cache
cppunittests
variable_printer
+metadata_generator
ast_printer
long.sh
massif.out
diff --git a/Makefile.am b/Makefile.am
index f9ba75d..08f66a9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -102,11 +102,14 @@ cppunittests_LDFLAGS = -static
endif
-noinst_PROGRAMS = variable_printer ast_printer
+noinst_PROGRAMS = variable_printer metadata_generator ast_printer
variable_printer_SOURCES = utils/variable_printer.cpp
variable_printer_LDADD = libcppbash.la
+metadata_generator_SOURCES = utils/metadata_generator.cpp
+metadata_generator_LDADD = libcppbash.la
+
ast_printer_SOURCES = utils/ast_printer.cpp
ast_printer_LDADD = libcppbash.la $(BOOST_PROGRAM_OPTIONS_LIB)
ast_printer_LDFLAGS = -static
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 33db85c..182f6c3 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -38,6 +38,8 @@ options
@postinclude{
+ #include <iostream>
+
#include <boost/format.hpp>
#include "core/interpreter.h"
@@ -228,7 +230,7 @@ simple_command
libbash_args,
ctx,
compound_command))
- throw interpreter_exception("Unimplemented command: " + $string_expr.libbash_value);
+ std::cerr << $string_expr.libbash_value << " is not implemented yet" << std::endl;
};
argument[std::vector<std::string>& args]
diff --git a/utils/metadata_generator.cpp b/utils/metadata_generator.cpp
new file mode 100644
index 0000000..9f5215d
--- /dev/null
+++ b/utils/metadata_generator.cpp
@@ -0,0 +1,56 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+ */
+///
+/// \file metadata_generator.cpp
+/// \author Mu Qiao
+/// \brief a simple utility for generating metadata
+///
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "libbash.h"
+
+static std::vector<std::string> metadata_names = {"DEPEND", "RDEPEND", "SLOT", "SRC_URI",
+ "RESTRICT", "HOMEPAGE", "LICENSE", "DESCRIPTION",
+ "KEYWORDS", "INHERITED", "IUSE", "REQUIRED_USE",
+ "PDEPEND", "PROVIDE", "EAPI", "PROPERTIES", "DEFINED_PHASES"};
+
+int main(int argc, char** argv)
+{
+ if(argc != 2)
+ {
+ std::cerr<<"Please provide your script as an argument"<<std::endl;
+ exit(EXIT_FAILURE);
+ }
+
+ std::unordered_map<std::string, std::vector<std::string>> variables;
+ libbash::interpret(argv[1], variables);
+
+ for(auto iter_name = metadata_names.begin(); iter_name != metadata_names.end(); ++iter_name)
+ {
+ auto iter_value = variables.find(*iter_name);
+ if(iter_value != variables.end())
+ std::cout << iter_value->second[0] << std::endl;
+ else
+ std::cout << std::endl;
+ }
+
+ return EXIT_SUCCESS;
+}