summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/Qt6CoreMacros.cmake9
-rw-r--r--src/tools/cmake_automoc_parser/main.cpp85
2 files changed, 57 insertions, 37 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index c4d0b35120..a82cf30b36 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -1169,6 +1169,8 @@ function(qt6_extract_metatypes target)
endif()
endif()
+ set(cmake_automoc_parser_timestamp "${type_list_file}.timestamp")
+
if (NOT use_dep_files)
# When a project is configured with a Visual Studio generator, CMake's
# cmQtAutoGenInitializer::InitAutogenTarget() can take one of two code paths on how to
@@ -1198,12 +1200,15 @@ function(qt6_extract_metatypes target)
add_custom_target(${target}_automoc_json_extraction
DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
- BYPRODUCTS ${type_list_file}
+ BYPRODUCTS
+ ${type_list_file}
+ "${cmake_automoc_parser_timestamp}"
COMMAND
${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
--cmake-autogen-cache-file "${cmake_autogen_cache_file}"
--cmake-autogen-info-file "${cmake_autogen_info_file}"
--output-file-path "${type_list_file}"
+ --timestamp-file-path "${cmake_automoc_parser_timestamp}"
${multi_config_args}
COMMENT "Running AUTOMOC file extraction for target ${target}"
COMMAND_EXPAND_LISTS
@@ -1217,11 +1222,13 @@ function(qt6_extract_metatypes target)
add_custom_command(OUTPUT ${type_list_file}
DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
${cmake_autogen_timestamp_file}
+ BYPRODUCTS "${cmake_automoc_parser_timestamp}"
COMMAND
${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
--cmake-autogen-cache-file "${cmake_autogen_cache_file}"
--cmake-autogen-info-file "${cmake_autogen_info_file}"
--output-file-path "${type_list_file}"
+ --timestamp-file-path "${cmake_automoc_parser_timestamp}"
${multi_config_args}
COMMENT "Running AUTOMOC file extraction for target ${target}"
COMMAND_EXPAND_LISTS
diff --git a/src/tools/cmake_automoc_parser/main.cpp b/src/tools/cmake_automoc_parser/main.cpp
index 6d0214638e..70cfcb1b68 100644
--- a/src/tools/cmake_automoc_parser/main.cpp
+++ b/src/tools/cmake_automoc_parser/main.cpp
@@ -30,6 +30,7 @@
#include <cstdio>
#include <cstdlib>
+#include <limits>
#include <qcommandlineoption.h>
#include <qcommandlineparser.h>
@@ -46,6 +47,7 @@
#include <qset.h>
#include <qstring.h>
#include <qstack.h>
+#include <qdatastream.h>
QT_BEGIN_NAMESPACE
@@ -194,38 +196,52 @@ static bool readParseCache(ParseCacheMap &entries, const QString &parseCacheFile
return true;
}
-static bool readJsonFiles(QList<QString> &entries, const QString &filePath)
+static bool writeJsonFiles(const QList<QString> &fileList, const QString &fileListFilePath,
+ const QString &timestampFilePath)
{
-
- QFile file(filePath);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- fprintf(stderr, "Could not open: %s\n", qPrintable(filePath));
+ QFile timestampFile(timestampFilePath);
+ if (!timestampFile.open(QIODevice::ReadWrite)) {
+ fprintf(stderr, "Could not open: %s\n", qPrintable(timestampFilePath));
return false;
}
- QTextStream textStream(&file);
- QString line;
- while (textStream.readLineInto(&line)) {
- entries.push_back(line);
+ qint64 timestamp = std::numeric_limits<qint64>::min();
+ QByteArray timestampBuffer = timestampFile.readAll();
+ if (timestampBuffer.size() == sizeof(timestamp)) {
+ QDataStream istream(&timestampBuffer, QIODevice::ReadOnly);
+ istream >> timestamp;
}
- file.close();
- return true;
-}
-static bool writeJsonFiles(const QList<QString> &fileList, const QString &fileListFilePath)
-{
- QFile file(fileListFilePath);
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- fprintf(stderr, "Could not open: %s\n", qPrintable(fileListFilePath));
- return false;
+ // Check if any of the metatype json files produced by automoc is newer than the last file
+ // processed by cmake_automoc parser
+ for (const auto &jsonFile : fileList) {
+ const qint64 jsonFileLastModified =
+ QFileInfo(jsonFile).lastModified().toMSecsSinceEpoch();
+ if (jsonFileLastModified > timestamp) {
+ timestamp = jsonFileLastModified;
+ }
}
- QTextStream textStream(&file);
- for (const auto &file : fileList) {
- textStream << file << Qt::endl;
- }
+ if (timestamp != std::numeric_limits<qint64>::min() || !QFile::exists(fileListFilePath)) {
+ QFile file(fileListFilePath);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ fprintf(stderr, "Could not open: %s\n", qPrintable(fileListFilePath));
+ return false;
+ }
- file.close();
+ QTextStream textStream(&file);
+ for (const auto &jsonFile : fileList) {
+ textStream << jsonFile << Qt::endl;
+ }
+ textStream.flush();
+
+ // Update the timestamp according the newest json file timestamp.
+ timestampBuffer.clear();
+ QDataStream ostream(&timestampBuffer, QIODevice::WriteOnly);
+ ostream << timestamp;
+ timestampFile.resize(0);
+ timestampFile.write(timestampBuffer);
+ }
return true;
}
@@ -270,6 +286,13 @@ int main(int argc, char **argv)
QStringLiteral("Set this option when using CMake with a multi-config generator"));
parser.addOption(isMultiConfigOption);
+ QCommandLineOption timestampFilePathOption(QStringLiteral("timestamp-file-path"));
+ timestampFilePathOption.setDescription(
+ QStringLiteral("The path to a timestamp file that determines whether the output"
+ " file needs to be updated."));
+ timestampFilePathOption.setValueName(QStringLiteral("timestamp file"));
+ parser.addOption(timestampFilePathOption);
+
QStringList arguments = QCoreApplication::arguments();
parser.process(arguments);
@@ -378,19 +401,9 @@ int main(int argc, char **argv)
jsonFileList.sort();
// Read Previous file list (if any)
- const QString fileListFilePath = parser.value(outputFileOption);
- QList<QString> previousList;
- QFile prev_file(fileListFilePath);
-
- // Only try to open file if it exists to avoid error messages
- if (prev_file.exists()) {
- (void)readJsonFiles(previousList, fileListFilePath);
- }
-
- if (previousList != jsonFileList || !QFile(fileListFilePath).exists()) {
- if (!writeJsonFiles(jsonFileList, fileListFilePath)) {
- return EXIT_FAILURE;
- }
+ if (!writeJsonFiles(jsonFileList, parser.value(outputFileOption),
+ parser.value(timestampFilePathOption))) {
+ return EXIT_FAILURE;
}
return EXIT_SUCCESS;