Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/crossdev:master commit in: /
Date: Wed, 29 Feb 2012 16:22:45
Message-Id: 1330449636.c0d8915eefa7f334f3912440016f50bd0b32995e.vapier@gentoo
commit:     c0d8915eefa7f334f3912440016f50bd0b32995e
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 28 17:20:36 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Tue Feb 28 17:20:36 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/crossdev.git;a=commit;h=c0d8915e

crossdev: output config in a shell-evalable style

Should simplify scripts trying to parse this as now they can do:
	eval $(crossdev --show-target-cfg ...); echo $foo

Rather than manually parsing like:
	foo=$(crossdev --show-target-cfg ... | awk '$1 == "foo" { print $NF }')

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 crossdev |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/crossdev b/crossdev
index 50a523e..68389d5 100755
--- a/crossdev
+++ b/crossdev
@@ -537,7 +537,7 @@ for with in HEADERS ; do
 done
 
 show_target_cfg() {
-	local pkgs
+	local pkgs crosspkgs=()
 
 	pkgs=(
 		binutils B
@@ -547,18 +547,27 @@ show_target_cfg() {
 	)
 	ex_gdb && pkgs+=( gdb D )
 
-	echo "arch ${TARCH}"
-	echo "target ${CTARGET}"
-	echo "category cross-${CTARGET}"
+	echo "arch=${TARCH}"
+	echo "target=${CTARGET}"
+	echo "category=cross-${CTARGET}"
 	while [[ ${#pkgs[@]} -gt 0 ]] ; do
-		local vcat="${pkgs[1]}CAT"
-		local vpkg="${pkgs[1]}PKG"
+		local pkg=${pkgs[0]}
+		local v=${pkgs[1]}
+		local vcat="${v}CAT"
+		local vpkg="${v}PKG"
+		local ocat="${pkg}_category"
+		local opkg="${pkg}_pn"
 
 		if [[ ${!vpkg} != "[none]" ]] ; then
-			echo "${pkgs[0]} ${!vcat} ${!vpkg}"
+			echo "${ocat}=${!vcat}"
+			echo "${opkg}=${!vpkg}"
+		else
+			printf '%s=\n' "${ocat}" "${opkg}"
 		fi
+		crosspkgs+=( ${pkg} )
 		pkgs=( ${pkgs[@]:2} )
 	done
+	echo "crosspkgs='${crosspkgs[*]}'"
 
 	exit 0
 }