- Use NixASTNode from PNDP
- Name dependencies sources - Separate fetching the metadata from the AST generation
This commit is contained in:
parent
19ec217ead
commit
aa74ee8cb5
13 changed files with 259 additions and 241 deletions
|
@ -12,7 +12,7 @@
|
|||
],
|
||||
|
||||
"require": {
|
||||
"svanderburg/pndp": "0.0.1"
|
||||
"svanderburg/pndp": "0.0.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpdocumentor/phpdocumentor": "2.9.x"
|
||||
|
|
97
composer.lock
generated
97
composer.lock
generated
|
@ -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",
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Dependencies;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFunInvocation;
|
||||
|
||||
/**
|
||||
* Represents a Mercurial dependency.
|
||||
*/
|
||||
class HgDependency extends Dependency
|
||||
{
|
||||
/**
|
||||
* Constructs a new Mercurial dependency instance.
|
||||
*
|
||||
* @param array $package An array of package configuration properties
|
||||
* @param array $sourceObj An array of download properties
|
||||
*/
|
||||
public function __construct(array $package, array $sourceObj)
|
||||
{
|
||||
parent::__construct($package, $sourceObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NixAST::toNixAST
|
||||
*/
|
||||
public function toNixAST()
|
||||
{
|
||||
$dependency = parent::toNixAST();
|
||||
|
||||
$hash = shell_exec('nix-prefetch-hg "'.$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Dependencies;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFunInvocation;
|
||||
|
||||
/**
|
||||
* Represents a Subversion dependency.
|
||||
*/
|
||||
class SVNDependency extends Dependency
|
||||
{
|
||||
/**
|
||||
* Constructs a new Subversion dependency instance.
|
||||
*
|
||||
* @param array $package An array of package configuration properties
|
||||
* @param array $sourceObj An array of download properties
|
||||
*/
|
||||
public function __construct(array $package, array $sourceObj)
|
||||
{
|
||||
parent::__construct($package, $sourceObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NixAST::toNixAST
|
||||
*/
|
||||
public function toNixAST()
|
||||
{
|
||||
$dependency = parent::toNixAST();
|
||||
|
||||
$hash = shell_exec('nix-prefetch-svn "'.$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Expressions;
|
||||
use Composer2Nix\ComposerConfig;
|
||||
use Composer2Nix\Dependencies\Dependency;
|
||||
use Composer2Nix\Sources\Source;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixAttrSet;
|
||||
use PNDP\AST\NixASTNode;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFile;
|
||||
use PNDP\AST\NixFunction;
|
||||
|
@ -13,7 +14,6 @@ use PNDP\AST\NixLet;
|
|||
use PNDP\AST\NixNoDefault;
|
||||
use PNDP\AST\NixObject;
|
||||
use PNDP\AST\NixURL;
|
||||
use Composer2Nix\NixASTNode;
|
||||
|
||||
/**
|
||||
* A representation of a packages expression specifying all dependencies
|
||||
|
@ -51,15 +51,16 @@ class PackagesExpression extends NixASTNode
|
|||
|
||||
private function generateDependenciesExpr(array $packages)
|
||||
{
|
||||
$dependencies = array();
|
||||
$sources = array();
|
||||
|
||||
foreach($packages as $package)
|
||||
{
|
||||
$dependency = Dependency::constructDependency($package, $this->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()
|
||||
{
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
// TODO: move to PNDP
|
||||
|
||||
namespace Composer2Nix;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixObject;
|
||||
|
||||
/**
|
||||
* A representation of a Nix expression that is non-terminal, i.e. it is
|
||||
* composed out of other objects.
|
||||
*/
|
||||
abstract class NixASTNode extends NixObject
|
||||
{
|
||||
/**
|
||||
* Returns a compound object that will be converted into a Nix
|
||||
* expression.
|
||||
*
|
||||
* @return mixed A composition of objects that can be converted into a Nix expression
|
||||
*/
|
||||
abstract public function toNixAST();
|
||||
|
||||
/**
|
||||
* @see NixObject::toNixExpr
|
||||
*/
|
||||
public function toNixExpr($indentLevel, $format)
|
||||
{
|
||||
return NixGenerator::phpToIndentedNix($this->toNixAST(), $indentLevel, $format);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Dependencies;
|
||||
namespace Composer2Nix\Sources;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFunInvocation;
|
||||
|
@ -7,8 +7,10 @@ use PNDP\AST\NixFunInvocation;
|
|||
/**
|
||||
* Represents a Git dependency.
|
||||
*/
|
||||
class GitDependency extends Dependency
|
||||
class GitSource extends Source
|
||||
{
|
||||
public $url;
|
||||
|
||||
/**
|
||||
* Constructs a new Git dependency instance.
|
||||
*
|
||||
|
@ -21,12 +23,10 @@ class GitDependency extends Dependency
|
|||
}
|
||||
|
||||
/**
|
||||
* @see NixAST::toNixAST
|
||||
* @see Source::fetch()
|
||||
*/
|
||||
public function toNixAST()
|
||||
public function fetch()
|
||||
{
|
||||
$dependency = parent::toNixAST();
|
||||
|
||||
$outputStr = shell_exec('nix-prefetch-git "'.$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
53
src/Composer2Nix/Sources/HgSource.php
Normal file
53
src/Composer2Nix/Sources/HgSource.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Sources;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFunInvocation;
|
||||
|
||||
/**
|
||||
* Represents a Mercurial source.
|
||||
*/
|
||||
class HgSource extends Source
|
||||
{
|
||||
public $hash;
|
||||
|
||||
/**
|
||||
* Constructs a new Mercurial dependency instance.
|
||||
*
|
||||
* @param array $package An array of package configuration properties
|
||||
* @param array $sourceObj An array of download properties
|
||||
*/
|
||||
public function __construct(array $package, array $sourceObj)
|
||||
{
|
||||
parent::__construct($package, $sourceObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Source::fetch()
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Dependencies;
|
||||
namespace Composer2Nix\Sources;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixFile;
|
||||
|
||||
/**
|
||||
* Represents a dependency to a local filesystem path.
|
||||
* Represents a source referring to a local filesystem path.
|
||||
*/
|
||||
class PathDependency extends Dependency
|
||||
class PathSource extends Source
|
||||
{
|
||||
public $path;
|
||||
|
||||
/**
|
||||
* Constructs a new Git dependency instance.
|
||||
*
|
||||
|
@ -20,13 +22,21 @@ class PathDependency extends Dependency
|
|||
}
|
||||
|
||||
/**
|
||||
* @see NixAST::toNixAST
|
||||
* @see Source::fetch()
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
51
src/Composer2Nix/Sources/SVNSource.php
Normal file
51
src/Composer2Nix/Sources/SVNSource.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Sources;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFunInvocation;
|
||||
|
||||
/**
|
||||
* Represents a Subversion source.
|
||||
*/
|
||||
class SVNSource extends Source
|
||||
{
|
||||
/**
|
||||
* Constructs a new Subversion dependency instance.
|
||||
*
|
||||
* @param array $package An array of package configuration properties
|
||||
* @param array $sourceObj An array of download properties
|
||||
*/
|
||||
public function __construct(array $package, array $sourceObj)
|
||||
{
|
||||
parent::__construct($package, $sourceObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Source::fetch()
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,25 +1,25 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Dependencies;
|
||||
use Composer2Nix\NixASTNode;
|
||||
namespace Composer2Nix\Sources;
|
||||
use PNDP\AST\NixASTNode;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Represents a dependency of a composer package that can be converted into a
|
||||
* Nix expression that obtains it.
|
||||
*/
|
||||
abstract class Dependency extends NixASTNode
|
||||
abstract class Source extends NixASTNode
|
||||
{
|
||||
public $package;
|
||||
|
||||
protected $sourceObj;
|
||||
|
||||
/**
|
||||
* Creates a new dependency instance.
|
||||
* Creates a new source instance.
|
||||
*
|
||||
* @param array $package An array of package configuration properties
|
||||
* @param array $sourceObj An array of download properties
|
||||
*/
|
||||
protected function __construct(array $package, array $sourceObj)
|
||||
public function __construct(array $package, array $sourceObj)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace Composer2Nix\Dependencies;
|
||||
namespace Composer2Nix\Sources;
|
||||
use PNDP\NixGenerator;
|
||||
use PNDP\AST\NixExpression;
|
||||
use PNDP\AST\NixFile;
|
||||
|
@ -7,10 +7,12 @@ use PNDP\AST\NixFunInvocation;
|
|||
use PNDP\AST\NixURL;
|
||||
|
||||
/**
|
||||
* Represents a Zip package dependency.
|
||||
* Represents a Zip package source.
|
||||
*/
|
||||
class ZipDependency extends Dependency
|
||||
class ZipSource extends Source
|
||||
{
|
||||
public $hash;
|
||||
|
||||
/**
|
||||
* Constructs a new Zip dependency instance.
|
||||
*
|
||||
|
@ -23,12 +25,10 @@ class ZipDependency extends Dependency
|
|||
}
|
||||
|
||||
/**
|
||||
* @see NixAST::toNixAST
|
||||
* @see Source::fetch()
|
||||
*/
|
||||
public function toNixAST()
|
||||
public function fetch()
|
||||
{
|
||||
$dependency = parent::toNixAST();
|
||||
|
||||
if($this->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;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue