/
make.drush.inc
766 lines (706 loc) · 28.3 KB
/
make.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
<?php
/**
* @file
* Drush Make commands.
*/
use \Drush\UpdateService\ReleaseInfo;
/**
* Default localization server for downloading translations.
*/
define('MAKE_DEFAULT_L10N_SERVER', 'http://ftp.drupal.org/files/translations/l10n_server.xml');
/**
* Make refuses to build makefiles whose api version is mismatched
* with make command.
*/
define('MAKE_API', 2);
include_once 'make.utilities.inc';
include_once 'make.download.inc';
include_once 'make.project.inc';
include_once 'generate.contents.make.inc';
/**
* Implements hook_drush_command().
*/
function make_drush_command() {
$projects = array(
'description' => 'Restrict the make to this comma-separated list of projects. To specify all projects, pass *.',
'example-value' => 'views,ctools',
);
$libraries = array(
'description' => 'Restrict the make to this comma-separated list of libraries. To specify all libraries, pass *.',
'example-value' => 'tinymce',
);
$items['make'] = array(
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'description' => 'Turns a makefile into a working Drupal codebase.',
'arguments' => array(
'makefile' => 'Filename of the makefile to use for this build.',
'build path' => 'The path at which to build the makefile.',
),
'examples' => array(
'drush make example.make example' => 'Build the example.make makefile in the example directory.',
'drush make --no-core --contrib-destination=. installprofile.make' => 'Build an installation profile within an existing Drupal site',
'drush make http://example.com/example.make example' => 'Build the remote example.make makefile in the example directory.',
'drush make example.make --no-build --lock=example.lock' => 'Write a new makefile to example.lock. All project versions will be resolved.',
),
'options' => array(
'version' => 'Print the make API version and exit.',
'concurrency' => array(
'description' => 'Set the number of concurrent projects that will be processed at the same time. The default is 1.',
'example-value' => '1',
),
'contrib-destination' => 'Specify a path under which modules and themes should be placed. Defaults to sites/all for Drupal 6,7 and the corresponding directory in the Drupal root for Drupal 8 and above.',
'force-complete' => 'Force a complete build even if errors occur.',
'ignore-checksums' => 'Ignore md5 checksums for downloads.',
'md5' => array(
'description' => 'Output an md5 hash of the current build after completion. Use --md5=print to print to stdout.',
'example-value' => 'print',
'value' => 'optional',
),
'make-update-default-url' => 'The default location to load the XML update information from.',
'no-build' => 'Do not build a codebase. Makes the `build path` argument optional.',
'no-cache' => 'Do not use the pm-download caching (defaults to cache enabled).',
'no-clean' => 'Leave temporary build directories in place instead of cleaning up after completion.',
'no-core' => 'Do not require a Drupal core project to be specified.',
'no-recursion' => 'Do not recurse into the makefiles of any downloaded projects; you can also set [do_recursion] = 0 on a per-project basis in the makefile.',
'no-patch-txt' => 'Do not write a PATCHES.txt file in the directory of each patched project.',
'no-gitinfofile' => 'Do not modify .info files when cloning from Git.',
'force-gitinfofile' => 'Force a modification of .info files when cloning from Git even if repository isn\'t hosted on Drupal.org.',
'no-gitprojectinfo' => 'Do not inject project info into .info files when cloning from Git.',
'overwrite' => 'Overwrite existing directories. Default is to merge.',
'prepare-install' => 'Prepare the built site for installation. Generate a properly permissioned settings.php and files directory.',
'tar' => 'Generate a tar archive of the build. The output filename will be [build path].tar.gz.',
'test' => 'Run a temporary test build and clean up.',
'translations' => 'Retrieve translations for the specified comma-separated list of language(s) if available for all projects.',
'working-copy' => 'Preserves VCS directories, like .git, for projects downloaded using such methods.',
'download-mechanism' => 'How to download files. Should be autodetected, but this is an override if it doesn\'t work. Options are "curl" and "make" (a native download method).',
'projects' => $projects,
'libraries' => $libraries,
'allow-override' => array(
'description' => 'Restrict the make options to a comma-separated list. Defaults to unrestricted.',
),
'lock' => array(
'description' => 'Generate a makefile, based on the one passed in, with all versions *resolved*. Defaults to printing to the terminal, but an output file may be provided.',
'example-value' => 'example.make.lock',
),
'shallow-clone' => array(
'description' => 'For makefile entries which use git for downloading, this option will utilize shallow clones where possible (ie. by using the git-clone\'s depth=1 option). If the "working-copy" option is not desired, this option will significantly speed up makes which involve modules stored in very large git repos. In fact, if "working-copy" option is enabled, this option cannot be used.',
),
),
'engines' => array('release_info'),
'topics' => array('docs-make', 'docs-make-example'),
);
$items['make-generate'] = array(
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
'description' => 'Generate a makefile from the current Drupal site.',
'examples' => array(
'drush generate-makefile example.make' => 'Generate a makefile with ALL projects versioned (should a project have a known version number)',
'drush generate-makefile example.make --exclude-versions' => 'Generate a makefile with NO projects versioned',
'drush generate-makefile example.make --exclude-versions=drupal,views,cck' => 'Generate a makefile with ALL projects versioned EXCEPT core, Views and CCK',
'drush generate-makefile example.make --include-versions=admin_menu,og,ctools (--exclude-versions)' => 'Generate a makefile with NO projects versioned EXCEPT Admin Menu, OG and CTools.',
),
'options' => array(
'exclude-versions' => 'Exclude all version numbers (default is include all version numbers) or optionally specify a list of projects to exclude from versioning',
'include-versions' => 'Include a specific list of projects, while all other projects remain unversioned in the makefile (so implies --exclude-versions)',
),
'engines' => array('release_info'),
'aliases' => array('generate-makefile'),
);
$items['make-convert'] = array(
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'description' => 'Convert a legacy makefile into YAML format.',
'arguments' => array(
'makefile' => 'Filename of the makefile to convert.',
),
'options' => array(
'projects' => $projects,
'libraries' => $libraries,
),
'required-arguments' => TRUE,
'examples' => array(
'drush make-convert example.make' => 'Convert example.make to example.make.yml',
),
);
// Hidden command to build a group of projects.
$items['make-process'] = array(
'hidden' => TRUE,
'arguments' => array(
'directory' => 'The temporary working directory to use',
),
'options' => array(
'projects-location' => 'Name of a temporary file containing json-encoded output of make_projects().',
'manifest' => 'An array of projects already being processed.',
),
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'engines' => array('release_info'),
);
$items['make-update'] = array(
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'description' => 'Process a makefile and outputs an equivalent makefile with projects version resolved to latest available.',
'arguments' => array(
'makefile' => 'Filename of the makefile to use for this build.',
),
'options' => array(
'result-file' => array(
'description' => 'Save to a file. If not provided, the updated makefile will be dump to stdout.',
'example-value' => 'updated.make',
),
),
'engines' => array('release_info', 'update_status'),
);
// Add docs topic.
$docs_dir = drush_get_context('DOC_PREFIX', DRUSH_BASE_PATH);
$items['docs-make'] = array(
'description' => 'Drush Make overview with examples',
'hidden' => TRUE,
'topic' => TRUE,
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'callback' => 'drush_print_file',
'callback arguments' => array($docs_dir . '/docs/make.md'),
);
$items['docs-make-example'] = array(
'description' => 'Drush Make example makefile',
'hidden' => TRUE,
'topic' => TRUE,
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'callback' => 'drush_print_file',
'callback arguments' => array($docs_dir . '/examples/example.make.yml'),
);
return $items;
}
/**
* Implements hook_drush_help().
*/
function make_drush_help($section) {
switch ($section) {
case 'drush:make':
return 'Turns a makefile into a Drupal codebase. For a full description of options and makefile syntax, see docs/make.txt and examples/example.make.';
case 'drush:make-generate':
return 'Generate a makefile from the current Drupal site, specifying project version numbers unless not known or otherwise specified. Unversioned projects will be interpreted later by drush make as "most recent stable release"';
}
}
/**
* Command argument complete callback.
*
* @return array
* Strong glob of files to complete on.
*/
function make_make_complete() {
return array(
'files' => array(
'directories' => array(
'pattern' => '*',
'flags' => GLOB_ONLYDIR,
),
'make' => array(
'pattern' => '*.make',
),
),
);
}
/**
* Validation callback for make command.
*/
function drush_make_validate($makefile = NULL, $build_path = NULL) {
// Don't validate if --version option is supplied.
if (drush_get_option('version', FALSE)) {
return;
}
if (drush_get_option('shallow-clone', FALSE) && drush_get_option('working-copy', FALSE)) {
return drush_set_error('MAKE_SHALLOW_CLONE_WORKING_COPY_CONFLICT', dt('You cannot use "--shallow-clone" and "--working-copy" options together.'));
}
// Error out if the build path is not valid and --no-build was not supplied.
if (!drush_get_option('no-build', FALSE) && !make_build_path($build_path)) {
return FALSE;
}
}
/**
* Implements drush_hook_pre_COMMAND().
*
* If --version option is supplied, print it and prevent execution of the command.
*/
function drush_make_pre_make($makefile = NULL, $build_path = NULL) {
if (drush_get_option('version', FALSE)) {
drush_print(dt('Drush make API version !version', array('!version' => MAKE_API)));
drush_print_pipe(MAKE_API);
// Prevent command execution.
return FALSE;
}
}
/**
* Drush callback; make based on the makefile.
*/
function drush_make($makefile = NULL, $build_path = NULL) {
// Set the cache option based on our '--no-cache' option.
_make_enable_cache();
// Build.
if (!drush_get_option('no-build', FALSE)) {
$info = make_parse_info_file($makefile);
drush_log(dt('Beginning to build !makefile.', array('!makefile' => $makefile)), 'ok');
// Default contrib destination depends on Drupal core version.
$core_version = str_replace('.x', '', $info['core'][0]);
$sitewide = drush_drupal_sitewide_directory($core_version);
$contrib_destination = drush_get_option('contrib-destination', $sitewide);
$build_path = make_build_path($build_path);
$make_dir = realpath(dirname($makefile));
$success = make_projects(FALSE, $contrib_destination, $info, $build_path, $make_dir);
if ($success) {
make_libraries(FALSE, $contrib_destination, $info, $build_path, $make_dir);
if (drush_get_option('prepare-install')) {
make_prepare_install($build_path);
}
if ($option = drush_get_option('md5')) {
$md5 = make_md5();
if ($option === 'print') {
drush_print($md5);
}
else {
drush_log(dt('Build hash: %md5', array('%md5' => $md5)), 'ok');
}
}
// Only take final build steps if not in testing mode.
if (!drush_get_option('test')) {
if (drush_get_option('tar')) {
make_tar($build_path);
}
else {
make_move_build($build_path);
}
}
make_clean_tmp();
}
}
// Process --lock.
if (drush_get_option('lock', FALSE)) {
return make_generate_from_makefile(drush_get_option('lock'), $makefile);
}
// Used by core-quick-drupal command.
// @see drush_core_quick_drupal().
return $info;
}
/**
* Command callback; convert ini makefile to YAML.
*/
function drush_make_convert($makefile) {
drush_log(dt('Beginning to convert !makefile.', array('!makefile' => $makefile)), 'ok');
$file = $makefile . '.yml';
$info = make_parse_info_file($makefile);
// Remove incorrect value.
unset($info['format']);
$dumper = drush_load_engine('outputformat', 'yaml');
$yaml = $dumper->format($info, array());
if (file_put_contents($file, $yaml)) {
drush_log(dt("Wrote make file @file", array('@file' => $file)), 'ok');
return $file;
}
else {
make_error('FILE_ERROR', dt("Unable to write file !file", array('!file' => $file)));
}
}
/**
* Drush callback: hidden file to process an individual project.
*
* @param string $directory
* Directory where the project is being built.
*/
function drush_make_process($directory) {
drush_get_engine('release_info');
// Set the temporary directory.
make_tmp(TRUE, $directory);
if (!$projects_location = drush_get_option('projects-location')) {
return drush_set_error('MAKE-PROCESS', dt('No projects passed to drush_make_process'));
}
$projects = json_decode(file_get_contents($projects_location), TRUE);
$manifest = drush_get_option('manifest', array());
foreach ($projects as $project) {
if ($instance = DrushMakeProject::getInstance($project['type'], $project)) {
$instance->setManifest($manifest);
$instance->make();
}
else {
make_error('PROJECT-TYPE', dt('Non-existent project type %type on project %project.', array('%type' => $project['type'], '%project' => $project['name'])));
}
}
}
/**
* Gather additional data on all projects specified in the make file.
*/
function make_prepare_projects($recursion, $info, $contrib_destination = '', $build_path = '', $make_dir = '') {
$release_info = drush_get_engine('release_info');
// Nothing to make if the project list is empty. Maybe complain about it.
if (empty($info['projects'])) {
if (drush_get_option('no-core') || $recursion) {
return TRUE;
}
else {
return drush_set_error('MAKE_NO_CORE', dt('No core project specified.'));
}
}
// Obtain translations to download along with the projects.
$translations = array();
if (isset($info['translations'])) {
$translations = $info['translations'];
}
if ($arg_translations = drush_get_option('translations', FALSE)) {
$translations = array_merge(explode(',', $arg_translations), $translations);
}
// Normalize projects.
$projects = array();
$ignore_checksums = drush_get_option('ignore-checksums');
foreach ($info['projects'] as $key => $project) {
// Merge the known data onto the project info.
$project += array(
'name' => $key,
'core' => $info['core'],
'translations' => $translations,
'build_path' => $build_path,
'contrib_destination' => $contrib_destination,
'version' => '',
'location' => drush_get_option('make-update-default-url', ReleaseInfo::DEFAULT_URL),
'subdir' => '',
'directory_name' => '',
'make_directory' => $make_dir,
'options' => array(),
);
// MD5 Checksum.
if ($ignore_checksums) {
unset($project['download']['md5']);
}
elseif (!empty($project['md5'])) {
$project['download']['md5'] = $project['md5'];
}
// If download components are specified, but not the download
// type, default to git.
if (isset($project['download']) && !isset($project['download']['type'])) {
$project['download']['type'] = 'git';
}
// Localization server.
if (!isset($project['l10n_url']) && ($project['location'] == ReleaseInfo::DEFAULT_URL)) {
$project['l10n_url'] = MAKE_DEFAULT_L10N_SERVER;
}
// Classify projects in core or contrib.
if ($project['location'] != ReleaseInfo::DEFAULT_URL && !isset($project['type'])) {
$request = make_prepare_request($project);
$is_core = $release_info->checkProject($request, 'core');
$project['download_type'] = ($is_core ? 'core' : 'contrib');
}
elseif (!empty($project['type'])) {
$project['download_type'] = ($project['type'] == 'core' ? 'core' : 'contrib');
}
else {
$project['download_type'] = ($project['name'] == 'drupal' ? 'core' : 'contrib');
}
$projects[$project['download_type']][$project['name']] = $project;
}
// Verify there're enough cores, but not too many.
$cores = !empty($projects['core']) ? count($projects['core']) : 0;
if (drush_get_option('no-core')) {
unset($projects['core']);
}
elseif ($cores == 0 && !$recursion) {
return drush_set_error('MAKE_NO_CORE', dt('No core project specified.'));
}
elseif ($cores == 1 && $recursion) {
unset($projects['core']);
}
elseif ($cores > 1) {
return drush_set_error('MAKE_MULTIPLE_CORES', dt('More than one core project specified.'));
}
// Set download type = pm for suitable projects.
foreach (array_keys($projects) as $project_type) {
foreach ($projects[$project_type] as $project) {
if (make_project_needs_release_info($project)) {
$request = make_prepare_request($project, $project_type);
$release = $release_info->selectReleaseBasedOnStrategy($request, '', 'ignore');
if ($release === FALSE) {
return FALSE;
}
$request['project_type'] = $release_info->get($request)->getType();
if (!isset($project['type'])) {
// Translate release_info key for project_type to drush make.
$project['type'] = $request['project_type'];
}
if (!isset($project['download'])) {
$project['download'] = array(
'type' => 'pm',
'full_version' => $release['version'],
'download_link' => $release['download_link'],
'status url' => $request['status url'],
);
}
}
$projects[$project_type][$project['name']] = $project;
}
}
if (!$recursion) {
$projects += array(
'core' => array(),
'contrib' => array(),
);
drush_set_option('DRUSH_MAKE_PROJECTS', array_merge($projects['core'], $projects['contrib']));
}
return $projects;
}
/**
* Process all projects specified in the make file.
*/
function make_projects($recursion, $contrib_destination, $info, $build_path, $make_dir) {
$projects = make_prepare_projects($recursion, $info, $contrib_destination, $build_path, $make_dir);
// Abort if there was an error processing projects.
if ($projects === FALSE) {
return FALSE;
}
// Core is built in place, rather than using make-process.
if (!empty($projects['core']) && count($projects['core'])) {
$project = current($projects['core']);
$project = DrushMakeProject::getInstance('core', $project);
$project->make();
}
// Process all projects concurrently using make-process.
if (isset($projects['contrib'])) {
$concurrency = drush_get_option('concurrency', 1);
// Generate $concurrency sub-processes to do the actual work.
$invocations = array();
$thread = 0;
foreach ($projects['contrib'] as $project) {
$thread = ++$thread % $concurrency;
// Ensure that we've set this sub-process up.
if (!isset($invocations[$thread])) {
$invocations[$thread] = array(
'args' => array(
make_tmp(),
),
'options' => array(
'projects' => array(),
),
'site' => array(),
);
}
// Add the project to this sub-process.
$invocations[$thread]['options']['projects'][] = $project;
// Add the manifest so recursive downloads do not override projects.
$invocations[$thread]['options']['manifest'] = array_keys($projects['contrib']);
}
if (!empty($invocations)) {
// Backend options.
$backend_options = array(
'concurrency' => $concurrency,
'method' => 'POST',
);
// Store projects in temporary files since passing this much data on the
// pipe buffer can break on certain systems.
_make_write_project_json($invocations);
$common_options = drush_redispatch_get_options();
// Merge in stdin options since we process makefiles recursively. See http://drupal.org/node/1510180.
$common_options = array_merge($common_options, drush_get_context('stdin'));
// Package handler should use 'wget'.
$common_options['package-handler'] = 'wget';
// Avoid any prompts from CLI.
$common_options['yes'] = TRUE;
// Use cache unless explicitly turned off.
if (!drush_get_option('no-cache', FALSE)) {
$common_options['cache'] = TRUE;
}
// Unless --verbose or --debug are passed, quiter backend output.
if (empty($common_options['verbose']) && empty($common_options['debug'])) {
$backend_options['#output-label'] = FALSE;
$backend_options['integrate'] = TRUE;
}
drush_backend_invoke_concurrent($invocations, $common_options, $backend_options, 'make-process', '@none');
}
}
return TRUE;
}
/**
* Writes out project data to temporary files.
*
* @param array &$invocations
* An array containing projects sorted by thread.
*/
function _make_write_project_json(array &$invocations) {
foreach ($invocations as $thread => $info) {
$projects = $info['options']['projects'];
unset($invocations[$thread]['options']['projects']);
$temp_file = drush_tempnam('make_projects');
file_put_contents($temp_file, json_encode($projects));
$invocations[$thread]['options']['projects-location'] = $temp_file;
}
}
/**
* Gather additional data on all libraries specified in the make file.
*/
function make_prepare_libraries($recursion, $info, $contrib_destination = '', $build_path = '', $make_dir = '') {
// Nothing to make if the libraries list is empty.
if (empty($info['libraries'])) {
return;
}
$libraries = array();
$ignore_checksums = drush_get_option('ignore-checksums');
foreach ($info['libraries'] as $key => $library) {
if (!is_string($key) || !is_array($library)) {
// TODO Print a prettier message.
continue;
}
// Merge the known data onto the library info.
$library += array(
'name' => $key,
'core' => $info['core'],
'build_path' => $build_path,
'contrib_destination' => $contrib_destination,
'subdir' => '',
'directory_name' => $key,
'make_directory' => $make_dir,
);
if ($ignore_checksums) {
unset($library['download']['md5']);
}
$libraries[$key] = $library;
}
if (!$recursion) {
drush_set_option('DRUSH_MAKE_LIBRARIES', $info['libraries']);
}
return $libraries;
}
/**
* Process all libraries specified in the make file.
*/
function make_libraries($recursion, $contrib_destination, $info, $build_path, $make_dir) {
$libraries = make_prepare_libraries($recursion, $info, $contrib_destination, $build_path, $make_dir);
if (empty($libraries)) {
return;
}
foreach ($libraries as $key => $library) {
$class = DrushMakeProject::getInstance('library', $library);
$class->make();
}
}
/**
* The path where the final build will be placed.
*/
function make_build_path($build_path) {
static $saved_path;
if (isset($saved_path)) {
return $saved_path;
}
// Determine the base of the build.
if (drush_get_option('tar')) {
$build_path = dirname($build_path) . '/' . basename($build_path, '.tar.gz') . '.tar.gz';
}
elseif (isset($build_path) && (!empty($build_path) || $build_path == '.')) {
$build_path = rtrim($build_path, '/');
}
// Allow tests to run without a specified base path.
elseif (drush_get_option('test') || drush_confirm(dt("Make new site in the current directory?"))) {
$build_path = '.';
}
else {
return drush_user_abort(dt('Build aborted.'));
}
if ($build_path != '.' && file_exists($build_path) && !drush_get_option('no-core', FALSE)) {
return drush_set_error('MAKE_PATH_EXISTS', dt('Base path %path already exists.', array('%path' => $build_path)));
}
$saved_path = $build_path;
return $build_path;
}
/**
* Move the completed build into place.
*/
function make_move_build($build_path) {
$tmp_path = make_tmp();
$ret = TRUE;
if ($build_path == '.' || (drush_get_option('no-core', FALSE) && file_exists($build_path))) {
$info = drush_scan_directory($tmp_path . DIRECTORY_SEPARATOR . '__build__', '/./', array('.', '..'), 0, FALSE, 'filename', 0, TRUE);
foreach ($info as $file) {
$destination = $build_path . DIRECTORY_SEPARATOR . $file->basename;
if (file_exists($destination)) {
// To prevent the removal of top-level directories such as 'modules' or
// 'themes', descend in a level if the file exists.
// TODO: This only protects one level of directories from being removed.
$overwrite = drush_get_option('overwrite', FALSE) ? FILE_EXISTS_OVERWRITE : FILE_EXISTS_MERGE;
if (is_dir($destination)) {
$files = drush_scan_directory($file->filename, '/./', array('.', '..'), 0, FALSE);
foreach ($files as $file) {
$ret = $ret && drush_copy_dir($file->filename, $destination . DIRECTORY_SEPARATOR . $file->basename, $overwrite);
}
}
else {
$ret = $ret && drush_copy_dir($file->filename, $destination, $overwrite);
}
}
else {
$ret = $ret && drush_copy_dir($file->filename, $destination);
}
}
}
else {
drush_mkdir(dirname($build_path));
$ret = drush_move_dir($tmp_path . DIRECTORY_SEPARATOR . '__build__', $tmp_path . DIRECTORY_SEPARATOR . basename($build_path), TRUE);
$ret = $ret && drush_copy_dir($tmp_path . DIRECTORY_SEPARATOR . basename($build_path), $build_path);
}
// Copying to final destination resets write permissions. Re-apply.
if (drush_get_option('prepare-install')) {
$default = $build_path . '/sites/default';
chmod($default . '/settings.php', 0666);
chmod($default . '/files', 0777);
}
if (!$ret) {
return drush_set_error('MAKE_CANNOT_MOVE_BUILD', dt("Cannot move build into place."));
}
return $ret;
}
/**
* Create a request array suitable for release_info engine.
*
* This is a convenience function to easily integrate drush_make
* with drush release_info engine.
*
* @todo: refactor 'make' to internally work with release_info keys.
*
* @param array $project
* Project array.
* @param string $type
* 'contrib' or 'core'.
*/
function make_prepare_request($project, $type = 'contrib') {
$request = array(
'name' => $project['name'],
'drupal_version' => $project['core'],
'status url' => $project['location'],
);
if ($project['version'] != '') {
$request['project_version'] = $project['version'];
$request['version'] = $type == 'core' ? $project['version'] : $project['core'] . '-' . $project['version'];
}
return $request;
}
/**
* Determine if the release information is required for this
* project. When it is determined that it is, this potentially results
* in the use of pm-download to process the project.
*
* If the location of the project is not customized (uses d.o), and
* one of the following is true, then release information is required:
*
* - $project['type'] has not been specified
* - $project['download'] has not been specified
*
* @see make_projects()
*/
function make_project_needs_release_info($project) {
return isset($project['location'])
// Only fetch release info if the project type is unknown OR if
// download attributes are unspecified.
&& (!isset($project['type']) || !isset($project['download']));
}
/**
* Enables caching if not explicitly disabled.
*
* @return bool
* The previous value of the 'cache' option.
*/
function _make_enable_cache() {
$cache_before = drush_get_option('cache');
if (!drush_get_option('no-cache', FALSE)) {
drush_set_option('cache', TRUE);
}
return $cache_before;
}