Add support for QtQuikCompiler retained resources

Support translating the QTQUICK_COMPILER_RETAINED_RESOURCES variable.

Fix missing PROPERTIES keyword for set_source_files_properties() commands.

Apply source file properties to standalone source files as they appear
in the project as it was possible for them to inherit values that were
not meant for them.

When creating resource lists, prefix them with the resource name
to avoid collisions.

Change-Id: I69ef85ea9414c0e7c07b1ebfb76d24bd878ce70f
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Leander Beernaert 2019-08-12 16:31:30 +02:00
parent 723d5c5056
commit 8630c5ac7e
2 changed files with 48 additions and 12 deletions

View File

@ -2413,11 +2413,13 @@ function(qt_quick_compiler_process_resources target resource_name)
set(qml_files)
set(resource_files)
set(retained_files)
# scan for qml files
foreach(file IN LISTS arg_FILES)
# check whether this resource should not be processed by the qt quick
# compiler
get_source_file_property(skip_compiler_check ${file} QT_SKIP_QUICKCOMPILER)
get_source_file_property(retain_compiler_check ${file} QT_RETAIN_QUICKCOMPILER)
if (skip_compiler_check)
list(APPEND resource_files ${file})
continue()
@ -2427,6 +2429,10 @@ function(qt_quick_compiler_process_resources target resource_name)
OR ${file} MATCHES "\.mjs$"
OR ${file} MATCHES "\.qml$")
list(APPEND qml_files ${file})
if (retain_compiler_check)
list(APPEND retained_files ${file})
list(APPEND resource_files ${file})
endif()
else()
list(APPEND resource_files ${file})
endif()
@ -2435,6 +2441,7 @@ function(qt_quick_compiler_process_resources target resource_name)
message(WARNING "add_qt_resource: Qml files were detected but the qmlcachgen target is not defined. Consider adding QmlTools to your find_package command.")
endif()
set(retained_resource_paths)
if (TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::qmlcachegen AND qml_files)
# Enable qt quick compiler support
set(qml_resource_file "${CMAKE_CURRENT_BINARY_DIR}/${resource_name}.qrc")
@ -2452,6 +2459,9 @@ function(qt_quick_compiler_process_resources target resource_name)
else()
set(file_resource_path "${arg_PREFIX}/${file_resource_path}")
endif()
if (file IN_LIST retained_files)
list(APPEND retained_resource_paths ${file_resource_path})
endif()
file(TO_CMAKE_PATH ${file_resource_path} file_resource_path)
list(APPEND file_resource_paths ${file_resource_path})
string(REGEX REPLACE "\.js$" "_js" compiled_file ${file_relative})
@ -2481,11 +2491,22 @@ function(qt_quick_compiler_process_resources target resource_name)
if (chained_resource_name)
set(resource_name_arg "${resource_name_arg}=${chained_resource_name}")
endif()
if (retained_resource_paths)
set(retained_loader_list "${CMAKE_CURRENT_BINARY_DIR}/qmlcache/${resource_name}/retained_file_list.rsp")
file(GENERATE
OUTPUT ${retained_loader_list}
CONTENT "$<JOIN:${retained_resource_paths},\n>"
)
set(retained_args "--retain" "@${retained_loader_list}")
endif()
add_custom_command(
OUTPUT ${qmlcache_loader_file}
DEPENDS ${qmlcache_loader_list}
COMMAND
${QT_CMAKE_EXPORT_NAMESPACE}::qmlcachegen
${retained_args}
--resource-name "${resource_name_arg}"
-o ${qmlcache_loader_file}
"@${qmlcache_loader_list}"

View File

@ -115,7 +115,8 @@ def find_qmake_conf(project_file_path: str = '') -> typing.Optional[str]:
return None
def process_qrc_file(target: str, filepath: str, base_dir: str = '', project_file_path: str = '', skip_qtquick_compiler: bool = False) -> str:
def process_qrc_file(target: str, filepath: str, base_dir: str = '', project_file_path: str = '', skip_qtquick_compiler: bool = False,
retain_qtquick_compiler: bool = False) -> str:
assert(target)
# Hack to handle QT_SOURCE_TREE. Assume currently that it's the same
@ -172,13 +173,14 @@ def process_qrc_file(target: str, filepath: str, base_dir: str = '', project_fil
alias = path
files[path] = alias
output += write_add_qt_resource_call(target, full_resource_name, prefix, base_dir, lang, files, skip_qtquick_compiler)
output += write_add_qt_resource_call(target, full_resource_name, prefix, base_dir, lang, files, skip_qtquick_compiler, retain_qtquick_compiler)
resource_count += 1
return output
def write_add_qt_resource_call(target: str, resource_name: str, prefix: typing.Optional[str], base_dir: typing.Optional[str], lang: typing.Optional[str], files: typing.Dict[str, str], skip_qtquick_compiler: bool) -> str:
def write_add_qt_resource_call(target: str, resource_name: str, prefix: typing.Optional[str], base_dir: typing.Optional[str],
lang: typing.Optional[str], files: typing.Dict[str, str], skip_qtquick_compiler: bool, retain_qtquick_compiler: bool) -> str:
output = ''
sorted_files = sorted(files.keys())
@ -195,13 +197,14 @@ def write_add_qt_resource_call(target: str, resource_name: str, prefix: typing.O
# Quote file paths in case there are spaces.
sorted_files = ['"{}"'.format(f) for f in sorted_files]
file_list = '\n '.join(sorted_files)
output += 'set({}_resource_files\n {}\n)\n\n'.format(resource_name, file_list)
file_list = "${{{}_resource_files}}".format(resource_name)
if skip_qtquick_compiler:
file_list = '\n '.join(sorted_files)
output += 'set(resource_files\n {}\n)\n\n'.format(file_list)
file_list = "${resource_files}"
output += 'set_source_files_properties(${resource_files} QT_SKIP_QUICKCOMPILER 1)\n\n'
else:
file_list = '\n '.join(sorted_files)
output += 'set_source_files_properties(${{{}_resource_files}} PROPERTIES QT_SKIP_QUICKCOMPILER 1)\n\n'.format(resource_name)
if retain_qtquick_compiler:
output += 'set_source_files_properties(${{{}_resource_files}} PROPERTIES QT_RETAIN_QUICKCOMPILER 1)\n\n'.format(resource_name)
params = ''
if lang:
@ -1688,13 +1691,16 @@ def write_resources(cm_fh: typing.IO[str], target: str, scope: Scope, indent: in
# Handle QRC files by turning them into add_qt_resource:
resources = scope.get_files('RESOURCES')
qtquickcompiler_skipped = scope.get_files('QTQUICK_COMPILER_SKIPPED_RESOURCES')
qtquickcompiler_retained = scope.get_files('QTQUICK_COMPILER_RETAINED_RESOURCES')
qrc_output = ''
if resources:
standalone_files: typing.List[str] = []
for r in resources:
skip_qtquick_compiler = r in qtquickcompiler_skipped
retain_qtquick_compiler = r in qtquickcompiler_retained
if r.endswith('.qrc'):
qrc_output += process_qrc_file(target, r, scope.basedir, scope.file_absolute_path, skip_qtquick_compiler)
qrc_output += process_qrc_file(target, r, scope.basedir, scope.file_absolute_path,
skip_qtquick_compiler, retain_qtquick_compiler)
else:
immediate_files = {f:"" for f in scope.get_files(r + ".files")}
if immediate_files:
@ -1706,8 +1712,16 @@ def write_resources(cm_fh: typing.IO[str], target: str, scope: Scope, indent: in
immediate_base = scope.get(r + ".base")
immediate_lang = None
immediate_name = "qmake_" + r
qrc_output += write_add_qt_resource_call(target, immediate_name, immediate_prefix, immediate_base, immediate_lang, immediate_files, skip_qtquick_compiler)
qrc_output += write_add_qt_resource_call(target, immediate_name, immediate_prefix, immediate_base, immediate_lang,
immediate_files, skip_qtquick_compiler, retain_qtquick_compiler)
else:
# stadalone source file properties need to be set as they
# are parsed.
if skip_qtquick_compiler:
output += 'set_source_files_properties("{}" PROPERTIES QT_SKIP_QUICKCOMPILER 1)\n\n'.format(r)
if retain_qtquick_compiler:
output += 'set_source_files_properties("{}" PROPERTIES QT_RETAIN_QUICKCOMPILER 1)\n\n'.format(r)
standalone_files.append(r)
if standalone_files:
@ -1717,7 +1731,8 @@ def write_resources(cm_fh: typing.IO[str], target: str, scope: Scope, indent: in
lang = None
files = {f:"" for f in standalone_files}
skip_qtquick_compiler = False
qrc_output += write_add_qt_resource_call(target, name, prefix, base, lang, files, skip_qtquick_compiler)
qrc_output += write_add_qt_resource_call(target, name, prefix, base, lang, files,
skip_qtquick_compiler = False, retain_qtquick_compiler = False)
if qrc_output: