aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-04-21 16:53:03 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-04-26 15:13:52 +0800
commit3174d0646b5f1a3d21a0661d8e87fc8380d73da9 (patch)
treeeb68f93b1f45dfb3a887b1487d1259da39f203e5
parentTest: rename *ebuild* to *bash* (diff)
downloadlibbash-3174d0646b5f1a3d21a0661d8e87fc8380d73da9.tar.gz
libbash-3174d0646b5f1a3d21a0661d8e87fc8380d73da9.tar.bz2
libbash-3174d0646b5f1a3d21a0661d8e87fc8380d73da9.zip
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.
-rw-r--r--Makefile.am13
-rw-r--r--scripts/sunpinyin-2.0.3-r1.ebuild32
-rw-r--r--scripts/sunpinyin-2.0.3-r1.ebuild.result25
-rw-r--r--src/core/interpreter.cpp7
-rw-r--r--src/core/interpreter.h2
-rw-r--r--src/libbash.cpp4
-rw-r--r--src/libbash.h3
-rw-r--r--test/api_test.cpp3
-rwxr-xr-xtest/ebuild_compiler.sh11
-rw-r--r--utils/metadata_generator.cpp47
-rw-r--r--utils/variable_printer.cpp3
11 files changed, 138 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index 03848ed..e161fcd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,7 +23,7 @@ include doxygen.am
ACLOCAL_AMFLAGS = -I m4
-TEST_EXTENSIONS= .gunit .bash
+TEST_EXTENSIONS= .gunit .bash .ebuild
GUNIT_LOG_COMPILER = $(srcdir)/bashast/gunit/runtests.sh
AM_GUNIT_LOG_FLAGS = @antlr_cp@:.
GUNIT_TESTS = bashast/gunit/arith_main.gunit \
@@ -60,7 +60,11 @@ BASH_RESULT = scripts/var_def.bash.result \
scripts/arithmetic_assignment.bash.result \
scripts/binary_arithmetic.bash.result
-TESTS = $(GUNIT_TESTS) $(BASH_TESTS)
+EBUILD_LOG_COMPILER = $(srcdir)/test/ebuild_compiler.sh
+EBUILD_TESTS = scripts/sunpinyin-2.0.3-r1.ebuild
+EBUILD_RESULT = scripts/sunpinyin-2.0.3-r1.ebuild.result
+
+TESTS = $(GUNIT_TESTS) $(BASH_TESTS) $(EBUILD_TESTS)
# these get cleaned so only add autogenerated stuff or modify CLEANFILES
check_JAVA = bashast/bashastLexer.java bashast/bashastParser.java
AM_JAVACFLAGS = -classpath @antlr_cp@
@@ -178,9 +182,12 @@ EXTRA_DIST = bashast/bashast.g \
test/verify_bashs_test.sh \
$(BASH_TESTS) \
$(BASH_RESULT) \
+ $(EBUILD_TESTS) \
+ $(EBUILD_RESULT) \
$(GUNIT_TESTS) \
$(GUNIT_LOG_COMPILER) \
- $(BASH_LOG_COMPILER)
+ $(BASH_LOG_COMPILER) \
+ $(EBUILD_LOG_COMPILER)
coding_standard.pdf: coding_standard/coding_standard.tex
$(AM_V_GEN)@PDFLATEX@ coding_standard/coding_standard.tex 2&>1 > /dev/null
diff --git a/scripts/sunpinyin-2.0.3-r1.ebuild b/scripts/sunpinyin-2.0.3-r1.ebuild
new file mode 100644
index 0000000..686121c
--- /dev/null
+++ b/scripts/sunpinyin-2.0.3-r1.ebuild
@@ -0,0 +1,32 @@
+EAPI="1"
+
+DESCRIPTION="SunPinyin is a SLM (Statistical Language Model) based IME"
+HOMEPAGE="http://sunpinyin.googlecode.com"
+SRC_URI="${HOMEPAGE}/files/${P}.tar.gz
+ http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
+ http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2"
+
+LICENSE="LGPL-2.1 CDDL"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+RDEPEND="dev-db/sqlite:3"
+DEPEND="${RDEPEND}
+ dev-util/pkgconfig"
+
+src_unpack() {
+ :
+}
+
+src_compile() {
+ :
+}
+
+src_install() {
+ :
+}
+
+pkg_postinst() {
+ :
+}
diff --git a/scripts/sunpinyin-2.0.3-r1.ebuild.result b/scripts/sunpinyin-2.0.3-r1.ebuild.result
new file mode 100644
index 0000000..d29858d
--- /dev/null
+++ b/scripts/sunpinyin-2.0.3-r1.ebuild.result
@@ -0,0 +1,25 @@
+dev-db/sqlite:3
+ dev-util/pkgconfig
+dev-db/sqlite:3
+0
+http://sunpinyin.googlecode.com/files/.tar.gz
+ http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
+ http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2
+
+http://sunpinyin.googlecode.com
+LGPL-2.1 CDDL
+SunPinyin is a SLM (Statistical Language Model) based IME
+~amd64 ~x86
+
+
+
+
+
+1
+
+compile install postinst unpack
+
+
+
+
+
diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
index f7e8f64..c156123 100644
--- a/src/core/interpreter.cpp
+++ b/src/core/interpreter.cpp
@@ -31,6 +31,8 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
+#include <boost/range/adaptor/map.hpp>
+#include <boost/range/algorithm/copy.hpp>
#include "libbashWalker.h"
@@ -163,3 +165,8 @@ void interpreter::trim_trailing_eols(std::string& value)
{
boost::trim_right_if(value, boost::is_any_of("\n"));
}
+
+void interpreter::get_all_function_names(std::vector<std::string>& function_names)
+{
+ boost::copy(functions | boost::adaptors::map_keys, back_inserter(function_names));
+}
diff --git a/src/core/interpreter.h b/src/core/interpreter.h
index af81c49..4f69c62 100644
--- a/src/core/interpreter.h
+++ b/src/core/interpreter.h
@@ -523,6 +523,8 @@ public:
return functions.find(name) != functions.end();
}
+ void get_all_function_names(std::vector<std::string>& function_names);
+
/// \brief execute builtin
/// \param builtin name
/// \param builtin arguments
diff --git a/src/libbash.cpp b/src/libbash.cpp
index 3dd03c6..0d1eadd 100644
--- a/src/libbash.cpp
+++ b/src/libbash.cpp
@@ -33,7 +33,8 @@
namespace libbash
{
void interpret(const std::string& path,
- std::unordered_map<std::string, std::vector<std::string>>& variables)
+ std::unordered_map<std::string, std::vector<std::string>>& variables,
+ std::vector<std::string>& functions)
{
std::ifstream input(path.c_str());
if(!input)
@@ -43,5 +44,6 @@ namespace libbash
for(auto iter = wbuilder.walker->begin(); iter != wbuilder.walker->end(); ++iter)
iter->second->get_all_values<std::string>(variables[iter->first]);
+ wbuilder.walker->get_all_function_names(functions);
}
}
diff --git a/src/libbash.h b/src/libbash.h
index 01ea5e4..ca8cdaa 100644
--- a/src/libbash.h
+++ b/src/libbash.h
@@ -41,7 +41,8 @@ namespace libbash
/// \param the path of target script
/// \param the map to store variables
void LIBBASH_API interpret(const std::string& path,
- std::unordered_map<std::string, std::vector<std::string>>& variables);
+ std::unordered_map<std::string, std::vector<std::string>>& variables,
+ std::vector<std::string>& functions);
}
#endif
diff --git a/test/api_test.cpp b/test/api_test.cpp
index 14ab059..813c3b0 100644
--- a/test/api_test.cpp
+++ b/test/api_test.cpp
@@ -31,6 +31,7 @@ using namespace std;
TEST(libbashapi, bad_path)
{
std::unordered_map<std::string, std::vector<std::string>> variables;
- EXPECT_THROW(libbash::interpret("not exist", variables),
+ std::vector<std::string> functions;
+ EXPECT_THROW(libbash::interpret("not exist", variables, functions),
interpreter_exception);
}
diff --git a/test/ebuild_compiler.sh b/test/ebuild_compiler.sh
new file mode 100755
index 0000000..5930b62
--- /dev/null
+++ b/test/ebuild_compiler.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+declare -i error=0
+
+for ebuild in $@
+do
+ ./metadata_generator $ebuild | diff -u $ebuild.result -
+ error+=$?
+done
+
+exit $error
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 <iostream>
+#include <set>
#include <string>
#include <vector>
+#include <boost/spirit/include/karma.hpp>
+
#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"};
+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"}
+};
int main(int argc, char** argv)
{
@@ -41,7 +62,8 @@ int main(int argc, char** argv)
}
std::unordered_map<std::string, std::vector<std::string>> variables;
- libbash::interpret(argv[1], variables);
+ 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)
{
@@ -52,5 +74,20 @@ int main(int argc, char** argv)
std::cout << 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);
+ }
+
+ 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<std::string, std::vector<std::string>> variables;
- libbash::interpret(argv[1], variables);
+ std::vector<std::string> functions;
+ libbash::interpret(argv[1], variables, functions);
std::map<std::string, std::vector<std::string>> sorted(variables.begin(), variables.end());
// Currently we don't need internal variables