From: Mike Frysinger Date: Sun, 6 Feb 2022 04:43:38 +0000 (-0500) Subject: py-compile: handle filenames with whitespace X-Git-Tag: v1.16i~123 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a913c268e462a89509726dfeba2cba5e406793c;p=thirdparty%2Fautomake.git py-compile: handle filenames with whitespace The list of files is put into a string and then split on whitespace. Fix the way the list of files are passed to the compile script. * lib/py-compile: Pass files as arguments, not as a string. * t/py-compile-files.sh: New test. --- diff --git a/lib/py-compile b/lib/py-compile index b5f317f15..ccf406235 100755 --- a/lib/py-compile +++ b/lib/py-compile @@ -1,7 +1,7 @@ #!/bin/sh # py-compile - Compile a Python program -scriptversion=2022-02-06.04; # UTC +scriptversion=2022-02-06.05; # UTC # Copyright (C) 2000-2022 Free Software Foundation, Inc. @@ -100,8 +100,7 @@ EOF shift done -files=$* -if test -z "$files"; then +if test $# -eq 0; then usage_error "no files given" fi @@ -143,10 +142,8 @@ fi $PYTHON -c " import sys, os, py_compile, $import_lib -files = '''$files''' - sys.stdout.write('Byte-compiling python modules...\n') -for file in files.split(): +for file in sys.argv[1:]: $pathtrans $filetrans if not os.path.exists(filepath) or not (len(filepath) >= 3 @@ -158,7 +155,7 @@ for file in files.split(): py_compile.compile(filepath, $import_call(filepath), path) else: py_compile.compile(filepath, filepath + 'c', path) -sys.stdout.write('\n')" || exit $? +sys.stdout.write('\n')" "$@" || exit $? # this will fail for python < 1.5, but that doesn't matter ... $PYTHON -O -c " @@ -168,9 +165,8 @@ import sys, os, py_compile, $import_lib if hasattr(sys, 'pypy_translation_info'): sys.exit(0) -files = '''$files''' sys.stdout.write('Byte-compiling python modules (optimized versions) ...\n') -for file in files.split(): +for file in sys.argv[1:]: $pathtrans $filetrans if not os.path.exists(filepath) or not (len(filepath) >= 3 @@ -182,7 +178,7 @@ for file in files.split(): py_compile.compile(filepath, $import_call(filepath$import_arg2), path) else: py_compile.compile(filepath, filepath + 'o', path) -sys.stdout.write('\n')" 2>/dev/null || exit $? +sys.stdout.write('\n')" "$@" 2>/dev/null || exit $? # Local Variables: # mode: shell-script diff --git a/t/py-compile-files.sh b/t/py-compile-files.sh new file mode 100644 index 000000000..fa2dd3251 --- /dev/null +++ b/t/py-compile-files.sh @@ -0,0 +1,36 @@ +#! /bin/sh +# Copyright (C) 2022 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Verify 'py-compile' script can handle inputs with spaces, etc... + +required=python +. test-init.sh + +cp "$am_scriptdir/py-compile" . \ + || fatal_ "failed to fetch auxiliary script py-compile" + +# Create files that require proper quoting. +mkdir "dir with spaces" +touch "nospace.py" "has space.py" "*.py" "dir with spaces/|.py" + +./py-compile "nospace.py" "has space.py" "*.py" "dir with spaces/|.py" + +py_installed "nospace.pyc" +py_installed "has space.pyc" +py_installed "*.pyc" +py_installed "dir with spaces/|.pyc" + +: