public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH 1/3] Introduce eqatag to output proper machine-readable QA logs
@ 2014-11-02 19:18 Michał Górny
  2014-11-02 19:18 ` [gentoo-portage-dev] [PATCH 2/3] Update the QA checks to new eqatag API Michał Górny
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michał Górny @ 2014-11-02 19:18 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

The eqatag command syntax conforms to pre-GLEP describing
install-qa-check.d. The qa.log file format strictly conforms to YAML for
easy machine parsing.
---
 bin/isolated-functions.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++++
 bin/misc-functions.sh     |  4 +++
 bin/save-ebuild-env.sh    |  2 +-
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 4992d77..f03503b 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -505,4 +505,72 @@ __repo_attr() {
 	return ${exit_status}
 }
 
+# eqaquote <string>
+#
+# outputs parameter escaped for quoting
+__eqaquote() {
+	local v=${1} esc=''
+
+	# quote backslashes
+	v=${v//\\/\\\\}
+	# quote the quotes
+	v=${v//\"/\\\"}
+	# quote newlines
+	while read -r; do
+		echo -n "${esc}${REPLY}"
+		esc='\n'
+	done <<<"${v}"
+}
+
+# eqatag <tag> [-v] [<key>=<value>...] [/<relative-path>...]
+#
+# output (to qa.log):
+# - tag: <tag>
+#   data:
+#     <key1>: "<value1>"
+#     <key2>: "<value2>"
+#   files:
+#     - "<path1>"
+#     - "<path2>"
+__eqatag() {
+	local tag i filenames=() data=() verbose=
+
+	if [[ ${1} == -v ]]; then
+		verbose=1
+		shift
+	fi
+
+	tag=${1}
+	shift
+	[[ -n ${tag} ]] || die "${FUNCNAME}: no tag specified"
+
+	# collect data & filenames
+	for i; do
+		if [[ ${i} == /* ]]; then
+			filenames+=( "${i}" )
+			[[ -n ${verbose} ]] && eqawarn "  ${i}"
+		elif [[ ${i} == *=* ]]; then
+			data+=( "${i}" )
+		else
+			die "${FUNCNAME}: invalid parameter: ${i}"
+		fi
+	done
+
+	(
+		echo "- tag: ${tag}"
+		if [[ ${data[@]} ]]; then
+			echo "  data:"
+			for i in "${data[@]}"; do
+				echo "    ${i%%=*}: \"$(__eqaquote "${i#*=}")\""
+			done
+		fi
+		if [[ ${filenames[@]} ]]; then
+			echo "  files:"
+			for i in "${filenames[@]}"; do
+				echo "    - \"$(__eqaquote "${i}")\""
+			done
+		fi
+	) >> "${T}"/qa.log
+}
+
 true
diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index cc652a9..6e6fcb4 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -551,6 +551,10 @@ install_hooks() {
 	return $ret
 }
 
+eqatag() {
+	__eqatag "${@}"
+}
+
 if [ -n "${MISC_FUNCTIONS_ARGS}" ]; then
 	__source_all_bashrcs
 	[ "$PORTAGE_DEBUG" == "1" ] && set -x
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
index dd233a9..eb83dca 100644
--- a/bin/save-ebuild-env.sh
+++ b/bin/save-ebuild-env.sh
@@ -76,7 +76,7 @@ __save_ebuild_env() {
 		__ebuild_arg_to_phase __ebuild_phase_funcs default \
 		__unpack_tar __unset_colors \
 		__source_env_files __try_source \
-		__eqalog __eqawarnlog \
+		__eqalog __eqawarnlog __eqatag \
 		${QA_INTERCEPTORS}
 
 	___eapi_has_usex && unset -f usex
-- 
2.1.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-03  0:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-02 19:18 [gentoo-portage-dev] [PATCH 1/3] Introduce eqatag to output proper machine-readable QA logs Michał Górny
2014-11-02 19:18 ` [gentoo-portage-dev] [PATCH 2/3] Update the QA checks to new eqatag API Michał Górny
2014-11-02 19:18 ` [gentoo-portage-dev] [PATCH 3/3] Remove __eqalog & __eqawarnlog Michał Górny
2014-11-03  0:05 ` [gentoo-portage-dev] [PATCH 1/3] Introduce eqatag to output proper machine-readable QA logs Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox