From eba5bb5d4496c0aec6ef2728a1794f0eb601579d Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Tue, 21 Nov 2017 15:49:50 +0100 Subject: [PATCH] In commands, resolve undefined to "" rather than no argument After some discussion with @dra27, it seems in general safer to hold the positional argument with an empty string rather than shift the possible remaining arguments. So for example, with build: ["some-command" foo "bar"] Previously, if `foo` wasn't defined, that would become `["some-command" "bar"]`. To avoid that, you had to use a string interpolation such as: build: ["some-command" "%{foo}%" "bar"] which is a little heavy under the fingers. With this patch, the behaviour would be the same. Obtaining the previous behaviour is still possible by using an explicit filter: build: ["some-command" foo {?foo} "bar"] which makes it explicit that the positional argument might be present or not --- doc/pages/Manual.md | 3 +++ src/format/opamFilter.ml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/pages/Manual.md b/doc/pages/Manual.md index 11b03541ffc..3891618fbb7 100644 --- a/doc/pages/Manual.md +++ b/doc/pages/Manual.md @@ -763,6 +763,9 @@ files. detect that the package is not installed from a release tarball, and may need additional preprocessing (_e.g._ `automake`). + If a term is undefined (_e.g._ an undefined variable), the empty string is + used as positional argument. + - `install: [ [ { } ... ] { } ... ]`: the list of commands that will be run in order to install the package. diff --git a/src/format/opamFilter.ml b/src/format/opamFilter.ml index 23fd6284ef2..94e8786ef4c 100644 --- a/src/format/opamFilter.ml +++ b/src/format/opamFilter.ml @@ -426,7 +426,7 @@ let arguments env (a,f) = | Some (S s) -> [s] | Some (B b) -> [string_of_bool b] | Some (L sl) -> sl - | None -> log "ERR in replacement: undefined ident %S" i; [] + | None -> log "ERR in replacement: undefined ident %S" i; [""] else []