diff options
Diffstat (limited to 'Library/Homebrew/dev-cmd')
| -rw-r--r-- | Library/Homebrew/dev-cmd/aspell-dictionaries.rb | 47 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/audit.rb | 103 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/bottle.rb | 11 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/bump-formula-pr.rb | 56 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/pull.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/tests.rb | 11 |
6 files changed, 79 insertions, 157 deletions
diff --git a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb b/Library/Homebrew/dev-cmd/aspell-dictionaries.rb deleted file mode 100644 index ab0e66d2b..000000000 --- a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb +++ /dev/null @@ -1,47 +0,0 @@ -#: @hide_from_man_page -#: * `aspell_dictionaries`: -#: Generates the new dictionaries for the `aspell` formula. - -require "open-uri" -require "resource" -require "formula" - -module Homebrew - module_function - - def aspell_dictionaries - dict_url = "https://ftpmirror.gnu.org/aspell/dict" - dict_mirror = "https://ftp.gnu.org/gnu/aspell/dict" - languages = {} - - open("#{dict_url}/0index.html") do |content| - content.each_line do |line| - break if %r{^</table} =~ line - next unless /^<tr><td><a/ =~ line - - fields = line.split('"') - lang = fields[1] - path = fields[3] - lang.tr!("-", "_") - languages[lang] = path - end - end - - languages.each do |lang, path| - r = Resource.new(lang) - r.owner = Formulary.factory("aspell") - r.url "#{dict_url}/#{path}" - r.mirror "#{dict_mirror}/#{path}" - r.fetch - puts <<-EOS - option "with-lang-#{r.name}", "Install #{r.name} dictionary" - resource "#{r.name}" do - url "#{r.url}" - mirror "#{r.mirrors.first}" - sha256 "#{r.cached_download.sha256}" - end - - EOS - end - end -end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index bfe4dbc00..89ab79996 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -40,6 +40,7 @@ require "formula" require "formula_versions" require "utils" +require "utils/curl" require "extend/ENV" require "formula_cellar_checks" require "official_taps" @@ -202,98 +203,6 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def self.check_http_content(url, user_agents: [:default], check_content: false, strict: false, require_http: false) - return unless url.start_with? "http" - - details = nil - user_agent = nil - hash_needed = url.start_with?("http:") && !require_http - user_agents.each do |ua| - details = http_content_headers_and_checksum(url, hash_needed: hash_needed, user_agent: ua) - user_agent = ua - break if details[:status].to_s.start_with?("2") - end - - unless details[:status] - # Hack around https://github.com/Homebrew/brew/issues/3199 - return if MacOS.version == :el_capitan - return "The URL #{url} is not reachable" - end - - unless details[:status].start_with? "2" - return "The URL #{url} is not reachable (HTTP status code #{details[:status]})" - end - - return unless hash_needed - - secure_url = url.sub "http", "https" - secure_details = - http_content_headers_and_checksum(secure_url, hash_needed: true, user_agent: user_agent) - - if !details[:status].to_s.start_with?("2") || - !secure_details[:status].to_s.start_with?("2") - return - end - - etag_match = details[:etag] && - details[:etag] == secure_details[:etag] - content_length_match = - details[:content_length] && - details[:content_length] == secure_details[:content_length] - file_match = details[:file_hash] == secure_details[:file_hash] - - if etag_match || content_length_match || file_match - return "The URL #{url} should use HTTPS rather than HTTP" - end - - return unless check_content - - no_protocol_file_contents = %r{https?:\\?/\\?/} - details[:file] = details[:file].gsub(no_protocol_file_contents, "/") - secure_details[:file] = secure_details[:file].gsub(no_protocol_file_contents, "/") - - # Check for the same content after removing all protocols - if details[:file] == secure_details[:file] - return "The URL #{url} should use HTTPS rather than HTTP" - end - - return unless strict - - # Same size, different content after normalization - # (typical causes: Generated ID, Timestamp, Unix time) - if details[:file].length == secure_details[:file].length - return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." - end - - lenratio = (100 * secure_details[:file].length / details[:file].length).to_i - return unless (90..110).cover?(lenratio) - "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." - end - - def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) - max_time = hash_needed ? "600" : "25" - output, = curl_output( - "--connect-timeout", "15", "--include", "--max-time", max_time, "--location", url, - user_agent: user_agent - ) - - status_code = :unknown - while status_code == :unknown || status_code.to_s.start_with?("3") - headers, _, output = output.partition("\r\n\r\n") - status_code = headers[%r{HTTP\/.* (\d+)}, 1] - end - - output_hash = Digest::SHA256.digest(output) if hash_needed - - { - status: status_code, - etag: headers[%r{ETag: ([wW]\/)?"(([^"]|\\")*)"}, 2], - content_length: headers[/Content-Length: (\d+)/, 1], - file_hash: output_hash, - file: output, - } - end - def audit_style return unless @style_offenses display_cop_names = ARGV.include?("--display-cop-names") @@ -558,10 +467,10 @@ class FormulaAuditor return unless @online return unless DevelopmentTools.curl_handles_most_https_certificates? - if http_content_problem = FormulaAuditor.check_http_content(homepage, - user_agents: [:browser, :default], - check_content: true, - strict: @strict) + if http_content_problem = curl_check_http_content(homepage, + user_agents: [:browser, :default], + check_content: true, + strict: @strict) problem http_content_problem end end @@ -1037,7 +946,7 @@ class ResourceAuditor # A `brew mirror`'ed URL is usually not yet reachable at the time of # pull request. next if url =~ %r{^https://dl.bintray.com/homebrew/mirror/} - if http_content_problem = FormulaAuditor.check_http_content(url, require_http: curl_openssl_or_deps) + if http_content_problem = curl_check_http_content(url, require_http: curl_openssl_or_deps) problem http_content_problem end elsif strategy <= GitDownloadStrategy diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index a54211f5c..204e7cef9 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -469,6 +469,17 @@ module Homebrew end unless ARGV.include? "--no-commit" + if ENV["HOMEBREW_GIT_NAME"] + ENV["GIT_AUTHOR_NAME"] = + ENV["GIT_COMMITTER_NAME"] = + ENV["HOMEBREW_GIT_NAME"] + end + if ENV["HOMEBREW_GIT_EMAIL"] + ENV["GIT_AUTHOR_EMAIL"] = + ENV["GIT_COMMITTER_EMAIL"] = + ENV["HOMEBREW_GIT_EMAIL"] + end + short_name = formula_name.split("/", -1).last pkg_version = bottle_hash["formula"]["pkg_version"] diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 9fe70da6b..59dfc121d 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -117,6 +117,17 @@ module Homebrew # user path, too. ENV["PATH"] = ENV["HOMEBREW_PATH"] + # Use the user's browser, too. + ENV["BROWSER"] = ENV["HOMEBREW_BROWSER"] + + # Setup GitHub environment variables + %w[GITHUB_USER GITHUB_PASSWORD GITHUB_TOKEN].each do |env| + homebrew_env = ENV["HOMEBREW_#{env}"] + next unless homebrew_env + next if homebrew_env.empty? + ENV[env] = homebrew_env + end + formula = ARGV.formulae.first if formula @@ -169,9 +180,9 @@ module Homebrew elsif new_tag && new_revision false elsif !hash_type - odie "#{formula}: no tag/revision specified!" + odie "#{formula}: no --tag=/--revision= arguments specified!" elsif !new_url - odie "#{formula}: no url specified!" + odie "#{formula}: no --url= argument specified!" else rsrc_url = if requested_spec != :devel && new_url =~ /.*ftpmirror.gnu.*/ new_mirror = new_url.sub "ftpmirror.gnu.org", "ftp.gnu.org/gnu" @@ -183,7 +194,7 @@ module Homebrew rsrc.download_strategy = CurlDownloadStrategy rsrc.owner = Resource.new(formula.name) rsrc.version = forced_version if forced_version - odie "No version specified!" unless rsrc.version + odie "No --version= argument specified!" unless rsrc.version rsrc_path = rsrc.fetch gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? @@ -191,7 +202,7 @@ module Homebrew if Utils.popen_read(tar, "-tf", rsrc_path) =~ %r{/.*\.} new_hash = rsrc_path.sha256 elsif new_url.include? ".tar" - odie "#{formula}: no url/#{hash_type} specified!" + odie "#{formula}: no --url=/--#{hash_type}= arguments specified!" end end @@ -310,23 +321,47 @@ module Homebrew end if ARGV.dry_run? + ohai "hub fork # read $HUB_REMOTE" ohai "git fetch --unshallow origin" if shallow ohai "git checkout --no-track -b #{branch} origin/master" ohai "git commit --no-edit --verbose --message='#{formula.name} #{new_formula_version}#{devel_message}' -- #{formula.path}" - ohai "hub fork # read $HUB_REMOTE" ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}" ohai "hub pull-request #{hub_args.join(" ")} -m '#{formula.name} #{new_formula_version}#{devel_message}'" ohai "git checkout -" else + reply = IO.popen(["hub", "fork"], "r+", err: "/dev/null") do |io| + reader = Thread.new { io.read } + sleep 1 + io.close_write + reader.value + end + + if reply.to_s.include? "username:" + formula.path.atomic_write(backup_file) unless ARGV.dry_run? + git_path = "$(brew --repo #{formula.tap})" if formula.tap + git_path ||= formula.path.parent + odie <<~EOS + Retry after configuring hub by running: + hub -C "#{git_path}" fork + Or setting HOMEBREW_GITHUB_TOKEN with at least 'public_repo' scope. + EOS + end + + remote = reply[/remote:? (\S+)/, 1] + + # repeat for hub 2.2 backwards compatibility: + remote = Utils.popen_read("hub", "fork", err: :out)[/remote:? (\S+)/, 1] if remote.to_s.empty? + + if remote.to_s.empty? + formula.path.atomic_write(backup_file) unless ARGV.dry_run? + odie "cannot get remote from 'hub'!" + end + safe_system "git", "fetch", "--unshallow", "origin" if shallow safe_system "git", "checkout", "--no-track", "-b", branch, "origin/master" safe_system "git", "commit", "--no-edit", "--verbose", "--message=#{formula.name} #{new_formula_version}#{devel_message}", "--", formula.path - remote = Utils.popen_read("hub fork 2>&1")[/remote:? (\S+)/, 1] - # repeat for hub 2.2 backwards compatibility: - remote = Utils.popen_read("hub fork 2>&1")[/remote:? (\S+)/, 1] if remote.to_s.empty? - odie "cannot get remote from 'hub'!" if remote.to_s.empty? safe_system "git", "push", "--set-upstream", remote, "#{branch}:#{branch}" pr_message = <<~EOS #{formula.name} #{new_formula_version}#{devel_message} @@ -335,8 +370,9 @@ module Homebrew EOS user_message = ARGV.value("message") if user_message - pr_message += <<~EOS + pr_message += "\n" + <<~EOS --- + #{user_message} EOS end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 7746e4db3..5979d87b8 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -80,6 +80,14 @@ module Homebrew odie "This command requires at least one argument containing a URL or pull request number" end + # Passthrough Git environment variables for e.g. git am + if ENV["HOMEBREW_GIT_NAME"] + ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] + end + if ENV["HOMEBREW_GIT_EMAIL"] + ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"] + end + do_bump = ARGV.include?("--bump") && !ARGV.include?("--clean") # Formulae with affected bottles that were published diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index af9dcc575..db2a6d33e 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -82,17 +82,20 @@ module Homebrew ] end + # Generate seed ourselves and output later to avoid multiple different + # seeds being output when running parallel tests. + seed = ARGV.include?("--seed") ? ARGV.next : rand(0xFFFF).to_i + args = ["-I", HOMEBREW_LIBRARY_PATH/"test"] args += %W[ + --seed #{seed} --color --require spec_helper - --format progress + --format NoSeedProgressFormatter --format ParallelTests::RSpec::RuntimeLogger --out #{HOMEBREW_CACHE}/tests/parallel_runtime_rspec.log ] - args << "--seed" << ARGV.next if ARGV.include? "--seed" - unless OS.mac? args << "--tag" << "~needs_macos" files = files.reject { |p| p =~ %r{^test/(os/mac|cask)(/.*|_spec\.rb)$} } @@ -102,6 +105,8 @@ module Homebrew files = files.reject { |p| p =~ %r{^test/os/linux(/.*|_spec\.rb)$} } end + puts "Randomized with seed #{seed}" + if parallel system "bundle", "exec", "parallel_rspec", *opts, "--", *args, "--", *files else |
