Skip to content

Commit

Permalink
Accept an empty value for --version-override option to say "don't che…
Browse files Browse the repository at this point in the history
…ck C headers"
  • Loading branch information
mlocati committed Jan 23, 2021
1 parent fec521d commit 727be6b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
29 changes: 28 additions & 1 deletion features/pecl/install-extensions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,34 @@ Feature: download and install PECL extensions
| apc | APC |
| apcu | apcu |
| mongo | mongo |
| memcache | memcache |

Scenario Outline: Does NOT install extensions from PECL repository having wrong version in source code
Given I run "pickle install <extension>-<version> --dry-run"
Then it should fail
And the output should contain:
"""
Version mismatch - '4.0.5.2' != '8.0' in source vs. XML
"""

Examples:
| extension | version |
| memcache | 8.0 |

Scenario Outline: Install extensions from PECL repository having wrong version in source code
Given I run "pickle install <extension>-<version> --dry-run --version-override"
Then it should pass
And the output should contain:
"""
- Installing <extension> (<version>)
"""
And the output should contain:
"""
Package name | <pretty>
"""

Examples:
| extension | version | pretty |
| memcache | 8.0 | memcache |

Scenario Outline: Install extensions from PECL repository with version constraint
Given I run "pickle install <extension>@<version> --dry-run"
Expand Down
3 changes: 3 additions & 0 deletions src/Base/Abstracts/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function getUniqueNameForFs()
is forced to implement it on its own. But so far ... */
public function updateVersion($version = null)
{
if ($version === '') {
return;
}
/* Be sure package root is set before! */
if ($version === null) {
$version = new Header\Version($this);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function configure()
'version-override',
null,
InputOption::VALUE_OPTIONAL,
'Override detected version'
'Override detected version (no value - or empty value - to use the version from package.xml)'
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/InstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function configure()
'version-override',
null,
InputOption::VALUE_OPTIONAL,
'Override detected version'
'Override detected version (no value - or empty value - to use the version from package.xml)'
);

if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
Expand Down
9 changes: 8 additions & 1 deletion src/Console/Helper/PackageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ public function convey(InputInterface $input, OutputInterface $output, $path, $t
$io = new ConsoleIO($input, $output, ($helperSet ? $helperSet : new HelperSet()));

$no_convert = $input->hasOption('no-convert') ? $input->getOption('no-convert') : false;
$versionOverride = $input->hasOption('version-override') ? $input->getOption('version-override') : null;
if ($input->hasOption('version-override')) {
$versionOverride = $input->getOption('version-override');
if ($versionOverride === null && $input->hasParameterOption('--version-override', true)) {
$versionOverride = '';
}
} else {
$versionOverride = null;
}

return (new Convey($path, $io))->deliver($target, $no_convert, $versionOverride);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Package/PHP/Util/PackageXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ public function dump($fname = null)
$this->jsonPath = $fname;
}

$version = $this->versionOverride ?? new Header\Version($this->package);
if ($version != $this->package->getPrettyVersion()) {
throw new \Exception("Version mismatch - '".$version."' != '".$this->package->getVersion().'. in source vs JSON');
if ($this->versionOverride !== '') {
$version = $this->versionOverride ?? (string) new Header\Version($this->package);
if ($version !== $this->package->getPrettyVersion()) {
throw new \Exception("Version mismatch - '".$version."' != '".$this->package->getVersion().'. in source vs JSON');
}
}

$dumper = new Dumper();
Expand Down
10 changes: 6 additions & 4 deletions src/Package/PHP/Util/XML/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function load($path, $versionOverride = null)

$package = [
'name' => (string) $xml->name,
'version' => $versionOverride ?? (string) $xml->version->release,
'version' => (string) $versionOverride === '' ? (string) $xml->version->release : $versionOverride,
'stability' => (string) $xml->stability->release,
'description' => (string) $xml->summary,
];
Expand Down Expand Up @@ -136,9 +136,11 @@ public function load($path, $versionOverride = null)
}
$ret_pkg->setRootDir(dirname($path));

$src_ver = $versionOverride ?? new Header\Version($ret_pkg);
if ($src_ver != $ret_pkg->getPrettyVersion()) {
throw new \Exception("Version mismatch - '".$src_ver."' != '".$ret_pkg->getPrettyVersion()."' in source vs. XML");
if ($versionOverride !== '') {
$src_ver = $versionOverride ?? (string) new Header\Version($ret_pkg);
if ($src_ver !== $ret_pkg->getPrettyVersion()) {
throw new \Exception("Version mismatch - '".$src_ver."' != '".$ret_pkg->getPrettyVersion()."' in source vs. XML");
}
}
$ret_pkg->setType('extension');

Expand Down

0 comments on commit 727be6b

Please sign in to comment.