diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2022-11-14 19:21:53 +0100 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2022-11-29 12:35:40 +0100 |
commit | 5a72b327fdf2cc764ed51c171bc4ae9ce10e7ed7 (patch) | |
tree | 42ebd5215caf21fa28ef859e7e32df3b276b0269 | |
parent | f6fefbc6caf2d7a8ab0b965626905efc1a32c397 (diff) |
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 <alexandru.croitor@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/tools/syncqt/main.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/tools/syncqt/main.cpp b/src/tools/syncqt/main.cpp index bbfae4bc58..24a841ba38 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 |