diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-07-28 19:06:16 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-07-28 19:06:16 +0000 |
commit | 12d6d6662eb6300e9ea00fc39440f209b99d86d4 (patch) | |
tree | 9398119b45febdc33a1578f9f5712be328cff939 /includes | |
parent | 3625dddf1174adce9dd988c7139e2a58b9245f52 (diff) | |
download | brdo-12d6d6662eb6300e9ea00fc39440f209b99d86d4.tar.gz brdo-12d6d6662eb6300e9ea00fc39440f209b99d86d4.tar.bz2 |
- Patch #211747 by chx, alex_b, dww: allow specifying version information as part of module dependencies.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/graph.inc | 6 | ||||
-rw-r--r-- | includes/module.inc | 51 |
2 files changed, 49 insertions, 8 deletions
diff --git a/includes/graph.inc b/includes/graph.inc index e9fffc587..aaaa19abb 100644 --- a/includes/graph.inc +++ b/includes/graph.inc @@ -14,7 +14,7 @@ * A three dimensional associated array, with the first keys being the names * of the vertices, these can be strings or numbers. The second key is * 'edges' and the third one are again vertices, each such key representing - * an edge. Values of array elements do not matter. + * an edge. Values of array elements are copied over. * * Example: * @code @@ -108,7 +108,7 @@ function _drupal_depth_first_search(&$graph, &$state, $start, &$component = NULL if (isset($graph[$start]['edges'])) { foreach ($graph[$start]['edges'] as $end => $v) { // Mark that $start can reach $end. - $graph[$start]['paths'][$end] = TRUE; + $graph[$start]['paths'][$end] = $v; if (isset($graph[$end]['component']) && $component != $graph[$end]['component']) { // This vertex already has a component, use that from now on and @@ -136,7 +136,7 @@ function _drupal_depth_first_search(&$graph, &$state, $start, &$component = NULL // paths. foreach ($graph[$start]['paths'] as $end => $v) { if (isset($graph[$end])) { - $graph[$end]['reverse_paths'][$start] = TRUE; + $graph[$end]['reverse_paths'][$start] = $v; } } diff --git a/includes/module.inc b/includes/module.inc index 4d25994f7..8fd4273ef 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -95,11 +95,52 @@ function module_list($refresh = FALSE, $sort = FALSE, $fixed_list = NULL) { function _module_build_dependencies($files) { require_once DRUPAL_ROOT . '/includes/graph.inc'; $roots = $files; + // We use named subpatterns and support every op that version_compare + // supports. Also, op is optional and defaults to equals. + $p_op = '(?P<operation>!=|==|=|<|<=|>|>=|<>)?'; + // Core version is always optional: 7.x-2.x and 2.x is treated the same. + $p_core = '(?:' . preg_quote(DRUPAL_CORE_COMPATIBILITY) . '-)?'; + $p_major = '(?P<major>\d+)'; + // By setting the minor version to x, branches can be matched. + $p_minor = '(?P<minor>\d+|x)'; foreach ($files as $filename => $file) { $graph[$file->name]['edges'] = array(); if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) { foreach ($file->info['dependencies'] as $dependency_name) { - $graph[$file->name]['edges'][$dependency_name] = 1; + $value = array(); + $parts = explode('(', $dependency_name, 2); + $dependency_name = trim($parts[0]); + if (isset($parts[1])) { + $value['original_version'] = ' (' . $parts[1]; + foreach (explode(',', $parts[1]) as $version) { + if (preg_match("/^\s*$p_op\s*$p_core$p_major\.$p_minor/", $version, $matches)) { + $op = !empty($matches['operation']) ? $matches['operation'] : '='; + if ($matches['minor'] == 'x') { + // If a module is newer than 2.x then it's at least 3.0. + $matches['minor'] = 0; + if ($op == '>') { + $matches['major']++; + $op = '>='; + } + // If a module is older or equivalent than 2.x then it is older + // than 3.0. + if ($op == '<=') { + $matches['major']++; + $op = '<'; + } + // Equivalence is checked by preg. + if ($op == '=' || $op == '==') { + $value['versions'][] = array('preg' => '/^' . $matches['major'] . '\./'); + $op = ''; + } + } + if ($op) { + $value['versions'][] = array('op' => $op, 'version' => $matches['major'] . '.' . $matches['minor']); + } + } + } + } + $graph[$file->name]['edges'][$dependency_name] = $value; unset($roots[$dependency_name]); } } @@ -138,13 +179,13 @@ function module_load_install($module) { /** * Load a module include file. - * + * * Examples: * @code * // Load node.admin.inc from the node module. * module_load_include('inc', 'node', 'node.admin'); * // Load content_types.inc from the node module. - * module_load_include('inc', 'node', 'content_types'); + * module_load_include('inc', 'node', 'content_types'); * @endcode * * Do not use this function to load an install file. Use module_load_install() @@ -155,7 +196,7 @@ function module_load_install($module) { * @param $module * The module to which the include file belongs. * @param $name - * Optionally, specify the base file name (without the $type extension). + * Optionally, specify the base file name (without the $type extension). * If not set, $module is used. */ function module_load_include($type, $module, $name = NULL) { @@ -194,7 +235,7 @@ function module_load_all_includes($type, $name = NULL) { */ function module_enable($module_list, $disable_modules_installed_hook = FALSE) { $invoke_modules = array(); - + // Try to install the enabled modules and collect which were installed. // $module_list is not changed and already installed modules are ignored. $modules_installed = array_filter($module_list, '_drupal_install_module'); |