Skip to content

Commit

Permalink
Update all options for each action
Browse files Browse the repository at this point in the history
This makes single-letter options work correctly when used after the
action name, which users often expect.

Previously, the set of options used internal to the macports API was
fixed at the time mportinit was called. This adds a way to update them
later.
  • Loading branch information
jmroot committed Nov 7, 2023
1 parent 01f5c5d commit aec0601
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
58 changes: 52 additions & 6 deletions src/macports1.0/macports.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ proc macports::ui_isset {val} {
return 0
}

# Return all current ui options
proc macports::get_ui_options {} {
return [array get macports::ui_options]
}
# Set all ui options
# Takes a value previously returned by get_ui_options
proc macports::set_ui_options {opts} {
global macports::ui_options
array unset macports::ui_options
array set macports::ui_options $opts
# This is also a config file option, so needs special handling
if {[info exists macports::ui_options(ports_verbose)]} {
set macports::portverbose $macports::ui_options(ports_verbose)
} else {
set macports::portverbose $macports::portverbose_frozen
}
}


# global_options accessor
proc macports::global_option_isset {val} {
Expand All @@ -134,6 +152,27 @@ proc macports::global_option_isset {val} {
return 0
}

# Return all current global options
proc macports::get_global_options {} {
return [array get macports::global_options]
}
# Set all global options
# Takes a value previously returned by get_global_options
proc macports::set_global_options {opts} {
global macports::global_options
array unset macports::global_options
array set macports::global_options $opts
# Options that can also be set in the config file need special handling
foreach {opt var} {ports_autoclean portautoclean ports_trace porttrace} {
if {[info exists macports::global_options($opt)]} {
set macports::$var $macports::global_options($opt)
} else {
set macports::$var [set macports::${var}_frozen]
}
}
}


proc macports::init_logging {mport} {
if {[getuid] == 0 && [geteuid] != 0} {
seteuid 0; setegid 0
Expand Down Expand Up @@ -293,14 +332,20 @@ proc ui_message {priority prefix args} {
}
}

# Init (or re-init) all ui channels
proc macports::ui_init_all {} {
foreach priority $macports::ui_priorities {
ui_init $priority
}
}

proc macports::ui_init {priority args} {
global macports::channels
set default_channel [macports::ui_channels_default $priority]
# Get the list of channels.
if {[llength [info commands ui_channels]] > 0} {
set channels($priority) [ui_channels $priority]
} else {
set channels($priority) $default_channel
set channels($priority) [macports::ui_channels_default $priority]
}

# Simplify ui_$priority.
Expand Down Expand Up @@ -664,10 +709,8 @@ proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
upvar $up_variations variations
}

# Initialize ui_*
foreach priority $macports::ui_priorities {
macports::ui_init $priority
}
# Initialize ui_* channels
macports::ui_init_all

package require Pextlib 1.0
package require registry 1.0
Expand Down Expand Up @@ -984,6 +1027,7 @@ Please edit sources.conf and change '$url' to '[string range $url 0 end-6]tarbal
set macports::portautoclean yes
global macports::portautoclean
}
set macports::portautoclean_frozen $portautoclean
# whether to keep logs after successful builds
if {![info exists keeplogs]} {
set macports::keeplogs no
Expand All @@ -1001,6 +1045,7 @@ Please edit sources.conf and change '$url' to '[string range $url 0 end-6]tarbal
set macports::porttrace no
global macports::porttrace
}
set macports::porttrace_frozen $porttrace
# Check command line override for trace
if {[info exists macports::global_options(ports_trace)]} {
if {$macports::global_options(ports_trace) ne $porttrace} {
Expand Down Expand Up @@ -1042,6 +1087,7 @@ Please edit sources.conf and change '$url' to '[string range $url 0 end-6]tarbal
set macports::portverbose no
global macports::portverbose
}
set macports::portverbose_frozen $portverbose
if {[info exists macports::ui_options(ports_verbose)]} {
if {$macports::ui_options(ports_verbose) ne $portverbose} {
set macports::portverbose $macports::ui_options(ports_verbose)
Expand Down
24 changes: 23 additions & 1 deletion src/port/port.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -4749,7 +4749,9 @@ proc lock_reg_if_needed {action} {

proc process_cmd { argv } {
global cmd_argc cmd_argv cmd_argn \
global_options global_options_base private_options ui_options \
global_options global_options_base private_options \
ui_options ui_options_base \
mp_global_options_base mp_ui_options_base \
current_portdir
set cmd_argv $argv
set cmd_argc [llength $argv]
Expand Down Expand Up @@ -4788,6 +4790,8 @@ proc process_cmd { argv } {
# Reset global_options from base before each action, as we munge it just below...
array unset global_options
array set global_options $global_options_base
array unset ui_options
array set ui_options $ui_options_base

# Find an action to execute
set actions [find_action $action]
Expand All @@ -4814,6 +4818,20 @@ proc process_cmd { argv } {
break
}

# Merge new options into the macports API options
array unset mp_global_options
array set mp_global_options $mp_global_options_base
array set mp_global_options [array get global_options]
macports::set_global_options [array get mp_global_options]

array unset mp_ui_options
array set mp_ui_options $mp_ui_options_base
array set mp_ui_options [array get ui_options]
macports::set_ui_options [array get mp_ui_options]

# Some options could change verbosity, so re-init ui channels
macports::ui_init_all

# What kind of arguments does the command expect?
set expand [action_needs_portlist $action]

Expand Down Expand Up @@ -5881,6 +5899,10 @@ set current_portdir [pwd]
# Freeze global_options into global_options_base; global_options
# will be reset to global_options_base prior to processing each command.
set global_options_base [array get global_options]
set ui_options_base [array get ui_options]
# Also save those used by the macports API
set mp_global_options_base [macports::get_global_options]
set mp_ui_options_base [macports::get_ui_options]

# First process any remaining args as action(s)
set exit_status 0
Expand Down
2 changes: 1 addition & 1 deletion src/port1.0/portchecksum.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ proc portchecksum::checksum_start {args} {
# Target main procedure. Verifies the checksums of all distfiles.
#
proc portchecksum::checksum_main {args} {
global UI_PREFIX all_dist_files checksums_array portverbose checksum.skip
global UI_PREFIX all_dist_files checksums_array checksum.skip

# If no files have been downloaded, there is nothing to checksum.
if {![info exists all_dist_files]} {
Expand Down

0 comments on commit aec0601

Please sign in to comment.