os/mac/xcode: add fast path for Xcode version detection
This commit is contained in:
		
							parent
							
								
									2cbe3886e0
								
							
						
					
					
						commit
						04ad24efe8
					
				@ -192,22 +192,32 @@ module OS
 | 
				
			|||||||
        # if return is used in the middle, which we do many times in here.
 | 
					        # if return is used in the middle, which we do many times in here.
 | 
				
			||||||
        return if !MacOS::Xcode.installed? && !MacOS::CLT.installed?
 | 
					        return if !MacOS::Xcode.installed? && !MacOS::CLT.installed?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        %W[
 | 
					        if MacOS::Xcode.installed?
 | 
				
			||||||
          #{prefix}/usr/bin/xcodebuild
 | 
					          # Fast path that will probably almost always work unless `xcode-select -p` is misconfigured
 | 
				
			||||||
          #{which("xcodebuild")}
 | 
					          version_plist = T.must(prefix).parent/"version.plist"
 | 
				
			||||||
        ].uniq.each do |xcodebuild_path|
 | 
					          if version_plist.file?
 | 
				
			||||||
          next unless File.executable? xcodebuild_path
 | 
					            data = Plist.parse_xml(version_plist, marshal: false)
 | 
				
			||||||
 | 
					            version = data["CFBundleShortVersionString"] if data
 | 
				
			||||||
 | 
					            return version if version
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version")
 | 
					          %W[
 | 
				
			||||||
          next unless $CHILD_STATUS.success?
 | 
					            #{prefix}/usr/bin/xcodebuild
 | 
				
			||||||
 | 
					            #{which("xcodebuild")}
 | 
				
			||||||
 | 
					          ].uniq.each do |xcodebuild_path|
 | 
				
			||||||
 | 
					            next unless File.executable? xcodebuild_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          xcode_version = xcodebuild_output[/Xcode (\d+(\.\d+)*)/, 1]
 | 
					            xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version")
 | 
				
			||||||
          return xcode_version if xcode_version
 | 
					            next unless $CHILD_STATUS.success?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          # Xcode 2.x's xcodebuild has a different version string
 | 
					            xcode_version = xcodebuild_output[/Xcode (\d+(\.\d+)*)/, 1]
 | 
				
			||||||
          case xcodebuild_output[/DevToolsCore-(\d+\.\d)/, 1]
 | 
					            return xcode_version if xcode_version
 | 
				
			||||||
          when "798.0" then return "2.5"
 | 
					
 | 
				
			||||||
          when "515.0" then return "2.0"
 | 
					            # Xcode 2.x's xcodebuild has a different version string
 | 
				
			||||||
 | 
					            case xcodebuild_output[/DevToolsCore-(\d+\.\d)/, 1]
 | 
				
			||||||
 | 
					            when "798.0" then return "2.5"
 | 
				
			||||||
 | 
					            when "515.0" then return "2.0"
 | 
				
			||||||
 | 
					            end
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user