This is an archive of the discontinued LLVM Phabricator instance.

[LNT] Python 3 support: don't assume order of cmake args
ClosedPublic

Authored by thopre on Oct 11 2019, 3:25 AM.

Details

Summary

runtest/test_suite-cache.shtest test assumes the order of cmake
arguments but some of these are stored in the same dictionary which does
not guarantee any specific ordering. This causes the test to fail on
Python 3.

In particular, CMAKE_C_COMPILER and CMAKE_CXX_COMPILER must come first
but can be in any particular order between each other, then cmake cache
option is expected to come next followed by other option in any
particular order. Since there is no good reason to have arguments in a
given group of option sorted, this commit adapts the testcase to accept
any order by testing each group of argument in a separate FileCheck
invocation.

Event Timeline

thopre created this revision.Oct 11 2019, 3:25 AM

Thanks for the patch @thopre ! I've got a comment above.

tests/runtest/test_suite-cache.shtest
18

My reading from this

for key in ['CMAKE_C_COMPILER:FILEPATH',                          
            'CMAKE_CXX_COMPILER:FILEPATH']:                       
    value = defs.pop(key, None)                                   
    if value is not None:                                         
        early_defs[key] = value                                   
                                                                  
cmake_cmd = ([cmake_cmd] +                                        
             ['-D%s=%s' % (k, v) for k, v in early_defs.items()] +
             cmake_flags + [self._test_suite_dir()] +             
             ['-D%s=%s' % (k, v) for k, v in defs.items()])

is that we may still want to check that the compilers and the cache appear in the specific order (right after the cmake).

The other ones, whose order is unpredictable, (-DFOO=BAR, -DBAR=BAZ) we do want to check them individually,

Does this make sense?

thopre updated this revision to Diff 233390.Dec 11 2019, 9:24 AM
thopre marked 2 inline comments as done.

Check that CMAKE_C(XX)?_COMPILER come first on cmake invocation

thopre added inline comments.Dec 11 2019, 9:24 AM
tests/runtest/test_suite-cache.shtest
18

It does, good catch! How about now?

rogfer01 added inline comments.Dec 12 2019, 12:06 AM
tests/runtest/test_suite-cache.shtest
18

Would it be possible to ensure the -C flag does appear right after the compilers?

It occurs to me that either we make Python 2 deterministic here using an OrderedDict for early_defs (and then we can write a simples check: first C, then CXX, then the cache file) or we write a check like the one below (untested!) where we allow any order and then the cache file

# We allow compilers in either order for Python 2 compat
# CHECK-CACHE1: Execute: {{.*}}cmake {{(-DCMAKE_CXX_COMPILER:FILEPATH=.*/FakeCompilers/clang\+\+-r154331 -DCMAKE_C_COMPILER:FILEPATH=.*/FakeCompilers/clang-r154331 )|(-DCMAKE_C_COMPILER:FILEPATH=.*/FakeCompilers/clang-r154331 -DCMAKE_CXX_COMPILER:FILEPATH=.*/FakeCompilers/clang\+\+-r154331 )}} -C {{.*}}/Release.cmake

(cmake documentation does not seem clear to me regarding the positional behaviour of -C and -D but I imagine early_defs exists for a reason)

thopre updated this revision to Diff 233558.Dec 12 2019, 3:03 AM
thopre marked 2 inline comments as done.

Restrict ordering of options further according to what the code does.

thopre edited the summary of this revision. (Show Details)Dec 12 2019, 3:03 AM
thopre added inline comments.
tests/runtest/test_suite-cache.shtest
18

Oh I see, early_defs, then cmake_flags (which includes -C option), then test_suite_dir then macro definitions.

rogfer01 accepted this revision.Dec 12 2019, 5:40 AM

LGTM.

Thanks again @thopre !

This revision is now accepted and ready to land.Dec 12 2019, 5:40 AM
thopre closed this revision.Dec 12 2019, 6:02 AM