Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/core/, test/, utils/
Date: Tue, 26 Apr 2011 11:02:37
Message-Id: 3174d0646b5f1a3d21a0661d8e87fc8380d73da9.betelgeuse@gentoo
1 commit: 3174d0646b5f1a3d21a0661d8e87fc8380d73da9
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Thu Apr 21 08:53:03 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 26 07:13:52 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3174d064
7
8 Core: support DEFINED_PHASES for metadata generation
9
10 We need to retrieve names of defined functions in order to generate
11 DEFINED_PHASES. The public API is modified a bit to support it. A
12 custom test is added for metadata generation.
13
14 ---
15 Makefile.am | 13 ++++++--
16 scripts/sunpinyin-2.0.3-r1.ebuild | 32 ++++++++++++++++++++
17 scripts/sunpinyin-2.0.3-r1.ebuild.result | 25 ++++++++++++++++
18 src/core/interpreter.cpp | 7 ++++
19 src/core/interpreter.h | 2 +
20 src/libbash.cpp | 4 ++-
21 src/libbash.h | 3 +-
22 test/api_test.cpp | 3 +-
23 test/ebuild_compiler.sh | 11 +++++++
24 utils/metadata_generator.cpp | 47 ++++++++++++++++++++++++++---
25 utils/variable_printer.cpp | 3 +-
26 11 files changed, 138 insertions(+), 12 deletions(-)
27
28 diff --git a/Makefile.am b/Makefile.am
29 index 03848ed..e161fcd 100644
30 --- a/Makefile.am
31 +++ b/Makefile.am
32 @@ -23,7 +23,7 @@ include doxygen.am
33
34 ACLOCAL_AMFLAGS = -I m4
35
36 -TEST_EXTENSIONS= .gunit .bash
37 +TEST_EXTENSIONS= .gunit .bash .ebuild
38 GUNIT_LOG_COMPILER = $(srcdir)/bashast/gunit/runtests.sh
39 AM_GUNIT_LOG_FLAGS = @antlr_cp@:.
40 GUNIT_TESTS = bashast/gunit/arith_main.gunit \
41 @@ -60,7 +60,11 @@ BASH_RESULT = scripts/var_def.bash.result \
42 scripts/arithmetic_assignment.bash.result \
43 scripts/binary_arithmetic.bash.result
44
45 -TESTS = $(GUNIT_TESTS) $(BASH_TESTS)
46 +EBUILD_LOG_COMPILER = $(srcdir)/test/ebuild_compiler.sh
47 +EBUILD_TESTS = scripts/sunpinyin-2.0.3-r1.ebuild
48 +EBUILD_RESULT = scripts/sunpinyin-2.0.3-r1.ebuild.result
49 +
50 +TESTS = $(GUNIT_TESTS) $(BASH_TESTS) $(EBUILD_TESTS)
51 # these get cleaned so only add autogenerated stuff or modify CLEANFILES
52 check_JAVA = bashast/bashastLexer.java bashast/bashastParser.java
53 AM_JAVACFLAGS = -classpath @antlr_cp@
54 @@ -178,9 +182,12 @@ EXTRA_DIST = bashast/bashast.g \
55 test/verify_bashs_test.sh \
56 $(BASH_TESTS) \
57 $(BASH_RESULT) \
58 + $(EBUILD_TESTS) \
59 + $(EBUILD_RESULT) \
60 $(GUNIT_TESTS) \
61 $(GUNIT_LOG_COMPILER) \
62 - $(BASH_LOG_COMPILER)
63 + $(BASH_LOG_COMPILER) \
64 + $(EBUILD_LOG_COMPILER)
65
66 coding_standard.pdf: coding_standard/coding_standard.tex
67 $(AM_V_GEN)@PDFLATEX@ coding_standard/coding_standard.tex 2&>1 > /dev/null
68
69 diff --git a/scripts/sunpinyin-2.0.3-r1.ebuild b/scripts/sunpinyin-2.0.3-r1.ebuild
70 new file mode 100644
71 index 0000000..686121c
72 --- /dev/null
73 +++ b/scripts/sunpinyin-2.0.3-r1.ebuild
74 @@ -0,0 +1,32 @@
75 +EAPI="1"
76 +
77 +DESCRIPTION="SunPinyin is a SLM (Statistical Language Model) based IME"
78 +HOMEPAGE="http://sunpinyin.googlecode.com"
79 +SRC_URI="${HOMEPAGE}/files/${P}.tar.gz
80 + http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
81 + http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2"
82 +
83 +LICENSE="LGPL-2.1 CDDL"
84 +SLOT="0"
85 +KEYWORDS="~amd64 ~x86"
86 +IUSE=""
87 +
88 +RDEPEND="dev-db/sqlite:3"
89 +DEPEND="${RDEPEND}
90 + dev-util/pkgconfig"
91 +
92 +src_unpack() {
93 + :
94 +}
95 +
96 +src_compile() {
97 + :
98 +}
99 +
100 +src_install() {
101 + :
102 +}
103 +
104 +pkg_postinst() {
105 + :
106 +}
107
108 diff --git a/scripts/sunpinyin-2.0.3-r1.ebuild.result b/scripts/sunpinyin-2.0.3-r1.ebuild.result
109 new file mode 100644
110 index 0000000..d29858d
111 --- /dev/null
112 +++ b/scripts/sunpinyin-2.0.3-r1.ebuild.result
113 @@ -0,0 +1,25 @@
114 +dev-db/sqlite:3
115 + dev-util/pkgconfig
116 +dev-db/sqlite:3
117 +0
118 +http://sunpinyin.googlecode.com/files/.tar.gz
119 + http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
120 + http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2
121 +
122 +http://sunpinyin.googlecode.com
123 +LGPL-2.1 CDDL
124 +SunPinyin is a SLM (Statistical Language Model) based IME
125 +~amd64 ~x86
126 +
127 +
128 +
129 +
130 +
131 +1
132 +
133 +compile install postinst unpack
134 +
135 +
136 +
137 +
138 +
139
140 diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
141 index f7e8f64..c156123 100644
142 --- a/src/core/interpreter.cpp
143 +++ b/src/core/interpreter.cpp
144 @@ -31,6 +31,8 @@
145 #include <boost/algorithm/string/replace.hpp>
146 #include <boost/algorithm/string/split.hpp>
147 #include <boost/algorithm/string/trim.hpp>
148 +#include <boost/range/adaptor/map.hpp>
149 +#include <boost/range/algorithm/copy.hpp>
150
151 #include "libbashWalker.h"
152
153 @@ -163,3 +165,8 @@ void interpreter::trim_trailing_eols(std::string& value)
154 {
155 boost::trim_right_if(value, boost::is_any_of("\n"));
156 }
157 +
158 +void interpreter::get_all_function_names(std::vector<std::string>& function_names)
159 +{
160 + boost::copy(functions | boost::adaptors::map_keys, back_inserter(function_names));
161 +}
162
163 diff --git a/src/core/interpreter.h b/src/core/interpreter.h
164 index af81c49..4f69c62 100644
165 --- a/src/core/interpreter.h
166 +++ b/src/core/interpreter.h
167 @@ -523,6 +523,8 @@ public:
168 return functions.find(name) != functions.end();
169 }
170
171 + void get_all_function_names(std::vector<std::string>& function_names);
172 +
173 /// \brief execute builtin
174 /// \param builtin name
175 /// \param builtin arguments
176
177 diff --git a/src/libbash.cpp b/src/libbash.cpp
178 index 3dd03c6..0d1eadd 100644
179 --- a/src/libbash.cpp
180 +++ b/src/libbash.cpp
181 @@ -33,7 +33,8 @@
182 namespace libbash
183 {
184 void interpret(const std::string& path,
185 - std::unordered_map<std::string, std::vector<std::string>>& variables)
186 + std::unordered_map<std::string, std::vector<std::string>>& variables,
187 + std::vector<std::string>& functions)
188 {
189 std::ifstream input(path.c_str());
190 if(!input)
191 @@ -43,5 +44,6 @@ namespace libbash
192
193 for(auto iter = wbuilder.walker->begin(); iter != wbuilder.walker->end(); ++iter)
194 iter->second->get_all_values<std::string>(variables[iter->first]);
195 + wbuilder.walker->get_all_function_names(functions);
196 }
197 }
198
199 diff --git a/src/libbash.h b/src/libbash.h
200 index 01ea5e4..ca8cdaa 100644
201 --- a/src/libbash.h
202 +++ b/src/libbash.h
203 @@ -41,7 +41,8 @@ namespace libbash
204 /// \param the path of target script
205 /// \param the map to store variables
206 void LIBBASH_API interpret(const std::string& path,
207 - std::unordered_map<std::string, std::vector<std::string>>& variables);
208 + std::unordered_map<std::string, std::vector<std::string>>& variables,
209 + std::vector<std::string>& functions);
210 }
211
212 #endif
213
214 diff --git a/test/api_test.cpp b/test/api_test.cpp
215 index 14ab059..813c3b0 100644
216 --- a/test/api_test.cpp
217 +++ b/test/api_test.cpp
218 @@ -31,6 +31,7 @@ using namespace std;
219 TEST(libbashapi, bad_path)
220 {
221 std::unordered_map<std::string, std::vector<std::string>> variables;
222 - EXPECT_THROW(libbash::interpret("not exist", variables),
223 + std::vector<std::string> functions;
224 + EXPECT_THROW(libbash::interpret("not exist", variables, functions),
225 interpreter_exception);
226 }
227
228 diff --git a/test/ebuild_compiler.sh b/test/ebuild_compiler.sh
229 new file mode 100755
230 index 0000000..5930b62
231 --- /dev/null
232 +++ b/test/ebuild_compiler.sh
233 @@ -0,0 +1,11 @@
234 +#!/bin/sh
235 +
236 +declare -i error=0
237 +
238 +for ebuild in $@
239 +do
240 + ./metadata_generator $ebuild | diff -u $ebuild.result -
241 + error+=$?
242 +done
243 +
244 +exit $error
245
246 diff --git a/utils/metadata_generator.cpp b/utils/metadata_generator.cpp
247 index 9f5215d..57facb1 100644
248 --- a/utils/metadata_generator.cpp
249 +++ b/utils/metadata_generator.cpp
250 @@ -22,15 +22,36 @@
251 /// \brief a simple utility for generating metadata
252 ///
253 #include <iostream>
254 +#include <set>
255 #include <string>
256 #include <vector>
257
258 +#include <boost/spirit/include/karma.hpp>
259 +
260 #include "libbash.h"
261
262 -static std::vector<std::string> metadata_names = {"DEPEND", "RDEPEND", "SLOT", "SRC_URI",
263 - "RESTRICT", "HOMEPAGE", "LICENSE", "DESCRIPTION",
264 - "KEYWORDS", "INHERITED", "IUSE", "REQUIRED_USE",
265 - "PDEPEND", "PROVIDE", "EAPI", "PROPERTIES", "DEFINED_PHASES"};
266 +static const std::vector<std::string> metadata_names = {"DEPEND", "RDEPEND", "SLOT", "SRC_URI",
267 + "RESTRICT", "HOMEPAGE", "LICENSE", "DESCRIPTION",
268 + "KEYWORDS", "INHERITED", "IUSE", "REQUIRED_USE",
269 + "PDEPEND", "PROVIDE", "EAPI", "PROPERTIES"};
270 +
271 +static const std::unordered_map<std::string, std::string> phases = {
272 + {"pkg_pretend", "ppretend"},
273 + {"pkg_setup", "setup"},
274 + {"src_unpack", "unpack"},
275 + {"src_prepare", "prepare"},
276 + {"src_configure", "configure"},
277 + {"src_compile", "compile"},
278 + {"src_test", "test"},
279 + {"src_install", "install"},
280 + {"pkg_preinst", "preinst"},
281 + {"pkg_postinst", "postinst"},
282 + {"pkg_prerm", "prerm"},
283 + {"pkg_postrm", "postrm"},
284 + {"pkg_config", "config"},
285 + {"pkg_info", "info"},
286 + {"pkg_nofetch", "nofetch"}
287 +};
288
289 int main(int argc, char** argv)
290 {
291 @@ -41,7 +62,8 @@ int main(int argc, char** argv)
292 }
293
294 std::unordered_map<std::string, std::vector<std::string>> variables;
295 - libbash::interpret(argv[1], variables);
296 + std::vector<std::string> functions;
297 + libbash::interpret(argv[1], variables, functions);
298
299 for(auto iter_name = metadata_names.begin(); iter_name != metadata_names.end(); ++iter_name)
300 {
301 @@ -52,5 +74,20 @@ int main(int argc, char** argv)
302 std::cout << std::endl;
303 }
304
305 + // Print defined phases
306 + std::set<std::string> sorted_phases;
307 + for(auto iter = functions.begin(); iter != functions.end(); ++iter)
308 + {
309 + auto iter_phase = phases.find(*iter);
310 + if(iter_phase != phases.end())
311 + sorted_phases.insert(iter_phase->second);
312 + }
313 +
314 + using namespace boost::spirit::karma;
315 + std::cout << format(string % ' ', sorted_phases) << std::endl;
316 +
317 + // Print empty lines
318 + std::cout << std::endl << std::endl << std::endl << std::endl << std::endl;
319 +
320 return EXIT_SUCCESS;
321 }
322
323 diff --git a/utils/variable_printer.cpp b/utils/variable_printer.cpp
324 index ed4aa69..192b3db 100644
325 --- a/utils/variable_printer.cpp
326 +++ b/utils/variable_printer.cpp
327 @@ -41,7 +41,8 @@ int main(int argc, char** argv)
328 }
329
330 std::unordered_map<std::string, std::vector<std::string>> variables;
331 - libbash::interpret(argv[1], variables);
332 + std::vector<std::string> functions;
333 + libbash::interpret(argv[1], variables, functions);
334
335 std::map<std::string, std::vector<std::string>> sorted(variables.begin(), variables.end());
336 // Currently we don't need internal variables