From 18701544a0cee53fb6a78cee607fde0baa213559 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Thu, 13 Mar 2014 00:37:57 +0700 Subject: [PATCH 1/3] Fixed 'cd' command for windows --- PHPCI/Helper/CommandExecutor.php | 2 +- PHPCI/Model/Build/RemoteGitBuild.php | 12 ++++++++++-- PHPCI/Plugin/Codeception.php | 3 +++ PHPCI/Plugin/Composer.php | 2 +- PHPCI/Plugin/Grunt.php | 9 ++++++++- vars.php | 5 +++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index a422d970..70bfcff5 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -127,7 +127,7 @@ class CommandExecutor } // Use "where" for windows and "which" for other OS - $findCmd = (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') ? 'which' : 'where'; + $findCmd = IS_WIN ? 'which' : 'where'; $findCmdResult = trim(shell_exec($findCmd . ' ' . $bin)); if (!empty($findCmdResult)) { diff --git a/PHPCI/Model/Build/RemoteGitBuild.php b/PHPCI/Model/Build/RemoteGitBuild.php index 43d1e6f7..4faf2557 100644 --- a/PHPCI/Model/Build/RemoteGitBuild.php +++ b/PHPCI/Model/Build/RemoteGitBuild.php @@ -67,7 +67,11 @@ class RemoteGitBuild extends Build $success = $builder->executeCommand('git clone -b %s %s "%s"', $this->getBranch(), $this->getCloneUrl(), $cloneTo); if (!empty($commit) && $commit != 'Manual') { - $builder->executeCommand('cd "%s" && git checkout %s', $cloneTo, $this->getCommitId()); + $cmd = 'cd "%s" && git checkout %s'; + if (IS_WIN) { + $cmd = 'cd /d "%s" && git checkout %s'; + } + $builder->executeCommand($cmd, $cloneTo, $this->getCommitId()); } return $success; @@ -97,7 +101,11 @@ class RemoteGitBuild extends Build $commit = $this->getCommitId(); if (!empty($commit) && $commit != 'Manual') { - $builder->executeCommand('cd "%s" && git checkout %s', $cloneTo, $this->getCommitId()); + $cmd = 'cd "%s" && git checkout %s'; + if (IS_WIN) { + $cmd = 'cd /d "%s" && git checkout %s'; + } + $builder->executeCommand($cmd, $cloneTo, $this->getCommitId()); } // Remove the key file: diff --git a/PHPCI/Plugin/Codeception.php b/PHPCI/Plugin/Codeception.php index bd168145..802d3540 100644 --- a/PHPCI/Plugin/Codeception.php +++ b/PHPCI/Plugin/Codeception.php @@ -70,6 +70,9 @@ class Codeception implements \PHPCI\Plugin } $cmd = 'cd "%s" && ' . $codecept . ' run -c "%s"'; + if (IS_WIN) { + $cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s"'; + } $success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $this->phpci->buildPath . $configPath); return $success; diff --git a/PHPCI/Plugin/Composer.php b/PHPCI/Plugin/Composer.php index 0b89afe0..d40ac100 100644 --- a/PHPCI/Plugin/Composer.php +++ b/PHPCI/Plugin/Composer.php @@ -46,7 +46,7 @@ class Composer implements \PHPCI\Plugin return false; } $cmd = ''; - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + if (IS_WIN) { $cmd = 'php '; } $cmd .= $composerLocation . ' --no-ansi --no-interaction '; diff --git a/PHPCI/Plugin/Grunt.php b/PHPCI/Plugin/Grunt.php index 477a4849..ddbe7aa3 100644 --- a/PHPCI/Plugin/Grunt.php +++ b/PHPCI/Plugin/Grunt.php @@ -60,12 +60,19 @@ class Grunt implements \PHPCI\Plugin public function execute() { // if npm does not work, we cannot use grunt, so we return false - if (!$this->phpci->executeCommand('cd %s && npm install', $this->directory)) { + $cmd = 'cd %s && npm install'; + if (IS_WIN) { + $cmd = 'cd /d %s && npm install'; + } + if (!$this->phpci->executeCommand($cmd, $this->directory)) { return false; } // build the grunt command $cmd = 'cd %s && ' . $this->grunt; + if (IS_WIN) { + $cmd = 'cd /d %s && ' . $this->grunt; + } $cmd .= ' --no-color'; $cmd .= ' --gruntfile %s'; $cmd .= ' %s'; // the task that will be executed diff --git a/vars.php b/vars.php index 5725805e..46b88c79 100644 --- a/vars.php +++ b/vars.php @@ -25,3 +25,8 @@ if (!defined('ENABLE_SHELL_PLUGIN')) { if (!defined('PHPCI_IS_CONSOLE')) { define('PHPCI_IS_CONSOLE', false); } + +$isWin = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false; +if (!defined('IS_WIN')) { + define('IS_WIN', $isWin); +} From 656e0a882ee91f5f4cb708d102ef4970dc721b57 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Fri, 14 Mar 2014 00:06:59 +0700 Subject: [PATCH 2/3] Change 'cp' command to 'copy' for windows --- PHPCI/Model/Build/LocalBuild.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PHPCI/Model/Build/LocalBuild.php b/PHPCI/Model/Build/LocalBuild.php index 8e6984c6..485376ad 100644 --- a/PHPCI/Model/Build/LocalBuild.php +++ b/PHPCI/Model/Build/LocalBuild.php @@ -45,7 +45,11 @@ class LocalBuild extends Build if (isset($buildSettings['prefer_symlink']) && $buildSettings['prefer_symlink'] === true) { return $this->handleSymlink($builder, $reference, $buildPath); } else { - $builder->executeCommand('cp -Rf "%s" "%s/"', $reference, $buildPath); + $cmd = 'cp -Rf "%s" "%s/"'; + if (IS_WIN) { + $cmd = 'copy /Y "%s" "%s/"'; + } + $builder->executeCommand($cmd, $reference, $buildPath); } return true; From 3aa4806e250c5ac197179625654941fa180147e3 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Sat, 15 Mar 2014 12:57:06 +0700 Subject: [PATCH 3/3] Windows fixes --- PHPCI/Helper/CommandExecutor.php | 2 +- PHPCI/Model/Build/LocalBuild.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index 70bfcff5..2e88b938 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -127,7 +127,7 @@ class CommandExecutor } // Use "where" for windows and "which" for other OS - $findCmd = IS_WIN ? 'which' : 'where'; + $findCmd = IS_WIN ? 'where' : 'which'; $findCmdResult = trim(shell_exec($findCmd . ' ' . $bin)); if (!empty($findCmdResult)) { diff --git a/PHPCI/Model/Build/LocalBuild.php b/PHPCI/Model/Build/LocalBuild.php index 485376ad..8cf3844b 100644 --- a/PHPCI/Model/Build/LocalBuild.php +++ b/PHPCI/Model/Build/LocalBuild.php @@ -47,7 +47,7 @@ class LocalBuild extends Build } else { $cmd = 'cp -Rf "%s" "%s/"'; if (IS_WIN) { - $cmd = 'copy /Y "%s" "%s/"'; + $cmd = 'xcopy /E /Y "%s" "%s/*"'; } $builder->executeCommand($cmd, $reference, $buildPath); }