From ce092d90fab059309775209f04c7a8a9f08b5688 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sun, 4 Sep 2016 11:28:38 -0700 Subject: bump-formula-pr: set sha256 automatically when possible --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index ce10da52a..5b3b4773d 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -89,7 +89,16 @@ module Homebrew elsif !hash_type odie "#{formula}: no tag/revision specified!" else - odie "#{formula}: no url/#{hash_type} specified!" + rsrc = Resource.new { @url = new_url } + rsrc.download_strategy = CurlDownloadStrategy + rsrc.owner = Resource.new(formula.name) + rsrc_path = rsrc.fetch + if Utils.popen_read("/usr/bin/tar", "-tf", rsrc_path) =~ /\/.*\./ + new_hash = rsrc_path.sha256 + else + odie "#{formula}: no url/#{hash_type} specified!" if new_url.include?(".tar") + new_hash = rsrc_path.sha256 + end end if ARGV.dry_run? -- cgit v1.2.3 From 743e9bbdaad1dc8cd23ae49ef3b42e3fc9f4a16a Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sun, 4 Sep 2016 11:20:03 -0700 Subject: bump-formula-pr: formula name guessing --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 5b3b4773d..79bfe2010 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -64,6 +64,25 @@ module Homebrew def bump_formula_pr formula = ARGV.formulae.first + new_url = ARGV.value("url") + if new_url && !formula + is_devel = ARGV.include?("--devel") + base_url = new_url.split("/")[0..4].join("/") + base_url = /#{Regexp.escape(base_url)}/ + guesses = [] + Formula.each do |f| + if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) + guesses << f + elsif f.stable && f.stable.url && f.stable.url.match(base_url) + guesses << f + end + end + if guesses.count == 1 + formula = guesses.shift + elsif guesses.count > 1 + odie "Couldn't guess formula for sure: could be one of these:\n#{guesses}" + end + end odie "No formula found!" unless formula requested_spec, formula_spec = if ARGV.include?("--devel") @@ -78,7 +97,6 @@ module Homebrew [checksum.hash_type.to_s, checksum.hexdigest] end - new_url = ARGV.value("url") new_hash = ARGV.value(hash_type) new_tag = ARGV.value("tag") new_revision = ARGV.value("revision") -- cgit v1.2.3 From 19df03219bfedaf29f1ed92c6b0b26e757163197 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sun, 4 Sep 2016 11:28:02 -0700 Subject: bump-formula-pr: --mirror option --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 79bfe2010..b67b48730 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -100,6 +100,7 @@ module Homebrew new_hash = ARGV.value(hash_type) new_tag = ARGV.value("tag") new_revision = ARGV.value("revision") + new_mirror = ARGV.value("mirror") new_url_hash = if new_url && new_hash true elsif new_tag && new_revision @@ -132,6 +133,10 @@ module Homebrew replacement_pairs << [/^ revision \d+\n(\n( head "))?/m, "\\2"] end + if requested_spec == :stable + replacement_pairs << [/(^ mirror .*\n)?/, ""] + end + replacement_pairs += if new_url_hash [ [formula_spec.url, new_url], @@ -146,6 +151,10 @@ module Homebrew backup_file = File.read(formula.path) unless ARGV.dry_run? + if new_mirror + replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1mirror \"#{new_mirror}\"\n"] + end + new_contents = inreplace_pairs(formula.path, replacement_pairs) new_formula_version = formula_version(formula, requested_spec, new_contents) -- cgit v1.2.3 From a9a62972bdce95a2b94db1be2e732480d88e17eb Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 6 Jul 2016 05:00:45 -0700 Subject: bump-formula-pr: handle explicit version DSL --version=1.2.3 option to set `version "1.2.3"` Note that --version=0 will remove a no-longer-needed explicit version --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index b67b48730..2d89d85e8 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -101,6 +101,7 @@ module Homebrew new_tag = ARGV.value("tag") new_revision = ARGV.value("revision") new_mirror = ARGV.value("mirror") + forced_version = ARGV.value("version") new_url_hash = if new_url && new_hash true elsif new_tag && new_revision @@ -155,6 +156,11 @@ module Homebrew replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1mirror \"#{new_mirror}\"\n"] end + if forced_version && forced_version != "0" + replacement_pairs << [old_formula_version, forced_version] + elsif forced_version && forced_version == "0" + replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] + end new_contents = inreplace_pairs(formula.path, replacement_pairs) new_formula_version = formula_version(formula, requested_spec, new_contents) -- cgit v1.2.3 From 394b0884ebd037ac69e44a6bab23d6e2341fb49c Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sun, 4 Sep 2016 11:21:08 -0700 Subject: bump-formula-pr: handle gnu mirrors and add explicit version when not preexisting --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 2d89d85e8..a38d6edb5 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -109,7 +109,13 @@ module Homebrew elsif !hash_type odie "#{formula}: no tag/revision specified!" else - rsrc = Resource.new { @url = new_url } + rsrc_url = if requested_spec != :devel && new_url =~ /.*ftpmirror.gnu.*/ + new_mirror = new_url.sub "ftpmirror.gnu.org", "ftp.gnu.org/gnu" + new_mirror + else + new_url + end + rsrc = Resource.new { @url = rsrc_url } rsrc.download_strategy = CurlDownloadStrategy rsrc.owner = Resource.new(formula.name) rsrc_path = rsrc.fetch @@ -157,7 +163,15 @@ module Homebrew end if forced_version && forced_version != "0" - replacement_pairs << [old_formula_version, forced_version] + if File.read(formula.path).include?("version \"#{old_formula_version}\"") + replacement_pairs << [old_formula_version.to_s, forced_version] + else + if new_mirror + replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + else + replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + end + end elsif forced_version && forced_version == "0" replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] end -- cgit v1.2.3 From f4cfb9ee87788dca0c0ca8e90bf0d17c43f1706e Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sun, 4 Sep 2016 11:25:00 -0700 Subject: bump-formula-pr: add --write option intended to be used in combination with --dry-run for a not-so-dry run the expected file modifications are made, but no git actions are taken --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index a38d6edb5..4ad230703 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -38,6 +38,7 @@ module Homebrew unless contents.errors.empty? raise Utils::InreplaceError, path => contents.errors end + path.atomic_write(contents) if ARGV.include?("--write") contents else Utils::Inreplace.inreplace(path) do |s| -- cgit v1.2.3 From ff51e09e170bd7508b8e20e9946ded5af0aa4c92 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Tue, 27 Sep 2016 02:50:46 -0700 Subject: bump-formula-pr: forced_version support for devel --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 4ad230703..f36584ff6 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -164,17 +164,25 @@ module Homebrew end if forced_version && forced_version != "0" - if File.read(formula.path).include?("version \"#{old_formula_version}\"") - replacement_pairs << [old_formula_version.to_s, forced_version] - else - if new_mirror - replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + if requested_spec == :stable + if File.read(formula.path).include?("version \"#{old_formula_version}\"") + replacement_pairs << [old_formula_version.to_s, forced_version] else - replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + if new_mirror + replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + else + replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] + end end + elsif requested_spec == :devel + replacement_pairs << [/( devel do.+?version \")#{old_formula_version}(\"\n.+?end\n)/m, "\\1#{forced_version}\\2"] end elsif forced_version && forced_version == "0" - replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] + if requested_spec == :stable + replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] + elsif requested_spec == :devel + replacement_pairs << [/( devel do.+?)^ +version \"[^\n]+\"\n(.+?end\n)/m, "\\1\\2"] + end end new_contents = inreplace_pairs(formula.path, replacement_pairs) -- cgit v1.2.3 From 5247cb83d78ad70db6a64f21cf11ff049be5ca91 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Tue, 27 Sep 2016 03:30:40 -0700 Subject: bump-formula-pr: style fixes --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index f36584ff6..2d4c0828b 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -120,11 +120,10 @@ module Homebrew rsrc.download_strategy = CurlDownloadStrategy rsrc.owner = Resource.new(formula.name) rsrc_path = rsrc.fetch - if Utils.popen_read("/usr/bin/tar", "-tf", rsrc_path) =~ /\/.*\./ - new_hash = rsrc_path.sha256 - else - odie "#{formula}: no url/#{hash_type} specified!" if new_url.include?(".tar") + if Utils.popen_read("/usr/bin/tar", "-tf", rsrc_path) =~ %r{/.*\.} new_hash = rsrc_path.sha256 + elsif new_url.include? ".tar" + odie "#{formula}: no url/#{hash_type} specified!" end end @@ -141,9 +140,7 @@ module Homebrew replacement_pairs << [/^ revision \d+\n(\n( head "))?/m, "\\2"] end - if requested_spec == :stable - replacement_pairs << [/(^ mirror .*\n)?/, ""] - end + replacement_pairs << [/(^ mirror .*\n)?/, ""] if requested_spec == :stable replacement_pairs += if new_url_hash [ @@ -167,12 +164,10 @@ module Homebrew if requested_spec == :stable if File.read(formula.path).include?("version \"#{old_formula_version}\"") replacement_pairs << [old_formula_version.to_s, forced_version] + elsif new_mirror + replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] else - if new_mirror - replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] - else - replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] - end + replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] end elsif requested_spec == :devel replacement_pairs << [/( devel do.+?version \")#{old_formula_version}(\"\n.+?end\n)/m, "\\1#{forced_version}\\2"] -- cgit v1.2.3 From 3811f57006aba36a76ed46e905fbf28b0836b37a Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Tue, 27 Sep 2016 03:29:47 -0700 Subject: bump-formula-pr: document new options --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 2d4c0828b..31e9cd2c1 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -3,7 +3,8 @@ #: Creates a pull request to update the formula with a new url or a new tag. #: #: If a is specified, the checksum of the new download must -#: also be specified. +#: also be specified. A best effort to determine the and +#: name will be made if either or both values are not supplied by the user. #: #: If a is specified, the git commit corresponding to that #: tag must also be specified. @@ -13,10 +14,19 @@ #: #: If `--dry-run` is passed, print what would be done rather than doing it. #: +#: If `--write` is passed along with `--dry-run`, perform a not-so-dry run +#: making the expected file modifications but not taking any git actions. +#: #: If `--audit` is passed, run `brew audit` before opening the PR. #: #: If `--strict` is passed, run `brew audit --strict` before opening the PR. #: +#: If `--mirror=` is passed, use the value as a mirror url. +#: +#: If `--version=` is passed, use the value to override the value +#: parsed from the url or tag. Note that `--version=0` can be used to delete +#: an existing `version` override from a formula if it has become redundant. +#: #: Note that this command cannot be used to transition a formula from a #: url-and-sha256 style specification into a tag-and-revision style #: specification, nor vice versa. It must use whichever style specification -- cgit v1.2.3