Skip to content

Commit

Permalink
build: use quoteShell for string arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy committed Sep 30, 2022
1 parent bc539e4 commit 160fc20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ Environment variables to be set during compile time
[config file](build/configDefault.nims#L70) ),
can be passed one at a time using `env:FOO=BAR`.
See the [examples](#configuration-examples) below.
The full set can also be passed as a Nim seqeunce using the
syntax `envs:'@["FOO=BAR","FOO2=BAR2"]'`.
Preserving the double quotes (by using single quotes here, or backslashes)
is important in this case.
For the single arguments (`env:FOO=BAR`) the double quotes will be added
The full set can also be passed as a Nim seqeunce of strings using the
syntax `envs:'@["FOO=BAR","FOO2=BAR2","FOO3_WITH_SPACE_QUOTES=BAR3 \"IN QUOTES\""]'`.
The third one defines an environment variable with name `FOO3_WITH_SPACE_QUOTES` and
its content `BAR3 "IN QUOTES"`.
The single quotes above prevent shell from interpreting the Nim expression,
which uses double quotes to denote Nim strings.
And the backslashes preserve the double quotes in Nim strings.
For the single arguments (`env:FOO=BAR`) the double quotes will be added by Nim
so are unnecessary.

Details on the Nim compiler options can be found
Expand Down
2 changes: 1 addition & 1 deletion build/configBase.nims
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ proc getNimFlags*(fo: flagsOpts): seq[string] =
if v=="":
defargs.add "--" & key
else:
defargs.add "--" & key & ":\"" & v & "\""
defargs.add "--" & key & ":" & quoteShell v
else:
if key.len>=7 and key[0..6]!="warning": # warnings don't seem to work here
switch(key, v)
Expand Down
2 changes: 1 addition & 1 deletion build/configDefault.nims
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ chromaDir = ""
gridDir = ""

# seq of extra environment variables to define during build
# e.g. @["OMPI_CXX=foo","BAR=1"]
# e.g. @["OMPI_CXX=foo","BAR=1","ENV_WITH_SPACE_QUOTES=SPACE \"WITH QUOTES\""]
envs = @[]

# seq of extra arguments for Nim during build
Expand Down

0 comments on commit 160fc20

Please sign in to comment.