Skip to content

Commit 136b796

Browse files
authored
Fixing VM config property expansion. (acquia#2039)
* Fixing VM config property expansion. * Fixing composer:require.
1 parent 8c9fa59 commit 136b796

File tree

6 files changed

+64
-40
lines changed

6 files changed

+64
-40
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"drush/drush": "^9.0.0-beta4",
2626
"grasmash/drupal-security-warning": "^1.0.0",
2727
"grasmash/yaml-cli": "^1.0.0",
28-
"grasmash/yaml-expander": "^1.0.5",
28+
"grasmash/yaml-expander": "^1.2.0",
2929
"php": ">=5.6",
3030
"phpunit/phpunit": "^4.8",
3131
"squizlabs/php_codesniffer": "^2.7",

composer.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/drupal-vm/config.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ vagrant_machine_name: ${project.machine_name}
66
vagrant_ip: ${random.ip}
77

88
# Use Ubuntu 16.04 LTS to match Acquia Cloud environments.
9-
vagrant_box: geerlingguy/ubuntu1604
9+
vagrant_box: ${base_box}
10+
workspace: ${workspace}
1011

1112
# Set drupal_site_name to the project's human-readable name.
1213
drupal_site_name: "${project.human_name}"
@@ -69,14 +70,7 @@ nodejs_npm_global_packages:
6970
- name: gulp-cli
7071
nodejs_install_npm_user: "{{ drupalvm_user }}"
7172
npm_config_prefix: "/home/{{ drupalvm_user }}/.npm-global"
72-
installed_extras:
73-
- adminer
74-
- drush
75-
- mailhog
76-
- memcached
77-
- nodejs
78-
- selenium
79-
- xdebug
73+
installed_extras: ${installed_extras}
8074

8175
# PHP 7
8276
php_version: "7.1"

src/Robo/Commands/Composer/ComposerCommand.php

+23-11
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,40 @@ class ComposerCommand extends BltTasks {
1414
* Requires a composer package.
1515
*
1616
* @command composer:require
17+
*
18+
* @option dev Whether package should be added to require-dev.
1719
*/
18-
public function requirePackage($package_name, $package_version) {
20+
public function requirePackage($package_name, $package_version, $options = ['dev' => FALSE]) {
1921

20-
$task = "composer require '{$package_name}''";
22+
/** @var \Robo\Task\Composer\RequireDependency $task */
23+
$task = $this->taskComposerRequire()
24+
->printOutput(TRUE)
25+
->dir($this->getConfigValue('repo.root'));
26+
if ($options['dev']) {
27+
$task->dev(TRUE);
28+
}
2129
if ($package_version) {
22-
$task = "composer require '{$package_name}:{$package_version}'";
30+
$task->dependency($package_name, $package_version);
2331
}
24-
25-
$result = $this->taskExec($task)
26-
->printOutput(TRUE)
27-
->dir($this->getConfigValue('repo.root'))
28-
->run();
32+
else {
33+
$task->dependency($package_name);
34+
}
35+
$result = $task->run();
2936

3037
if (!$result->wasSuccessful()) {
3138
$this->logger->error("An error occurred while requiring {$package_name}.");
3239
$this->say("This is likely due to an incompatibility with your existing packages.");
3340
$confirm = $this->confirm("Should BLT attempt to update all of your Composer packages in order to find a compatible version?");
3441
if ($confirm) {
35-
$result = $this->taskExec("composer require '{$package_name}:{$package_version}' --no-update && composer update")
42+
$command = "composer require '{$package_name}:{$package_version}' --no-update ";
43+
if ($options['dev']) {
44+
$command .= "--dev ";
45+
}
46+
$command .= "&& composer update";
47+
$task = $this->taskExec($command)
3648
->printOutput(TRUE)
37-
->dir($this->getConfigValue('repo.root'))
38-
->run();
49+
->dir($this->getConfigValue('repo.root'));
50+
$result = $task->run();
3951
if (!$result->wasSuccessful()) {
4052
throw new BltException("Unable to install {$package_name} package.");
4153
}

src/Robo/Commands/Vm/VmCommand.php

+24-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Acquia\Blt\Robo\BltTasks;
66
use Acquia\Blt\Robo\Exceptions\BltException;
7+
use function file_get_contents;
78
use Robo\Contract\VerbosityThresholdInterface;
89
use Symfony\Component\Yaml\Yaml;
910

@@ -208,6 +209,7 @@ protected function requireDrupalVm() {
208209
$package_options = [
209210
'package_name' => 'geerlingguy/drupal-vm',
210211
'package_version' => $this->drupalVmVersionConstraint,
212+
['dev' => TRUE],
211213
];
212214
return $this->invokeCommand('composer:require', $package_options);
213215
}
@@ -219,7 +221,7 @@ protected function requireDrupalVm() {
219221
* TRUE if it is present already and matches version constraint.
220222
*/
221223
protected function isDrupalVmRequired() {
222-
$composer_json = json_decode($this->getConfigValue('repo.root') . '/composer.json', TRUE);
224+
$composer_json = json_decode(file_get_contents($this->getConfigValue('repo.root') . '/composer.json'), TRUE);
223225
return !empty($composer_json['require-dev']['geerlingguy/drupal-vm'])
224226
&& $composer_json['require-dev']['geerlingguy/drupal-vm'] == $this->drupalVmVersionConstraint;
225227
}
@@ -249,7 +251,7 @@ protected function checkRequirements() {
249251
*/
250252
protected function validateConfig($config) {
251253
if (strstr($config['vagrant_machine_name'], '_')) {
252-
$this->logger->warning("vagrant_machine_namefor should not contain an underscore.");
254+
$this->logger->warning("vagrant_machine_name should not contain an underscore.");
253255
}
254256
}
255257

@@ -267,11 +269,27 @@ protected function setBaseBox($config) {
267269
],
268270
'geerlingguy/ubuntu1604');
269271

270-
if ($base_box == 'beet/box') {
271-
$config->set('workspace', '/beetbox/workspace/{{ php_version }}');
272-
$config->set('installed_extras', []);
272+
switch ($base_box) {
273+
case 'beet/box':
274+
$config->set('workspace', '/beetbox/workspace/{{ php_version }}');
275+
$config->set('installed_extras', ['drush']);
276+
break;
277+
278+
case 'geerlingguy/ubuntu1604':
279+
$config->set('workspace', '/root');
280+
$config->set('installed_extras', [
281+
'adminer',
282+
'drush',
283+
'mailhog',
284+
'memcached',
285+
'nodejs',
286+
'selenium',
287+
'xdebug',
288+
]);
289+
break;
273290
}
274-
$config->set('vagrant_box', $base_box);
291+
292+
$config->set('base_box', $base_box);
275293
}
276294

277295
/**
@@ -282,7 +300,6 @@ protected function customizeConfigFiles() {
282300
$config = clone $this->getConfig();
283301

284302
$config->set('drupalvm.config.dir', $this->vmConfigDir);
285-
$config->expandFileProperties($this->projectDrupalVmVagrantfile);
286303

287304
// Generate a Random IP address for the new VM.
288305
$random_local_ip = "192.168." . rand(0, 255) . '.' . rand(0, 255);

src/Robo/Inspector/Inspector.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ public function getMySqlAvailable() {
298298
* TRUE if Drupal VM configuration exists.
299299
*/
300300
public function isDrupalVmConfigPresent() {
301-
return file_exists($this->getConfigValue('repo.root') . '/Vagrantfile');
301+
return file_exists($this->getConfigValue('repo.root') . '/Vagrantfile')
302+
&& file_exists($this->getConfigValue('vm.config'));
302303
}
303304

304305
/**

0 commit comments

Comments
 (0)