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,34 +53,43 @@ class Generator
foreach($packages as $package) 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); $sourceObj = Generator::selectSourceObject($preferredInstall, $package);
switch($sourceObj["type"]) switch($sourceObj["type"])
{ {
case "path": case "path":
fwrite($handle, ' "'.$package["name"].'" = '.Generator::composeNixFilePath($sourceObj['url']).';'."\n"); fwrite($handle, ' src = '.Generator::composeNixFilePath($sourceObj['url']).";\n");
break; break;
case "zip": case "zip":
fwrite($handle, ' "'.$package["name"].'" = composerEnv.buildZipPackage {'."\n"); fwrite($handle, " src = composerEnv.buildZipPackage {\n");
if($sourceObj["reference"] == "") if($sourceObj["reference"] == "")
$reference = ""; $reference = "";
else else
$reference = "-".$sourceObj["reference"]; $reference = "-".$sourceObj["reference"];
fwrite($handle, ' name = "'.strtr($package["name"], "/", "-").$reference.'";'."\n"); fwrite($handle, ' name = "'.strtr($package["name"], "/", "-").$reference.'";'."\n");
if(substr($sourceObj["url"], 0, 7) === "http://" || substr($sourceObj["url"], 0, 8) === "https://") if(substr($sourceObj["url"], 0, 7) === "http://" || substr($sourceObj["url"], 0, 8) === "https://")
{ {
$hash = shell_exec('nix-prefetch-url "'.$sourceObj['url'].'"'); $hash = shell_exec('nix-prefetch-url "'.$sourceObj['url'].'"');
fwrite($handle, " src = fetchurl {\n"); fwrite($handle, " src = fetchurl {\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n"); fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' sha256 = "'.substr($hash, 0, -1).'";'."\n"); fwrite($handle, ' sha256 = "'.substr($hash, 0, -1).'";'."\n");
fwrite($handle, " };\n"); fwrite($handle, " };\n");
} }
else else
fwrite($handle, " src = ".Generator::composeNixFilePath($sourceObj['url']).";\n"); fwrite($handle, " src = ".Generator::composeNixFilePath($sourceObj['url']).";\n");
fwrite($handle, " };\n"); fwrite($handle, " };\n");
break; break;
@ -91,39 +100,41 @@ class Generator
$output = json_decode($outputStr, true); $output = json_decode($outputStr, true);
$hash = $output["sha256"]; $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, ' name = "'.strtr($package["name"], "/", "-").'-'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n"); fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n"); fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' sha256 = "'.$hash.'";'."\n"); fwrite($handle, ' sha256 = "'.$hash.'";'."\n");
fwrite($handle, " };\n"); fwrite($handle, " };\n");
break; break;
case "hg": case "hg":
$hash = shell_exec('nix-prefetch-hg "'.$sourceObj['url'].'" '.$sourceObj["reference"]); $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, ' name = "'.strtr($package["name"], "/", "-").'-'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n"); fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n"); fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' sha256 = "'.substr($hash, 0, -1).'";'."\n"); fwrite($handle, ' sha256 = "'.substr($hash, 0, -1).'";'."\n");
fwrite($handle, " };\n"); fwrite($handle, " };\n");
break; break;
case "svn": case "svn":
$hash = shell_exec('nix-prefetch-svn "'.$sourceObj['url'].'" '.$sourceObj["reference"]); $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, ' name = "'.strtr($package["name"], "/", "-").'-'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n"); fwrite($handle, ' url = "'.$sourceObj["url"].'";'."\n");
fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n"); fwrite($handle, ' rev = "'.$sourceObj["reference"].'";'."\n");
fwrite($handle, ' sha256 = "'.substr($hash, 0, -1).'";'."\n"); fwrite($handle, ' sha256 = "'.substr($hash, 0, -1).'";'."\n");
fwrite($handle, " };\n"); fwrite($handle, " };\n");
break; break;
default: default:
throw new Exception("Cannot convert dependency of type: ".$sourceObj["type"]); throw new Exception("Cannot convert dependency of type: ".$sourceObj["type"]);
} }
fwrite($handle, " };\n");
} }
fwrite($handle, " };\n"); fwrite($handle, " };\n");

View file

@ -142,9 +142,15 @@ rec {
dependency = dependencies.${dependencyName}; dependency = dependencies.${dependencyName};
in in
'' ''
vendorDir="$(dirname ${dependencyName})" ${if dependency.targetDir == "" then ''
mkdir -p "$vendorDir" vendorDir="$(dirname ${dependencyName})"
ln -s "${dependency}" "$vendorDir/$(basename "${dependencyName}")" mkdir -p "$vendorDir"
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)} '') (builtins.attrNames dependencies)}
cd .. cd ..