- Add homepage and license attributes to metadata of the package

- Patch the shebangs of the executables
This commit is contained in:
Sander van der Burg 2017-09-20 23:23:32 +02:00
parent 914f54f33d
commit 67805db37f
2 changed files with 51 additions and 6 deletions

View file

@ -46,7 +46,7 @@ class Generator
return "./".$target;
}
private static function generatePackagesExpression($outputFile, $name, $preferredInstall, array $packages, $executable, $symlinkDependencies)
private static function generatePackagesExpression(array $config, $outputFile, $name, $preferredInstall, array $packages, $executable, $symlinkDependencies)
{
$handle = fopen($outputFile, "w");
@ -136,6 +136,27 @@ class Generator
$dependencies[$package["name"]] = $dependency;
}
/* Compose meta properties */
$meta = array();
if(array_key_exists("homepage", $config))
$meta["homepage"] = $config["homepage"];
if(array_key_exists("license", $config))
{
if(is_string($config["license"]))
$meta["license"] = $config["license"];
else if(is_array($config["license"]))
{
if(count($config["license"]) > 0)
$meta["license"] = $config["license"][0];
for($i = 1; $i < count($config["license"]); $i++)
$meta["license"] .= ", ".$config["license"][$i];
}
}
/* Compose package function invocation */
$expr = new NixFunction(array(
"composerEnv" => new NixNoDefault(),
"fetchurl" => new NixNoDefault(),
@ -149,7 +170,8 @@ class Generator
"src" => new NixFile("./."),
"executable" => $executable,
"dependencies" => new NixInherit(),
"symlinkDependencies" => $symlinkDependencies
"symlinkDependencies" => $symlinkDependencies,
"meta" => new NixAttrSet($meta)
))));
$exprStr = NixGenerator::phpToNix($expr, true);
@ -240,7 +262,7 @@ class Generator
$packages = array();
/* Generate packages expression */
Generator::generatePackagesExpression($outputFile, $name, $preferredInstall, $packages, $executable, $symlinkDependencies);
Generator::generatePackagesExpression($config, $outputFile, $name, $preferredInstall, $packages, $executable, $symlinkDependencies);
/* Generate composition expression */
Generator::generateCompositionExpression($compositionFile, $outputFile, $composerEnvFile);

View file

@ -49,7 +49,7 @@ rec {
'';
};
buildPackage = { name, src, dependencies ? [], symlinkDependencies ? false, executable ? false, removeComposerArtifacts ? false, postInstall ? ""}@args:
buildPackage = { name, src, dependencies ? [], symlinkDependencies ? false, executable ? false, removeComposerArtifacts ? false, postInstall ? "", ...}@args:
let
reconstructInstalled = writeTextFile {
name = "reconstructinstalled.php";
@ -186,7 +186,30 @@ rec {
${stdenv.lib.optionalString executable ''
${constructBin} composer.json
ln -s $(pwd)/vendor/bin $out/bin
patchShebangs $out/bin
''}
${stdenv.lib.optionalString (!symlinkDependencies) ''
# Patch the shebangs if possible
if [ -d $out/bin ]
then
# Look for all executables in bin/
for i in $out/bin/*
do
# Look for their location
realFile=$(readlink -f "$i")
# Restore write permissions
chmod u+wx "$(dirname "$realFile")"
chmod u+w "$realFile"
# Patch shebang
sed -e "s|#!/usr/bin/php|#!${php}/bin/php|" \
-e "s|#!/usr/bin/env php|#!${php}/bin/php|" \
"$realFile" > tmp
mv tmp "$realFile"
chmod u+x "$realFile"
done
fi
''}
${stdenv.lib.optionalString (removeComposerArtifacts) ''