Skip to content

Commit

Permalink
Use @@HOMEBREW_PREFIX@@ for replacements in external patches
Browse files Browse the repository at this point in the history
  • Loading branch information
pkryger committed Oct 23, 2024
1 parent 13a26d5 commit ff03947
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def apply
patch_file = patch_dir/patch_file
Utils.safe_popen_write("patch", "-g", "0", "-f", "-#{strip}") do |p|
File.foreach(patch_file) do |line|
data = line.gsub("HOMEBREW_PREFIX", HOMEBREW_PREFIX)
data = line.gsub("@@HOMEBREW_PREFIX@@", HOMEBREW_PREFIX)
p.write(data)
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/patching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stabl
formula.patch
s = File.read("libexec/NOOP")
expect(s).not_to include("NOOP"), "libexec/NOOP was not patched as expected"
expect(s).not_to include("HOMEBREW_PREFIX"), "libexec/NOOP was not patched as expected"
expect(s).not_to include("@@HOMEBREW_PREFIX@@"), "libexec/NOOP was not patched as expected"
expect(s).to include(HOMEBREW_PREFIX.to_s), "libexec/NOOP was not patched as expected"
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/support/fixtures/patches/noop-d.diff
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ index bfdda4c..e08d8f4 100755
#!/bin/bash
-echo NOOP
\ No newline at end of file
+echo HOMEBREW_PREFIX
+echo @@HOMEBREW_PREFIX@@
\ No newline at end of file
2 changes: 1 addition & 1 deletion Library/Homebrew/test/support/lib/startup/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
TESTBALL_PATCHES_SHA256 = "799c2d551ac5c3a5759bea7796631a7906a6a24435b52261a317133a0bfb34d9"
PATCH_A_SHA256 = "83404f4936d3257e65f176c4ffb5a5b8d6edd644a21c8d8dcc73e22a6d28fcfa"
PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b90"
PATCH_D_SHA256 = "29946529088576919b0a56146c346e63692832ab3568cc34fed647c3e4dc2072"
PATCH_D_SHA256 = "07c72c4463339e6e2ce235f3b26e316d4940017bf4b5236e27e757a44d67636c"

TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
4 changes: 3 additions & 1 deletion docs/Formula-Cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ Patches can also be embedded by passing a string. This makes it possible to prov
patch :p0, "..."
```

In patches, the string "HOMEBREW\_PREFIX" is replaced with the value of the constant `HOMEBREW_PREFIX` before the patch is applied.
In embedded patches, the string "HOMEBREW\_PREFIX" is replaced with the value of the constant `HOMEBREW_PREFIX` before the patch is applied.

In external patches, the string "@@HOMEBREW\_PREFIX@@" is replaced with the value of the constant `HOMEBREW_PREFIX` before the patch is applied.

### Creating the diff

Expand Down

0 comments on commit ff03947

Please sign in to comment.