diff --git a/includes/command.inc b/includes/command.inc index 51fbe38..5b391e5 100644 --- a/includes/command.inc +++ b/includes/command.inc @@ -1399,12 +1399,16 @@ function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) { $files = drush_scan_directory($path, "/\.drush($dmv|)\.inc$/", $nomask); foreach ($files as $filename => $info) { $module = basename($filename); - $module = str_replace(array('.drush.inc', ".drush$dmv.inc"), '', $module); + $drupal_version = 'all'; + if (preg_match('/\.d([0-9]+[+-]*)\.drush/', $module, $matches)) { + $drupal_version = $matches[1]; + } + $module = preg_replace('/(\.d[0-9]+[+-]*|)\.*drush[0-9]*\.inc/', '', $module); // Only try to bootstrap modules that we have never seen before, or that we // have tried to load but did not due to an unmet _drush_load() requirement. if (!array_key_exists($module, $evaluated) && file_exists($filename)) { $evaluated[$module] = TRUE; - $list[$module] = $filename; + $list[$module][$drupal_version] = $filename; } } } @@ -1417,41 +1421,47 @@ function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) { // Check each file in the consideration list; if there is // a modulename_drush_load() function in modulename.drush.load.inc, // then call it to determine if this file should be loaded. - foreach ($list as $module => $filename) { - $load_command = TRUE; - $load_test_inc = dirname($filename) . "/" . $module . ".drush.load.inc"; - if (file_exists($load_test_inc)) { - include_once($load_test_inc); - $load_test_func = $module . "_drush_load"; - if (function_exists($load_test_func)) { - $load_command = $load_test_func($phase); + $load = array(); + foreach ($list as $module => $variant) { + foreach ($variant as $drupal_version => $filename) { + $load_command = FALSE; + if (($drupal_version == 'all') || ($drupal_version == drush_get_context('DRUSH_DRUPAL_MAJOR_VERSION', ''))) { + $load_command = TRUE; + $load_test_inc = dirname($filename) . "/" . $module . ".drush.load.inc"; + if (file_exists($load_test_inc)) { + include_once($load_test_inc); + $load_test_func = $module . "_drush_load"; + if (function_exists($load_test_func)) { + $load_command = $load_test_func($phase); + } + } } - } - if ($load_command) { - // Only try to require if the file exists. If not, a file from the - // command file cache may not be available anymore, in which case - // we rebuild the cache for this phase. - if ($filepath = realpath($filename)) { - require_once $filepath; - unset($deferred[$module]); + if ($load_command) { + // Only try to require if the file exists. If not, a file from the + // command file cache may not be available anymore, in which case + // we rebuild the cache for this phase. + if ($filepath = realpath($filename)) { + require_once $filepath; + unset($deferred[$module]); + $load[$module] = $filename; + } + elseif (!$reset) { + _drush_add_commandfiles($searchpath, $phase, TRUE); + } } - elseif (!$reset) { - _drush_add_commandfiles($searchpath, $phase, TRUE); + else { + // Signal that we should try again on + // the next bootstrap phase. We set + // the flag to the filename of the first + // module we find so that only that one + // will be retried. + $deferred[$module][$drupal_version] = $filename; } } - else { - unset($list[$module]); - // Signal that we should try again on - // the next bootstrap phase. We set - // the flag to the filename of the first - // module we find so that only that one - // will be retried. - $deferred[$module] = $filename; - } } - if (sizeof($list)) { - $cache = array_merge($cache, $list); + if (sizeof($load)) { + $cache = array_merge($cache, $load); ksort($cache); } }