Skip to content

[BUG] distutils.ccompiler.CCompiler.has_function does not quote provided includes anymore #3820

@rokm

Description

@rokm

setuptools version

67.2.0

Python version

3.x

OS

Linux (but presumably applicable to all)

Additional environment information

No response

Description

As of 56a5b33 (setuptools 67.2.0), the distutils.ccompiler.CCompiler.has_function in the setuptools-provided distutils ceased to quote the provided includes in the generated test C file (here).

Therefore, the compilation of the generated test C file always fails.

Expected behavior

The provided includes should be quoted (as before the change) to retain compatibility with older code using this function.

How to Reproduce

  1. Run the following test code on Linux:
# program.py
import distutils.ccompiler

# Check for `clock` function in the standard library
cc = distutils.ccompiler.new_compiler()
has_clock = cc.has_function('clock', includes=['time.h'])
print("Has clock:" , has_clock)

Output

With setuptools 67.2.0:

$ python program.py 
/tmp/clocku2l593gf.c:1:10: error: #include expects "FILENAME" or <FILENAME>
    1 | #include time.h
      |          ^~~~
/tmp/clocku2l593gf.c: In function ‘main’:
/tmp/clocku2l593gf.c:3:5: warning: implicit declaration of function ‘clock’ [-Wimplicit-function-declaration]
    3 |     clock();
      |     ^~~~~
/tmp/clocku2l593gf.c:1:1: note: ‘clock’ is defined in header ‘<time.h>’; did you forget to ‘#include <time.h>’?
  +++ |+#include <time.h>
    1 | #include time.h
Has clock: False

With setuptools 67.1.0:

$ python program.py 
Has clock: True

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssues that need to be evaluated for severity and status.bug
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions