From ba1efa71ae3d5055e3076eaad7cf7e6a6e800066 Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 29 Jun 2022 21:04:31 +0300 Subject: [PATCH] stdenv: substituteInPlace: accept multiple filenames I don't know if getopt is available everywhere, so I did not use it. in any case, it can be changed to use getopt in the future if needed. --- doc/stdenv/stdenv.chapter.md | 4 ++-- pkgs/stdenv/generic/setup.sh | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index b57698cb90b..83464a759a5 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -913,9 +913,9 @@ substitute ./foo.in ./foo.out \ --subst-var someVar ``` -### `substituteInPlace` \ \ {#fun-substituteInPlace} +### `substituteInPlace` \ \ {#fun-substituteInPlace} -Like `substitute`, but performs the substitutions in place on the file \. +Like `substitute`, but performs the substitutions in place on the files passed. ### `substituteAll` \ \ {#fun-substituteAll} diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index de8d13160f9..0ba8d101823 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -771,9 +771,18 @@ substitute() { } substituteInPlace() { - local fileName="$1" - shift - substitute "$fileName" "$fileName" "$@" + local -a fileNames=() + for arg in "$@"; do + if [[ "$arg" = "--"* ]]; then + break + fi + fileNames+=("$arg") + shift + done + + for file in "${fileNames[@]}"; do + substitute "$file" "$file" "$@" + done } _allFlags() {