+2024-10-10 Bruno Haible <bruno@clisp.org>
+
+ csharpcomp-script: Handle directories with spaces correctly.
+ Reported by Michele Locati <michele@locati.it>.
+ * build-aux/csharpcomp.sh.in (command_for_print, command_for_eval,
+ options_csc_for_print, options_csc_for_eval, sources_csc_for_print,
+ sources_csc_for_eval): New variables.
+ (sed_protect_1, sed_protect_2a, sed_protect_2b, sed_protect_2c,
+ sed_protect_3a, sed_protect_3b): New variables, copied from
+ build-aux/x-to-1.in.
+ (func_add_word_to_command): New function, copied from
+ build-aux/x-to-1.in.
+ (func_add_word_to_options_csc, func_add_word_to_sources_csc): New
+ functions.
+ (options_csc, sources_csc): Remove variables. Use
+ func_add_word_to_options_csc, func_add_word_to_sources_csc instead of
+ augmenting them.
+ Use options_csc_for_print, options_csc_for_eval, sources_csc_for_print,
+ sources_csc_for_eval when invoking csc.
+ * build-aux/csharpexec.sh.in (sed_quote_subst): Remove unused variable.
+
2024-10-09 Bruno Haible <bruno@clisp.org>
csharpcomp: Avoid error on Windows.
}
}
+# In order to construct a command that invokes csc, we need 'eval', because
+# some of the arguments may contain spaces.
+command_for_print=
+command_for_eval=
+options_csc_for_print=
+options_csc_for_eval=
+sources_csc_for_print=
+sources_csc_for_eval=
+# Protecting special characters, hiding them from 'eval':
+# Double each backslash.
+sed_protect_1='s/\\/\\\\/g'
+# Escape each dollar, backquote, double-quote.
+sed_protect_2a='s/\$/\\$/g'
+sed_protect_2b='s/`/\\`/g'
+sed_protect_2c='s/"/\\"/g'
+# Add double-quotes at the beginning and end of the word.
+sed_protect_3a='1s/^/"/'
+sed_protect_3b='$s/$/"/'
+func_add_word_to_command ()
+{
+ command_for_print="${command_for_print:+$command_for_print }$1"
+ word_protected=`echo "$1" | sed -e "$sed_protect_1" -e "$sed_protect_2a" -e "$sed_protect_2b" -e "$sed_protect_2c" -e "$sed_protect_3a" -e "$sed_protect_3b"`
+ command_for_eval="${command_for_eval:+$command_for_eval }$word_protected"
+}
+func_add_word_to_options_csc ()
+{
+ options_csc_for_print="${options_csc_for_print:+$options_csc_for_print }$1"
+ word_protected=`echo "$1" | sed -e "$sed_protect_1" -e "$sed_protect_2a" -e "$sed_protect_2b" -e "$sed_protect_2c" -e "$sed_protect_3a" -e "$sed_protect_3b"`
+ options_csc_for_eval="${options_csc_for_eval:+$options_csc_for_eval }$word_protected"
+}
+func_add_word_to_sources_csc ()
+{
+ sources_csc_for_print="${sources_csc_for_print:+$sources_csc_for_print }$1"
+ word_protected=`echo "$1" | sed -e "$sed_protect_1" -e "$sed_protect_2a" -e "$sed_protect_2b" -e "$sed_protect_2c" -e "$sed_protect_3a" -e "$sed_protect_3b"`
+ sources_csc_for_eval="${sources_csc_for_eval:+$sources_csc_for_eval }$word_protected"
+}
+
sed_quote_subst='s/\([|&;<>()$`"'"'"'*?[#~=% \\]\)/\\\1/g'
+
options_mcs=
-options_csc="-nologo"
sources=
-sources_csc=
+func_add_word_to_options_csc "-nologo"
while test $# != 0; do
case "$1" in
-o)
case "$2" in
*.dll)
options_mcs="$options_mcs -target:library"
- options_csc="$options_csc -target:library"
+ func_add_word_to_options_csc "-target:library"
;;
*.exe)
- options_csc="$options_csc -target:exe"
+ func_add_word_to_options_csc "-target:exe"
;;
esac
options_mcs="$options_mcs -out:"`echo "$2" | sed -e "$sed_quote_subst"`
arg=`cygpath -w "$arg"`
;;
esac
- options_csc="$options_csc -out:"`echo "$arg" | sed -e "$sed_quote_subst"`
+ func_add_word_to_options_csc "-out:$arg"
shift
;;
-L)
arg=`cygpath -w "$arg"`
;;
esac
- options_csc="$options_csc -lib:"`echo "$arg" | sed -e "$sed_quote_subst"`
+ func_add_word_to_options_csc "-lib:$arg"
shift
;;
-l)
options_mcs="$options_mcs -reference:"`echo "$2" | sed -e "$sed_quote_subst"`
- options_csc="$options_csc -reference:"`echo "$2" | sed -e "$sed_quote_subst"`".dll"
+ func_add_word_to_options_csc "-reference:$2.dll"
shift
;;
-O)
- options_csc="$options_csc -optimize+"
+ func_add_word_to_options_csc "-optimize+"
;;
-g)
options_mcs="$options_mcs -debug"
- options_csc="$options_csc -debug+"
+ func_add_word_to_options_csc "-debug+"
;;
-*)
echo "csharpcomp: unknown option '$1'" 1>&2
arg=`cygpath -w "$arg"`
;;
esac
- options_csc="$options_csc -resource:"`echo "$arg" | sed -e "$sed_quote_subst"`
+ func_add_word_to_options_csc "-resource:$arg"
;;
*.cs)
sources="$sources "`echo "$1" | sed -e "$sed_quote_subst"`
arg=`cygpath -w "$arg"`
;;
esac
- sources_csc="$sources_csc "`echo "$arg" | sed -e "$sed_quote_subst"`
+ func_add_word_to_sources_csc "$arg"
;;
*)
echo "csharpcomp: unknown type of argument '$1'" 1>&2
arg=`cygpath -w "$arg"`
;;
esac
- options_csc="$options_csc -lib:"`echo "$arg" | sed -e "$sed_quote_subst"`
+ func_add_word_to_options_csc "-lib:$arg"
for file in `cd "$dotnet_runtime_dir" && echo [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*.dll`; do
case "$file" in
*.Native.*) ;;
- *) options_csc="$options_csc -reference:"`echo "$file" | sed -e "$sed_quote_subst"` ;;
+ *) func_add_word_to_options_csc "-reference:$file" ;;
esac
done
+ func_add_word_to_command dotnet
csc="$dotnet_sdk_dir/Roslyn/bincore/csc.dll"
case "@build_os@" in
cygwin*)
csc=`cygpath -w "$csc"`
;;
esac
- test -z "$CSHARP_VERBOSE" || echo dotnet "$csc" $options_csc $sources_csc
- exec dotnet "$csc" $options_csc $sources_csc
+ func_add_word_to_command "$csc"
+ test -z "$CSHARP_VERBOSE" || echo "$command_for_print $options_csc_for_print $sources_csc_for_print"
+ eval "$command_for_eval $options_csc_for_eval $sources_csc_for_eval"
+ exit $?
else
if test -n "@HAVE_DOTNET_CSC@" || test -n "@HAVE_CSC@"; then
- test -z "$CSHARP_VERBOSE" || echo csc $options_csc $sources_csc
- exec csc $options_csc $sources_csc
+ test -z "$CSHARP_VERBOSE" || echo "csc $options_csc_for_print $sources_csc_for_print"
+ eval "csc $options_csc_for_eval $sources_csc_for_eval"
+ exit $?
else
echo 'C# compiler not found, try installing mono or dotnet, then reconfigure' 1>&2
exit 1