Patching with Drush Make
Patching software is a common practice in open source software that enables developers to fix bugs and implement features within their projects, independent of the upstream software’s development cycle. The offset of this approach is that it can become cumbersome to maintain and re-apply patches as the upstream software continues to fix bugs, implement features and fix security vulnerabilities. With Drupal, patches can be better managed with an automated tool called Drush Make. This tool allows you to define a list of patched upstream (contrib) software and can aid the automated upgrade of this software to help save time and reduce the risk of software regressions.
Installing Drush Make
Drush Make, is one of many tools that comes with Drush 5.x and later. Drush is a command line tool for developers to administer Drupal. To install Drush, please visit https://github.com/drush-ops/drush and follow the instructions on installing Drush. For Windows machines, there is also a windows installer available: http://drush.ws/drush_windows_installer
Creating a patch file for Drush Make
Once Drush is installed, you’ll need to create a drush make file that lists all the patched Drupal projects in use. Below is an example file that lists Drupal core and the Drupal Views module as tracked patched files.
; Specify the version of Drupal being used.
core = 7.x
; Specify the api version of Drush Make.
api = 2
; Drupal core patches can be add like contrib patches:
projects[drupal][patch] = ../patches/drupal-actions-985814-11-D7.patch
; This line implicitly adds the Rules module as a patched project
; and points to a patched file.
projects[rules][patch] = '../patches/rules-2145837-use-update-path-1.patch'
; Alternately you can reference the online source and also comment on where
; this patch came from:
; ; Save roles name than roles id in rules config for better feature integration
; ; See https://drupal.org/comment/8540753#comment-8540753
; projects[rules][patch] = https://drupal.org/files/issues/rules-update-path-1.patch
; Projects can also have multiple patches applied
projects[workflow][patch] = ../patches/workflow-dup-history-log-385038-17.patch
projects[workflow][patch] = ../patches/workflow-features-roles-name-2149477-2.patch
Applying updates with Drush Make
Once you have a Make file in place that manages all of your projects with patches, you can easily run Drush make on the command line to attempt to upgrade all the projects and reapply the patches.
$ drush make patches.make
Make new site in the current directory? (y/n): y
drupal-7.26 downloaded. [ok]
drupal patched with drupal-actions-985814-11-D7.patch. [ok]
Generated PATCHES.txt file for drupal [ok]
>> Project workflow contains 12 modules: workflow_views, workflow_vbo, workflow_search_api, workflow_rules, workflow_revert, workflownode, workflowfield, workflow_cleanup, workflow_admin_ui, workflow_actions, workflow_access, workflow.
>> workflow-7.x-2.2 downloaded. [ok]
>> Unable to patch workflow with workflow-duplicated-history-log-385038-17.patch. [error]
>> Project rules contains 4 modules: rules_scheduler, rules_i18n, rules_admin, rules.
>> rules-7.x-2.6 downloaded. [ok]
>> rules patched with rules-2145837-use-update-path-1.patch. [ok]
>> Generated PATCHES.txt file for rules [ok]
>> Unable to patch workflow with workflow-transition-features-2044199-1.patch. [error]
In the output sample above, drush make was able to download and apply patches to Drupal core and the Rules module. However, the Workflow module failed to apply its updates. This means that the patches no longer apply to the latest version of Workflow. This will be because either the patch has been committed to later versions of the module or another patch to the module now conflicts with your patch. Unfortunately, this means human intervention will be required to review the patch to determine if the patch is still needed and if so, re-roll the patch. Updating specific projects with Drush Make In the example highlighted above, Drush Make updated all projects specified in the patches.make file. However, in many cases, you may only want to apply updates to specific modules which Drush Make will also allow you to do; shown in the example below:
$ drush make --no-core --projects=rules patches.make The command above prevents Drush Make from downloading Drupal core (--no-core) and specifies to only download the Rules module (--projects=rules). This is particularly useful when you wish to only upgrade those modules with security vulnerabilities. Note: The projects passed in using the --projects option must also be specified in the Make file.
Drush Make is a packaging tool for Drupal that can be used as a patching tool. For more information on Drush Make please see: http://drush.ws/docs/make.txt https://github.com/drush-ops/drush/blob/master/examples/example.make