Skip to content

Commit

Permalink
In commands, resolve undefined to "" rather than no argument
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AltGr committed Nov 22, 2017
1 parent 487ff29 commit eba5bb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/pages/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

- <a id="opamfield-install">
`install: [ [ <string> { <filter> } ... ] { <filter> } ... ]`</a>:
the list of commands that will be run in order to install the package.
Expand Down
2 changes: 1 addition & 1 deletion src/format/opamFilter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
[]

Expand Down

0 comments on commit eba5bb5

Please sign in to comment.