aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb56
-rw-r--r--Library/Homebrew/diagnostic.rb2
-rw-r--r--Library/Homebrew/download_strategy.rb3
-rw-r--r--Library/Homebrew/formula.rb12
-rw-r--r--Library/Homebrew/formula_installer.rb1
-rw-r--r--Library/Homebrew/keg.rb5
-rw-r--r--Library/Homebrew/manpages/brew.1.md.erb39
-rw-r--r--Library/Homebrew/rubocops/components_order_cop.rb57
-rw-r--r--Library/Homebrew/rubocops/extend/formula_cop.rb5
-rw-r--r--Library/Homebrew/sandbox.rb4
-rwxr-xr-xLibrary/Homebrew/shims/scm/git1
-rw-r--r--Library/Homebrew/test/diagnostic_spec.rb2
-rw-r--r--Library/Homebrew/test/rubocops/components_order_cop_spec.rb47
-rw-r--r--Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb25
-rw-r--r--Library/Homebrew/utils.rb4
15 files changed, 197 insertions, 66 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index 0b9fe0a7e..cbe26b422 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -307,25 +307,41 @@ class FormulaAuditor
unversioned_name = unversioned_formula.basename(".rb")
problem "#{formula} is versioned but no #{unversioned_name} formula exists"
end
- elsif ARGV.build_stable?
- versioned_formulae = Dir[formula.path.to_s.gsub(/\.rb$/, "@*.rb")]
- needs_versioned_alias = !versioned_formulae.empty? &&
- formula.tap &&
- formula.aliases.grep(/.@\d/).empty?
- if needs_versioned_alias
- _, last_alias_version = File.basename(versioned_formulae.sort.reverse.first)
- .gsub(/\.rb$/, "")
- .split("@")
- major, minor, = formula.version.to_s.split(".")
- alias_name = if last_alias_version.split(".").length == 1
- "#{formula.name}@#{major}"
+ elsif ARGV.build_stable? &&
+ !(versioned_formulae = Dir[formula.path.to_s.gsub(/\.rb$/, "@*.rb")]).empty?
+ versioned_aliases = formula.aliases.grep(/.@\d/)
+ _, last_alias_version =
+ File.basename(versioned_formulae.sort.reverse.first)
+ .gsub(/\.rb$/, "").split("@")
+ major, minor, = formula.version.to_s.split(".")
+ alias_name_major = "#{formula.name}@#{major}"
+ alias_name_major_minor = "#{alias_name_major}.#{minor}"
+ alias_name = if last_alias_version.split(".").length == 1
+ alias_name_major
+ else
+ alias_name_major_minor
+ end
+ valid_alias_names = [alias_name_major, alias_name_major_minor]
+
+ valid_versioned_aliases = versioned_aliases & valid_alias_names
+ invalid_versioned_aliases = versioned_aliases - valid_alias_names
+
+ if valid_versioned_aliases.empty?
+ if formula.tap
+ problem <<-EOS.undent
+ Formula has other versions so create a versioned alias:
+ cd #{formula.tap.alias_dir}
+ ln -s #{formula.path.to_s.gsub(formula.tap.path, "..")} #{alias_name}
+ EOS
else
- "#{formula.name}@#{major}.#{minor}"
+ problem "Formula has other versions so create an alias named #{alias_name}."
end
+ end
+
+ unless invalid_versioned_aliases.empty?
problem <<-EOS.undent
- Formula has other versions so create an alias:
- cd #{formula.tap.alias_dir}
- ln -s #{formula.path.to_s.gsub(formula.tap.path, "..")} #{alias_name}
+ Formula has invalid versioned aliases:
+ #{invalid_versioned_aliases.join("\n ")}
EOS
end
end
@@ -967,8 +983,12 @@ class FormulaAuditor
problem "#{$2} modules should be vendored rather than use deprecated `depends_on \"#{$1}\" => :#{$2}#{$3}`"
end
- if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+.*(?<!\?[( ])['"](.+)['"]/
- problem "Dependency #{$1} should not use option #{$2}"
+ if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+(.*)/
+ dep = $1
+ $2.split(" ").map do |o|
+ next unless o =~ /^\[?['"](.*)['"]/
+ problem "Dependency #{dep} should not use option #{$1}"
+ end
end
# Commented-out depends_on
diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index 1544e6765..6bb5c8b8e 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -100,7 +100,7 @@ module Homebrew
# See https://github.com/Homebrew/legacy-homebrew/pull/9986
def check_path_for_trailing_slashes
- bad_paths = PATH.new(ENV["PATH"]).select { |p| p.end_with?("/") }
+ bad_paths = PATH.new(ENV["HOMEBREW_PATH"]).select { |p| p.end_with?("/") }
return if bad_paths.empty?
inject_file_list bad_paths, <<-EOS.undent
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index a0025cef3..d74efe0bb 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -520,6 +520,9 @@ class S3DownloadStrategy < CurlDownloadStrategy
bucket = $1
key = $2
+ ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"]
+ ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"]
+
obj = AWS::S3.new.buckets[bucket].objects[key]
begin
s3url = obj.url_for(:get)
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 17a34dd13..1b3b718da 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1943,8 +1943,10 @@ class Formula
old_curl_home = ENV["CURL_HOME"]
old_path = ENV["HOMEBREW_PATH"]
- ENV["HOME"] = env_home
- ENV["CURL_HOME"] = old_curl_home || old_home
+ unless ARGV.interactive?
+ ENV["HOME"] = env_home
+ ENV["CURL_HOME"] = old_curl_home || old_home
+ end
ENV["HOMEBREW_PATH"] = nil
setup_home env_home
@@ -1955,8 +1957,10 @@ class Formula
yield staging
ensure
@buildpath = nil
- ENV["HOME"] = old_home
- ENV["CURL_HOME"] = old_curl_home
+ unless ARGV.interactive?
+ ENV["HOME"] = old_home
+ ENV["CURL_HOME"] = old_curl_home
+ end
ENV["HOMEBREW_PATH"] = old_path
end
end
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index ad87c2a5f..f50d9ed9e 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -664,6 +664,7 @@ class FormulaInstaller
sandbox = Sandbox.new
formula.logs.mkpath
sandbox.record_log(formula.logs/"build.sandbox.log")
+ sandbox.allow_write_path(ENV["HOME"]) if ARGV.interactive?
sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula)
sandbox.allow_write_xcode
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index d4b9c5d77..8733def27 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -468,7 +468,10 @@ class Keg
end
def aliases
- Formulary.from_rack(rack).aliases
+ formula = Formulary.from_rack(rack)
+ aliases = formula.aliases
+ return aliases if formula.stable?
+ aliases.reject { |a| a.include?("@") }
rescue FormulaUnavailableError
[]
end
diff --git a/Library/Homebrew/manpages/brew.1.md.erb b/Library/Homebrew/manpages/brew.1.md.erb
index 5b0228e3f..29f8d0bec 100644
--- a/Library/Homebrew/manpages/brew.1.md.erb
+++ b/Library/Homebrew/manpages/brew.1.md.erb
@@ -98,8 +98,15 @@ can take several different forms:
The formula file will be cached for later use.
## ENVIRONMENT
+ * `HOMEBREW_ARTIFACT_DOMAIN`:
+ If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries.
+
+ * `HOMEBREW_AUTO_UPDATE_SECS`:
+ If set, Homebrew will only check for autoupdates once per this seconds interval.
+
+ *Default:* `60`.
- * `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`:
+ * `HOMEBREW_AWS_ACCESS_KEY_ID`, `HOMEBREW_AWS_SECRET_ACCESS_KEY`:
When using the `S3` download strategy, Homebrew will look in
these variables for access credentials (see
<https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment>
@@ -107,30 +114,9 @@ can take several different forms:
the `S3` download strategy will download with a public
(unsigned) URL.
- * `BROWSER`:
- If set, and `HOMEBREW_BROWSER` is not, use `BROWSER` as the web browser
- when opening project homepages.
-
- * `EDITOR`:
- If set, and `HOMEBREW_EDITOR` and `VISUAL` are not, use `EDITOR` as the text editor.
-
- * `GIT`:
- When using Git, Homebrew will use `GIT` if set,
- a Homebrew-built Git if installed, or the system-provided binary.
-
- Set this to force Homebrew to use a particular git binary.
-
* `HOMEBREW_BOTTLE_DOMAIN`:
If set, instructs Homebrew to use the given URL as a download mirror for bottles.
- * `HOMEBREW_ARTIFACT_DOMAIN`:
- If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries.
-
- * `HOMEBREW_AUTO_UPDATE_SECS`:
- If set, Homebrew will only check for autoupdates once per this seconds interval.
-
- *Default:* `60`.
-
* `HOMEBREW_BROWSER`:
If set, uses this setting as the browser when opening project homepages,
instead of the OS default browser.
@@ -178,6 +164,12 @@ can take several different forms:
If set, Homebrew will always use its vendored, relocatable Ruby 2.0 version
even if the system version of Ruby is >=2.0.
+ * `HOMEBREW_GIT`:
+ When using Git, Homebrew will use `GIT` if set,
+ a Homebrew-built Git if installed, or the system-provided binary.
+
+ Set this to force Homebrew to use a particular git binary.
+
* `HOMEBREW_GITHUB_API_TOKEN`:
A personal access token for the GitHub API, which you can create at
<https://github.com/settings/tokens>. If set, GitHub will allow you a
@@ -243,9 +235,6 @@ can take several different forms:
* `HOMEBREW_VERBOSE`:
If set, Homebrew always assumes `--verbose` when running commands.
- * `VISUAL`:
- If set, and `HOMEBREW_EDITOR` is not, use `VISUAL` as the text editor.
-
## USING HOMEBREW BEHIND A PROXY
Homebrew uses several commands for downloading files (e.g. `curl`, `git`, `svn`).
diff --git a/Library/Homebrew/rubocops/components_order_cop.rb b/Library/Homebrew/rubocops/components_order_cop.rb
index a6259133d..dfddbe145 100644
--- a/Library/Homebrew/rubocops/components_order_cop.rb
+++ b/Library/Homebrew/rubocops/components_order_cop.rb
@@ -36,7 +36,7 @@ module RuboCop
[{ name: :test, type: :block_call }],
]
- present_components = component_precedence_list.map do |components|
+ @present_components = component_precedence_list.map do |components|
relevant_components = []
components.each do |component|
case component[:type]
@@ -51,20 +51,63 @@ module RuboCop
relevant_components.delete_if(&:nil?)
end
- present_components = present_components.delete_if(&:empty?)
-
- present_components.each_cons(2) do |preceding_component, succeeding_component|
- offensive_nodes = check_precedence(preceding_component, succeeding_component)
- component_problem offensive_nodes[0], offensive_nodes[1] if offensive_nodes
+ # Check if each present_components is above rest of the present_components
+ @present_components.take(@present_components.size-1).each_with_index do |preceding_component, p_idx|
+ next if preceding_component.empty?
+ @present_components.drop(p_idx+1).each do |succeeding_component|
+ next if succeeding_component.empty?
+ @offensive_nodes = check_precedence(preceding_component, succeeding_component)
+ component_problem @offensive_nodes[0], @offensive_nodes[1] if @offensive_nodes
+ end
end
end
private
+ # Method to format message for reporting component precedence violations
def component_problem(c1, c2)
- # Method to format message for reporting component precedence violations
problem "`#{format_component(c1)}` (line #{line_number(c1)}) should be put before `#{format_component(c2)}` (line #{line_number(c2)})"
end
+
+ # autocorrect method gets called just after component_problem method call
+ def autocorrect(_node)
+ succeeding_node = @offensive_nodes[0]
+ preceding_node = @offensive_nodes[1]
+ lambda do |corrector|
+ reorder_components(corrector, succeeding_node, preceding_node)
+ end
+ end
+
+ # Reorder two nodes in the source, using the corrector instance in autocorrect method
+ # Components of same type are grouped together when rewriting the source
+ # Linebreaks are introduced if components are of two different methods/blocks/multilines
+ def reorder_components(corrector, node1, node2)
+ # order_idx : node1's index in component_precedence_list
+ # curr_p_idx: node1's index in preceding_comp_arr
+ # preceding_comp_arr: array containing components of same type
+ order_idx, curr_p_idx, preceding_comp_arr = get_state(node1)
+
+ # curr_p_idx > 0 means node1 needs to be grouped with its own kind
+ if curr_p_idx>0
+ node2 = preceding_comp_arr[curr_p_idx-1]
+ indentation = " " * (start_column(node2) - line_start_column(node2))
+ line_breaks = node2.multiline? ? "\n\n" : "\n"
+ corrector.insert_after(node2.source_range, line_breaks+indentation+node1.source)
+ else
+ indentation = " " * (start_column(node2) - line_start_column(node2))
+ # No line breaks upto version_scheme, order_idx == 8
+ line_breaks = order_idx>8 ? "\n\n" : "\n"
+ corrector.insert_before(node2.source_range, node1.source+line_breaks+indentation)
+ end
+ corrector.remove(range_with_surrounding_space(node1.source_range, :left))
+ end
+
+ # Returns precedence index and component's index to properly reorder and group during autocorrect
+ def get_state(node1)
+ @present_components.each_with_index do |comp, idx|
+ return [idx, comp.index(node1), comp] if comp.member?(node1)
+ end
+ end
end
end
end
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index 4120be6ef..3f70086b3 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -180,9 +180,10 @@ module RuboCop
node.source_range.source_buffer
end
- # Returns the string representation if node is of type str
+ # Returns the string representation if node is of type str(plain) or dstr(interpolated)
def string_content(node)
- node.str_content if node.type == :str
+ return node.str_content if node.type == :str
+ node.each_child_node(:str).map(&:str_content).join("") if node.type == :dstr
end
# Returns printable component name
diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb
index 9597dafa8..b16bbde1a 100644
--- a/Library/Homebrew/sandbox.rb
+++ b/Library/Homebrew/sandbox.rb
@@ -5,10 +5,6 @@ class Sandbox
SANDBOX_EXEC = "/usr/bin/sandbox-exec".freeze
SANDBOXED_TAPS = %w[
homebrew/core
- homebrew/dupes
- homebrew/fuse
- homebrew/devel-only
- homebrew/tex
].freeze
def self.available?
diff --git a/Library/Homebrew/shims/scm/git b/Library/Homebrew/shims/scm/git
index 82bb47c25..bfb779c25 100755
--- a/Library/Homebrew/shims/scm/git
+++ b/Library/Homebrew/shims/scm/git
@@ -86,7 +86,6 @@ fi
case "$(lowercase "$SCM_FILE")" in
git)
[[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(which "$HOMEBREW_GIT")" "$@"
- [[ -n "$GIT" ]] && safe_exec "$(which "$GIT")" "$@"
;;
svn)
[[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(which "$HOMEBREW_SVN")" "$@"
diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_spec.rb
index 12a8e0c42..c4373671e 100644
--- a/Library/Homebrew/test/diagnostic_spec.rb
+++ b/Library/Homebrew/test/diagnostic_spec.rb
@@ -7,7 +7,7 @@ describe Homebrew::Diagnostic::Checks do
end
specify "#check_path_for_trailing_slashes" do
- ENV["PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
+ ENV["HOMEBREW_PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
expect(subject.check_path_for_trailing_slashes)
.to match("Some directories in your path end in a slash")
end
diff --git a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
index 05ff53d8f..25467c635 100644
--- a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
@@ -113,4 +113,51 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
expect(actual.column).to eq(expected[:column])
end
end
+
+ context "When auditing formula components order with autocorrect" do
+ it "When url precedes homepage" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+ end
+ EOS
+ correct_source = <<-EOS.undent
+ class Foo < Formula
+ homepage "http://example.com"
+ url "http://example.com/foo-1.0.tgz"
+ end
+ EOS
+
+ corrected_source = autocorrect_source(cop, source)
+ expect(corrected_source).to eq(correct_source)
+ end
+
+ it "When `resource` precedes `depends_on`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ resource "foo2" do
+ url "https://example.com/foo-2.0.tgz"
+ end
+
+ depends_on "openssl"
+ end
+ EOS
+ correct_source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ depends_on "openssl"
+
+ resource "foo2" do
+ url "https://example.com/foo-2.0.tgz"
+ end
+ end
+ EOS
+ corrected_source = autocorrect_source(cop, source)
+ expect(corrected_source).to eq(correct_source)
+ end
+ end
end
diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
index 581667935..432b15e3c 100644
--- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
@@ -51,6 +51,31 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
end
end
+ it "When desc is multiline string" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ desc '#{"bar"*10}'\
+ '#{"foo"*21}'
+ end
+ EOS
+
+ msg = <<-EOS.undent
+ Description is too long. "name: desc" should be less than 80 characters.
+ Length is calculated as Foo + desc. (currently 98)
+ EOS
+ expected_offenses = [{ message: msg,
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
it "When wrong \"command-line\" usage in desc" do
source = <<-EOS.undent
class Foo < Formula
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index c37633e41..28d7fc283 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -320,7 +320,7 @@ def which_all(cmd, path = ENV["PATH"])
end
def which_editor
- editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL").compact.reject(&:empty?).first
+ editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first
if editor
editor_name, _, editor_args = editor.partition " "
editor_path = which(editor_name, ENV["HOMEBREW_PATH"])
@@ -356,7 +356,7 @@ def exec_editor(*args)
end
def exec_browser(*args)
- browser = ENV["HOMEBREW_BROWSER"] || ENV["BROWSER"]
+ browser = ENV["HOMEBREW_BROWSER"]
browser ||= OS::PATH_OPEN if defined?(OS::PATH_OPEN)
return unless browser
safe_exec(browser, *args)