-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
macports.tcl
6688 lines (6107 loc) · 259 KB
/
macports.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
# -*- 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 snapshot 1.0
package require restore 1.0
package require migrate 1.0
package require Tclx
# catch wrapper shared with port1.0
package require mpcommon 1.0
namespace eval macports {
variable bootstrap_options [dict create]
# Config file options with no special handling
foreach opt [list binpath auto_path clonebin_path extra_env portdbformat \
portarchivetype portimage_mode hfscompression portautoclean \
porttrace portverbose keeplogs destroot_umask release_urls release_version_urls \
rsync_server rsync_options rsync_dir \
startupitem_autostart startupitem_type startupitem_install \
place_worksymlink xcodeversion xcodebuildcmd xcodecltversion xcode_license_unaccepted \
configureccache ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
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 \
default_compilers pkg_post_unarchive_deletions ui_interactive] {
dict set bootstrap_options $opt {}
}
# Config file options that are a filesystem path and should be fully resolved
foreach opt [list applications_dir archive_sites_conf ccache_dir developer_dir \
frameworks_dir packagemaker_path portdbpath prefix pubkeys_conf \
sources_conf variants_conf] {
dict set bootstrap_options $opt is_path 1
}
unset opt
variable user_options {}
variable portinterp_options [list \
portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
registry.path registry.format user_home user_path user_ssh_auth_sock \
portarchivetype portarchive_hfscompression archivefetch_pubkeys \
portautoclean portimage_mode 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]
# Options set in the portfile interpreter but only in system_options
variable portinterp_private_options [list clonebin_path]
# 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 [list developer_dir xcodeversion xcodebuildcmd \
xcodecltversion xcode_license_unaccepted]
variable open_mports {}
variable ui_priorities [list error warn msg notice info debug any]
variable current_phase main
variable ui_prefix {---> }
variable cache_dirty [dict create]
variable tool_path_cache [dict create]
variable variant_descriptions [dict create]
variable getprotocol_re {(?x)([^:]+)://.+}
variable file_porturl_re {^file://(.*)}
variable source_is_snapshot_re {^((?:https?|ftp|rsync)://.+/)(.+\.(tar\.gz|tar\.bz2|tar))$}
# All valid depends_* options
variable all_dep_types [list depends_fetch depends_extract depends_patch depends_build depends_lib depends_run depends_test]
# Which depends_* types need to have matching archs when installing
variable archcheck_install_dep_types [list depends_build depends_lib depends_run]
# Which depends_* types need to have matching archs if used
variable archcheck_dep_types [list {*}${archcheck_install_dep_types} depends_test]
}
##
# 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} {
variable ui_options
if {[info exists ui_options($val)]} {
return [string is true -strict $ui_options($val)]
}
return 0
}
# Return all current ui options
proc macports::get_ui_options {} {
variable ui_options
return [array get ui_options]
}
# Set all ui options
# Takes a value previously returned by get_ui_options
proc macports::set_ui_options {opts} {
variable ui_options; variable portverbose
array unset ui_options
array set ui_options $opts
# This is also a config file option, so needs special handling
if {[info exists ui_options(ports_verbose)]} {
set portverbose $ui_options(ports_verbose)
} else {
variable portverbose_frozen
set portverbose $portverbose_frozen
}
}
# global_options accessor
proc macports::global_option_isset {val} {
variable global_options
if {[info exists global_options($val)]} {
return [string is true -strict $global_options($val)]
}
return 0
}
# Return all current global options
proc macports::get_global_options {} {
variable global_options
return [array get global_options]
}
# Set all global options
# Takes a value previously returned by get_global_options
proc macports::set_global_options {opts} {
variable global_options
array unset global_options
array set 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} {
variable $var
if {[info exists global_options($opt)]} {
set $var $global_options($opt)
} else {
variable ${var}_frozen
set $var [set ${var}_frozen]
}
}
}
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} {
variable debuglogname; variable debuglog
set portinfo [mportinfo $mport]
set portname [dict get $portinfo name]
set portpath [ditem_key $mport portpath]
set logdir [macports::getportlogpath $portpath $portname]
file mkdir $logdir
set debuglogname [file join $logdir main.log]
# Append to the file if it already exists
set debuglog [open $debuglogname a]
puts $debuglog version:1
ui_debug "Starting logging for $portname @[dict get $portinfo version]_[dict get $portinfo revision][dict get $portinfo canonical_active_variants]"
}
# log platform information
proc macports::_log_sysinfo {} {
foreach v [list current_phase os_platform os_subplatform os_version \
os_arch macos_version macosx_sdk_version \
macosx_deployment_target xcodeversion xcodecltversion] {
variable $v
}
set previous_phase ${current_phase}
set current_phase "sysinfo"
if {$os_platform eq "darwin"} {
if {$os_subplatform eq "macosx"} {
if {[vercmp $macos_version >= 10.12] } {
set os_version_string "macOS ${macos_version}"
} elseif {[vercmp $macos_version >= 10.8]} {
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 {
global tcl_platform
# 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}, CLT ${xcodecltversion}"
ui_debug "SDK ${macosx_sdk_version}"
ui_debug "MACOSX_DEPLOYMENT_TARGET: ${macosx_deployment_target}"
}
set current_phase $previous_phase
}
proc macports::push_log {mport} {
variable logenabled; variable logstack
variable debuglog; variable debuglogname
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 {} {
variable logenabled
if {![info exists logenabled]} {
return -code error "pop_log called before push_log"
}
variable logstack
if {$logenabled && [llength $logstack] > 0} {
variable debuglog; variable debuglogname
close $debuglog
set logstack [lreplace ${logstack}[set logstack {}] end end]
if {[llength $logstack] > 0} {
lassign [lindex $logstack end] debuglog debuglogname
} else {
unset debuglog
unset debuglogname
}
}
}
proc set_phase {phase} {
global macports::current_phase
set 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 macports::debuglog
#
# 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 $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]} {
if {[info exists current_phase]} {
set phase $current_phase
}
set strprefix ":${priority}:$phase "
if {[lindex $args 0] eq "-nonewline"} {
puts -nonewline $debuglog $strprefix[lindex $args 1]
} else {
foreach str [split [lindex $args 0] "\n"] {
puts $debuglog $strprefix$str
}
}
}
}
# Init (or re-init) all ui channels
proc macports::ui_init_all {} {
variable ui_priorities
variable ui_options
foreach priority $ui_priorities {
ui_init $priority
}
foreach pname {progress_download progress_generic} {
if {![macports::ui_isset ports_debug] && [info exists ui_options($pname)]} {
interp alias {} ui_$pname {} $ui_options($pname)
} else {
interp alias {} ui_$pname {} return -level 0
}
}
}
proc macports::ui_init {priority args} {
variable channels
# Get the list of channels.
if {[llength [info commands ui_channels]] > 0} {
set channels($priority) [ui_channels $priority]
} else {
set channels($priority) [macports::ui_channels_default $priority]
}
# Simplify ui_$priority.
try {
set prefix [ui_prefix $priority]
} on error {} {
set prefix [ui_prefix_default $priority]
}
try {
::ui_init $priority $prefix $channels($priority) {*}$args
} on error {} {
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} {
global macports::warning_done
if {![info exists warning_done($id)]} {
ui_warn $msg
set 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 {
macports_try -pass_signal {
return [macports::binaryInPath $prog]
} on error {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} {
variable $name
return [set $name]
}
# Load a cache file
# filename: Name relative to ${portdbpath}/cache to load from
# Returns a dict created from the file contents if successful, or an
# empty dict otherwise.
proc macports::load_cache {filename} {
variable portdbpath
set cachefd -1
macports_try -pass_signal {
set cachefd [open ${portdbpath}/cache/${filename} r]
set cache [dict create {*}[gets $cachefd]]
} on error {errorInfo} {
set cache [dict create]
ui_debug "Error reading ${portdbpath}/cache/${filename}: $errorInfo"
} finally {
if {$cachefd != -1} {
close $cachefd
}
}
return $cache
}
# Save a cache file
# filename: Name relative to ${portdbpath}/cache to save to
# cache: A dict containing the cache data
proc macports::save_cache {filename cache} {
variable portdbpath
set cachefd -1
macports_try -pass_signal {
file mkdir ${portdbpath}/cache
set cachefd [open ${portdbpath}/cache/${filename} w]
puts $cachefd $cache
} on error {errorInfo} {
ui_debug "Error writing ${portdbpath}/cache/${filename}: $errorInfo"
} finally {
if {$cachefd != -1} {
close $cachefd
}
}
}
# deferred and on-need extraction of xcodeversion and xcodebuildcmd.
proc macports::setxcodeinfo {name1 name2 op} {
variable xcodeversion; variable xcodebuildcmd
variable developer_dir; variable portdbpath
variable os_major
trace remove variable xcodeversion read macports::setxcodeinfo
trace remove variable xcodebuildcmd read macports::setxcodeinfo
set xcodeversion_overridden [info exists xcodeversion]
set xcodebuildcmd_overridden [info exists xcodebuildcmd]
# Potentially read by developer_dir trace proc
if {!${xcodeversion_overridden}} {
set xcodeversion {}
}
# First try the cache
set xcodeinfo_cache [load_cache xcodeinfo]
# Refresh everything if the OS major version changed
if {[dict exists $xcodeinfo_cache os_major]
&& [dict get $xcodeinfo_cache os_major] != $os_major
} {
set xcodeinfo_cache [dict create]
}
# The same cache file is used for xcodecltversion
set clt_refreshed [set_xcodecltversion xcodeinfo_cache]
# Figure out which file to check to see if Xcode was updated
if {[file extension [file dirname [file dirname $developer_dir]]] eq ".app"} {
# New style, Developer dir inside Xcode.app
set checkfile [file dirname $developer_dir]/Info.plist
} else {
# Old style, Xcode.app inside Developer dir
set checkfile ${developer_dir}/Applications/Xcode.app/Contents/Info.plist
}
set checkfile_found [file isfile $checkfile]
set xcode_refresh 1
if {$checkfile_found && [dict exists $xcodeinfo_cache $checkfile mtime]
&& [dict exists $xcodeinfo_cache $checkfile xcodeversion]
&& [dict exists $xcodeinfo_cache $checkfile xcodebuildcmd]} {
if {[file mtime $checkfile] == [dict get $xcodeinfo_cache $checkfile mtime]} {
if {!${xcodeversion_overridden}} {
set xcodeversion [dict get $xcodeinfo_cache $checkfile xcodeversion]
}
if {!${xcodebuildcmd_overridden}} {
set xcodebuildcmd [dict get $xcodeinfo_cache $checkfile xcodebuildcmd]
}
if {!$clt_refreshed} {
return
}
set xcode_refresh 0
} else {
ui_debug "Xcode mtime has changed, refreshing version info"
}
}
if {$xcode_refresh} {
macports_try -pass_signal {
set xcodebuild [findBinary xcodebuild $macports::autoconf::xcodebuild_path]
if {!${xcodeversion_overridden}} {
# Determine xcode version
set xcodeversion 2.0orlower
macports_try -pass_signal {
set xcodebuildversion [exec -ignorestderr -- $xcodebuild -version 2> /dev/null]
if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
set xcodeversion $xcode_v
} elseif {[regexp {DevToolsCore-(.*);} $xcodebuildversion - devtoolscore_v] == 1} {
if {$devtoolscore_v >= 1809.0} {
set xcodeversion 3.2.6
} elseif {$devtoolscore_v >= 1763.0} {
set xcodeversion 3.2.5
} elseif {$devtoolscore_v >= 1705.0} {
set xcodeversion 3.2.4
} elseif {$devtoolscore_v >= 1691.0} {
set xcodeversion 3.2.3
} elseif {$devtoolscore_v >= 1648.0} {
set xcodeversion 3.2.2
} elseif {$devtoolscore_v >= 1614.0} {
set xcodeversion 3.2.1
} elseif {$devtoolscore_v >= 1608.0} {
set xcodeversion 3.2
} elseif {$devtoolscore_v >= 1204.0} {
set xcodeversion 3.1.4
} elseif {$devtoolscore_v >= 1192.0} {
set xcodeversion 3.1.3
} elseif {$devtoolscore_v >= 1148.0} {
set xcodeversion 3.1.2
} elseif {$devtoolscore_v >= 1114.0} {
set xcodeversion 3.1.1
} elseif {$devtoolscore_v >= 1100.0} {
set xcodeversion 3.1
} elseif {$devtoolscore_v >= 921.0} {
set xcodeversion 3.0
} elseif {$devtoolscore_v >= 798.0} {
set xcodeversion 2.5
} elseif {$devtoolscore_v >= 762.0} {
set xcodeversion 2.4.1
} elseif {$devtoolscore_v >= 757.0} {
set xcodeversion 2.4
} elseif {$devtoolscore_v >= 747.0} {
set xcodeversion 2.3
} elseif {$devtoolscore_v >= 650.0} {
set xcodeversion 2.2.1
} elseif {$devtoolscore_v > 620.0} {
# XXX find actual version corresponding to 2.2
set xcodeversion 2.2
} elseif {$devtoolscore_v >= 620.0} {
set xcodeversion 2.1
}
}
} on error {} {
set xcodeversion none
}
}
if {!${xcodebuildcmd_overridden}} {
set xcodebuildcmd $xcodebuild
}
} on error {} {
if {!${xcodeversion_overridden}} {
set xcodeversion none
}
if {!${xcodebuildcmd_overridden}} {
set xcodebuildcmd none
}
}
}
if {[file writable $portdbpath]} {
if {$checkfile_found} {
dict unset xcodeinfo_cache $checkfile
# Don't cache overridden values
if {!${xcodeversion_overridden} && !${xcodebuildcmd_overridden}} {
dict set xcodeinfo_cache $checkfile xcodeversion $xcodeversion
dict set xcodeinfo_cache $checkfile xcodebuildcmd $xcodebuildcmd
dict set xcodeinfo_cache $checkfile mtime [file mtime $checkfile]
}
}
# Remove any entries for Xcode installations that no longer exist
set xcodeinfo_cache [dict filter $xcodeinfo_cache script {key info} {
expr {[string index $key 0] ne "/" || [file isfile $key]}
}]
dict set xcodeinfo_cache os_major $os_major
save_cache xcodeinfo $xcodeinfo_cache
}
}
# deferred calculation of developer_dir
proc macports::set_developer_dir {name1 name2 op} {
variable developer_dir
trace remove variable developer_dir read macports::set_developer_dir
if {[info exists developer_dir]} {
return
}
# Look for xcodeselect, and make sure it has a valid value
macports_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
macports_try -pass_signal {
set devdir [exec -ignorestderr $xcodeselect -print-path 2> /dev/null]
if {[_is_valid_developer_dir $devdir]} {
set developer_dir $devdir
return
}
} on error {} {}
# 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 [list]
macports_try -pass_signal {
set mdfind [findBinary mdfind $macports::autoconf::mdfind_path]
set installed_xcodes [exec -ignorestderr $mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2> /dev/null]
} on error {} {}
# 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
macports_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 -ignorestderr $mdls -raw -name kMDItemVersion $xcode 2> /dev/null]
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"
}
}
} on error {} {
ui_error "No Xcode installation was found."
ui_error "Please install Xcode and/or run xcode-select to specify its location."
}
ui_error
} on error {} {}
# Try the default
variable os_major
variable xcodeversion
if {$os_major >= 11 && ([vercmp $xcodeversion 4.3] >= 0 ||
($xcodeversion eq {} && [file exists /Applications/Xcode.app/Contents/Developer]))
} {
set developer_dir /Applications/Xcode.app/Contents/Developer
} else {
set developer_dir /Developer
}
}
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
}
# deferred calculation of xcodecltversion
# @return 1 if cachevar has been updated, 0 otherwise
proc macports::set_xcodecltversion {cachevar} {
variable xcodecltversion
trace remove variable xcodecltversion read macports::setxcodeinfo
if {[info exists xcodecltversion]} {
return 0
}
# Same test as used to set the default for use_xcode
if {![file executable /Library/Developer/CommandLineTools/usr/bin/make]} {
set xcodecltversion none
return 0
}
upvar $cachevar cache
if {[dict exists $cache clt version] && [dict exists $cache clt mtime]
&& [dict exists $cache clt checkfile]
&& [file mtime [dict get $cache clt checkfile]] == [dict get $cache clt mtime]} {
set xcodecltversion [dict get $cache clt version]
return 0
}
# Potential names for the CLTs pkg on different OS versions.
set pkgnames [list CLTools_Executables CLTools_Base DeveloperToolsCLI DeveloperToolsCLILeo]
if {[catch {exec -ignorestderr /usr/sbin/pkgutil --pkgs=com\\.apple\\.pkg\\.([join $pkgnames |]) 2> /dev/null} result]} {
set xcodecltversion none
return 0
}
set pkgs [split $result \n]
set found_pkgname {}
# Check in order from newest to oldest, just in case something
# stuck around from an older OS version.
foreach pkgname $pkgnames {
set fullpkgname com.apple.pkg.${pkgname}
if {$fullpkgname in $pkgs} {
if {![catch {exec -ignorestderr /usr/sbin/pkgutil --pkg-info $fullpkgname 2> /dev/null} result]} {
foreach line [split $result \n] {
lassign [split $line] name val
if {$name eq "version:"} {
set xcodecltversion $val
set found_pkgname $fullpkgname
break
}
}
if {$found_pkgname ne {}} {
break
}
} else {
ui_debug "set_xcodecltversion: Failed to get info for installed pkg ${fullpkgname}: $result"
}
}
}
if {$found_pkgname ne {}} {
# TODO: See if there are more possible locations.
foreach dir {/Library/Apple/System/Library/Receipts /System/Library/Receipts /private/var/db/receipts} {
set checkfile ${dir}/${found_pkgname}.plist
if {[file exists $checkfile]} {
dict set cache clt checkfile $checkfile
dict set cache clt mtime [file mtime $checkfile]
dict set cache clt version $xcodecltversion
return 1
}
}
} else {
set xcodecltversion none
}
return 0
}
proc macports::set_xcode_license_unaccepted {name1 name2 op} {
variable xcode_license_unaccepted
trace remove variable xcode_license_unaccepted read macports::set_xcode_license_unaccepted
if {[info exists xcode_license_unaccepted]} {
return
}
catch {exec [findBinary xcrun $macports::autoconf::xcrun_path] clang 2>@1} output
set output [join [lrange [split $output "\n"] 0 end-1] "\n"]
if {[string match -nocase "*license*" $output]} {
set xcode_license_unaccepted yes
return
}
set xcode_license_unaccepted no
}
proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
global auto_noexec env tcl_platform \
macports::autoconf::macports_conf_path \
macports::macports_user_dir \
macports::user_home \
macports::user_path \
macports::sudo_user \
macports::user_ssh_auth_sock \
macports::bootstrap_options \
macports::user_options \
macports::portsharepath \
macports::registry.format \
macports::registry.path \
macports::rsync_dir \
macports::rsync_options \
macports::rsync_server \
macports::sources \
macports::sources_default \
macports::destroot_umask \
macports::macportsuser \
macports::prefix_frozen \
macports::applications_dir \
macports::applications_dir_frozen \
macports::frameworks_dir_frozen \
macports::developer_dir \
macports::xcodebuildcmd \
macports::xcodeversion \
macports::xcodecltversion \
macports::xcode_license_unaccepted \
macports::configureccache \
macports::ccache_dir \
macports::ccache_size \
macports::configuredistcc \
macports::configurepipe \
macports::buildnicevalue \
macports::buildmakejobs \
macports::host_blacklist \
macports::preferred_hosts \
macports::keeplogs \
macports::place_worksymlink \
macports::revupgrade_autorun \
macports::revupgrade_mode \
macports::sandbox_enable \
macports::sandbox_network \
macports::startupitem_autostart \
macports::startupitem_install \
macports::startupitem_type \
macports::buildfromsource \
macports::portarchivetype \
macports::portautoclean \
macports::portautoclean_frozen \
macports::portimage_mode \
macports::porttrace \
macports::porttrace_frozen \
macports::portverbose \
macports::portverbose_frozen \
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::delete_la_files \
macports::cxx_stdlib \
macports::hfscompression \
macports::portarchive_hfscompression \
macports::host_cache \
macports::porturl_prefix_map \
macports::clonebin_path \
macports::ui_options \
macports::global_options \
macports::global_variations
# Disable unknown(n)'s behavior of running unknown commands in the system
# shell
set auto_noexec yes
if {$up_ui_options eq {}} {