Since variables in a .cygport file can be computed from arbitrary shell
expressions, perhaps containing variables that cygport itself defines,
other programs can't determine their value just by parsing the .cygport
file.

Add 'vars' command to output arbitrary variables defined by the .cygport
file.

The idea is that the output from this should be eval-able in a shell to
be further used, but it probably needs some additional escaping (of
newlines?) to be completely right in all cases.

e.g

> $ cygport libX11.cygport vars PVR BUILD_REQUIRES
> PVR='1.7.1-1'
> BUILD_REQUIRES='xtrans xorgproto libxcb-devel xmlto xorg-sgml-doctools 
> docbook-xml43'

> eval $(cygport libX11.cygport vars BUILD_REQUIRES) ; for r in 
> ${BUILD_REQUIRES} ; do echo $r; done
> xtrans
> xorgproto
> libxcb-devel
> xmlto
> xorg-sgml-doctools
> docbook-xml43
---

Notes:
    This is a generalization of the idea in [1], for querying the
    build-depends of a package.
    
    https://cygwin.com/pipermail/cygwin-apps/2021-January/041006.html

 bin/cygport.in               |  5 +++++
 data/cygport-bash-completion |  2 +-
 lib/pkg_info.cygpart         | 10 +++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/bin/cygport.in b/bin/cygport.in
index afc6f7e..e9295be 100755
--- a/bin/cygport.in
+++ b/bin/cygport.in
@@ -623,6 +623,11 @@ do
                        __show_info;
                        _status=$?;
                        ;;
+               vars)
+                       __show_vars ${argv[@]:$((++arg_n))};
+                       _status=$?;
+                       arg_n=$argc;  # consumed all remaining args
+                       ;;
                homepage|web*|www*)
                        __show_web;
                        _status=$?;
diff --git a/data/cygport-bash-completion b/data/cygport-bash-completion
index 86df238..9085e19 100644
--- a/data/cygport-bash-completion
+++ b/data/cygport-bash-completion
@@ -12,7 +12,7 @@ _cygport()
                check test inst install list dep depends \
                package pkg package-test pkg-test diff mkdiff mkpatch \
                upload stage announce almostall all all-test clean finish \
-               help info version homepage website'
+               help info version homepage website vars'
 
        if [[ $COMP_CWORD -eq 1 ]] ; then
                # first arg: source file completion
diff --git a/lib/pkg_info.cygpart b/lib/pkg_info.cygpart
index 4b18993..a5475cc 100644
--- a/lib/pkg_info.cygpart
+++ b/lib/pkg_info.cygpart
@@ -658,5 +658,13 @@ __show_web() {
        ${mybrowser} ${mywww} &>/dev/null &
 }
 
+__show_vars() {
+       for v in "$@"
+       do
+               echo "${v}='${!v}'"
+       done
+}
+
 readonly -f __list_files __list_debug_files __list_deps \
-           __show_deps __show_info __show_web __pager
+           __show_deps __show_info __show_web __pager \
+           __show_vars
-- 
2.31.1

Reply via email to