From 6324549ea823d067e7fe4de9aee5865c107ee42f Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Wed, 18 Jan 2023 16:14:23 +0100 Subject: [PATCH] Fixed accumulating include dirs after compile - fixes https://github.com/pypa/setuptools/issues/3591 --- distutils/ccompiler.py | 2 +- distutils/tests/test_ccompiler.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 16147167..4a5aeb7c 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -389,7 +389,7 @@ def _fix_compile_args(self, output_dir, macros, include_dirs): raise TypeError("'macros' (if supplied) must be a list of tuples") if include_dirs is None: - include_dirs = self.include_dirs + include_dirs = list(self.include_dirs) elif isinstance(include_dirs, (list, tuple)): include_dirs = list(include_dirs) + (self.include_dirs or []) else: diff --git a/distutils/tests/test_ccompiler.py b/distutils/tests/test_ccompiler.py index c868a56b..88497d25 100644 --- a/distutils/tests/test_ccompiler.py +++ b/distutils/tests/test_ccompiler.py @@ -76,3 +76,17 @@ def test_has_function_prototype(): assert not compiler.has_function( 'setuptools_does_not_exist', includes=[''] ) + + +def test_include_dirs_after_multiple_compile_calls(c_file): + """ + Calling compile multiple times should not change the include dirs + (regression test for setuptools issue #3591). + """ + compiler = ccompiler.new_compiler() + python = sysconfig.get_paths()['include'] + compiler.set_include_dirs([python]) + compiler.compile(_make_strs([c_file])) + assert compiler.include_dirs == [python] + compiler.compile(_make_strs([c_file])) + assert compiler.include_dirs == [python]