Skip to content

Commit

Permalink
Cache result of Xcode license acceptance check
Browse files Browse the repository at this point in the history
  • Loading branch information
jmroot committed Dec 12, 2023
1 parent 2bf5c36 commit 338f08b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
41 changes: 38 additions & 3 deletions src/macports1.0/macports.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace eval macports {
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 xcodecltversion \
place_worksymlink xcodeversion xcodebuildcmd xcodecltversion xcode_license_unaccepted \
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 \
Expand All @@ -75,7 +75,7 @@ namespace eval macports {
# 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 "developer_dir xcodeversion xcodebuildcmd xcodecltversion"
variable portinterp_deferred_options "developer_dir xcodeversion xcodebuildcmd xcodecltversion xcode_license_unaccepted"

variable open_mports {}

Expand Down Expand Up @@ -548,6 +548,10 @@ proc macports::set_developer_dir {name1 name2 op} {

trace remove variable macports::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]
Expand Down Expand Up @@ -655,6 +659,10 @@ proc macports::set_xcodecltversion {name1 name2 op} {

trace remove variable macports::xcodecltversion read macports::set_xcodecltversion

if {[info exists xcodecltversion]} {
return
}

# Potential names for the CLTs pkg on different OS versions.
set pkgnames [list CLTools_Executables CLTools_Base DeveloperToolsCLI DeveloperToolsCLILeo]

Expand Down Expand Up @@ -685,6 +693,25 @@ proc macports::set_xcodecltversion {name1 name2 op} {
set macports::xcodecltversion none
}

proc macports::set_xcode_license_unaccepted {name1 name2 op} {
global macports::xcode_license_unaccepted

trace remove variable macports::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 macports::xcode_license_unaccepted yes
return
}

set macports::xcode_license_unaccepted no
}


proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
# Disable unknown(n)'s behavior of running unknown commands in the system
Expand Down Expand Up @@ -737,6 +764,7 @@ proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
macports::xcodebuildcmd \
macports::xcodeversion \
macports::xcodecltversion \
macports::xcode_license_unaccepted \
macports::configureccache \
macports::ccache_dir \
macports::ccache_size \
Expand Down Expand Up @@ -1370,6 +1398,13 @@ match macports.conf.default."
set macports::xcodecltversion {}
}
}
if {![info exists xcode_license_unaccepted]} {
if {$os_platform eq "darwin"} {
trace add variable macports::xcode_license_unaccepted read macports::set_xcode_license_unaccepted
} else {
set macports::xcode_license_unaccepted no
}
}

if {![info exists developer_dir]} {
if {$os_platform eq "darwin"} {
Expand Down Expand Up @@ -5996,7 +6031,7 @@ proc macports::get_tool_path {tool} {
set toolpath "/usr/bin/${tool}"
if {![file executable $toolpath]} {
# Use xcode's xcrun to find the named tool.
if {[catch {exec -ignorestderr [findBinary xcrun $portutil::autoconf::xcrun_path] -find ${tool} 2> /dev/null} toolpath]} {
if {[catch {exec -ignorestderr [findBinary xcrun $macports::autoconf::xcrun_path] -find ${tool} 2> /dev/null} toolpath]} {
set toolpath ""
}
}
Expand Down
1 change: 1 addition & 0 deletions src/macports1.0/macports_autoconf.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace eval macports::autoconf {
variable xar_path "@XAR@"
variable xcode_select_path "@XCODE_SELECT@"
variable xcodebuild_path "@XCODEBUILD@"
variable xcrun_path "@XCRUN@"
variable os_platform "@OS_PLATFORM@"
variable os_major "@OS_MAJOR@"
}
7 changes: 2 additions & 5 deletions src/port1.0/portutil.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -3397,7 +3397,7 @@ proc check_supported_archs {} {
# check if the installed xcode version is new enough
proc _check_xcode_version {} {
global os.subplatform os.major macos_version_major xcodeversion \
xcodecltversion use_xcode subport
xcodecltversion use_xcode xcode_license_unaccepted subport

if {${os.subplatform} eq "macosx"} {
switch $macos_version_major {
Expand Down Expand Up @@ -3561,10 +3561,7 @@ proc _check_xcode_version {} {
return 1
}

# Check whether users have agreed to the Xcode license agreement
catch {exec [findBinary xcrun $portutil::autoconf::xcrun_path] clang 2>@1} output
set output [join [lrange [split $output "\n"] 0 end-1] "\n"]
if {[string match -nocase "*license*" $output]} {
if {$xcode_license_unaccepted} {
ui_error "It seems you have not accepted the Xcode license; most ports will fail to build."
ui_error "Agree to the license by opening Xcode or running `sudo xcodebuild -license'."
return 1
Expand Down

0 comments on commit 338f08b

Please sign in to comment.