forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblt
executable file
·119 lines (109 loc) · 2.93 KB
/
blt
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
#!/usr/bin/env php
<?php
$repo_root = find_repo_root();
$autoload = require_once $repo_root . '/vendor/autoload.php';
if (!isset($autoload)) {
print "Unable to find autoloader for BLT\n";
exit(1);
}
$robo_namespaces = [
'acsf',
'ci',
'custom',
'drupal',
'setup',
'tests',
'vm',
];
$robo_commands = [
'doctor'
];
$params_string = implode(' ', array_slice($argv, 1));
// If command begins with string in $robo_namespaces, execute command via Robo.
if (!empty($argv[1])) {
foreach ($robo_namespaces as $namespace) {
if (strpos($argv[1], $namespace) === 0) {
require_once __DIR__. '/blt-robo-run.php';
}
}
}
// If command is in $robo_commands, execute command via Robo.
if (!empty($argv[1]) && in_array($argv[1], $robo_commands)) {
$command = $argv[1];
require_once __DIR__. '/blt-robo-run.php';
}
// Otherwise, execute target via Phing.
else {
chdir($repo_root);
$phing = $repo_root . '/vendor/phing/phing/bin/phing';
array_splice($argv, 1, 0, array('-logger', 'vendor.acquia.blt.phing.phingcludes.BltLogger'));
array_splice($argv, 1, 0, array('-f', './vendor/acquia/blt/phing/build.xml'));
// @see vendor/bin/phing
ini_set('html_errors', 'off');
putenv("PHING_HOME=" . realpath(dirname($phing) . '/../'));
$phing_include = dirname($phing) . '/phing.php';
require_once $phing_include;
}
/**
* Finds the root directory for the repository.
*
* @return bool|string
*/
function find_repo_root() {
$possible_repo_roots = [
$_SERVER['PWD'],
getcwd(),
realpath(__DIR__ . '/../'),
realpath(__DIR__ . '/../../../'),
];
foreach ($possible_repo_roots as $possible_repo_root) {
if ($repo_root = find_directory_containing_files($possible_repo_root, ['vendor/bin/blt', 'vendor/autoload.php'])) {
return $repo_root;
}
}
}
/**
* Traverses file system upwards in search of a given file.
*
* Begins searching for $file in $working_directory and climbs up directories
* $max_height times, repeating search.
*
* @param string $working_directory
* @param array $files
* @param int $max_height
*
* @return bool|string
* FALSE if file was not found. Otherwise, the directory path containing the
* file.
*/
function find_directory_containing_files($working_directory, $files, $max_height = 10) {
// Find the root directory of the git repository containing BLT.
// We traverse the file tree upwards $max_height times until we find
// vendor/bin/blt.
$file_path = $working_directory;
for ($i = 0; $i <= $max_height; $i++) {
if (files_exist($file_path, $files)) {
return $file_path;
}
else {
$file_path = realpath($file_path . '/..');
}
}
return FALSE;
}
/**
* Determines if an array of files exist in a particular directory.
*
* @param string $dir
* @param array $files
*
* @return bool
*/
function files_exist($dir, $files) {
foreach ($files as $file) {
if (!file_exists($dir . '/' . $file)) {
return FALSE;
}
}
return TRUE;
}