From 43d6caf0e3c093bf03d1ecf8516ee4201285a6e7 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sun, 8 Mar 2020 18:33:04 +0000 Subject: [PATCH] patch: add support for changing directory --- Library/Homebrew/patch.rb | 4 +++- Library/Homebrew/resource.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index de2783147c..bf11d5d019 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -135,7 +135,7 @@ class ExternalPatch end def apply - dir = Pathname.pwd + base_dir = Pathname.pwd resource.unpack do patch_dir = Pathname.pwd if patch_files.empty? @@ -149,6 +149,8 @@ class ExternalPatch patch_files << children.first.basename end + dir = base_dir + dir /= resource.directory if resource.directory.present? dir.cd do patch_files.each do |patch_file| ohai "Applying #{patch_file}" diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index ca43031ab5..920a787c3f 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -198,6 +198,7 @@ class Resource def initialize(&block) @patch_files = [] + @directory = nil super "patch", &block end @@ -206,6 +207,12 @@ class Resource @patch_files.concat(paths) @patch_files.uniq! end + + def directory(val = nil) + return @directory if val.nil? + + @directory = val + end end end