[89996] trunk/base/src

jmr at macports.org jmr at macports.org
Sun Feb 19 06:15:31 PST 2012


Revision: 89996
          http://trac.macports.org/changeset/89996
Author:   jmr at macports.org
Date:     2012-02-19 06:15:27 -0800 (Sun, 19 Feb 2012)
Log Message:
-----------
move code for initialising developer_dir to the macports1.0 level so it only runs once, simplify, fix for non-macosx platforms

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/port1.0/portmain.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2012-02-19 11:16:45 UTC (rev 89995)
+++ trunk/base/src/macports1.0/macports.tcl	2012-02-19 14:15:27 UTC (rev 89996)
@@ -65,7 +65,7 @@
     # 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"
+    variable portinterp_deferred_options "xcodeversion xcodebuildcmd developer_dir"
 
     variable open_mports {}
 
@@ -419,6 +419,75 @@
     }
 }
 
+# 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
+
+    set devdir ""
+    # Look for xcodeselect, and make sure it has a valid value
+    if {![catch {binaryInPath xcode-select} xcodeselect]} {
+
+        # We have xcode-select: ask it where xcode is
+        set devdir [exec $xcodeselect -print-path 2> /dev/null]
+
+        # If the directory is valid, use it
+        if {[_is_valid_developer_dir $devdir]} {
+            return $devdir
+        }
+
+        # The directory from xcode-select isn't correct.
+        # Ask mdfind where Xcode is and make some suggestions for the user
+        set installed_xcodes {}
+        if {![catch {binaryInPath mdfind} mdfind]} {
+            set installed_xcodes [exec $mdfind \"kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'\"]
+        }
+        if {[llength $installed_xcodes] > 0} {
+            # One, or more than one, Xcode installations found
+            ui_error "No valid Xcode installation is properly selected."
+
+            ui_error
+            ui_error "Please use xcode-select to select an Xcode installation:"
+            foreach xcode $installed_xcodes {
+                ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer"
+            }
+            ui_error
+        }
+        # Try the default
+        if {$os_major >= 11 && [vercmp $xcodeversion 4.3] >= 0} {
+            set devdir "/Applications/Xcode.app/Contents/Developer"
+        } else {
+            set devdir "/Developer"
+        }
+        if {![_is_valid_developer_dir $devdir]} {
+            ui_error "No valid Xcode installation was found. Please install or correctly select Xcode."
+        }
+    }
+
+    return $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 {Headers 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 {}}} {
     if {$up_ui_options eq ""} {
         array set macports::ui_options {}
@@ -940,7 +1009,15 @@
         trace add variable macports::xcodebuildcmd read macports::setxcodeinfo
     }
 
-    if {[vercmp $xcodeversion 4.3] >= 0} {
+    if {![info exists developer_dir]} {
+        if {$os_platform == "darwin"} {
+            trace add variable macports::developer_dir read macports::set_developer_dir
+        } else {
+            set macports::developer_dir ""
+        }
+    }
+
+    if {$os_major >= 11 && $os_platform == "darwin" && [vercmp $xcodeversion 4.3] >= 0} {
         macports::link_xcode_plist $env(HOME)
     }
 

Modified: trunk/base/src/port1.0/portmain.tcl
===================================================================
--- trunk/base/src/port1.0/portmain.tcl	2012-02-19 11:16:45 UTC (rev 89995)
+++ trunk/base/src/port1.0/portmain.tcl	2012-02-19 14:15:27 UTC (rev 89996)
@@ -91,7 +91,6 @@
 default prefix /opt/local
 default applications_dir /Applications/MacPorts
 default frameworks_dir {${prefix}/Library/Frameworks}
-default developer_dir {[portmain::get_developer_dir]}
 default destdir destroot
 default destpath {${workpath}/${destdir}}
 # destroot is provided as a clearer name for the "destpath" variable
@@ -146,84 +145,6 @@
 default compiler.cpath {${prefix}/include}
 default compiler.library_path {${prefix}/lib}
 
-
-proc 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 {Headers Library usr} {
-        if {![file isdirectory "${dir}/${subdir}"]} {
-            return 0
-        }
-    }
-    
-    # The specified directory seems valid for Xcode
-    return 1
-}
-
-
-proc get_xcode_suggestions {} {
-    # Ask mdfind where Xcode is
-    set result ""
-    if {![catch {set mdfind [binaryInPath mdfind]}]} {
-        set result [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
-    }
-    return $result
-}
-
-
-proc portmain::get_developer_dir {} {
-    set devdir ""
-
-    # Look for xcodeselect, and make sure it has a valid value
-    if {![catch {set xcodeselect [binaryInPath xcode-select]}]} {
-        
-        # We have xcodeselect: ask it where xcode is
-        set devdir [exec $xcodeselect -print-path 2> /dev/null]
-
-        # If the directory is valid, use it
-        if {[is_valid_developer_dir $devdir]} {
-            return $devdir
-        }
-        
-        # The directory from xcodeselect isn't correct.
-        # Make some suggestions for the user
-        set installed_xcodes [get_xcode_suggestions]
-        if {[llength $installed_xcodes] == 0} {
-            # No installed Xcodes found
-            ui_error "No valid Xcode installation was found; please install Xcode"
-        } else {
-            # One, or more than one, Xcode installations found
-            ui_error "No valid Xcode installation is properly selected"
-            
-            ui_error
-            ui_error "Please use xcode-select to select an Xcode installation:"
-            foreach xcode $installed_xcodes {
-                ui_error "    sudo xcode-select -switch ${xcode}"
-            }
-            ui_error
-        }
-    }
-    
-    # xcode-select wasn't found, look for Xcode at /Developer
-    set devdir "/Developer"
-    if {[is_valid_developer_dir $devdir]} {
-        return $devdir
-    }
-    
-    ui_error
-    ui_error "No valid Xcode installation was found: please install Xcode"
-    ui_error
-    
-    # We return /Developer here even though we know it's wrong. Abort instead?
-    return "/Developer"
-}
-
 # start gsoc08-privileges
 
 # Record initial euid/egid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20120219/b69a7be8/attachment.html>


More information about the macports-changes mailing list