From 5a72b327fdf2cc764ed51c171bc4ae9ce10e7ed7 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Mon, 14 Nov 2022 19:21:53 +0100 Subject: [PATCH] syncqt: Use absolute paths to aliased header files in corner cases If source and build directories are located on different Windows disks, or one of them contains a symbolic link in the path, std::filesystem:relative is unable to calculate the relative path. So the generated header files contain empty entries. In this cases use the absolute file paths for include directives in the header file aliases. Fixes: QTBUG-108452 Change-Id: Iefc8f0ce2b54dcc31971d4a1944bf7fa55f8164e Reviewed-by: Alexandru Croitor Reviewed-by: Ivan Solovev Reviewed-by: Amir Masoud Abdol Reviewed-by: Qt CI Bot --- src/tools/syncqt/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tools/syncqt/main.cpp b/src/tools/syncqt/main.cpp index bbfae4bc586..24a841ba38e 100644 --- a/src/tools/syncqt/main.cpp +++ b/src/tools/syncqt/main.cpp @@ -505,6 +505,7 @@ class SyncScanner enum { Active, Stopped, IgnoreNext, Ignore } m_versionScriptGeneratorState = Active; + std::filesystem::path m_outputRootName; std::filesystem::path m_currentFile; std::string m_currentFilename; std::string m_currentFileString; @@ -521,7 +522,9 @@ public: SyncScanner(CommandLineOptions *commandLineArgs) : m_commandLineArgs(commandLineArgs), m_masterHeaderContents(MasterHeaderIncludeComparator), - m_warningMessagePreamble(WarningMessagePreamble) + m_warningMessagePreamble(WarningMessagePreamble), + m_outputRootName( + std::filesystem::weakly_canonical(m_commandLineArgs->includeDir()).root_name()) { } @@ -739,6 +742,7 @@ public: FileStamp originalStamp = std::filesystem::last_write_time(headerFile, ec); if (ec) originalStamp = FileStamp::clock::now(); + ec.clear(); bool isPrivate = m_currentFileType & PrivateHeader; bool isQpa = m_currentFileType & QpaHeader; @@ -758,8 +762,14 @@ public: std::filesystem::create_directories(outputDir); bool headerFileExists = std::filesystem::exists(headerFile); - std::string aliasedFilepath = - std::filesystem::relative(headerFile, outputDir).generic_string(); + + std::filesystem::path headerFileRootName = + std::filesystem::weakly_canonical(headerFile, ec).root_name(); + std::string aliasedFilepath = !ec && headerFileRootName == m_outputRootName + ? std::filesystem::relative(headerFile, outputDir).generic_string() + : headerFile.generic_string(); + ec.clear(); + std::string aliasPath = outputDir + '/' + m_currentFilename; // If the '-copy' argument is passed, we copy the original file to a corresponding output