function make_generate_from_makefile

8.0.x generate.contents.make.inc make_generate_from_makefile($file, $makefile)
7.x generate.contents.make.inc make_generate_from_makefile($file, $makefile)
master generate.contents.make.inc make_generate_from_makefile($file, $makefile)

Write a makefile based on data parsed from a previous makefile.

Parameters

$file: The path to the file to write our generated makefile to, or TRUE to print to the terminal.

$makefile: A makefile on which to base our generated one.

2 calls to make_generate_from_makefile()
drush_make in commands/make/make.drush.inc
Drush callback; make based on the makefile.
drush_make_update in commands/make/update.make.inc
Command callback for make-update.

File

commands/make/generate.contents.make.inc, line 85
Functions for the generate makefile command.

Code

function make_generate_from_makefile($file, $makefile) {
  $info = make_parse_info_file($makefile);
  $projects = drush_get_option('DRUSH_MAKE_PROJECTS', FALSE);
  if ($projects === FALSE) {
    $projects = make_prepare_projects(FALSE, $info);
    if (isset($projects['contrib'])) {
      $projects = array_merge($projects['core'], $projects['contrib']);
    }
  }

  $defaults = $info['defaults'];
  $core = current($projects);
  $core = $core['core'];
  foreach ($projects as $name => $project) {
    // If a specific revision was requested, do not set the version.
    if (!isset($project['revision'])) {
      $projects[$name]['version'] = $project['download']['full_version'];
      if ($project['type'] != 'core' && strpos($projects[$name]['version'], $project['core']) === 0) {
        $projects[$name]['version'] = substr($projects[$name]['version'], strlen($project['core'] . '-'));
      }
    }
    else {
      unset($projects[$name]['version']);
    }
    $projects[$name]['_type'] = $project['type'];

    // Don't clutter the makefile with defaults
    if (is_array($defaults)) {
      foreach ($defaults as $type => $defs) {
        if ($type == 'projects') {
          foreach ($defs as $key => $value) {
            if (isset($project[$key]) && $project[$key] == $value) {
              unset($projects[$name][$key]);
            }
          }
        }
      }
    }
    if ($project['name'] == $name) {
      unset($projects[$name]['name']);
    }
    if ($project['type'] == 'module' && !isset($info[$name]['type'])) {
      unset($projects[$name]['type']); // Module is the default
    }
    if (!(isset($project['download']['type'])) || ($project['download']['type'] == 'pm')) {
      unset($projects[$name]['download']); // PM is the default
    }
    $ignore = array(
      'build_path',
      'contrib_destination',
      'core',
      'location',
      'make_directory',
      'l10n_url',
      'download_type',
    );
    foreach ($ignore as $key) {
      unset($projects[$name][$key]);
    }
    // Remove empty entries (e.g. 'directory_name')
    $projects[$name] = _make_generate_array_filter($projects[$name]);
  }

  $libraries = drush_get_option('DRUSH_MAKE_LIBRARIES', FALSE);
  if ($libraries === FALSE) {
    $libraries = $info['libraries'];
  }
  if (is_array($libraries)) {
    foreach ($libraries as $name => $library) {
      $libraries[$name]['type'] = 'library';
      $libraries[$name]['_type'] = 'librarie';
    }
  }

  $contents = _drush_make_generate_makefile_contents($projects, $libraries, $core, $defaults);

  // Write or print our makefile.
  $file = $file !== TRUE ? $file : NULL;
  make_generate_print($contents, $file);
}