diff options
author | Mike Frysinger <vapier@gentoo.org> | 2022-02-05 23:43:38 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2022-02-05 23:43:38 -0500 |
commit | 8a913c268e462a89509726dfeba2cba5e406793c (patch) | |
tree | 642d7a34b854835a686c9117eed5b1c585468dd1 | |
parent | faa1d2c5cb09be9ff5c65f97a8312834a78c762a (diff) | |
download | automake-8a913c268e462a89509726dfeba2cba5e406793c.tar.gz |
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.
-rwxr-xr-x | lib/py-compile | 16 | ||||
-rw-r--r-- | t/py-compile-files.sh | 36 |
2 files changed, 42 insertions, 10 deletions
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 <https://www.gnu.org/licenses/>. + +# 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" + +: |