From dd58d24fa612df73264bb69f82517e1c2bc6999a Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 7 Oct 2016 15:55:16 +0200 Subject: [PATCH 1/2] stdenv: document makeWrapper Add function documentation to `makeWrapper`. Also add user documentation to the nixpkgs manual. --- doc/stdenv.xml | 44 +++++++++++++++++++ .../build-support/setup-hooks/make-wrapper.sh | 20 +++++++++ 2 files changed, 64 insertions(+) diff --git a/doc/stdenv.xml b/doc/stdenv.xml index 2e88d6b4154..b05b7cd2b3b 100644 --- a/doc/stdenv.xml +++ b/doc/stdenv.xml @@ -1091,7 +1091,35 @@ functions. + + + makeWrapper + executable + wrapperfile + args + Constructs a wrapper for a program with various + possible arguments. For example: + + +# adds `FOOBAR=baz` to `$out/bin/foo`’s environment +makeWrapper $out/bin/foo $wrapperfile --set FOOBAR baz + +# prefixes the binary paths of `hello` and `git` +# Be advised that paths often should be patched in directly +# (via string replacements or in `configurePhase`). +makeWrapper $out/bin/foo $wrapperfile --prefix PATH : ${lib.makeBinPath [ hello git ]} + + + There’s many more kinds of arguments, they are documented in + nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh. + + wrapProgram is a convenience function you probably + want to use most of the time. + + + + substitute infile @@ -1250,6 +1278,22 @@ someVar=$(stripHash $name; echo $strippedName) + + + + wrapProgram + executable + makeWrapperArgs + Convenience function for makeWrapper + that automatically creates a sane wrapper file + + It takes all the same arguments as makeWrapper, + except for --argv0. + + It cannot be applied multiple times, since it will overwrite the wrapper + file. + + diff --git a/pkgs/build-support/setup-hooks/make-wrapper.sh b/pkgs/build-support/setup-hooks/make-wrapper.sh index d922db5ccf5..086875976d3 100644 --- a/pkgs/build-support/setup-hooks/make-wrapper.sh +++ b/pkgs/build-support/setup-hooks/make-wrapper.sh @@ -1,3 +1,23 @@ +# construct an executable file that wraps the actual executable +# makeWrapper EXECUTABLE ARGS + +# ARGS: +# --argv0 NAME : set name of executed process to NAME +# (otherwise it’s called …-wrapped) +# --set VAR VAL : add VAR with value VAL to the executable’s environment +# --unset VAR : remove VAR from the environment +# --run COMMAND : run command before the executable +# The command can push extra flags to a magic list variable +# extraFlagsArray, which are then added to the invocation +# of the executable +# --add-flags FLAGS : add FLAGS to invocation of executable + +# --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP +# --suffix +# --suffix-each ENV SEP VALS : like --suffix, but VALS is a list +# --prefix-contents ENV SEP FILES : like --suffix-each, but contents of FILES +# are read first and used as VALS +# --suffix-contents makeWrapper() { local original=$1 local wrapper=$2 From 5ae18574fcea525861e721fb6cb510630a3ad1ec Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 7 Oct 2016 15:56:07 +0200 Subject: [PATCH 2/2] stdenv/makeWrapper: make extraFlagsArray local extraFlagsArray should not be exposed outside of `makeWrapper`, it should only be possible to set it inside a script supplied via the `--run` argument. --- pkgs/build-support/setup-hooks/make-wrapper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/make-wrapper.sh b/pkgs/build-support/setup-hooks/make-wrapper.sh index 086875976d3..4f55493ae48 100644 --- a/pkgs/build-support/setup-hooks/make-wrapper.sh +++ b/pkgs/build-support/setup-hooks/make-wrapper.sh @@ -22,7 +22,7 @@ makeWrapper() { local original=$1 local wrapper=$2 local params varName value command separator n fileNames - local argv0 flagsBefore flags + local argv0 flagsBefore flags extraFlagsArray mkdir -p "$(dirname $wrapper)"