Skip to content

Warn if GNU patch is not detected when using patch - #5893

Merged
kit-ty-kate merged 3 commits into
ocaml:masterfrom
kit-ty-kate:gpatch-detect
Apr 5, 2024
Merged

Warn if GNU patch is not detected when using patch#5893
kit-ty-kate merged 3 commits into
ocaml:masterfrom
kit-ty-kate:gpatch-detect

Conversation

@kit-ty-kate

@kit-ty-kate kit-ty-kate commented Mar 21, 2024

Copy link
Copy Markdown
Member

Lightweight alternative to #5892
See #5400

In this PR, once per process if a patch is going to be applied (either a patch application in a package or a repository update) we first check which patch executable to use. If no GNU patch is detected we display a warning.

On some platforms the name of the patch command can change depending on the context (e.g. macOS where Homebrew provides patch but Macports provides gpatch), so to handle that we simply check both patch and gpatch and detect which one is GNU patch. On the platforms more likely to have patch as GNU patch we check patch first and default to it if none were found, and inversely on the platforms that are more likely to have gpatch as GNU patch.

@rjbou rjbou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On the idea and the code, lgtm!
Can you explain in the main comment why this is applied only on updating opam repositories ?
Also, a precision in the changes/PR/commits, it is not specific to opam update, but more generally opam repositories updating. These updates can be launched by opam update, opam switch, and opam init.

Comment thread src/core/opamSystem.ml Outdated
@kit-ty-kate
kit-ty-kate force-pushed the gpatch-detect branch 2 times, most recently from bc57e7b to 3fce7b6 Compare April 2, 2024 18:35
Comment thread src/core/opamSystem.ml Outdated
@kit-ty-kate kit-ty-kate changed the title Warn if GNU patch is not detected during opam update Warn if GNU patch is not detected during a repository update Apr 2, 2024
@kit-ty-kate
kit-ty-kate marked this pull request as draft April 2, 2024 19:46
@kit-ty-kate kit-ty-kate changed the title Warn if GNU patch is not detected during a repository update Warn if GNU patch is not detected when using patch Apr 3, 2024
@kit-ty-kate
kit-ty-kate marked this pull request as ready for review April 3, 2024 14:07
@hannesm

hannesm commented Apr 3, 2024

Copy link
Copy Markdown
Member

I do understand the logic to look for "gpatch" .. "patch" -- but I'd do it differently:

  • not look for gpatch on GNU/Linux (i.e. only look for it on BSD and macOS)
  • unify the whole lookup to uniformly look for gpatch first and if not found (or not GNU patch) go for patch

Of course your PR is fine, but I wonder in terms of lines of code and code understandability whether it is worth it (my experience is if you have the least platform-specific conditionals, the easiest it is to debug).

But these are only my 2 cents... thanks for your work on this.

Comment thread src/core/opamSystem.ml
Comment on lines +1652 to +1661
| DragonFly
| FreeBSD
| NetBSD
| OpenBSD -> ("gpatch", ["patch"])
| Cygwin
| Darwin
| Linux
| Unix
| Win32
| Other _ -> ("patch", ["gpatch"])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@hannesm like this?

Suggested change
| DragonFly
| FreeBSD
| NetBSD
| OpenBSD -> ("gpatch", ["patch"])
| Cygwin
| Darwin
| Linux
| Unix
| Win32
| Other _ -> ("patch", ["gpatch"])
| Darwin
| DragonFly
| FreeBSD
| NetBSD
| OpenBSD -> ("gpatch", ["patch"])
| Cygwin
| Linux
| Unix
| Win32
| Other _ -> ("patch", [])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the problem with that is that it changes the behaviour compared to 2.1.5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, well, or even:

let default_cmd, other_cmds = "gpatch", [ "patch" ]

avoiding the match on the os type at all. But I hear your "changes the behaviour". With that in mind, I like your PR very much.

The only suggestion left is:

  let default_cmd, other_cmds =
    match OpamStd.Sys.os () with
    | DragonFly
    | FreeBSD
    | NetBSD
    | OpenBSD
    | Darwin -> ("gpatch", ["patch"])
    | Cygwin
    | Linux
    | Unix
    | Win32
    | Other _ -> ("patch", [])

so, put Darwin into the pot where gpatch is tried first, and don't try gpatch on Linux & Windows.

But as said, maybe the current state is best for avoiding too much trouble / regressions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually considering the code and platforms, maybe

let default_cmd, other_cmds = "patch", [ "gpatch" ]

is suitable? This would on OpenBSD and FreeBSD call patch --version, and then go to using gpatch...

Comment thread src/core/opamSystem.mli Outdated
Comment thread master_changes.md
Comment thread src/core/opamSystem.ml

@rjbou rjbou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! tiny formatting remark that you can ignore :)

Comment thread src/client/opamInitDefaults.ml Outdated
@rjbou

rjbou commented Apr 4, 2024

Copy link
Copy Markdown
Collaborator

related to #3639

@kit-ty-kate
kit-ty-kate merged commit f013288 into ocaml:master Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants