[geos-devel] [GEOS] #1015: Update geos-config tool for consistency
Greg Troxel
gdt at lexort.com
Tue Feb 18 12:24:36 PST 2020
"Regina Obe" <lr at pcorp.us> writes:
> Speaking of reverting the last change that started this whole
> discussion -- does anyone have thoughts on alternative to printf for
> sh? I would like to keep the intent if possible without causing
> backward compatibility issues.
>
> I assume these are the sections that would need reverting.
>
> https://git.osgeo.org/gitea/geos/geos/pulls/99.diff - in the tools/geos-config.cmake #!/bin/sh
>
> index 24a5725..abef1e3 100644
> --- a/tools/geos-config.cmake
> +++ b/tools/geos-config.cmake
> @@ -1,12 +1,12 @@
> -#!/bin/sh
> +#!/bin/bash -e
>
> -prefix=@CMAKE_INSTALL_PREFIX@
> -exec_prefix=@CMAKE_INSTALL_PREFIX@/bin
> -libdir=@CMAKE_INSTALL_PREFIX@/lib
> +# escape path
> +prefix=$(printf %q "@CMAKE_INSTALL_PREFIX@")
> +libdir=${prefix}/lib
>
> and tools/geos-config.in
>
> --- a/tools/geos-config.in
> +++ b/tools/geos-config.in
> @@ -1,11 +1,12 @@
> -#!/bin/sh
> -prefix=@prefix@
> -exec_prefix=@exec_prefix@
> -libdir=@libdir@
> +#!/bin/bash -e
> +
> +# escape paths
> +prefix=$(printf %q "@prefix@")
> +libdir=$(printf %q "@libdir@")
So assigning
prefix=@prefix@
works perfectly fine. The problem is when that is printed later.
If it's just space we are worried about, one could basically printf into
sed to change space to "\ ", and I think that's what the stack overflow
suggestion is doing.
The basic problem is that the build ecosystems assume that one can use
space to tokenize arguments. That is indeed the ancient Unix tradition,
and fighting that leads to lots of pain with quoting.
There's another problem here, which is that inserting \ for quoting is
presuming that the output of geos-config is going to be interpreted by a
shell, rather than taken as is and used to build a command line. I
suppose there is that implication because there are multiiple arguments
separated by a space. One could argue that the interface is space
separated arguments, not shell language. So overall I see allowing
spaces in prefix as heading off into not-well-defined behavior.
More information about the geos-devel
mailing list