Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

kit-ty-kate
Copy link
Member

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

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.

Copy link
Collaborator

@rjbou rjbou left a comment

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.

src/core/opamSystem.ml Outdated Show resolved Hide resolved
@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
src/core/opamSystem.ml Outdated Show resolved Hide resolved
@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
Copy link
Member

hannesm commented Apr 3, 2024

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 on lines +1652 to +1661
| DragonFly
| FreeBSD
| NetBSD
| OpenBSD -> ("gpatch", ["patch"])
| Cygwin
| Darwin
| Linux
| Unix
| Win32
| Other _ -> ("patch", ["gpatch"])
Copy link
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
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
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
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...

src/core/opamSystem.mli Outdated Show resolved Hide resolved
master_changes.md Show resolved Hide resolved
src/core/opamSystem.ml Show resolved Hide resolved
Copy link
Collaborator

@rjbou rjbou left a comment

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 :)

src/client/opamInitDefaults.ml Outdated Show resolved Hide resolved
@rjbou
Copy link
Collaborator

rjbou commented Apr 4, 2024

related to #3639

@kit-ty-kate kit-ty-kate merged commit f013288 into ocaml:master Apr 5, 2024
29 checks passed
Opam 2.2.0 automation moved this from For beta2 to Done Apr 5, 2024
@kit-ty-kate kit-ty-kate deleted the gpatch-detect branch April 5, 2024 10:04
@kit-ty-kate kit-ty-kate mentioned this pull request May 7, 2024
4 tasks
@rjbou rjbou modified the milestones: 2.2.0~beta2, 2.1.6 May 7, 2024
@rjbou rjbou added this to PR in Progress in Opam 2.1.x via automation May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Opam 2.1.x
  
PR in Progress
Opam 2.2.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants