-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
port.tcl
executable file
·5805 lines (5095 loc) · 198 KB
/
port.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!@TCLSH@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
#
# Copyright (c) 2004-2016 The MacPorts Project
# Copyright (c) 2004 Robert Shaw <rshaw@opendarwin.org>
# Copyright (c) 2002-2003 Apple Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Create a namespace for some local variables
namespace eval portclient::progress {
##
# Indicate whether the term::ansi::send tcllib package is available and was
# imported. "yes", if the package is available, "no" otherwise.
variable hasTermAnsiSend no
}
if {![catch {package require term::ansi::send}]} {
set portclient::progress::hasTermAnsiSend yes
}
package require Tclx
package require macports
package require Pextlib 1.0
# Standard procedures
proc print_usage {{verbose 1}} {
global cmdname
set syntax {
[-bcdfknopqRstuvy] [-D portdir] [-F cmdfile] action [privopts] [actionflags]
[[portname|pseudo-portname|port-url] [@version] [+-variant]... [option=value]...]...
}
if {$verbose} {
puts stderr "Usage: $cmdname$syntax"
puts stderr "\"$cmdname help\" or \"man 1 port\" for more information."
} else {
puts stderr "$cmdname$syntax"
}
}
proc print_help {args} {
global action_array
print_usage 0
# Generate and format the command list from the action_array
set cmds ""
set lineLen 0
foreach cmd [lsort [array names action_array]] {
if {$lineLen > 65} {
set cmds "$cmds,\n"
set lineLen 0
}
if {$lineLen == 0} {
set new "$cmd"
} else {
set new ", $cmd"
}
incr lineLen [string length $new]
set cmds "$cmds$new"
}
set cmdText "Supported actions
------------------
$cmds
"
set text {
Pseudo-portnames
----------------
Pseudo-portnames are words that may be used in place of a portname, and
which expand to some set of ports. The common pseudo-portnames are:
all, current, active, inactive, actinact, installed, uninstalled, outdated,
obsolete, requested, unrequested and leaves.
These pseudo-portnames expand to the set of ports named.
Pseudo-portnames starting with variants:, variant:, description:, depends:,
depends_lib:, depends_run:, depends_build:, depends_fetch:, depends_extract:,
depends_test:,
portdir:, homepage:, epoch:, platforms:, platform:, name:, long_description:,
maintainers:, maintainer:, categories:, category:, version:, revision:, and
license: each select a set of ports based on a regex search of metadata
about the ports. In all such cases, a standard regex pattern following
the colon will be used to select the set of ports to which the
pseudo-portname expands.
Pseudo-portnames starting with depof:, rdepof:, rdepends:, dependentof:, and
rdependentof: select ports that are direct or recursive dependencies or
dependents of the following portname, respectively.
Portnames that contain standard glob characters will be expanded to the
set of ports matching the glob pattern.
Port expressions
----------------
Portnames, port glob patterns, and pseudo-portnames may be logically
combined using expressions consisting of and, or, not, !, (, and ).
For more information
--------------------
See man pages: port(1), macports.conf(5), portfile(7), portgroup(7),
porthier(7), portstyle(7). Also, see https://www.macports.org.
}
puts "$cmdText$text"
}
# Produce error message and exit
proc fatal s {
global argv0
ui_error "$argv0: $s"
exit 1
}
##
# Helper function to define constants
#
# Constants defined with const can simply be accessed in the same way as
# calling a proc.
#
# Example:
# const FOO 42
# puts [FOO]
#
# @param name variable name
# @param value constant variable value
proc const {name args} {
proc $name {} [list return [expr $args]]
}
# Produce an error message, and exit, unless
# we're handling errors in a soft fashion, in which
# case we continue
proc fatal_softcontinue s {
if {[macports::global_option_isset ports_force]} {
ui_error $s
return -code continue
} else {
fatal $s
}
}
# Produce an error message, and break, unless
# we're handling errors in a soft fashion, in which
# case we continue
proc break_softcontinue { msg status name_status } {
upvar $name_status status_var
ui_error $msg
if {[macports::ui_isset ports_processall]} {
set status_var 0
return -code continue
} else {
set status_var $status
return -code break
}
}
# show the URL for the ticket reporting instructions
proc print_tickets_url {args} {
if {${macports::prefix} ne "/usr/local" && ${macports::prefix} ne "/usr"} {
ui_error "Follow https://guide.macports.org/#project.tickets to report a bug."
}
}
# Form a composite version as is sometimes used for registry functions
# This function sorts the variants and presents them in a canonical representation
proc composite_version {version variations {emptyVersionOkay 0}} {
# Form a composite version out of the version and variations
# Select the variations into positive and negative
set pos {}
set neg {}
foreach { key val } $variations {
if {$val eq "+"} {
lappend pos $key
} elseif {$val eq "-"} {
lappend neg $key
}
}
# If there is no version, we have nothing to do
set composite_version ""
if {$version ne "" || $emptyVersionOkay} {
set pos_str ""
set neg_str ""
if {[llength $pos]} {
set pos_str "+[join [lsort -ascii $pos] "+"]"
}
if {[llength $neg]} {
set neg_str "-[join [lsort -ascii $neg] "-"]"
}
set composite_version "$version$pos_str$neg_str"
}
return $composite_version
}
proc split_variants {variants} {
set result {}
set l [regexp -all -inline -- {([-+])([[:alpha:]_]+[\w\.]*)} $variants]
foreach { match sign variant } $l {
lappend result $variant $sign
}
return $result
}
##
# Maps friendly field names to their real name
# Names which do not need mapping are not changed.
#
# @param field friendly name
# @return real name
proc map_friendly_field_names { field } {
switch -- $field {
variant -
platform -
maintainer -
subport {
set field "${field}s"
}
category {
set field "categories"
}
}
return $field
}
proc registry_installed {portname {portversion ""}} {
set ilist [registry::installed $portname $portversion]
if { [llength $ilist] > 1 } {
# set portname again since the one we were passed may not have had the correct case
set portname [lindex $ilist 0 0]
ui_notice "The following versions of $portname are currently installed:"
foreach i [portlist_sortint $ilist] {
set iname [lindex $i 0]
set iversion [lindex $i 1]
set irevision [lindex $i 2]
set ivariants [lindex $i 3]
set iactive [lindex $i 4]
if { $iactive == 0 } {
puts " $iname @${iversion}_${irevision}${ivariants}"
} elseif { $iactive == 1 } {
puts " $iname @${iversion}_${irevision}${ivariants} (active)"
}
}
return -code error "Registry error: Please specify the full version as recorded in the port registry."
} else {
return [lindex $ilist 0]
}
}
proc entry_for_portlist {portentry} {
global global_options
# Each portlist entry currently has the following elements in it:
# url if any
# name
# version (version_revision)
# variants array (variant=>+-)
# requested_variants array (variant=>+-)
# options array (key=>value)
# fullname (name/version_revision+-variants)
array set port $portentry
if {![info exists port(url)]} { set port(url) "" }
if {![info exists port(name)]} { set port(name) "" }
if {![info exists port(version)]} { set port(version) "" }
if {![info exists port(variants)]} { set port(variants) "" }
if {![info exists port(requested_variants)]} { set port(requested_variants) "" }
if {![info exists port(options)]} { set port(options) [array get global_options] }
# If neither portname nor url is specified, then default to the current port
if { $port(url) eq "" && $port(name) eq "" } {
set url file://.
set portname [url_to_portname $url]
set port(url) $url
set port(name) $portname
if {$portname eq ""} {
ui_error "A default port name could not be supplied."
}
}
# Form the fully discriminated portname: portname/version_revison+-variants
set port(fullname) "$port(name)/[composite_version $port(version) $port(variants)]"
return [array get port]
}
proc add_to_portlist {listname portentry} {
upvar $listname portlist
# Form portlist entry and add to portlist
lappend portlist [entry_for_portlist $portentry]
}
proc add_ports_to_portlist {listname ports {overridelist ""}} {
upvar $listname portlist
array set overrides $overridelist
# Add each entry to the named portlist, overriding any values
# specified as overrides
foreach portentry $ports {
array set port $portentry
if {[info exists overrides(version)]} { set port(version) $overrides(version) }
if {[info exists overrides(variants)]} { set port(variants) $overrides(variants) }
if {[info exists overrides(requested_variants)]} { set port(requested_variants) $overrides(requested_variants) }
if {[info exists overrides(options)]} { set port(options) $overrides(options) }
add_to_portlist portlist [array get port]
}
}
proc url_to_portname { url {quiet 0} } {
# Save directory and restore the directory, since mportopen changes it
set savedir [pwd]
set portname ""
if {[catch {set ctx [mportopen $url]} result]} {
if {!$quiet} {
ui_msg "Can't map the URL '$url' to a port description file (\"${result}\")."
ui_msg "Please verify that the directory and portfile syntax are correct."
}
} else {
array set portinfo [mportinfo $ctx]
set portname $portinfo(name)
mportclose $ctx
}
cd $savedir
return $portname
}
# Supply a default porturl/portname if the portlist is empty
proc require_portlist { nameportlist {is_upgrade "no"} } {
global private_options
upvar $nameportlist portlist
if {[llength $portlist] == 0 && (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) eq "no")} {
if {${is_upgrade} eq "yes"} {
# $> port upgrade outdated
# Error: No ports matched the given expression
# is not very user friendly - if we're in the special case of
# "upgrade", let's print a message that's a little easier to
# understand and less alarming.
ui_msg "Nothing to upgrade."
return 1
}
ui_error "No ports matched the given expression"
return 1
}
if {[llength $portlist] == 0} {
set portlist [get_current_port]
if {[llength $portlist] == 0} {
# there was no port in current directory
return 1
}
}
return 0
}
# Execute the enclosed block once for every element in the portlist
# When the block is entered, the following variables will have been set:
# portspec, porturl, portname, portversion, options, variations, requested_variations
proc foreachport {portlist block} {
set savedir [pwd]
foreach portspec $portlist {
# Set the variables for the block
uplevel 1 "array unset portspec; array set portspec { $portspec }"
uplevel 1 {
set porturl $portspec(url)
set portname $portspec(name)
set portversion $portspec(version)
array unset variations
array set variations $portspec(variants)
array unset requested_variations
array set requested_variations $portspec(requested_variants)
array unset options
array set options $portspec(options)
}
# Invoke block
uplevel 1 $block
# Restore cwd after each port, since mportopen changes it, and otherwise relative
# urls would break on subsequent passes
if {[file exists $savedir]} {
cd $savedir
} else {
cd ~
}
}
}
proc portlist_compare { a b } {
array set a_ $a
array set b_ $b
set namecmp [string equal -nocase $a_(name) $b_(name)]
if {$namecmp != 1} {
if {$a_(name) eq [lindex [lsort -dictionary [list $a_(name) $b_(name)]] 0]} {
return -1
}
return 1
}
set avr_ [split $a_(version) "_"]
set bvr_ [split $b_(version) "_"]
set versioncmp [vercmp [lindex $avr_ 0] [lindex $bvr_ 0]]
if {$versioncmp != 0} {
return $versioncmp
}
set ar_ [lindex $avr_ 1]
set br_ [lindex $bvr_ 1]
if {$ar_ < $br_} {
return -1
} elseif {$ar_ > $br_} {
return 1
} else {
return 0
}
}
# Sort two ports in NVR (name@version_revision) order
proc portlist_sort { list } {
return [lsort -command portlist_compare $list]
}
proc portlist_compareint { a b } {
array set a_ [list "name" [lindex $a 0] "version" "[lindex $a 1]_[lindex $a 2]"]
array set b_ [list "name" [lindex $b 0] "version" "[lindex $b 1]_[lindex $b 2]"]
return [portlist_compare [array get a_] [array get b_]]
}
# Same as portlist_sort, but with numeric indexes {name version revision}
proc portlist_sortint { list } {
return [lsort -command portlist_compareint $list]
}
# sort portlist so dependents come before their dependencies
proc portlist_sortdependents { portlist } {
foreach p $portlist {
array set pvals $p
lappend entries($pvals(name)) $p
if {![info exists dependents($pvals(name))]} {
set dependents($pvals(name)) {}
foreach result [registry::list_dependents $pvals(name)] {
lappend dependents($pvals(name)) [lindex $result 2]
}
}
array unset pvals
}
set ret {}
foreach p $portlist {
portlist_sortdependents_helper $p entries dependents seen ret
}
return $ret
}
proc portlist_sortdependents_helper {p up_entries up_dependents up_seen up_retlist} {
upvar $up_seen seen
if {![info exists seen($p)]} {
set seen($p) 1
upvar $up_entries entries $up_dependents dependents $up_retlist retlist
array set pvals $p
foreach dependent $dependents($pvals(name)) {
if {[info exists entries($dependent)]} {
foreach entry $entries($dependent) {
portlist_sortdependents_helper $entry entries dependents seen retlist
}
}
}
lappend retlist $p
}
}
proc regex_pat_sanitize { s } {
set sanitized [regsub -all {[\\(){}+$.^]} $s {\\&}]
return $sanitized
}
##
# Makes sure we get the current terminal size
proc term_init_size {} {
global env
if {![info exists env(COLUMNS)] || ![info exists env(LINES)]} {
if {[isatty stdout]} {
set size [term_get_size stdout]
if {![info exists env(LINES)] && [lindex $size 0] > 0} {
set env(LINES) [lindex $size 0]
}
if {![info exists env(COLUMNS)] && [lindex $size 1] > 0} {
set env(COLUMNS) [lindex $size 1]
}
}
}
}
##
# Wraps a multi-line string at specified textwidth
#
# @see wrapline
#
# @param string input string
# @param maxlen text width (0 defaults to current terminal width)
# @param indent prepend to every line
# @return wrapped string
proc wrap {string maxlen {indent ""} {indentfirstline 1}} {
global env
if {$maxlen == 0} {
if {![info exists env(COLUMNS)]} {
# no width for wrapping
return $string
}
set maxlen $env(COLUMNS)
}
set splitstring {}
set indentline $indentfirstline
foreach line [split $string "\n"] {
lappend splitstring [wrapline $line $maxlen $indent $indentline]
set indentline 1
}
return [join $splitstring "\n"]
}
##
# Wraps a line at specified textwidth
#
# @see wrap
#
# @param line input line
# @param maxlen text width (0 defaults to current terminal width)
# @param indent prepend to every line
# @return wrapped string
proc wrapline {line maxlen {indent ""} {indentfirstline 1}} {
global env
if {$maxlen == 0} {
if {![info exists env(COLUMNS)]} {
# no width for wrapping
return $string
}
set maxlen $env(COLUMNS)
}
set string [split $line " "]
if {$indentfirstline == 0} {
set newline ""
set maxlen [expr {$maxlen - [string length $indent]}]
} else {
set newline $indent
}
append newline [lindex $string 0]
set joiner " "
set first 1
foreach word [lrange $string 1 end] {
if {[string length $newline]+[string length $word] >= $maxlen} {
lappend lines $newline
set newline $indent
set joiner ""
# If indentfirstline is set to 0, reset maxlen to its
# original length after appending the first line to lines.
if {$first == 1 && $indentfirstline == 0} {
set maxlen [expr {$maxlen + [string length $indent]}]
}
set first 0
}
append newline $joiner $word
set joiner " "
}
lappend lines $newline
return [join $lines "\n"]
}
##
# Wraps a line at a specified width with a label in front
#
# @see wrap
#
# @param label label for output
# @param string input string
# @param maxlen text width (0 defaults to current terminal width)
# @return wrapped string
proc wraplabel {label string maxlen {indent ""}} {
append label ": [string repeat " " [expr {[string length $indent] - [string length "$label: "]}]]"
return "$label[wrap $string $maxlen $indent 0]"
}
##########################################
# Port selection
##########################################
proc unique_results_to_portlist {infos} {
set result {}
array unset unique
foreach {name info} $infos {
array unset portinfo
array set portinfo $info
set portentry [entry_for_portlist [list url $portinfo(porturl) name $name]]
array unset entry
array set entry $portentry
if {[info exists unique($entry(fullname))]} continue
set unique($entry(fullname)) 1
lappend result $portentry
}
return $result
}
proc get_matching_ports {pattern {casesensitive no} {matchstyle glob} {field name}} {
if {[catch {set res [mportsearch $pattern $casesensitive $matchstyle $field]} result]} {
ui_debug $::errorInfo
fatal "search for portname $pattern failed: $result"
}
set results [unique_results_to_portlist $res]
# Return the list of all ports, sorted
return [portlist_sort $results]
}
proc get_all_ports {} {
global all_ports_cache
if {![info exists all_ports_cache]} {
if {[catch {set res [mportlistall]} result]} {
ui_debug $::errorInfo
fatal "listing all ports failed: $result"
}
set results [unique_results_to_portlist $res]
set all_ports_cache [portlist_sort $results]
}
return $all_ports_cache
}
proc get_current_ports {} {
# This is just a synonym for get_current_port that
# works with the regex in element
return [get_current_port]
}
proc get_current_port {} {
set url file://.
set portname [url_to_portname $url]
if {$portname eq ""} {
ui_msg "To use the current port, you must be in a port's directory."
return [list]
}
set results {}
add_to_portlist results [list url $url name $portname]
return $results
}
proc get_installed_ports { {ignore_active yes} {active yes} } {
set ilist {}
if { [catch {set ilist [registry::installed]} result] } {
if {$result ne "Registry error: No ports registered as installed."} {
ui_debug $::errorInfo
fatal "port installed failed: $result"
}
}
set results {}
foreach i $ilist {
set iname [lindex $i 0]
set iversion [lindex $i 1]
set irevision [lindex $i 2]
set ivariants [split_variants [lindex $i 3]]
set iactive [lindex $i 4]
if { ${ignore_active} eq "yes" || (${active} eq "yes") == (${iactive} != 0) } {
add_to_portlist results [list name $iname version "${iversion}_${irevision}" variants $ivariants]
}
}
# Return the list of ports, sorted
return [portlist_sort $results]
}
proc get_uninstalled_ports {} {
# Return all - installed
set all [get_all_ports]
set installed [get_installed_ports]
return [opComplement $all $installed]
}
proc get_active_ports {} {
return [get_installed_ports no yes]
}
proc get_inactive_ports {} {
return [get_installed_ports no no]
}
proc get_actinact_ports {} {
set inactive_ports [get_inactive_ports]
set active_ports [get_active_ports]
set results {}
foreach port $inactive_ports {
array set portspec $port
set portname $portspec(name)
lappend inact($portname) $port
}
foreach port $active_ports {
array set portspec $port
set portname $portspec(name)
if {[info exists inact($portname)]} {
if {![info exists added_inact($portname)]} {
foreach inact_spec $inact($portname) {
lappend results $inact_spec
}
set added_inact($portname) 1
}
lappend results $port
}
}
return $results
}
proc get_outdated_ports {} {
# Get the list of installed ports
set ilist {}
if { [catch {set ilist [registry::installed]} result] } {
if {$result ne "Registry error: No ports registered as installed."} {
ui_debug $::errorInfo
fatal "port installed failed: $result"
}
}
# Now process the list, keeping only those ports that are outdated
set results {}
if { [llength $ilist] > 0 } {
foreach i $ilist {
# Get information about the installed port
set portname [lindex $i 0]
set installed_version [lindex $i 1]
set installed_revision [lindex $i 2]
set installed_compound "${installed_version}_${installed_revision}"
set installed_variants [lindex $i 3]
set is_active [lindex $i 4]
if {$is_active == 0} continue
set installed_epoch [lindex $i 5]
# Get info about the port from the index
if {[catch {set res [mportlookup $portname]} result]} {
ui_debug $::errorInfo
fatal "lookup of portname $portname failed: $result"
}
if {[llength $res] < 2} {
if {[macports::ui_isset ports_debug]} {
puts stderr "$portname ($installed_compound is installed; the port was not found in the port index)"
}
continue
}
array unset portinfo
array set portinfo [lindex $res 1]
# Get information about latest available version and revision
set latest_version $portinfo(version)
set latest_revision 0
if {[info exists portinfo(revision)] && $portinfo(revision) > 0} {
set latest_revision $portinfo(revision)
}
set latest_compound "${latest_version}_${latest_revision}"
set latest_epoch 0
if {[info exists portinfo(epoch)]} {
set latest_epoch $portinfo(epoch)
}
# Compare versions, first checking epoch, then version, then revision
set comp_result 0
if {$installed_version != $latest_version} {
set comp_result [expr {$installed_epoch - $latest_epoch}]
if { $comp_result == 0 } {
set comp_result [vercmp $installed_version $latest_version]
}
}
if { $comp_result == 0 } {
set comp_result [expr {$installed_revision - $latest_revision}]
}
if {$comp_result == 0} {
set regref [registry::open_entry $portname $installed_version $installed_revision $installed_variants $installed_epoch]
set os_platform_installed [registry::property_retrieve $regref os_platform]
set os_major_installed [registry::property_retrieve $regref os_major]
if {$os_platform_installed ne "" && $os_platform_installed != 0
&& $os_major_installed ne "" && $os_major_installed != 0
&& ($os_platform_installed != ${macports::os_platform} || $os_major_installed != ${macports::os_major})} {
set comp_result -1
}
}
# Add outdated ports to our results list
if { $comp_result < 0 } {
add_to_portlist results [list name $portname version $installed_compound variants [split_variants $installed_variants]]
}
}
}
return [portlist_sort $results]
}
proc get_obsolete_ports {} {
set ilist [get_installed_ports]
set results {}
foreach i $ilist {
array set port $i
if {[catch {mportlookup $port(name)} result]} {
ui_debug "$::errorInfo"
break_softcontinue "lookup of portname $portname failed: $result" 1 status
}
if {[llength $result] < 2} {
lappend results $i
}
}
# Return the list of ports, already sorted
return [portlist_sort $results]
}
# return ports that have registry property $propname set to $propval
proc get_ports_with_prop {propname propval} {
set ilist {}
if { [catch {set ilist [registry::installed]} result] } {
if {$result ne "Registry error: No ports registered as installed."} {
ui_debug $::errorInfo
fatal "port installed failed: $result"
}
}
set results {}
foreach i $ilist {
set iname [lindex $i 0]
set iversion [lindex $i 1]
set irevision [lindex $i 2]
set ivariants [lindex $i 3]
set iepoch [lindex $i 5]
set regref [registry::open_entry $iname $iversion $irevision $ivariants $iepoch]
if {[registry::property_retrieve $regref $propname] eq $propval} {
add_to_portlist results [list name $iname version "${iversion}_${irevision}" variants [split_variants $ivariants]]
}
}
# Return the list of ports, sorted
return [portlist_sort $results]
}
proc get_requested_ports {} {
return [get_ports_with_prop requested 1]
}
proc get_unrequested_ports {} {
return [get_ports_with_prop requested 0]
}
proc get_leaves_ports {} {
set ilist {}
if { [catch {set ilist [registry::installed]} result] } {
if {$result ne "Registry error: No ports registered as installed."} {
ui_debug $::errorInfo
fatal "port installed failed: $result"
}
}
registry::open_dep_map
set results {}
foreach i $ilist {
set iname [lindex $i 0]
if {[registry::list_dependents $iname] eq ""} {
add_to_portlist results [list name $iname version "[lindex $i 1]_[lindex $i 2]" variants [split_variants [lindex $i 3]]]
}
}
return [portlist_sort [opIntersection $results [get_unrequested_ports]]]
}
proc get_rleaves_ports {} {
if { [catch {set ilist [get_unrequested_ports]} result] } {
if {$result ne "Registry error: No ports registered as installed."} {
ui_debug $::errorInfo
fatal "port installed failed: $result"
}
}
registry::open_dep_map
set requested [get_requested_ports]
set results {}
foreach i $ilist {
set iname [lindex $i 9]
set deplist [get_dependent_ports $iname 1]
if {$deplist eq "" || [opIntersection $deplist $requested] eq ""} {
add_to_portlist results $i
}
}
return [portlist_sort $results]
}
proc get_dependent_ports {portname recursive} {
registry::open_dep_map
set deplist [registry::list_dependents $portname]
# could return specific versions here using registry2.0 features
set results {}
foreach dep $deplist {
add_to_portlist results [list name [lindex $dep 2]]
}
# actually do this iteratively to avoid hitting Tcl's recursion limit
if {$recursive} {
while 1 {
set rportlist {}
set newlist {}
foreach dep $deplist {
set depname [lindex $dep 2]
if {![info exists seen($depname)]} {
set seen($depname) 1
set rdeplist [registry::list_dependents $depname]
foreach rdep $rdeplist {
lappend newlist $rdep
add_to_portlist rportlist [list name [lindex $rdep 2]]
}
}
}
if {[llength $rportlist] > 0} {
set results [opUnion $results $rportlist]
set deplist $newlist
} else {
break
}
}
}
return [portlist_sort $results]
}
proc get_rdepends_ports {portname} {
if {![info exists ::portDependenciesArray]} {
# make an associative array of all the port names and their (reverse) dependencies
# much faster to build this once than to call mportsearch thousands of times
set deptypes {depends_fetch depends_extract depends_build depends_lib depends_run depends_test}
foreach {pname pinfolist} [mportlistall] {