nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #172769 from ncfavier/wrappers-append-args

makeWrapper,makeBinaryWrapper: implement `--append-flags`

authored by

Thiago Kenji Okada and committed by
GitHub
299538e8 b108b8cc

+80 -57
+6 -10
pkgs/applications/networking/instant-messengers/teams/default.nix
··· 57 57 ]; 58 58 59 59 preFixup = '' 60 - gappsWrapperArgs+=(--prefix PATH : "${coreutils}/bin:${gawk}/bin") 60 + gappsWrapperArgs+=( 61 + --prefix PATH : "${coreutils}/bin:${gawk}/bin" 62 + 63 + # fix for https://docs.microsoft.com/en-us/answers/questions/298724/open-teams-meeting-link-on-linux-doens39t-work.html?childToView=309406#comment-309406 64 + --append-flags '--disable-namespace-sandbox --disable-setuid-sandbox' 65 + ) 61 66 ''; 62 67 63 68 ··· 123 118 echo "Adding runtime dependencies to RPATH of Node module $mod" 124 119 patchelf --set-rpath "$runtime_rpath:$mod_rpath" "$mod" 125 120 done; 126 - 127 - # fix for https://docs.microsoft.com/en-us/answers/questions/298724/open-teams-meeting-link-on-linux-doens39t-work.html?childToView=309406#comment-309406 128 - wrapped=$out/bin/.teams-old 129 - mv "$out/bin/teams" "$wrapped" 130 - cat > "$out/bin/teams" << EOF 131 - #! ${runtimeShell} 132 - exec $wrapped "\$@" --disable-namespace-sandbox --disable-setuid-sandbox 133 - EOF 134 - chmod +x "$out/bin/teams" 135 121 ''; 136 122 }; 137 123
+40 -24
pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh
··· 15 15 # makeWrapper EXECUTABLE OUT_PATH ARGS 16 16 17 17 # ARGS: 18 - # --argv0 NAME : set the name of the executed process to NAME 19 - # (if unset or empty, defaults to EXECUTABLE) 20 - # --inherit-argv0 : the executable inherits argv0 from the wrapper. 21 - # (use instead of --argv0 '$0') 22 - # --set VAR VAL : add VAR with value VAL to the executable's environment 23 - # --set-default VAR VAL : like --set, but only adds VAR if not already set in 24 - # the environment 25 - # --unset VAR : remove VAR from the environment 26 - # --chdir DIR : change working directory (use instead of --run "cd DIR") 27 - # --add-flags FLAGS : add FLAGS to invocation of executable 28 - # TODO(@ncfavier): --append-flags 18 + # --argv0 NAME : set the name of the executed process to NAME 19 + # (if unset or empty, defaults to EXECUTABLE) 20 + # --inherit-argv0 : the executable inherits argv0 from the wrapper. 21 + # (use instead of --argv0 '$0') 22 + # --set VAR VAL : add VAR with value VAL to the executable's environment 23 + # --set-default VAR VAL : like --set, but only adds VAR if not already set in 24 + # the environment 25 + # --unset VAR : remove VAR from the environment 26 + # --chdir DIR : change working directory (use instead of --run "cd DIR") 27 + # --add-flags ARGS : prepend ARGS to the invocation of the executable 28 + # (that is, *before* any arguments passed on the command line) 29 + # --append-flags ARGS : append ARGS to the invocation of the executable 30 + # (that is, *after* any arguments passed on the command line) 29 31 30 32 # --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP 31 33 # --suffix ··· 85 83 # makeCWrapper EXECUTABLE ARGS 86 84 # ARGS: same as makeWrapper 87 85 makeCWrapper() { 88 - local argv0 inherit_argv0 n params cmd main flagsBefore flags executable length 86 + local argv0 inherit_argv0 n params cmd main flagsBefore flagsAfter flags executable length 89 87 local uses_prefix uses_suffix uses_assert uses_assert_success uses_stdio uses_asprintf 90 88 executable=$(escapeStringLiteral "$1") 91 89 params=("$@") ··· 152 150 n=$((n + 1)) 153 151 [ $n -ge "$length" ] && main="$main#error makeCWrapper: $p takes 1 argument"$'\n' 154 152 ;; 153 + --append-flags) 154 + flags="${params[n + 1]}" 155 + flagsAfter="$flagsAfter $flags" 156 + uses_assert=1 157 + n=$((n + 1)) 158 + [ $n -ge "$length" ] && main="$main#error makeCWrapper: $p takes 1 argument"$'\n' 159 + ;; 155 160 --argv0) 156 161 argv0=$(escapeStringLiteral "${params[n + 1]}") 157 162 inherit_argv0= ··· 174 165 ;; 175 166 esac 176 167 done 177 - # shellcheck disable=SC2086 178 - [ -z "$flagsBefore" ] || main="$main"${main:+$'\n'}$(addFlags $flagsBefore)$'\n'$'\n' 168 + [[ -z "$flagsBefore" && -z "$flagsAfter" ]] || main="$main"${main:+$'\n'}$(addFlags "$flagsBefore" "$flagsAfter")$'\n'$'\n' 179 169 [ -z "$inherit_argv0" ] && main="${main}argv[0] = \"${argv0:-${executable}}\";"$'\n' 180 170 main="${main}return execv(\"${executable}\", argv);"$'\n' 181 171 ··· 192 184 } 193 185 194 186 addFlags() { 195 - local result n flag flags var 187 + local n flag before after var 188 + # shellcheck disable=SC2086 189 + before=($1) after=($2) 196 190 var="argv_tmp" 197 - flags=("$@") 198 - for ((n = 0; n < ${#flags[*]}; n += 1)); do 199 - flag=$(escapeStringLiteral "${flags[$n]}") 200 - result="$result${var}[$((n+1))] = \"$flag\";"$'\n' 201 - done 202 - printf '%s\n' "char **$var = calloc($((n+1)) + argc, sizeof(*$var));" 191 + printf '%s\n' "char **$var = calloc(${#before[@]} + argc + ${#after[@]} + 1, sizeof(*$var));" 203 192 printf '%s\n' "assert($var != NULL);" 204 193 printf '%s\n' "${var}[0] = argv[0];" 205 - printf '%s' "$result" 194 + for ((n = 0; n < ${#before[@]}; n += 1)); do 195 + flag=$(escapeStringLiteral "${before[n]}") 196 + printf '%s\n' "${var}[$((n + 1))] = \"$flag\";" 197 + done 206 198 printf '%s\n' "for (int i = 1; i < argc; ++i) {" 207 - printf '%s\n' " ${var}[$n + i] = argv[i];" 199 + printf '%s\n' " ${var}[${#before[@]} + i] = argv[i];" 208 200 printf '%s\n' "}" 209 - printf '%s\n' "${var}[$n + argc] = NULL;" 201 + for ((n = 0; n < ${#after[@]}; n += 1)); do 202 + flag=$(escapeStringLiteral "${after[n]}") 203 + printf '%s\n' "${var}[${#before[@]} + argc + $n] = \"$flag\";" 204 + done 205 + printf '%s\n' "${var}[${#before[@]} + argc + ${#after[@]}] = NULL;" 210 206 printf '%s\n' "argv = $var;" 211 207 } 212 208 ··· 375 363 shift 1 376 364 ;; 377 365 --add-flags) 366 + formatArgsLine 1 "$@" 367 + shift 1 368 + ;; 369 + --append-flags) 378 370 formatArgsLine 1 "$@" 379 371 shift 1 380 372 ;;
+20 -14
pkgs/build-support/setup-hooks/make-wrapper.sh
··· 11 11 # makeWrapper EXECUTABLE OUT_PATH ARGS 12 12 13 13 # ARGS: 14 - # --argv0 NAME : set the name of the executed process to NAME 15 - # (if unset or empty, defaults to EXECUTABLE) 16 - # --inherit-argv0 : the executable inherits argv0 from the wrapper. 17 - # (use instead of --argv0 '$0') 18 - # --set VAR VAL : add VAR with value VAL to the executable's environment 19 - # --set-default VAR VAL : like --set, but only adds VAR if not already set in 20 - # the environment 21 - # --unset VAR : remove VAR from the environment 22 - # --chdir DIR : change working directory (use instead of --run "cd DIR") 23 - # --run COMMAND : run command before the executable 24 - # --add-flags FLAGS : add FLAGS to invocation of executable 25 - # TODO(@ncfavier): --append-flags 14 + # --argv0 NAME : set the name of the executed process to NAME 15 + # (if unset or empty, defaults to EXECUTABLE) 16 + # --inherit-argv0 : the executable inherits argv0 from the wrapper. 17 + # (use instead of --argv0 '$0') 18 + # --set VAR VAL : add VAR with value VAL to the executable's environment 19 + # --set-default VAR VAL : like --set, but only adds VAR if not already set in 20 + # the environment 21 + # --unset VAR : remove VAR from the environment 22 + # --chdir DIR : change working directory (use instead of --run "cd DIR") 23 + # --run COMMAND : run command before the executable 24 + # --add-flags ARGS : prepend ARGS to the invocation of the executable 25 + # (that is, *before* any arguments passed on the command line) 26 + # --append-flags ARGS : append ARGS to the invocation of the executable 27 + # (that is, *after* any arguments passed on the command line) 26 28 27 29 # --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP 28 30 # --suffix ··· 38 36 local original="$1" 39 37 local wrapper="$2" 40 38 local params varName value command separator n fileNames 41 - local argv0 flagsBefore flags 39 + local argv0 flagsBefore flagsAfter flags 42 40 43 41 assertExecutable "$original" 44 42 ··· 167 165 flags="${params[$((n + 1))]}" 168 166 n=$((n + 1)) 169 167 flagsBefore="$flagsBefore $flags" 168 + elif [[ "$p" == "--append-flags" ]]; then 169 + flags="${params[$((n + 1))]}" 170 + n=$((n + 1)) 171 + flagsAfter="$flagsAfter $flags" 170 172 elif [[ "$p" == "--argv0" ]]; then 171 173 argv0="${params[$((n + 1))]}" 172 174 n=$((n + 1)) ··· 183 177 done 184 178 185 179 echo exec ${argv0:+-a \"$argv0\"} \""$original"\" \ 186 - "$flagsBefore" '"$@"' >> "$wrapper" 180 + "$flagsBefore" '"$@"' "$flagsAfter" >> "$wrapper" 187 181 188 182 chmod +x "$wrapper" 189 183 }
+4 -2
pkgs/test/make-binary-wrapper/add-flags.c
··· 3 3 #include <assert.h> 4 4 5 5 int main(int argc, char **argv) { 6 - char **argv_tmp = calloc(5 + argc, sizeof(*argv_tmp)); 6 + char **argv_tmp = calloc(4 + argc + 2 + 1, sizeof(*argv_tmp)); 7 7 assert(argv_tmp != NULL); 8 8 argv_tmp[0] = argv[0]; 9 9 argv_tmp[1] = "-x"; ··· 13 13 for (int i = 1; i < argc; ++i) { 14 14 argv_tmp[4 + i] = argv[i]; 15 15 } 16 - argv_tmp[4 + argc] = NULL; 16 + argv_tmp[4 + argc + 0] = "-foo"; 17 + argv_tmp[4 + argc + 1] = "-bar"; 18 + argv_tmp[4 + argc + 2] = NULL; 17 19 argv = argv_tmp; 18 20 19 21 argv[0] = "/send/me/flags";
+1
pkgs/test/make-binary-wrapper/add-flags.cmdline
··· 1 + --append-flags "-foo -bar" \ 1 2 --add-flags "-x -y -z" \ 2 3 --add-flags -abc
+2
pkgs/test/make-binary-wrapper/add-flags.env
··· 4 4 -y 5 5 -z 6 6 -abc 7 + -foo 8 + -bar
+2 -2
pkgs/test/make-binary-wrapper/combination.c
··· 36 36 set_env_suffix("PATH", ":", "/usr/local/bin/"); 37 37 putenv("MESSAGE2=WORLD"); 38 38 39 - char **argv_tmp = calloc(4 + argc, sizeof(*argv_tmp)); 39 + char **argv_tmp = calloc(3 + argc + 0 + 1, sizeof(*argv_tmp)); 40 40 assert(argv_tmp != NULL); 41 41 argv_tmp[0] = argv[0]; 42 42 argv_tmp[1] = "-x"; ··· 45 45 for (int i = 1; i < argc; ++i) { 46 46 argv_tmp[3 + i] = argv[i]; 47 47 } 48 - argv_tmp[3 + argc] = NULL; 48 + argv_tmp[3 + argc + 0] = NULL; 49 49 argv = argv_tmp; 50 50 51 51 argv[0] = "my-wrapper";
+5 -5
pkgs/test/make-wrapper/default.nix
··· 62 62 (mkWrapperBinary { name = "test-unset"; args = [ "--unset" "VAR" ]; }) 63 63 (mkWrapperBinary { name = "test-run"; args = [ "--run" "echo bar" ]; }) 64 64 (mkWrapperBinary { name = "test-run-and-set"; args = [ "--run" "export VAR=foo" "--set" "VAR" "bar" ]; }) 65 - (mkWrapperBinary { name = "test-args"; args = [ "--add-flags" "abc" ]; wrapped = wrappedBinaryArgs; }) 65 + (mkWrapperBinary { name = "test-args"; args = [ "--add-flags" "abc" "--append-flags" "xyz" ]; wrapped = wrappedBinaryArgs; }) 66 66 (mkWrapperBinary { name = "test-prefix"; args = [ "--prefix" "VAR" ":" "abc" ]; }) 67 67 (mkWrapperBinary { name = "test-prefix-noglob"; args = [ "--prefix" "VAR" ":" "./*" ]; }) 68 68 (mkWrapperBinary { name = "test-suffix"; args = [ "--suffix" "VAR" ":" "abc" ]; }) ··· 89 89 # --unset works 90 90 + mkTest "VAR=foo test-unset" "VAR=" 91 91 92 - # --add-flags works 93 - + mkTest "test-args" "abc" 94 - # given flags are appended 95 - + mkTest "test-args foo" "abc foo" 92 + # --add-flags and --append-flags work 93 + + mkTest "test-args" "abc xyz" 94 + # given flags are kept 95 + + mkTest "test-args foo" "abc foo xyz" 96 96 97 97 # --run works 98 98 + mkTest "test-run" "bar\nVAR="