-
-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathmacports.tcl
More file actions
5695 lines (5181 loc) · 222 KB
/
macports.tcl
File metadata and controls
5695 lines (5181 loc) · 222 KB
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
# -*- 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
# macports.tcl
#
# Copyright (c) 2002 - 2003 Apple Inc.
# Copyright (c) 2004 - 2005 Paul Guyot, <pguyot@kallisys.net>.
# Copyright (c) 2004 - 2006 Ole Guldberg Jensen <olegb@opendarwin.org>.
# Copyright (c) 2004 - 2005 Robert Shaw <rshaw@opendarwin.org>
# Copyright (c) 2004 - 2020 The MacPorts Project
# 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.
#
package provide macports 1.0
package require macports_dlist 1.0
package require macports_util 1.0
package require diagnose 1.0
package require reclaim 1.0
package require selfupdate 1.0
package require Tclx
# catch wrapper shared with port1.0
package require mpcommon 1.0
namespace eval macports {
namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities
variable bootstrap_options "\
portdbpath binpath auto_path extra_env sources_conf prefix portdbformat \
portarchivetype hfscompression portautoclean \
porttrace portverbose keeplogs destroot_umask variants_conf rsync_server rsync_options \
rsync_dir startupitem_autostart startupitem_type startupitem_install \
place_worksymlink xcodeversion xcodebuildcmd \
configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
applications_dir frameworks_dir developer_dir universal_archs build_arch macosx_sdk_version macosx_deployment_target \
macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip \
master_site_local patch_site_local archive_site_local buildfromsource \
revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
host_blacklist preferred_hosts sandbox_enable sandbox_network delete_la_files cxx_stdlib \
packagemaker_path default_compilers pkg_post_unarchive_deletions ui_interactive"
variable user_options {}
variable portinterp_options "\
portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
registry.path registry.format user_home user_path user_ssh_auth_sock \
portarchivetype archivefetch_pubkeys portautoclean porttrace keeplogs portverbose destroot_umask \
rsync_server rsync_options rsync_dir startupitem_autostart startupitem_type startupitem_install \
place_worksymlink macportsuser sudo_user \
configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
applications_dir applications_dir_frozen current_phase frameworks_dir frameworks_dir_frozen \
developer_dir universal_archs build_arch os_arch os_endian os_version os_major os_minor \
os_platform os_subplatform macos_version macos_version_major macosx_version macosx_sdk_version \
macosx_deployment_target packagemaker_path default_compilers sandbox_enable sandbox_network \
delete_la_files cxx_stdlib pkg_post_unarchive_deletions $user_options"
# deferred options are only computed when needed.
# they are not exported to the trace thread.
# they are not exported to the interpreter in system_options array.
variable portinterp_deferred_options "xcodeversion xcodebuildcmd developer_dir"
variable open_mports {}
variable ui_priorities "error warn msg notice info debug any"
variable current_phase main
variable ui_prefix "---> "
}
##
# Return the version of MacPorts you are running
#
# This proc never fails and always returns the current version in the format
# major.minor.patch. Note that the value of patch will not be meaningful for
# Git master, but we guarantee that it will compare to be greater than any
# released versions from the same major.minor.x series. You should use the
# MacPorts-provided Tcl extension "vercmp" to do version number comparisons on
# the return value of this function.
proc macports::version {} {
return ${macports::autoconf::macports_version}
}
# Provided UI instantiations
# For standard messages, the following priorities are defined
# debug, info, msg, warn, error
# Clients of the library are expected to provide ui_prefix and ui_channels with
# the following prototypes.
# proc ui_prefix {priority}
# proc ui_channels {priority}
# ui_prefix returns the prefix for the messages, if any.
# ui_channels returns a list of channels to output the message to, empty for
# no message.
# if these functions are not provided, defaults are used.
# Clients of the library may optionally provide ui_init with the following
# prototype.
# proc ui_init {priority prefix channels message}
# ui_init needs to correctly define the proc ::ui_$priority {message} or throw
# an error.
# if this function is not provided or throws an error, default procedures for
# ui_$priority are defined.
# ui_options accessor
proc macports::ui_isset {val} {
if {[info exists macports::ui_options($val)]} {
return [string is true -strict $macports::ui_options($val)]
}
return 0
}
# global_options accessor
proc macports::global_option_isset {val} {
if {[info exists macports::global_options($val)]} {
return [string is true -strict $macports::global_options($val)]
}
return 0
}
proc macports::init_logging {mport} {
if {[getuid] == 0 && [geteuid] != 0} {
seteuid 0; setegid 0
}
if {[catch {macports::ch_logging $mport} err]} {
ui_debug "Logging disabled, error opening log file: $err"
return 1
}
macports::_log_sysinfo
return 0
}
proc macports::ch_logging {mport} {
array set portinfo [mportinfo $mport]
set portname $portinfo(name)
set portpath [ditem_key $mport portpath]
set logname [macports::getportlogpath $portpath $portname]
file mkdir $logname
set logname [file join $logname main.log]
set ::debuglogname $logname
# Append to the file if it already exists
set ::debuglog [open $::debuglogname a]
puts $::debuglog version:1
ui_debug "Starting logging for $portname @$portinfo(version)_$portinfo(revision)$portinfo(canonical_active_variants)"
}
# log platform information
proc macports::_log_sysinfo {} {
global macports::current_phase
global macports::os_platform macports::os_subplatform \
macports::os_version macports::os_major macports::os_minor \
macports::os_endian macports::os_arch \
macports::macos_version macports::macosx_sdk_version macports::macosx_deployment_target \
macports::xcodeversion
global tcl_platform
set previous_phase ${macports::current_phase}
set macports::current_phase "sysinfo"
if {$os_platform eq "darwin"} {
if {$os_subplatform eq "macosx"} {
if {[vercmp $macos_version 10.12] >= 0} {
set os_version_string "macOS ${macos_version}"
} elseif {[vercmp $macos_version 10.8] >= 0} {
set os_version_string "OS X ${macos_version}"
} else {
set os_version_string "Mac OS X ${macos_version}"
}
} else {
set os_version_string "PureDarwin ${os_version}"
}
} else {
# use capitalized platform name
set os_version_string "$tcl_platform(os) ${os_version}"
}
ui_debug "$os_version_string ($os_platform/$os_version) arch $os_arch"
ui_debug "MacPorts [macports::version]"
if {$os_platform eq "darwin" && $os_subplatform eq "macosx"} {
ui_debug "Xcode ${xcodeversion}"
ui_debug "SDK ${macosx_sdk_version}"
ui_debug "MACOSX_DEPLOYMENT_TARGET: ${macosx_deployment_target}"
}
set macports::current_phase $previous_phase
}
proc macports::push_log {mport} {
if {![info exists ::logenabled]} {
if {[macports::init_logging $mport] == 0} {
set ::logenabled yes
set ::logstack [list [list $::debuglog $::debuglogname]]
return
} else {
set ::logenabled no
}
}
if {$::logenabled} {
if {[macports::init_logging $mport] == 0} {
lappend ::logstack [list $::debuglog $::debuglogname]
}
}
}
proc macports::pop_log {} {
if {![info exists ::logenabled]} {
return -code error "pop_log called before push_log"
}
if {$::logenabled && [llength $::logstack] > 0} {
close $::debuglog
set ::logstack [lreplace $::logstack end end]
if {[llength $::logstack] > 0} {
set top [lindex $::logstack end]
set ::debuglog [lindex $top 0]
set ::debuglogname [lindex $top 1]
} else {
unset ::debuglog
unset ::debuglogname
}
}
}
proc set_phase {phase} {
global macports::current_phase
set macports::current_phase $phase
if {$phase ne "main"} {
set cur_time [clock format [clock seconds] -format {%+}]
ui_debug "$phase phase started at $cur_time"
}
}
proc ui_message {priority prefix args} {
global macports::channels macports::current_phase
#
# validate $args
#
switch [llength $args] {
0 - 1 {}
2 {
if {[lindex $args 0] ne "-nonewline"} {
set hint "error: when 4 arguments are given, 3rd must be \"-nonewline\""
error "$hint\nusage: ui_message priority prefix ?-nonewline? string"
}
}
default {
set hint "error: too many arguments specified"
error "$hint\nusage: ui_message priority prefix ?-nonewline? string"
}
}
foreach chan $macports::channels($priority) {
if {[lindex $args 0] eq "-nonewline"} {
puts -nonewline $chan $prefix[lindex $args 1]
} else {
puts $chan $prefix[lindex $args 0]
}
}
if {[info exists ::debuglog]} {
set chan $::debuglog
if {[info exists macports::current_phase]} {
set phase $macports::current_phase
}
set strprefix ":${priority}:$phase "
if {[lindex $args 0] eq "-nonewline"} {
puts -nonewline $chan $strprefix[lindex $args 1]
} else {
foreach str [split [lindex $args 0] "\n"] {
puts $chan $strprefix$str
}
}
}
}
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
}
# Simplify ui_$priority.
try {
set prefix [ui_prefix $priority]
} catch * {
set prefix [ui_prefix_default $priority]
}
try {
::ui_init $priority $prefix $channels($priority) {*}$args
} catch * {
interp alias {} ui_$priority {} ui_message $priority $prefix
}
}
# Default implementation of ui_prefix
proc macports::ui_prefix_default {priority} {
switch -- $priority {
debug {
return "DEBUG: "
}
error {
return "Error: "
}
warn {
return "Warning: "
}
default {
return {}
}
}
}
# Default implementation of ui_channels:
# ui_options(ports_debug) - If set, output debugging messages
# ui_options(ports_verbose) - If set, output info messages (ui_info)
# ui_options(ports_quiet) - If set, don't output "standard messages"
proc macports::ui_channels_default {priority} {
switch -- $priority {
debug {
if {[ui_isset ports_debug]} {
return stderr
} else {
return {}
}
}
info {
if {[ui_isset ports_verbose]} {
return stdout
} else {
return {}
}
}
notice {
if {[ui_isset ports_quiet]} {
return {}
} else {
return stdout
}
}
msg {
return stdout
}
warn -
error {
return stderr
}
default {
return stdout
}
}
}
proc ui_warn_once {id msg} {
variable macports::warning_done
if {![info exists macports::warning_done($id)]} {
ui_warn $msg
set macports::warning_done($id) 1
}
}
# Replace puts to catch errors (typically broken pipes when being piped to head)
rename puts tcl::puts
proc puts {args} {
catch {tcl::puts {*}$args}
}
# find a binary either in a path defined at MacPorts' configuration time
# or in the PATH environment variable through macports::binaryInPath (fallback)
proc macports::findBinary {prog {autoconf_hint {}}} {
if {$autoconf_hint ne "" && [file executable $autoconf_hint]} {
return $autoconf_hint
} else {
try -pass_signal {
return [macports::binaryInPath $prog]
} catch {{*} eCode eMessage} {
error "$eMessage or at its MacPorts configuration time location, did you move it?"
}
}
}
# check for a binary in the path
# returns an error code if it cannot be found
proc macports::binaryInPath {prog} {
global env
foreach dir [split $env(PATH) :] {
if {[file executable [file join $dir $prog]]} {
return [file join $dir $prog]
}
}
return -code error [format [msgcat::mc "Failed to locate '%s' in path: '%s'"] $prog $env(PATH)];
}
# deferred option processing
proc macports::getoption {name} {
global macports::$name
return [set $name]
}
# deferred and on-need extraction of xcodeversion and xcodebuildcmd.
proc macports::setxcodeinfo {name1 name2 op} {
global macports::xcodeversion macports::xcodebuildcmd
trace remove variable macports::xcodeversion read macports::setxcodeinfo
trace remove variable macports::xcodebuildcmd read macports::setxcodeinfo
try -pass_signal {
set xcodebuild [findBinary xcodebuild $macports::autoconf::xcodebuild_path]
if {![info exists xcodeversion]} {
# Determine xcode version
set macports::xcodeversion 2.0orlower
try -pass_signal {
set xcodebuildversion [exec -- $xcodebuild -version 2> /dev/null]
if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
set macports::xcodeversion $xcode_v
} elseif {[regexp {DevToolsCore-(.*);} $xcodebuildversion - devtoolscore_v] == 1} {
if {$devtoolscore_v >= 1809.0} {
set macports::xcodeversion 3.2.6
} elseif {$devtoolscore_v >= 1763.0} {
set macports::xcodeversion 3.2.5
} elseif {$devtoolscore_v >= 1705.0} {
set macports::xcodeversion 3.2.4
} elseif {$devtoolscore_v >= 1691.0} {
set macports::xcodeversion 3.2.3
} elseif {$devtoolscore_v >= 1648.0} {
set macports::xcodeversion 3.2.2
} elseif {$devtoolscore_v >= 1614.0} {
set macports::xcodeversion 3.2.1
} elseif {$devtoolscore_v >= 1608.0} {
set macports::xcodeversion 3.2
} elseif {$devtoolscore_v >= 1204.0} {
set macports::xcodeversion 3.1.4
} elseif {$devtoolscore_v >= 1192.0} {
set macports::xcodeversion 3.1.3
} elseif {$devtoolscore_v >= 1148.0} {
set macports::xcodeversion 3.1.2
} elseif {$devtoolscore_v >= 1114.0} {
set macports::xcodeversion 3.1.1
} elseif {$devtoolscore_v >= 1100.0} {
set macports::xcodeversion 3.1
} elseif {$devtoolscore_v >= 921.0} {
set macports::xcodeversion 3.0
} elseif {$devtoolscore_v >= 798.0} {
set macports::xcodeversion 2.5
} elseif {$devtoolscore_v >= 762.0} {
set macports::xcodeversion 2.4.1
} elseif {$devtoolscore_v >= 757.0} {
set macports::xcodeversion 2.4
} elseif {$devtoolscore_v >= 747.0} {
set macports::xcodeversion 2.3
} elseif {$devtoolscore_v >= 650.0} {
set macports::xcodeversion 2.2.1
} elseif {$devtoolscore_v > 620.0} {
# XXX find actual version corresponding to 2.2
set macports::xcodeversion 2.2
} elseif {$devtoolscore_v >= 620.0} {
set macports::xcodeversion 2.1
}
}
} catch {*} {
set macports::xcodeversion none
}
}
if {![info exists xcodebuildcmd]} {
set macports::xcodebuildcmd $xcodebuild
}
} catch {*} {
if {![info exists xcodeversion]} {
set macports::xcodeversion none
}
if {![info exists xcodebuildcmd]} {
set macports::xcodebuildcmd none
}
}
}
# deferred calculation of developer_dir
proc macports::set_developer_dir {name1 name2 op} {
global macports::developer_dir macports::os_major macports::xcodeversion
trace remove variable macports::developer_dir read macports::set_developer_dir
# Look for xcodeselect, and make sure it has a valid value
try -pass_signal {
set xcodeselect [findBinary xcode-select $macports::autoconf::xcode_select_path]
# We have xcode-select: ask it where xcode is and check if it's valid.
# If no xcode is selected, xcode-select will fail, so catch that
try -pass_signal {
set devdir [exec $xcodeselect -print-path 2> /dev/null]
if {[_is_valid_developer_dir $devdir]} {
set macports::developer_dir $devdir
return
}
} catch {*} {}
# The directory from xcode-select isn't correct.
# Ask mdfind where Xcode is and make some suggestions for the user,
# searching by bundle identifier for various Xcode versions (3.x and 4.x)
set installed_xcodes {}
try -pass_signal {
set mdfind [findBinary mdfind $macports::autoconf::mdfind_path]
set installed_xcodes [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
} catch {*} {}
# In case mdfind metadata wasn't complete, also look in two well-known locations for Xcode.app
foreach app {/Applications/Xcode.app /Developer/Applications/Xcode.app} {
if {[file isdirectory $app]} {
lappend installed_xcodes $app
}
}
# Form a list of unique xcode installations
set installed_xcodes [lsort -unique $installed_xcodes]
# Present instructions to the user
ui_error
try -pass_signal {
if {[llength $installed_xcodes] == 0} {
error "No Xcode installation was found."
}
set mdls [findBinary mdls $macports::autoconf::mdls_path]
# One, or more than one, Xcode installations found
ui_error "No valid Xcode installation is properly selected."
ui_error "Please use xcode-select to select an Xcode installation:"
foreach xcode $installed_xcodes {
set vers [exec $mdls -raw -name kMDItemVersion $xcode]
if {$vers eq {(null)}} {set vers unknown}
if {[_is_valid_developer_dir ${xcode}/Contents/Developer]} {
# Though xcode-select shipped with xcode 4.3 supports and encourages
# direct use of the app path, older xcode-select does not.
# Specify the Contents/Developer directory if it exists
ui_error " sudo xcode-select -switch ${xcode}/Contents/Developer # version $vers"
} elseif {[vercmp $vers 4.3] >= 0} {
# Future proofing: fall back to the app-path only for xcode >= 4.3, since Contents/Developer doesn't exist
ui_error " sudo xcode-select -switch $xcode # version $vers"
} elseif {[_is_valid_developer_dir ${xcode}/../..]} {
# Older xcode (< 4.3) is below the developer directory
ui_error " sudo xcode-select -switch [file normalize ${xcode}/../..] # version $vers"
} else {
ui_error " # malformed Xcode at ${xcode}, version $vers"
}
}
} catch {*} {
ui_error "No Xcode installation was found."
ui_error "Please install Xcode and/or run xcode-select to specify its location."
}
ui_error
} catch {*} {}
# Try the default
if {$os_major >= 11 && [vercmp $xcodeversion 4.3] >= 0} {
set devdir /Applications/Xcode.app/Contents/Developer
} else {
set devdir /Developer
}
set macports::developer_dir $devdir
}
proc macports::_is_valid_developer_dir {dir} {
# Check whether specified directory looks valid for an Xcode installation
# Verify that the directory exists
if {![file isdirectory $dir]} {
return 0
}
# Verify that the directory has some key subdirectories
foreach subdir {Library usr} {
if {![file isdirectory ${dir}/$subdir]} {
return 0
}
}
# The specified directory seems valid for Xcode
return 1
}
proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
# Disable unknown(n)'s behavior of running unknown commands in the system
# shell
set ::auto_noexec yes
if {$up_ui_options eq {}} {
array set macports::ui_options {}
} else {
upvar $up_ui_options temp_ui_options
array set macports::ui_options [array get temp_ui_options]
}
if {$up_options eq {}} {
array set macports::global_options {}
} else {
upvar $up_options temp_options
array set macports::global_options [array get temp_options]
}
if {$up_variations eq {}} {
array set variations {}
} else {
upvar $up_variations variations
}
# Initialize ui_*
foreach priority $macports::ui_priorities {
macports::ui_init $priority
}
package require Pextlib 1.0
package require registry 1.0
package require registry2 2.0
package require machista 1.0
global auto_path env tcl_platform \
macports::autoconf::macports_conf_path \
macports::macports_user_dir \
macports::bootstrap_options \
macports::user_options \
macports::portconf \
macports::portsharepath \
macports::registry.format \
macports::registry.path \
macports::sources \
macports::sources_default \
macports::destroot_umask \
macports::prefix \
macports::macportsuser \
macports::prefix_frozen \
macports::applications_dir_frozen \
macports::frameworks_dir_frozen \
macports::xcodebuildcmd \
macports::xcodeversion \
macports::configureccache \
macports::ccache_dir \
macports::ccache_size \
macports::configuredistcc \
macports::configurepipe \
macports::buildnicevalue \
macports::buildmakejobs \
macports::universal_archs \
macports::build_arch \
macports::os_arch \
macports::os_endian \
macports::os_version \
macports::os_major \
macports::os_minor \
macports::os_platform \
macports::os_subplatform \
macports::macos_version \
macports::macos_version_major \
macports::macosx_version \
macports::macosx_sdk_version \
macports::macosx_deployment_target \
macports::archivefetch_pubkeys \
macports::ping_cache \
macports::host_cache \
macports::delete_la_files \
macports::cxx_stdlib \
macports::hfscompression
# Set the system encoding to utf-8
encoding system utf-8
# Set up signal handling for SIGTERM and SIGINT
# Specifying error here will case the program to abort where it is with
# a Tcl error, which can be caught, if necessary.
signal -restart error {TERM INT}
# Set RLIMIT_NOFILE to the maximum possible
set_max_open_files
# set up platform info variables
set os_arch $tcl_platform(machine)
# Set os_arch to match `uname -p`
if {$os_arch eq "Power Macintosh"} {
set os_arch "powerpc"
} elseif {$os_arch eq "i586" || $os_arch eq "i686" || $os_arch eq "x86_64"} {
set os_arch "i386"
} elseif {$os_arch eq "arm64"} {
set os_arch "arm"
}
set os_version $tcl_platform(osVersion)
set os_major [lindex [split $os_version .] 0]
set os_minor [lindex [split $os_version .] 1]
set os_platform [string tolower $tcl_platform(os)]
# Remove trailing "Endian"
set os_endian [string range $tcl_platform(byteOrder) 0 end-6]
set os_subplatform {}
set macos_version {}
if {$os_platform eq "darwin"} {
if {[file isdirectory /System/Library/Frameworks/Carbon.framework]} {
# macOS
set os_subplatform macosx
if {[file executable /usr/bin/sw_vers]} {
try -pass_signal {
set macos_version [exec /usr/bin/sw_vers -productVersion]
} catch {* ec result} {
ui_debug "sw_vers exists but running it failed: $result"
}
}
} else {
# PureDarwin
set os_subplatform puredarwin
}
}
if {[vercmp $macos_version 11] >= 0} {
# Big Sur is apparently any 11.x version
set macos_version_major [lindex [split $macos_version .] 0]
} else {
set macos_version_major [join [lrange [split $macos_version .] 0 1] .]
}
# backward compatibility synonym
set macosx_version $macos_version_major
# Check that the current platform is the one we were configured for, otherwise need to do migration
if {($os_platform ne $macports::autoconf::os_platform) || ($os_platform eq "darwin" && $os_major != $macports::autoconf::os_major)} {
ui_error "Current platform \"$os_platform $os_major\" does not match expected platform \"$macports::autoconf::os_platform $macports::autoconf::os_major\""
ui_error "If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration"
return -code error "OS platform mismatch"
}
# Ensure that the macports user directory (i.e. ~/.macports) exists if HOME is defined.
# Also save $HOME for later use before replacing it with our own.
if {[info exists env(HOME)]} {
set macports::user_home $env(HOME)
set macports::macports_user_dir [file normalize $macports::autoconf::macports_user_dir]
} elseif {[info exists env(SUDO_USER)] && $os_platform eq "darwin"} {
set macports::user_home [exec dscl -q . -read /Users/$env(SUDO_USER) NFSHomeDirectory | cut -d ' ' -f 2]
set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
} elseif {[exec id -u] != 0 && $os_platform eq "darwin"} {
set macports::user_home [exec dscl -q . -read /Users/[exec id -un] NFSHomeDirectory | cut -d ' ' -f 2]
set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
} else {
# Otherwise define the user directory as a directory that will never exist
set macports::macports_user_dir /dev/null/NO_HOME_DIR
set macports::user_home /dev/null/NO_HOME_DIR
}
# Save the path for future processing
set macports::user_path $env(PATH)
# Likewise any SUDO_USER
if {[info exists env(SUDO_USER)]} {
set macports::sudo_user $env(SUDO_USER)
}
# Save SSH_AUTH_SOCK for ports tree sync
if {[info exists env(SSH_AUTH_SOCK)]} {
set macports::user_ssh_auth_sock $env(SSH_AUTH_SOCK)
}
# Configure the search path for configuration files
set conf_files {}
lappend conf_files ${macports_conf_path}/macports.conf
if {[file isdirectory $macports_user_dir]} {
lappend conf_files ${macports_user_dir}/macports.conf
}
if {[info exists env(PORTSRC)]} {
set PORTSRC $env(PORTSRC)
lappend conf_files $PORTSRC
}
# Process all configuration files we find on conf_files list
set conf_option_re {^(\w+)([ \t]+(.*))?$}
foreach file $conf_files {
if {[file exists $file]} {
set portconf $file
set fd [open $file r]
while {[gets $fd line] >= 0} {
if {[regexp $conf_option_re $line match option ignore val] == 1} {
if {$option in $bootstrap_options} {
set macports::$option [string trim $val]
global macports::$option
}
}
}
close $fd
}
}
# Process per-user only settings
set per_user ${macports_user_dir}/user.conf
if {[file exists $per_user]} {
set fd [open $per_user r]
while {[gets $fd line] >= 0} {
if {[regexp $conf_option_re $line match option ignore val] == 1} {
if {$option in $user_options} {
set macports::$option $val
global macports::$option
}
}
}
close $fd
}
if {![info exists sources_conf]} {
return -code error "sources_conf must be set in ${macports_conf_path}/macports.conf or in your ${macports_user_dir}/macports.conf file"
}
set sources_conf_comment_re {^\s*#|^$}
set sources_conf_source_re {^([\w-]+://\S+)(?:\s+\[(\w+(?:,\w+)*)\])?$}
set fd [open $sources_conf r]
while {[gets $fd line] >= 0} {
set line [string trimright $line]
if {![regexp $sources_conf_comment_re $line]} {
if {[regexp $sources_conf_source_re $line _ url flags]} {
set flags [split $flags ,]
foreach flag $flags {
if {$flag ni [list nosync default]} {
ui_warn "$sources_conf source '$line' specifies invalid flag '$flag'"
}
if {$flag eq "default"} {
if {[info exists sources_default]} {
ui_warn "More than one default port source is defined."
}
set sources_default [concat [list $url] $flags]
}
}
if {[string match rsync://*rsync.macports.org/release/ports/ $url]} {
ui_warn "MacPorts is configured to use an unsigned source for the ports tree.\
Please edit sources.conf and change '$url' to '[string range $url 0 end-6]tarballs/ports.tar'."
}
lappend sources [concat [list $url] $flags]
} else {
ui_warn "$sources_conf specifies invalid source '$line', ignored."
}
}
}
close $fd
if {![info exists sources]} {
if {[file isdirectory ports]} {
set sources file://[pwd]/ports
} else {
return -code error "No sources defined in $sources_conf"
}
}
# Make sure the default port source is defined. Otherwise
# [macports::getportresourcepath] fails when the first source doesn't
# contain _resources.
if {![info exists sources_default]} {
ui_warn "No default port source specified in ${sources_conf}, using last source as default"
set sources_default [lindex $sources end]
}
# regex also used by pubkeys.conf
set variants_conf_comment_re {^[\ \t]*#.*$|^$}
if {[info exists variants_conf]} {
if {[file exists $variants_conf]} {
set variants_conf_setting_re {^([-+])([-A-Za-z0-9_+\.]+)$}
set fd [open $variants_conf r]
while {[gets $fd line] >= 0} {
set line [string trimright $line]
if {![regexp $variants_conf_comment_re $line]} {
foreach arg [split $line " \t"] {
if {[regexp $variants_conf_setting_re $arg match sign opt] == 1} {
if {![info exists variations($opt)]} {
set variations($opt) $sign
}
} else {
ui_warn "$variants_conf specifies invalid variant syntax '$arg', ignored."
}
}
}
}
close $fd
} else {
ui_debug "$variants_conf does not exist, variants_conf setting ignored."
}
}
global macports::global_variations
array set macports::global_variations [array get variations]
# pubkeys.conf
set macports::archivefetch_pubkeys {}
if {[file isfile [file join $macports_conf_path pubkeys.conf]]} {
set fd [open [file join $macports_conf_path pubkeys.conf] r]
while {[gets $fd line] >= 0} {
set line [string trim $line]
if {![regexp $variants_conf_comment_re $line]} {
lappend macports::archivefetch_pubkeys $line
}
}
close $fd
} else {
ui_debug "pubkeys.conf does not exist."
}
if {![info exists portdbpath]} {
return -code error "portdbpath must be set in ${macports_conf_path}/macports.conf or in your ${macports_user_dir}/macports.conf"
}
if {![file isdirectory $portdbpath]} {
if {![file exists $portdbpath]} {
if {[catch {file mkdir $portdbpath} result]} {
return -code error "portdbpath $portdbpath does not exist and could not be created: $result"
}
} else {
return -code error "$portdbpath is not a directory. Please create the directory $portdbpath and try again"
}
}
set env(HOME) [file join $portdbpath home]
set registry.path $portdbpath
# Format for receipts; currently only "sqlite" is allowed
# could previously be "flat", so we switch that to sqlite
if {![info exists portdbformat] || $portdbformat eq "flat" || $portdbformat eq "sqlite"} {
set registry.format receipt_sqlite
} else {
return -code error "unknown registry format '$portdbformat' set in macports.conf"
}
# Autoclean mode, whether to automatically call clean after "install"
if {![info exists portautoclean]} {
set macports::portautoclean yes
global macports::portautoclean
}
# whether to keep logs after successful builds
if {![info exists keeplogs]} {
set macports::keeplogs no
global macports::keeplogs
}
# Check command line override for autoclean
if {[info exists macports::global_options(ports_autoclean)]} {
if {$macports::global_options(ports_autoclean) ne $portautoclean} {
set macports::portautoclean $macports::global_options(ports_autoclean)
}
}
# Trace mode, whether to use darwintrace to debug ports.
if {![info exists porttrace]} {
set macports::porttrace no
global macports::porttrace
}
# Check command line override for trace
if {[info exists macports::global_options(ports_trace)]} {
if {$macports::global_options(ports_trace) ne $porttrace} {
set macports::porttrace $macports::global_options(ports_trace)
}
}
# Check command line override for source/binary only mode
if {![info exists macports::global_options(ports_binary_only)]
&& ![info exists macports::global_options(ports_source_only)]
&& [info exists macports::buildfromsource]} {
if {$macports::buildfromsource eq "never"} {
set macports::global_options(ports_binary_only) yes
set temp_options(ports_binary_only) yes
} elseif {$macports::buildfromsource eq "always"} {
set macports::global_options(ports_source_only) yes
set temp_options(ports_source_only) yes
} elseif {$macports::buildfromsource ne "ifneeded"} {
ui_warn "'buildfromsource' set to unknown value '$macports::buildfromsource', using 'ifneeded' instead"
}
}
# Duplicate prefix into prefix_frozen, so that port actions
# can always get to the original prefix, even if a portfile overrides prefix
set macports::prefix_frozen $prefix
if {![info exists macports::applications_dir]} {
set macports::applications_dir /Applications/MacPorts
}
set macports::applications_dir_frozen ${macports::applications_dir}
if {[info exists macports::frameworks_dir]} {
set macports::frameworks_dir_frozen ${macports::frameworks_dir}
} else {
set macports::frameworks_dir_frozen ${macports::prefix_frozen}/Library/Frameworks
}
# Export verbosity.
if {![info exists portverbose]} {
set macports::portverbose no
global macports::portverbose
}