Possibility to apply a patch to a target directory with Drush make? Is there any way to declare target directory for a patch in a Drush make file?

I need to apply a patch to a subfolder of a module. The reason is that CiviCRM's project is composed from multiple repositories (the patch is from the civicrm-drupal repository, which corresponds to civicrm/drupal in the packaged module).

There was a proposal along these lines in #745224, but ultimately only support for -p0 and -p1-type patches was committed.

(I'm now using a work-around by declaring a library in that location and applying a patch to it, but a cleaner way would be nice).
After clarifying that the goal of the original question was to be able to use patches generated by pull requests on GitHub directly, I'm suggesting an alternative answer.  My original answer is correct if the goal is to package this on Drupal.org.  Because a drupal-org.make requires patches to be found on Drupal.org, the path can be updated in the patch to to target directories within the CiviCRM project.  drupal-org.make also requires all external projects to be whitelisted.  Only the sk (starterkit) build of CiviCRM is whitelisted (https://www.drupal.org/node/1588192) because of the size and licensing limits.  

When using drush make locally, you can use both patches and code from any source. 


  IIRC it was a bit more complicated than just combining the repos?


It really isn't more complicated than just combining the repos.  There is some additional logic in https://github.com/civicrm/civicrm-core/blob/master/tools/scripts/releaser/releaser and https://github.com/civicrm/civicrm-core/blob/master/distmaker/distmaker.sh, but you can really focus on what happens in...

https://github.com/civicrm/civicrm-core/blob/master/distmaker/dists/drupal_php5.sh

dm_install_core "$SRC" "$TRG" 
dm_install_packages "$SRC/packages" "$TRG/packages" 
dm_install_drupal "$SRC/drupal" "$TRG/drupal"


That combines https://github.com/civicrm/civicrm-core with https://github.com/civicrm/civicrm-drupal and https://github.com/civicrm/civicrm-packages.

Other than the versioning, that's really all that happens when a new release of CiviCRM is packaged.  There isn't any code for a D7 release that doesn't come from those 3 repos.  By adding each of these projects directly, the relative path of the code will match what the patch expects allowing the patch to be applied in the .make.  

So to get something like https://github.com/civicrm/civicrm-drupal/pull/144.patch to work before it is merged into a release, your .make would look something like...

libraries[civicrm][download][type] = get
libraries[civicrm][download][url] = "https://github.com/civicrm/civicrm-core/archive/4.4.10.zip"
libraries[civicrm][destination] = "modules/"
libraries[civicrm][directory_name] = civicrm 

libraries[civicrm-drupal][download][type] = get
libraries[civicrm-drupal][download][url] = "https://github.com/civicrm/civicrm-drupal/archive/7.x-4.5.4.zip"
libraries[civicrm-drupal][destination] = "modules/civicrm/"
libraries[civicrm-drupal][directory_name] = drupal
libraries[civicrm-drupal][patch][144] = https://github.com/civicrm/civicrm-drupal/pull/144.patch

libraries[civicrm-drupal][download][type] = get
libraries[civicrm-drupal][download][url] = "https://github.com/civicrm/civicrm-packages/archive/4.5.3.zip"
libraries[civicrm-drupal][destination] = "modules/civicrm/"
libraries[civicrm-drupal][directory_name] = packages