Index: libraries.api.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.api.php,v
retrieving revision 1.5
diff -u -p -r1.5 libraries.api.php
--- libraries.api.php	3 Nov 2010 22:22:42 -0000	1.5
+++ libraries.api.php	4 Nov 2010 14:18:25 -0000
@@ -102,6 +102,10 @@
  *     names and whose values are sets of files to load for the module, using
  *     the same notion as the top-level 'files' property. Each specified file
  *     should contain the full path to the file.
+ *   - dependencies: (optional) An array of library dependencies. This can
+ *     either be a non associative array of library names or an associative
+ *     array where the keys are the library names and the values the variants of
+ *     the libraries that are to be loaded.
  *   Additional top-level properties can be registered as needed.
  *
  * @see hook_library()
@@ -221,6 +225,11 @@ function hook_libraries_info() {
         'js' => 'ex_lib.inc',
       ),
     ),
+    // Optional: Register dependency information. The libraries listed here will
+    // be loaded automatically along with this one. As seen below, it is
+    // possible to specify the variant of the dependent library.
+    'dependencies' => array(
+      'jquery' => 'minified',
   );
 
   // A very simple library. No changing APIs (hence, no versions), no variants.
@@ -301,6 +310,9 @@ function hook_libraries_info() {
                 'tiny_mce_jquery.js' => array('preprocess' => FALSE),
               ),
             ),
+            // This variant depends on jQuery. It is not important which variant
+            // of jQuery is loaded, though.
+            'dependencies' => array('jquery'),
           ),
           'source' => array(
             'files' => array(
Index: libraries.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.drush.inc,v
retrieving revision 1.2
diff -u -p -r1.2 libraries.drush.inc
--- libraries.drush.inc	10 Oct 2010 03:55:16 -0000	1.2
+++ libraries.drush.inc	4 Nov 2010 14:18:25 -0000
@@ -52,7 +52,7 @@ function libraries_drush_list() {
   }
 
   else {
-    $header = array('Name', 'Status', 'Version', 'Variants');
+    $header = array('Name', 'Status', 'Version', 'Variants', 'Dependencies');
     $rows = array();
     foreach ($libraries as $library_name => $library) {
       $version = $library['version'];
@@ -63,6 +63,7 @@ function libraries_drush_list() {
         $status = drupal_ucfirst($library['error']);
         $version = (empty($library['version']) ? '-' : $library['version']);
       }
+
       if (empty($library['variants'])) {
         $variants = '-';
       }
@@ -81,7 +82,23 @@ function libraries_drush_list() {
         }
       }
 
-      $rows[] = array($library_name, $status, $version, $variants);
+      if (empty($library['dependencies'])) {
+        $dependencies = '-';
+      }
+      else {
+        $dependencies = array();
+        foreach ($library['dependencies'] as $dep_name => $dep_variant) {
+          if (!empty($dep_variant)) {
+            $dependencies[] = "$dep_name ($dep_variant)";
+          }
+          else {
+            $dependencies[] = $dep_name;
+          }
+        }
+        $dependencies = implode(', ', $dependencies);
+      }
+
+      $rows[] = array($library_name, $status, $version, $variants, $dependencies);
     }
     $table = new Console_Table();
     drush_print($table->fromArray($header, $rows));
Index: libraries.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.module,v
retrieving revision 1.12
diff -u -p -r1.12 libraries.module
--- libraries.module	4 Nov 2010 13:08:00 -0000	1.12
+++ libraries.module	4 Nov 2010 14:18:25 -0000
@@ -211,6 +211,7 @@ function libraries_info($library = NULL)
         'variants' => array(),
         'versions' => array(),
         'integration files' => array(),
+        'dependencies' => array(),
       );
     }
 
@@ -341,6 +342,38 @@ function libraries_detect_library(&$libr
     }
   }
 
+  // Check dependencies.
+  if (!empty($library['dependencies'])) {
+    // We support both associative and indexed arrays as dependency information.
+    if (isset($library['dependencies'][0])) {
+      foreach ($library['dependencies'] as $i => $dependency) {
+        $library['dependencies'][$dependency] = NULL;
+        unset($library['dependencies'][$i]);
+      }
+    }
+    foreach ($library['dependencies'] as $dep_name => $dep_variant) {
+      $dep_library = libraries_info($dep_name);
+      libraries_detect_library($dep_library);
+      if (!$dep_library['installed']) {
+        $library['error'] = 'unmet dependencies';
+        $library['error message'] = t('The %dep_library library, which the %library library depends on, is not installed.', array(
+          '%dep_library' => $dep_library['name'],
+          '%library' => $library['name'],
+        ));
+        return;
+      }
+      elseif (!empty($dep_variant) && (!isset($dep_library['variants'][$dep_variant]) || !$dep_library['variants'][$dep_variant]['installed'])) {
+        $library['error'] = 'unmet dependencies';
+        $library['error message'] = t('The %dep_variant variant of the %dep_library library, which the %library library depends on, is not installed.', array(
+          '%dep_variant' => $dep_variant,
+          '%dep_library' => $dep_library['name'],
+          '%library' => $library['name'],
+        ));
+        return;
+      }
+    }
+  }
+
   // If we end up here, the library should be usable.
   $library['installed'] = TRUE;
 }
@@ -372,6 +405,13 @@ function libraries_load($name, $variant 
     $library = array_merge($library, $library['variants'][$variant]);
   }
 
+  // Load library dependencies.
+  if (!empty($library['dependencies'])) {
+    foreach ($library['dependencies'] as $dep_name => $dep_variant) {
+      libraries_load($dep_name, $dep_variant);
+    }
+  }
+
   return libraries_load_files($library, $variant);
 }
 
Index: tests/libraries.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries.test,v
retrieving revision 1.9
diff -u -p -r1.9 libraries.test
--- tests/libraries.test	3 Nov 2010 22:22:42 -0000	1.9
+++ tests/libraries.test	4 Nov 2010 14:18:26 -0000
@@ -149,6 +149,35 @@ class LibrariesTestCase extends DrupalWe
     $this->verbose(var_export($library, TRUE));
     $this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
 
+    // Test missing library dependency.
+    $library = libraries_info('example_dependency_missing');
+    libraries_detect_library($library);
+    $this->verbose(var_export($library, TRUE));
+    $this->assertEqual($library['error'], 'unmet dependencies', 'Missing dependencies detected.');
+    $error_message = t('The %dep_library library, which the %library library depends on, is not installed.', array(
+      '%dep_library' => 'Example missing',
+      '%library' => $library['name'],
+    ));
+    $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing dependency.');
+
+    // Test missing variant in library dependency.
+    $library = libraries_info('example_dependency_variant_missing');
+    libraries_detect_library($library);
+    $this->verbose(var_export($library, TRUE));
+    $this->assertEqual($library['error'], 'unmet dependencies', 'Missing variant in a dependency detected.');
+    $error_message = t('The %dep_variant variant of the %dep_library library, which the %library library depends on, is not installed.', array(
+      '%dep_variant' => 'example_variant',
+      '%dep_library' => 'Example variant missing',
+      '%library' => $library['name'],
+    ));
+    $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing variant in a dependecy.');
+
+    // Test installed dependecy.
+    $library = libraries_info('example_dependency_installed');
+    libraries_detect_library($library);
+    $this->verbose(var_export($library, TRUE));
+    $this->assertEqual($library['installed'], TRUE, 'Library with an installed dependency detected correctly.');
+
     // Test loading of a simple library with a top-level files property.
     $this->drupalGet('libraries_test/simple');
     $this->assertLibraryFiles('example_1', 'Simple library loading');
@@ -170,6 +199,11 @@ class LibrariesTestCase extends DrupalWe
     // Test version overloading and variant loading.
     $this->drupalGet('libraries_test/versions_and_variants');
     $this->assertLibraryFiles('example_4', 'Concurrent version and variant overloading');
+
+    // Test loading of a library with a dependecy.
+    $this->drupalGet('libraries_test/dependency');
+    $this->assertLibraryFiles('example_1', 'Dependency loading');
+
   }
 
   /**
Index: tests/libraries_test.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries_test.module,v
retrieving revision 1.7
diff -u -p -r1.7 libraries_test.module
--- tests/libraries_test.module	3 Nov 2010 22:22:42 -0000	1.7
+++ tests/libraries_test.module	4 Nov 2010 14:18:26 -0000
@@ -215,6 +215,30 @@ function libraries_test_libraries_info()
     ),
   );
 
+  $libraries['example_dependency_installed'] = array(
+    'name' => 'Example dependency installed',
+    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'version callback' => '_libraries_test_return_version',
+    'version arguments' => array('2'),
+    'dependencies' => array('example_simple'),
+  );
+  $libraries['example_dependency_missing'] = array(
+    'name' => 'Example dependency missing',
+    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'version callback' => '_libraries_test_return_version',
+    'version arguments' => array('2'),
+    'dependencies' => array('example_missing'),
+  );
+  $libraries['example_dependency_variant_missing'] = array(
+    'name' => 'Example dependency variant missing',
+    'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
+    'version callback' => '_libraries_test_return_version',
+    'version arguments' => array('2'),
+    'dependencies' => array(
+      'example_variant_missing' => 'example_variant',
+    ),
+  );
+
   // This library is used together with libraries_info() to be populated with
   // the defaults.
   $libraries['example_empty'] = array();
@@ -334,6 +358,12 @@ function libraries_test_menu() {
     'page arguments' => array('example_versions_and_variants', 'example_variant_2'),
     'access callback' => TRUE,
   );
+  $items['libraries_test/dependency'] = array(
+    'title' => 'Test loading of dependencies',
+    'page callback' => '_libraries_test_load',
+    'page arguments' => array('example_dependency_installed'),
+    'access callback' => TRUE,
+  );
   return $items;
 }
 
