Change generated expression and builder to cope with the target-dir property

This commit is contained in:
Sander van der Burg 2017-08-12 13:56:03 +00:00
parent f7c27f896f
commit def3501b91
2 changed files with 46 additions and 29 deletions

View file

@ -53,16 +53,25 @@ class Generator
foreach($packages as $package)
{
fwrite($handle, ' "'.$package["name"].'" = {'."\n");
if(array_key_exists("target-dir", $package))
$targetDir = $package["target-dir"];
else
$targetDir = "";
fwrite($handle, ' targetDir = "'.$targetDir.'";'."\n");
$sourceObj = Generator::selectSourceObject($preferredInstall, $package);
switch($sourceObj["type"])
{
case "path":
fwrite($handle, ' "'.$package["name"].'" = '.Generator::composeNixFilePath($sourceObj['url']).';'."\n");
fwrite($handle, ' src = '.Generator::composeNixFilePath($sourceObj['url']).";\n");
break;
case "zip":
fwrite($handle, ' "'.$package["name"].'" = composerEnv.buildZipPackage {'."\n");
fwrite($handle, " src = composerEnv.buildZipPackage {\n");
if($sourceObj["reference"] == "")
$reference = "";
@ -91,7 +100,7 @@ class Generator
$output = json_decode($outputStr, true);
$hash = $output["sha256"];
fwrite($handle, ' "'.$package["name"].'" = fetchgit {'."\n");
fwrite($handle, " src = fetchgit {\n");
fwrite($handle, ' name = "'.strtr($package["name"], "/", "-").'-'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n");
@ -102,7 +111,7 @@ class Generator
case "hg":
$hash = shell_exec('nix-prefetch-hg "'.$sourceObj['url'].'" '.$sourceObj["reference"]);
fwrite($handle, ' "'.$package["name"].'" = fetchhg {'."\n");
fwrite($handle, " src = fetchhg {\n");
fwrite($handle, ' name = "'.strtr($package["name"], "/", "-").'-'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n");
@ -113,7 +122,7 @@ class Generator
case "svn":
$hash = shell_exec('nix-prefetch-svn "'.$sourceObj['url'].'" '.$sourceObj["reference"]);
fwrite($handle, ' "'.$package["name"].'" = fetchsvn {'."\n");
fwrite($handle, " src = fetchsvn {\n");
fwrite($handle, ' name = "'.strtr($package["name"], "/", "-").'-'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n");
@ -124,6 +133,8 @@ class Generator
default:
throw new Exception("Cannot convert dependency of type: ".$sourceObj["type"]);
}
fwrite($handle, " };\n");
}
fwrite($handle, " };\n");

View file

@ -142,9 +142,15 @@ rec {
dependency = dependencies.${dependencyName};
in
''
${if dependency.targetDir == "" then ''
vendorDir="$(dirname ${dependencyName})"
mkdir -p "$vendorDir"
ln -s "${dependency}" "$vendorDir/$(basename "${dependencyName}")"
ln -s "${dependency.src}" "$vendorDir/$(basename "${dependencyName}")"
'' else ''
namespaceDir="${dependencyName}/$(dirname "${dependency.targetDir}")"
mkdir -p "$namespaceDir"
ln -s "${dependency.src}" "$namespaceDir/$(basename "${dependency.targetDir}")"
''}
'') (builtins.attrNames dependencies)}
cd ..