{"action":"created","comment":{"url":"https://api.github.com/repos/Homebrew/homebrew/pulls/comments/48949210","id":48949210,"diff_hunk":"@@ -35,28 +35,36 @@ def without_clt?\n       end\n \n       def prefix\n-        @prefix ||=\n-          begin\n-            dir = MacOS.active_developer_dir\n-\n-            if dir.empty? || dir == CLT::MAVERICKS_PKG_PATH || !File.directory?(dir)\n-              path = bundle_path\n-              path.join(\"Contents\", \"Developer\") if path\n-            else\n-              Pathname.new(dir)\n-            end\n-          end\n+        @prefix = uncached_prefix unless instance_variable_defined?(:@prefix)\n+        @prefix\n+      end\n+\n+      def uncached_prefix\n+        dir = MacOS.active_developer_dir\n+        if dir.empty? || dir == CLT::MAVERICKS_PKG_PATH || !File.directory?(dir)\n+          path = bundle_path\n+          path/\"Contents/Developer\" if path\n+        else\n+          Pathname.new(dir)\n+        end\n+      end\n+\n+      def auto_selected?\n+        !prefix.nil? && prefix.to_s != MacOS.active_developer_dir\n       end\n \n       def toolchain_path\n         Pathname.new(\"#{prefix}/Toolchains/XcodeDefault.xctoolchain\") if installed? && version >= \"4.3\"\n       end\n \n-      # Ask Spotlight where Xcode is. If the user didn't install the\n-      # helper tools and installed Xcode in a non-conventional place, this\n-      # is our only option. See: https://superuser.com/questions/390757\n       def bundle_path\n-        MacOS.app_with_bundle_id(V4_BUNDLE_ID, V3_BUNDLE_ID)\n+        # Ask Spotlight where Xcode is if the path returned by `xcode-select` is\n+        # invalid or points at the CLT. Make sure we only auto-select an Xcode\n+        # installation in one of the default locations (see #default_prefix).\n+        xcode_path = MacOS.mdfind(V4_BUNDLE_ID, V3_BUNDLE_ID).detect do |path|\n+          \"#{path}/\".start_with?(\"/Applications/Xcode.app/\", \"/Developer/\")\n+        end","path":"Library/Homebrew/os/mac/xcode.rb","position":47,"original_position":47,"commit_id":"d8e74fa1518576e2dd2f3737de4db2b45fd17fea","original_commit_id":"d8e74fa1518576e2dd2f3737de4db2b45fd17fea","user":{"login":"mikemcquaid","id":125011,"avatar_url":"https://avatars.githubusercontent.com/u/125011?v=3","gravatar_id":"","url":"https://api.github.com/users/mikemcquaid","html_url":"https://github.com/mikemcquaid","followers_url":"https://api.github.com/users/mikemcquaid/followers","following_url":"https://api.github.com/users/mikemcquaid/following{/other_user}","gists_url":"https://api.github.com/users/mikemcquaid/gists{/gist_id}","starred_url":"https://api.github.com/users/mikemcquaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikemcquaid/subscriptions","organizations_url":"https://api.github.com/users/mikemcquaid/orgs","repos_url":"https://api.github.com/users/mikemcquaid/repos","events_url":"https://api.github.com/users/mikemcquaid/events{/privacy}","received_events_url":"https://api.github.com/users/mikemcquaid/received_events","type":"User","site_admin":true},"body":"I lean on maintaining existing behaviour except when we're fixing critical issues and I think there's a much simpler/safer fix for the described user issue. I suggest we have a hardcoded list of locations to look for first and then use Spotlight if they don't work. Even excluding `/Volumes` may break things for people with small SSDs who stick Xcode on another partition for space reasons.","created_at":"2016-01-06T11:40:52Z","updated_at":"2016-01-06T11:40:52Z","html_url":"https://github.com/Homebrew/homebrew/pull/47752#discussion_r48949210","pull_request_url":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752","_links":{"self":{"href":"https://api.github.com/repos/Homebrew/homebrew/pulls/comments/48949210"},"html":{"href":"https://github.com/Homebrew/homebrew/pull/47752#discussion_r48949210"},"pull_request":{"href":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752"}}},"pull_request":{"url":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752","id":55190463,"html_url":"https://github.com/Homebrew/homebrew/pull/47752","diff_url":"https://github.com/Homebrew/homebrew/pull/47752.diff","patch_url":"https://github.com/Homebrew/homebrew/pull/47752.patch","issue_url":"https://api.github.com/repos/Homebrew/homebrew/issues/47752","number":47752,"state":"open","locked":false,"title":"xcode: auto-select Xcode prefix more carefully","user":{"login":"UniqMartin","id":11892150,"avatar_url":"https://avatars.githubusercontent.com/u/11892150?v=3","gravatar_id":"","url":"https://api.github.com/users/UniqMartin","html_url":"https://github.com/UniqMartin","followers_url":"https://api.github.com/users/UniqMartin/followers","following_url":"https://api.github.com/users/UniqMartin/following{/other_user}","gists_url":"https://api.github.com/users/UniqMartin/gists{/gist_id}","starred_url":"https://api.github.com/users/UniqMartin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UniqMartin/subscriptions","organizations_url":"https://api.github.com/users/UniqMartin/orgs","repos_url":"https://api.github.com/users/UniqMartin/repos","events_url":"https://api.github.com/users/UniqMartin/events{/privacy}","received_events_url":"https://api.github.com/users/UniqMartin/received_events","type":"User","site_admin":false},"body":"Addresses #47579 by no longer accepting the first Xcode found by Spotlight, but only one that is (on modern systems) inside `/Applications/Xcode.app`. (This only applies if the CLT are selected via `xcode-select` instead of some Xcode installation.)\r\n\r\nThis should avoid picking up arbitrary Xcode installations while still retaining some magic as to not break a typical user installation, where we have recommended to use the CLT in most cases. Also, `brew config` now reports whether Xcode was auto-selected by Homebrew or not.\r\n\r\nThe relevant lines of `brew config` for various scenarios now look like this:\r\n\r\n```\r\n$ sudo xcode-select -s /Library/Developer/CommandLineTools # no Xcode installed\r\nXcode: N/A\r\nCLT: 7.2.0.0.1.1447826929\r\n\r\n$ sudo xcode-select -s /Library/Developer/CommandLineTools # with Xcode installed\r\nXcode: 7.2 => /Applications/Xcode.app/Contents/Developer (auto-selected)\r\nCLT: 7.2.0.0.1.1447826929\r\n\r\n$ sudo xcode-select -s /Applications/Xcode.app\r\nXcode: 7.2\r\nCLT: 7.2.0.0.1.1447826929\r\n\r\n$ sudo xcode-select -s /Volumes/DeveloperStuff/Xcode/Xcode-7.0.1.app\r\nXcode: 7.0.1 => /Volumes/DeveloperStuff/Xcode/Xcode-7.0.1.app/Contents/Developer\r\nCLT: 7.2.0.0.1.1447826929\r\n```\r\n\r\ncc @mistydemeo @mikemcquaid @apjanke ","created_at":"2016-01-06T08:59:24Z","updated_at":"2016-01-06T11:40:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"66ac7f956e3ddd03f4d8828ff829361780c5e9d0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752/commits","review_comments_url":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752/comments","review_comment_url":"https://api.github.com/repos/Homebrew/homebrew/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Homebrew/homebrew/issues/47752/comments","statuses_url":"https://api.github.com/repos/Homebrew/homebrew/statuses/d8e74fa1518576e2dd2f3737de4db2b45fd17fea","head":{"label":"UniqMartin:xcode-auto-select","ref":"xcode-auto-select","sha":"d8e74fa1518576e2dd2f3737de4db2b45fd17fea","user":{"login":"UniqMartin","id":11892150,"avatar_url":"https://avatars.githubusercontent.com/u/11892150?v=3","gravatar_id":"","url":"https://api.github.com/users/UniqMartin","html_url":"https://github.com/UniqMartin","followers_url":"https://api.github.com/users/UniqMartin/followers","following_url":"https://api.github.com/users/UniqMartin/following{/other_user}","gists_url":"https://api.github.com/users/UniqMartin/gists{/gist_id}","starred_url":"https://api.github.com/users/UniqMartin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UniqMartin/subscriptions","organizations_url":"https://api.github.com/users/UniqMartin/orgs","repos_url":"https://api.github.com/users/UniqMartin/repos","events_url":"https://api.github.com/users/UniqMartin/events{/privacy}","received_events_url":"https://api.github.com/users/UniqMartin/received_events","type":"User","site_admin":false},"repo":{"id":33837479,"name":"homebrew","full_name":"UniqMartin/homebrew","owner":{"login":"UniqMartin","id":11892150,"avatar_url":"https://avatars.githubusercontent.com/u/11892150?v=3","gravatar_id":"","url":"https://api.github.com/users/UniqMartin","html_url":"https://github.com/UniqMartin","followers_url":"https://api.github.com/users/UniqMartin/followers","following_url":"https://api.github.com/users/UniqMartin/following{/other_user}","gists_url":"https://api.github.com/users/UniqMartin/gists{/gist_id}","starred_url":"https://api.github.com/users/UniqMartin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UniqMartin/subscriptions","organizations_url":"https://api.github.com/users/UniqMartin/orgs","repos_url":"https://api.github.com/users/UniqMartin/repos","events_url":"https://api.github.com/users/UniqMartin/events{/privacy}","received_events_url":"https://api.github.com/users/UniqMartin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/UniqMartin/homebrew","description":":tea: Personal fork of “The missing package manager for OS X”","fork":true,"url":"https://api.github.com/repos/UniqMartin/homebrew","forks_url":"https://api.github.com/repos/UniqMartin/homebrew/forks","keys_url":"https://api.github.com/repos/UniqMartin/homebrew/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UniqMartin/homebrew/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UniqMartin/homebrew/teams","hooks_url":"https://api.github.com/repos/UniqMartin/homebrew/hooks","issue_events_url":"https://api.github.com/repos/UniqMartin/homebrew/issues/events{/number}","events_url":"https://api.github.com/repos/UniqMartin/homebrew/events","assignees_url":"https://api.github.com/repos/UniqMartin/homebrew/assignees{/user}","branches_url":"https://api.github.com/repos/UniqMartin/homebrew/branches{/branch}","tags_url":"https://api.github.com/repos/UniqMartin/homebrew/tags","blobs_url":"https://api.github.com/repos/UniqMartin/homebrew/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UniqMartin/homebrew/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UniqMartin/homebrew/git/refs{/sha}","trees_url":"https://api.github.com/repos/UniqMartin/homebrew/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UniqMartin/homebrew/statuses/{sha}","languages_url":"https://api.github.com/repos/UniqMartin/homebrew/languages","stargazers_url":"https://api.github.com/repos/UniqMartin/homebrew/stargazers","contributors_url":"https://api.github.com/repos/UniqMartin/homebrew/contributors","subscribers_url":"https://api.github.com/repos/UniqMartin/homebrew/subscribers","subscription_url":"https://api.github.com/repos/UniqMartin/homebrew/subscription","commits_url":"https://api.github.com/repos/UniqMartin/homebrew/commits{/sha}","git_commits_url":"https://api.github.com/repos/UniqMartin/homebrew/git/commits{/sha}","comments_url":"https://api.github.com/repos/UniqMartin/homebrew/comments{/number}","issue_comment_url":"https://api.github.com/repos/UniqMartin/homebrew/issues/comments{/number}","contents_url":"https://api.github.com/repos/UniqMartin/homebrew/contents/{+path}","compare_url":"https://api.github.com/repos/UniqMartin/homebrew/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UniqMartin/homebrew/merges","archive_url":"https://api.github.com/repos/UniqMartin/homebrew/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UniqMartin/homebrew/downloads","issues_url":"https://api.github.com/repos/UniqMartin/homebrew/issues{/number}","pulls_url":"https://api.github.com/repos/UniqMartin/homebrew/pulls{/number}","milestones_url":"https://api.github.com/repos/UniqMartin/homebrew/milestones{/number}","notifications_url":"https://api.github.com/repos/UniqMartin/homebrew/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UniqMartin/homebrew/labels{/name}","releases_url":"https://api.github.com/repos/UniqMartin/homebrew/releases{/id}","created_at":"2015-04-12T23:04:38Z","updated_at":"2015-12-20T09:09:49Z","pushed_at":"2016-01-06T11:22:57Z","git_url":"git://github.com/UniqMartin/homebrew.git","ssh_url":"git@github.com:UniqMartin/homebrew.git","clone_url":"https://github.com/UniqMartin/homebrew.git","svn_url":"https://github.com/UniqMartin/homebrew","homepage":"","size":66547,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"Homebrew:master","ref":"master","sha":"7d2f7cb05c4c8f092c457c547c3404e4684405cf","user":{"login":"Homebrew","id":1503512,"avatar_url":"https://avatars.githubusercontent.com/u/1503512?v=3","gravatar_id":"","url":"https://api.github.com/users/Homebrew","html_url":"https://github.com/Homebrew","followers_url":"https://api.github.com/users/Homebrew/followers","following_url":"https://api.github.com/users/Homebrew/following{/other_user}","gists_url":"https://api.github.com/users/Homebrew/gists{/gist_id}","starred_url":"https://api.github.com/users/Homebrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Homebrew/subscriptions","organizations_url":"https://api.github.com/users/Homebrew/orgs","repos_url":"https://api.github.com/users/Homebrew/repos","events_url":"https://api.github.com/users/Homebrew/events{/privacy}","received_events_url":"https://api.github.com/users/Homebrew/received_events","type":"Organization","site_admin":false},"repo":{"id":206084,"name":"homebrew","full_name":"Homebrew/homebrew","owner":{"login":"Homebrew","id":1503512,"avatar_url":"https://avatars.githubusercontent.com/u/1503512?v=3","gravatar_id":"","url":"https://api.github.com/users/Homebrew","html_url":"https://github.com/Homebrew","followers_url":"https://api.github.com/users/Homebrew/followers","following_url":"https://api.github.com/users/Homebrew/following{/other_user}","gists_url":"https://api.github.com/users/Homebrew/gists{/gist_id}","starred_url":"https://api.github.com/users/Homebrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Homebrew/subscriptions","organizations_url":"https://api.github.com/users/Homebrew/orgs","repos_url":"https://api.github.com/users/Homebrew/repos","events_url":"https://api.github.com/users/Homebrew/events{/privacy}","received_events_url":"https://api.github.com/users/Homebrew/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Homebrew/homebrew","description":":beer: The missing package manager for OS X.","fork":false,"url":"https://api.github.com/repos/Homebrew/homebrew","forks_url":"https://api.github.com/repos/Homebrew/homebrew/forks","keys_url":"https://api.github.com/repos/Homebrew/homebrew/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Homebrew/homebrew/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Homebrew/homebrew/teams","hooks_url":"https://api.github.com/repos/Homebrew/homebrew/hooks","issue_events_url":"https://api.github.com/repos/Homebrew/homebrew/issues/events{/number}","events_url":"https://api.github.com/repos/Homebrew/homebrew/events","assignees_url":"https://api.github.com/repos/Homebrew/homebrew/assignees{/user}","branches_url":"https://api.github.com/repos/Homebrew/homebrew/branches{/branch}","tags_url":"https://api.github.com/repos/Homebrew/homebrew/tags","blobs_url":"https://api.github.com/repos/Homebrew/homebrew/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Homebrew/homebrew/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Homebrew/homebrew/git/refs{/sha}","trees_url":"https://api.github.com/repos/Homebrew/homebrew/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Homebrew/homebrew/statuses/{sha}","languages_url":"https://api.github.com/repos/Homebrew/homebrew/languages","stargazers_url":"https://api.github.com/repos/Homebrew/homebrew/stargazers","contributors_url":"https://api.github.com/repos/Homebrew/homebrew/contributors","subscribers_url":"https://api.github.com/repos/Homebrew/homebrew/subscribers","subscription_url":"https://api.github.com/repos/Homebrew/homebrew/subscription","commits_url":"https://api.github.com/repos/Homebrew/homebrew/commits{/sha}","git_commits_url":"https://api.github.com/repos/Homebrew/homebrew/git/commits{/sha}","comments_url":"https://api.github.com/repos/Homebrew/homebrew/comments{/number}","issue_comment_url":"https://api.github.com/repos/Homebrew/homebrew/issues/comments{/number}","contents_url":"https://api.github.com/repos/Homebrew/homebrew/contents/{+path}","compare_url":"https://api.github.com/repos/Homebrew/homebrew/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Homebrew/homebrew/merges","archive_url":"https://api.github.com/repos/Homebrew/homebrew/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Homebrew/homebrew/downloads","issues_url":"https://api.github.com/repos/Homebrew/homebrew/issues{/number}","pulls_url":"https://api.github.com/repos/Homebrew/homebrew/pulls{/number}","milestones_url":"https://api.github.com/repos/Homebrew/homebrew/milestones{/number}","notifications_url":"https://api.github.com/repos/Homebrew/homebrew/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Homebrew/homebrew/labels{/name}","releases_url":"https://api.github.com/repos/Homebrew/homebrew/releases{/id}","created_at":"2009-05-20T19:38:37Z","updated_at":"2016-01-06T11:27:01Z","pushed_at":"2016-01-06T11:23:06Z","git_url":"git://github.com/Homebrew/homebrew.git","ssh_url":"git@github.com:Homebrew/homebrew.git","clone_url":"https://github.com/Homebrew/homebrew.git","svn_url":"https://github.com/Homebrew/homebrew","homepage":"http://brew.sh","size":1408349,"stargazers_count":28296,"watchers_count":28296,"language":"Ruby","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":13978,"mirror_url":null,"open_issues_count":409,"forks":13978,"open_issues":409,"watchers":28296,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752"},"html":{"href":"https://github.com/Homebrew/homebrew/pull/47752"},"issue":{"href":"https://api.github.com/repos/Homebrew/homebrew/issues/47752"},"comments":{"href":"https://api.github.com/repos/Homebrew/homebrew/issues/47752/comments"},"review_comments":{"href":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752/comments"},"review_comment":{"href":"https://api.github.com/repos/Homebrew/homebrew/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Homebrew/homebrew/pulls/47752/commits"},"statuses":{"href":"https://api.github.com/repos/Homebrew/homebrew/statuses/d8e74fa1518576e2dd2f3737de4db2b45fd17fea"}}}}