Implement SUBDIR-= conversion in pro2cmake tool

CMake doesn't support removing subdirectories therefore one need to
convert all removal to conditional adds. The resulting code doesn't
win a beauty contest. That is because handle_subdir works on already
processed strings which means it doesn't have access to the boolean
operations. As such it can not minimize the expressions, but it works
and in the most simple cases it is pretty good.

The patch re-generates CMakeLists.txt under tests/auto/corelib/kernel
excluding qcoreapplication, qmetatype, qmimedata, qobject, qtimer,
which are suffering from unrelated problems, like for example Gui,
pthread linkage issues.

Change-Id: I18a02f6eda7a3b41b1313211c8bc9ce277bb67be
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Jędrzej Nowacki 2019-07-03 14:39:03 +02:00 committed by Alexandru Croitor
parent a920c16ef2
commit b26b1455d7
28 changed files with 566 additions and 29 deletions

View File

@ -1,13 +1,40 @@
# Generated from kernel.pro.
# add_subdirectory(qcoreapplication)
add_subdirectory(qdeadlinetimer)
add_subdirectory(qelapsedtimer)
add_subdirectory(qeventdispatcher)
if(NOT ((NOT TARGET Qt::Network)))
add_subdirectory(qeventloop)
endif()
add_subdirectory(qmath)
add_subdirectory(qmetaenum)
add_subdirectory(qmetamethod)
add_subdirectory(qmetaobject)
add_subdirectory(qmetaobjectbuilder)
add_subdirectory(qmetamethod)
add_subdirectory(qmetaproperty)
# add_subdirectory(qmimedata)
# add_subdirectory(qmetatype)
add_subdirectory(qmetaenum)
if(NOT ((NOT TARGET Qt::Gui)))
# add_subdirectory(qmimedata)
endif()
if(NOT ((ANDROID OR APPLE_UIKIT) OR (NOT TARGET Qt::Network)))
# add_subdirectory(qobject)
endif()
add_subdirectory(qpointer)
if(NOT ((ANDROID OR APPLE_UIKIT) OR (NOT QT_FEATURE_private_tests)))
add_subdirectory(qsharedmemory)
endif()
add_subdirectory(qsignalblocker)
add_subdirectory(qsignalmapper)
# add_subdirectory(qwineventnotifier)
if(NOT ((NOT QT_FEATURE_private_tests) OR (NOT TARGET Qt::Network)))
add_subdirectory(qsocketnotifier)
endif()
if(NOT ((ANDROID OR APPLE_UIKIT) OR (NOT QT_FEATURE_systemsemaphore)))
add_subdirectory(qsystemsemaphore)
endif()
# add_subdirectory(qtimer)
add_subdirectory(qtranslator)
add_subdirectory(qvariant)
if(NOT ((NOT win32_x_ OR WINRT)))
add_subdirectory(qwineventnotifier)
endif()

View File

@ -1 +1,13 @@
add_qt_test(tst_qdeadlinetimer SOURCES tst_qdeadlinetimer.cpp)
# Generated from qdeadlinetimer.pro.
#####################################################################
## tst_qdeadlinetimer Test:
#####################################################################
add_qt_test(tst_qdeadlinetimer
SOURCES
tst_qdeadlinetimer.cpp
)
#### Keys ignored in scope 1:.:.:qdeadlinetimer.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1 +1,13 @@
add_qt_test(tst_qelapsedtimer SOURCES tst_qelapsedtimer.cpp)
# Generated from qelapsedtimer.pro.
#####################################################################
## tst_qelapsedtimer Test:
#####################################################################
add_qt_test(tst_qelapsedtimer
SOURCES
tst_qelapsedtimer.cpp
)
#### Keys ignored in scope 1:.:.:qelapsedtimer.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1 +1,13 @@
add_qt_test(tst_qeventdispatcher SOURCES tst_qeventdispatcher.cpp)
# Generated from qeventdispatcher.pro.
#####################################################################
## tst_qeventdispatcher Test:
#####################################################################
add_qt_test(tst_qeventdispatcher
SOURCES
tst_qeventdispatcher.cpp
)
#### Keys ignored in scope 1:.:.:qeventdispatcher.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -0,0 +1,30 @@
# Generated from qeventloop.pro.
#####################################################################
## tst_qeventloop Test:
#####################################################################
add_qt_test(tst_qeventloop
SOURCES
tst_qeventloop.cpp
LIBRARIES
Qt::CorePrivate
PUBLIC_LIBRARIES
Qt::Network
)
#### Keys ignored in scope 1:.:.:qeventloop.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
extend_target(tst_qeventloop CONDITION WIN32 AND NOT WINRT
PUBLIC_LIBRARIES
user32
)
extend_target(tst_qeventloop CONDITION QT_FEATURE_glib
DEFINES
HAVE_GLIB
)

View File

@ -1 +1,13 @@
add_qt_test(tst_qmath SOURCES tst_qmath.cpp)
# Generated from qmath.pro.
#####################################################################
## tst_qmath Test:
#####################################################################
add_qt_test(tst_qmath
SOURCES
tst_qmath.cpp
)
#### Keys ignored in scope 1:.:.:qmath.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1 +1,13 @@
add_qt_test(tst_qmetaenum SOURCES tst_qmetaenum.cpp)
# Generated from qmetaenum.pro.
#####################################################################
## tst_qmetaenum Test:
#####################################################################
add_qt_test(tst_qmetaenum
SOURCES
tst_qmetaenum.cpp
)
#### Keys ignored in scope 1:.:.:qmetaenum.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1 +1,13 @@
add_qt_test(tst_qmetamethod SOURCES tst_qmetamethod.cpp)
# Generated from qmetamethod.pro.
#####################################################################
## tst_qmetamethod Test:
#####################################################################
add_qt_test(tst_qmetamethod
SOURCES
tst_qmetamethod.cpp
)
#### Keys ignored in scope 1:.:.:qmetamethod.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1 +1,21 @@
add_qt_test(tst_qmetaobject SOURCES tst_qmetaobject.cpp LIBRARIES Qt::CorePrivate)
# Generated from qmetaobject.pro.
#####################################################################
## tst_qmetaobject Test:
#####################################################################
add_qt_test(tst_qmetaobject
SOURCES
tst_qmetaobject.cpp
LIBRARIES
Qt::CorePrivate
)
#### Keys ignored in scope 1:.:.:qmetaobject.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
#### Keys ignored in scope 2:.:.:qmetaobject.pro:qtConfig(c++14):
# CONFIG = "c++14"

View File

@ -1 +1,15 @@
add_qt_test(tst_qmetaobjectbuilder SOURCES tst_qmetaobjectbuilder.cpp LIBRARIES Qt::CorePrivate)
# Generated from qmetaobjectbuilder.pro.
#####################################################################
## tst_qmetaobjectbuilder Test:
#####################################################################
add_qt_test(tst_qmetaobjectbuilder
SOURCES
tst_qmetaobjectbuilder.cpp
LIBRARIES
Qt::CorePrivate
)
#### Keys ignored in scope 1:.:.:qmetaobjectbuilder.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1 +1,13 @@
add_qt_test(tst_qmetaproperty SOURCES tst_qmetaproperty.cpp)
# Generated from qmetaproperty.pro.
#####################################################################
## tst_qmetaproperty Test:
#####################################################################
add_qt_test(tst_qmetaproperty
SOURCES
tst_qmetaproperty.cpp
)
#### Keys ignored in scope 1:.:.:qmetaproperty.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -0,0 +1,41 @@
# Generated from qmetatype.pro.
#####################################################################
## tst_qmetatype Test:
#####################################################################
add_qt_test(tst_qmetatype
SOURCES
tst_qmetatype.cpp
DEFINES
QT_DISABLE_DEPRECATED_BEFORE=0
INCLUDE_DIRECTORIES
../../../other/qvariant_common
LIBRARIES
Qt::CorePrivate
)
#### Keys ignored in scope 1:.:.:qmetatype.pro:<TRUE>:
# CONFIG = "testcase"
# TESTDATA = "./typeFlags.bin"
## Scopes:
#####################################################################
extend_target(tst_qmetatype CONDITION MSVC OR WINRT
COMPILE_OPTIONS
/bigobj
)
#### Keys ignored in scope 3:.:.:qmetatype.pro:WINRT:
# QMAKE_CFLAGS_RELEASE = "--O2"
# QMAKE_CXXFLAGS_RELEASE = "--O2"
#### Keys ignored in scope 4:.:.:qmetatype.pro:CLANG:
# QMAKE_CFLAGS_RELEASE = "--O2" "--g"
# QMAKE_CXXFLAGS_RELEASE = "--O2" "--g"
extend_target(tst_qmetatype CONDITION CLANG AND (TEST_architecture_arch STREQUAL "arm")
DEFINES
TST_QMETATYPE_BROKEN_COMPILER
)

View File

@ -1 +1,13 @@
add_qt_test(tst_qmimedata SOURCES tst_qmimedata.cpp)
# Generated from qmimedata.pro.
#####################################################################
## tst_qmimedata Test:
#####################################################################
add_qt_test(tst_qmimedata
SOURCES
tst_qmimedata.cpp
)
#### Keys ignored in scope 1:.:.:qmimedata.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -0,0 +1,29 @@
# Generated from qobject.pro.
#####################################################################
## tst_qobject Test:
#####################################################################
add_qt_test(tst_qobject
SOURCES
tst_qobject.cpp
DEFINES
QT_DISABLE_DEPRECATED_BEFORE=0
LIBRARIES
Qt::CorePrivate
PUBLIC_LIBRARIES
Qt::Network
)
#### Keys ignored in scope 3:.:.:test.pro:<TRUE>:
# CONFIG = "testcase" "console"
## Scopes:
#####################################################################
#### Keys ignored in scope 4:.:.:test.pro:QT_CONFIG___contains___c++1z:
# CONFIG = "c++1z"
if(NOT WINRT)
add_subdirectory(signalbug)
endif()

View File

@ -0,0 +1,14 @@
# Generated from signalbug.pro.
#####################################################################
## signalbug Binary:
#####################################################################
add_qt_executable(signalbug
GUI
SOURCES
signalbug.cpp signalbug.h
)
#### Keys ignored in scope 1:.:.:signalbug.pro:<TRUE>:
# _LOADED = "qt_test_helper"

View File

@ -0,0 +1,21 @@
# Generated from qpointer.pro.
#####################################################################
## tst_qpointer Test:
#####################################################################
add_qt_test(tst_qpointer
SOURCES
tst_qpointer.cpp
)
#### Keys ignored in scope 1:.:.:qpointer.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
extend_target(tst_qpointer CONDITION TARGET Qt::Widgets
PUBLIC_LIBRARIES
Qt::Widgets
)

View File

@ -0,0 +1,30 @@
# Generated from qsharedmemory.pro.
if(QT_FEATURE_sharedmemory)
#####################################################################
## tst_qsharedmemory Test:
#####################################################################
add_qt_test(tst_qsharedmemory
SOURCES
tst_qsharedmemory.cpp
LIBRARIES
Qt::CorePrivate
)
#### Keys ignored in scope 4:.:.:test.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
extend_target(tst_qsharedmemory CONDITION LINUX
PUBLIC_LIBRARIES
rt
)
if(NOT WINRT)
add_subdirectory(producerconsumer)
endif()
endif()

View File

@ -0,0 +1,16 @@
# Generated from producerconsumer.pro.
#####################################################################
## producerconsumer Binary:
#####################################################################
add_qt_executable(producerconsumer
GUI
SOURCES
main.cpp
PUBLIC_LIBRARIES
Qt::Test
)
#### Keys ignored in scope 1:.:.:producerconsumer.pro:<TRUE>:
# _LOADED = "qt_test_helper"

View File

@ -0,0 +1,13 @@
# Generated from qsignalblocker.pro.
#####################################################################
## tst_qsignalblocker Test:
#####################################################################
add_qt_test(tst_qsignalblocker
SOURCES
tst_qsignalblocker.cpp
)
#### Keys ignored in scope 1:.:.:qsignalblocker.pro:<TRUE>:
# CONFIG = "testcase" "console"

View File

@ -1 +1,13 @@
add_qt_test(tst_qsignalmapper SOURCES tst_qsignalmapper.cpp)
# Generated from qsignalmapper.pro.
#####################################################################
## tst_qsignalmapper Test:
#####################################################################
add_qt_test(tst_qsignalmapper
SOURCES
tst_qsignalmapper.cpp
)
#### Keys ignored in scope 1:.:.:qsignalmapper.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -0,0 +1,9 @@
# Generated from qsocketnotifier.pro.
#####################################################################
## tst_qsocketnotifier Test:
#####################################################################
add_qt_test(tst_qsocketnotifier
SOURCES
tst_qsocketnotifier.cpp

View File

@ -0,0 +1,20 @@
# Generated from qsystemsemaphore.pro.
add_subdirectory(acquirerelease)
#####################################################################
## tst_qsystemsemaphore Test:
#####################################################################
add_qt_test(tst_qsystemsemaphore
SOURCES
tst_qsystemsemaphore.cpp
)
#### Keys ignored in scope 2:.:.:test.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
#### Keys ignored in scope 3:.:.:test.pro:WIN32:
# CONFIG = "console"

View File

@ -0,0 +1,16 @@
# Generated from acquirerelease.pro.
#####################################################################
## acquirerelease Binary:
#####################################################################
add_qt_executable(acquirerelease
GUI
SOURCES
main.cpp
PUBLIC_LIBRARIES
Qt::Test
)
#### Keys ignored in scope 1:.:.:acquirerelease.pro:<TRUE>:
# _LOADED = "qt_test_helper"

View File

@ -0,0 +1,21 @@
# Generated from qtimer.pro.
#####################################################################
## tst_qtimer Test:
#####################################################################
add_qt_test(tst_qtimer
SOURCES
tst_qtimer.cpp
LIBRARIES
Qt::CorePrivate
)
#### Keys ignored in scope 1:.:.:qtimer.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
#### Keys ignored in scope 2:.:.:qtimer.pro:QT_CONFIG___contains___c++1z:
# CONFIG = "c++1z"

View File

@ -0,0 +1,33 @@
# Generated from qtranslator.pro.
#####################################################################
## tst_qtranslator Test:
#####################################################################
add_qt_test(tst_qtranslator
SOURCES
tst_qtranslator.cpp
)
# Resources:
add_qt_resource(tst_qtranslator "qtranslator" PREFIX "/tst_qtranslator" FILES
hellotr_empty.qm
hellotr_la.qm)
#### Keys ignored in scope 1:.:.:qtranslator.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
# Resources:
add_qt_resource(tst_qtranslator "android_testdata" PREFIX "/android_testdata" FILES
dependencies_la.qm
hellotr_empty.qm
hellotr_la.qm
msgfmt_from_po.qm)
#### Keys ignored in scope 3:.:.:qtranslator.pro:else:
# TESTDATA = "dependencies_la.qm" "hellotr_empty.qm" "hellotr_la.qm" "msgfmt_from_po.qm"

View File

@ -0,0 +1,34 @@
# Generated from qvariant.pro.
#####################################################################
## tst_qvariant Test:
#####################################################################
add_qt_test(tst_qvariant
SOURCES
tst_qvariant.cpp
DEFINES
QT_DISABLE_DEPRECATED_BEFORE=0
INCLUDE_DIRECTORIES
../../../other/qvariant_common
LIBRARIES
Qt::CorePrivate
)
# Resources:
add_qt_resource(tst_qvariant "qvariant" FILES
stream/qt4.9/
stream/qt5.0/)
#### Keys ignored in scope 1:.:.:qvariant.pro:<TRUE>:
# CONFIG = "testcase"
## Scopes:
#####################################################################
#### Keys ignored in scope 2:.:.:qvariant.pro:qtConfig(c++14):
# CONFIG = "c++14"
#### Keys ignored in scope 3:.:.:qvariant.pro:qtConfig(c++1z):
# CONFIG = "c++1z"

View File

@ -1 +1,15 @@
add_qt_test(tst_qwineventnotifier SOURCES tst_qwineventnotifier.cpp LIBRARIES Qt::CorePrivate)
# Generated from qwineventnotifier.pro.
#####################################################################
## tst_qwineventnotifier Test:
#####################################################################
add_qt_test(tst_qwineventnotifier
SOURCES
tst_qwineventnotifier.cpp
LIBRARIES
Qt::CorePrivate
)
#### Keys ignored in scope 1:.:.:qwineventnotifier.pro:<TRUE>:
# CONFIG = "testcase"

View File

@ -1026,9 +1026,35 @@ def map_condition(condition: str) -> str:
def handle_subdir(scope: Scope, cm_fh: typing.IO[str], *,
indent: int = 0, is_example: bool=False) -> None:
ind = ' ' * indent
def find_all_remove_subdir(scope: Scope,
current_conditions: typing.FrozenSet[str]=None,
rm_subdir_conditions: typing.Dict[str, typing.Set[typing.FrozenSet[str]]]=None) -> typing.Dict[str, typing.Set[typing.FrozenSet[str]]]:
rm_subdir_conditions = rm_subdir_conditions if rm_subdir_conditions is not None else dict()
for sd in scope.get_files('SUBDIRS'):
if sd.startswith('-') and current_conditions is not None:
conditions = rm_subdir_conditions.get(sd[1:], set())
conditions.add(current_conditions)
rm_subdir_conditions[sd[1:]] = conditions
current_conditions = current_conditions if current_conditions is not None else frozenset()
for child_scope in scope.children:
assert child_scope.condition
find_all_remove_subdir(child_scope, frozenset((*current_conditions, child_scope.condition)), rm_subdir_conditions)
return rm_subdir_conditions
rm_subdir_conditions = find_all_remove_subdir(scope)
for sd in scope.get_files('SUBDIRS'):
if os.path.isdir(sd):
cm_fh.write('{}add_subdirectory({})\n'.format(ind, sd))
conditions = rm_subdir_conditions.get(sd)
cond_ind = ind
if conditions:
conditions_str = " OR ".join(sorted("(" + " AND ".join(condition) + ")" for condition in conditions))
cm_fh.write(f'{ind}if(NOT ({conditions_str}))\n')
cond_ind += " "
cm_fh.write(f'{cond_ind}add_subdirectory({sd})\n')
if conditions:
cm_fh.write(f'{ind}endif()\n')
elif os.path.isfile(sd):
subdir_result = parseProFile(sd, debug=False)
subdir_scope \
@ -1039,22 +1065,23 @@ def handle_subdir(scope: Scope, cm_fh: typing.IO[str], *,
do_include(subdir_scope)
cmakeify_scope(subdir_scope, cm_fh, indent=indent, is_example=is_example)
elif sd.startswith('-'):
cm_fh.write('{}### remove_subdirectory'
'("{}")\n'.format(ind, sd[1:]))
pass
else:
print(' XXXX: SUBDIR {} in {}: Not found.'.format(sd, scope))
for c in scope.children:
cond = c.condition
if cond == 'else':
cm_fh.write('\n{}else()\n'.format(ind))
elif cond:
cm_fh.write('\n{}if({})\n'.format(ind, cond))
handle_subdir(c, cm_fh, indent=indent + 1, is_example=is_example)
if cond:
cm_fh.write('{}endif()\n'.format(ind))
temp_buf = io.StringIO('') # we do not want to print empty conditions
handle_subdir(c, temp_buf, indent=indent + 1, is_example=is_example)
sub_call_str = temp_buf.getvalue()
if sub_call_str:
if cond == 'else':
cm_fh.write('\n{}else()\n'.format(ind))
elif cond:
cm_fh.write('\n{}if({})\n'.format(ind, cond))
cm_fh.write(sub_call_str)
if cond:
cm_fh.write('{}endif()\n'.format(ind))
def sort_sources(sources: typing.List[str]) -> typing.List[str]: