language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
Homebrew
brew
557f6e33a9496513006a3ec69f9d3f3d0450e9e5.json
audit: check resource placement
Library/Homebrew/cmd/audit.rb
@@ -186,6 +186,7 @@ def audit_file [/^ keg_only/, "keg_only"], [/^ option/, "option"], [/^ depends_on/, "depends_on"], + [/^ (go_)?resource/, "resource"], [/^ def install/, "install method"], [/^ def caveats/, "caveats method"], [/^ test do/, "test block"],
false
Other
Homebrew
brew
9cab3011856d0d4308054887f7459dc91e444ed3.json
diagnostic: improve check for 'gnubin' in PATH Both `coreutils` and `findutils` suggest to add `#{opt_libexec}/gnubin` to PATH in their caveats to get the non-prefixed binaries from those formulae. Check this in addition to the version-specific directory that is less likely to be in PATH. Closes Homebrew/homebrew#48207. Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Library/Homebrew/diagnostic.rb
@@ -1198,20 +1198,28 @@ def check_for_bad_python_symlink end def check_for_non_prefixed_coreutils - gnubin = "#{Formulary.factory("coreutils").prefix}/libexec/gnubin" - if paths.include? gnubin then <<-EOS.undent + coreutils = Formula["coreutils"] + return unless coreutils.any_version_installed? + + gnubin = %W[#{coreutils.opt_libexec}/gnubin #{coreutils.libexec}/gnubin] + return if (paths & gnubin).empty? + + <<-EOS.undent Putting non-prefixed coreutils in your path can cause gmp builds to fail. - EOS - end + EOS end def check_for_non_prefixed_findutils - gnubin = "#{Formulary.factory("findutils").prefix}/libexec/gnubin" + findutils = Formula["findutils"] + return unless findutils.any_version_installed? + + gnubin = %W[#{findutils.opt_libexec}/gnubin #{findutils.libexec}/gnubin] default_names = Tab.for_name("findutils").with? "default-names" - if paths.include?(gnubin) || default_names then <<-EOS.undent + return if !default_names && (paths & gnubin).empty? + + <<-EOS.undent Putting non-prefixed findutils in your path can cause python builds to fail. - EOS - end + EOS end def check_for_pydistutils_cfg_in_home
false
Other
Homebrew
brew
c25e11563c839f2d4c49cb28d3bcbff177cc3fb3.json
tests: fix a file leak
Library/Homebrew/test/test_integration_cmds.rb
@@ -158,6 +158,8 @@ def test_uninstall def test_cleanup (HOMEBREW_CACHE/"test").write "test" assert_match "#{HOMEBREW_CACHE}/test", cmd("cleanup", "--prune=all") + ensure + (HOMEBREW_CACHE/"test").rmtree end def test_readall
false
Other
Homebrew
brew
77975168e0f2d5e6627d049d6055bc159e3fd89d.json
bin/brew: add support for developer bash commands This also means `bin/brew` is again consistent with `brew command` and `brew commands`.
bin/brew
@@ -135,7 +135,11 @@ then fi HOMEBREW_COMMAND="$1" -HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$1.sh" +if [[ -f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" ]] ; then + HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" +elif [[ -n "$HOMEBREW_DEVELOPER" && -f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" ]] ; then + HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" +fi if [[ "$(id -u)" = "0" && "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ]] then @@ -151,7 +155,7 @@ EOS esac fi -if [[ -f "$HOMEBREW_BASH_COMMAND" ]] +if [[ -n "$HOMEBREW_BASH_COMMAND" ]] then # Bash commands don't need the first argument, which is just the command name. shift
false
Other
Homebrew
brew
6106ac903550ee323eb08a8abac02ce7c74c4a4d.json
update-bash: discourage direct use Remove the executable bit from the file to make it clear it is not supposed to be executed directly. This should make the shebang line and the early check also unnecessary.
Library/Homebrew/cmd/update-bash.sh
@@ -1,12 +1,3 @@ -#!/bin/bash - -if [[ -z "$HOMEBREW_BREW_FILE" ]] -then - # we don't use odie here, because it's only available when this script is called from brew. - echo "Error: $(basename "$0") must be called from brew!" >&2 - exit 1 -fi - brew() { "$HOMEBREW_BREW_FILE" "$@" }
false
Other
Homebrew
brew
a59c1ae6cb90644869862e6432ed8e82ac361ebe.json
os/mac: hide GCC warnings in `config` output.
Library/Homebrew/os/mac.rb
@@ -132,7 +132,7 @@ def default_compiler def gcc_40_build_version @gcc_40_build_version ||= if (path = locate("gcc-4.0")) - `#{path} --version`[/build (\d{4,})/, 1].to_i + `#{path} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i end end alias_method :gcc_4_0_build_version, :gcc_40_build_version @@ -142,7 +142,7 @@ def gcc_42_build_version begin gcc = MacOS.locate("gcc-4.2") || HOMEBREW_PREFIX.join("opt/apple-gcc42/bin/gcc-4.2") if gcc.exist? && !gcc.realpath.basename.to_s.start_with?("llvm") - `#{gcc} --version`[/build (\d{4,})/, 1].to_i + `#{gcc} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i end end end
false
Other
Homebrew
brew
e1875b7a43f233252d795a4e10ee4125658466e8.json
audit: avoid false positive pkgshare problems
Library/Homebrew/cmd/audit.rb
@@ -878,11 +878,11 @@ def audit_line(line, lineno) problem "`#{$1}` is now unnecessary" end - if line =~ /#\{share\}\/#{formula.name}/ + if line =~ %r{#\{share\}/#{formula.name}[/'"]} problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}" end - if line =~ /share\/"#{formula.name}"/ + if line =~ %r{share/"#{formula.name}[/'"]} problem "Use pkgshare instead of (share/\"#{formula.name}\")" end end
false
Other
Homebrew
brew
3d9bc57feacf32d9050569b3645c29d2a0ddd749.json
doc: Fix some typos at Formula Cookbook Closes Homebrew/homebrew#48342. Signed-off-by: Dominyk Tiller <dominyktiller@gmail.com>
share/doc/homebrew/Formula-Cookbook.md
@@ -70,7 +70,7 @@ so you can override this with `brew create <url> --set-name <name>`. ## Fill in the [`homepage`](http://www.rubydoc.info/github/Homebrew/homebrew/master/Formula#homepage%3D-class_method) -**We don’t accept formulae without [`homepage`](http://www.rubydoc.info/github/Homebrew/homebrew/master/Formula#homepage%3D-class_method)s!** +**We don’t accept formulae without a [`homepage`](http://www.rubydoc.info/github/Homebrew/homebrew/master/Formula#homepage%3D-class_method)!** A SSL/TLS (https) [`homepage`](http://www.rubydoc.info/github/Homebrew/homebrew/master/Formula#homepage%3D-class_method) is preferred, if one is available.
false
Other
Homebrew
brew
ead10917d63fb2385d1a9325e5220ad3e8b81ad4.json
Add directions for subscribing to mailing list Closes Homebrew/homebrew#48369. Signed-off-by: Tim D. Smith <git@tim-smith.us>
share/doc/homebrew/README.md
@@ -25,7 +25,7 @@ Read [CONTRIBUTING.md](/CONTRIBUTING.md). ### Community Forums - [@MacHomebrew](https://twitter.com/MacHomebrew) -- [homebrew-discuss@googlegroups.com](mailto:homebrew-discuss@googlegroups.com) ([archive](https://groups.google.com/forum/#!forum/homebrew-discuss)) +- [homebrew-discuss@googlegroups.com](mailto:homebrew-discuss@googlegroups.com) ([archive](https://groups.google.com/forum/#!forum/homebrew-discuss)) - subscribe by sending a mail to [homebrew-discuss+subscribe@googlegroups.com](mailto:homebrew-discuss+subscribe@googlegroups.com) - [freenode.net\#machomebrew](irc://irc.freenode.net/#machomebrew) ## Supporters
false
Other
Homebrew
brew
e3687a5ba21385025eb97522654f56557535ba75.json
update-bash: use array for QUIET_ARGS Per @UniqMartin's advice, avoid disabling shellcheck rules. Closes Homebrew/homebrew#48286. Signed-off-by: Xu Cheng <xucheng@me.com>
Library/Homebrew/cmd/update-bash.sh
@@ -103,11 +103,9 @@ read_current_revision() { git rev-parse -q --verify HEAD } -# Don't warn about QUIET_ARGS; they need to be unquoted. -# shellcheck disable=SC2086 pop_stash() { [[ -z "$STASHED" ]] && return - git stash pop $QUIET_ARGS + git stash pop "${QUIET_ARGS[@]}" if [[ -n "$HOMEBREW_VERBOSE" ]] then echo "Restoring your stashed changes to $DIR:" @@ -123,8 +121,6 @@ pop_stash_message() { unset STASHED } -# Don't warn about QUIET_ARGS; they need to be unquoted. -# shellcheck disable=SC2086 reset_on_interrupt() { if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] then @@ -133,7 +129,7 @@ reset_on_interrupt() { if [[ -n "$INITIAL_REVISION" ]] then - git reset --hard "$INITIAL_REVISION" $QUIET_ARGS + git reset --hard "$INITIAL_REVISION" "${QUIET_ARGS[@]}" fi if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] @@ -146,8 +142,6 @@ reset_on_interrupt() { exit 130 } -# Don't warn about QUIET_ARGS; they need to be unquoted. -# shellcheck disable=SC2086 pull() { local DIR local TAP_VAR @@ -190,8 +184,8 @@ pull() { fi git -c "user.email=brew-update@localhost" \ -c "user.name=brew update" \ - stash save --include-untracked $QUIET_ARGS - git reset --hard $QUIET_ARGS + stash save --include-untracked "${QUIET_ARGS[@]}" + git reset --hard "${QUIET_ARGS[@]}" STASHED="1" fi @@ -201,9 +195,9 @@ pull() { # it to `origin/#{@upstream_branch}`. Otherwise, just check it out. if git merge-base --is-ancestor "$UPSTREAM_BRANCH" "origin/$UPSTREAM_BRANCH" &>/dev/null then - git checkout --force "$UPSTREAM_BRANCH" $QUIET_ARGS + git checkout --force "$UPSTREAM_BRANCH" "${QUIET_ARGS[@]}" else - git checkout --force -B "$UPSTREAM_BRANCH" "origin/$UPSTREAM_BRANCH" $QUIET_ARGS + git checkout --force -B "$UPSTREAM_BRANCH" "origin/$UPSTREAM_BRANCH" "${QUIET_ARGS[@]}" fi fi @@ -215,9 +209,9 @@ pull() { if [[ -n "$HOMEBREW_REBASE" ]] then - git rebase $QUIET_ARGS "origin/$UPSTREAM_BRANCH" + git rebase "${QUIET_ARGS[@]}" "origin/$UPSTREAM_BRANCH" else - git merge --no-edit --ff $QUIET_ARGS "origin/$UPSTREAM_BRANCH" + git merge --no-edit --ff "${QUIET_ARGS[@]}" "origin/$UPSTREAM_BRANCH" fi export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(read_current_revision)" @@ -226,7 +220,7 @@ pull() { if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] then - git checkout "$INITIAL_BRANCH" $QUIET_ARGS + git checkout "$INITIAL_BRANCH" "${QUIET_ARGS[@]}" pop_stash else pop_stash_message @@ -295,7 +289,9 @@ EOS if [[ -z "$HOMEBREW_VERBOSE" ]] then - QUIET_ARGS="-q" + QUIET_ARGS=(-q) + else + QUIET_ARGS=() fi # ensure GIT_CONFIG is unset as we need to operate on .git/config @@ -316,7 +312,7 @@ EOS cd "$DIR" || continue UPSTREAM_BRANCH="$(upstream_branch)" # the refspec ensures that the default upstream branch gets updated - git fetch $QUIET_ARGS origin \ + git fetch "${QUIET_ARGS[@]}" origin \ "refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" & done
false
Other
Homebrew
brew
eb54a6b5d5b05bfd9cc910a9633c35821c49c98f.json
update-bash: handle option flags like -vd Per @UniqMartin's advice, the original code will fail to handle flags like `-vd`, because once a case is handled, no other cases are evaluate.
Library/Homebrew/cmd/update-bash.sh
@@ -243,9 +243,10 @@ update-bash() { --rebase) HOMEBREW_REBASE=1 ;; --simulate-from-current-branch) HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH=1 ;; --*) ;; - -*v*) HOMEBREW_VERBOSE=1 ;; - -*d*) HOMEBREW_DEBUG=1 ;; - -*) ;; + -*) + [[ "$i" = *v* ]] && HOMEBREW_VERBOSE=1; + [[ "$i" = *d* ]] && HOMEBREW_DEBUG=1; + ;; *) odie <<-EOS This command updates brew itself, and does not take formula names.
false
Other
Homebrew
brew
f7c276a0bee204af223e68a53af13c90674ea356.json
update-bash: fix revision variable setting * only set HOMEBREW_UPDATE_BEFORE inside pull instead of fetch. * fix HOMEBREW_UPDATE_BEFORE/AFTER variable settings. They should be set to INITIAL_REVISION and CURRENT_REVISION correspondingly. * avoid unnecessary duplicated shellout. * remove unused variable.
Library/Homebrew/cmd/update-bash.sh
@@ -176,9 +176,10 @@ pull() { # "brew update --simulate-from-current-branch" if [[ -n "$HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH" ]] then - INITIAL_REVISION="$(git rev-parse -q --verify "$(upstream_branch)")" + INITIAL_REVISION="$(git rev-parse -q --verify "$UPSTREAM_BRANCH")" CURRENT_REVISION="$(read_current_revision)" - export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(git rev-parse "$UPSTREAM_BRANCH")" + export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION" + export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_REVISION" if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION" then odie "Your HEAD is not a descendant of $UPSTREAM_BRANCH!" @@ -199,6 +200,7 @@ pull() { fi INITIAL_REVISION="$(read_current_revision)" + export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION" # ensure we don't munge line endings on checkout git config core.autocrlf false @@ -210,8 +212,7 @@ pull() { git merge --no-edit --ff $QUIET_ARGS "origin/$UPSTREAM_BRANCH" fi - CURRENT_REVISION="$(read_current_revision)" - export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(git rev-parse "$UPSTREAM_BRANCH")" + export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(read_current_revision)" trap '' SIGINT @@ -300,8 +301,6 @@ EOS do [[ -d "$DIR/.git" ]] || continue cd "$DIR" || continue - TAP_VAR=$(repo_var "$DIR") - export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$(git rev-parse "$(upstream_branch)")" UPSTREAM_BRANCH="$(upstream_branch)" # the refspec ensures that the default upstream branch gets updated git fetch $QUIET_ARGS origin \
false
Other
Homebrew
brew
2f52ca9dedae8f4e1fb144d54f9377ced3abd585.json
update-bash: kill all of subprocess on interrupt when fetching
Library/Homebrew/cmd/update-bash.sh
@@ -293,6 +293,9 @@ EOS # this procedure will be removed in the future if it seems unnecessary rename_taps_dir_if_necessary + # kill all of subprocess on interrupt + trap '{ pkill -P $$; wait; exit 130; }' SIGINT + for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* do [[ -d "$DIR/.git" ]] || continue @@ -306,6 +309,7 @@ EOS done wait + trap - SIGINT for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* do
false
Other
Homebrew
brew
fafe8f0f53bf91fc41f016b5c2af41ca712783f7.json
update: implement rename_taps_dir_if_necessary in bash rename_taps_dir_if_necessary must be performed before actual update. Otherwise, it will report that `HOMEBREW_UPDAET_BEFORE<REPO_VAR>` is unset.
Library/Homebrew/cmd/update-bash.sh
@@ -44,6 +44,36 @@ git_init_if_necessary() { fi } +rename_taps_dir_if_necessary() { + local tap_dir + for tap_dir in "$HOMEBREW_LIBRARY"/Taps/* + do + [[ -d "$tap_dir/.git" ]] || continue + local tap_dir_basename + tap_dir_basename="${tap_dir##*/}" + if [[ "$tap_dir_basename" = *"-"* ]] + then + # only replace the *last* dash: yes, tap filenames suck + local user + local repo + user="$(echo "${tap_dir_basename%-*}" | tr "[:upper:]" "[:lower:]")" + repo="$(echo "${tap_dir_basename:${#user}+1}" | tr "[:upper:]" "[:lower:]")" + mkdir -p "$HOMEBREW_LIBRARY/Taps/$user" + mv "$tap_dir", "$HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo" + + if [[ ${#${tap_dir_basename//[^\-]}} -gt 1 ]] + then + echo "Homebrew changed the structure of Taps like <someuser>/<sometap>." >&2 + echo "So you may need to rename $HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo manually." >&2 + fi + else + echo "Homebrew changed the structure of Taps like <someuser>/<sometap>. " >&2 + echo "$tap_dir is an incorrect Tap path." >&2 + echo "So you may need to rename it to $HOMEBREW_LIBRARY/Taps/<someuser>/homebrew-<sometap> manually." >&2 + fi + done +} + repo_var() { local repo_var="$1" if [[ "$repo_var" = "$HOMEBREW_REPOSITORY" ]] @@ -247,6 +277,9 @@ EOS chdir "$HOMEBREW_REPOSITORY" git_init_if_necessary + # rename Taps directories + # this procedure will be removed in the future if it seems unnecessary + rename_taps_dir_if_necessary for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* do
true
Other
Homebrew
brew
fafe8f0f53bf91fc41f016b5c2af41ca712783f7.json
update: implement rename_taps_dir_if_necessary in bash rename_taps_dir_if_necessary must be performed before actual update. Otherwise, it will report that `HOMEBREW_UPDAET_BEFORE<REPO_VAR>` is unset.
Library/Homebrew/cmd/update-report.rb
@@ -23,10 +23,6 @@ def update_report end report.update(master_updater.report) - # rename Taps directories - # this procedure will be removed in the future if it seems unnecessasry - rename_taps_dir_if_necessary - updated_taps = [] Tap.each do |tap| next unless tap.git? @@ -106,34 +102,6 @@ def shorten_revision(revision) `git rev-parse --short #{revision}`.chomp end - def rename_taps_dir_if_necessary - Dir.glob("#{HOMEBREW_LIBRARY}/Taps/*/") do |tapd| - begin - if File.directory?(tapd + "/.git") - tapd_basename = File.basename(tapd) - if tapd_basename.include?("-") - # only replace the *last* dash: yes, tap filenames suck - user, repo = tapd_basename.reverse.sub("-", "/").reverse.split("/") - - FileUtils.mkdir_p("#{HOMEBREW_LIBRARY}/Taps/#{user.downcase}") - FileUtils.mv(tapd, "#{HOMEBREW_LIBRARY}/Taps/#{user.downcase}/homebrew-#{repo.downcase}") - - if tapd_basename.count("-") >= 2 - opoo "Homebrew changed the structure of Taps like <someuser>/<sometap>. "\ - + "So you may need to rename #{HOMEBREW_LIBRARY}/Taps/#{user.downcase}/homebrew-#{repo.downcase} manually." - end - else - opoo "Homebrew changed the structure of Taps like <someuser>/<sometap>. "\ - "#{tapd} is incorrect name format. You may need to rename it like <someuser>/<sometap> manually." - end - end - rescue => ex - onoe ex.message - next # next tap directory - end - end - end - def load_tap_migrations load "tap_migrations.rb" rescue LoadError
true
Other
Homebrew
brew
9cd2658073f642af615f24133db9f02c0df2bb9a.json
update-bash: avoid shellout for stripping prefix
Library/Homebrew/cmd/update-bash.sh
@@ -54,8 +54,8 @@ repo_var() { upstream_branch() { local upstream_branch - upstream_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | - sed -e 's|refs/remotes/origin/||' )" + upstream_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)" + upstream_branch="${upstream_branch#refs/remotes/origin/}" [[ -z "$upstream_branch" ]] && upstream_branch="master" echo "$upstream_branch" }
false
Other
Homebrew
brew
83e13733762fdc728980e57a82cd19979d30141d.json
update-bash: use odie and chdir from bin/brew
Library/Homebrew/cmd/update-bash.sh
@@ -2,6 +2,7 @@ if [[ -z "$HOMEBREW_BREW_FILE" ]] then + # we don't use odie here, because it's only available when this script is called from brew. echo "Error: $(basename "$0") must be called from brew!" >&2 exit 1 fi @@ -134,8 +135,7 @@ pull() { export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(git rev-parse "$UPSTREAM_BRANCH")" if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION" then - echo "Your HEAD is not a descendant of $UPSTREAM_BRANCH!" >&2 - exit 1 + odie "Your HEAD is not a descendant of $UPSTREAM_BRANCH!" fi return fi @@ -183,8 +183,7 @@ pull() { update-bash() { if [[ -z "$HOMEBREW_DEVELOPER" ]] then - echo "This command is currently only for Homebrew developers' use." >&2 - exit 1 + odie "This command is currently only for Homebrew developers' use." fi for i in "$@" @@ -201,9 +200,10 @@ update-bash() { -*d*) HOMEBREW_DEBUG=1 ;; -*) ;; *) - echo "This command updates brew itself, and does not take formula names." >&2 - echo "Use 'brew upgrade <formula>'." >&2 - exit 1 + odie <<-EOS +This command updates brew itself, and does not take formula names. +Use 'brew upgrade <formula>'. +EOS ;; esac done @@ -216,23 +216,20 @@ update-bash() { # check permissions if [[ "$HOMEBREW_PREFIX" = "/usr/local" && ! -w /usr/local ]] then - echo "Error: /usr/local must be writable!" >&2 - exit 1 + odie "/usr/local must be writable!" fi if [[ ! -w "$HOMEBREW_REPOSITORY" ]] then - echo "Error: $HOMEBREW_REPOSITORY must be writable!" >&2 - exit 1 + odie "$HOMEBREW_REPOSITORY must be writable!" fi if [[ -z "$(which_git)" ]] then brew install git if [[ -z "$(which_git)" ]] then - echo "Error: Git must be installed and in your PATH!" >&2 - exit 1 + odie "Git must be installed and in your PATH!" fi fi @@ -244,10 +241,7 @@ update-bash() { # ensure GIT_CONFIG is unset as we need to operate on .git/config unset GIT_CONFIG - cd "$HOMEBREW_REPOSITORY" || { - echo "Error: failed to cd to $HOMEBREW_REPOSITORY!" >&2 - exit 1 - } + chdir "$HOMEBREW_REPOSITORY" git_init_if_necessary for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* @@ -270,11 +264,7 @@ update-bash() { pull "$DIR" done - cd "$HOMEBREW_REPOSITORY" || { - echo "Error: failed to cd to $HOMEBREW_REPOSITORY!" >&2 - exit 1 - } - + chdir "$HOMEBREW_REPOSITORY" brew update-report "$@" return $? }
false
Other
Homebrew
brew
bb5cf70a02e14480408908c998add40193b6bcf9.json
update-bash: fix incorrect argument parsing
Library/Homebrew/cmd/update-bash.sh
@@ -198,7 +198,7 @@ update-bash() { --simulate-from-current-branch) HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH=1 ;; --*) ;; -*v*) HOMEBREW_VERBOSE=1 ;; - -*v*) HOMEBREW_DEBUG=1 ;; + -*d*) HOMEBREW_DEBUG=1 ;; -*) ;; *) echo "This command updates brew itself, and does not take formula names." >&2
false
Other
Homebrew
brew
274640c97a44756f1b4f32cf0adfd540cbce8b1a.json
tests: use unique identifiers w/ integration tests Commands executed during integration testing are executed in a separate process and thus generate a new result set for each command. To avoid that these results override each other, they need to have a unique `command_name`. Derive this name from the test class/name and the index of the command inside that test, resulting in identifiers like `IntegrationCommandTests#test_prefix.1 brew --prefix`. Also replaces `TEST_TMPDIR` in the arguments with `"@TMPDIR@"` to get a cleaner command identifier that is independent of the temporary directory that changes with every run.
Library/Homebrew/test/.simplecov
@@ -13,8 +13,8 @@ SimpleCov.start do add_filter "Homebrew/vendor/" end -if name = ENV["HOMEBREW_INTEGRATION_TEST"] - SimpleCov.command_name "brew #{name}" +if ENV["HOMEBREW_INTEGRATION_TEST"] + SimpleCov.command_name ENV["HOMEBREW_INTEGRATION_TEST"] SimpleCov.at_exit do exit_code = $!.nil? ? 0 : $!.status $stdout.reopen("/dev/null")
true
Other
Homebrew
brew
274640c97a44756f1b4f32cf0adfd540cbce8b1a.json
tests: use unique identifiers w/ integration tests Commands executed during integration testing are executed in a separate process and thus generate a new result set for each command. To avoid that these results override each other, they need to have a unique `command_name`. Derive this name from the test class/name and the index of the command inside that test, resulting in identifiers like `IntegrationCommandTests#test_prefix.1 brew --prefix`. Also replaces `TEST_TMPDIR` in the arguments with `"@TMPDIR@"` to get a cleaner command identifier that is independent of the temporary directory that changes with every run.
Library/Homebrew/test/test_integration_cmds.rb
@@ -4,6 +4,16 @@ require "fileutils" class IntegrationCommandTests < Homebrew::TestCase + def setup + @cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`. + end + + def cmd_id_from_args(args) + args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@") + test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}" + "[#{test_pretty}] brew #{args_pretty}" + end + def cmd_output(*args) # 1.8-compatible way of writing def cmd_output(*args, **env) env = args.last.is_a?(Hash) ? args.pop : {} @@ -18,7 +28,7 @@ def cmd_output(*args) cmd_args += args Bundler.with_original_env do ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew" - ENV["HOMEBREW_INTEGRATION_TEST"] = args.join " " + ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args) ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR env.each_pair { |k,v| ENV[k] = v }
true
Other
Homebrew
brew
a12c5816aa9d80755f65a4fe53e7d55888a914ac.json
tests: remove useless filter for coverage tests The filter for `vendor/bundle/` is useless because this directory is located in `Homebrew/test/` and that one is already filtered. Moreover, SimpleCov already loads the `bundler_filter` profile (that installs basically the same filter) in its default configuration.
Library/Homebrew/test/.simplecov
@@ -7,7 +7,6 @@ SimpleCov.start do coverage_dir File.expand_path("#{tests_path}/coverage") root File.expand_path("#{tests_path}/../../") - add_filter "vendor/bundle/" add_filter "Formula/" add_filter "Homebrew/compat/" add_filter "Homebrew/test/"
false
Other
Homebrew
brew
37e61aed6266e57c55708774743f5ae802bd0aeb.json
build#install: install metafiles in buildpath This came up in https://github.com/Homebrew/homebrew-emacs/pull/158#issuecomment-172031003; `install_metafiles` is passed the current directory, which can be changed during installation by `Dir.chdir`. There may be cases where the metafiles are in a subdirectory, but my guess is those are rare and this is brittle and undocumented behavior anyway.
Library/Homebrew/build.rb
@@ -133,7 +133,7 @@ def install Tab.create(formula, ENV.compiler, stdlibs.first, formula.build, formula.source_modified_time).write # Find and link metafiles - formula.prefix.install_metafiles Pathname.pwd + formula.prefix.install_metafiles formula.buildpath formula.prefix.install_metafiles formula.libexec if formula.libexec.exist? end end
false
Other
Homebrew
brew
2d65caaee9ed1f7a9991451cc71eabe8f7c494cc.json
bin/brew: use not operator inside `[[`
bin/brew
@@ -122,7 +122,7 @@ fi # Many Pathname operations use getwd when they shouldn't, and then throw # odd exceptions. Reduce our support burden by showing a user-friendly error. -if ! [[ -d "$(pwd)" ]] +if [[ ! -d "$(pwd)" ]] then odie "The current working directory doesn't exist, cannot proceed." fi
false
Other
Homebrew
brew
318ce388d75bb87cf2ee9966bfc19f0346460998.json
bin/brew: use full path for xcode-select Closes Homebrew/homebrew#48197. Signed-off-by: Xu Cheng <xucheng@me.com>
bin/brew
@@ -96,7 +96,7 @@ export HOMEBREW_CELLAR if [[ -n "$HOMEBREW_OSX" ]] then - if [[ "$('xcode-select' --print-path)" = "/" ]] + if [[ "$('/usr/bin/xcode-select' --print-path)" = "/" ]] then odie <<EOS Your xcode-select path is currently set to '/'.
false
Other
Homebrew
brew
f51587ee7474a6582d9a44ae54f2a7937b046125.json
brew.rb: fix style problem Generated by `brew style --fix Library/brew.rb`
Library/brew.rb
@@ -82,7 +82,7 @@ def require?(path) end if internal_cmd - Homebrew.send cmd.to_s.gsub("-", "_").downcase + Homebrew.send cmd.to_s.tr("-", "_").downcase elsif which "brew-#{cmd}" %w[CACHE CELLAR LIBRARY_PATH PREFIX REPOSITORY].each do |e| ENV["HOMEBREW_#{e}"] = Object.const_get("HOMEBREW_#{e}").to_s @@ -93,7 +93,7 @@ def require?(path) else require "tap" possible_tap = case cmd - when *%w[brewdle brewdler bundle bundler] + when "brewdle", "brewdler", "bundle", "bundler" Tap.fetch("Homebrew", "bundle") when "cask" Tap.fetch("caskroom", "cask")
false
Other
Homebrew
brew
b324d61f35f9eaee3825817ede071e5e592939e6.json
bin/brew: remove unpin from sudo check list We only need to check sudo for commands which create files.
bin/brew
@@ -140,7 +140,7 @@ HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$1.sh" if [[ "$(id -u)" = "0" && "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ]] then case "$HOMEBREW_COMMAND" in - instal|install|reinstall|postinstall|ln|link|pin|unpin|update|update-bash|upgrade|create|migrate|tap|switch) + instal|install|reinstall|postinstall|ln|link|pin|update|update-bash|upgrade|create|migrate|tap|switch) odie <<EOS Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND' You can use brew with sudo, but only if the brew executable is owned by root.
false
Other
Homebrew
brew
e12e1a5d5d71a250d66e3070f0047dd10278eb38.json
bin/brew: introduce odie function
bin/brew
@@ -1,10 +1,23 @@ #!/bin/bash +odie() { + if [[ -t 2 ]] # check whether stderr is a tty. + then + echo -ne "\033[4;31mError\033[0m: " >&2 # highlight Error with underline and red color + else + echo -n "Error: " >&2 + fi + if [[ $# -eq 0 ]] + then + /bin/cat >&2 + else + echo "$*" >&2 + fi + exit 1 +} + chdir() { - cd "$@" >/dev/null || { - echo "Error: failed to cd to " "$@" "!" >&2 - exit 1 - } + cd "$@" >/dev/null || odie "Error: failed to cd to $*!" } # Force UTF-8 to avoid encoding issues for users with broken locale settings. @@ -46,8 +59,7 @@ esac if [[ "$HOMEBREW_PREFIX" = "/" || "$HOMEBREW_PREFIX" = "/usr" ]] then # it may work, but I only see pain this route and don't want to support it - echo "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" >&2 - exit 1 + odie "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" fi # Users may have these set, pointing the system Ruby @@ -86,36 +98,33 @@ if [[ -n "$HOMEBREW_OSX" ]] then if [[ "$('xcode-select' --print-path)" = "/" ]] then - cat >&2 <<EOS + odie <<EOS Your xcode-select path is currently set to '/'. This causes the 'xcrun' tool to hang, and can render Homebrew unusable. If you are using Xcode, you should: sudo xcode-select -switch /Applications/Xcode.app Otherwise, you should: sudo rm -rf /usr/share/xcode-select EOS - exit 1 fi XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)" XCRUN_STATUS="$?" if [[ "$XCRUN_STATUS" -ne 0 && "$XCRUN_OUTPUT" = *license* ]] then - cat >&2 <<EOS + odie <<EOS You have not agreed to the Xcode license. Please resolve this by running: sudo xcodebuild -license EOS - exit 1 fi fi # Many Pathname operations use getwd when they shouldn't, and then throw # odd exceptions. Reduce our support burden by showing a user-friendly error. if ! [[ -d "$(pwd)" ]] then - echo "The current working directory doesn't exist, cannot proceed." >&2 - exit 1 + odie "The current working directory doesn't exist, cannot proceed." fi if [[ "$1" = -v ]] @@ -132,13 +141,12 @@ if [[ "$(id -u)" = "0" && "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ]] then case "$HOMEBREW_COMMAND" in install|reinstall|postinstall|link|pin|unpin|update|update-bash|upgrade|create|migrate|tap|switch) - cat >&2 <<EOS + odie <<EOS Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND' You can use brew with sudo, but only if the brew executable is owned by root. However, this is both not recommended and completely unsupported so do so at your own risk. EOS - exit 1 ;; esac fi
false
Other
Homebrew
brew
29c50d256741fc54a99aec1f6b9513ecb32ef8f7.json
bin/brew: remove unnecessary check HOMEBREW_BASH_COMMAND variable will always exist. So we only need to check whether the corresponding file exist or not.
bin/brew
@@ -143,7 +143,7 @@ EOS esac fi -if [ -n "$HOMEBREW_BASH_COMMAND" ] && [ -x "$HOMEBREW_BASH_COMMAND" ] +if [ -x "$HOMEBREW_BASH_COMMAND" ] then # source rather than executing directly to ensure the entire file is read into # memory before it is run. This makes running a Bash script behave more like
false
Other
Homebrew
brew
f9b33e26e077a80e85caa1b2434943ab7b55de60.json
brew: remove duplicated logic This is now handled by `bin/brew`
Library/brew.rb
@@ -12,9 +12,6 @@ if ARGV == %w[--version] || ARGV == %w[-v] puts "Homebrew #{Homebrew.homebrew_version_string}" exit 0 -elsif ARGV.first == "-v" - # Shift the -v to the end of the parameter list - ARGV << ARGV.shift end if OS.mac? && MacOS.version < "10.6"
false
Other
Homebrew
brew
92a71a534f9aa956eecc7ebeac0bd5dbe0ca980f.json
os/mac: use start_with? when possible Closes Homebrew/homebrew#48071. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/os/mac.rb
@@ -141,7 +141,7 @@ def gcc_42_build_version @gcc_42_build_version ||= begin gcc = MacOS.locate("gcc-4.2") || HOMEBREW_PREFIX.join("opt/apple-gcc42/bin/gcc-4.2") - if gcc.exist? && gcc.realpath.basename.to_s !~ /^llvm/ + if gcc.exist? && !gcc.realpath.basename.to_s.start_with?("llvm") `#{gcc} --version`[/build (\d{4,})/, 1].to_i end end @@ -150,7 +150,7 @@ def gcc_42_build_version def llvm_build_version @llvm_build_version ||= - if (path = locate("llvm-gcc")) && path.realpath.basename.to_s !~ /^clang/ + if (path = locate("llvm-gcc")) && !path.realpath.basename.to_s.start_with?("clang") `#{path} --version`[/LLVM build (\d{4,})/, 1].to_i end end
true
Other
Homebrew
brew
92a71a534f9aa956eecc7ebeac0bd5dbe0ca980f.json
os/mac: use start_with? when possible Closes Homebrew/homebrew#48071. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/os/mac/xcode.rb
@@ -141,9 +141,9 @@ def provides_cvs? def default_prefix? if version < "4.3" - %r{^/Developer} === prefix + prefix.to_s.start_with? "/Developer" else - %r{^/Applications/Xcode.app} === prefix + prefix.to_s.start_with? "/Applications/Xcode.app" end end end
true
Other
Homebrew
brew
89c63279d43e3103ded9c0cd4c2fcb271435ca5f.json
Remove cleanup --force from bash completion
Library/Contributions/brew_bash_completion.sh
@@ -162,13 +162,6 @@ _brew_bottle () _brew_cleanup () { - local cur="${COMP_WORDS[COMP_CWORD]}" - case "$cur" in - --*) - __brewcomp "--force" - return - ;; - esac __brew_complete_installed }
false
Other
Homebrew
brew
b118539c8c17147e76eed7a0caf44e537f170f43.json
bin/brew: use a function to avoid issues. Otherwise when `bin/brew` is updated in-place Bash will carry on from the offset and this can cause issues. Thanks to `@UniqMartin` for pointing this out.
bin/brew
@@ -156,8 +156,7 @@ then # Hide shellcheck complaint: # shellcheck source=/dev/null source "$HOMEBREW_BASH_COMMAND" - "$HOMEBREW_COMMAND" "$@" - exit $? + { "$HOMEBREW_COMMAND" "$@"; exit $?; } else exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/brew.rb" "$@" fi
false
Other
Homebrew
brew
42681b51f83193f0fb9c178c85e2d1b17926ebd2.json
formula_installer: build formula options better. Previously we got all the options based on the build, any inherited options, any passed options and the tab. We want to make sure that these then exclude any options that don't exist as, otherwise, passing an option that doesn't exist (or has been deleted) is enough to stop a bottle being poured. This was particularly nasty on upgrades where we deleted options and one left in the tab would stop the bottle being poured. Closes Homebrew/homebrew#47891. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Library/Homebrew/formula_installer.rb
@@ -353,6 +353,7 @@ def effective_build_options_for(dependent, inherited_options = []) args = dependent.build.used_options args |= dependent == formula ? options : inherited_options args |= Tab.for_formula(dependent).used_options + args &= dependent.options BuildOptions.new(args, dependent.options) end
false
Other
Homebrew
brew
6f91b429ceee780088b659e519e19262bcfd48cf.json
Move some brew.rb logic to bin/brew.
Library/brew.rb
@@ -4,11 +4,6 @@ HOMEBREW_BREW_FILE = ENV["HOMEBREW_BREW_FILE"] -if ARGV == %w[--prefix] - puts File.dirname(File.dirname(HOMEBREW_BREW_FILE)) - exit 0 -end - require "pathname" HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent.join("Homebrew") $:.unshift(HOMEBREW_LIBRARY_PATH.to_s) @@ -22,49 +17,13 @@ ARGV << ARGV.shift end -if OS.mac? - # Check for bad xcode-select before other checks, because `doctor` and - # many other things will hang. Note that this bug was fixed in 10.9 - if MacOS.version < :mavericks && MacOS.active_developer_dir == "/" - odie <<-EOS.undent - Your xcode-select path is currently set to '/'. - This causes the `xcrun` tool to hang, and can render Homebrew unusable. - If you are using Xcode, you should: - sudo xcode-select -switch /Applications/Xcode.app - Otherwise, you should: - sudo rm -rf /usr/share/xcode-select - EOS - end - - # Check for user agreement of the Xcode license before permitting - # any other brew usage to continue. This prevents the situation where - # people are instructed to "please re-run as root via sudo" on brew commands. - # The check can only fail when Xcode is installed & the active developer dir. - if MacOS::Xcode.installed? && `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success? - odie <<-EOS.undent - You have not agreed to the Xcode license. Please resolve this by running: - sudo xcodebuild -license - EOS - end -end - -case HOMEBREW_PREFIX.to_s -when "/", "/usr" - # it may work, but I only see pain this route and don't want to support it - abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}" -end - if OS.mac? && MacOS.version < "10.6" abort <<-EOABORT.undent Homebrew requires Snow Leopard or higher. For Tiger and Leopard support, see: https://github.com/mistydemeo/tigerbrew EOABORT end -# Many Pathname operations use getwd when they shouldn't, and then throw -# odd exceptions. Reduce our support burden by showing a user-friendly error. -Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed." - def require?(path) require path rescue LoadError => e @@ -94,20 +53,6 @@ def require?(path) cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) - sudo_check = %w[ install reinstall postinstall link pin unpin - update upgrade create migrate tap switch ] - - if sudo_check.include? cmd - if Process.uid.zero? && !File.stat(HOMEBREW_BREW_FILE).uid.zero? - raise <<-EOS.undent - Cowardly refusing to `sudo brew #{cmd}` - You can use brew with sudo, but only if the brew executable is owned by root. - However, this is both not recommended and completely unsupported so do so at - your own risk. - EOS - end - end - # Add contributed commands to PATH before checking. Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/cmd"].each do |tap_cmd_dir| ENV["PATH"] += "#{File::PATH_SEPARATOR}#{tap_cmd_dir}"
true
Other
Homebrew
brew
6f91b429ceee780088b659e519e19262bcfd48cf.json
Move some brew.rb logic to bin/brew.
bin/brew
@@ -37,6 +37,19 @@ else HOMEBREW_CELLAR="$HOMEBREW_REPOSITORY/Cellar" fi +case "$*" in + --prefix) echo "$HOMEBREW_PREFIX"; exit 0 ;; + --cellar) echo "$HOMEBREW_CELLAR"; exit 0 ;; + --repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;; +esac + +if [ "$HOMEBREW_PREFIX" = "/" ] || [ "$HOMEBREW_PREFIX" = "/usr" ] +then + # it may work, but I only see pain this route and don't want to support it + echo "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" >&2 + exit 1 +fi + # Users may have these set, pointing the system Ruby # at non-system gem paths unset GEM_HOME @@ -47,9 +60,14 @@ then unset HOMEBREW_RUBY_PATH fi +if [ "$(uname -s)" = "Darwin" ] +then + HOMEBREW_OSX="1" +fi + if [ -z "$HOMEBREW_RUBY_PATH" ] then - if [ "$(uname -s)" = "Darwin" ] + if [ -n "$HOMEBREW_OSX" ] then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else @@ -64,6 +82,42 @@ export HOMEBREW_REPOSITORY export HOMEBREW_LIBRARY export HOMEBREW_CELLAR +if [ -n "$HOMEBREW_OSX" ] +then + if [ "$('xcode-select' --print-path)" = "/" ] + then + cat >&2 <<EOS +Your xcode-select path is currently set to '/'. +This causes the 'xcrun' tool to hang, and can render Homebrew unusable. +If you are using Xcode, you should: + sudo xcode-select -switch /Applications/Xcode.app +Otherwise, you should: + sudo rm -rf /usr/share/xcode-select +EOS + exit 1 + fi + + XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)" + XCRUN_STATUS="$?" + + if [ "$XCRUN_STATUS" -ne 0 ] && [[ "$XCRUN_OUTPUT" = *license* ]] + then + cat >&2 <<EOS +You have not agreed to the Xcode license. Please resolve this by running: + sudo xcodebuild -license +EOS + exit 1 + fi +fi + +# Many Pathname operations use getwd when they shouldn't, and then throw +# odd exceptions. Reduce our support burden by showing a user-friendly error. +if ! [ -d "$(pwd)" ] +then + echo "The current working directory doesn't exist, cannot proceed." >&2 + exit 1 +fi + for i in "$@" do if [[ "$1" = -v ]] @@ -72,10 +126,26 @@ do set -- "$@" -v fi [[ "$i" =~ ^- ]] && continue + HOMEBREW_COMMAND="$i" HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$i.sh" break done +if [ "$(id -u)" = "0" ] && [ "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ] +then + case "$HOMEBREW_COMMAND" in + install|reinstall|postinstall|link|pin|unpin|update|update-bash|upgrade|create|migrate|tap|switch) + cat >&2 <<EOS +Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND' +You can use brew with sudo, but only if the brew executable is owned by root. +However, this is both not recommended and completely unsupported so do so at +your own risk. +EOS + exit 1 + ;; + esac +fi + if [ -n "$HOMEBREW_BASH_COMMAND" ] && [ -x "$HOMEBREW_BASH_COMMAND" ] then # source rather than executing directly to ensure the entire file is read into
true
Other
Homebrew
brew
effca7d9c60495f7c5c21af637da4e0e2952f66e.json
bin/brew: set more HOMEBREW_* env from Bash.
Library/Homebrew/config.rb
@@ -31,21 +31,16 @@ def mkpath end # Where we link under -HOMEBREW_PREFIX = Pathname.new(HOMEBREW_BREW_FILE).dirname.parent +HOMEBREW_PREFIX = Pathname.new(ENV["HOMEBREW_PREFIX"]) # Where .git is found -HOMEBREW_REPOSITORY = Pathname.new(HOMEBREW_BREW_FILE).realpath.dirname.parent +HOMEBREW_REPOSITORY = Pathname.new(ENV["HOMEBREW_REPOSITORY"]) -HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library" +HOMEBREW_LIBRARY = Pathname.new(ENV["HOMEBREW_LIBRARY"]) HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions" -# Where we store built products; /usr/local/Cellar if it exists, -# otherwise a Cellar relative to the Repository. -HOMEBREW_CELLAR = if (HOMEBREW_PREFIX+"Cellar").exist? - HOMEBREW_PREFIX+"Cellar" -else - HOMEBREW_REPOSITORY+"Cellar" -end +# Where we store built products +HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"]) HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/").expand_path
true
Other
Homebrew
brew
effca7d9c60495f7c5c21af637da4e0e2952f66e.json
bin/brew: set more HOMEBREW_* env from Bash.
bin/brew
@@ -21,7 +21,18 @@ then chdir "$BREW_SYMLINK_DIRECTORY" && pwd -P)" fi -BREW_LIBRARY_DIRECTORY="$(chdir "$BREW_FILE_DIRECTORY"/../Library && pwd -P)" +HOMEBREW_PREFIX="$(chdir "$(dirname "$(dirname "$HOMEBREW_BREW_FILE")")" && pwd -P)" +HOMEBREW_REPOSITORY="$(chdir "$BREW_FILE_DIRECTORY"/../ && pwd -P)" +HOMEBREW_LIBRARY="$(chdir "$BREW_FILE_DIRECTORY"/../Library && pwd -P)" + +# Where we store built products; /usr/local/Cellar if it exists, +# otherwise a Cellar relative to the Repository. +if [ -d "$HOMEBREW_PREFIX/Cellar" ] +then + HOMEBREW_CELLAR="$HOMEBREW_PREFIX/Cellar" +else + HOMEBREW_CELLAR="$HOMEBREW_REPOSITORY/Cellar" +fi # Users may have these set, pointing the system Ruby # at non-system gem paths @@ -45,5 +56,9 @@ fi export HOMEBREW_BREW_FILE export HOMEBREW_RUBY_PATH +export HOMEBREW_PREFIX +export HOMEBREW_REPOSITORY +export HOMEBREW_LIBRARY +export HOMEBREW_CELLAR exec "$HOMEBREW_RUBY_PATH" -W0 "$BREW_LIBRARY_DIRECTORY/brew.rb" "$@"
true
Other
Homebrew
brew
f92fc98ec03fd6b5176f65dd0d0d855925dcf59b.json
test-bot: change directory for git rev-parse --verify
Library/Homebrew/cmd/test-bot.rb
@@ -213,7 +213,7 @@ def initialize(argument, options={}) @repository = @tap.path @skip_homebrew = options.fetch(:skip_homebrew, false) - if quiet_system "git", "rev-parse", "--verify", "-q", argument + if quiet_system "git", "-C", @repository.to_s, "rev-parse", "--verify", "-q", argument @hash = argument elsif url_match = argument.match(HOMEBREW_PULL_OR_COMMIT_URL_REGEX) @url = url_match[0]
false
Other
Homebrew
brew
d4c7dedf1246e31daca2aa9be22f8f6e4a6c528f.json
audit: imporve revision check logic * Check revision decrease against both stable and devel spec. * Check revision reset only for stable spec if stable spec is available.
Library/Homebrew/cmd/audit.rb
@@ -588,8 +588,14 @@ def audit_revision revision_map = fv.revision_map("origin/master") if (revisions = revision_map[formula.version]).any? problem "revision should not decrease" if formula.revision < revisions.max - else - problem "revision should be removed" unless formula.revision == 0 + elsif formula.revision != 0 + if formula.stable + if revision_map[formula.stable.version].empty? # check stable spec + problem "revision should be removed" + end + else # head/devel-only formula + problem "revision should be removed" + end end end
false
Other
Homebrew
brew
b73a6f195af2a29c618f453f55db98329010f385.json
test-bot: remove dead code
Library/Homebrew/cmd/test-bot.rb
@@ -287,12 +287,6 @@ def diff_formulae(start_revision, end_revision, path, filter) end.compact end - def brew_update - return unless current_branch == "master" - success = quiet_system "brew", "update" - success ||= quiet_system "brew", "update" - end - @category = __method__ @start_branch = current_branch
false
Other
Homebrew
brew
4a8632e54d02b8c71ab581f18287a682e1640bcc.json
unpack: preserve file attributes like mtime Closes Homebrew/homebrew#48068. Signed-off-by: Xu Cheng <xucheng@me.com>
Library/Homebrew/cmd/unpack.rb
@@ -28,7 +28,7 @@ def unpack ENV["VERBOSE"] = "1" # show messages about tar f.brew do f.patch if ARGV.flag?("--patch") - cp_r getwd, stage_dir + cp_r getwd, stage_dir, :preserve => true end ENV["VERBOSE"] = nil
false
Other
Homebrew
brew
8deec537d15d35821be4e8e253ad2a877535cbc8.json
test_download_strategies: add mtime test
Library/Homebrew/test/resources/source-with-broken-symlink/broken-link
@@ -1 +0,0 @@ -does-not-exist \ No newline at end of file
true
Other
Homebrew
brew
8deec537d15d35821be4e8e253ad2a877535cbc8.json
test_download_strategies: add mtime test
Library/Homebrew/test/test_bottle.rb
@@ -1,8 +0,0 @@ -require "testing_env" -require "cmd/bottle" - -class BottleTests < Homebrew::TestCase - def test_most_recent_mtime_with_broken_symlink() - refute_nil Homebrew.most_recent_mtime(Pathname(File.join(TEST_DIRECTORY, 'resources/source-with-broken-symlink'))) - end -end
true
Other
Homebrew
brew
8deec537d15d35821be4e8e253ad2a877535cbc8.json
test_download_strategies: add mtime test
Library/Homebrew/test/test_download_strategies.rb
@@ -11,6 +11,8 @@ def initialize(url = "http://example.com/foo.tar.gz", specs = {}) end class AbstractDownloadStrategyTests < Homebrew::TestCase + include FileUtils + def setup @name = "foo" @resource = ResourceDouble.new @@ -34,6 +36,15 @@ def test_expand_safe_system_args_does_not_mutate_argument assert_equal %w[foo bar baz], @args refute_same @args, result end + + def test_source_modified_time + mktemp "mtime" do + touch "foo", :mtime => Time.now - 10 + touch "bar", :mtime => Time.now - 100 + ln_s "not-exist", "baz" + assert_equal File.mtime("foo"), @strategy.source_modified_time + end + end end class VCSDownloadStrategyTests < Homebrew::TestCase
true
Other
Homebrew
brew
7958343f1694a72c8f15b7bf0e00a888fa321996.json
bottle: read source modified time from tabfile * Avoid unnecessary stage overhead * Support different download strategy, e.g. `git`.
Library/Homebrew/cmd/bottle.rb
@@ -140,10 +140,6 @@ def bottle_output(bottle) erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "") end - def most_recent_mtime(pathname) - pathname.to_enum(:find).select(&:exist?).map(&:mtime).max - end - def bottle_formula(f) unless f.installed? return ofail "Formula not installed or up-to-date: #{f.full_name}" @@ -194,10 +190,6 @@ def bottle_formula(f) relocatable = false skip_relocation = false - formula_source_time = f.stable.stage do - most_recent_mtime(Pathname.pwd) - end - keg.lock do original_tab = nil @@ -216,11 +208,11 @@ def bottle_formula(f) tab.time = nil tab.write - keg.find {|k| File.utime(File.atime(k), formula_source_time, k) } + keg.find {|k| File.utime(File.atime(k), tab.source_modified_time, k) } cd cellar do safe_system "tar", "cf", tar_path, "#{f.name}/#{f.pkg_version}" - File.utime(File.atime(tar_path), formula_source_time, tar_path) + File.utime(File.atime(tar_path), tab.source_modified_time, tar_path) relocatable_tar_path = "#{f}-bottle.tar" mv tar_path, relocatable_tar_path # Use gzip, faster to compress than bzip2, faster to uncompress than bzip2
false
Other
Homebrew
brew
fab16b83e94cb38d9f90834c87b7f1604f19f14e.json
tab: add source modified time metadata
Library/Homebrew/tab.rb
@@ -15,14 +15,15 @@ def self.clear_cache CACHE.clear end - def self.create(formula, compiler, stdlib, build) + def self.create(formula, compiler, stdlib, build, source_modified_time) attributes = { "used_options" => build.used_options.as_flags, "unused_options" => build.unused_options.as_flags, "tabfile" => formula.prefix.join(FILENAME), "built_as_bottle" => build.bottle?, "poured_from_bottle" => false, "time" => Time.now.to_i, + "source_modified_time" => source_modified_time.to_i, "HEAD" => Homebrew.git_head, "compiler" => compiler, "stdlib" => stdlib, @@ -43,6 +44,7 @@ def self.from_file(path) def self.from_file_content(content, path) attributes = Utils::JSON.load(content) attributes["tabfile"] = path + attributes["source_modified_time"] ||= 0 attributes["source"] ||= {} tapped_from = attributes["tapped_from"] @@ -133,6 +135,7 @@ def self.empty "built_as_bottle" => false, "poured_from_bottle" => false, "time" => nil, + "source_modified_time" => 0, "HEAD" => nil, "stdlib" => nil, "compiler" => "clang", @@ -214,13 +217,18 @@ def spec source["spec"].to_sym end + def source_modified_time + Time.at(super) + end + def to_json attributes = { "used_options" => used_options.as_flags, "unused_options" => unused_options.as_flags, "built_as_bottle" => built_as_bottle, "poured_from_bottle" => poured_from_bottle, "time" => time, + "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, "stdlib" => (stdlib.to_s if stdlib), "compiler" => (compiler.to_s if compiler),
true
Other
Homebrew
brew
fab16b83e94cb38d9f90834c87b7f1604f19f14e.json
tab: add source modified time metadata
Library/Homebrew/test/test_tab.rb
@@ -7,15 +7,16 @@ def setup @used = Options.create(%w[--with-foo --without-bar]) @unused = Options.create(%w[--with-baz --without-qux]) - @tab = Tab.new("used_options" => @used.as_flags, - "unused_options" => @unused.as_flags, - "built_as_bottle" => false, - "poured_from_bottle" => true, - "time" => nil, - "HEAD" => TEST_SHA1, - "compiler" => "clang", - "stdlib" => "libcxx", - "source" => { + @tab = Tab.new("used_options" => @used.as_flags, + "unused_options" => @unused.as_flags, + "built_as_bottle" => false, + "poured_from_bottle" => true, + "time" => nil, + "source_modified_time" => 0, + "HEAD" => TEST_SHA1, + "compiler" => "clang", + "stdlib" => "libcxx", + "source" => { "tap" => "Homebrew/homebrew", "path" => nil, "spec" => "stable"
true
Other
Homebrew
brew
31da9b266a5eab3bc349d62e7f5cd7cb67741375.json
audit: enforce revision check Add two checks: * revision should be reset to 0 for new version. * revision should not decrease inside the same version interval. Closes Homebrew/homebrew#48032. Signed-off-by: Xu Cheng <xucheng@me.com>
Library/Homebrew/cmd/audit.rb
@@ -1,4 +1,5 @@ require "formula" +require "formula_versions" require "utils" require "extend/ENV" require "formula_cellar_checks" @@ -579,6 +580,19 @@ def audit_specs end end + def audit_revision + return unless formula.tap # skip formula not from core or any taps + return unless formula.tap.git? # git log is required + + fv = FormulaVersions.new(formula) + revision_map = fv.revision_map("origin/master") + if (revisions = revision_map[formula.version]).any? + problem "revision should not decrease" if formula.revision < revisions.max + else + problem "revision should be removed" unless formula.revision == 0 + end + end + def audit_legacy_patches return unless formula.respond_to?(:patches) legacy_patches = Patch.normalize_legacy_patches(formula.patches).grep(LegacyPatch) @@ -932,6 +946,7 @@ def audit audit_formula_name audit_class audit_specs + audit_revision audit_desc audit_homepage audit_bottle_spec
true
Other
Homebrew
brew
31da9b266a5eab3bc349d62e7f5cd7cb67741375.json
audit: enforce revision check Add two checks: * revision should be reset to 0 for new version. * revision should not decrease inside the same version interval. Closes Homebrew/homebrew#48032. Signed-off-by: Xu Cheng <xucheng@me.com>
Library/Homebrew/formula_versions.rb
@@ -54,4 +54,14 @@ def bottle_version_map(branch) end map end + + def revision_map(branch) + map = Hash.new { |h, k| h[k] = [] } + rev_list(branch) do |rev| + formula_at_revision(rev) do |f| + map[f.version] << f.revision + end + end + map + end end
true
Other
Homebrew
brew
159373707b4d8da7f27dbae92585b11674cbd8a2.json
Cookbook: remove ref to obsolete 'def patches'
share/doc/homebrew/Formula-Cookbook.md
@@ -769,7 +769,7 @@ Check if the formula you are updating is a dependency for any other formulae by Homebrew wants to maintain a consistent Ruby style across all formulae based on [Ruby Style Guide](https://github.com/styleguide/ruby). Other formulae may not have been updated to match this guide yet but all new ones should. Also: -* The order of methods in a formula should be consistent with other formulae (e.g.: `def patches` goes before `def install`) +* The order of methods in a formula should be consistent with other formulae (e.g.: `def install` goes before `def post_install`) * An empty line is required before the `__END__` line # Troubleshooting for people writing new formulae
false
Other
Homebrew
brew
07e849e7f4b3dd7cc3e5cb19f0a6d4d1247b63c9.json
Fix built_as_bottle in Formula's to_hash This was caused by a "race" between two commits. bash-3.2$ git log -n1 --format=%ai 3344229 2012-08-15 22:08:40 -0500 bash-3.2$ git log -n1 --format=%ci 3344229 2012-09-17 20:01:37 -0500 bash-3.2$ git log -n1 --format=%ai 8837423 2012-08-25 11:31:57 -0700 bash-3.2$ git log -n1 --format=%ci 8837423 2012-08-25 11:52:37 -0700 "built_bottle" was renamed "built_as_bottle" in 8837423 after the date 3344229 was authored but before the date it was committed to master, and unfortunately in the interim 3344229 hadn't been updated to reflect the name change. This commit changes the Formula class's to_hash method to use tab.built_as_bottle not tab.built_bottle, which doesn't exist. At this time, there is no way that to_hash could have known that tab.built_bottle is bogus. Perhaps this could be made safer in the future, so that non-existent methods cause an error here rather than just silently returning null. Closes Homebrew/homebrew#47912 Closes Homebrew/homebrew#47916. Signed-off-by: Xu Cheng <xucheng@me.com>
Library/Homebrew/formula.rb
@@ -1287,7 +1287,7 @@ def to_hash hsh["installed"] << { "version" => keg.version.to_s, "used_options" => tab.used_options.as_flags, - "built_as_bottle" => tab.built_bottle, + "built_as_bottle" => tab.built_as_bottle, "poured_from_bottle" => tab.poured_from_bottle } end
false
Other
Homebrew
brew
9810c2a412526346797f2f1ef60ddbccddeca2cb.json
test_tap: restore private remote test Only test it if HOMEBREW_GITHUB_API_TOKEN is set.
Library/Homebrew/test/test_tap.rb
@@ -5,7 +5,6 @@ def setup @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" @path.mkpath @tap = Tap.new("Homebrew", "foo") - @tap.stubs(:private?).returns(true) if ENV["HOMEBREW_NO_GITHUB_API"] end def setup_tap_files @@ -116,6 +115,11 @@ def test_remote refute_predicate version_tap, :private? end + def test_private_remote + skip "HOMEBREW_GITHUB_API_TOKEN is required" unless ENV["HOMEBREW_GITHUB_API_TOKEN"] + assert_predicate @tap, :private? + end + def test_install_tap_already_tapped_error assert_raises(TapAlreadyTappedError) { @tap.install } end
false
Other
Homebrew
brew
86cc780ea252881cdda4541c3c251af7995224b0.json
test_tap: remove problematic test `Tap#private?` requires Github API, which can cause problem on Travis CI due to API rate limit.
Library/Homebrew/test/test_tap.rb
@@ -104,7 +104,6 @@ def test_remote assert_equal "https://github.com/Homebrew/homebrew-foo", @tap.remote assert_raises(TapUnavailableError) { Tap.new("Homebrew", "bar").remote } refute_predicate @tap, :custom_remote? - assert_predicate @tap, :private? version_tap = Tap.new("Homebrew", "versions") version_tap.path.mkpath
false
Other
Homebrew
brew
f239a448b2750a2f4df5cf7dd7a0df918b130f17.json
Cookbook: Replace 'onoe' with 'odie' Closes Homebrew/homebrew#47948. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
share/doc/homebrew/Formula-Cookbook.md
@@ -338,7 +338,7 @@ Three commands are provided for displaying informational messages to the user: * `opoo` for warning messages * `odie` for error messages and immediately exiting -In particular, when a test needs to be performed before installation use `onoe` to bail out gracefully. For example: +In particular, when a test needs to be performed before installation use `odie` to bail out gracefully. For example: ```ruby if build.with?("qt") && build.with("qt5")
false
Other
Homebrew
brew
bcedfe64e8ca64e092ca72c3f61fe164c28c8af5.json
doctor: simplify handling of slow checks Some (rather slow) checks should run after all other checks. Make that more obvious by removing them from the sorted list of all checks and then re-appending them to the resulting list. (Should be slightly more efficient than the `<array>.reverse.uniq.reverse` incantation, though that hardly matters given the cumulated run time of all the checks.) Slightly extend the list after verifying what the slowest checks are for various Homebrew installations (slowest check last). Closes Homebrew/homebrew#47753. Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Library/Homebrew/cmd/doctor.rb
@@ -12,9 +12,13 @@ def doctor checks.inject_dump_stats! if ARGV.switch? "D" if ARGV.named.empty? - methods = checks.all.sort - methods << "check_for_linked_keg_only_brews" << "check_for_outdated_homebrew" - methods = methods.reverse.uniq.reverse + slow_checks = %w[ + check_for_broken_symlinks + check_missing_deps + check_for_outdated_homebrew + check_for_linked_keg_only_brews + ] + methods = (checks.all.sort - slow_checks) + slow_checks else methods = ARGV.named end
false
Other
Homebrew
brew
1b4cc77e14401480111cbd5a53e38bead641d8d8.json
requirements: add rbenv requirement
Library/Homebrew/requirements.rb
@@ -66,6 +66,13 @@ class PostgresqlRequirement < Requirement satisfy { which "pg_config" } end +class RbenvRequirement < Requirement + fatal true + default_formula "rbenv" + + satisfy { which "rbenv" } +end + class GPGRequirement < Requirement fatal true default_formula "gpg" @@ -124,4 +131,3 @@ class GitRequirement < Requirement default_formula "git" satisfy { Utils.git_available? } end -
false
Other
Homebrew
brew
7076ed890a1eee10c94791e7557ab16769ab80ef.json
os/mac: add outdated_release? method. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Library/Homebrew/os/mac.rb
@@ -28,6 +28,11 @@ def prerelease? version >= "10.12" end + def outdated_release? + # TODO: bump version when new OS is released + version < "10.9" + end + def cat version.to_sym end
false
Other
Homebrew
brew
6826cd68da17560e8440b880c05741a5820358a6.json
formula_installer: improve empty installation detection Use FormulaAuditor.audit_prefix_has_contents from audit.rb, which has better logic. Closes Homebrew/homebrew#47678. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Library/Homebrew/formula_installer.rb
@@ -8,6 +8,7 @@ require "cleaner" require "formula_cellar_checks" require "install_renamed" +require "cmd/audit" require "cmd/postinstall" require "hooks/bottles" require "debrew" @@ -572,7 +573,11 @@ def build end end - raise "Empty installation" if Dir["#{formula.prefix}/*"].empty? + auditor = FormulaAuditor.new(formula) + auditor.audit_prefix_has_contents + unless formula.prefix.exist? && auditor.problems.empty? + raise "Empty installation" + end rescue Exception ignore_interrupts do
false
Other
Homebrew
brew
91d4ba7158f3d8fc32b2a668cd1153a0d6971087.json
update: abbreviate hashes to at least 7 characters Abbreviations will be longer if needed to preserve uniqueness. This makes it more consistent with `git rev-parse --short`, https://github.com/Homebrew/homebrew/commits, etc. For example, instead of: Updated Homebrew from 40d1e9c2 to 90b9bdf4. We see: Updated Homebrew from 40d1e9c to 90b9bdf. See 0c48248b6555353c8d60b61973639c8423ce586c for the original introduction of eight-character abbreviations.
Library/Homebrew/cmd/update.rb
@@ -41,8 +41,9 @@ def update master_updater.pull! master_updated = master_updater.updated? if master_updated - puts "Updated Homebrew from #{master_updater.initial_revision[0, 8]} " \ - "to #{master_updater.current_revision[0, 8]}." + initial_short = shorten_revision(master_updater.initial_revision) + current_short = shorten_revision(master_updater.current_revision) + puts "Updated Homebrew from #{initial_short} to #{current_short}." end report.update(master_updater.report) @@ -133,6 +134,10 @@ def update private + def shorten_revision(revision) + `git rev-parse --short #{revision}`.chomp + end + def git_init_if_necessary if Dir[".git/*"].empty? safe_system "git", "init"
false
Other
Homebrew
brew
319ea4273e61944b41f033194496cdf6df9fe288.json
list: exclude Ruby from unbrewed Those are created by the `ruby` formula in core and various Ruby formulae from `homebrew/versions` and contain Gems and other stuff that is to be retained across updates. Treat it like Python in this regard. This avoids spurious output in `brew list --unbrewed` when a brewed `ruby` is used to, e.g., install Gems. Closes Homebrew/homebrew#47750. Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Library/Homebrew/cmd/list.rb
@@ -49,6 +49,9 @@ def list lib/python[23].[0-9]/* lib/pypy/* lib/pypy3/* + lib/ruby/gems/[12].* + lib/ruby/site_ruby/[12].* + lib/ruby/vendor_ruby/[12].* share/pypy/* share/pypy3/* share/doc/homebrew/*
false
Other
Homebrew
brew
d6c6f003935dc3d41e794cdcd17642604b295544.json
Common-Issues: add section for upgrading OS X. Closes Homebrew/homebrew#47008. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
share/doc/homebrew/Common-Issues.md
@@ -160,3 +160,17 @@ To list all files that would be deleted: Don't follow the advice here but fix by using `Language::Python.setup_install_args` in the formula as described in [Python for Formula Authors](Python-for-Formula-Authors.md). + +### Upgrading OS X + +Upgrading OS X can cause errors like the following: + +- `dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.54.dylib` +- `configure: error: Cannot find libz` + +Following an OS X upgrade it may be necessary to reinstall the Xcode Command Line Tools and `brew upgrade` all installed formula: + +```bash +xcode-select --install +brew upgrade +```
false
Other
Homebrew
brew
8161595015736d52fcdf4017037155734326e57b.json
manpage: add parentheses in 'search' synopsis For consistency with other commands where there is a list of mutually exclusive options of which exactly one has to be specified.
Library/Homebrew/manpages/brew.1.md
@@ -365,7 +365,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note surrounded with slashes, then it is interpreted as a regular expression. The search for <text> is extended online to some popular taps. - * `search` `--debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu` <text>: + * `search` (`--debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu`) <text>: Search for <text> in the given package manager's list. * `sh` [`--env=std`]:
true
Other
Homebrew
brew
8161595015736d52fcdf4017037155734326e57b.json
manpage: add parentheses in 'search' synopsis For consistency with other commands where there is a list of mutually exclusive options of which exactly one has to be specified.
share/doc/homebrew/brew.1.html
@@ -283,7 +283,7 @@ <h2 id="COMMANDS">COMMANDS</h2> <dt><code>search</code>, <code>-S</code> <var>text</var>|<code>/</code><var>text</var><code>/</code></dt><dd><p>Perform a substring search of formula names for <var>text</var>. If <var>text</var> is surrounded with slashes, then it is interpreted as a regular expression. The search for <var>text</var> is extended online to some popular taps.</p></dd> -<dt><code>search</code> <code>--debian</code>|<code>--fedora</code>|<code>--fink</code>|<code>--macports</code>|<code>--opensuse</code>|<code>--ubuntu</code> <var>text</var></dt><dd><p>Search for <var>text</var> in the given package manager's list.</p></dd> +<dt><code>search</code> (<code>--debian</code>|<code>--fedora</code>|<code>--fink</code>|<code>--macports</code>|<code>--opensuse</code>|<code>--ubuntu</code>) <var>text</var></dt><dd><p>Search for <var>text</var> in the given package manager's list.</p></dd> <dt><code>sh</code> [<code>--env=std</code>]</dt><dd><p>Instantiate a Homebrew build environment. Uses our years-battle-hardened Homebrew build logic to help your <code>./configure &amp;&amp; make &amp;&amp; make install</code> or even your <code>gem install</code> succeed. Especially handy if you run Homebrew
true
Other
Homebrew
brew
8161595015736d52fcdf4017037155734326e57b.json
manpage: add parentheses in 'search' synopsis For consistency with other commands where there is a list of mutually exclusive options of which exactly one has to be specified.
share/man/man1/brew.1
@@ -390,7 +390,7 @@ Display all locally available formulae for brewing (including tapped ones)\. No Perform a substring search of formula names for \fItext\fR\. If \fItext\fR is surrounded with slashes, then it is interpreted as a regular expression\. The search for \fItext\fR is extended online to some popular taps\. . .TP -\fBsearch\fR \fB\-\-debian\fR|\fB\-\-fedora\fR|\fB\-\-fink\fR|\fB\-\-macports\fR|\fB\-\-opensuse\fR|\fB\-\-ubuntu\fR \fItext\fR +\fBsearch\fR (\fB\-\-debian\fR|\fB\-\-fedora\fR|\fB\-\-fink\fR|\fB\-\-macports\fR|\fB\-\-opensuse\fR|\fB\-\-ubuntu\fR) \fItext\fR Search for \fItext\fR in the given package manager\'s list\. . .TP
true
Other
Homebrew
brew
b3627cc5b2893f33984b9fee9648c415ff350b5c.json
manpage: fix minor formatting inconsistencies
Library/Homebrew/manpages/brew.1.md
@@ -190,7 +190,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note To view formula history locally: `brew log -p <formula>`. - * `info --json=`<version> (`--all`|`--installed`|<formulae>): + * `info` `--json=`<version> (`--all`|`--installed`|<formulae>): Print a JSON representation of <formulae>. Currently the only accepted value for <version> is `v1`. @@ -240,7 +240,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note To install a newer version of HEAD use `brew rm <foo> && brew install --HEAD <foo>`. - * `install --interactive` [`--git`] <formula>: + * `install` `--interactive` [`--git`] <formula>: Download and patch <formula>, then open a shell. This allows the user to run `./configure --help` and otherwise determine how to turn the software package into a Homebrew formula. @@ -284,7 +284,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note List all installed formulae. If `--full-name` is passed, print formulae with full-qualified names. - * `ls`, `list --unbrewed`: + * `ls`, `list` `--unbrewed`: List all files in the Homebrew prefix not installed by Homebrew. * `ls`, `list` [`--versions` [`--multiple`]] [`--pinned`] [<formulae>]: @@ -365,7 +365,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note surrounded with slashes, then it is interpreted as a regular expression. The search for <text> is extended online to some popular taps. - * `search --debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu` <text>: + * `search` `--debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu` <text>: Search for <text> in the given package manager's list. * `sh` [`--env=std`]: @@ -397,13 +397,13 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note By default, the repository is cloned as a shallow copy (`--depth=1`), but if `--full` is passed, a full clone will be used. - * `tap --repair`: + * `tap` `--repair`: Migrate tapped formulae from symlink-based to directory-based structure. - * `tap --list-official`: + * `tap` `--list-official`: List all official taps. - * `tap --list-pinned`: + * `tap` `--list-pinned`: List all pinned taps. * `tap-info` <tap>:
true
Other
Homebrew
brew
b3627cc5b2893f33984b9fee9648c415ff350b5c.json
manpage: fix minor formatting inconsistencies
share/doc/homebrew/brew.1.html
@@ -150,7 +150,7 @@ <h2 id="COMMANDS">COMMANDS</h2> <dt><code>info</code> <code>--github</code> <var>formula</var></dt><dd><p>Open a browser to the GitHub History page for formula <var>formula</var>.</p> <p>To view formula history locally: <code>brew log -p &lt;formula></code>.</p></dd> -<dt><code>info --json=</code><var>version</var> (<code>--all</code>|<code>--installed</code>|<var>formulae</var>)</dt><dd><p>Print a JSON representation of <var>formulae</var>. Currently the only accepted value +<dt><code>info</code> <code>--json=</code><var>version</var> (<code>--all</code>|<code>--installed</code>|<var>formulae</var>)</dt><dd><p>Print a JSON representation of <var>formulae</var>. Currently the only accepted value for <var>version</var> is <code>v1</code>.</p> <p>Pass <code>--all</code> to get information on all formulae, or <code>--installed</code> to get @@ -196,7 +196,7 @@ <h2 id="COMMANDS">COMMANDS</h2> <p>To install a newer version of HEAD use <code>brew rm &lt;foo> &amp;&amp; brew install --HEAD &lt;foo></code>.</p></dd> -<dt><code>install --interactive</code> [<code>--git</code>] <var>formula</var></dt><dd><p>Download and patch <var>formula</var>, then open a shell. This allows the user to +<dt><code>install</code> <code>--interactive</code> [<code>--git</code>] <var>formula</var></dt><dd><p>Download and patch <var>formula</var>, then open a shell. This allows the user to run <code>./configure --help</code> and otherwise determine how to turn the software package into a Homebrew formula.</p> @@ -228,7 +228,7 @@ <h2 id="COMMANDS">COMMANDS</h2> directory instead of the system directory. It may need to be created, first.</p></dd> <dt><code>ls</code>, <code>list</code> [<code>--full-name</code>]</dt><dd><p>List all installed formulae. If <code>--full-name</code> is passed, print formulae with full-qualified names.</p></dd> -<dt><code>ls</code>, <code>list --unbrewed</code></dt><dd><p>List all files in the Homebrew prefix not installed by Homebrew.</p></dd> +<dt><code>ls</code>, <code>list</code> <code>--unbrewed</code></dt><dd><p>List all files in the Homebrew prefix not installed by Homebrew.</p></dd> <dt><code>ls</code>, <code>list</code> [<code>--versions</code> [<code>--multiple</code>]] [<code>--pinned</code>] [<var>formulae</var>]</dt><dd><p>List the installed files for <var>formulae</var>. Combined with <code>--verbose</code>, recursively list the contents of all subdirectories in each <var>formula</var>'s keg.</p> @@ -283,7 +283,7 @@ <h2 id="COMMANDS">COMMANDS</h2> <dt><code>search</code>, <code>-S</code> <var>text</var>|<code>/</code><var>text</var><code>/</code></dt><dd><p>Perform a substring search of formula names for <var>text</var>. If <var>text</var> is surrounded with slashes, then it is interpreted as a regular expression. The search for <var>text</var> is extended online to some popular taps.</p></dd> -<dt><code>search --debian</code>|<code>--fedora</code>|<code>--fink</code>|<code>--macports</code>|<code>--opensuse</code>|<code>--ubuntu</code> <var>text</var></dt><dd><p>Search for <var>text</var> in the given package manager's list.</p></dd> +<dt><code>search</code> <code>--debian</code>|<code>--fedora</code>|<code>--fink</code>|<code>--macports</code>|<code>--opensuse</code>|<code>--ubuntu</code> <var>text</var></dt><dd><p>Search for <var>text</var> in the given package manager's list.</p></dd> <dt><code>sh</code> [<code>--env=std</code>]</dt><dd><p>Instantiate a Homebrew build environment. Uses our years-battle-hardened Homebrew build logic to help your <code>./configure &amp;&amp; make &amp;&amp; make install</code> or even your <code>gem install</code> succeed. Especially handy if you run Homebrew @@ -305,9 +305,9 @@ <h2 id="COMMANDS">COMMANDS</h2> <p>By default, the repository is cloned as a shallow copy (<code>--depth=1</code>), but if <code>--full</code> is passed, a full clone will be used.</p></dd> -<dt><code>tap --repair</code></dt><dd><p>Migrate tapped formulae from symlink-based to directory-based structure.</p></dd> -<dt><code>tap --list-official</code></dt><dd><p>List all official taps.</p></dd> -<dt><code>tap --list-pinned</code></dt><dd><p>List all pinned taps.</p></dd> +<dt><code>tap</code> <code>--repair</code></dt><dd><p>Migrate tapped formulae from symlink-based to directory-based structure.</p></dd> +<dt><code>tap</code> <code>--list-official</code></dt><dd><p>List all official taps.</p></dd> +<dt><code>tap</code> <code>--list-pinned</code></dt><dd><p>List all pinned taps.</p></dd> <dt><code>tap-info</code> <var>tap</var></dt><dd><p>Display information about <var>tap</var>.</p></dd> <dt><code>tap-info</code> <code>--json=</code><var>version</var> (<code>--installed</code>|<var>taps</var>)</dt><dd><p>Print a JSON representation of <var>taps</var>. Currently the only accepted value for <var>version</var> is <code>v1</code>.</p>
true
Other
Homebrew
brew
b3627cc5b2893f33984b9fee9648c415ff350b5c.json
manpage: fix minor formatting inconsistencies
share/man/man1/brew.1
@@ -207,7 +207,7 @@ Open a browser to the GitHub History page for formula \fIformula\fR\. To view formula history locally: \fBbrew log \-p <formula>\fR\. . .TP -\fBinfo \-\-json=\fR\fIversion\fR (\fB\-\-all\fR|\fB\-\-installed\fR|\fIformulae\fR) +\fBinfo\fR \fB\-\-json=\fR\fIversion\fR (\fB\-\-all\fR|\fB\-\-installed\fR|\fIformulae\fR) Print a JSON representation of \fIformulae\fR\. Currently the only accepted value for \fIversion\fR is \fBv1\fR\. . .IP @@ -257,7 +257,7 @@ If \fB\-\-HEAD\fR is passed, and \fIformula\fR defines it, install the HEAD vers To install a newer version of HEAD use \fBbrew rm <foo> && brew install \-\-HEAD <foo>\fR\. . .TP -\fBinstall \-\-interactive\fR [\fB\-\-git\fR] \fIformula\fR +\fBinstall\fR \fB\-\-interactive\fR [\fB\-\-git\fR] \fIformula\fR Download and patch \fIformula\fR, then open a shell\. This allows the user to run \fB\./configure \-\-help\fR and otherwise determine how to turn the software package into a Homebrew formula\. . .IP @@ -302,7 +302,7 @@ If provided, \fB\-\-local\fR will move them into the user\'s \fB~/Applications\f List all installed formulae\. If \fB\-\-full\-name\fR is passed, print formulae with full\-qualified names\. . .TP -\fBls\fR, \fBlist \-\-unbrewed\fR +\fBls\fR, \fBlist\fR \fB\-\-unbrewed\fR List all files in the Homebrew prefix not installed by Homebrew\. . .TP @@ -390,7 +390,7 @@ Display all locally available formulae for brewing (including tapped ones)\. No Perform a substring search of formula names for \fItext\fR\. If \fItext\fR is surrounded with slashes, then it is interpreted as a regular expression\. The search for \fItext\fR is extended online to some popular taps\. . .TP -\fBsearch \-\-debian\fR|\fB\-\-fedora\fR|\fB\-\-fink\fR|\fB\-\-macports\fR|\fB\-\-opensuse\fR|\fB\-\-ubuntu\fR \fItext\fR +\fBsearch\fR \fB\-\-debian\fR|\fB\-\-fedora\fR|\fB\-\-fink\fR|\fB\-\-macports\fR|\fB\-\-opensuse\fR|\fB\-\-ubuntu\fR \fItext\fR Search for \fItext\fR in the given package manager\'s list\. . .TP @@ -419,15 +419,15 @@ With \fIURL\fR specified, taps a formula repository from anywhere, using any tra By default, the repository is cloned as a shallow copy (\fB\-\-depth=1\fR), but if \fB\-\-full\fR is passed, a full clone will be used\. . .TP -\fBtap \-\-repair\fR +\fBtap\fR \fB\-\-repair\fR Migrate tapped formulae from symlink\-based to directory\-based structure\. . .TP -\fBtap \-\-list\-official\fR +\fBtap\fR \fB\-\-list\-official\fR List all official taps\. . .TP -\fBtap \-\-list\-pinned\fR +\fBtap\fR \fB\-\-list\-pinned\fR List all pinned taps\. . .TP
true
Other
Homebrew
brew
aaefcb02b6649551d8a86a5f0237041c14113dfb.json
manpage: improve synopsis for 'options' command The options `--all`, `--installed`, and a list of formulae are mutually exclusive arguments, of which exactly one is required.
Library/Homebrew/manpages/brew.1.md
@@ -315,8 +315,8 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--force` is passed, then treat installed <formulae> and passed <formulae> like if they are from same taps and migrate them anyway. - * `options` [`--compact`] [`--all`] [`--installed`] <formula>: - Display install options specific to <formula>. + * `options` [`--compact`] (`--all`|`--installed`|<formulae>): + Display install options specific to <formulae>. If `--compact` is passed, show all options on a single line separated by spaces.
true
Other
Homebrew
brew
aaefcb02b6649551d8a86a5f0237041c14113dfb.json
manpage: improve synopsis for 'options' command The options `--all`, `--installed`, and a list of formulae are mutually exclusive arguments, of which exactly one is required.
share/doc/homebrew/brew.1.html
@@ -249,7 +249,7 @@ <h2 id="COMMANDS">COMMANDS</h2> <p>If <code>--force</code> is passed, then treat installed <var>formulae</var> and passed <var>formulae</var> like if they are from same taps and migrate them anyway.</p></dd> -<dt><code>options</code> [<code>--compact</code>] [<code>--all</code>] [<code>--installed</code>] <var>formula</var></dt><dd><p>Display install options specific to <var>formula</var>.</p> +<dt><code>options</code> [<code>--compact</code>] (<code>--all</code>|<code>--installed</code>|<var>formulae</var>)</dt><dd><p>Display install options specific to <var>formulae</var>.</p> <p>If <code>--compact</code> is passed, show all options on a single line separated by spaces.</p>
true
Other
Homebrew
brew
aaefcb02b6649551d8a86a5f0237041c14113dfb.json
manpage: improve synopsis for 'options' command The options `--all`, `--installed`, and a list of formulae are mutually exclusive arguments, of which exactly one is required.
share/man/man1/brew.1
@@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "December 2015" "Homebrew" "brew" +.TH "BREW" "1" "January 2016" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The missing package manager for OS X @@ -334,8 +334,8 @@ Migrate renamed packages to new name, where \fIformulae\fR are old names of pack If \fB\-\-force\fR is passed, then treat installed \fIformulae\fR and passed \fIformulae\fR like if they are from same taps and migrate them anyway\. . .TP -\fBoptions\fR [\fB\-\-compact\fR] [\fB\-\-all\fR] [\fB\-\-installed\fR] \fIformula\fR -Display install options specific to \fIformula\fR\. +\fBoptions\fR [\fB\-\-compact\fR] (\fB\-\-all\fR|\fB\-\-installed\fR|\fIformulae\fR) +Display install options specific to \fIformulae\fR\. . .IP If \fB\-\-compact\fR is passed, show all options on a single line separated by spaces\.
true
Other
Homebrew
brew
a508f9f94b55089d2e37e4f0b0869bd0e425d40c.json
Revert "formula: pass sdk_path in std_cmake_args" This reverts commit 5896555e5352b5e4f16f583ea444942cd1fc56bd. It caused header-location issue on dual-developer-tool systems for certain formulae. Will need looking at again, but we'll probably have to try and do this a different way. Closes Homebrew/homebrew#47668.
Library/Homebrew/formula.rb
@@ -1047,7 +1047,6 @@ def std_cmake_args -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON - -DCMAKE_OSX_SYSROOT=#{MacOS.sdk_path} -Wno-dev ] end
false
Other
Homebrew
brew
0472b3f34048b7396631d33d4e1cda506ce1a5b1.json
doctor: use respond_to? instead of NoMethodError Closes Homebrew/homebrew#47715. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/doctor.rb
@@ -21,13 +21,13 @@ def doctor first_warning = true methods.each do |method| - begin - out = checks.send(method) - rescue NoMethodError + unless checks.respond_to?(method) Homebrew.failed = true puts "No check available by the name: #{method}" next end + + out = checks.send(method) unless out.nil? || out.empty? if first_warning $stderr.puts <<-EOS.undent
false
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/doctor.rb
@@ -1,1318 +1,15 @@ -require "cmd/missing" -require "formula" -require "keg" -require "language/python" -require "version" - -class Volumes - def initialize - @volumes = get_mounts - end - - def which(path) - vols = get_mounts path - - # no volume found - if vols.empty? - return -1 - end - - vol_index = @volumes.index(vols[0]) - # volume not found in volume list - if vol_index.nil? - return -1 - end - vol_index - end - - def get_mounts(path = nil) - vols = [] - # get the volume of path, if path is nil returns all volumes - - args = %w[/bin/df -P] - args << path if path - - Utils.popen_read(*args) do |io| - io.each_line do |line| - case line.chomp - # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / - when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ - vols << $1 - end - end - end - vols - end -end - -class Checks - ############# HELPERS - # Finds files in HOMEBREW_PREFIX *and* /usr/local. - # Specify paths relative to a prefix eg. "include/foo.h". - # Sets @found for your convenience. - def find_relative_paths(*relative_paths) - @found = %W[#{HOMEBREW_PREFIX} /usr/local].uniq.inject([]) do |found, prefix| - found + relative_paths.map { |f| File.join(prefix, f) }.select { |f| File.exist? f } - end - end - - def inject_file_list(list, str) - list.inject(str) { |s, f| s << " #{f}\n" } - end - ############# END HELPERS - - # Sorry for the lack of an indent here, the diff would have been unreadable. - # See https://github.com/Homebrew/homebrew/pull/9986 - def check_path_for_trailing_slashes - bad_paths = ENV["PATH"].split(File::PATH_SEPARATOR).select { |p| p[-1..-1] == "/" } - return if bad_paths.empty? - inject_file_list bad_paths, <<-EOS.undent - Some directories in your path end in a slash. - Directories in your path should not end in a slash. This can break other - doctor checks. The following directories should be edited: - EOS - end - - # Installing MacGPG2 interferes with Homebrew in a big way - # https://github.com/GPGTools/MacGPG2 - def check_for_macgpg2 - return if File.exist? "/usr/local/MacGPG2/share/gnupg/VERSION" - - suspects = %w[ - /Applications/start-gpg-agent.app - /Library/Receipts/libiconv1.pkg - /usr/local/MacGPG2 - ] - - if suspects.any? { |f| File.exist? f } then <<-EOS.undent - You may have installed MacGPG2 via the package installer. - Several other checks in this script will turn up problems, such as stray - dylibs in /usr/local and permissions issues with share and man in /usr/local/. - EOS - end - end - - # Anaconda installs multiple system & brew dupes, including OpenSSL, Python, - # sqlite, libpng, Qt, etc. Regularly breaks compile on Vim, MacVim and others. - # Is flagged as part of the *-config script checks below, but people seem - # to ignore those as warnings rather than extremely likely breakage. - def check_for_anaconda - return unless which("anaconda") - return unless which("python") - - anaconda = which("anaconda").realpath.dirname - python_binary = Utils.popen_read which("python"), "-c", "import sys; sys.stdout.write(sys.executable)" - python = Pathname.new(python_binary).realpath.dirname - - # Only warn if Python lives with Anaconda, since is most problematic case. - if python == anaconda then <<-EOS.undent - Anaconda is known to frequently break Homebrew builds, including Vim and - MacVim, due to bundling many duplicates of system and Homebrew-available - tools. - - If you encounter a build failure please temporarily remove Anaconda - from your $PATH and attempt the build again prior to reporting the - failure to us. Thanks! - EOS - end - end - - def __check_stray_files(dir, pattern, white_list, message) - return unless File.directory?(dir) - - files = Dir.chdir(dir) do - Dir[pattern].select { |f| File.file?(f) && !File.symlink?(f) } - Dir.glob(white_list) - end.map { |file| File.join(dir, file) } - - inject_file_list(files, message) unless files.empty? - end - - def check_for_stray_dylibs - # Dylibs which are generally OK should be added to this list, - # with a short description of the software they come with. - white_list = [ - "libfuse.2.dylib", # MacFuse - "libfuse_ino64.2.dylib", # MacFuse - "libmacfuse_i32.2.dylib", # OSXFuse MacFuse compatibility layer - "libmacfuse_i64.2.dylib", # OSXFuse MacFuse compatibility layer - "libosxfuse_i32.2.dylib", # OSXFuse - "libosxfuse_i64.2.dylib", # OSXFuse - "libTrAPI.dylib", # TrAPI / Endpoint Security VPN - "libntfs-3g.*.dylib", # NTFS-3G - "libntfs.*.dylib", # NTFS-3G - "libublio.*.dylib", # NTFS-3G - "libUFSDNTFS.dylib", # Paragon NTFS - "libUFSDExtFS.dylib", # Paragon ExtFS - ] - - __check_stray_files "/usr/local/lib", "*.dylib", white_list, <<-EOS.undent - Unbrewed dylibs were found in /usr/local/lib. - If you didn't put them there on purpose they could cause problems when - building Homebrew formulae, and may need to be deleted. - - Unexpected dylibs: - EOS - end - - def check_for_stray_static_libs - # Static libs which are generally OK should be added to this list, - # with a short description of the software they come with. - white_list = [ - "libsecurity_agent_client.a", # OS X 10.8.2 Supplemental Update - "libsecurity_agent_server.a", # OS X 10.8.2 Supplemental Update - "libntfs-3g.a", # NTFS-3G - "libntfs.a", # NTFS-3G - "libublio.a", # NTFS-3G - ] - - __check_stray_files "/usr/local/lib", "*.a", white_list, <<-EOS.undent - Unbrewed static libraries were found in /usr/local/lib. - If you didn't put them there on purpose they could cause problems when - building Homebrew formulae, and may need to be deleted. - - Unexpected static libraries: - EOS - end - - def check_for_stray_pcs - # Package-config files which are generally OK should be added to this list, - # with a short description of the software they come with. - white_list = [ - "fuse.pc", # OSXFuse/MacFuse - "macfuse.pc", # OSXFuse MacFuse compatibility layer - "osxfuse.pc", # OSXFuse - "libntfs-3g.pc", # NTFS-3G - "libublio.pc", # NTFS-3G - ] - - __check_stray_files "/usr/local/lib/pkgconfig", "*.pc", white_list, <<-EOS.undent - Unbrewed .pc files were found in /usr/local/lib/pkgconfig. - If you didn't put them there on purpose they could cause problems when - building Homebrew formulae, and may need to be deleted. - - Unexpected .pc files: - EOS - end - - def check_for_stray_las - white_list = [ - "libfuse.la", # MacFuse - "libfuse_ino64.la", # MacFuse - "libosxfuse_i32.la", # OSXFuse - "libosxfuse_i64.la", # OSXFuse - "libntfs-3g.la", # NTFS-3G - "libntfs.la", # NTFS-3G - "libublio.la", # NTFS-3G - ] - - __check_stray_files "/usr/local/lib", "*.la", white_list, <<-EOS.undent - Unbrewed .la files were found in /usr/local/lib. - If you didn't put them there on purpose they could cause problems when - building Homebrew formulae, and may need to be deleted. - - Unexpected .la files: - EOS - end - - def check_for_stray_headers - white_list = [ - "fuse.h", # MacFuse - "fuse/**/*.h", # MacFuse - "macfuse/**/*.h", # OSXFuse MacFuse compatibility layer - "osxfuse/**/*.h", # OSXFuse - "ntfs/**/*.h", # NTFS-3G - "ntfs-3g/**/*.h", # NTFS-3G - ] - - __check_stray_files "/usr/local/include", "**/*.h", white_list, <<-EOS.undent - Unbrewed header files were found in /usr/local/include. - If you didn't put them there on purpose they could cause problems when - building Homebrew formulae, and may need to be deleted. - - Unexpected header files: - EOS - end - - def check_for_other_package_managers - ponk = MacOS.macports_or_fink - unless ponk.empty? - <<-EOS.undent - You have MacPorts or Fink installed: - #{ponk.join(", ")} - - This can cause trouble. You don't have to uninstall them, but you may want to - temporarily move them out of the way, e.g. - - sudo mv /opt/local ~/macports - EOS - end - end - - def check_for_broken_symlinks - broken_symlinks = [] - - Keg::PRUNEABLE_DIRECTORIES.each do |d| - next unless d.directory? - d.find do |path| - if path.symlink? && !path.resolved_path_exists? - broken_symlinks << path - end - end - end - return if broken_symlinks.empty? - inject_file_list broken_symlinks, <<-EOS.undent - Broken symlinks were found. Remove them with `brew prune`: - EOS - end - - def check_for_unsupported_osx - if !ARGV.homebrew_developer? && OS::Mac.prerelease? then <<-EOS.undent - You are using OS X #{MacOS.version}. - We do not provide support for this pre-release version. - You may encounter build failures or other breakages. - EOS - end - end - - # TODO: distill down into single method definition a la BuildToolsError - if MacOS.version >= "10.9" - def check_for_installed_developer_tools - unless MacOS::Xcode.installed? || MacOS::CLT.installed? then <<-EOS.undent - No developer tools installed. - Install the Command Line Tools: - xcode-select --install - EOS - end - end - - if OS::Mac.prerelease? - def check_xcode_up_to_date - if MacOS::Xcode.installed? && MacOS::Xcode.outdated? - <<-EOS.undent - Your Xcode (#{MacOS::Xcode.version}) is outdated - Please update to Xcode #{MacOS::Xcode.latest_version}. - Xcode can be updated from - https://developer.apple.com/xcode/downloads/ - EOS - end - end - else - def check_xcode_up_to_date - if MacOS::Xcode.installed? && MacOS::Xcode.outdated? - <<-EOS.undent - Your Xcode (#{MacOS::Xcode.version}) is outdated - Please update to Xcode #{MacOS::Xcode.latest_version}. - Xcode can be updated from the App Store. - EOS - end - end - end - - def check_clt_up_to_date - if MacOS::CLT.installed? && MacOS::CLT.outdated? then <<-EOS.undent - A newer Command Line Tools release is available. - Update them from Software Update in the App Store. - EOS - end - end - elsif MacOS.version == "10.8" || MacOS.version == "10.7" - def check_for_installed_developer_tools - unless MacOS::Xcode.installed? || MacOS::CLT.installed? then <<-EOS.undent - No developer tools installed. - You should install the Command Line Tools. - The standalone package can be obtained from - https://developer.apple.com/downloads - or it can be installed via Xcode's preferences. - EOS - end - end - - def check_xcode_up_to_date - if MacOS::Xcode.installed? && MacOS::Xcode.outdated? then <<-EOS.undent - Your Xcode (#{MacOS::Xcode.version}) is outdated - Please update to Xcode #{MacOS::Xcode.latest_version}. - Xcode can be updated from - https://developer.apple.com/xcode/downloads/ - EOS - end - end - - def check_clt_up_to_date - if MacOS::CLT.installed? && MacOS::CLT.outdated? then <<-EOS.undent - A newer Command Line Tools release is available. - The standalone package can be obtained from - https://developer.apple.com/downloads - or it can be installed via Xcode's preferences. - EOS - end - end - else - def check_for_installed_developer_tools - unless MacOS::Xcode.installed? then <<-EOS.undent - Xcode is not installed. Most formulae need Xcode to build. - It can be installed from - https://developer.apple.com/xcode/downloads/ - EOS - end - end - - def check_xcode_up_to_date - if MacOS::Xcode.installed? && MacOS::Xcode.outdated? then <<-EOS.undent - Your Xcode (#{MacOS::Xcode.version}) is outdated - Please update to Xcode #{MacOS::Xcode.latest_version}. - Xcode can be updated from - https://developer.apple.com/xcode/downloads/ - EOS - end - end - end - - def check_for_osx_gcc_installer - if (MacOS.version < "10.7" || MacOS::Xcode.version > "4.1") && \ - MacOS.clang_version == "2.1" - message = <<-EOS.undent - You seem to have osx-gcc-installer installed. - Homebrew doesn't support osx-gcc-installer. It causes many builds to fail and - is an unlicensed distribution of really old Xcode files. - EOS - if MacOS.version >= :mavericks - message += <<-EOS.undent - Please run `xcode-select --install` to install the CLT. - EOS - elsif MacOS.version >= :lion - message += <<-EOS.undent - Please install the CLT or Xcode #{MacOS::Xcode.latest_version}. - EOS - else - message += <<-EOS.undent - Please install Xcode #{MacOS::Xcode.latest_version}. - EOS - end - end - end - - def check_for_stray_developer_directory - # if the uninstaller script isn't there, it's a good guess neither are - # any troublesome leftover Xcode files - uninstaller = Pathname.new("/Developer/Library/uninstall-developer-folder") - if MacOS::Xcode.version >= "4.3" && uninstaller.exist? then <<-EOS.undent - You have leftover files from an older version of Xcode. - You should delete them using: - #{uninstaller} - EOS - end - end - - def check_for_bad_install_name_tool - return if MacOS.version < "10.9" - - libs = Pathname.new("/usr/bin/install_name_tool").dynamically_linked_libraries - - # otool may not work, for example if the Xcode license hasn't been accepted yet - return if libs.empty? - - unless libs.include? "/usr/lib/libxcselect.dylib" then <<-EOS.undent - You have an outdated version of /usr/bin/install_name_tool installed. - This will cause binary package installations to fail. - This can happen if you install osx-gcc-installer or RailsInstaller. - To restore it, you must reinstall OS X or restore the binary from - the OS packages. - EOS - end - end - - def __check_subdir_access(base) - target = HOMEBREW_PREFIX+base - return unless target.exist? - - cant_read = [] - - target.find do |d| - next unless d.directory? - cant_read << d unless d.writable_real? - end - - return if cant_read.empty? - inject_file_list cant_read.sort, <<-EOS.undent - Some directories in #{target} aren't writable. - This can happen if you "sudo make install" software that isn't managed - by Homebrew. If a brew tries to add locale information to one of these - directories, then the install will fail during the link step. - - You should probably `sudo chown -R $(whoami)` them: - EOS - end - - def check_access_share_locale - __check_subdir_access "share/locale" - end - - def check_access_share_man - __check_subdir_access "share/man" - end - - def check_access_homebrew_repository - unless HOMEBREW_REPOSITORY.writable_real? then <<-EOS.undent - The #{HOMEBREW_REPOSITORY} is not writable. - - You should probably change the ownership and permissions of #{HOMEBREW_REPOSITORY} - back to your user account. - sudo chown -R $(whoami) #{HOMEBREW_REPOSITORY} - EOS - end - end - - def check_access_usr_local - return unless HOMEBREW_PREFIX.to_s == "/usr/local" - - unless HOMEBREW_PREFIX.writable_real? then <<-EOS.undent - The /usr/local directory is not writable. - Even if this directory was writable when you installed Homebrew, other - software may change permissions on this directory. Some versions of the - "InstantOn" component of Airfoil or running Cocktail cleanup/optimizations - are known to do this. - - You should probably change the ownership and permissions of /usr/local - back to your user account. - sudo chown -R $(whoami):admin /usr/local - EOS - end - end - - def check_tmpdir_sticky_bit - # Repair Disk Permissions was removed(?) in El Capitan. - # https://support.apple.com/en-us/HT201560 - if MacOS.version < "10.11" - fix_message = "Please run \"Repair Disk Permissions\" in Disk Utility." - else - fix_message = "Please execute `sudo chmod +t #{HOMEBREW_TEMP}` in your Terminal" - end - - world_writable = HOMEBREW_TEMP.stat.mode & 0777 == 0777 - if world_writable && !HOMEBREW_TEMP.sticky? then <<-EOS.undent - #{HOMEBREW_TEMP} is world-writable but does not have the sticky bit set. - #{fix_message} - EOS - end - end - - (Keg::TOP_LEVEL_DIRECTORIES + ["lib/pkgconfig"]).each do |d| - define_method("check_access_#{d.sub("/", "_")}") do - dir = HOMEBREW_PREFIX.join(d) - if dir.exist? && !dir.writable_real? then <<-EOS.undent - #{dir} isn't writable. - - This can happen if you "sudo make install" software that isn't managed - by Homebrew. If a formula tries to write a file to this directory, the - install will fail during the link step. - - You should probably change the ownership and permissions of #{dir} - back to your user account. - sudo chown -R $(whoami) #{dir} - EOS - end - end - end - - def check_access_site_packages - if Language::Python.homebrew_site_packages.exist? && !Language::Python.homebrew_site_packages.writable_real? - <<-EOS.undent - #{Language::Python.homebrew_site_packages} isn't writable. - This can happen if you "sudo pip install" software that isn't managed - by Homebrew. If you install a formula with Python modules, the install - will fail during the link step. - - You should probably change the ownership and permissions of #{Language::Python.homebrew_site_packages} - back to your user account. - sudo chown -R $(whoami) #{Language::Python.homebrew_site_packages} - EOS - end - end - - def check_access_logs - if HOMEBREW_LOGS.exist? && !HOMEBREW_LOGS.writable_real? - <<-EOS.undent - #{HOMEBREW_LOGS} isn't writable. - Homebrew writes debugging logs to this location. - - You should probably change the ownership and permissions of #{HOMEBREW_LOGS} - back to your user account. - sudo chown -R $(whoami) #{HOMEBREW_LOGS} - EOS - end - end - - def check_access_cache - if HOMEBREW_CACHE.exist? && !HOMEBREW_CACHE.writable_real? - <<-EOS.undent - #{HOMEBREW_CACHE} isn't writable. - This can happen if you run `brew install` or `brew fetch` as another user. - Homebrew caches downloaded files to this location. - - You should probably change the ownership and permissions of #{HOMEBREW_CACHE} - back to your user account. - sudo chown -R $(whoami) #{HOMEBREW_CACHE} - EOS - end - end - - def check_access_cellar - if HOMEBREW_CELLAR.exist? && !HOMEBREW_CELLAR.writable_real? - <<-EOS.undent - #{HOMEBREW_CELLAR} isn't writable. - - You should probably change the ownership and permissions of #{HOMEBREW_CELLAR} - back to your user account. - sudo chown -R $(whoami) #{HOMEBREW_CELLAR} - EOS - end - end - - def check_access_prefix_opt - opt = HOMEBREW_PREFIX.join("opt") - if opt.exist? && !opt.writable_real? - <<-EOS.undent - #{opt} isn't writable. - You should probably change the ownership and permissions of #{opt} - back to your user account. - sudo chown -R $(whoami) #{opt} - EOS - end - end - - def check_ruby_version - ruby_version = MacOS.version >= "10.9" ? "2.0" : "1.8" - if RUBY_VERSION[/\d\.\d/] != ruby_version then <<-EOS.undent - Ruby version #{RUBY_VERSION} is unsupported on #{MacOS.version}. Homebrew - is developed and tested on Ruby #{ruby_version}, and may not work correctly - on other Rubies. Patches are accepted as long as they don't cause breakage - on supported Rubies. - EOS - end - end - - def check_homebrew_prefix - unless HOMEBREW_PREFIX.to_s == "/usr/local" - <<-EOS.undent - Your Homebrew is not installed to /usr/local - You can install Homebrew anywhere you want, but some brews may only build - correctly if you install in /usr/local. Sorry! - EOS - end - end - - def check_xcode_prefix - prefix = MacOS::Xcode.prefix - return if prefix.nil? - if prefix.to_s.match(" ") - <<-EOS.undent - Xcode is installed to a directory with a space in the name. - This will cause some formulae to fail to build. - EOS - end - end - - def check_xcode_prefix_exists - prefix = MacOS::Xcode.prefix - return if prefix.nil? - unless prefix.exist? - <<-EOS.undent - The directory Xcode is reportedly installed to doesn't exist: - #{prefix} - You may need to `xcode-select` the proper path if you have moved Xcode. - EOS - end - end - - def check_xcode_select_path - if !MacOS::CLT.installed? && !File.file?("#{MacOS.active_developer_dir}/usr/bin/xcodebuild") - path = MacOS::Xcode.bundle_path - path = "/Developer" if path.nil? || !path.directory? - <<-EOS.undent - Your Xcode is configured with an invalid path. - You should change it to the correct path: - sudo xcode-select -switch #{path} - EOS - end - end - - def check_user_path_1 - $seen_prefix_bin = false - $seen_prefix_sbin = false - - out = nil - - paths.each do |p| - case p - when "/usr/bin" - unless $seen_prefix_bin - # only show the doctor message if there are any conflicts - # rationale: a default install should not trigger any brew doctor messages - conflicts = Dir["#{HOMEBREW_PREFIX}/bin/*"]. - map { |fn| File.basename fn }. - select { |bn| File.exist? "/usr/bin/#{bn}" } - - if conflicts.size > 0 - out = inject_file_list conflicts, <<-EOS.undent - /usr/bin occurs before #{HOMEBREW_PREFIX}/bin - This means that system-provided programs will be used instead of those - provided by Homebrew. The following tools exist at both paths: - EOS - - out += <<-EOS.undent - - Consider setting your PATH so that #{HOMEBREW_PREFIX}/bin - occurs before /usr/bin. Here is a one-liner: - echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} - EOS - end - end - when "#{HOMEBREW_PREFIX}/bin" - $seen_prefix_bin = true - when "#{HOMEBREW_PREFIX}/sbin" - $seen_prefix_sbin = true - end - end - out - end - - def check_user_path_2 - unless $seen_prefix_bin - <<-EOS.undent - Homebrew's bin was not found in your PATH. - Consider setting the PATH for example like so - echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} - EOS - end - end - - def check_user_path_3 - # Don't complain about sbin not being in the path if it doesn't exist - sbin = (HOMEBREW_PREFIX+"sbin") - if sbin.directory? && sbin.children.length > 0 - unless $seen_prefix_sbin - <<-EOS.undent - Homebrew's sbin was not found in your PATH but you have installed - formulae that put executables in #{HOMEBREW_PREFIX}/sbin. - Consider setting the PATH for example like so - echo 'export PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"' >> #{shell_profile} - EOS - end - end - end - - def check_for_bad_curl - if MacOS.version <= "10.8" && !Formula["curl"].installed? then <<-EOS.undent - The system curl on 10.8 and below is often incapable of supporting - modern secure connections & will fail on fetching formulae. - - We recommend you: - brew install curl - EOS - end - end - - def check_user_curlrc - if %w[CURL_HOME HOME].any? { |key| ENV[key] && File.exist?("#{ENV[key]}/.curlrc") } then <<-EOS.undent - You have a curlrc file - If you have trouble downloading packages with Homebrew, then maybe this - is the problem? If the following command doesn't work, then try removing - your curlrc: - curl https://github.com - EOS - end - end - - def check_for_unsupported_curl_vars - # Support for SSL_CERT_DIR seemed to be removed in the 10.10.5 update. - if MacOS.version >= :yosemite && !ENV["SSL_CERT_DIR"].nil? then <<-EOS.undent - SSL_CERT_DIR support was removed from Apple's curl. - If fetching formulae fails you should: - unset SSL_CERT_DIR - and remove it from #{shell_profile} if present. - EOS - end - end - - def check_which_pkg_config - binary = which "pkg-config" - return if binary.nil? - - mono_config = Pathname.new("/usr/bin/pkg-config") - if mono_config.exist? && mono_config.realpath.to_s.include?("Mono.framework") then <<-EOS.undent - You have a non-Homebrew 'pkg-config' in your PATH: - /usr/bin/pkg-config => #{mono_config.realpath} - - This was most likely created by the Mono installer. `./configure` may - have problems finding brew-installed packages using this other pkg-config. - - Mono no longer installs this file as of 3.0.4. You should - `sudo rm /usr/bin/pkg-config` and upgrade to the latest version of Mono. - EOS - elsif binary.to_s != "#{HOMEBREW_PREFIX}/bin/pkg-config" then <<-EOS.undent - You have a non-Homebrew 'pkg-config' in your PATH: - #{binary} - - `./configure` may have problems finding brew-installed packages using - this other pkg-config. - EOS - end - end - - def check_for_gettext - find_relative_paths("lib/libgettextlib.dylib", - "lib/libintl.dylib", - "include/libintl.h") - - return if @found.empty? - - # Our gettext formula will be caught by check_linked_keg_only_brews - f = Formulary.factory("gettext") rescue nil - return if f && f.linked_keg.directory? && @found.all? do |path| - Pathname.new(path).realpath.to_s.start_with? "#{HOMEBREW_CELLAR}/gettext" - end - - s = <<-EOS.undent_________________________________________________________72 - gettext files detected at a system prefix - These files can cause compilation and link failures, especially if they - are compiled with improper architectures. Consider removing these files: - EOS - inject_file_list(@found, s) - end - - def check_for_iconv - unless find_relative_paths("lib/libiconv.dylib", "include/iconv.h").empty? - if (f = Formulary.factory("libiconv") rescue nil) && f.linked_keg.directory? - unless f.keg_only? then <<-EOS.undent - A libiconv formula is installed and linked - This will break stuff. For serious. Unlink it. - EOS - end - else - s = <<-EOS.undent_________________________________________________________72 - libiconv files detected at a system prefix other than /usr - Homebrew doesn't provide a libiconv formula, and expects to link against - the system version in /usr. libiconv in other prefixes can cause - compile or link failure, especially if compiled with improper - architectures. OS X itself never installs anything to /usr/local so - it was either installed by a user or some other third party software. - - tl;dr: delete these files: - EOS - inject_file_list(@found, s) - end - end - end - - def check_for_config_scripts - return unless HOMEBREW_CELLAR.exist? - real_cellar = HOMEBREW_CELLAR.realpath - - scripts = [] - - whitelist = %W[ - /usr/bin /usr/sbin - /usr/X11/bin /usr/X11R6/bin /opt/X11/bin - #{HOMEBREW_PREFIX}/bin #{HOMEBREW_PREFIX}/sbin - /Applications/Server.app/Contents/ServerRoot/usr/bin - /Applications/Server.app/Contents/ServerRoot/usr/sbin - ].map(&:downcase) - - paths.each do |p| - next if whitelist.include?(p.downcase) || !File.directory?(p) - - realpath = Pathname.new(p).realpath.to_s - next if realpath.start_with?(real_cellar.to_s, HOMEBREW_CELLAR.to_s) - - scripts += Dir.chdir(p) { Dir["*-config"] }.map { |c| File.join(p, c) } - end - - return if scripts.empty? - inject_file_list scripts, <<-EOS.undent - "config" scripts exist outside your system or Homebrew directories. - `./configure` scripts often look for *-config scripts to determine if - software packages are installed, and what additional flags to use when - compiling and linking. - - Having additional scripts in your path can confuse software installed via - Homebrew if the config script overrides a system or Homebrew provided - script of the same name. We found the following "config" scripts: - EOS - end - - def check_DYLD_vars - found = ENV.keys.grep(/^DYLD_/) - return if found.empty? - s = inject_file_list found.map { |e| "#{e}: #{ENV.fetch(e)}" }, <<-EOS.undent - Setting DYLD_* vars can break dynamic linking. - Set variables: - EOS - if found.include? "DYLD_INSERT_LIBRARIES" - s += <<-EOS.undent - - Setting DYLD_INSERT_LIBRARIES can cause Go builds to fail. - Having this set is common if you use this software: - http://asepsis.binaryage.com/ - EOS - end - s - end - - def check_for_symlinked_cellar - return unless HOMEBREW_CELLAR.exist? - if HOMEBREW_CELLAR.symlink? - <<-EOS.undent - Symlinked Cellars can cause problems. - Your Homebrew Cellar is a symlink: #{HOMEBREW_CELLAR} - which resolves to: #{HOMEBREW_CELLAR.realpath} - - The recommended Homebrew installations are either: - (A) Have Cellar be a real directory inside of your HOMEBREW_PREFIX - (B) Symlink "bin/brew" into your prefix, but don't symlink "Cellar". - - Older installations of Homebrew may have created a symlinked Cellar, but this can - cause problems when two formula install to locations that are mapped on top of each - other during the linking step. - EOS - end - end - - def check_for_multiple_volumes - return unless HOMEBREW_CELLAR.exist? - volumes = Volumes.new - - # Find the volumes for the TMP folder & HOMEBREW_CELLAR - real_cellar = HOMEBREW_CELLAR.realpath - - tmp = Pathname.new(Dir.mktmpdir("doctor", HOMEBREW_TEMP)) - real_temp = tmp.realpath.parent - - where_cellar = volumes.which real_cellar - where_temp = volumes.which real_temp - - Dir.delete tmp - - unless where_cellar == where_temp then <<-EOS.undent - Your Cellar and TEMP directories are on different volumes. - OS X won't move relative symlinks across volumes unless the target file already - exists. Brews known to be affected by this are Git and Narwhal. - - You should set the "HOMEBREW_TEMP" environmental variable to a suitable - directory on the same volume as your Cellar. - EOS - end - end - - def check_filesystem_case_sensitive - volumes = Volumes.new - case_sensitive_vols = [HOMEBREW_PREFIX, HOMEBREW_REPOSITORY, HOMEBREW_CELLAR, HOMEBREW_TEMP].select do |dir| - # We select the dir as being case-sensitive if either the UPCASED or the - # downcased variant is missing. - # Of course, on a case-insensitive fs, both exist because the os reports so. - # In the rare situation when the user has indeed a downcased and an upcased - # dir (e.g. /TMP and /tmp) this check falsely thinks it is case-insensitive - # but we don't care beacuse: 1. there is more than one dir checked, 2. the - # check is not vital and 3. we would have to touch files otherwise. - upcased = Pathname.new(dir.to_s.upcase) - downcased = Pathname.new(dir.to_s.downcase) - dir.exist? && !(upcased.exist? && downcased.exist?) - end.map { |case_sensitive_dir| volumes.get_mounts(case_sensitive_dir) }.uniq - return if case_sensitive_vols.empty? - <<-EOS.undent - The filesystem on #{case_sensitive_vols.join(",")} appears to be case-sensitive. - The default OS X filesystem is case-insensitive. Please report any apparent problems. - EOS - end - - def __check_git_version - # https://help.github.com/articles/https-cloning-errors - `git --version`.chomp =~ /git version ((?:\d+\.?)+)/ - - if $1 && Version.new($1) < Version.new("1.7.10") - git_upgrade_cmd = Formula["git"].any_version_installed? ? "upgrade" : "install" - - <<-EOS.undent - An outdated version of Git was detected in your PATH. - Git 1.7.10 or newer is required to perform checkouts over HTTPS from GitHub. - Please upgrade: brew #{git_upgrade_cmd} git - EOS - end - end - - def check_for_git - if Utils.git_available? - __check_git_version - else <<-EOS.undent - Git could not be found in your PATH. - Homebrew uses Git for several internal functions, and some formulae use Git - checkouts instead of stable tarballs. You may want to install Git: - brew install git - EOS - end - end - - def check_git_newline_settings - return unless Utils.git_available? - - autocrlf = `git config --get core.autocrlf`.chomp - - if autocrlf == "true" then <<-EOS.undent - Suspicious Git newline settings found. - - The detected Git newline settings will cause checkout problems: - core.autocrlf = #{autocrlf} - - If you are not routinely dealing with Windows-based projects, - consider removing these by running: - `git config --global core.autocrlf input` - EOS - end - end - - def check_git_origin - return if !Utils.git_available? || !(HOMEBREW_REPOSITORY/".git").exist? - - origin = Homebrew.git_origin - - if origin.nil? then <<-EOS.undent - Missing git origin remote. - - Without a correctly configured origin, Homebrew won't update - properly. You can solve this by adding the Homebrew remote: - cd #{HOMEBREW_REPOSITORY} - git remote add origin https://github.com/Homebrew/homebrew.git - EOS - elsif origin !~ /(mxcl|Homebrew)\/homebrew(\.git)?$/ then <<-EOS.undent - Suspicious git origin remote found. - - With a non-standard origin, Homebrew won't pull updates from - the main repository. The current git origin is: - #{origin} - - Unless you have compelling reasons, consider setting the - origin remote to point at the main repository, located at: - https://github.com/Homebrew/homebrew.git - EOS - end - end - - def check_for_autoconf - return unless MacOS::Xcode.provides_autotools? - - autoconf = which("autoconf") - safe_autoconfs = %w[/usr/bin/autoconf /Developer/usr/bin/autoconf] - unless autoconf.nil? || safe_autoconfs.include?(autoconf.to_s) then <<-EOS.undent - An "autoconf" in your path blocks the Xcode-provided version at: - #{autoconf} - - This custom autoconf may cause some Homebrew formulae to fail to compile. - EOS - end - end - - def __check_linked_brew(f) - f.installed_prefixes.each do |prefix| - prefix.find do |src| - next if src == prefix - dst = HOMEBREW_PREFIX + src.relative_path_from(prefix) - return true if dst.symlink? && src == dst.resolved_path - end - end - - false - end - - def check_for_linked_keg_only_brews - return unless HOMEBREW_CELLAR.exist? - - linked = Formula.installed.select do |f| - f.keg_only? && __check_linked_brew(f) - end - - return if linked.empty? - inject_file_list linked.map(&:full_name), <<-EOS.undent - Some keg-only formula are linked into the Cellar. - Linking a keg-only formula, such as gettext, into the cellar with - `brew link <formula>` will cause other formulae to detect them during - the `./configure` step. This may cause problems when compiling those - other formulae. - - Binaries provided by keg-only formulae may override system binaries - with other strange results. - - You may wish to `brew unlink` these brews: - EOS - end - - def check_for_other_frameworks - # Other frameworks that are known to cause problems when present - %w[expat.framework libexpat.framework libcurl.framework]. - map { |frmwrk| "/Library/Frameworks/#{frmwrk}" }. - select { |frmwrk| File.exist? frmwrk }. - map do |frmwrk| - <<-EOS.undent - #{frmwrk} detected - This can be picked up by CMake's build system and likely cause the build to - fail. You may need to move this file out of the way to compile CMake. - EOS - end.join - end - - def check_tmpdir - tmpdir = ENV["TMPDIR"] - "TMPDIR #{tmpdir.inspect} doesn't exist." unless tmpdir.nil? || File.directory?(tmpdir) - end - - def check_missing_deps - return unless HOMEBREW_CELLAR.exist? - missing = Set.new - Homebrew.missing_deps(Formula.installed).each_value do |deps| - missing.merge(deps) - end - - if missing.any? then <<-EOS.undent - Some installed formula are missing dependencies. - You should `brew install` the missing dependencies: - - brew install #{missing.sort_by(&:full_name) * " "} - - Run `brew missing` for more details. - EOS - end - end - - def check_git_status - return unless Utils.git_available? - HOMEBREW_REPOSITORY.cd do - unless `git status --untracked-files=all --porcelain -- Library/Homebrew/ 2>/dev/null`.chomp.empty? - <<-EOS.undent_________________________________________________________72 - You have uncommitted modifications to Homebrew - If this is a surprise to you, then you should stash these modifications. - Stashing returns Homebrew to a pristine state but can be undone - should you later need to do so for some reason. - cd #{HOMEBREW_LIBRARY} && git stash && git clean -d -f - EOS - end - end - end - - def check_for_enthought_python - if which "enpkg" then <<-EOS.undent - Enthought Python was found in your PATH. - This can cause build problems, as this software installs its own - copies of iconv and libxml2 into directories that are picked up by - other build systems. - EOS - end - end - - def check_for_library_python - if File.exist?("/Library/Frameworks/Python.framework") then <<-EOS.undent - Python is installed at /Library/Frameworks/Python.framework - - Homebrew only supports building against the System-provided Python or a - brewed Python. In particular, Pythons installed to /Library can interfere - with other software installs. - EOS - end - end - - def check_for_old_homebrew_share_python_in_path - s = "" - ["", "3"].map do |suffix| - if paths.include?((HOMEBREW_PREFIX/"share/python#{suffix}").to_s) - s += "#{HOMEBREW_PREFIX}/share/python#{suffix} is not needed in PATH.\n" - end - end - unless s.empty? - s += <<-EOS.undent - Formerly homebrew put Python scripts you installed via `pip` or `pip3` - (or `easy_install`) into that directory above but now it can be removed - from your PATH variable. - Python scripts will now install into #{HOMEBREW_PREFIX}/bin. - You can delete anything, except 'Extras', from the #{HOMEBREW_PREFIX}/share/python - (and #{HOMEBREW_PREFIX}/share/python3) dir and install affected Python packages - anew with `pip install --upgrade`. - EOS - end - end - - def check_for_bad_python_symlink - return unless which "python" - `python -V 2>&1` =~ /Python (\d+)\./ - # This won't be the right warning if we matched nothing at all - return if $1.nil? - unless $1 == "2" then <<-EOS.undent - python is symlinked to python#{$1} - This will confuse build scripts and in general lead to subtle breakage. - EOS - end - end - - def check_for_non_prefixed_coreutils - gnubin = "#{Formulary.factory("coreutils").prefix}/libexec/gnubin" - if paths.include? gnubin then <<-EOS.undent - Putting non-prefixed coreutils in your path can cause gmp builds to fail. - EOS - end - end - - def check_for_non_prefixed_findutils - default_names = Tab.for_name("findutils").with? "default-names" - if default_names then <<-EOS.undent - Putting non-prefixed findutils in your path can cause python builds to fail. - EOS - end - end - - def check_for_pydistutils_cfg_in_home - if File.exist? "#{ENV["HOME"]}/.pydistutils.cfg" then <<-EOS.undent - A .pydistutils.cfg file was found in $HOME, which may cause Python - builds to fail. See: - https://bugs.python.org/issue6138 - https://bugs.python.org/issue4655 - EOS - end - end - - def check_for_outdated_homebrew - return unless Utils.git_available? - HOMEBREW_REPOSITORY.cd do - if File.directory? ".git" - local = `git rev-parse -q --verify refs/remotes/origin/master`.chomp - remote = /^([a-f0-9]{40})/.match(`git ls-remote origin refs/heads/master 2>/dev/null`) - if remote.nil? || local == remote[0] - return - end - end - - timestamp = if File.directory? ".git" - `git log -1 --format="%ct" HEAD`.to_i - else - HOMEBREW_LIBRARY.mtime.to_i - end - - if Time.now.to_i - timestamp > 60 * 60 * 24 then <<-EOS.undent - Your Homebrew is outdated. - You haven't updated for at least 24 hours. This is a long time in brewland! - To update Homebrew, run `brew update`. - EOS - end - end - end - - def check_for_unlinked_but_not_keg_only - unlinked = Formula.racks.reject do |rack| - if !(HOMEBREW_REPOSITORY/"Library/LinkedKegs"/rack.basename).directory? - begin - Formulary.from_rack(rack).keg_only? - rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError - false - end - else - true - end - end.map(&:basename) - - return if unlinked.empty? - inject_file_list unlinked, <<-EOS.undent - You have unlinked kegs in your Cellar - Leaving kegs unlinked can lead to build-trouble and cause brews that depend on - those kegs to fail to run properly once built. Run `brew link` on these: - EOS - end - - def check_xcode_license_approved - # If the user installs Xcode-only, they have to approve the - # license or no "xc*" tool will work. - if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success? then <<-EOS.undent - You have not agreed to the Xcode license. - Builds will fail! Agree to the license by opening Xcode.app or running: - sudo xcodebuild -license - EOS - end - end - - def check_for_latest_xquartz - return unless MacOS::XQuartz.version - return if MacOS::XQuartz.provided_by_apple? - - installed_version = Version.new(MacOS::XQuartz.version) - latest_version = Version.new(MacOS::XQuartz.latest_version) - - return if installed_version >= latest_version - - <<-EOS.undent - Your XQuartz (#{installed_version}) is outdated - Please install XQuartz #{latest_version}: - https://xquartz.macosforge.org - EOS - end - - def check_for_old_env_vars - if ENV["HOMEBREW_KEEP_INFO"] - <<-EOS.undent - `HOMEBREW_KEEP_INFO` is no longer used - info files are no longer deleted by default; you may - remove this environment variable. - EOS - end - end - - def check_for_pth_support - homebrew_site_packages = Language::Python.homebrew_site_packages - return unless homebrew_site_packages.directory? - return if Language::Python.reads_brewed_pth_files?("python") != false - return unless Language::Python.in_sys_path?("python", homebrew_site_packages) - user_site_packages = Language::Python.user_site_packages "python" - <<-EOS.undent - Your default Python does not recognize the Homebrew site-packages - directory as a special site-packages directory, which means that .pth - files will not be followed. This means you will not be able to import - some modules after installing them with Homebrew, like wxpython. To fix - this for the current user, you can run: - - mkdir -p #{user_site_packages} - echo 'import site; site.addsitedir("#{homebrew_site_packages}")' >> #{user_site_packages}/homebrew.pth - EOS - end - - def check_for_external_cmd_name_conflict - cmds = paths.flat_map { |p| Dir["#{p}/brew-*"] }.uniq - cmds = cmds.select { |cmd| File.file?(cmd) && File.executable?(cmd) } - cmd_map = {} - cmds.each do |cmd| - cmd_name = File.basename(cmd, ".rb") - cmd_map[cmd_name] ||= [] - cmd_map[cmd_name] << cmd - end - cmd_map.reject! { |_cmd_name, cmd_paths| cmd_paths.size == 1 } - return if cmd_map.empty? - s = "You have external commands with conflicting names.\n" - cmd_map.each do |cmd_name, cmd_paths| - s += inject_file_list cmd_paths, <<-EOS.undent - - Found command `#{cmd_name}` in following places: - EOS - end - s - end - - def all - methods.map(&:to_s).grep(/^check_/) - end -end # end class Checks +require "diagnostic" module Homebrew def doctor - checks = Checks.new + checks = Diagnostic::Checks.new if ARGV.include? "--list-checks" puts checks.all.sort exit end - inject_dump_stats(checks) if ARGV.switch? "D" + checks.inject_dump_stats! if ARGV.switch? "D" if ARGV.named.empty? methods = checks.all.sort @@ -1349,19 +46,4 @@ def doctor puts "Your system is ready to brew." unless Homebrew.failed? end - - def inject_dump_stats(checks) - checks.extend Module.new { - def send(method, *) - time = Time.now - super - ensure - $times[method] = Time.now - time - end - } - $times = {} - at_exit do - puts $times.sort_by { |_k, v| v }.map { |k, v| "#{k}: #{v}" } - end - end end
true
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/install.rb
@@ -1,5 +1,5 @@ require "blacklist" -require "cmd/doctor" +require "diagnostic" require "cmd/search" require "formula_installer" require "tap" @@ -159,7 +159,7 @@ def check_writable_install_location end def check_xcode - checks = Checks.new + checks = Diagnostic::Checks.new %w[ check_for_unsupported_osx check_for_bad_install_name_tool
true
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/missing.rb
@@ -1,30 +1,8 @@ require "formula" require "tab" +require "diagnostic" module Homebrew - def missing_deps(ff) - missing = {} - ff.each do |f| - missing_deps = f.recursive_dependencies do |dependent, dep| - if dep.optional? || dep.recommended? - tab = Tab.for_formula(dependent) - Dependency.prune unless tab.with?(dep) - elsif dep.build? - Dependency.prune - end - end - - missing_deps.map!(&:to_formula) - missing_deps.reject! { |d| d.installed_prefixes.any? } - - unless missing_deps.empty? - yield f.full_name, missing_deps if block_given? - missing[f.full_name] = missing_deps - end - end - missing - end - def missing return unless HOMEBREW_CELLAR.exist? @@ -34,7 +12,7 @@ def missing ARGV.resolved_formulae end - missing_deps(ff) do |name, missing| + Diagnostic.missing_deps(ff) do |name, missing| print "#{name}: " if ff.size > 1 puts "#{missing * " "}" end
true
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/update.rb
@@ -1,5 +1,5 @@ require "cmd/tap" -require "cmd/doctor" +require "diagnostic" require "formula_versions" require "migrator" require "formulary" @@ -15,7 +15,7 @@ def update end # check permissions - checks = Checks.new + checks = Diagnostic::Checks.new %w[ check_access_usr_local check_access_homebrew_repository
true
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/diagnostic.rb
@@ -0,0 +1,1344 @@ +require "keg" +require "language/python" +require "formula" +require "version" + +module Homebrew + module Diagnostic + def self.missing_deps(ff) + missing = {} + ff.each do |f| + missing_deps = f.recursive_dependencies do |dependent, dep| + if dep.optional? || dep.recommended? + tab = Tab.for_formula(dependent) + Dependency.prune unless tab.with?(dep) + elsif dep.build? + Dependency.prune + end + end + + missing_deps.map!(&:to_formula) + missing_deps.reject! { |d| d.installed_prefixes.any? } + + unless missing_deps.empty? + yield f.full_name, missing_deps if block_given? + missing[f.full_name] = missing_deps + end + end + missing + end + + class Volumes + def initialize + @volumes = get_mounts + end + + def which(path) + vols = get_mounts path + + # no volume found + if vols.empty? + return -1 + end + + vol_index = @volumes.index(vols[0]) + # volume not found in volume list + if vol_index.nil? + return -1 + end + vol_index + end + + def get_mounts(path = nil) + vols = [] + # get the volume of path, if path is nil returns all volumes + + args = %w[/bin/df -P] + args << path if path + + Utils.popen_read(*args) do |io| + io.each_line do |line| + case line.chomp + # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / + when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ + vols << $1 + end + end + end + vols + end + end + + class Checks + ############# HELPERS + # Finds files in HOMEBREW_PREFIX *and* /usr/local. + # Specify paths relative to a prefix eg. "include/foo.h". + # Sets @found for your convenience. + def find_relative_paths(*relative_paths) + @found = [HOMEBREW_PREFIX, "/usr/local"].uniq.inject([]) do |found, prefix| + found + relative_paths.map { |f| File.join(prefix, f) }.select { |f| File.exist? f } + end + end + + def inject_file_list(list, str) + list.inject(str) { |s, f| s << " #{f}\n" } + end + ############# END HELPERS + + def inject_dump_stats! + self.extend Module.new { + def send(method, *) + time = Time.now + super + ensure + $times[method] = Time.now - time + end + } + $times = {} + at_exit do + puts $times.sort_by { |_k, v| v }.map { |k, v| "#{k}: #{v}" } + end + end + + # See https://github.com/Homebrew/homebrew/pull/9986 + def check_path_for_trailing_slashes + bad_paths = ENV["PATH"].split(File::PATH_SEPARATOR).select { |p| p[-1..-1] == "/" } + return if bad_paths.empty? + inject_file_list bad_paths, <<-EOS.undent + Some directories in your path end in a slash. + Directories in your path should not end in a slash. This can break other + doctor checks. The following directories should be edited: + EOS + end + + # Installing MacGPG2 interferes with Homebrew in a big way + # https://github.com/GPGTools/MacGPG2 + def check_for_macgpg2 + return if File.exist? "/usr/local/MacGPG2/share/gnupg/VERSION" + + suspects = %w[ + /Applications/start-gpg-agent.app + /Library/Receipts/libiconv1.pkg + /usr/local/MacGPG2 + ] + + if suspects.any? { |f| File.exist? f } then <<-EOS.undent + You may have installed MacGPG2 via the package installer. + Several other checks in this script will turn up problems, such as stray + dylibs in /usr/local and permissions issues with share and man in /usr/local/. + EOS + end + end + + # Anaconda installs multiple system & brew dupes, including OpenSSL, Python, + # sqlite, libpng, Qt, etc. Regularly breaks compile on Vim, MacVim and others. + # Is flagged as part of the *-config script checks below, but people seem + # to ignore those as warnings rather than extremely likely breakage. + def check_for_anaconda + return unless which("anaconda") + return unless which("python") + + anaconda = which("anaconda").realpath.dirname + python_binary = Utils.popen_read which("python"), "-c", "import sys; sys.stdout.write(sys.executable)" + python = Pathname.new(python_binary).realpath.dirname + + # Only warn if Python lives with Anaconda, since is most problematic case. + if python == anaconda then <<-EOS.undent + Anaconda is known to frequently break Homebrew builds, including Vim and + MacVim, due to bundling many duplicates of system and Homebrew-available + tools. + + If you encounter a build failure please temporarily remove Anaconda + from your $PATH and attempt the build again prior to reporting the + failure to us. Thanks! + EOS + end + end + + def __check_stray_files(dir, pattern, white_list, message) + return unless File.directory?(dir) + + files = Dir.chdir(dir) do + Dir[pattern].select { |f| File.file?(f) && !File.symlink?(f) } - Dir.glob(white_list) + end.map { |file| File.join(dir, file) } + + inject_file_list(files, message) unless files.empty? + end + + def check_for_stray_dylibs + # Dylibs which are generally OK should be added to this list, + # with a short description of the software they come with. + white_list = [ + "libfuse.2.dylib", # MacFuse + "libfuse_ino64.2.dylib", # MacFuse + "libmacfuse_i32.2.dylib", # OSXFuse MacFuse compatibility layer + "libmacfuse_i64.2.dylib", # OSXFuse MacFuse compatibility layer + "libosxfuse_i32.2.dylib", # OSXFuse + "libosxfuse_i64.2.dylib", # OSXFuse + "libTrAPI.dylib", # TrAPI / Endpoint Security VPN + "libntfs-3g.*.dylib", # NTFS-3G + "libntfs.*.dylib", # NTFS-3G + "libublio.*.dylib", # NTFS-3G + "libUFSDNTFS.dylib", # Paragon NTFS + "libUFSDExtFS.dylib", # Paragon ExtFS + ] + + __check_stray_files "/usr/local/lib", "*.dylib", white_list, <<-EOS.undent + Unbrewed dylibs were found in /usr/local/lib. + If you didn't put them there on purpose they could cause problems when + building Homebrew formulae, and may need to be deleted. + + Unexpected dylibs: + EOS + end + + def check_for_stray_static_libs + # Static libs which are generally OK should be added to this list, + # with a short description of the software they come with. + white_list = [ + "libsecurity_agent_client.a", # OS X 10.8.2 Supplemental Update + "libsecurity_agent_server.a", # OS X 10.8.2 Supplemental Update + "libntfs-3g.a", # NTFS-3G + "libntfs.a", # NTFS-3G + "libublio.a", # NTFS-3G + ] + + __check_stray_files "/usr/local/lib", "*.a", white_list, <<-EOS.undent + Unbrewed static libraries were found in /usr/local/lib. + If you didn't put them there on purpose they could cause problems when + building Homebrew formulae, and may need to be deleted. + + Unexpected static libraries: + EOS + end + + def check_for_stray_pcs + # Package-config files which are generally OK should be added to this list, + # with a short description of the software they come with. + white_list = [ + "fuse.pc", # OSXFuse/MacFuse + "macfuse.pc", # OSXFuse MacFuse compatibility layer + "osxfuse.pc", # OSXFuse + "libntfs-3g.pc", # NTFS-3G + "libublio.pc", # NTFS-3G + ] + + __check_stray_files "/usr/local/lib/pkgconfig", "*.pc", white_list, <<-EOS.undent + Unbrewed .pc files were found in /usr/local/lib/pkgconfig. + If you didn't put them there on purpose they could cause problems when + building Homebrew formulae, and may need to be deleted. + + Unexpected .pc files: + EOS + end + + def check_for_stray_las + white_list = [ + "libfuse.la", # MacFuse + "libfuse_ino64.la", # MacFuse + "libosxfuse_i32.la", # OSXFuse + "libosxfuse_i64.la", # OSXFuse + "libntfs-3g.la", # NTFS-3G + "libntfs.la", # NTFS-3G + "libublio.la", # NTFS-3G + ] + + __check_stray_files "/usr/local/lib", "*.la", white_list, <<-EOS.undent + Unbrewed .la files were found in /usr/local/lib. + If you didn't put them there on purpose they could cause problems when + building Homebrew formulae, and may need to be deleted. + + Unexpected .la files: + EOS + end + + def check_for_stray_headers + white_list = [ + "fuse.h", # MacFuse + "fuse/**/*.h", # MacFuse + "macfuse/**/*.h", # OSXFuse MacFuse compatibility layer + "osxfuse/**/*.h", # OSXFuse + "ntfs/**/*.h", # NTFS-3G + "ntfs-3g/**/*.h", # NTFS-3G + ] + + __check_stray_files "/usr/local/include", "**/*.h", white_list, <<-EOS.undent + Unbrewed header files were found in /usr/local/include. + If you didn't put them there on purpose they could cause problems when + building Homebrew formulae, and may need to be deleted. + + Unexpected header files: + EOS + end + + def check_for_other_package_managers + ponk = MacOS.macports_or_fink + unless ponk.empty? + <<-EOS.undent + You have MacPorts or Fink installed: + #{ponk.join(", ")} + + This can cause trouble. You don't have to uninstall them, but you may want to + temporarily move them out of the way, e.g. + + sudo mv /opt/local ~/macports + EOS + end + end + + def check_for_broken_symlinks + broken_symlinks = [] + + Keg::PRUNEABLE_DIRECTORIES.each do |d| + next unless d.directory? + d.find do |path| + if path.symlink? && !path.resolved_path_exists? + broken_symlinks << path + end + end + end + return if broken_symlinks.empty? + inject_file_list broken_symlinks, <<-EOS.undent + Broken symlinks were found. Remove them with `brew prune`: + EOS + end + + def check_for_unsupported_osx + if !ARGV.homebrew_developer? && OS::Mac.prerelease? then <<-EOS.undent + You are using OS X #{MacOS.version}. + We do not provide support for this pre-release version. + You may encounter build failures or other breakages. + EOS + end + end + + # TODO: distill down into single method definition a la BuildToolsError + if MacOS.version >= "10.9" + def check_for_installed_developer_tools + unless MacOS::Xcode.installed? || MacOS::CLT.installed? then <<-EOS.undent + No developer tools installed. + Install the Command Line Tools: + xcode-select --install + EOS + end + end + + if OS::Mac.prerelease? + def check_xcode_up_to_date + if MacOS::Xcode.installed? && MacOS::Xcode.outdated? + <<-EOS.undent + Your Xcode (#{MacOS::Xcode.version}) is outdated + Please update to Xcode #{MacOS::Xcode.latest_version}. + Xcode can be updated from + https://developer.apple.com/xcode/downloads/ + EOS + end + end + else + def check_xcode_up_to_date + if MacOS::Xcode.installed? && MacOS::Xcode.outdated? + <<-EOS.undent + Your Xcode (#{MacOS::Xcode.version}) is outdated + Please update to Xcode #{MacOS::Xcode.latest_version}. + Xcode can be updated from the App Store. + EOS + end + end + end + + def check_clt_up_to_date + if MacOS::CLT.installed? && MacOS::CLT.outdated? then <<-EOS.undent + A newer Command Line Tools release is available. + Update them from Software Update in the App Store. + EOS + end + end + elsif MacOS.version == "10.8" || MacOS.version == "10.7" + def check_for_installed_developer_tools + unless MacOS::Xcode.installed? || MacOS::CLT.installed? then <<-EOS.undent + No developer tools installed. + You should install the Command Line Tools. + The standalone package can be obtained from + https://developer.apple.com/downloads + or it can be installed via Xcode's preferences. + EOS + end + end + + def check_xcode_up_to_date + if MacOS::Xcode.installed? && MacOS::Xcode.outdated? then <<-EOS.undent + Your Xcode (#{MacOS::Xcode.version}) is outdated + Please update to Xcode #{MacOS::Xcode.latest_version}. + Xcode can be updated from + https://developer.apple.com/xcode/downloads/ + EOS + end + end + + def check_clt_up_to_date + if MacOS::CLT.installed? && MacOS::CLT.outdated? then <<-EOS.undent + A newer Command Line Tools release is available. + The standalone package can be obtained from + https://developer.apple.com/downloads + or it can be installed via Xcode's preferences. + EOS + end + end + else + def check_for_installed_developer_tools + unless MacOS::Xcode.installed? then <<-EOS.undent + Xcode is not installed. Most formulae need Xcode to build. + It can be installed from + https://developer.apple.com/xcode/downloads/ + EOS + end + end + + def check_xcode_up_to_date + if MacOS::Xcode.installed? && MacOS::Xcode.outdated? then <<-EOS.undent + Your Xcode (#{MacOS::Xcode.version}) is outdated + Please update to Xcode #{MacOS::Xcode.latest_version}. + Xcode can be updated from + https://developer.apple.com/xcode/downloads/ + EOS + end + end + end + + def check_for_osx_gcc_installer + if (MacOS.version < "10.7" || MacOS::Xcode.version > "4.1") && \ + MacOS.clang_version == "2.1" + message = <<-EOS.undent + You seem to have osx-gcc-installer installed. + Homebrew doesn't support osx-gcc-installer. It causes many builds to fail and + is an unlicensed distribution of really old Xcode files. + EOS + if MacOS.version >= :mavericks + message += <<-EOS.undent + Please run `xcode-select --install` to install the CLT. + EOS + elsif MacOS.version >= :lion + message += <<-EOS.undent + Please install the CLT or Xcode #{MacOS::Xcode.latest_version}. + EOS + else + message += <<-EOS.undent + Please install Xcode #{MacOS::Xcode.latest_version}. + EOS + end + end + end + + def check_for_stray_developer_directory + # if the uninstaller script isn't there, it's a good guess neither are + # any troublesome leftover Xcode files + uninstaller = Pathname.new("/Developer/Library/uninstall-developer-folder") + if MacOS::Xcode.version >= "4.3" && uninstaller.exist? then <<-EOS.undent + You have leftover files from an older version of Xcode. + You should delete them using: + #{uninstaller} + EOS + end + end + + def check_for_bad_install_name_tool + return if MacOS.version < "10.9" + + libs = Pathname.new("/usr/bin/install_name_tool").dynamically_linked_libraries + + # otool may not work, for example if the Xcode license hasn't been accepted yet + return if libs.empty? + + unless libs.include? "/usr/lib/libxcselect.dylib" then <<-EOS.undent + You have an outdated version of /usr/bin/install_name_tool installed. + This will cause binary package installations to fail. + This can happen if you install osx-gcc-installer or RailsInstaller. + To restore it, you must reinstall OS X or restore the binary from + the OS packages. + EOS + end + end + + def __check_subdir_access(base) + target = HOMEBREW_PREFIX+base + return unless target.exist? + + cant_read = [] + + target.find do |d| + next unless d.directory? + cant_read << d unless d.writable_real? + end + + return if cant_read.empty? + inject_file_list cant_read.sort, <<-EOS.undent + Some directories in #{target} aren't writable. + This can happen if you "sudo make install" software that isn't managed + by Homebrew. If a brew tries to add locale information to one of these + directories, then the install will fail during the link step. + + You should probably `sudo chown -R $(whoami)` them: + EOS + end + + def check_access_share_locale + __check_subdir_access "share/locale" + end + + def check_access_share_man + __check_subdir_access "share/man" + end + + def check_access_homebrew_repository + unless HOMEBREW_REPOSITORY.writable_real? then <<-EOS.undent + The #{HOMEBREW_REPOSITORY} is not writable. + + You should probably change the ownership and permissions of #{HOMEBREW_REPOSITORY} + back to your user account. + sudo chown -R $(whoami) #{HOMEBREW_REPOSITORY} + EOS + end + end + + def check_access_usr_local + return unless HOMEBREW_PREFIX.to_s == "/usr/local" + + unless HOMEBREW_PREFIX.writable_real? then <<-EOS.undent + The /usr/local directory is not writable. + Even if this directory was writable when you installed Homebrew, other + software may change permissions on this directory. Some versions of the + "InstantOn" component of Airfoil or running Cocktail cleanup/optimizations + are known to do this. + + You should probably change the ownership and permissions of /usr/local + back to your user account. + sudo chown -R $(whoami):admin /usr/local + EOS + end + end + + def check_tmpdir_sticky_bit + # Repair Disk Permissions was removed(?) in El Capitan. + # https://support.apple.com/en-us/HT201560 + if MacOS.version < "10.11" + fix_message = "Please run \"Repair Disk Permissions\" in Disk Utility." + else + fix_message = "Please execute `sudo chmod +t #{HOMEBREW_TEMP}` in your Terminal" + end + + world_writable = HOMEBREW_TEMP.stat.mode & 0777 == 0777 + if world_writable && !HOMEBREW_TEMP.sticky? then <<-EOS.undent + #{HOMEBREW_TEMP} is world-writable but does not have the sticky bit set. + #{fix_message} + EOS + end + end + + (Keg::TOP_LEVEL_DIRECTORIES + ["lib/pkgconfig"]).each do |d| + define_method("check_access_#{d.sub("/", "_")}") do + dir = HOMEBREW_PREFIX.join(d) + if dir.exist? && !dir.writable_real? then <<-EOS.undent + #{dir} isn't writable. + + This can happen if you "sudo make install" software that isn't managed + by Homebrew. If a formula tries to write a file to this directory, the + install will fail during the link step. + + You should probably change the ownership and permissions of #{dir} + back to your user account. + sudo chown -R $(whoami) #{dir} + EOS + end + end + end + + def check_access_site_packages + if Language::Python.homebrew_site_packages.exist? && !Language::Python.homebrew_site_packages.writable_real? + <<-EOS.undent + #{Language::Python.homebrew_site_packages} isn't writable. + This can happen if you "sudo pip install" software that isn't managed + by Homebrew. If you install a formula with Python modules, the install + will fail during the link step. + + You should probably change the ownership and permissions of #{Language::Python.homebrew_site_packages} + back to your user account. + sudo chown -R $(whoami) #{Language::Python.homebrew_site_packages} + EOS + end + end + + def check_access_logs + if HOMEBREW_LOGS.exist? && !HOMEBREW_LOGS.writable_real? + <<-EOS.undent + #{HOMEBREW_LOGS} isn't writable. + Homebrew writes debugging logs to this location. + + You should probably change the ownership and permissions of #{HOMEBREW_LOGS} + back to your user account. + sudo chown -R $(whoami) #{HOMEBREW_LOGS} + EOS + end + end + + def check_access_cache + if HOMEBREW_CACHE.exist? && !HOMEBREW_CACHE.writable_real? + <<-EOS.undent + #{HOMEBREW_CACHE} isn't writable. + This can happen if you run `brew install` or `brew fetch` as another user. + Homebrew caches downloaded files to this location. + + You should probably change the ownership and permissions of #{HOMEBREW_CACHE} + back to your user account. + sudo chown -R $(whoami) #{HOMEBREW_CACHE} + EOS + end + end + + def check_access_cellar + if HOMEBREW_CELLAR.exist? && !HOMEBREW_CELLAR.writable_real? + <<-EOS.undent + #{HOMEBREW_CELLAR} isn't writable. + + You should probably change the ownership and permissions of #{HOMEBREW_CELLAR} + back to your user account. + sudo chown -R $(whoami) #{HOMEBREW_CELLAR} + EOS + end + end + + def check_access_prefix_opt + opt = HOMEBREW_PREFIX.join("opt") + if opt.exist? && !opt.writable_real? + <<-EOS.undent + #{opt} isn't writable. + You should probably change the ownership and permissions of #{opt} + back to your user account. + sudo chown -R $(whoami) #{opt} + EOS + end + end + + def check_ruby_version + ruby_version = MacOS.version >= "10.9" ? "2.0" : "1.8" + if RUBY_VERSION[/\d\.\d/] != ruby_version then <<-EOS.undent + Ruby version #{RUBY_VERSION} is unsupported on #{MacOS.version}. Homebrew + is developed and tested on Ruby #{ruby_version}, and may not work correctly + on other Rubies. Patches are accepted as long as they don't cause breakage + on supported Rubies. + EOS + end + end + + def check_homebrew_prefix + unless HOMEBREW_PREFIX.to_s == "/usr/local" + <<-EOS.undent + Your Homebrew is not installed to /usr/local + You can install Homebrew anywhere you want, but some brews may only build + correctly if you install in /usr/local. Sorry! + EOS + end + end + + def check_xcode_prefix + prefix = MacOS::Xcode.prefix + return if prefix.nil? + if prefix.to_s.match(" ") + <<-EOS.undent + Xcode is installed to a directory with a space in the name. + This will cause some formulae to fail to build. + EOS + end + end + + def check_xcode_prefix_exists + prefix = MacOS::Xcode.prefix + return if prefix.nil? + unless prefix.exist? + <<-EOS.undent + The directory Xcode is reportedly installed to doesn't exist: + #{prefix} + You may need to `xcode-select` the proper path if you have moved Xcode. + EOS + end + end + + def check_xcode_select_path + if !MacOS::CLT.installed? && !File.file?("#{MacOS.active_developer_dir}/usr/bin/xcodebuild") + path = MacOS::Xcode.bundle_path + path = "/Developer" if path.nil? || !path.directory? + <<-EOS.undent + Your Xcode is configured with an invalid path. + You should change it to the correct path: + sudo xcode-select -switch #{path} + EOS + end + end + + def check_user_path_1 + $seen_prefix_bin = false + $seen_prefix_sbin = false + + out = nil + + paths.each do |p| + case p + when "/usr/bin" + unless $seen_prefix_bin + # only show the doctor message if there are any conflicts + # rationale: a default install should not trigger any brew doctor messages + conflicts = Dir["#{HOMEBREW_PREFIX}/bin/*"]. + map { |fn| File.basename fn }. + select { |bn| File.exist? "/usr/bin/#{bn}" } + + if conflicts.size > 0 + out = inject_file_list conflicts, <<-EOS.undent + /usr/bin occurs before #{HOMEBREW_PREFIX}/bin + This means that system-provided programs will be used instead of those + provided by Homebrew. The following tools exist at both paths: + EOS + + out += <<-EOS.undent + + Consider setting your PATH so that #{HOMEBREW_PREFIX}/bin + occurs before /usr/bin. Here is a one-liner: + echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} + EOS + end + end + when "#{HOMEBREW_PREFIX}/bin" + $seen_prefix_bin = true + when "#{HOMEBREW_PREFIX}/sbin" + $seen_prefix_sbin = true + end + end + out + end + + def check_user_path_2 + unless $seen_prefix_bin + <<-EOS.undent + Homebrew's bin was not found in your PATH. + Consider setting the PATH for example like so + echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} + EOS + end + end + + def check_user_path_3 + # Don't complain about sbin not being in the path if it doesn't exist + sbin = (HOMEBREW_PREFIX+"sbin") + if sbin.directory? && sbin.children.length > 0 + unless $seen_prefix_sbin + <<-EOS.undent + Homebrew's sbin was not found in your PATH but you have installed + formulae that put executables in #{HOMEBREW_PREFIX}/sbin. + Consider setting the PATH for example like so + echo 'export PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"' >> #{shell_profile} + EOS + end + end + end + + def check_for_bad_curl + if MacOS.version <= "10.8" && !Formula["curl"].installed? then <<-EOS.undent + The system curl on 10.8 and below is often incapable of supporting + modern secure connections & will fail on fetching formulae. + + We recommend you: + brew install curl + EOS + end + end + + def check_user_curlrc + if %w[CURL_HOME HOME].any? { |key| ENV[key] && File.exist?("#{ENV[key]}/.curlrc") } then <<-EOS.undent + You have a curlrc file + If you have trouble downloading packages with Homebrew, then maybe this + is the problem? If the following command doesn't work, then try removing + your curlrc: + curl https://github.com + EOS + end + end + + def check_for_unsupported_curl_vars + # Support for SSL_CERT_DIR seemed to be removed in the 10.10.5 update. + if MacOS.version >= :yosemite && !ENV["SSL_CERT_DIR"].nil? then <<-EOS.undent + SSL_CERT_DIR support was removed from Apple's curl. + If fetching formulae fails you should: + unset SSL_CERT_DIR + and remove it from #{shell_profile} if present. + EOS + end + end + + def check_which_pkg_config + binary = which "pkg-config" + return if binary.nil? + + mono_config = Pathname.new("/usr/bin/pkg-config") + if mono_config.exist? && mono_config.realpath.to_s.include?("Mono.framework") then <<-EOS.undent + You have a non-Homebrew 'pkg-config' in your PATH: + /usr/bin/pkg-config => #{mono_config.realpath} + + This was most likely created by the Mono installer. `./configure` may + have problems finding brew-installed packages using this other pkg-config. + + Mono no longer installs this file as of 3.0.4. You should + `sudo rm /usr/bin/pkg-config` and upgrade to the latest version of Mono. + EOS + elsif binary.to_s != "#{HOMEBREW_PREFIX}/bin/pkg-config" then <<-EOS.undent + You have a non-Homebrew 'pkg-config' in your PATH: + #{binary} + + `./configure` may have problems finding brew-installed packages using + this other pkg-config. + EOS + end + end + + def check_for_gettext + find_relative_paths("lib/libgettextlib.dylib", + "lib/libintl.dylib", + "include/libintl.h") + + return if @found.empty? + + # Our gettext formula will be caught by check_linked_keg_only_brews + f = Formulary.factory("gettext") rescue nil + return if f && f.linked_keg.directory? && @found.all? do |path| + Pathname.new(path).realpath.to_s.start_with? "#{HOMEBREW_CELLAR}/gettext" + end + + s = <<-EOS.undent_________________________________________________________72 + gettext files detected at a system prefix + These files can cause compilation and link failures, especially if they + are compiled with improper architectures. Consider removing these files: + EOS + inject_file_list(@found, s) + end + + def check_for_iconv + unless find_relative_paths("lib/libiconv.dylib", "include/iconv.h").empty? + if (f = Formulary.factory("libiconv") rescue nil) && f.linked_keg.directory? + unless f.keg_only? then <<-EOS.undent + A libiconv formula is installed and linked + This will break stuff. For serious. Unlink it. + EOS + end + else + s = <<-EOS.undent_________________________________________________________72 + libiconv files detected at a system prefix other than /usr + Homebrew doesn't provide a libiconv formula, and expects to link against + the system version in /usr. libiconv in other prefixes can cause + compile or link failure, especially if compiled with improper + architectures. OS X itself never installs anything to /usr/local so + it was either installed by a user or some other third party software. + + tl;dr: delete these files: + EOS + inject_file_list(@found, s) + end + end + end + + def check_for_config_scripts + return unless HOMEBREW_CELLAR.exist? + real_cellar = HOMEBREW_CELLAR.realpath + + scripts = [] + + whitelist = %W[ + /usr/bin /usr/sbin + /usr/X11/bin /usr/X11R6/bin /opt/X11/bin + #{HOMEBREW_PREFIX}/bin #{HOMEBREW_PREFIX}/sbin + /Applications/Server.app/Contents/ServerRoot/usr/bin + /Applications/Server.app/Contents/ServerRoot/usr/sbin + ].map(&:downcase) + + paths.each do |p| + next if whitelist.include?(p.downcase) || !File.directory?(p) + + realpath = Pathname.new(p).realpath.to_s + next if realpath.start_with?(real_cellar.to_s, HOMEBREW_CELLAR.to_s) + + scripts += Dir.chdir(p) { Dir["*-config"] }.map { |c| File.join(p, c) } + end + + return if scripts.empty? + inject_file_list scripts, <<-EOS.undent + "config" scripts exist outside your system or Homebrew directories. + `./configure` scripts often look for *-config scripts to determine if + software packages are installed, and what additional flags to use when + compiling and linking. + + Having additional scripts in your path can confuse software installed via + Homebrew if the config script overrides a system or Homebrew provided + script of the same name. We found the following "config" scripts: + EOS + end + + def check_DYLD_vars + found = ENV.keys.grep(/^DYLD_/) + return if found.empty? + s = inject_file_list found.map { |e| "#{e}: #{ENV.fetch(e)}" }, <<-EOS.undent + Setting DYLD_* vars can break dynamic linking. + Set variables: + EOS + if found.include? "DYLD_INSERT_LIBRARIES" + s += <<-EOS.undent + + Setting DYLD_INSERT_LIBRARIES can cause Go builds to fail. + Having this set is common if you use this software: + http://asepsis.binaryage.com/ + EOS + end + s + end + + def check_for_symlinked_cellar + return unless HOMEBREW_CELLAR.exist? + if HOMEBREW_CELLAR.symlink? + <<-EOS.undent + Symlinked Cellars can cause problems. + Your Homebrew Cellar is a symlink: #{HOMEBREW_CELLAR} + which resolves to: #{HOMEBREW_CELLAR.realpath} + + The recommended Homebrew installations are either: + (A) Have Cellar be a real directory inside of your HOMEBREW_PREFIX + (B) Symlink "bin/brew" into your prefix, but don't symlink "Cellar". + + Older installations of Homebrew may have created a symlinked Cellar, but this can + cause problems when two formula install to locations that are mapped on top of each + other during the linking step. + EOS + end + end + + def check_for_multiple_volumes + return unless HOMEBREW_CELLAR.exist? + volumes = Volumes.new + + # Find the volumes for the TMP folder & HOMEBREW_CELLAR + real_cellar = HOMEBREW_CELLAR.realpath + + tmp = Pathname.new(Dir.mktmpdir("doctor", HOMEBREW_TEMP)) + real_temp = tmp.realpath.parent + + where_cellar = volumes.which real_cellar + where_temp = volumes.which real_temp + + Dir.delete tmp + + unless where_cellar == where_temp then <<-EOS.undent + Your Cellar and TEMP directories are on different volumes. + OS X won't move relative symlinks across volumes unless the target file already + exists. Brews known to be affected by this are Git and Narwhal. + + You should set the "HOMEBREW_TEMP" environmental variable to a suitable + directory on the same volume as your Cellar. + EOS + end + end + + def check_filesystem_case_sensitive + volumes = Volumes.new + case_sensitive_vols = [HOMEBREW_PREFIX, HOMEBREW_REPOSITORY, HOMEBREW_CELLAR, HOMEBREW_TEMP].select do |dir| + # We select the dir as being case-sensitive if either the UPCASED or the + # downcased variant is missing. + # Of course, on a case-insensitive fs, both exist because the os reports so. + # In the rare situation when the user has indeed a downcased and an upcased + # dir (e.g. /TMP and /tmp) this check falsely thinks it is case-insensitive + # but we don't care beacuse: 1. there is more than one dir checked, 2. the + # check is not vital and 3. we would have to touch files otherwise. + upcased = Pathname.new(dir.to_s.upcase) + downcased = Pathname.new(dir.to_s.downcase) + dir.exist? && !(upcased.exist? && downcased.exist?) + end.map { |case_sensitive_dir| volumes.get_mounts(case_sensitive_dir) }.uniq + return if case_sensitive_vols.empty? + <<-EOS.undent + The filesystem on #{case_sensitive_vols.join(",")} appears to be case-sensitive. + The default OS X filesystem is case-insensitive. Please report any apparent problems. + EOS + end + + def __check_git_version + # https://help.github.com/articles/https-cloning-errors + `git --version`.chomp =~ /git version ((?:\d+\.?)+)/ + + if $1 && Version.new($1) < Version.new("1.7.10") + git_upgrade_cmd = Formula["git"].any_version_installed? ? "upgrade" : "install" + + <<-EOS.undent + An outdated version of Git was detected in your PATH. + Git 1.7.10 or newer is required to perform checkouts over HTTPS from GitHub. + Please upgrade: brew #{git_upgrade_cmd} git + EOS + end + end + + def check_for_git + if Utils.git_available? + __check_git_version + else <<-EOS.undent + Git could not be found in your PATH. + Homebrew uses Git for several internal functions, and some formulae use Git + checkouts instead of stable tarballs. You may want to install Git: + brew install git + EOS + end + end + + def check_git_newline_settings + return unless Utils.git_available? + + autocrlf = `git config --get core.autocrlf`.chomp + + if autocrlf == "true" then <<-EOS.undent + Suspicious Git newline settings found. + + The detected Git newline settings will cause checkout problems: + core.autocrlf = #{autocrlf} + + If you are not routinely dealing with Windows-based projects, + consider removing these by running: + `git config --global core.autocrlf input` + EOS + end + end + + def check_git_origin + return if !Utils.git_available? || !(HOMEBREW_REPOSITORY/".git").exist? + + origin = Homebrew.git_origin + + if origin.nil? then <<-EOS.undent + Missing git origin remote. + + Without a correctly configured origin, Homebrew won't update + properly. You can solve this by adding the Homebrew remote: + cd #{HOMEBREW_REPOSITORY} + git remote add origin https://github.com/Homebrew/homebrew.git + EOS + elsif origin !~ /(mxcl|Homebrew)\/homebrew(\.git)?$/ then <<-EOS.undent + Suspicious git origin remote found. + + With a non-standard origin, Homebrew won't pull updates from + the main repository. The current git origin is: + #{origin} + + Unless you have compelling reasons, consider setting the + origin remote to point at the main repository, located at: + https://github.com/Homebrew/homebrew.git + EOS + end + end + + def check_for_autoconf + return unless MacOS::Xcode.provides_autotools? + + autoconf = which("autoconf") + safe_autoconfs = %w[/usr/bin/autoconf /Developer/usr/bin/autoconf] + unless autoconf.nil? || safe_autoconfs.include?(autoconf.to_s) then <<-EOS.undent + An "autoconf" in your path blocks the Xcode-provided version at: + #{autoconf} + + This custom autoconf may cause some Homebrew formulae to fail to compile. + EOS + end + end + + def __check_linked_brew(f) + f.installed_prefixes.each do |prefix| + prefix.find do |src| + next if src == prefix + dst = HOMEBREW_PREFIX + src.relative_path_from(prefix) + return true if dst.symlink? && src == dst.resolved_path + end + end + + false + end + + def check_for_linked_keg_only_brews + return unless HOMEBREW_CELLAR.exist? + + linked = Formula.installed.select do |f| + f.keg_only? && __check_linked_brew(f) + end + + return if linked.empty? + inject_file_list linked.map(&:full_name), <<-EOS.undent + Some keg-only formula are linked into the Cellar. + Linking a keg-only formula, such as gettext, into the cellar with + `brew link <formula>` will cause other formulae to detect them during + the `./configure` step. This may cause problems when compiling those + other formulae. + + Binaries provided by keg-only formulae may override system binaries + with other strange results. + + You may wish to `brew unlink` these brews: + EOS + end + + def check_for_other_frameworks + # Other frameworks that are known to cause problems when present + %w[expat.framework libexpat.framework libcurl.framework]. + map { |frmwrk| "/Library/Frameworks/#{frmwrk}" }. + select { |frmwrk| File.exist? frmwrk }. + map do |frmwrk| + <<-EOS.undent + #{frmwrk} detected + This can be picked up by CMake's build system and likely cause the build to + fail. You may need to move this file out of the way to compile CMake. + EOS + end.join + end + + def check_tmpdir + tmpdir = ENV["TMPDIR"] + "TMPDIR #{tmpdir.inspect} doesn't exist." unless tmpdir.nil? || File.directory?(tmpdir) + end + + def check_missing_deps + return unless HOMEBREW_CELLAR.exist? + missing = Set.new + Homebrew::Diagnostic.missing_deps(Formula.installed).each_value do |deps| + missing.merge(deps) + end + + if missing.any? then <<-EOS.undent + Some installed formula are missing dependencies. + You should `brew install` the missing dependencies: + + brew install #{missing.sort_by(&:full_name) * " "} + + Run `brew missing` for more details. + EOS + end + end + + def check_git_status + return unless Utils.git_available? + HOMEBREW_REPOSITORY.cd do + unless `git status --untracked-files=all --porcelain -- Library/Homebrew/ 2>/dev/null`.chomp.empty? + <<-EOS.undent_________________________________________________________72 + You have uncommitted modifications to Homebrew + If this is a surprise to you, then you should stash these modifications. + Stashing returns Homebrew to a pristine state but can be undone + should you later need to do so for some reason. + cd #{HOMEBREW_LIBRARY} && git stash && git clean -d -f + EOS + end + end + end + + def check_for_enthought_python + if which "enpkg" then <<-EOS.undent + Enthought Python was found in your PATH. + This can cause build problems, as this software installs its own + copies of iconv and libxml2 into directories that are picked up by + other build systems. + EOS + end + end + + def check_for_library_python + if File.exist?("/Library/Frameworks/Python.framework") then <<-EOS.undent + Python is installed at /Library/Frameworks/Python.framework + + Homebrew only supports building against the System-provided Python or a + brewed Python. In particular, Pythons installed to /Library can interfere + with other software installs. + EOS + end + end + + def check_for_old_homebrew_share_python_in_path + s = "" + ["", "3"].map do |suffix| + if paths.include?((HOMEBREW_PREFIX/"share/python#{suffix}").to_s) + s += "#{HOMEBREW_PREFIX}/share/python#{suffix} is not needed in PATH.\n" + end + end + unless s.empty? + s += <<-EOS.undent + Formerly homebrew put Python scripts you installed via `pip` or `pip3` + (or `easy_install`) into that directory above but now it can be removed + from your PATH variable. + Python scripts will now install into #{HOMEBREW_PREFIX}/bin. + You can delete anything, except 'Extras', from the #{HOMEBREW_PREFIX}/share/python + (and #{HOMEBREW_PREFIX}/share/python3) dir and install affected Python packages + anew with `pip install --upgrade`. + EOS + end + end + + def check_for_bad_python_symlink + return unless which "python" + `python -V 2>&1` =~ /Python (\d+)\./ + # This won't be the right warning if we matched nothing at all + return if $1.nil? + unless $1 == "2" then <<-EOS.undent + python is symlinked to python#{$1} + This will confuse build scripts and in general lead to subtle breakage. + EOS + end + end + + def check_for_non_prefixed_coreutils + gnubin = "#{Formulary.factory("coreutils").prefix}/libexec/gnubin" + if paths.include? gnubin then <<-EOS.undent + Putting non-prefixed coreutils in your path can cause gmp builds to fail. + EOS + end + end + + def check_for_non_prefixed_findutils + default_names = Tab.for_name("findutils").with? "default-names" + if default_names then <<-EOS.undent + Putting non-prefixed findutils in your path can cause python builds to fail. + EOS + end + end + + def check_for_pydistutils_cfg_in_home + if File.exist? "#{ENV["HOME"]}/.pydistutils.cfg" then <<-EOS.undent + A .pydistutils.cfg file was found in $HOME, which may cause Python + builds to fail. See: + https://bugs.python.org/issue6138 + https://bugs.python.org/issue4655 + EOS + end + end + + def check_for_outdated_homebrew + return unless Utils.git_available? + HOMEBREW_REPOSITORY.cd do + if File.directory? ".git" + local = `git rev-parse -q --verify refs/remotes/origin/master`.chomp + remote = /^([a-f0-9]{40})/.match(`git ls-remote origin refs/heads/master 2>/dev/null`) + if remote.nil? || local == remote[0] + return + end + end + + timestamp = if File.directory? ".git" + `git log -1 --format="%ct" HEAD`.to_i + else + HOMEBREW_LIBRARY.mtime.to_i + end + + if Time.now.to_i - timestamp > 60 * 60 * 24 then <<-EOS.undent + Your Homebrew is outdated. + You haven't updated for at least 24 hours. This is a long time in brewland! + To update Homebrew, run `brew update`. + EOS + end + end + end + + def check_for_unlinked_but_not_keg_only + unlinked = Formula.racks.reject do |rack| + if !(HOMEBREW_REPOSITORY/"Library/LinkedKegs"/rack.basename).directory? + begin + Formulary.from_rack(rack).keg_only? + rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError + false + end + else + true + end + end.map(&:basename) + + return if unlinked.empty? + inject_file_list unlinked, <<-EOS.undent + You have unlinked kegs in your Cellar + Leaving kegs unlinked can lead to build-trouble and cause brews that depend on + those kegs to fail to run properly once built. Run `brew link` on these: + EOS + end + + def check_xcode_license_approved + # If the user installs Xcode-only, they have to approve the + # license or no "xc*" tool will work. + if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success? then <<-EOS.undent + You have not agreed to the Xcode license. + Builds will fail! Agree to the license by opening Xcode.app or running: + sudo xcodebuild -license + EOS + end + end + + def check_for_latest_xquartz + return unless MacOS::XQuartz.version + return if MacOS::XQuartz.provided_by_apple? + + installed_version = Version.new(MacOS::XQuartz.version) + latest_version = Version.new(MacOS::XQuartz.latest_version) + + return if installed_version >= latest_version + + <<-EOS.undent + Your XQuartz (#{installed_version}) is outdated + Please install XQuartz #{latest_version}: + https://xquartz.macosforge.org + EOS + end + + def check_for_old_env_vars + if ENV["HOMEBREW_KEEP_INFO"] + <<-EOS.undent + `HOMEBREW_KEEP_INFO` is no longer used + info files are no longer deleted by default; you may + remove this environment variable. + EOS + end + end + + def check_for_pth_support + homebrew_site_packages = Language::Python.homebrew_site_packages + return unless homebrew_site_packages.directory? + return if Language::Python.reads_brewed_pth_files?("python") != false + return unless Language::Python.in_sys_path?("python", homebrew_site_packages) + user_site_packages = Language::Python.user_site_packages "python" + <<-EOS.undent + Your default Python does not recognize the Homebrew site-packages + directory as a special site-packages directory, which means that .pth + files will not be followed. This means you will not be able to import + some modules after installing them with Homebrew, like wxpython. To fix + this for the current user, you can run: + + mkdir -p #{user_site_packages} + echo 'import site; site.addsitedir("#{homebrew_site_packages}")' >> #{user_site_packages}/homebrew.pth + EOS + end + + def check_for_external_cmd_name_conflict + cmds = paths.flat_map { |p| Dir["#{p}/brew-*"] }.uniq + cmds = cmds.select { |cmd| File.file?(cmd) && File.executable?(cmd) } + cmd_map = {} + cmds.each do |cmd| + cmd_name = File.basename(cmd, ".rb") + cmd_map[cmd_name] ||= [] + cmd_map[cmd_name] << cmd + end + cmd_map.reject! { |_cmd_name, cmd_paths| cmd_paths.size == 1 } + return if cmd_map.empty? + s = "You have external commands with conflicting names.\n" + cmd_map.each do |cmd_name, cmd_paths| + s += inject_file_list cmd_paths, <<-EOS.undent + + Found command `#{cmd_name}` in following places: + EOS + end + s + end + + def all + methods.map(&:to_s).grep(/^check_/) + end + end # end class Checks + end +end
true
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/exceptions.rb
@@ -265,8 +265,8 @@ def dump puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n") end - require "cmd/doctor" - unsupported_osx = Checks.new.check_for_unsupported_osx + require "diagnostic" + unsupported_osx = Diagnostic::Checks.new.check_for_unsupported_osx opoo unsupported_osx if unsupported_osx end end
true
Other
Homebrew
brew
9f1442db14f8791c6563a701a094b4fc0c2c9b56.json
doctor: move code away from cmd/ Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/test/test_integration_cmds.rb
@@ -1,6 +1,7 @@ require "bundler" require "testing_env" require "core_formula_repository" +require "fileutils" class IntegrationCommandTests < Homebrew::TestCase def cmd_output(*args) @@ -152,7 +153,7 @@ class Foo < Formula cmd("readall", "--aliases", "--syntax") cmd("readall", "Homebrew/homebrew") ensure - formula_file.unlink + formula_file.unlink unless formula_file.nil? repo.alias_dir.rmtree end @@ -181,4 +182,58 @@ def test_tap ensure Tap::TAP_DIRECTORY.rmtree end + + def test_missing + url = "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" + sha256 = "1dfb13ce0f6143fe675b525fc9e168adb2215c5d5965c9f57306bb993170914f" + repo = CoreFormulaRepository.new + foo_file = repo.formula_dir/"foo.rb" + foo_file.write <<-EOS.undent + class Foo < Formula + url "#{url}" + sha256 "#{sha256}" + end + EOS + + bar_file = repo.formula_dir/"bar.rb" + bar_file.write <<-EOS.undent + class Bar < Formula + url "#{url}" + sha256 "#{sha256}" + depends_on "foo" + end + EOS + + cmd("install", "bar") + cmd("uninstall", "foo") + assert_match "foo", cmd("missing") + ensure + cmd("uninstall", "--force", "foo", "bar") + cmd("cleanup", "--force", "--prune=all") + foo_file.unlink unless foo_file.nil? + bar_file.unlink unless bar_file.nil? + end + + def test_doctor_check_path_for_trailing_slashes + assert_match "Some directories in your path end in a slash", + cmd_fail("doctor", "check_path_for_trailing_slashes", + {"PATH" => ENV["PATH"] + File::PATH_SEPARATOR + "/foo/bar/"}) + end + + def test_doctor_check_for_anaconda + mktmpdir do |path| + anaconda = "#{path}/anaconda" + python = "#{path}/python" + FileUtils.touch anaconda + File.open(python, "w") do |file| + file.write("#! #{`which bash`}\necho -n '#{python}'\n") + end + FileUtils.chmod 0777, anaconda + FileUtils.chmod 0777, python + + assert_match "Anaconda", + cmd_fail("doctor", "check_for_anaconda", + {"PATH" => path + File::PATH_SEPARATOR + ENV["PATH"]}) + end + end end
true
Other
Homebrew
brew
5d8a6e368f2c8fd5d2075cfb9dd8bb3928c2ac42.json
integration tests: allow env overriding
Library/Homebrew/test/test_integration_cmds.rb
@@ -4,6 +4,8 @@ class IntegrationCommandTests < Homebrew::TestCase def cmd_output(*args) + # 1.8-compatible way of writing def cmd_output(*args, **env) + env = args.last.is_a?(Hash) ? args.pop : {} cmd_args = %W[ -W0 -I#{HOMEBREW_LIBRARY_PATH}/test/lib @@ -16,6 +18,8 @@ def cmd_output(*args) ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew" ENV["HOMEBREW_INTEGRATION_TEST"] = args.join " " ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR + env.each_pair { |k,v| ENV[k] = v } + read, write = IO.pipe begin pid = fork do
false
Other
Homebrew
brew
d99cfd139424b12f662eecba28acb05994865aa0.json
tap: require string extensions Fixes Homebrew/homebrew#47684.
Library/Homebrew/tap.rb
@@ -1,3 +1,5 @@ +require "extend/string" + # a {Tap} is used to extend the formulae provided by Homebrew core. # Usually, it's synced with a remote git repository. And it's likely # a Github repository with the name of `user/homebrew-repo`. In such
false
Other
Homebrew
brew
dafa11af9a0b346d12fb9e26adb21d8cff0d5a16.json
doctor: add explicit anaconda warning Closes Homebrew/homebrew#47540. Signed-off-by: Dominyk Tiller <dominyktiller@gmail.com>
Library/Homebrew/cmd/doctor.rb
@@ -92,6 +92,31 @@ def check_for_macgpg2 end end + # Anaconda installs multiple system & brew dupes, including OpenSSL, Python, + # sqlite, libpng, Qt, etc. Regularly breaks compile on Vim, MacVim and others. + # Is flagged as part of the *-config script checks below, but people seem + # to ignore those as warnings rather than extremely likely breakage. + def check_for_anaconda + return unless which("anaconda") + return unless which("python") + + anaconda = which("anaconda").realpath.dirname + python_binary = Utils.popen_read which("python"), "-c", "import sys; sys.stdout.write(sys.executable)" + python = Pathname.new(python_binary).realpath.dirname + + # Only warn if Python lives with Anaconda, since is most problematic case. + if python == anaconda then <<-EOS.undent + Anaconda is known to frequently break Homebrew builds, including Vim and + MacVim, due to bundling many duplicates of system and Homebrew-available + tools. + + If you encounter a build failure please temporarily remove Anaconda + from your $PATH and attempt the build again prior to reporting the + failure to us. Thanks! + EOS + end + end + def __check_stray_files(dir, pattern, white_list, message) return unless File.directory?(dir)
false
Other
Homebrew
brew
bd4f633673e12793d8ec18a45c352a2d4d1fc382.json
tests: use predefined commit author for robustness Some tests, that construct a Git repository for testing, will silently fail if the global Git user isn't properly set up. There are valid use cases for this, thus use a fixed commit author/committer for all tests instead of relying on the user's configuration.
Library/Homebrew/cmd/tests.rb
@@ -5,6 +5,13 @@ def tests ENV["HOMEBREW_TESTS_COVERAGE"] = "1" if ARGV.include? "--coverage" ENV["HOMEBREW_NO_COMPAT"] = "1" if ARGV.include? "--no-compat" + # Override author/committer as global settings might be invalid and thus + # will cause silent failure during the setup of dummy Git repositories. + %w[AUTHOR COMMITTER].each do |role| + ENV["GIT_#{role}_NAME"] = "brew tests" + ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" + end + Homebrew.install_gem_setup_path! "bundler" unless quiet_system("bundle", "check") system "bundle", "install", "--path", "vendor/bundle"
false
Other
Homebrew
brew
47afde940a70f2a3a597f01bf52f1b8ad096e65f.json
formula: fix undefined method error Fixes: Homebrew/homebrew#47673. Closes Homebrew/homebrew#47672. Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Library/Homebrew/formula.rb
@@ -1495,7 +1495,7 @@ def eligible_kegs_for_cleanup # If the cellar only has one version installed, don't complain # that we can't tell which one to keep. Don't complain at all if the # only installed version is a pinned formula. - opoo "Skipping #{full_name}: most recent version #{f.pkg_version} not installed" + opoo "Skipping #{full_name}: most recent version #{pkg_version} not installed" end eligible_for_cleanup end
false
Other
Homebrew
brew
8f8c3cc1b195b29551c10fea40889dae92ac3b55.json
integration tests: fix failing test If the test fails above `formula_file`’s definition this line fails because `formula_file` is `nil`. Closes Homebrew/homebrew#47663. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/test/test_integration_cmds.rb
@@ -119,7 +119,7 @@ class Testball < Formula ensure cmd("uninstall", "--force", "testball") cmd("cleanup", "--force", "--prune=all") - formula_file.unlink + formula_file.unlink unless formula_file.nil? end def test_uninstall
false
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cleanup.rb
@@ -0,0 +1,156 @@ +require "bottles" +require "formula" +require "thread" + +module Homebrew + module Cleanup + @@disk_cleanup_size = 0 + + def self.cleanup + cleanup_cellar + cleanup_cache + cleanup_logs + unless ARGV.dry_run? + cleanup_lockfiles + rm_DS_Store + end + end + + def self.update_disk_cleanup_size(path_size) + @@disk_cleanup_size += path_size + end + + def self.disk_cleanup_size + @@disk_cleanup_size + end + + def self.cleanup_formula(formula) + formula.eligible_kegs_for_cleanup.each do |keg| + cleanup_path(keg) { keg.uninstall } + end + end + + def self.cleanup_logs + return unless HOMEBREW_LOGS.directory? + HOMEBREW_LOGS.subdirs.each do |dir| + cleanup_path(dir) { dir.rmtree } if prune?(dir, :days_default => 14) + end + end + + def self.cleanup_cellar + Formula.installed.each do |formula| + cleanup_formula formula + end + end + + def self.cleanup_cache + return unless HOMEBREW_CACHE.directory? + HOMEBREW_CACHE.children.each do |path| + if path.to_s.end_with? ".incomplete" + cleanup_path(path) { path.unlink } + next + end + if path.basename.to_s == "java_cache" && path.directory? + cleanup_path(path) { FileUtils.rm_rf path } + next + end + if prune?(path) + if path.file? + cleanup_path(path) { path.unlink } + elsif path.directory? && path.to_s.include?("--") + cleanup_path(path) { FileUtils.rm_rf path } + end + next + end + + next unless path.file? + file = path + + if Pathname::BOTTLE_EXTNAME_RX === file.to_s + version = bottle_resolve_version(file) rescue file.version + else + version = file.version + end + next unless version + next unless (name = file.basename.to_s[/(.*)-(?:#{Regexp.escape(version)})/, 1]) + + next unless HOMEBREW_CELLAR.directory? + + begin + f = Formulary.from_rack(HOMEBREW_CELLAR/name) + rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError + next + end + + file_is_stale = if PkgVersion === version + f.pkg_version > version + else + f.version > version + end + + if file_is_stale || ARGV.switch?("s") && !f.installed? || bottle_file_outdated?(f, file) + cleanup_path(file) { file.unlink } + end + end + end + + def self.cleanup_path(path) + if ARGV.dry_run? + puts "Would remove: #{path} (#{path.abv})" + else + puts "Removing: #{path}... (#{path.abv})" + yield + end + + update_disk_cleanup_size(path.disk_usage) + end + + def self.cleanup_lockfiles + return unless HOMEBREW_CACHE_FORMULA.directory? + candidates = HOMEBREW_CACHE_FORMULA.children + lockfiles = candidates.select { |f| f.file? && f.extname == ".brewing" } + lockfiles.each do |file| + next unless file.readable? + file.open.flock(File::LOCK_EX | File::LOCK_NB) && file.unlink + end + end + + def self.rm_DS_Store + paths = Queue.new + %w[Cellar Frameworks Library bin etc include lib opt sbin share var]. + map { |p| HOMEBREW_PREFIX/p }.each { |p| paths << p if p.exist? } + workers = (0...Hardware::CPU.cores).map do + Thread.new do + begin + while p = paths.pop(true) + quiet_system "find", p, "-name", ".DS_Store", "-delete" + end + rescue ThreadError # ignore empty queue error + end + end + end + workers.map(&:join) + end + + def self.prune?(path, options = {}) + @time ||= Time.now + + path_modified_time = path.mtime + days_default = options[:days_default] + + prune = ARGV.value "prune" + + return true if prune == "all" + + prune_time = if prune + @time - 60 * 60 * 24 * prune.to_i + elsif days_default + @time - 60 * 60 * 24 * days_default.to_i + end + + return false unless prune_time + + path_modified_time < prune_time + end + end +end
true
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/cleanup.rb
@@ -1,200 +1,21 @@ -require "formula" -require "keg" -require "bottles" -require "thread" +require "cleanup" require "utils" module Homebrew - @@disk_cleanup_size = 0 - - def update_disk_cleanup_size(path_size) - @@disk_cleanup_size += path_size - end - def cleanup if ARGV.named.empty? - cleanup_cellar - cleanup_cache - cleanup_logs - unless ARGV.dry_run? - cleanup_lockfiles - rm_DS_Store - end + Cleanup.cleanup else - ARGV.resolved_formulae.each { |f| cleanup_formula(f) } + ARGV.resolved_formulae.each { |f| Cleanup.cleanup_formula f } end - if @@disk_cleanup_size > 0 - disk_space = disk_usage_readable(@@disk_cleanup_size) + if Cleanup.disk_cleanup_size > 0 + disk_space = disk_usage_readable(Cleanup.disk_cleanup_size) if ARGV.dry_run? ohai "This operation would free approximately #{disk_space} of disk space." else ohai "This operation has freed approximately #{disk_space} of disk space." end end end - - def cleanup_logs - return unless HOMEBREW_LOGS.directory? - HOMEBREW_LOGS.subdirs.each do |dir| - cleanup_path(dir) { dir.rmtree } if prune?(dir, :days_default => 14) - end - end - - def cleanup_cellar - Formula.installed.each do |formula| - cleanup_formula formula - end - end - - def cleanup_formula(f) - if f.installed? - eligible_kegs = f.installed_kegs.select { |k| f.pkg_version > k.version } - if eligible_kegs.any? && eligible_for_cleanup?(f) - eligible_kegs.each { |keg| cleanup_keg(keg) } - else - eligible_kegs.each { |keg| opoo "Skipping (old) keg-only: #{keg}" } - end - elsif f.installed_prefixes.any? && !f.pinned? - # If the cellar only has one version installed, don't complain - # that we can't tell which one to keep. Don't complain at all if the - # only installed version is a pinned formula. - opoo "Skipping #{f.full_name}: most recent version #{f.pkg_version} not installed" - end - end - - def cleanup_keg(keg) - if keg.linked? - opoo "Skipping (old) #{keg} due to it being linked" - else - cleanup_path(keg) { keg.uninstall } - end - end - - def cleanup_cache - return unless HOMEBREW_CACHE.directory? - HOMEBREW_CACHE.children.each do |path| - if path.to_s.end_with? ".incomplete" - cleanup_path(path) { path.unlink } - next - end - if path.basename.to_s == "java_cache" && path.directory? - cleanup_path(path) { FileUtils.rm_rf path } - next - end - if prune?(path) - if path.file? - cleanup_path(path) { path.unlink } - elsif path.directory? && path.to_s.include?("--") - cleanup_path(path) { FileUtils.rm_rf path } - end - next - end - - next unless path.file? - file = path - - if Pathname::BOTTLE_EXTNAME_RX === file.to_s - version = bottle_resolve_version(file) rescue file.version - else - version = file.version - end - next unless version - next unless (name = file.basename.to_s[/(.*)-(?:#{Regexp.escape(version)})/, 1]) - - next unless HOMEBREW_CELLAR.directory? - - begin - f = Formulary.from_rack(HOMEBREW_CELLAR/name) - rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError - next - end - - file_is_stale = if PkgVersion === version - f.pkg_version > version - else - f.version > version - end - - if file_is_stale || ARGV.switch?("s") && !f.installed? || bottle_file_outdated?(f, file) - cleanup_path(file) { file.unlink } - end - end - end - - def cleanup_path(path) - if ARGV.dry_run? - puts "Would remove: #{path} (#{path.abv})" - else - puts "Removing: #{path}... (#{path.abv})" - yield - end - update_disk_cleanup_size(path.disk_usage) - end - - def cleanup_lockfiles - return unless HOMEBREW_CACHE_FORMULA.directory? - candidates = HOMEBREW_CACHE_FORMULA.children - lockfiles = candidates.select { |f| f.file? && f.extname == ".brewing" } - lockfiles.each do |file| - next unless file.readable? - file.open.flock(File::LOCK_EX | File::LOCK_NB) && file.unlink - end - end - - def rm_DS_Store - paths = Queue.new - %w[Cellar Frameworks Library bin etc include lib opt sbin share var]. - map { |p| HOMEBREW_PREFIX/p }.each { |p| paths << p if p.exist? } - workers = (0...Hardware::CPU.cores).map do - Thread.new do - begin - while p = paths.pop(true) - quiet_system "find", p, "-name", ".DS_Store", "-delete" - end - rescue ThreadError # ignore empty queue error - end - end - end - workers.map(&:join) - end - - def prune?(path, options = {}) - @time ||= Time.now - - path_modified_time = path.mtime - days_default = options[:days_default] - - prune = ARGV.value "prune" - - return true if prune == "all" - - prune_time = if prune - @time - 60 * 60 * 24 * prune.to_i - elsif days_default - @time - 60 * 60 * 24 * days_default.to_i - end - - return false unless prune_time - - path_modified_time < prune_time - end - - def eligible_for_cleanup?(formula) - # It used to be the case that keg-only kegs could not be cleaned up, because - # older brews were built against the full path to the keg-only keg. Then we - # introduced the opt symlink, and built against that instead. So provided - # no brew exists that was built against an old-style keg-only keg, we can - # remove it. - if !formula.keg_only? || ARGV.force? - true - elsif formula.opt_prefix.directory? - # SHA records were added to INSTALL_RECEIPTS the same day as opt symlinks - Formula.installed.select do |f| - f.deps.any? do |d| - d.to_formula.full_name == formula.full_name rescue d.name == formula.name - end - end.all? { |f| f.installed_prefixes.all? { |keg| Tab.for_keg(keg).HEAD } } - end - end end
true
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/cmd/upgrade.rb
@@ -1,5 +1,5 @@ require "cmd/install" -require "cmd/cleanup" +require "cleanup" module Homebrew def upgrade @@ -44,7 +44,9 @@ def upgrade outdated.each do |f| upgrade_formula(f) - cleanup_formula(f) if ARGV.include?("--cleanup") && f.installed? + next unless ARGV.include?("--cleanup") + next unless f.installed? + Homebrew::Cleanup.cleanup_formula f end end
true
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/formula.rb
@@ -1475,6 +1475,50 @@ def system(cmd, *args) end end + # @private + def eligible_kegs_for_cleanup + eligible_for_cleanup = [] + if installed? + eligible_kegs = installed_kegs.select { |k| pkg_version > k.version } + if eligible_kegs.any? && eligible_for_cleanup? + eligible_kegs.each do |keg| + if keg.linked? + opoo "Skipping (old) #{keg} due to it being linked" + else + eligible_for_cleanup << keg + end + end + else + eligible_kegs.each { |keg| opoo "Skipping (old) keg-only: #{keg}" } + end + elsif installed_prefixes.any? && !pinned? + # If the cellar only has one version installed, don't complain + # that we can't tell which one to keep. Don't complain at all if the + # only installed version is a pinned formula. + opoo "Skipping #{full_name}: most recent version #{f.pkg_version} not installed" + end + eligible_for_cleanup + end + + # @private + def eligible_for_cleanup? + # It used to be the case that keg-only kegs could not be cleaned up, because + # older brews were built against the full path to the keg-only keg. Then we + # introduced the opt symlink, and built against that instead. So provided + # no brew exists that was built against an old-style keg-only keg, we can + # remove it. + if !keg_only? || ARGV.force? + true + elsif opt_prefix.directory? + # SHA records were added to INSTALL_RECEIPTS the same day as opt symlinks + Formula.installed.select do |f| + f.deps.any? do |d| + d.to_formula.full_name == full_name rescue d.name == name + end + end.all? { |f| f.installed_prefixes.all? { |keg| Tab.for_keg(keg).HEAD } } + end + end + private def exec_cmd(cmd, args, out, logfn)
true
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/test/test_cleanup.rb
@@ -0,0 +1,76 @@ +require "testing_env" +require "testball" +require "cleanup" +require "fileutils" +require "pathname" + +class CleanupTests < Homebrew::TestCase + def setup + @ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store" + FileUtils.touch @ds_store + end + + def teardown + FileUtils.rm_f @ds_store + ARGV.delete "--dry-run" + ARGV.delete "--prune=all" + end + + def test_cleanup + shutup { Homebrew::Cleanup.cleanup } + refute_predicate @ds_store, :exist? + end + + def test_cleanup_dry_run + ARGV << "--dry-run" + shutup { Homebrew::Cleanup.cleanup } + assert_predicate @ds_store, :exist? + end + + def test_cleanup_formula + f1 = Class.new(Testball) { version "0.1" }.new + f2 = Class.new(Testball) { version "0.2" }.new + f3 = Class.new(Testball) { version "0.3" }.new + + shutup do + f1.brew { f1.install } + f2.brew { f2.install } + f3.brew { f3.install } + end + + assert_predicate f1, :installed? + assert_predicate f2, :installed? + assert_predicate f3, :installed? + + shutup { Homebrew::Cleanup.cleanup_formula f3 } + + refute_predicate f1, :installed? + refute_predicate f2, :installed? + assert_predicate f3, :installed? + ensure + [f1, f2, f3].each(&:clear_cache) + f3.rack.rmtree + end + + def test_cleanup_logs + path = (HOMEBREW_LOGS/"delete_me") + path.mkpath + ARGV << "--prune=all" + shutup { Homebrew::Cleanup.cleanup_logs } + refute_predicate path, :exist? + end + + def test_cleanup_cache_incomplete_downloads + incomplete = (HOMEBREW_CACHE/"something.incomplete") + incomplete.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate incomplete, :exist? + end + + def test_cleanup_cache_java_cache + java_cache = (HOMEBREW_CACHE/"java_cache") + java_cache.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate java_cache, :exist? + end +end
true
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/test/test_cmd_cleanup.rb
@@ -1,30 +0,0 @@ -require "testing_env" -require "testball" -require "cmd/cleanup" - -class CleanupTests < Homebrew::TestCase - def test_cleanup - f1 = Class.new(Testball) { version "0.1" }.new - f2 = Class.new(Testball) { version "0.2" }.new - f3 = Class.new(Testball) { version "0.3" }.new - - shutup do - f1.brew { f1.install } - f2.brew { f2.install } - f3.brew { f3.install } - end - - assert_predicate f1, :installed? - assert_predicate f2, :installed? - assert_predicate f3, :installed? - - shutup { Homebrew.cleanup_formula(f3) } - - refute_predicate f1, :installed? - refute_predicate f2, :installed? - assert_predicate f3, :installed? - ensure - [f1, f2, f3].each(&:clear_cache) - f3.rack.rmtree - end -end
true
Other
Homebrew
brew
9bdd6619e23f498320c3d3a6be8bd8d095a6d521.json
cleanup: move code away from cmd/ Closes Homebrew/homebrew#47484. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/test/test_formula.rb
@@ -1,5 +1,6 @@ require "testing_env" require "testball" +require "formula" class FormulaTests < Homebrew::TestCase def test_formula_instantiation @@ -345,4 +346,25 @@ def test_to_hash_bottle assert h.is_a?(Hash), "Formula#to_hash should return a Hash" assert h["versions"]["bottle"], "The hash should say the formula is bottled" end + + def test_eligible_kegs_for_cleanup + f1 = Class.new(Testball) { version "0.1" }.new + f2 = Class.new(Testball) { version "0.2" }.new + f3 = Class.new(Testball) { version "0.3" }.new + + shutup do + f1.brew { f1.install } + f2.brew { f2.install } + f3.brew { f3.install } + end + + assert_predicate f1, :installed? + assert_predicate f2, :installed? + assert_predicate f3, :installed? + + assert_equal f3.installed_kegs[0..1], f3.eligible_kegs_for_cleanup + ensure + [f1, f2, f3].each(&:clear_cache) + f3.rack.rmtree + end end
true
Other
Homebrew
brew
821dbab5f88e9dcbb9f08ba5ef3d8e1bf5dece3b.json
doctor: extend curl warning
Library/Homebrew/cmd/doctor.rb
@@ -677,9 +677,10 @@ def check_user_path_3 end def check_for_bad_curl - if MacOS.version <= "10.6" && !Formula["curl"].installed? then <<-EOS.undent - The system curl on 10.6 and below is often incapable of supporting + if MacOS.version <= "10.8" && !Formula["curl"].installed? then <<-EOS.undent + The system curl on 10.8 and below is often incapable of supporting modern secure connections & will fail on fetching formulae. + We recommend you: brew install curl EOS
false
Other
Homebrew
brew
c7c9919d3aaba19ea8974549d582bba189e0b2a1.json
compilers: use comma consistently
Library/Homebrew/compilers.rb
@@ -6,7 +6,7 @@ module CompilerConstants "gcc-4.0" => :gcc_4_0, "gcc-4.2" => :gcc, "llvm-gcc" => :llvm, - "clang" => :clang + "clang" => :clang, } COMPILERS = COMPILER_SYMBOL_MAP.values + @@ -67,12 +67,12 @@ def inspect create(:gcc => "4.3"), create(:gcc => "4.4"), create(:gcc => "4.5"), - create(:gcc => "4.6") + create(:gcc => "4.6"), ], :openmp => [ create(:clang), - create(:llvm) - ] + create(:llvm), + ], } end @@ -85,7 +85,7 @@ class CompilerSelector :clang => [:clang, :gcc, :llvm, :gnu, :gcc_4_0], :gcc => [:gcc, :llvm, :gnu, :clang, :gcc_4_0], :llvm => [:llvm, :gcc, :gnu, :clang, :gcc_4_0], - :gcc_4_0 => [:gcc_4_0, :gcc, :llvm, :gnu, :clang] + :gcc_4_0 => [:gcc_4_0, :gcc, :llvm, :gnu, :clang], } def self.select_for(formula, compilers = self.compilers)
false
Other
Homebrew
brew
abd4c699d1f64be9794bcf28409c3a133322fc2c.json
pathname: remove redundant spacing
Library/Homebrew/extend/pathname.rb
@@ -177,7 +177,6 @@ def default_stat end private :default_stat - # @private def cp_path_sub(pattern, replacement) raise "#{self} does not exist" unless self.exist? @@ -230,7 +229,6 @@ def rmdir_if_possible false end - # @private def version require "version"
false
Other
Homebrew
brew
cff0c63d034b79c0d9766356f0532110a12a816c.json
test_intergration_cmds: fix minor typo
Library/Homebrew/test/test_integration_cmds.rb
@@ -109,7 +109,7 @@ def test_bottle formula_file = CoreFormulaRepository.new.formula_dir/"testball.rb" formula_file.write <<-EOS.undent class Testball < Formula - url "https://example.com/testabll-0.1.tar.gz" + url "https://example.com/testball-0.1.tar.gz" end EOS HOMEBREW_CACHE.cd do
false
Other
Homebrew
brew
15fe924484f22a295f9b024b68f946e410c5531e.json
RubyRequirement: check all available ruby Closes Homebrew/homebrew#47605. Signed-off-by: Xu Cheng <xucheng@me.com>
Library/Homebrew/requirements/ruby_requirement.rb
@@ -9,14 +9,11 @@ def initialize(tags) end satisfy :build_env => false do - next unless which "ruby" - version = /\d\.\d/.match Utils.popen_read("ruby", "--version") - next unless version - Version.new(version.to_s) >= Version.new(@version) - end - - env do - ENV.prepend_path "PATH", which("ruby").dirname + which_all("ruby").detect do |ruby| + version = /\d\.\d/.match Utils.popen_read(ruby, "--version") + next unless version + Version.new(version.to_s) >= Version.new(@version) + end end def message
false
Other
Homebrew
brew
e1dfafa54ccf95d6abe5de28da53ea1e6406f567.json
Improve dash separated version detection. * Also with test case. Closes Homebrew/homebrew#47584. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/test/test_versions.rb
@@ -365,4 +365,8 @@ def test_opam_version def test_waf_version assert_version_detected "1.8.12", "https://waf.io/waf-1.8.12" end + + def test_dash_separated_version + assert_version_detected "6-20151227", "ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2" + end end
true
Other
Homebrew
brew
e1dfafa54ccf95d6abe5de28da53ea1e6406f567.json
Improve dash separated version detection. * Also with test case. Closes Homebrew/homebrew#47584. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Library/Homebrew/version.rb
@@ -312,7 +312,7 @@ def self._parse(spec) return m.captures.first unless m.nil? # e.g. lame-398-1 - m = /-((?:\d)+-\d)/.match(stem) + m = /-((?:\d)+-\d+)/.match(stem) return m.captures.first unless m.nil? # e.g. foobar-4.5.1
true