Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

new patch DSL, with support for checksums #21648

Closed
wants to merge 4 commits into from

Conversation

camillol
Copy link
Contributor

@camillol camillol commented Aug 4, 2013

Man has long dreamed of having checksumming supported for patches (#6795, #10199).
Unfortunately, all who have tried the challenge ended up giving up (#11956).

Until now.

New DSL examples (from the socat formula):

patch :p0, "https://trac.macports.org/export/90442/trunk/dports/sysutils/socat/files/patch-xioexit.c.diff", "4a72f278d960310144556f7e1c2645f492b289bdc28de9f786a1ecd6dcdf21b7"
patch :p1, DATA if build.devel?

Yes, the lines are long.

[SNIP]

@MikeMcQuaid
Copy link
Member

I'm in favour of this in theory as long as Homebrew can provide new checksums (which isn't clear from the code) and we can do something about the line length (perhaps use a block instead)?

@camillol
Copy link
Contributor Author

camillol commented Aug 4, 2013

What do you mean by homebrew providing new checksums?

For the long lines, you can just break them:

patch :p0,
  "https://trac.macports.org/export/90442/trunk/dports/sysutils/socat/files/patch-xioexit.c.diff",
  "4a72f278d960310144556f7e1c2645f492b289bdc28de9f786a1ecd6dcdf21b7"
patch :p1, DATA if build.devel?

@camillol camillol mentioned this pull request Aug 4, 2013
@jacknagel
Copy link
Contributor

Test suite needs to be updated, it doesn't even run after applying this

@@ -43,6 +43,7 @@ def klass
# have a "no such formula" message.
raise
rescue LoadError, NameError
raise if ARGV.debug? # let's see the REAL error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a separate pull request (because it can be pulled while the patches DSL is still under review.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamv
Copy link
Contributor

adamv commented Aug 4, 2013

Does this support sha1 patches or just sha256 patches?

@adamv
Copy link
Contributor

adamv commented Aug 4, 2013

NOTE: I'm going to edit out the large animated gif above

@camillol
Copy link
Contributor Author

camillol commented Aug 4, 2013

@jacknagel test suit updated.
@adamv only sha256.

@camillol
Copy link
Contributor Author

camillol commented Aug 4, 2013

For now, we don't need to use anything but sha256, so a raw string is enough.
Alternatively, we could pass in a checksum object, returned by a suitable function. For example, it might be nice to have patch :p1, url, sha256(...), but only if we can have checksum sha256(...) in the main formula DSL, which we can't because we're already committed to sha256 being a class method.
In any case, if we ever need other hashes in the future, we can add support for them either by passing them as checksum objects, or as strings of different length (assuming they won't be the same length as 256), or as strings with a prefix ('sha999:...').
The third option is to have a separate argument specifying the hash type, e.g. patch :p1, url, :sha256, '...', but that's ugly and unnecessary.

@MikeMcQuaid
Copy link
Member

@camillol I mean some way of (even if an option or ARGV.homebrew_developer?) of downloading a patch and emitting the checksum to the console if it's missing so it becomes easier to populate them without having to curl it manually. It would be good if checksums could be SHA-1 and SHA-256 and we default to the latter for consistency elsewhere.

I still would rather we split this into a block rather than adding another argument onto a method invocation.

@adamv
Copy link
Contributor

adamv commented Aug 5, 2013

Check the checksum length to see if it should be treated as sha1 or sha256.

@camillol
Copy link
Contributor Author

camillol commented Aug 5, 2013

@MikeMcQuaid now you can give an empty string for the patch checksum (patch :p1, url, ""), and homebrew will print a warning showing the patch's checksum. It will also warn about checksumless patches in the old patches method (but not for DATA, of course).

@adamv I don't see the need to support sha1.

@MikeMcQuaid
Copy link
Member

@camillol That sounds good. Probably want to make that only print for developers so we don't spam too hard existing formulae that haven't been updated. Might want to make it an audit rule (@jacknagel)? I dunno.

I do, however, think it's really important we both have SHA-1 support and default to that rather than SHA-256. Unless I'm overruled by a few other maintainers I kinda insist on it.

@camillol
Copy link
Contributor Author

camillol commented Aug 5, 2013

Why is SHA-1 support important?

@MikeMcQuaid
Copy link
Member

Because we use it most widely for archive checksums and I think SHA-256 is overkill at this point (as I explained in the other PR).

@camillol
Copy link
Contributor Author

camillol commented Aug 5, 2013

Ok, but what's the problem? Are you concerned that it might be too secure? Is there a performance issue?

@camillol
Copy link
Contributor Author

camillol commented Aug 5, 2013

Removed the formulary change, btw.

@MikeMcQuaid
Copy link
Member

@camillol Why not use SHA-512 or SHA-3? If we want to use SHA-256 as default everywhere in Homebrew that's a different discussion. As SHA-1 is the default for formulae tarballs it should be the default for patches too.

@LinusU
Copy link
Contributor

LinusU commented Oct 24, 2013

Just a suggestion, as I'm considering taking a stab at this and also include cache support for patches.

patch do
  url 'https://trac.macports.org/export/90442/trunk/dports/sysutils/socat/files/patch-xioexit.c.diff'
  sha256 '4a72f278d960310144556f7e1c2645f492b289bdc28de9f786a1ecd6dcdf21b7'
end

patch do
  data DATA
  sha1 '40840f60975de4010e490a8c0f97c3082d32e60c'
end

Maybe even allow this, thoughts?

patch do
  applyUnless OS.Linux?
  url 'https://trac.macports.org/export/90442/trunk/dports/sysutils/socat/files/patch-xioexit.c.diff'
  sha256 '4a72f278d960310144556f7e1c2645f492b289bdc28de9f786a1ecd6dcdf21b7'
end
patch do
  applyIf MacOS.version > 14
  url 'https://trac.macports.org/export/90442/trunk/dports/sysutils/socat/files/patch-xioexit.c.diff'
  sha256 '4a72f278d960310144556f7e1c2645f492b289bdc28de9f786a1ecd6dcdf21b7'
end

@jacknagel
Copy link
Contributor

@LinusU I have a complete implementation, it's not quite merge ready though: #22775

@jacknagel
Copy link
Contributor

Closing since we're going a different direction here.

@jacknagel jacknagel closed this Oct 24, 2013
@LinusU
Copy link
Contributor

LinusU commented Oct 24, 2013

@jacknagel Cool!

@Homebrew Homebrew locked and limited conversation to collaborators Feb 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants