querying arbitrary variables via `port info --var`

René J.V. Bertin rjvbertin at gmail.com
Wed Oct 28 08:39:57 PDT 2015


On Monday October 26 2015 16:22:51 Ryan Schmidt wrote:

> A port might do things in its pre-configure or pre-build phases that work on the files in the work directory. For example, it might copy a file, or compile a file. These operations would fail if you're just trying to get info about the port, because the work directory wouldn't exist.

True. 
Then again, the variables that are currently exported for use with --info can also be modified in a pre- phase. A catch-22, it seems :)

> Look at the following procedures in src/port1.0/portutil.tcl:
> 
> handle_option
> handle_option-append
> handle_option-prepend
> handle_option-delete
> handle_option-strsed
> handle_option-replace

I'd have found those myself, promised :)
That same file also defines the options_export procedure, so I now have a rough working prototype that calls `options_export $option` in the procedures cited above. With the code copied below in action_info in bin/port, I can now query any predefined variable set or modified through those procedures:

            } elseif {$opt eq "var"} {
                if {[info exists global_options(ports_info_var)]} {
                    set opt ${global_options(ports_info_var)}
                    set ropt $opt
                    if {[info exists portinfo($opt)]} {
                        set inf "$portinfo($opt)"
                    } else {
                        ui_error "variable \"$opt\" cannot be queried via info --var"
                        return 1
                    }
                } else {
                    ui_error "info --var requires a variable name"
                    return 1
                }
            }

As to changes made to the configure arguments in a pre-configure phase: I've already mentioned once before that I'd find it useful if the exact configure command were dumped to a dedicated file in `port work` rather than only in `port logfile`.

Cheers,
R.



More information about the macports-dev mailing list