Merge pull request #7875 from Bo98/license-bottle-block

dev-cmd/bottle: fix positioning of bottle block in some cases
This commit is contained in:
Bo Anderson 2020-07-02 18:11:08 +01:00 committed by GitHub
commit c1cbf1a1cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -531,25 +531,21 @@ module Homebrew
odie "--keep-old was passed but there was no existing bottle block!" if args.keep_old? odie "--keep-old was passed but there was no existing bottle block!" if args.keep_old?
puts output puts output
update_or_add = "add" update_or_add = "add"
if s.include? "stable do" pattern = /(
indent = s.slice(/^( +)stable do/, 1).length (\ {2}\#[^\n]*\n)* # comments
string = s.sub!(/^ {#{indent}}stable do(.|\n)+?^ {#{indent}}end\n/m, '\0' + output + "\n") \ {2}( # two spaces at the beginning
else (url|head)\ ['"][\S\ ]+['"] # url or head with a string
pattern = /( (
(\ {2}\#[^\n]*\n)* # comments ,[\S\ ]*$ # url may have options
\ {2}( # two spaces at the beginning (\n^\ {3}[\S\ ]+$)* # options can be in multiple lines
(url|head)\ ['"][\S\ ]+['"] # url or head with a string )?|
( (homepage|desc|sha256|version|mirror|license)\ ['"][\S\ ]+['"]| # specs with a string
,[\S\ ]*$ # url may have options (revision|version_scheme)\ \d+| # revision with a number
(\n^\ {3}[\S\ ]+$)* # options can be in multiple lines (stable|livecheck)\ do(\n+^\ {4}[\S\ ]+$)*\n+^\ {2}end # components with blocks
)?| )\n+ # multiple empty lines
(homepage|desc|sha1|sha256|version|mirror)\ ['"][\S\ ]+['"]| # specs with a string )+
(revision|version_scheme)\ \d+ # revision with a number /mx
)\n+ # multiple empty lines string = s.sub!(pattern, '\0' + output + "\n")
)+
/mx
string = s.sub!(pattern, '\0' + output + "\n")
end
odie "Bottle block addition failed!" unless string odie "Bottle block addition failed!" unless string
end end
end end