This is an archive of the discontinued LLVM Phabricator instance.

[Clang] [Python] Fix tests when default config file contains -include
ClosedPublic

Authored by thesamesam on Jan 8 2023, 8:33 PM.

Details

Summary

In Gentoo, we make use of Clang's recently-enhanced config file support
and add a default include to clang invocations using '-include ...'.

This breaks clang-python tests like so:

======================================================================
ERROR: test_includes (tests.cindex.test_translation_unit.TestTranslationUnit)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py", line 145, in test_includes
    eq(i[0], i[1])
  File "/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py", line 132, in eq
    self.assert_normpaths_equal(expected[0], actual.source.name)
AttributeError: 'NoneType' object has no attribute 'name'

======================================================================
FAIL: test_inclusion_directive (tests.cindex.test_translation_unit.TestTranslationUnit)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py", line 157, in test_inclusion_directive
    self.assert_normpaths_equal(i[0], i[1])
  File "/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py", line 126, in assert_normpaths_equal
    self.assertEqual(os.path.normpath(path1),
AssertionError: '/var/tmp/portage/dev-python/clang-python-1[58 chars]r1.h' != '/usr/include/gentoo/fortify.h'
- /var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/INPUTS/header1.h
+ /usr/include/gentoo/fortify.h

Disable using the default Clang configuration files on the system, like
we did for other tests.

Bug: https://bugs.gentoo.org/890204
Signed-off-by: Sam James <sam@gentoo.org>

Diff Detail

Event Timeline

thesamesam created this revision.Jan 8 2023, 8:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 8 2023, 8:33 PM
Herald added a subscriber: arphaman. · View Herald Transcript
thesamesam requested review of this revision.Jan 8 2023, 8:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 8 2023, 8:33 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I'm wondering if we shouldn't just by setting CLANG_NO_DEFAULT_CONFIG=1 like in clang's test suite rather than tying to predict how different config files will affect these tests.

Set CLANG_NO_DEFAULT_CONFIG in environment instead to reduce
cat-and-mouse issues.

Add comment.

xen0n added a subscriber: xen0n.Jan 22 2023, 12:58 AM
xen0n added inline comments.
clang/bindings/python/tests/cindex/util.py
82

This is essentially an import-time side effect, IMO it could be better to instead put the envvar provision in clang/bindings/python/tests/CMakeLists.txt: the add_custom_target there already is making use of env so should be relatively easy to stuff this there too.

thesamesam added inline comments.Jan 22 2023, 7:34 PM
clang/bindings/python/tests/cindex/util.py
82

I hesitated to do that because it doesn't vary with the environment at all (the test should never really be run with custom configs), but given you've suggested it, that tips the balance on me being undecided - so I'll implement that now. Thanks!

Switch to setting CLANG_NO_DEFAULT_CONFIG via CMake instead.

xen0n accepted this revision.Jan 23 2023, 12:41 PM
This revision is now accepted and ready to land.Jan 23 2023, 12:41 PM
This revision was landed with ongoing or failed builds.Jan 23 2023, 1:15 PM
This revision was automatically updated to reflect the committed changes.