diff --git a/composer.json b/composer.json index 01efb68..e0cb450 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { - "svanderburg/pndp": "0.0.1" + "svanderburg/pndp": "0.0.2" }, "require-dev": { "phpdocumentor/phpdocumentor": "2.9.x" diff --git a/composer.lock b/composer.lock index 8390013..1f8cdb3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,22 +4,25 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "ca5ed9191c272685068c66b76ed1bae8", + "content-hash": "4e19529241df314ff818b5e402ebf060", "packages": [ { "name": "svanderburg/pndp", - "version": "v0.0.1", + "version": "v0.0.2", "source": { "type": "git", "url": "https://github.com/svanderburg/pndp.git", - "reference": "99b0904e0f2efb35b8f012892912e0d171e9c2da" + "reference": "4bfe9c4120c23354ab8dc295957dc3009a39bff0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/svanderburg/pndp/zipball/99b0904e0f2efb35b8f012892912e0d171e9c2da", - "reference": "99b0904e0f2efb35b8f012892912e0d171e9c2da", + "url": "https://api.github.com/repos/svanderburg/pndp/zipball/4bfe9c4120c23354ab8dc295957dc3009a39bff0", + "reference": "4bfe9c4120c23354ab8dc295957dc3009a39bff0", "shasum": "" }, + "require-dev": { + "phpdocumentor/phpdocumentor": "2.9.x" + }, "bin": [ "bin/pndp-build" ], @@ -41,7 +44,7 @@ } ], "description": "PNDP: An internal DSL for Nix in PHP", - "time": "2017-09-11T21:11:09+00:00" + "time": "2017-10-22T12:43:22+00:00" } ], "packages-dev": [ @@ -1499,16 +1502,16 @@ }, { "name": "symfony/config", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "0b8541d18507d10204a08384640ff6df3c739ebe" + "reference": "1dbeaa8e2db4b29159265867efff075ad961558c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/0b8541d18507d10204a08384640ff6df3c739ebe", - "reference": "0b8541d18507d10204a08384640ff6df3c739ebe", + "url": "https://api.github.com/repos/symfony/config/zipball/1dbeaa8e2db4b29159265867efff075ad961558c", + "reference": "1dbeaa8e2db4b29159265867efff075ad961558c", "shasum": "" }, "require": { @@ -1551,20 +1554,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2017-04-12T14:07:15+00:00" + "time": "2017-10-04T18:56:36+00:00" }, { "name": "symfony/console", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "c0807a2ca978e64d8945d373a9221a5c35d1a253" + "reference": "f81549d2c5fdee8d711c9ab3c7e7362353ea5853" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c0807a2ca978e64d8945d373a9221a5c35d1a253", - "reference": "c0807a2ca978e64d8945d373a9221a5c35d1a253", + "url": "https://api.github.com/repos/symfony/console/zipball/f81549d2c5fdee8d711c9ab3c7e7362353ea5853", + "reference": "f81549d2c5fdee8d711c9ab3c7e7362353ea5853", "shasum": "" }, "require": { @@ -1612,7 +1615,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-08-27T14:29:03+00:00" + "time": "2017-10-01T21:00:16+00:00" }, { "name": "symfony/debug", @@ -1673,16 +1676,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "1377400fd641d7d1935981546aaef780ecd5bf6d" + "reference": "7fe089232554357efb8d4af65ce209fc6e5a2186" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/1377400fd641d7d1935981546aaef780ecd5bf6d", - "reference": "1377400fd641d7d1935981546aaef780ecd5bf6d", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/7fe089232554357efb8d4af65ce209fc6e5a2186", + "reference": "7fe089232554357efb8d4af65ce209fc6e5a2186", "shasum": "" }, "require": { @@ -1729,7 +1732,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-06-02T07:47:27+00:00" + "time": "2017-10-01T21:00:16+00:00" }, { "name": "symfony/filesystem", @@ -1782,16 +1785,16 @@ }, { "name": "symfony/finder", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "4f4e84811004e065a3bb5ceeb1d9aa592630f9ad" + "reference": "a945724b201f74d543e356f6059c930bb8d10c92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/4f4e84811004e065a3bb5ceeb1d9aa592630f9ad", - "reference": "4f4e84811004e065a3bb5ceeb1d9aa592630f9ad", + "url": "https://api.github.com/repos/symfony/finder/zipball/a945724b201f74d543e356f6059c930bb8d10c92", + "reference": "a945724b201f74d543e356f6059c930bb8d10c92", "shasum": "" }, "require": { @@ -1827,20 +1830,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-06-01T20:52:29+00:00" + "time": "2017-10-01T21:00:16+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.5.0", + "version": "v1.6.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803" + "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803", - "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", "shasum": "" }, "require": { @@ -1852,7 +1855,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -1886,20 +1889,20 @@ "portable", "shim" ], - "time": "2017-06-14T15:44:48+00:00" + "time": "2017-10-11T12:05:26+00:00" }, { "name": "symfony/process", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "57e52a0a6a80ea0aec4fc1b785a7920a95cb88a8" + "reference": "26c9fb02bf06bd6b90f661a5bd17e510810d0176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/57e52a0a6a80ea0aec4fc1b785a7920a95cb88a8", - "reference": "57e52a0a6a80ea0aec4fc1b785a7920a95cb88a8", + "url": "https://api.github.com/repos/symfony/process/zipball/26c9fb02bf06bd6b90f661a5bd17e510810d0176", + "reference": "26c9fb02bf06bd6b90f661a5bd17e510810d0176", "shasum": "" }, "require": { @@ -1935,20 +1938,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-07-03T08:04:30+00:00" + "time": "2017-10-01T21:00:16+00:00" }, { "name": "symfony/stopwatch", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "e02577b841394a78306d7b547701bb7bb705bad5" + "reference": "28ee62ea4736431ca817cdaebcb005663e9cd1cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/e02577b841394a78306d7b547701bb7bb705bad5", - "reference": "e02577b841394a78306d7b547701bb7bb705bad5", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/28ee62ea4736431ca817cdaebcb005663e9cd1cb", + "reference": "28ee62ea4736431ca817cdaebcb005663e9cd1cb", "shasum": "" }, "require": { @@ -1984,7 +1987,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2017-04-12T14:07:15+00:00" + "time": "2017-10-01T21:00:16+00:00" }, { "name": "symfony/translation", @@ -2052,16 +2055,16 @@ }, { "name": "symfony/validator", - "version": "v2.8.27", + "version": "v2.8.28", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "864ba6865e253a7ffc3db5629af676cfdc3bd104" + "reference": "1531ddfd96efd1b2c231cbf45f22e652a8f67925" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/864ba6865e253a7ffc3db5629af676cfdc3bd104", - "reference": "864ba6865e253a7ffc3db5629af676cfdc3bd104", + "url": "https://api.github.com/repos/symfony/validator/zipball/1531ddfd96efd1b2c231cbf45f22e652a8f67925", + "reference": "1531ddfd96efd1b2c231cbf45f22e652a8f67925", "shasum": "" }, "require": { @@ -2121,7 +2124,7 @@ ], "description": "Symfony Validator Component", "homepage": "https://symfony.com", - "time": "2017-08-27T14:29:03+00:00" + "time": "2017-10-01T21:00:16+00:00" }, { "name": "twig/twig", diff --git a/src/Composer2Nix/Dependencies/HgDependency.php b/src/Composer2Nix/Dependencies/HgDependency.php deleted file mode 100644 index 52a0d09..0000000 --- a/src/Composer2Nix/Dependencies/HgDependency.php +++ /dev/null @@ -1,47 +0,0 @@ -sourceObj['url'].'" '.$this->sourceObj["reference"]); - - if($hash === false) - throw new Exception("Error while invoking nix-prefetch-hg"); - else - { - $dependency["src"] = new NixFunInvocation(new NixExpression("fetchhg"), array( - "name" => strtr($this->package["name"], "/", "-").'-'.$this->sourceObj["reference"], - "url" => $this->sourceObj["url"], - "rev" => $this->sourceObj["reference"], - "sha256" => $hash - )); - } - - return $dependency; - } -} -?> diff --git a/src/Composer2Nix/Dependencies/SVNDependency.php b/src/Composer2Nix/Dependencies/SVNDependency.php deleted file mode 100644 index ad479d6..0000000 --- a/src/Composer2Nix/Dependencies/SVNDependency.php +++ /dev/null @@ -1,47 +0,0 @@ -sourceObj['url'].'" '.$this->sourceObj["reference"]); - - if($hash === false) - throw new Exception("Error while invoking nix-prefetch-svn"); - else - { - $dependency["src"] = new NixFunInvocation(new NixExpression("fetchsvn"), array( - "name" => strtr($this->package["name"], "/", "-").'-'.$this->sourceObj["reference"], - "url" => $this->sourceObj["url"], - "rev" => $this->sourceObj["reference"], - "sha256" => $hash - )); - } - - return $dependency; - } -} -?> diff --git a/src/Composer2Nix/Expressions/CompositionExpression.php b/src/Composer2Nix/Expressions/CompositionExpression.php index a9a3a1f..8f4e97f 100644 --- a/src/Composer2Nix/Expressions/CompositionExpression.php +++ b/src/Composer2Nix/Expressions/CompositionExpression.php @@ -2,6 +2,7 @@ namespace Composer2Nix\Expressions; use PNDP\NixGenerator; use PNDP\AST\NixAttrReference; +use PNDP\AST\NixASTNode; use PNDP\AST\NixExpression; use PNDP\AST\NixFunction; use PNDP\AST\NixFunInvocation; @@ -10,7 +11,6 @@ use PNDP\AST\NixImport; use PNDP\AST\NixInherit; use PNDP\AST\NixLet; use PNDP\AST\NixObject; -use Composer2Nix\NixASTNode; /** * A representation of a composition expression whose purpose is to compose @@ -52,7 +52,7 @@ class CompositionExpression extends NixASTNode } /** - * @see NixAST::toNixAST + * @see NixAST::toNixAST() */ public function toNixAST() { diff --git a/src/Composer2Nix/Expressions/PackagesExpression.php b/src/Composer2Nix/Expressions/PackagesExpression.php index d6de421..805e155 100644 --- a/src/Composer2Nix/Expressions/PackagesExpression.php +++ b/src/Composer2Nix/Expressions/PackagesExpression.php @@ -1,9 +1,10 @@ preferredInstall); - $dependencies[$package["name"]] = $dependency; + $source = Source::constructSource($package, $this->preferredInstall); + $source->fetch(); + $sources[$package["name"]] = $source; } - return new NixAttrSet($dependencies); + return new NixAttrSet($sources); } private function generatePackageMetaDataExpr() @@ -101,7 +102,7 @@ class PackagesExpression extends NixASTNode } /** - * @see NixAST::toNixAST + * @see NixAST::toNixAST() */ public function toNixAST() { diff --git a/src/Composer2Nix/NixASTNode.php b/src/Composer2Nix/NixASTNode.php deleted file mode 100644 index f20023a..0000000 --- a/src/Composer2Nix/NixASTNode.php +++ /dev/null @@ -1,30 +0,0 @@ -toNixAST(), $indentLevel, $format); - } -} -?> diff --git a/src/Composer2Nix/Dependencies/GitDependency.php b/src/Composer2Nix/Sources/GitSource.php similarity index 58% rename from src/Composer2Nix/Dependencies/GitDependency.php rename to src/Composer2Nix/Sources/GitSource.php index 81a5ab5..8ab7597 100644 --- a/src/Composer2Nix/Dependencies/GitDependency.php +++ b/src/Composer2Nix/Sources/GitSource.php @@ -1,5 +1,5 @@ sourceObj['url'].'" '.$this->sourceObj["reference"]); if($outputStr === false) @@ -34,17 +34,25 @@ class GitDependency extends Dependency else { $output = json_decode($outputStr, true); - $hash = $output["sha256"]; - - $dependency["src"] = new NixFunInvocation(new NixExpression("fetchgit"), array( - "name" => strtr($this->package["name"], "/", "-").'-'.$this->sourceObj["reference"], - "url" => $this->sourceObj["url"], - "rev" => $this->sourceObj["reference"], - "sha256" => $hash - )); + $this->hash = $output["sha256"]; } + } - return $dependency; + /** + * @see NixAST::toNixAST() + */ + public function toNixAST() + { + $ast = parent::toNixAST(); + + $ast["src"] = new NixFunInvocation(new NixExpression("fetchgit"), array( + "name" => strtr($this->package["name"], "/", "-").'-'.$this->sourceObj["reference"], + "url" => $this->sourceObj["url"], + "rev" => $this->sourceObj["reference"], + "sha256" => $this->hash + )); + + return $ast; } } ?> diff --git a/src/Composer2Nix/Sources/HgSource.php b/src/Composer2Nix/Sources/HgSource.php new file mode 100644 index 0000000..92a1def --- /dev/null +++ b/src/Composer2Nix/Sources/HgSource.php @@ -0,0 +1,53 @@ +hash = shell_exec('nix-prefetch-hg "'.$this->sourceObj['url'].'" '.$this->sourceObj["reference"]); + + if($this->hash === false) + throw new Exception("Error while invoking nix-prefetch-hg"); + } + + /** + * @see NixAST::toNixAST() + */ + public function toNixAST() + { + $ast = parent::toNixAST(); + + $ast["src"] = new NixFunInvocation(new NixExpression("fetchhg"), array( + "name" => strtr($this->package["name"], "/", "-").'-'.$this->sourceObj["reference"], + "url" => $this->sourceObj["url"], + "rev" => $this->sourceObj["reference"], + "sha256" => $this->hash + )); + + return $ast; + } +} +?> diff --git a/src/Composer2Nix/Dependencies/PathDependency.php b/src/Composer2Nix/Sources/PathSource.php similarity index 53% rename from src/Composer2Nix/Dependencies/PathDependency.php rename to src/Composer2Nix/Sources/PathSource.php index 8a79a8d..905df72 100644 --- a/src/Composer2Nix/Dependencies/PathDependency.php +++ b/src/Composer2Nix/Sources/PathSource.php @@ -1,13 +1,15 @@ path = $this->sourceObj['url']; + } + + /** + * @see NixAST::toNixAST() */ public function toNixAST() { - $dependency = parent::toNixAST(); - $dependency["src"] = new NixFile($this->sourceObj['url']); - return $dependency; + $ast = parent::toNixAST(); + $ast["src"] = new NixFile($this->path); + return $ast; } } ?> diff --git a/src/Composer2Nix/Sources/SVNSource.php b/src/Composer2Nix/Sources/SVNSource.php new file mode 100644 index 0000000..6864235 --- /dev/null +++ b/src/Composer2Nix/Sources/SVNSource.php @@ -0,0 +1,51 @@ +hash = shell_exec('nix-prefetch-svn "'.$this->sourceObj['url'].'" '.$this->sourceObj["reference"]); + + if($this->hash === false) + throw new Exception("Error while invoking nix-prefetch-svn"); + } + + /** + * @see NixAST::toNixAST() + */ + public function toNixAST() + { + $ast = parent::toNixAST(); + + $ast["src"] = new NixFunInvocation(new NixExpression("fetchsvn"), array( + "name" => strtr($this->package["name"], "/", "-").'-'.$this->sourceObj["reference"], + "url" => $this->sourceObj["url"], + "rev" => $this->sourceObj["reference"], + "sha256" => $this->hash + )); + + return $ast; + } +} +?> diff --git a/src/Composer2Nix/Dependencies/Dependency.php b/src/Composer2Nix/Sources/Source.php similarity index 64% rename from src/Composer2Nix/Dependencies/Dependency.php rename to src/Composer2Nix/Sources/Source.php index be70f80..3e6eab9 100644 --- a/src/Composer2Nix/Dependencies/Dependency.php +++ b/src/Composer2Nix/Sources/Source.php @@ -1,25 +1,25 @@ package = $package; $this->sourceObj = $sourceObj; @@ -48,47 +48,52 @@ abstract class Dependency extends NixASTNode } /** - * Constructs a new dependency from a package configuration. + * Constructs a new source from a package configuration. * * @param array $package An array of package configuration properties * @param string $preferredInstall Preferred installation type (source or dist) - * @return A specific kind of dependency object derived from the dependencies' type + * @return A specific kind of dependency object derived from the source's type * @throw An exception if the type is unrecognized */ - public static function constructDependency(array $package, $preferredInstall) + public static function constructSource(array $package, $preferredInstall) { - $sourceObj = Dependency::selectSourceObject($preferredInstall, $package); + $sourceObj = Source::selectSourceObject($preferredInstall, $package); switch($sourceObj["type"]) { case "path": - return new PathDependency($package, $sourceObj); + return new PathSource($package, $sourceObj); case "zip": - return new ZipDependency($package, $sourceObj); + return new ZipSource($package, $sourceObj); case "git": - return new GitDependency($package, $sourceObj); + return new GitSource($package, $sourceObj); case "hg": - return new HgDependency($package, $sourceObj); + return new HgSource($package, $sourceObj); case "svn": - return new SVNDependency($package, $sourceObj); + return new SVNSource($package, $sourceObj); default: throw new Exception("Cannot convert dependency of type: ".$sourceObj["type"]); } } /** - * @see NixAST::toNixAST + * Fetches the package metadata from the external source. + */ + abstract public function fetch(); + + /** + * @see NixAST::toNixAST() */ public function toNixAST() { - $dependency = array(); + $ast = array(); if(array_key_exists("target-dir", $this->package)) - $dependency["targetDir"] = $this->package["target-dir"]; + $ast["targetDir"] = $this->package["target-dir"]; else - $dependency["targetDir"] = ""; + $ast["targetDir"] = ""; - return $dependency; + return $ast; } } ?> diff --git a/src/Composer2Nix/Dependencies/ZipDependency.php b/src/Composer2Nix/Sources/ZipSource.php similarity index 58% rename from src/Composer2Nix/Dependencies/ZipDependency.php rename to src/Composer2Nix/Sources/ZipSource.php index 23c6871..5062370 100644 --- a/src/Composer2Nix/Dependencies/ZipDependency.php +++ b/src/Composer2Nix/Sources/ZipSource.php @@ -1,5 +1,5 @@ sourceObj["reference"] == "") $reference = ""; else @@ -36,27 +36,38 @@ class ZipDependency extends Dependency if(substr($this->sourceObj["url"], 0, 7) === "http://" || substr($this->sourceObj["url"], 0, 8) === "https://") { - $hash = shell_exec('nix-prefetch-url "'.$this->sourceObj['url'].'"'); + $this->hash = shell_exec('nix-prefetch-url "'.$this->sourceObj['url'].'"'); - if($hash === null) + if($this->hash === false) throw new Exception("Error while invoking nix-prefetch-url"); - else - { - $src = new NixFunInvocation(new NixFile("fetchurl"), array( - "url" => new NixURL($this->sourceObj["url"]), - "sha256" => substr($hash, 0, -1) - )); - } } else - $src = new NixFile($this->sourceObj['url']); + $this->hash = null; + } - $dependency["src"] = new NixFunInvocation(new NixExpression("composerEnv.buildZipPackage"), array( + /** + * @see NixAST::toNixAST() + */ + public function toNixAST() + { + $ast = parent::toNixAST(); + + if($this->hash === null) + $src = new NixFile($this->sourceObj['url']); + else + { + $src = new NixFunInvocation(new NixFile("fetchurl"), array( + "url" => new NixURL($this->sourceObj["url"]), + "sha256" => substr($this->hash, 0, -1) + )); + } + + $ast["src"] = new NixFunInvocation(new NixExpression("composerEnv.buildZipPackage"), array( "name" => strtr($this->package["name"], "/", "-").$reference, "src" => $src )); - return $dependency; + return $ast; } } ?>