Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o, kentnl@g.o
Cc: vapier@g.o, tools-portage@g.o, Kent Fredric <kentnl@g.o>
Subject: Re: [gentoo-dev] [PATCH] app-portage/eclass-manpages: Add support for @OUTPUT
Date: Mon, 01 May 2017 10:11:42
Message-Id: F9F371BB-5D50-46DC-A0FB-C11E2EFD503A@gentoo.org
In Reply to: [gentoo-dev] [PATCH] app-portage/eclass-manpages: Add support for @OUTPUT by kentnl@gentoo.org
1 Dnia 30 kwietnia 2017 23:36:46 CEST, kentnl@g.o napisał(a):
2 >From: Kent Fredric <kentnl@g.o>
3 >
4 >@RETURNS is abused presently both as bash exit code values ( that
5 >is, bash return values ), and capturable STOUT values.
6 >
7 >This is problematic, as they're not equivalent: One is passed
8 >around via $? , and the other requires VAR=$(func) to capture.
9 >
10 >Additionally, functions can have both output, and return values,
11 >and both can be used together.
12 >
13 >For example:
14 >
15 > function get_thing_version() {
16 > if [[ "${FAIL}" ]]; then
17 > echo "libthing not installed"
18 > return 1
19 > fi
20 > echo "1.0"
21 > return 0
22 > }
23 >
24 > # this line works and MYVAR gets "1.0"
25 > # and does not die
26 > MYVAR=$(get_thing_version) \
27 > || die "Can't get thing version, ${MYVAR}"
28 >
29 > # This dies with the error message communicated from the
30 > # function
31 > FAIL=1
32 > MYVAR=$(get_thing_version) \
33 > || die "Can't get thing version, ${MYVAR}"
34 >
35 >Hence, a reasonable documentation for a function like this would
36 >be:
37 >
38 >@OUTPUT: version of thing when present, explanation of cause for thing
39 >missing otherwise
40 > @RETURN: 0 on success, non-zero otherwise
41 >
42 >Package-Manager: Portage-2.3.4, Repoman-2.3.2
43 >---
44 > app-portage/eclass-manpages/files/eclass-to-manpage.awk | 9 +++++++++
45 > 1 file changed, 9 insertions(+)
46 >
47 >diff --git a/app-portage/eclass-manpages/files/eclass-to-manpage.awk
48 >b/app-portage/eclass-manpages/files/eclass-to-manpage.awk
49 >index 0b65162c04..0d41f96327 100644
50 >--- a/app-portage/eclass-manpages/files/eclass-to-manpage.awk
51 >+++ b/app-portage/eclass-manpages/files/eclass-to-manpage.awk
52 >@@ -27,6 +27,7 @@
53 > # The format of functions:
54 > # @FUNCTION: foo
55 > # @USAGE: <required arguments to foo> [optional arguments to foo]
56 >+# @OUTPUT: <values emitted to STDOUT>
57 > # @RETURN: <whatever foo returns>
58 > # @MAINTAINER:
59 > # <optional; list of contacts, one per line>
60 >@@ -217,6 +218,7 @@ function show_function_header() {
61 > function handle_function() {
62 > func_name = $3
63 > usage = ""
64 >+ funcout = ""
65 > funcret = ""
66 > maintainer = ""
67 > internal = 0
68 >@@ -231,6 +233,8 @@ function handle_function() {
69 > getline
70 > if ($2 == "@USAGE:")
71 > usage = eat_line()
72 >+ if ($2 == "@OUTPUT:")
73 >+ funcout = eat_line()
74 > if ($2 == "@RETURN:")
75 > funcret = eat_line()
76 > if ($2 == "@MAINTAINER:")
77 >@@ -257,6 +261,11 @@ function handle_function() {
78 > print ""
79 > print "Return value: " funcret
80 > }
81 >+ if (funcout != "") {
82 >+ if (desc !="")
83 >+ print ""
84 >+ print "Outputs: " funcout
85 >+ }
86
87 Move this above return value. Functions usually output before returning.
88
89 >
90 > if (blurb == "")
91 > fail(func_name ": no @BLURB found")
92
93
94 --
95 Best regards,
96 Michał Górny (by phone)