<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/c97e75d2c6296ea2bfe49cbe2f0960bf289f7ace">https://github.com/macports/macports-base/commit/c97e75d2c6296ea2bfe49cbe2f0960bf289f7ace</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit c97e75d2c6296ea2bfe49cbe2f0960bf289f7ace
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Fri Feb 23 13:20:31 2024 +1100
<span style='display:block; white-space:pre;color:#404040;'> Cache xcodeversion persistently
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> The cache is invalidated if the mtime of Xcode's Info.plist changes.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Motivation: With recent Xcode versions, 'xcodebuild -version' can
</span><span style='display:block; white-space:pre;color:#404040;'> sometimes take up to 30 seconds.
</span>---
src/macports1.0/macports.tcl | 134 ++++++++++++++++++++++++++++++++-----------
1 file changed, 101 insertions(+), 33 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/macports1.0/macports.tcl b/src/macports1.0/macports.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index d7404398d..877cb2f4c 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/macports1.0/macports.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/macports1.0/macports.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -467,77 +467,143 @@ proc macports::getoption {name} {
</span>
# deferred and on-need extraction of xcodeversion and xcodebuildcmd.
proc macports::setxcodeinfo {name1 name2 op} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- global macports::xcodeversion macports::xcodebuildcmd
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variable xcodeversion; variable xcodebuildcmd
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variable developer_dir; variable portdbpath
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- trace remove variable macports::xcodeversion read macports::setxcodeinfo
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- trace remove variable macports::xcodebuildcmd read macports::setxcodeinfo
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ trace remove variable xcodeversion read macports::setxcodeinfo
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ trace remove variable xcodebuildcmd read macports::setxcodeinfo
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion_overridden [info exists xcodeversion]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodebuildcmd_overridden [info exists xcodebuildcmd]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # First try the cache
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ macports_try -pass_signal {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set versfile -1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set versfile [open ${portdbpath}/cache/xcodeinfo r]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeinfo_cache [dict create {*}[gets $versfile]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } on error {errorInfo} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeinfo_cache [dict create]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Error loading ${portdbpath}/cache/xcodeinfo: $errorInfo"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } finally {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$versfile != -1} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ close $versfile
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Figure out which file to check to see if Xcode was updated
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[file extension [file dirname [file dirname $developer_dir]]] eq ".app"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # New style, Developer dir inside Xcode.app
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set checkfile [file dirname $developer_dir]/Info.plist
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Old style, Xcode.app inside Developer dir
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set checkfile ${developer_dir}/Applications/Xcode.app/Contents/Info.plist
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set checkfile_found [file isfile $checkfile]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$checkfile_found && [dict exists $xcodeinfo_cache $checkfile mtime]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && [dict exists $xcodeinfo_cache $checkfile xcodeversion]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && [dict exists $xcodeinfo_cache $checkfile xcodebuildcmd]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[file mtime $checkfile] == [dict get $xcodeinfo_cache $checkfile mtime]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodeversion_overridden}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion [dict get $xcodeinfo_cache $checkfile xcodeversion]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodebuildcmd_overridden}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodebuildcmd [dict get $xcodeinfo_cache $checkfile xcodebuildcmd]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Xcode mtime has changed, refreshing version info"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span>
macports_try -pass_signal {
set xcodebuild [findBinary xcodebuild $macports::autoconf::xcodebuild_path]
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists xcodeversion]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodeversion_overridden}} {
</span> # Determine xcode version
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.0orlower
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.0orlower
</span> macports_try -pass_signal {
set xcodebuildversion [exec -ignorestderr -- $xcodebuild -version 2> /dev/null]
if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion $xcode_v
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion $xcode_v
</span> } elseif {[regexp {DevToolsCore-(.*);} $xcodebuildversion - devtoolscore_v] == 1} {
if {$devtoolscore_v >= 1809.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2.6
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2.6
</span> } elseif {$devtoolscore_v >= 1763.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2.5
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2.5
</span> } elseif {$devtoolscore_v >= 1705.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2.4
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2.4
</span> } elseif {$devtoolscore_v >= 1691.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2.3
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2.3
</span> } elseif {$devtoolscore_v >= 1648.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2.2
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2.2
</span> } elseif {$devtoolscore_v >= 1614.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2.1
</span> } elseif {$devtoolscore_v >= 1608.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.2
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.2
</span> } elseif {$devtoolscore_v >= 1204.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.1.4
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.1.4
</span> } elseif {$devtoolscore_v >= 1192.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.1.3
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.1.3
</span> } elseif {$devtoolscore_v >= 1148.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.1.2
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.1.2
</span> } elseif {$devtoolscore_v >= 1114.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.1.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.1.1
</span> } elseif {$devtoolscore_v >= 1100.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.1
</span> } elseif {$devtoolscore_v >= 921.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 3.0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 3.0
</span> } elseif {$devtoolscore_v >= 798.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.5
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.5
</span> } elseif {$devtoolscore_v >= 762.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.4.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.4.1
</span> } elseif {$devtoolscore_v >= 757.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.4
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.4
</span> } elseif {$devtoolscore_v >= 747.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.3
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.3
</span> } elseif {$devtoolscore_v >= 650.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.2.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.2.1
</span> } elseif {$devtoolscore_v > 620.0} {
# XXX find actual version corresponding to 2.2
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.2
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.2
</span> } elseif {$devtoolscore_v >= 620.0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion 2.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion 2.1
</span> }
}
} on error {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion none
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion none
</span> }
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists xcodebuildcmd]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodebuildcmd $xcodebuild
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodebuildcmd_overridden}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodebuildcmd $xcodebuild
</span> }
} on error {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists xcodeversion]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodeversion none
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodeversion_overridden}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeversion none
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if {![info exists xcodebuildcmd]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set macports::xcodebuildcmd none
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodebuildcmd_overridden}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodebuildcmd none
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[file writable $portdbpath]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$checkfile_found} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict unset xcodeinfo_cache $checkfile
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Don't cache overridden values
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {!${xcodeversion_overridden} && !${xcodebuildcmd_overridden}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict set xcodeinfo_cache $checkfile xcodeversion $xcodeversion
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict set xcodeinfo_cache $checkfile xcodebuildcmd $xcodebuildcmd
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict set xcodeinfo_cache $checkfile mtime [file mtime $checkfile]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Remove any entries for Xcode installations that no longer exist
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set xcodeinfo_cache [dict filter $xcodeinfo_cache script {filename info} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ file isfile $filename
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[catch {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ file mkdir ${portdbpath}/cache
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set versfile [open ${portdbpath}/cache/xcodeinfo w]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts $versfile $xcodeinfo_cache
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ close $versfile
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } result]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Error writing ${portdbpath}/cache/xcodeinfo: $result"
</span> }
}
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1612,6 +1678,8 @@ proc macports::worker_init {workername portpath porturl portbuildpath options va
</span>
# Tell the sub interpreter about all the Tcl packages we already
# know about so it won't glob for packages.
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ # TODO: There are a lot of these. Should we restrict it to only
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # the packages that are likely to be needed?
</span> foreach pkgName [package names] {
foreach pkgVers [package versions $pkgName] {
set pkgLoadScript [package ifneeded $pkgName $pkgVers]
</pre><pre style='margin:0'>
</pre>