Skip to content

Commit f06618a

Browse files
committed
base: add ui_debug[1-3]
1 parent f9f1a33 commit f06618a

10 files changed

Lines changed: 88 additions & 5 deletions

File tree

doc/port.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ Verbose mode, generates verbose messages
448448
Debug mode, generate debugging messages, implies \-v
449449
.RE
450450
.PP
451+
\-dlevel
452+
.RS 4
453+
Debug mode, generate debugging messages at specified level, implies \-v
454+
.RE
455+
.PP
451456
\-q
452457
.RS 4
453458
Quiet mode, suppress informational messages to a minimum, implies \-N

doc/port.1.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ The port command recognizes several global flags and options.
127127
-d::
128128
Debug mode, generate debugging messages, implies -v
129129
130+
-dlevel::
131+
Debug mode, generate debugging messages at specified level, implies -v
132+
130133
-q::
131134
Quiet mode, suppress informational messages to a minimum, implies -N
132135

src/macports1.0/macports.tcl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,21 @@ proc macports::ui_prefix_default {priority} {
339339
# ui_options(ports_verbose) - If set, output info messages (ui_info)
340340
# ui_options(ports_quiet) - If set, don't output "standard messages"
341341
proc macports::ui_channels_default {priority} {
342-
switch -- $priority {
342+
switch -regexp -- $priority {
343343
debug {
344344
if {[ui_isset ports_debug]} {
345345
return stderr
346346
} else {
347347
return {}
348348
}
349349
}
350+
debug[0-9] {
351+
if {[ui_isset ports_debug_x] && (${priority} le ${ports_debug_x})} {
352+
return stderr
353+
} else {
354+
return {}
355+
}
356+
}
350357
info {
351358
if {[ui_isset ports_verbose]} {
352359
return stdout

src/pextlib1.0/Pextlib.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ static void ui_message(Tcl_Interp *interp, const char *severity, const char *for
135135
free(tclcmd);
136136
}
137137

138+
__attribute__((format(printf, 3, 0)))
139+
static void ui_debug_x(Tcl_Interp *interp, unsigned int level, const char *format, va_list va) {
140+
char cLevel[20]; // longer than necessary, but also safer
141+
142+
sprintf(cLevel, "debug%u", level);
143+
ui_message(interp, cLevel, format, va);
144+
}
145+
138146
__attribute__((format(printf, 2, 3)))
139147
void ui_error(Tcl_Interp *interp, const char *format, ...) {
140148
va_list va;
@@ -187,6 +195,33 @@ void ui_debug(Tcl_Interp *interp, const char *format, ...) {
187195
va_end(va);
188196
}
189197

198+
__attribute__((format(printf, 2, 3)))
199+
void ui_debug1(Tcl_Interp *interp, const char *format, ...) {
200+
va_list va;
201+
202+
va_start(va, format);
203+
ui_debug_x(interp, 1 /*debug level*/, format, va);
204+
va_end(va);
205+
}
206+
207+
__attribute__((format(printf, 2, 3)))
208+
void ui_debug2(Tcl_Interp *interp, const char *format, ...) {
209+
va_list va;
210+
211+
va_start(va, format);
212+
ui_debug_x(interp, 2 /*debug level*/, format, va);
213+
va_end(va);
214+
}
215+
216+
__attribute__((format(printf, 2, 3)))
217+
void ui_debug3(Tcl_Interp *interp, const char *format, ...) {
218+
va_list va;
219+
220+
va_start(va, format);
221+
ui_debug_x(interp, 3 /*debug level*/, format, va);
222+
va_end(va);
223+
}
224+
190225
int StrsedCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
191226
{
192227
char *pattern, *string, *res;

src/pextlib1.0/Pextlib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void ui_msg(Tcl_Interp *interp, const char *format, ...) __attribute__((format(p
3535
void ui_notice(Tcl_Interp *interp, const char *format, ...) __attribute__((format(printf, 2, 3)));
3636
void ui_info(Tcl_Interp *interp, const char *format, ...) __attribute__((format(printf, 2, 3)));
3737
void ui_debug(Tcl_Interp *interp, const char *format, ...) __attribute__((format(printf, 2, 3)));
38+
void ui_debug1(Tcl_Interp *interp, const char *format, ...) __attribute__((format(printf, 2, 3)));
39+
void ui_debug2(Tcl_Interp *interp, const char *format, ...) __attribute__((format(printf, 2, 3)));
40+
void ui_debug3(Tcl_Interp *interp, const char *format, ...) __attribute__((format(printf, 2, 3)));
3841

3942
/* Mount point file system case-sensitivity caching infrastructure. */
4043
typedef struct _mount_cs_cache mount_cs_cache_t;

src/pextlib1.0/tests/system.tcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ set failures 0
1212
proc ui_debug {args} {
1313
# ignored
1414
}
15+
proc ui_debug1 {args} {
16+
# ignored
17+
}
18+
proc ui_debug2 {args} {
19+
# ignored
20+
}
21+
proc ui_debug3 {args} {
22+
# ignored
23+
}
1524
proc ui_info {args} {
1625
global output
1726
append output "$args\n"

src/port/port.tcl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ package require Pextlib 1.0
5050
proc print_usage {{verbose 1}} {
5151
global cmdname
5252
set syntax {
53-
[-bcdfknNopqRstuvy] [-D portdir|portname] [-F cmdfile] action [actionflags]
53+
[-bcdfknNopqRstuvy] [-d[level]] [-D portdir|portname] [-F cmdfile] action [actionflags]
5454
[[portname|pseudo-portname|port-url] [@version] [+-variant]... [option=value]...]...
5555
}
5656

@@ -4568,7 +4568,7 @@ proc parse_options { action ui_options_name global_options_name } {
45684568
# Process short arg(s)
45694569
set opts [string range $arg 1 end]
45704570
foreach c [split $opts {}] {
4571-
switch -- $c {
4571+
switch -regexp -- $c {
45724572
v {
45734573
set ui_options(ports_verbose) yes
45744574
}
@@ -4577,6 +4577,19 @@ proc parse_options { action ui_options_name global_options_name } {
45774577
# debug implies verbose
45784578
set ui_options(ports_verbose) yes
45794579
}
4580+
[0-3] {
4581+
#d[0-3]
4582+
# TEMP HACK: Since args processed char-by-char, just use numeric for now
4583+
set ui_options(ports_debug) yes
4584+
# debug implies verbose
4585+
set ui_options(ports_verbose) yes
4586+
4587+
#set debug_level [regsub {d(\d)} ${c} {\1}]
4588+
#set ui_options(ports_debug_x) "debug${debug_level}"
4589+
#unset debug_level
4590+
4591+
set ui_options(ports_debug_x) "debug${c}"
4592+
}
45804593
q {
45814594
set ui_options(ports_quiet) yes
45824595
# quiet implies noninteractive

src/port/portindex.tcl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ for {set i 0} {$i < $argc} {incr i} {
197197
{^-.+} {
198198
if {$arg eq "-d"} { # Turn on debug output
199199
set ui_options(ports_debug) yes
200+
elseif {[regexp {\-d[0-3]} ${arg}] == 1} { # Turn on debugX output
201+
set ui_options(ports_debug) yes
202+
203+
set debug_level [regsub {\-d(\d)} ${arg} {\1}]
204+
set ui_options(ports_debug_x) "debug${debug_level}"
205+
unset debug_level
200206
} elseif {$arg eq "-o"} { # Set output directory
201207
incr i
202208
set outdir [file join [pwd] [lindex $argv $i]]

src/port1.0/port.tcl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ namespace eval port {
5454
proc run_callbacks {} {
5555
variable _callback_list
5656
foreach callback ${_callback_list} {
57+
#ui_debug1 "Running callback ${callback}"
5758
ui_debug "Running callback ${callback}"
5859
${callback}
60+
#ui_debug1 "Finished running callback ${callback}"
5961
ui_debug "Finished running callback ${callback}"
6062
}
6163
set _callback_list [list]

src/port1.0/portutil.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,7 @@ proc PortGroup {group version} {
26072607
if {[file exists $groupFile]} {
26082608
lappend PortInfo(portgroups) [list $group $version $groupFile]
26092609
uplevel "source $groupFile"
2610-
ui_debug "Sourcing PortGroup $group $version from $groupFile"
2610+
ui_debug1 "Sourcing PortGroup $group $version from $groupFile"
26112611
return
26122612
}
26132613
}
@@ -2618,7 +2618,7 @@ proc PortGroup {group version} {
26182618
if {[file exists $groupFile]} {
26192619
lappend PortInfo(portgroups) [list $group $version $groupFile]
26202620
uplevel "source $groupFile"
2621-
ui_debug "Sourcing PortGroup $group $version from $groupFile"
2621+
ui_debug1 "Sourcing PortGroup $group $version from $groupFile"
26222622
} else {
26232623
ui_error "${subport}: PortGroup ${group} ${version} could not be located. ${group}-${version}.tcl does not exist."
26242624
return -code error "PortGroup not found"

0 commit comments

Comments
 (0)