Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4/*
5 * The tool generates deployment artifacts for the Qt builds such as:
6 * - CaMeL case header files named by public C++ symbols located in public module header files
7 * - Header file that contains the module version information, and named as <module>Vesion
8 * - LD version script if applicable
9 * - Aliases or copies of the header files sorted by the generic Qt-types: public/private/qpa
10 * and stored in the corresponding directories.
11 * Also the tool executes conformity checks on each header file if applicable, to make sure they
12 * follow rules that are relevant for their header type.
13 * The tool can be run in two modes: with either '-all' or '-headers' options specified. Depending
14 * on the selected mode, the tool either scans the filesystem to find header files or use the
15 * pre-defined list of header files.
16 */
17
18#include <algorithm>
19#include <iostream>
20#include <fstream>
21#include <string>
22#include <string_view>
23#include <cstring>
24#include <sstream>
25#include <filesystem>
26#include <unordered_map>
27#include <vector>
28#include <regex>
29#include <map>
30#include <set>
31#include <stdexcept>
32#include <array>
33
39
40// Enum contains the list of checks that can be executed on header files.
43 NamespaceChecks = 1, /* Checks if header file is wrapped with QT_<BEGIN|END>_NAMESPACE macros */
44 PrivateHeaderChecks = 2, /* Checks if the public header includes a private header */
45 IncludeChecks = 4, /* Checks if the real header file but not an alias is included */
46 WeMeantItChecks = 8, /* Checks if private header files contains 'We meant it' disclaimer */
48 /* Checks that lead to the fatal error of the sync process: */
51};
52
54
55static const std::regex GlobalHeaderRegex("^q(.*)global\\.h$");
56
57constexpr std::string_view ErrorMessagePreamble = "ERROR: ";
58constexpr std::string_view WarningMessagePreamble = "WARNING: ";
59
60// This comparator is used to sort include records in master header.
61// It's used to put q.*global.h file to the top of the list and sort all other files alphabetically.
62bool MasterHeaderIncludeComparator(const std::string &a, const std::string &b)
63{
64 std::smatch amatch;
65 std::smatch bmatch;
66
67 if (std::regex_match(a, amatch, GlobalHeaderRegex)) {
68 if (std::regex_match(b, bmatch, GlobalHeaderRegex)) {
69 return amatch[1].str().empty()
70 || (!bmatch[1].str().empty() && amatch[1].str() < bmatch[1].str());
71 }
72 return true;
73 } else if (std::regex_match(b, bmatch, GlobalHeaderRegex)) {
74 return false;
75 }
76
77 return a < b;
78};
79
80namespace utils {
81std::string asciiToLower(std::string s)
82{
83 std::transform(s.begin(), s.end(), s.begin(),
84 [](unsigned char c) { return (c >= 'A' && c <= 'Z') ? c | 0x20 : c; });
85 return s;
86}
87
88std::string asciiToUpper(std::string s)
89{
90 std::transform(s.begin(), s.end(), s.begin(),
91 [](unsigned char c) { return (c >= 'a' && c <= 'z') ? c & 0xdf : c; });
92 return s;
93}
94
95bool parseVersion(const std::string &version, int &major, int &minor)
96{
97 const size_t separatorPos = version.find('.');
98 if (separatorPos == std::string::npos || separatorPos == (version.size() - 1)
99 || separatorPos == 0)
100 return false;
101
102 try {
103 size_t pos = 0;
104 major = std::stoi(version.substr(0, separatorPos), &pos);
105 if (pos != separatorPos)
106 return false;
107
108 const size_t nextPart = separatorPos + 1;
109 pos = 0;
110 minor = std::stoi(version.substr(nextPart), &pos);
111 if (pos != (version.size() - nextPart))
112 return false;
113 } catch (const std::invalid_argument &) {
114 return false;
115 } catch (const std::out_of_range &) {
116 return false;
117 }
118
119 return true;
120}
121
123{
124 struct : public std::streambuf
125 {
126 int overflow(int c) override { return c; }
127 } buff;
128
129public:
131} DummyOutput;
132
134{
135 std::cerr << "Internal error. Please create bugreport at https://bugreports.qt.io "
136 "using 'Build tools: Other component.'"
137 << std::endl;
138}
139
140void printFilesystemError(const std::filesystem::filesystem_error &fserr, std::string_view errorMsg)
141{
142 std::cerr << errorMsg << ": " << fserr.path1() << ".\n"
143 << fserr.what() << "(" << fserr.code().value() << ")" << std::endl;
144}
145
146std::filesystem::path normilizedPath(const std::string &path)
147{
148 try {
149 auto result = std::filesystem::path(std::filesystem::weakly_canonical(path).generic_string());
150 return result;
151 } catch (const std::filesystem::filesystem_error &fserr) {
152 printFilesystemError(fserr, "Unable to normalize path");
153 throw;
154 }
155}
156
157bool createDirectories(const std::string &path, std::string_view errorMsg, bool *exists = nullptr)
158{
159 bool result = true;
160 try {
161 if (!std::filesystem::exists(path)) {
162 if (exists)
163 *exists = false;
164 std::filesystem::create_directories(path);
165 } else {
166 if (exists)
167 *exists = true;
168 }
169 } catch (const std::filesystem::filesystem_error &fserr) {
170 result = false;
171 std::cerr << errorMsg << ": " << path << ".\n"
172 << fserr.code().message() << "(" << fserr.code().value() << "):" << fserr.what()
173 << std::endl;
174 }
175 return result;
176}
177
178} // namespace utils
179
180using FileStamp = std::filesystem::file_time_type;
181
183{
184 template<typename T>
185 struct CommandLineOption
186 {
187 CommandLineOption(T *_value, bool _isOptional = false)
188 : value(_value), isOptional(_isOptional)
189 {
190 }
191
192 T *value;
193 bool isOptional;
194 };
195
196public:
197 CommandLineOptions(int argc, char *argv[]) : m_isValid(parseArguments(argc, argv)) { }
198
199 bool isValid() const { return m_isValid; }
200
201 const std::string &moduleName() const { return m_moduleName; }
202
203 const std::string &sourceDir() const { return m_sourceDir; }
204
205 const std::string &binaryDir() const { return m_binaryDir; }
206
207 const std::string &includeDir() const { return m_includeDir; }
208
209 const std::string &installIncludeDir() const { return m_installIncludeDir; }
210
211 const std::string &privateIncludeDir() const { return m_privateIncludeDir; }
212
213 const std::string &qpaIncludeDir() const { return m_qpaIncludeDir; }
214
215 const std::string &rhiIncludeDir() const { return m_rhiIncludeDir; }
216
217 const std::string &ssgIncludeDir() const { return m_ssgIncludeDir; }
218
219 const std::string &stagingDir() const { return m_stagingDir; }
220
221 const std::string &versionScriptFile() const { return m_versionScriptFile; }
222
223 const std::set<std::string> &knownModules() const { return m_knownModules; }
224
225 const std::regex &qpaHeadersRegex() const { return m_qpaHeadersRegex; }
226
227 const std::regex &rhiHeadersRegex() const { return m_rhiHeadersRegex; }
228
229 const std::regex &ssgHeadersRegex() const { return m_ssgHeadersRegex; }
230
231 const std::regex &privateHeadersRegex() const { return m_privateHeadersRegex; }
232
233 const std::regex &publicNamespaceRegex() const { return m_publicNamespaceRegex; }
234
235 const std::set<std::string> &headers() const { return m_headers; }
236
237 const std::set<std::string> &generatedHeaders() const { return m_generatedHeaders; }
238
239 bool scanAllMode() const { return m_scanAllMode; }
240
241 bool isInternal() const { return m_isInternal; }
242
243 bool isNonQtModule() const { return m_isNonQtModule; }
244
245 bool printHelpOnly() const { return m_printHelpOnly; }
246
247 bool debug() const { return m_debug; }
248
249 bool copy() const { return m_copy; }
250
251 bool minimal() const { return m_minimal; }
252
253 bool showOnly() const { return m_showOnly; }
254
255 bool warningsAreErrors() const { return m_warningsAreErrors; }
256
257 void printHelp() const
258 {
259 std::cout << "Usage: syncqt -sourceDir <dir> -binaryDir <dir> -module <module name>"
260 " -includeDir <dir> -privateIncludeDir <dir> -qpaIncludeDir <dir> -rhiIncludeDir <dir> -ssgIncludeDir <dir>"
261 " -stagingDir <dir> <-headers <header list>|-all> [-debug]"
262 " [-versionScript <path>] [-qpaHeadersFilter <regex>] [-rhiHeadersFilter <regex>]"
263 " [-knownModules <module1> <module2>... <moduleN>]"
264 " [-nonQt] [-internal] [-copy]\n"
265 ""
266 "Mandatory arguments:\n"
267 " -module Module name.\n"
268 " -headers List of header files.\n"
269 " -all In 'all' mode syncqt scans source\n"
270 " directory for public qt headers and\n"
271 " artifacts not considering CMake source\n"
272 " tree. The main use cases are the \n"
273 " generating of documentation and creating\n"
274 " API review changes.\n"
275 " -sourceDir Module source directory.\n"
276 " -binaryDir Module build directory.\n"
277 " -includeDir Module include directory where the\n"
278 " generated header files will be located.\n"
279 " -privateIncludeDir Module include directory for the\n"
280 " generated private header files.\n"
281 " -qpaIncludeDir Module include directory for the \n"
282 " generated QPA header files.\n"
283 " -rhiIncludeDir Module include directory for the \n"
284 " generated RHI header files.\n"
285 " -ssgIncludeDir Module include directory for the \n"
286 " generated SSG header files.\n"
287 " -stagingDir Temporary staging directory to collect\n"
288 " artifacts that need to be installed.\n"
289 " -knownModules list of known modules. syncqt uses the\n"
290 " list to check the #include macros\n"
291 " consistency.\n"
292 "Optional arguments:\n"
293 " -internal Indicates that the module is internal.\n"
294 " -nonQt Indicates that the module is not a Qt\n"
295 " module.\n"
296 " -privateHeadersFilter Regex that filters private header files\n"
297 " from the list of 'headers'.\n"
298 " -qpaHeadersFilter Regex that filters qpa header files from.\n"
299 " the list of 'headers'.\n"
300 " -rhiHeadersFilter Regex that filters rhi header files from.\n"
301 " the list of 'headers'.\n"
302 " -ssgHeadersFilter Regex that filters ssg files from.\n"
303 " the list of 'headers'.\n"
304 " -publicNamespaceFilter Symbols that are in the specified\n"
305 " namespace.\n"
306 " are treated as public symbols.\n"
307 " -versionScript Generate linker version script by\n"
308 " provided path.\n"
309 " -debug Enable debug output.\n"
310 " -copy Copy header files instead of creating\n"
311 " aliases.\n"
312 " -minimal Do not create CaMeL case headers for the\n"
313 " public C++ symbols.\n"
314 " -showonly Show actions, but not perform them.\n"
315 " -warningsAreErrors Treat all warnings as errors.\n"
316 " -help Print this help.\n";
317 }
318
319private:
320 template<typename T>
321 [[nodiscard]] bool checkRequiredArguments(const std::unordered_map<std::string, T> &arguments)
322 {
323 bool ret = true;
324 for (const auto &argument : arguments) {
325 if (!argument.second.isOptional
326 && (!argument.second.value || argument.second.value->size()) == 0) {
327 std::cerr << "Missing argument: " << argument.first << std::endl;
328 ret = false;
329 }
330 }
331 return ret;
332 }
333
334 [[nodiscard]] bool parseArguments(int argc, char *argv[])
335 {
336 std::string qpaHeadersFilter;
337 std::string rhiHeadersFilter;
338 std::string ssgHeadersFilter;
339 std::string privateHeadersFilter;
340 std::string publicNamespaceFilter;
341 const std::unordered_map<std::string, CommandLineOption<std::string>> stringArgumentMap = {
342 { "-module", { &m_moduleName } },
343 { "-sourceDir", { &m_sourceDir } },
344 { "-binaryDir", { &m_binaryDir } },
345 { "-installIncludeDir", { &m_installIncludeDir, true } },
346 { "-privateHeadersFilter", { &privateHeadersFilter, true } },
347 { "-qpaHeadersFilter", { &qpaHeadersFilter, true } },
348 { "-rhiHeadersFilter", { &rhiHeadersFilter, true } },
349 { "-ssgHeadersFilter", { &ssgHeadersFilter, true } },
350 { "-includeDir", { &m_includeDir } },
351 { "-privateIncludeDir", { &m_privateIncludeDir } },
352 { "-qpaIncludeDir", { &m_qpaIncludeDir } },
353 { "-rhiIncludeDir", { &m_rhiIncludeDir } },
354 { "-ssgIncludeDir", { &m_ssgIncludeDir } },
355 { "-stagingDir", { &m_stagingDir, true } },
356 { "-versionScript", { &m_versionScriptFile, true } },
357 { "-publicNamespaceFilter", { &publicNamespaceFilter, true } },
358 };
359
360 const std::unordered_map<std::string, CommandLineOption<std::set<std::string>>>
361 listArgumentMap = {
362 { "-headers", { &m_headers, true } },
363 { "-generatedHeaders", { &m_generatedHeaders, true } },
364 { "-knownModules", { &m_knownModules, true } },
365 };
366
367 const std::unordered_map<std::string, CommandLineOption<bool>> boolArgumentMap = {
368 { "-nonQt", { &m_isNonQtModule, true } }, { "-debug", { &m_debug, true } },
369 { "-help", { &m_printHelpOnly, true } },
370 { "-internal", { &m_isInternal, true } }, { "-all", { &m_scanAllMode, true } },
371 { "-copy", { &m_copy, true } }, { "-minimal", { &m_minimal, true } },
372 { "-showonly", { &m_showOnly, true } }, { "-showOnly", { &m_showOnly, true } },
373 { "-warningsAreErrors", { &m_warningsAreErrors, true } }
374 };
375
376 std::string *currentValue = nullptr;
377 std::set<std::string> *currentListValue = nullptr;
378
379 auto parseArgument = [&](const std::string &arg) -> bool {
380 if (arg[0] == '-') {
381 currentValue = nullptr;
382 currentListValue = nullptr;
383 {
384 auto it = stringArgumentMap.find(arg);
385 if (it != stringArgumentMap.end()) {
386 if (it->second.value == nullptr) {
388 return false;
389 }
390 currentValue = it->second.value;
391 return true;
392 }
393 }
394
395 {
396 auto it = boolArgumentMap.find(arg);
397 if (it != boolArgumentMap.end()) {
398 if (it->second.value == nullptr) {
400 return false;
401 }
402 *(it->second.value) = true;
403 return true;
404 }
405 }
406
407 {
408 auto it = listArgumentMap.find(arg);
409 if (it != listArgumentMap.end()) {
410 if (it->second.value == nullptr) {
412 return false;
413 }
414 currentListValue = it->second.value;
415 currentListValue->insert(""); // Indicate that argument is provided
416 return true;
417 }
418 }
419
420 std::cerr << "Unknown argument: " << arg << std::endl;
421 return false;
422 }
423
424 if (currentValue != nullptr) {
425 *currentValue = arg;
426 currentValue = nullptr;
427 } else if (currentListValue != nullptr) {
428 currentListValue->insert(arg);
429 } else {
430 std::cerr << "Unknown argument: " << arg << std::endl;
431 return false;
432 }
433 return true;
434 };
435
436 for (int i = 1; i < argc; ++i) {
437 std::string arg(argv[i]);
438 if (arg.empty())
439 continue;
440
441 if (arg[0] == '@') {
442 std::ifstream ifs(arg.substr(1), std::ifstream::in);
443 if (!ifs.is_open()) {
444 std::cerr << "Unable to open rsp file: " << arg[0] << std::endl;
445 return false;
446 }
447 std::string argFromFile;
448 while (std::getline(ifs, argFromFile)) {
449 if (argFromFile.empty())
450 continue;
451 if (!parseArgument(argFromFile))
452 return false;
453 }
454 ifs.close();
455 continue;
456 }
457
458 if (!parseArgument(arg))
459 return false;
460 }
461
462 if (m_printHelpOnly)
463 return true;
464
465 if (!qpaHeadersFilter.empty())
466 m_qpaHeadersRegex = std::regex(qpaHeadersFilter);
467
468 if (!rhiHeadersFilter.empty())
469 m_rhiHeadersRegex = std::regex(rhiHeadersFilter);
470
471 if (!ssgHeadersFilter.empty())
472 m_ssgHeadersRegex = std::regex(ssgHeadersFilter);
473
474 if (!privateHeadersFilter.empty())
475 m_privateHeadersRegex = std::regex(privateHeadersFilter);
476
477 if (!publicNamespaceFilter.empty())
478 m_publicNamespaceRegex = std::regex(publicNamespaceFilter);
479
480 if (m_headers.empty() && !m_scanAllMode) {
481 std::cerr << "You need to specify either -headers or -all option." << std::endl;
482 return false;
483 }
484
485 if (!m_headers.empty() && m_scanAllMode) {
486 std::cerr << "Both -headers and -all are specified. Need to choose only one"
487 "operational mode." << std::endl;
488 return false;
489 }
490
491 for (const auto &argument : listArgumentMap)
492 argument.second.value->erase("");
493
494 bool ret = true;
495 ret &= checkRequiredArguments(stringArgumentMap);
496 ret &= checkRequiredArguments(listArgumentMap);
497
498 normilizePaths();
499
500 return ret;
501 }
502
503 // Convert all paths from command line to a generic one.
504 void normilizePaths()
505 {
506 const std::array paths = {
507 &m_sourceDir, &m_binaryDir, &m_includeDir,
508 &m_installIncludeDir, &m_privateIncludeDir, &m_qpaIncludeDir,
509 &m_rhiIncludeDir, &m_stagingDir, &m_versionScriptFile,
510 };
511 for (auto path : paths) {
512 if (!path->empty())
513 *path = utils::normilizedPath(*path).generic_string();
514 }
515 }
516
517 std::string m_moduleName;
518 std::string m_sourceDir;
519 std::string m_binaryDir;
520 std::string m_includeDir;
521 std::string m_installIncludeDir;
522 std::string m_privateIncludeDir;
523 std::string m_qpaIncludeDir;
524 std::string m_rhiIncludeDir;
525 std::string m_ssgIncludeDir;
526 std::string m_stagingDir;
527 std::string m_versionScriptFile;
528 std::set<std::string> m_knownModules;
529 std::set<std::string> m_headers;
530 std::set<std::string> m_generatedHeaders;
531 bool m_scanAllMode = false;
532 bool m_copy = false;
533 bool m_isNonQtModule = false;
534 bool m_isInternal = false;
535 bool m_printHelpOnly = false;
536 bool m_debug = false;
537 bool m_minimal = false;
538 bool m_showOnly = false;
539 bool m_warningsAreErrors = false;
540 std::regex m_qpaHeadersRegex;
541 std::regex m_rhiHeadersRegex;
542 std::regex m_ssgHeadersRegex;
543 std::regex m_privateHeadersRegex;
544 std::regex m_publicNamespaceRegex;
545
546 bool m_isValid;
547};
548
550{
551 class SymbolDescriptor
552 {
553 public:
554 // Where the symbol comes from
555 enum SourceType {
556 Pragma = 0, // pragma qt_class is mentioned a header file
557 Declaration, // The symbol declaration inside a header file
558 MaxSourceType
559 };
560
561 void update(const std::string &file, SourceType type)
562 {
563 if (type < m_type) {
564 m_file = file;
565 m_type = type;
566 }
567 }
568
569 // The file that contains a symbol.
570 const std::string &file() const { return m_file; }
571
572 private:
573 SourceType m_type = MaxSourceType;
574 std::string m_file;
575 };
577
578 struct ParsingResult
579 {
580 std::vector<std::string> versionScriptContent;
581 std::string requireConfig;
582 bool masterInclude = true;
583 };
584
585 CommandLineOptions *m_commandLineArgs = nullptr;
586
587 std::map<std::string /* header file name */, std::string /* header feature guard name */,
588 decltype(MasterHeaderIncludeComparator) *>
589 m_masterHeaderContents;
590
591 std::unordered_map<std::string /* the deprecated header name*/,
592 std::string /* the replacement */>
593 m_deprecatedHeaders;
594 std::vector<std::string> m_versionScriptContents;
595 std::set<std::string> m_producedHeaders;
596 std::vector<std::string> m_headerCheckExceptions;
597 SymbolContainer m_symbols;
598 std::ostream &scannerDebug() const
599 {
600 if (m_commandLineArgs->debug())
601 return std::cout;
602 return utils::DummyOutput;
603 }
604
605 enum { Active, Stopped, IgnoreNext, Ignore } m_versionScriptGeneratorState = Active;
606
607 std::filesystem::path m_outputRootName;
608 std::filesystem::path m_currentFile;
609 std::string m_currentFilename;
610 std::string m_currentFileString;
611 size_t m_currentFileLineNumber = 0;
612 bool m_currentFileInSourceDir = false;
613
614 enum FileType { PublicHeader = 0, PrivateHeader = 1, QpaHeader = 2, ExportHeader = 4, RhiHeader = 8, SsgHeader = 16 };
615 unsigned int m_currentFileType = PublicHeader;
616
617 int m_criticalChecks = CriticalChecks;
618 std::string_view m_warningMessagePreamble;
619
620public:
629
630 // The function converts the relative path to a header files to the absolute. It also makes the
631 // path canonical(removes '..' and '.' parts of the path). The source directory passed in
632 // '-sourceDir' command line argument is used as base path for relative paths to create the
633 // absolute path.
634 [[nodiscard]] std::filesystem::path makeHeaderAbsolute(const std::string &filename) const;
635
637 {
638 if (m_commandLineArgs->warningsAreErrors()) {
639 m_criticalChecks = AllChecks;
640 m_warningMessagePreamble = ErrorMessagePreamble;
641 }
642
643 m_versionScriptGeneratorState =
644 m_commandLineArgs->versionScriptFile().empty() ? Stopped : Active;
645 auto error = NoError;
646
647 // In the scan all mode we ingore the list of header files that is specified in the
648 // '-headers' argument, and collect header files from the source directory tree.
649 if (m_commandLineArgs->scanAllMode()) {
650 for (auto const &entry :
651 std::filesystem::recursive_directory_iterator(m_commandLineArgs->sourceDir())) {
652
653 const bool isRegularFile = entry.is_regular_file();
654 const bool isHeaderFlag = isHeader(entry);
655 const bool isDocFileHeuristicFlag =
656 isDocFileHeuristic(entry.path().generic_string());
657 const bool shouldProcessHeader =
658 isRegularFile && isHeaderFlag && !isDocFileHeuristicFlag;
659 const std::string filePath = entry.path().generic_string();
660
661 if (shouldProcessHeader) {
662 scannerDebug() << "Processing header: " << filePath << std::endl;
663 if (!processHeader(makeHeaderAbsolute(filePath)))
664 error = SyncFailed;
665 } else {
666 scannerDebug()
667 << "Skipping processing header: " << filePath
668 << " isRegularFile: " << isRegularFile
669 << " isHeaderFlag: " << isHeaderFlag
670 << " isDocFileHeuristicFlag: " << isDocFileHeuristicFlag
671 << std::endl;
672 }
673 }
674 } else {
675 // Since the list of header file is quite big syncqt supports response files to avoid
676 // the issues with long command lines.
677 std::set<std::string> rspHeaders;
678 const auto &headers = m_commandLineArgs->headers();
679 for (auto it = headers.begin(); it != headers.end(); ++it) {
680 const auto &header = *it;
681 scannerDebug() << "Processing header: " << header << std::endl;
683 error = SyncFailed;
684 }
685 }
686 for (const auto &header : rspHeaders) {
687 scannerDebug() << "Processing header: " << header << std::endl;
688 if (!processHeader(makeHeaderAbsolute(header)))
689 error = SyncFailed;
690 }
691 }
692
693 // No further processing in minimal mode.
694 if (m_commandLineArgs->minimal())
695 return error;
696
697 // Generate aliases for all unique symbols collected during the header files parsing.
698 for (auto it = m_symbols.begin(); it != m_symbols.end(); ++it) {
699 const std::string &filename = it->second.file();
700 if (!filename.empty()) {
702 m_commandLineArgs->includeDir() + '/' + it->first, filename)) {
703 m_producedHeaders.insert(it->first);
704 } else {
705 error = SyncFailed;
706 }
707 }
708 }
709
710 // Generate the header file containing version information.
711 if (!m_commandLineArgs->isNonQtModule()) {
712 std::string moduleNameLower = utils::asciiToLower(m_commandLineArgs->moduleName());
713 std::string versionHeaderFilename(moduleNameLower + "version.h");
714 std::string versionHeaderCamel(m_commandLineArgs->moduleName() + "Version");
715 std::string versionFile = m_commandLineArgs->includeDir() + '/' + versionHeaderFilename;
716
717 std::error_code ec;
718 FileStamp originalStamp = std::filesystem::last_write_time(versionFile, ec);
719 if (ec)
720 originalStamp = FileStamp::clock::now();
721
722 if (generateVersionHeader(versionFile)) {
723 if (!generateAliasedHeaderFileIfTimestampChanged(
724 m_commandLineArgs->includeDir() + '/' + versionHeaderCamel,
725 versionFile, originalStamp)) {
726 error = SyncFailed;
727 }
728 m_masterHeaderContents[versionHeaderFilename] = {};
729 m_producedHeaders.insert(versionHeaderFilename);
730 m_producedHeaders.insert(versionHeaderCamel);
731 } else {
732 error = SyncFailed;
733 }
734 }
735
736 if (!m_commandLineArgs->scanAllMode()) {
737 if (!m_commandLineArgs->isNonQtModule()) {
739 error = SyncFailed;
740
742 error = SyncFailed;
743 }
744
745 if (!m_commandLineArgs->versionScriptFile().empty()) {
747 error = SyncFailed;
748 }
749 }
750
751 if (!m_commandLineArgs->isNonQtModule()) {
753 error = SyncFailed;
754 }
755
756 if (!m_commandLineArgs->scanAllMode() && !m_commandLineArgs->stagingDir().empty()) {
757 // Copy the generated files to a spearate staging directory to make the installation
758 // process eaiser.
760 error = SyncFailed;
761 }
762 return error;
763 }
764
765 // The function copies files, that were generated while the sync procedure to a staging
766 // directory. This is necessary to simplify the installation of the generated files.
767 [[nodiscard]] bool copyGeneratedHeadersToStagingDirectory(const std::string &outputDirectory,
768 bool skipCleanup = false)
769 {
770 bool result = true;
771 bool outDirExists = false;
772 if (!utils::createDirectories(outputDirectory, "Unable to create staging directory",
773 &outDirExists))
774 return false;
775
776 if (outDirExists && !skipCleanup) {
777 try {
778 for (const auto &entry :
779 std::filesystem::recursive_directory_iterator(outputDirectory)) {
780 if (m_producedHeaders.find(entry.path().filename().generic_string())
781 == m_producedHeaders.end()) {
782 // Check if header file came from another module as result of the
783 // cross-module deprecation before removing it.
784 std::string firstLine;
785 {
786 std::ifstream input(entry.path(), std::ifstream::in);
787 if (input.is_open()) {
788 std::getline(input, firstLine);
789 input.close();
790 }
791 }
792 if (firstLine.find("#ifndef DEPRECATED_HEADER_"
793 + m_commandLineArgs->moduleName())
794 == 0
795 || firstLine.find("#ifndef DEPRECATED_HEADER_") != 0)
796 std::filesystem::remove(entry.path());
797 }
798 }
799 } catch (const std::filesystem::filesystem_error &fserr) {
800 utils::printFilesystemError(fserr, "Unable to clean the staging directory");
801 return false;
802 }
803 }
804
805 for (const auto &header : m_producedHeaders) {
806 std::filesystem::path src(m_commandLineArgs->includeDir() + '/' + header);
807 std::filesystem::path dst(outputDirectory + '/' + header);
808 if (!m_commandLineArgs->showOnly())
809 result &= updateOrCopy(src, dst);
810 }
811 return result;
812 }
813
814 void resetCurrentFileInfoData(const std::filesystem::path &headerFile)
815 {
816 // This regex filters the generated '*exports.h' and '*exports_p.h' header files.
817 static const std::regex ExportsHeaderRegex("^q(.*)exports(_p)?\\.h$");
818
819 m_currentFile = headerFile;
820 m_currentFileLineNumber = 0;
821 m_currentFilename = m_currentFile.filename().generic_string();
822 m_currentFileType = PublicHeader;
823 m_currentFileString = m_currentFile.generic_string();
824 m_currentFileInSourceDir = m_currentFileString.find(m_commandLineArgs->sourceDir()) == 0;
825
826 if (isHeaderPrivate(m_currentFilename))
827 m_currentFileType = PrivateHeader;
828
829 if (isHeaderQpa(m_currentFilename))
830 m_currentFileType = QpaHeader | PrivateHeader;
831
832 if (isHeaderRhi(m_currentFilename))
833 m_currentFileType = RhiHeader | PrivateHeader;
834
835 if (isHeaderSsg(m_currentFilename))
836 m_currentFileType = SsgHeader | PrivateHeader;
837
838 if (std::regex_match(m_currentFilename, ExportsHeaderRegex))
839 m_currentFileType |= ExportHeader;
840 }
841
842 [[nodiscard]] bool processHeader(const std::filesystem::path &headerFile)
843 {
844 // This regex filters any paths that contain the '3rdparty' directory.
845 static const std::regex ThirdPartyFolderRegex("(^|.+/)3rdparty/.+");
846
847 // This regex filters '-config.h' and '-config_p.h' header files.
848 static const std::regex ConfigHeaderRegex("^(q|.+-)config(_p)?\\.h");
849
851 // We assume that header files ouside of the module source or build directories do not
852 // belong to the module. Skip any processing.
853 if (!m_currentFileInSourceDir
854 && m_currentFileString.find(m_commandLineArgs->binaryDir()) != 0) {
855 scannerDebug() << "Header file: " << headerFile
856 << " is outside the sync directories. Skipping." << std::endl;
857 m_headerCheckExceptions.push_back(m_currentFileString);
858 return true;
859 }
860
861 // Check if a directory is passed as argument. That shouldn't happen, print error and exit.
862 if (m_currentFilename.empty()) {
863 std::cerr << "Header file name of " << m_currentFileString << "is empty" << std::endl;
864 return false;
865 }
866
867 std::error_code ec;
868 FileStamp originalStamp = std::filesystem::last_write_time(headerFile, ec);
869 if (ec)
870 originalStamp = FileStamp::clock::now();
871 ec.clear();
872
873 bool isPrivate = m_currentFileType & PrivateHeader;
874 bool isQpa = m_currentFileType & QpaHeader;
875 bool isRhi = m_currentFileType & RhiHeader;
876 bool isSsg = m_currentFileType & SsgHeader;
877 bool isExport = m_currentFileType & ExportHeader;
878 scannerDebug()
879 << "processHeader:start: " << headerFile
880 << " m_currentFilename: " << m_currentFilename
881 << " isPrivate: " << isPrivate
882 << " isQpa: " << isQpa
883 << " isRhi: " << isRhi
884 << " isSsg: " << isSsg
885 << std::endl;
886
887 // Chose the directory where to generate the header aliases or to copy header file if
888 // the '-copy' argument is passed.
889 std::string outputDir = m_commandLineArgs->includeDir();
890 if (isQpa)
891 outputDir = m_commandLineArgs->qpaIncludeDir();
892 else if (isRhi)
893 outputDir = m_commandLineArgs->rhiIncludeDir();
894 else if (isSsg)
895 outputDir = m_commandLineArgs->ssgIncludeDir();
896 else if (isPrivate)
897 outputDir = m_commandLineArgs->privateIncludeDir();
898
899 if (!utils::createDirectories(outputDir, "Unable to create output directory"))
900 return false;
901
902 bool headerFileExists = std::filesystem::exists(headerFile);
903
904 std::string aliasedFilepath = headerFile.generic_string();
905
906 std::string aliasPath = outputDir + '/' + m_currentFilename;
907
908 // If the '-copy' argument is passed, we copy the original file to a corresponding output
909 // directory otherwise we only create a header file alias that contains relative path to
910 // the original header file in the module source or build tree.
911 if (m_commandLineArgs->copy() && headerFileExists) {
912 if (!updateOrCopy(headerFile, aliasPath))
913 return false;
914 } else {
915 if (!generateAliasedHeaderFileIfTimestampChanged(aliasPath, aliasedFilepath,
916 originalStamp))
917 return false;
918 }
919
920 // No further processing in minimal mode.
921 if (m_commandLineArgs->minimal())
922 return true;
923
924 // Stop processing if header files doesn't exist. This happens at configure time, since
925 // either header files are generated later than syncqt is running or header files only
926 // generated at build time. These files will be processed at build time, if CMake files
927 // contain the correct dependencies between the missing header files and the module
928 // 'sync_headers' targets.
929 if (!headerFileExists) {
930 scannerDebug() << "Header file: " << headerFile
931 << " doesn't exist, but is added to syncqt scanning. Skipping.";
932 return true;
933 }
934
935 bool isGenerated = isHeaderGenerated(m_currentFileString);
936
937 // Make sure that we detect the '3rdparty' directory inside the source directory only,
938 // since full path to the Qt sources might contain '/3rdparty/' too.
939 bool is3rdParty = std::regex_match(
940 std::filesystem::relative(headerFile, m_commandLineArgs->sourceDir())
941 .generic_string(),
942 ThirdPartyFolderRegex);
943
944 // No processing of generated Qt config header files.
945 if (!std::regex_match(m_currentFilename, ConfigHeaderRegex)) {
946 unsigned int skipChecks = m_commandLineArgs->scanAllMode() ? AllChecks : NoChecks;
947
948 // Collect checks that should skipped for the header file.
949 if (m_commandLineArgs->isNonQtModule() || is3rdParty || isQpa || isRhi || isSsg
950 || !m_currentFileInSourceDir || isGenerated) {
951 skipChecks = AllChecks;
952 } else {
953 if (std::regex_match(m_currentFilename, GlobalHeaderRegex) || isExport)
954 skipChecks |= NamespaceChecks;
955
956 if (isHeaderPCH(m_currentFilename))
957 skipChecks |= WeMeantItChecks;
958
959 if (isPrivate) {
960 skipChecks |= NamespaceChecks;
961 skipChecks |= PrivateHeaderChecks;
962 skipChecks |= IncludeChecks;
963 } else {
964 skipChecks |= WeMeantItChecks;
965 }
966 }
967
968 ParsingResult parsingResult;
969 parsingResult.masterInclude = m_currentFileInSourceDir && !isExport && !is3rdParty
970 && !isQpa && !isRhi && !isSsg && !isPrivate && !isGenerated;
971 if (!parseHeader(headerFile, parsingResult, skipChecks)) {
972 scannerDebug() << "parseHeader failed: " << headerFile << std::endl;
973 return false;
974 }
975
976 // Record the private header file inside the version script content.
977 if (isPrivate && !m_commandLineArgs->versionScriptFile().empty()
978 && !parsingResult.versionScriptContent.empty()) {
979 m_versionScriptContents.insert(m_versionScriptContents.end(),
980 parsingResult.versionScriptContent.begin(),
981 parsingResult.versionScriptContent.end());
982 }
983
984 // Add the '#if QT_CONFIG(<feature>)' check for header files that supposed to be
985 // included into the module master header only if corresponding feature is enabled.
986 bool willBeInModuleMasterHeader = false;
987 if (!isQpa && !isRhi && !isSsg && !isPrivate) {
988 if (m_currentFilename.find('_') == std::string::npos
989 && parsingResult.masterInclude) {
990 m_masterHeaderContents[m_currentFilename] = parsingResult.requireConfig;
991 willBeInModuleMasterHeader = true;
992 }
993 }
994
995 scannerDebug()
996 << "processHeader:end: " << headerFile
997 << " is3rdParty: " << is3rdParty
998 << " isGenerated: " << isGenerated
999 << " m_currentFileInSourceDir: " << m_currentFileInSourceDir
1000 << " willBeInModuleMasterHeader: " << willBeInModuleMasterHeader
1001 << std::endl;
1002 } else if (m_currentFilename == "qconfig.h") {
1003 // Hardcode generating of QtConfig alias
1004 updateSymbolDescriptor("QtConfig", "qconfig.h", SyncScanner::SymbolDescriptor::Pragma);
1005 }
1006
1007 return true;
1008 }
1009
1010 void parseVersionScriptContent(const std::string buffer, ParsingResult &result)
1011 {
1012 // This regex looks for the symbols that needs to be placed into linker version script.
1013 static const std::regex VersionScriptSymbolRegex(
1014 "^(?:struct|class)(?:\\s+Q_\\w*_EXPORT)?\\s+([\\w:]+)[^;]*(;$)?");
1015
1016 // This regex looks for the namespaces that needs to be placed into linker version script.
1017 static const std::regex VersionScriptNamespaceRegex(
1018 "^namespace\\s+Q_\\w+_EXPORT\\s+([\\w:]+).*");
1019
1020 // This regex filters the tailing colon from the symbol name.
1021 static const std::regex TrailingColonRegex("([\\w]+):$");
1022
1023 switch (m_versionScriptGeneratorState) {
1024 case Ignore:
1025 scannerDebug() << "line ignored: " << buffer << std::endl;
1026 m_versionScriptGeneratorState = Active;
1027 return;
1028 case Stopped:
1029 return;
1030 case IgnoreNext:
1031 m_versionScriptGeneratorState = Ignore;
1032 break;
1033 case Active:
1034 break;
1035 }
1036
1037 if (buffer.empty())
1038 return;
1039
1040 std::smatch match;
1041 std::string symbol;
1042 if (std::regex_match(buffer, match, VersionScriptSymbolRegex) && match[2].str().empty())
1043 symbol = match[1].str();
1044 else if (std::regex_match(buffer, match, VersionScriptNamespaceRegex))
1045 symbol = match[1].str();
1046
1047 if (std::regex_match(symbol, match, TrailingColonRegex))
1048 symbol = match[1].str();
1049
1050 // checkLineForSymbols(buffer, symbol);
1051 if (!symbol.empty() && symbol[symbol.size() - 1] != ';') {
1052 std::string relPath = m_currentFileInSourceDir
1053 ? std::filesystem::relative(m_currentFile, m_commandLineArgs->sourceDir())
1054 .string()
1055 : std::filesystem::relative(m_currentFile, m_commandLineArgs->binaryDir())
1056 .string();
1057
1058 std::string versionStringRecord = " *";
1059 size_t startPos = 0;
1060 size_t endPos = 0;
1061 while (endPos != std::string::npos) {
1062 endPos = symbol.find("::", startPos);
1063 size_t length = endPos != std::string::npos ? (endPos - startPos)
1064 : (symbol.size() - startPos);
1065 if (length > 0) {
1066 std::string symbolPart = symbol.substr(startPos, length);
1067 versionStringRecord += std::to_string(symbolPart.size());
1068 versionStringRecord += symbolPart;
1069 }
1070 startPos = endPos + 2;
1071 }
1072 versionStringRecord += "*;";
1073 if (versionStringRecord.size() < LinkerScriptCommentAlignment)
1074 versionStringRecord +=
1075 std::string(LinkerScriptCommentAlignment - versionStringRecord.size(), ' ');
1076 versionStringRecord += " # ";
1077 versionStringRecord += relPath;
1078 versionStringRecord += ":";
1079 versionStringRecord += std::to_string(m_currentFileLineNumber);
1080 versionStringRecord += "\n";
1081 result.versionScriptContent.push_back(versionStringRecord);
1082 }
1083 }
1084
1085 // The function parses 'headerFile' and collect artifacts that are used at generating step.
1086 // 'timeStamp' is saved in internal structures to compare it when generating files.
1087 // 'result' the function output value that stores the result of parsing.
1088 // 'skipChecks' checks that are not applicable for the header file.
1089 [[nodiscard]] bool parseHeader(const std::filesystem::path &headerFile,
1090 ParsingResult &result,
1091 unsigned int skipChecks)
1092 {
1093 if (m_commandLineArgs->showOnly())
1094 std::cout << headerFile << " [" << m_commandLineArgs->moduleName() << "]" << std::endl;
1095 // This regex checks if line contains a macro.
1096 static const std::regex MacroRegex("^\\s*#.*");
1097
1098 // The regex's bellow check line for known pragmas:
1099 //
1100 // - 'once' is not allowed in installed headers, so error out.
1101 //
1102 // - 'qt_sync_skip_header_check' avoid any header checks.
1103 //
1104 // - 'qt_sync_stop_processing' stops the header proccesing from a moment when pragma is
1105 // found. Important note: All the parsing artifacts were found before this point are
1106 // stored for further processing.
1107 //
1108 // - 'qt_sync_suspend_processing' pauses processing and skip lines inside a header until
1109 // 'qt_sync_resume_processing' is found. 'qt_sync_stop_processing' stops processing if
1110 // it's found before the 'qt_sync_resume_processing'.
1111 //
1112 // - 'qt_sync_resume_processing' resumes processing after 'qt_sync_suspend_processing'.
1113 //
1114 // - 'qt_class(<symbol>)' manually declares the 'symbol' that should be used to generate
1115 // the CaMeL case header alias.
1116 //
1117 // - 'qt_deprecates([module/]<deprecated header file>[,<major.minor>])' indicates that
1118 // this header file replaces the 'deprecated header file'. syncqt will create the
1119 // deprecated header file' with the special deprecation content. Pragma optionally
1120 // accepts the Qt version where file should be removed. If the current Qt version is
1121 // higher than the deprecation version, syncqt displays deprecation warning and skips
1122 // generating the deprecated header. If the module is specified and is different from
1123 // the one this header file belongs to, syncqt attempts to generate header files
1124 // for the specified module. Cross-module deprecation only works within the same repo.
1125 // See the 'generateDeprecatedHeaders' function for details.
1126 //
1127 // - 'qt_no_master_include' indicates that syncqt should avoid including this header
1128 // files into the module master header file.
1129 static const std::regex OnceRegex(R"(^#\s*pragma\s+once$)");
1130 static const std::regex SkipHeaderCheckRegex("^#\\s*pragma qt_sync_skip_header_check$");
1131 static const std::regex StopProcessingRegex("^#\\s*pragma qt_sync_stop_processing$");
1132 static const std::regex SuspendProcessingRegex("^#\\s*pragma qt_sync_suspend_processing$");
1133 static const std::regex ResumeProcessingRegex("^#\\s*pragma qt_sync_resume_processing$");
1134 static const std::regex ExplixitClassPragmaRegex("^#\\s*pragma qt_class\\‍(([^\\‍)]+)\\‍)$");
1135 static const std::regex DeprecatesPragmaRegex("^#\\s*pragma qt_deprecates\\‍(([^\\‍)]+)\\‍)$");
1136 static const std::regex NoMasterIncludePragmaRegex("^#\\s*pragma qt_no_master_include$");
1137
1138 // This regex checks if header contains 'We mean it' disclaimer. All private headers should
1139 // contain them.
1140 static const std::string_view WeMeantItString("We mean it.");
1141
1142 // The regex's check if the content of header files is wrapped with the Qt namespace macros.
1143 static const std::regex BeginNamespaceRegex("^QT_BEGIN_NAMESPACE(_[A-Z_]+)?$");
1144 static const std::regex EndNamespaceRegex("^QT_END_NAMESPACE(_[A-Z_]+)?$");
1145
1146 // This regex checks if line contains the include macro of the following formats:
1147 // - #include <file>
1148 // - #include "file"
1149 // - # include <file>
1150 static const std::regex IncludeRegex("^#\\s*include\\s*[<\"](.+)[>\"]");
1151
1152 // This regex checks if line contains namespace definition.
1153 static const std::regex NamespaceRegex("\\s*namespace ([^ ]*)\\s+");
1154
1155 // This regex checks if line contains the Qt iterator declaration, that need to have
1156 // CaMel case header alias.
1157 static const std::regex DeclareIteratorRegex("^ *Q_DECLARE_\\w*ITERATOR\\‍((\\w+)\\‍);?$");
1158
1159 // This regex checks if header file contains the QT_REQUIRE_CONFIG call.
1160 // The macro argument is used to wrap an include of the header file inside the module master
1161 // header file with the '#if QT_CONFIG(<feature>)' guard.
1162 static const std::regex RequireConfigRegex("^ *QT_REQUIRE_CONFIG\\‍((\\w+)\\‍);?$");
1163
1164 // This regex looks for the ELFVERSION tag this is control key-word for the version script
1165 // content processing.
1166 // ELFVERSION tag accepts the following values:
1167 // - stop - stops the symbols lookup for a version script starting from this line.
1168 // - ignore-next - ignores the line followed by the current one.
1169 // - ignore - ignores the current line.
1170 static const std::regex ElfVersionTagRegex(".*ELFVERSION:(stop|ignore-next|ignore).*");
1171
1172 std::ifstream input(headerFile, std::ifstream::in);
1173 if (!input.is_open()) {
1174 std::cerr << "Unable to open " << headerFile << std::endl;
1175 return false;
1176 }
1177
1178 bool hasQtBeginNamespace = false;
1179 std::string qtBeginNamespace;
1180 std::string qtEndNamespace;
1181 bool hasWeMeantIt = false;
1182 bool isSuspended = false;
1183 bool isMultiLineComment = false;
1184 std::size_t bracesDepth = 0;
1185 std::size_t namespaceCount = 0;
1186 std::string namespaceString;
1187
1188 std::smatch match;
1189
1190 std::string buffer;
1191 std::string line;
1192 std::string tmpLine;
1193 std::size_t linesProcessed = 0;
1194 int faults = NoChecks;
1195
1196 const auto error = [&] () -> decltype(auto) {
1197 return std::cerr << ErrorMessagePreamble << m_currentFileString
1198 << ":" << m_currentFileLineNumber << " ";
1199 };
1200
1201 // Read file line by line
1202 while (std::getline(input, tmpLine)) {
1203 ++m_currentFileLineNumber;
1204 line.append(tmpLine);
1205 if (line.empty() || line.at(line.size() - 1) == '\\') {
1206 continue;
1207 }
1208 buffer.clear();
1209 buffer.reserve(line.size());
1210 // Optimize processing by looking for a special sequences such as:
1211 // - start-end of comments
1212 // - start-end of class/structures
1213 // And avoid processing of the the data inside these blocks.
1214 for (std::size_t i = 0; i < line.size(); ++i) {
1215 if (line[i] == '\r')
1216 continue;
1217 if (bracesDepth == namespaceCount) {
1218 if (line[i] == '/') {
1219 if ((i + 1) < line.size()) {
1220 if (line[i + 1] == '*') {
1221 isMultiLineComment = true;
1222 continue;
1223 } else if (line[i + 1] == '/') { // Single line comment
1224 if (!(skipChecks & WeMeantItChecks)
1225 && line.find(WeMeantItString) != std::string::npos) {
1226 hasWeMeantIt = true;
1227 continue;
1228 }
1229 if (m_versionScriptGeneratorState != Stopped
1230 && std::regex_match(line, match, ElfVersionTagRegex)) {
1231 if (match[1].str() == "ignore")
1232 m_versionScriptGeneratorState = Ignore;
1233 else if (match[1].str() == "ignore-next")
1234 m_versionScriptGeneratorState = IgnoreNext;
1235 else if (match[1].str() == "stop")
1236 m_versionScriptGeneratorState = Stopped;
1237 }
1238 break;
1239 }
1240 }
1241 } else if (line[i] == '*' && (i + 1) < line.size() && line[i + 1] == '/') {
1242 ++i;
1243 isMultiLineComment = false;
1244 continue;
1245 }
1246 }
1247
1248 if (isMultiLineComment) {
1249 if (!(skipChecks & WeMeantItChecks) &&
1250 line.find(WeMeantItString) != std::string::npos) {
1251 hasWeMeantIt = true;
1252 continue;
1253 }
1254 continue;
1255 }
1256
1257 if (line[i] == '{') {
1258 if (std::regex_match(buffer, match, NamespaceRegex)) {
1259 ++namespaceCount;
1260 namespaceString += "::";
1261 namespaceString += match[1].str();
1262 }
1263 ++bracesDepth;
1264 continue;
1265 } else if (line[i] == '}') {
1266 if (namespaceCount > 0 && bracesDepth == namespaceCount) {
1267 namespaceString.resize(namespaceString.rfind("::"));
1268 --namespaceCount;
1269 }
1270 --bracesDepth;
1271 } else if (bracesDepth == namespaceCount) {
1272 buffer += line[i];
1273 }
1274 }
1275 line.clear();
1276
1277 scannerDebug() << m_currentFilename << ": " << buffer << std::endl;
1278
1279 if (m_currentFileType & PrivateHeader) {
1280 parseVersionScriptContent(buffer, result);
1281 }
1282
1283 if (buffer.empty())
1284 continue;
1285
1286 ++linesProcessed;
1287
1288 bool skipSymbols =
1289 (m_currentFileType & PrivateHeader) || (m_currentFileType & QpaHeader) || (m_currentFileType & RhiHeader)
1290 || (m_currentFileType & SsgHeader);
1291
1292 // Parse pragmas
1293 if (std::regex_match(buffer, MacroRegex)) {
1294 if (std::regex_match(buffer, SkipHeaderCheckRegex)) {
1295 skipChecks = AllChecks;
1296 faults = NoChecks;
1297 } else if (std::regex_match(buffer, StopProcessingRegex)) {
1298 if (skipChecks == AllChecks)
1299 m_headerCheckExceptions.push_back(m_currentFileString);
1300 return true;
1301 } else if (std::regex_match(buffer, SuspendProcessingRegex)) {
1302 isSuspended = true;
1303 } else if (std::regex_match(buffer, ResumeProcessingRegex)) {
1304 isSuspended = false;
1305 } else if (std::regex_match(buffer, match, ExplixitClassPragmaRegex)) {
1306 if (!skipSymbols) {
1307 updateSymbolDescriptor(match[1].str(), m_currentFilename,
1308 SymbolDescriptor::Pragma);
1309 } else {
1310 // TODO: warn about skipping symbols that are defined explicitly
1311 }
1312 } else if (std::regex_match(buffer, NoMasterIncludePragmaRegex)) {
1313 result.masterInclude = false;
1314 } else if (std::regex_match(buffer, match, DeprecatesPragmaRegex)) {
1315 m_deprecatedHeaders[match[1].str()] =
1316 m_commandLineArgs->moduleName() + '/' + m_currentFilename;
1317 } else if (std::regex_match(buffer, OnceRegex)) {
1318 if (!(skipChecks & PragmaOnceChecks)) {
1319 faults |= PragmaOnceChecks;
1320 error() << "\"#pragma once\" is not allowed in installed header files: "
1321 "https://lists.qt-project.org/pipermail/development/2022-October/043121.html"
1322 << std::endl;
1323 }
1324 } else if (std::regex_match(buffer, match, IncludeRegex) && !isSuspended) {
1325 if (!(skipChecks & IncludeChecks)) {
1326 std::string includedHeader = match[1].str();
1327 if (!(skipChecks & PrivateHeaderChecks)
1328 && isHeaderPrivate(std::filesystem::path(includedHeader)
1329 .filename()
1330 .generic_string())) {
1331 faults |= PrivateHeaderChecks;
1332 error() << "includes private header " << includedHeader << std::endl;
1333 }
1334 for (const auto &module : m_commandLineArgs->knownModules()) {
1335 std::string suggestedHeader = "Qt" + module + '/' + includedHeader;
1336 const std::string suggestedHeaderReversePath = "/../" + suggestedHeader;
1337 if (std::filesystem::exists(m_commandLineArgs->includeDir()
1338 + suggestedHeaderReversePath)
1339 || std::filesystem::exists(m_commandLineArgs->installIncludeDir()
1340 + '/' + suggestedHeader)) {
1341 faults |= IncludeChecks;
1342 std::cerr << m_warningMessagePreamble << m_currentFileString
1343 << ":" << m_currentFileLineNumber
1344 << " includes " << includedHeader
1345 << " when it should include "
1346 << suggestedHeader << std::endl;
1347 }
1348 }
1349 }
1350 }
1351 continue;
1352 }
1353
1354 // Logic below this line is affected by the 'qt_sync_suspend_processing' and
1355 // 'qt_sync_resume_processing' pragmas.
1356 if (isSuspended)
1357 continue;
1358
1359 // Look for the symbols in header file.
1360 if (!skipSymbols) {
1361 std::string symbol;
1362 if (checkLineForSymbols(buffer, symbol)) {
1363 if (namespaceCount == 0
1364 || std::regex_match(namespaceString,
1365 m_commandLineArgs->publicNamespaceRegex())) {
1366 updateSymbolDescriptor(symbol, m_currentFilename,
1367 SymbolDescriptor::Declaration);
1368 }
1369 continue;
1370 } else if (std::regex_match(buffer, match, DeclareIteratorRegex)) {
1371 std::string iteratorSymbol = match[1].str() + "Iterator";
1372 updateSymbolDescriptor(std::string("Q") + iteratorSymbol, m_currentFilename,
1373 SymbolDescriptor::Declaration);
1374 updateSymbolDescriptor(std::string("QMutable") + iteratorSymbol,
1375 m_currentFilename, SymbolDescriptor::Declaration);
1376 continue;
1377 } else if (std::regex_match(buffer, match, RequireConfigRegex)) {
1378 result.requireConfig = match[1].str();
1379 continue;
1380 }
1381 }
1382
1383 // Check for both QT_BEGIN_NAMESPACE and QT_END_NAMESPACE macros are present in the
1384 // header file.
1385 if (!(skipChecks & NamespaceChecks)) {
1386 if (std::regex_match(buffer, match, BeginNamespaceRegex)) {
1387 qtBeginNamespace = match[1].str();
1388 hasQtBeginNamespace = true;
1389 } else if (std::regex_match(buffer, match, EndNamespaceRegex)) {
1390 qtEndNamespace = match[1].str();
1391 }
1392 }
1393 }
1394 input.close();
1395
1396 // Error out if namespace checks are failed.
1397 if (!(skipChecks & NamespaceChecks)) {
1398 if (hasQtBeginNamespace) {
1399 if (qtBeginNamespace != qtEndNamespace) {
1400 faults |= NamespaceChecks;
1401 std::cerr << m_warningMessagePreamble << m_currentFileString
1402 << " the begin namespace macro QT_BEGIN_NAMESPACE" << qtBeginNamespace
1403 << " doesn't match the end namespace macro QT_END_NAMESPACE"
1404 << qtEndNamespace << std::endl;
1405 }
1406 } else {
1407 faults |= NamespaceChecks;
1408 std::cerr << m_warningMessagePreamble << m_currentFileString
1409 << " does not include QT_BEGIN_NAMESPACE" << std::endl;
1410 }
1411 }
1412
1413 if (!(skipChecks & WeMeantItChecks) && !hasWeMeantIt) {
1414 faults |= WeMeantItChecks;
1415 std::cerr << m_warningMessagePreamble << m_currentFileString
1416 << " does not have the \"We mean it.\" warning"
1417 << std::endl;
1418 }
1419
1420 scannerDebug() << "linesTotal: " << m_currentFileLineNumber
1421 << " linesProcessed: " << linesProcessed << std::endl;
1422
1423 if (skipChecks == AllChecks)
1424 m_headerCheckExceptions.push_back(m_currentFileString);
1425
1426 // Exit with an error if any of critical checks are present.
1427 return !(faults & m_criticalChecks);
1428 }
1429
1430 // The function checks if line contains the symbol that needs to have a CaMeL-style alias.
1431 [[nodiscard]] bool checkLineForSymbols(const std::string &line, std::string &symbol)
1432 {
1433 scannerDebug() << "checkLineForSymbols: " << line << std::endl;
1434
1435 // This regex checks if line contains class or structure declaration like:
1436 // - <class|stuct> StructName
1437 // - template <> class ClassName
1438 // - class ClassName : [public|protected|private] BaseClassName
1439 // - class ClassName [QT_TEXT_STREAM_FINAL|Q_DECL_FINAL|final|sealed]
1440 // And possible combinations of the above variants.
1441 static const std::regex ClassRegex(
1442 "^ *(template *<.*> *)?(class|struct +)([^<>:]*\\s+)?" // Preceding part
1443 "((?!Q[A-Z_0-9]*_FINAL|final|sealed)Q[a-zA-Z0-9_]+)" // Actual symbol
1444 "(\\s+Q[A-Z_0-9]*_FINAL|\\s+final|\\s+sealed)?\\s*(:|$).*"); // Trailing part
1445
1446 // This regex checks if line contains function pointer typedef declaration like:
1447 // - typedef void (* QFunctionPointerType)(int, char);
1448 static const std::regex FunctionPointerRegex(
1449 "^ *typedef *.*\\‍(\\*(Q[^\\‍)]+)\\‍)\\‍(.*\\‍); *");
1450
1451 // This regex checks if line contains class or structure typedef declaration like:
1452 // - typedef AnySymbol<char> QAnySymbolType;
1453 static const std::regex TypedefRegex("^ *typedef\\s+(.*)\\s+(Q\\w+); *$");
1454
1455 std::smatch match;
1456 if (std::regex_match(line, match, FunctionPointerRegex)) {
1457 symbol = match[1].str();
1458 } else if (std::regex_match(line, match, TypedefRegex)) {
1459 symbol = match[2].str();
1460 } else if (std::regex_match(line, match, ClassRegex)) {
1461 symbol = match[4].str();
1462 } else {
1463 return false;
1464 }
1465 return !symbol.empty();
1466 }
1467
1468 [[nodiscard]] bool isHeaderQpa(const std::string &headerFileName)
1469 {
1470 return std::regex_match(headerFileName, m_commandLineArgs->qpaHeadersRegex());
1471 }
1472
1473 [[nodiscard]] bool isHeaderRhi(const std::string &headerFileName)
1474 {
1475 return std::regex_match(headerFileName, m_commandLineArgs->rhiHeadersRegex());
1476 }
1477
1478 [[nodiscard]] bool isHeaderSsg(const std::string &headerFileName)
1479 {
1480 return std::regex_match(headerFileName, m_commandLineArgs->ssgHeadersRegex());
1481 }
1482
1483 [[nodiscard]] bool isHeaderPrivate(const std::string &headerFile)
1484 {
1485 return std::regex_match(headerFile, m_commandLineArgs->privateHeadersRegex());
1486 }
1487
1488 [[nodiscard]] bool isHeaderPCH(const std::string &headerFilename)
1489 {
1490 static const std::string pchSuffix("_pch.h");
1491 return headerFilename.find(pchSuffix, headerFilename.size() - pchSuffix.size())
1492 != std::string::npos;
1493 }
1494
1495 [[nodiscard]] bool isHeader(const std::filesystem::path &path)
1496 {
1497 return path.extension().string() == ".h";
1498 }
1499
1500 [[nodiscard]] bool isDocFileHeuristic(const std::string &headerFilePath)
1501 {
1502 return headerFilePath.find("/doc/") != std::string::npos;
1503 }
1504
1505 [[nodiscard]] bool isHeaderGenerated(const std::string &header)
1506 {
1507 return m_commandLineArgs->generatedHeaders().find(header)
1508 != m_commandLineArgs->generatedHeaders().end();
1509 }
1510
1511 [[nodiscard]] bool generateQtCamelCaseFileIfContentChanged(const std::string &outputFilePath,
1512 const std::string &aliasedFilePath);
1513
1515 const std::string &outputFilePath, const std::string &aliasedFilePath,
1516 const FileStamp &originalStamp = FileStamp::clock::now());
1517
1518 bool writeIfDifferent(const std::string &outputFile, const std::string &buffer);
1519
1521 {
1522 if (m_masterHeaderContents.empty())
1523 return true;
1524
1525 std::string outputFile =
1526 m_commandLineArgs->includeDir() + '/' + m_commandLineArgs->moduleName();
1527
1528 std::string moduleUpper = utils::asciiToUpper(m_commandLineArgs->moduleName());
1529 std::stringstream buffer;
1530 buffer << "#ifndef QT_" << moduleUpper << "_MODULE_H\n"
1531 << "#define QT_" << moduleUpper << "_MODULE_H\n"
1532 << "#include <" << m_commandLineArgs->moduleName() << "/"
1533 << m_commandLineArgs->moduleName() << "Depends>\n";
1534 for (const auto &headerContents : m_masterHeaderContents) {
1535 if (!headerContents.second.empty()) {
1536 buffer << "#if QT_CONFIG(" << headerContents.second << ")\n"
1537 << "#include <" << m_commandLineArgs->moduleName() << "/"
1538 << headerContents.first << ">\n"
1539 << "#endif\n";
1540 } else {
1541 buffer << "#include <" << m_commandLineArgs->moduleName() << "/"
1542 << headerContents.first << ">\n";
1543 }
1544 }
1545 buffer << "#endif\n";
1546
1547 m_producedHeaders.insert(m_commandLineArgs->moduleName());
1548 return writeIfDifferent(outputFile, buffer.str());
1549 }
1550
1551 [[nodiscard]] bool generateVersionHeader(const std::string &outputFile)
1552 {
1553 std::string moduleNameUpper = utils::asciiToUpper( m_commandLineArgs->moduleName());
1554
1555 std::stringstream buffer;
1556 buffer << "/* This file was generated by syncqt. */\n"
1557 << "#ifndef QT_" << moduleNameUpper << "_VERSION_H\n"
1558 << "#define QT_" << moduleNameUpper << "_VERSION_H\n\n"
1559 << "#define " << moduleNameUpper << "_VERSION_STR \"" << QT_VERSION_STR << "\"\n\n"
1560 << "#define " << moduleNameUpper << "_VERSION "
1561 << "0x0" << QT_VERSION_MAJOR << "0" << QT_VERSION_MINOR << "0" << QT_VERSION_PATCH
1562 << "\n\n"
1563 << "#endif // QT_" << moduleNameUpper << "_VERSION_H\n";
1564
1565 return writeIfDifferent(outputFile, buffer.str());
1566 }
1567
1569 {
1570 static std::regex cIdentifierSymbolsRegex("[^a-zA-Z0-9_]");
1571 const std::string guard_base = "DEPRECATED_HEADER_" + m_commandLineArgs->moduleName();
1572 bool result = true;
1573 for (auto it = m_deprecatedHeaders.begin(); it != m_deprecatedHeaders.end(); ++it) {
1574 const std::string &descriptor = it->first;
1575 const std::string &replacement = it->second;
1576
1577 const auto separatorPos = descriptor.find(',');
1578 std::string headerPath = descriptor.substr(0, separatorPos);
1579 std::string versionDisclaimer;
1580 if (separatorPos != std::string::npos) {
1581 std::string version = descriptor.substr(separatorPos + 1);
1582 versionDisclaimer = " and will be removed in Qt " + version;
1583 int minor = 0;
1584 int major = 0;
1585 if (!utils::parseVersion(version, major, minor)) {
1586 std::cerr << ErrorMessagePreamble
1587 << "Invalid version format specified for the deprecated header file "
1588 << headerPath << ": '" << version
1589 << "'. Expected format: 'major.minor'.\n";
1590 result = false;
1591 continue;
1592 }
1593
1594 if (QT_VERSION_MAJOR > major
1595 || (QT_VERSION_MAJOR == major && QT_VERSION_MINOR >= minor)) {
1596 std::cerr << WarningMessagePreamble << headerPath
1597 << " is marked as deprecated and will not be generated in Qt "
1598 << QT_VERSION_STR
1599 << ". The respective qt_deprecates pragma needs to be removed.\n";
1600 continue;
1601 }
1602 }
1603
1604 const auto moduleSeparatorPos = headerPath.find('/');
1605 std::string headerName = moduleSeparatorPos != std::string::npos
1606 ? headerPath.substr(moduleSeparatorPos + 1)
1607 : headerPath;
1608 const std::string moduleName = moduleSeparatorPos != std::string::npos
1609 ? headerPath.substr(0, moduleSeparatorPos)
1610 : m_commandLineArgs->moduleName();
1611
1612 bool isCrossModuleDeprecation = moduleName != m_commandLineArgs->moduleName();
1613
1614 std::string qualifiedHeaderName =
1615 std::regex_replace(headerName, cIdentifierSymbolsRegex, "_");
1616 std::string guard = guard_base + "_" + qualifiedHeaderName;
1617 std::string warningText = "Header <" + moduleName + "/" + headerName + "> is deprecated"
1618 + versionDisclaimer + ". Please include <" + replacement + "> instead.";
1619 std::stringstream buffer;
1620 buffer << "#ifndef " << guard << "\n"
1621 << "#define " << guard << "\n"
1622 << "#if defined(__GNUC__)\n"
1623 << "# warning " << warningText << "\n"
1624 << "#elif defined(_MSC_VER)\n"
1625 << "# pragma message (\"" << warningText << "\")\n"
1626 << "#endif\n"
1627 << "#include <" << replacement << ">\n"
1628 << "#endif\n";
1629
1630 const std::string outputDir = isCrossModuleDeprecation
1631 ? m_commandLineArgs->includeDir() + "/../" + moduleName
1632 : m_commandLineArgs->includeDir();
1633 writeIfDifferent(outputDir + '/' + headerName, buffer.str());
1634
1635 // Add header file to staging installation directory for cross-module deprecation case.
1636 if (isCrossModuleDeprecation) {
1637 const std::string stagingDir = outputDir + "/.syncqt_staging/";
1638 writeIfDifferent(stagingDir + headerName, buffer.str());
1639 }
1640 m_producedHeaders.insert(headerName);
1641 }
1642 return result;
1643 }
1644
1646 {
1647 std::stringstream buffer;
1648 for (const auto &header : m_headerCheckExceptions)
1649 buffer << header << ";";
1650 return writeIfDifferent(m_commandLineArgs->binaryDir() + '/'
1651 + m_commandLineArgs->moduleName()
1652 + "_header_check_exceptions",
1653 buffer.str());
1654 }
1655
1657 {
1658 std::stringstream buffer;
1659 for (const auto &content : m_versionScriptContents)
1660 buffer << content;
1661 return writeIfDifferent(m_commandLineArgs->versionScriptFile(), buffer.str());
1662 }
1663
1664 bool updateOrCopy(const std::filesystem::path &src, const std::filesystem::path &dst) noexcept;
1665 void updateSymbolDescriptor(const std::string &symbol, const std::string &file,
1666 SymbolDescriptor::SourceType type);
1667};
1668
1669// The function updates information about the symbol:
1670// - The path and modification time of the file where the symbol was found.
1671// - The source of finding
1672// Also displays a short info about a symbol in show only mode.
1673void SyncScanner::updateSymbolDescriptor(const std::string &symbol, const std::string &file,
1674 SymbolDescriptor::SourceType type)
1675{
1676 if (m_commandLineArgs->showOnly())
1677 std::cout << " SYMBOL: " << symbol << std::endl;
1678 m_symbols[symbol].update(file, type);
1679}
1680
1681[[nodiscard]] std::filesystem::path
1682SyncScanner::makeHeaderAbsolute(const std::string &filename) const
1683{
1684 if (std::filesystem::path(filename).is_relative())
1685 return utils::normilizedPath(m_commandLineArgs->sourceDir() + '/' + filename);
1686
1687 return utils::normilizedPath(filename);
1688}
1689
1690bool SyncScanner::updateOrCopy(const std::filesystem::path &src,
1691 const std::filesystem::path &dst) noexcept
1692{
1693 if (m_commandLineArgs->showOnly())
1694 return true;
1695
1696 if (src == dst) {
1697 std::cout << "Source and destination paths are same when copying " << src.string()
1698 << ". Skipping." << std::endl;
1699 return true;
1700 }
1701
1702 std::error_code ec;
1703 std::filesystem::copy(src, dst, std::filesystem::copy_options::update_existing, ec);
1704 if (ec) {
1705 ec.clear();
1706 std::filesystem::remove(dst, ec);
1707 if (ec) {
1708 // On some file systems(e.g. vboxfs) the std::filesystem::copy doesn't support
1709 // std::filesystem::copy_options::overwrite_existing remove file first and then copy.
1710 std::cerr << "Unable to remove file: " << src << " to " << dst << " error: ("
1711 << ec.value() << ")" << ec.message() << std::endl;
1712 return false;
1713 }
1714
1715 std::filesystem::copy(src, dst, std::filesystem::copy_options::overwrite_existing, ec);
1716 if (ec) {
1717 std::cerr << "Unable to copy file: " << src << " to " << dst << " error: ("
1718 << ec.value() << ")" << ec.message() << std::endl;
1719 return false;
1720 }
1721 }
1722 return true;
1723}
1724
1725// The function generates Qt CaMeL-case files.
1726// CaMeL-case files can have timestamp that is the same as or newer than timestamp of file that
1727// supposed to included there. It's not an issue when we generate regular aliases because the
1728// content of aliases is always the same, but we only want to "touch" them when content of original
1729// is changed.
1730bool SyncScanner::generateQtCamelCaseFileIfContentChanged(const std::string &outputFilePath,
1731 const std::string &aliasedFilePath)
1732{
1733 if (m_commandLineArgs->showOnly())
1734 return true;
1735
1736 std::string buffer = "#include <";
1737 buffer += m_commandLineArgs->moduleName() + "/";
1738 buffer += aliasedFilePath;
1739 buffer += "> // IWYU pragma: export\n";
1740
1741 return writeIfDifferent(outputFilePath, buffer);
1742}
1743
1744// The function generates aliases for files in source tree. Since the content of these aliases is
1745// always same, it's ok to check only timestamp and touch files in case if stamp of original is
1746// newer than the timestamp of an alias.
1748 const std::string &aliasedFilePath,
1749 const FileStamp &originalStamp)
1750{
1751 if (m_commandLineArgs->showOnly())
1752 return true;
1753
1754 auto relativePath = std::filesystem::relative(aliasedFilePath, m_commandLineArgs->includeDir()).generic_string();
1755 const bool aliasIsInsideIncludeDir = relativePath.find("../") != 0;
1756
1757 if (std::filesystem::exists({ outputFilePath })
1758 && std::filesystem::last_write_time({ outputFilePath }) >= originalStamp) {
1759 return true;
1760 }
1761 scannerDebug() << "Rewrite " << outputFilePath << std::endl;
1762
1763 std::ofstream ofs;
1764 ofs.open(outputFilePath, std::ofstream::out | std::ofstream::trunc);
1765 if (!ofs.is_open()) {
1766 std::cerr << "Unable to write header file alias: " << outputFilePath << std::endl;
1767 return false;
1768 }
1769
1770 ofs << "#include ";
1771 if (aliasIsInsideIncludeDir)
1772 ofs << "<" << m_commandLineArgs->moduleName() + "/" << relativePath << ">";
1773 else
1774 ofs << "\"" << aliasedFilePath << "\"";
1775 ofs << " // IWYU pragma: export\n";
1776 ofs.close();
1777 return true;
1778}
1779
1780bool SyncScanner::writeIfDifferent(const std::string &outputFile, const std::string &buffer)
1781{
1782 if (m_commandLineArgs->showOnly())
1783 return true;
1784
1785 static const std::streamsize bufferSize = 1025;
1786 bool differs = false;
1787 std::filesystem::path outputFilePath(outputFile);
1788
1789 std::string outputDirectory = outputFilePath.parent_path().string();
1790
1791 if (!utils::createDirectories(outputDirectory, "Unable to create output directory"))
1792 return false;
1793
1794 auto expectedSize = buffer.size();
1795#ifdef _WINDOWS
1796 // File on disk has \r\n instead of just \n
1797 expectedSize += std::count(buffer.begin(), buffer.end(), '\n');
1798#endif
1799
1800 if (std::filesystem::exists(outputFilePath)
1801 && expectedSize == std::filesystem::file_size(outputFilePath)) {
1802 char rdBuffer[bufferSize];
1803 memset(rdBuffer, 0, bufferSize);
1804
1805 std::ifstream ifs(outputFile, std::fstream::in);
1806 if (!ifs.is_open()) {
1807 std::cerr << "Unable to open " << outputFile << " for comparison." << std::endl;
1808 return false;
1809 }
1810 std::streamsize currentPos = 0;
1811
1812 std::size_t bytesRead = 0;
1813 do {
1814 ifs.read(rdBuffer, bufferSize - 1); // Read by 1K
1815 bytesRead = ifs.gcount();
1816 if (buffer.compare(currentPos, bytesRead, rdBuffer) != 0) {
1817 differs = true;
1818 break;
1819 }
1820 currentPos += bytesRead;
1821 memset(rdBuffer, 0, bufferSize);
1822 } while (bytesRead > 0);
1823
1824 ifs.close();
1825 } else {
1826 differs = true;
1827 }
1828
1829 scannerDebug() << "Update: " << outputFile << " " << differs << std::endl;
1830 if (differs) {
1831 std::ofstream ofs;
1832 ofs.open(outputFilePath, std::fstream::out | std::ofstream::trunc);
1833 if (!ofs.is_open()) {
1834 std::cerr << "Unable to write header content to " << outputFilePath << std::endl;
1835 return false;
1836 }
1837 ofs << buffer;
1838
1839 ofs.close();
1840 }
1841 return true;
1842}
1843
1844int main(int argc, char *argv[])
1845{
1846 CommandLineOptions options(argc, argv);
1847 if (!options.isValid())
1848 return InvalidArguments;
1849
1850 if (options.printHelpOnly()) {
1851 options.printHelp();
1852 return NoError;
1853 }
1854
1855 SyncScanner scanner = SyncScanner(&options);
1856 return scanner.sync();
1857}
const std::string & rhiIncludeDir() const
Definition main.cpp:215
const std::string & privateIncludeDir() const
Definition main.cpp:211
const std::string & sourceDir() const
Definition main.cpp:203
const std::string & installIncludeDir() const
Definition main.cpp:209
bool copy() const
Definition main.cpp:249
const std::string & binaryDir() const
Definition main.cpp:205
bool minimal() const
Definition main.cpp:251
const std::string & ssgIncludeDir() const
Definition main.cpp:217
const std::set< std::string > & generatedHeaders() const
Definition main.cpp:237
bool isValid() const
Definition main.cpp:199
const std::string & moduleName() const
Definition main.cpp:201
bool isInternal() const
Definition main.cpp:241
const std::string & versionScriptFile() const
Definition main.cpp:221
const std::regex & publicNamespaceRegex() const
Definition main.cpp:233
const std::string & stagingDir() const
Definition main.cpp:219
const std::string & qpaIncludeDir() const
Definition main.cpp:213
const std::set< std::string > & knownModules() const
Definition main.cpp:223
const std::string & includeDir() const
Definition main.cpp:207
bool isNonQtModule() const
Definition main.cpp:243
bool debug() const
Definition main.cpp:247
const std::regex & qpaHeadersRegex() const
Definition main.cpp:225
void printHelp() const
Definition main.cpp:257
CommandLineOptions(int argc, char *argv[])
Definition main.cpp:197
const std::regex & ssgHeadersRegex() const
Definition main.cpp:229
const std::regex & privateHeadersRegex() const
Definition main.cpp:231
bool scanAllMode() const
Definition main.cpp:239
bool printHelpOnly() const
Definition main.cpp:245
bool warningsAreErrors() const
Definition main.cpp:255
const std::regex & rhiHeadersRegex() const
Definition main.cpp:227
bool showOnly() const
Definition main.cpp:253
const std::set< std::string > & headers() const
Definition main.cpp:235
bool generateVersionHeader(const std::string &outputFile)
Definition main.cpp:1551
bool generateLinkerVersionScript()
Definition main.cpp:1656
bool isHeaderQpa(const std::string &headerFileName)
Definition main.cpp:1468
void parseVersionScriptContent(const std::string buffer, ParsingResult &result)
Definition main.cpp:1010
bool updateOrCopy(const std::filesystem::path &src, const std::filesystem::path &dst) noexcept
Definition main.cpp:1690
bool checkLineForSymbols(const std::string &line, std::string &symbol)
Definition main.cpp:1431
void updateSymbolDescriptor(const std::string &symbol, const std::string &file, SymbolDescriptor::SourceType type)
Definition main.cpp:1673
bool isHeaderGenerated(const std::string &header)
Definition main.cpp:1505
std::filesystem::path makeHeaderAbsolute(const std::string &filename) const
Definition main.cpp:1682
bool generateMasterHeader()
Definition main.cpp:1520
bool generateAliasedHeaderFileIfTimestampChanged(const std::string &outputFilePath, const std::string &aliasedFilePath, const FileStamp &originalStamp=FileStamp::clock::now())
Definition main.cpp:1747
ErrorCodes sync()
Definition main.cpp:636
bool isHeader(const std::filesystem::path &path)
Definition main.cpp:1495
bool generateDeprecatedHeaders()
Definition main.cpp:1568
bool copyGeneratedHeadersToStagingDirectory(const std::string &outputDirectory, bool skipCleanup=false)
Definition main.cpp:767
bool writeIfDifferent(const std::string &outputFile, const std::string &buffer)
Definition main.cpp:1780
bool isHeaderRhi(const std::string &headerFileName)
Definition main.cpp:1473
bool isHeaderSsg(const std::string &headerFileName)
Definition main.cpp:1478
bool parseHeader(const std::filesystem::path &headerFile, ParsingResult &result, unsigned int skipChecks)
Definition main.cpp:1089
bool isDocFileHeuristic(const std::string &headerFilePath)
Definition main.cpp:1500
bool isHeaderPCH(const std::string &headerFilename)
Definition main.cpp:1488
bool processHeader(const std::filesystem::path &headerFile)
Definition main.cpp:842
SyncScanner(CommandLineOptions *commandLineArgs)
Definition main.cpp:621
bool generateQtCamelCaseFileIfContentChanged(const std::string &outputFilePath, const std::string &aliasedFilePath)
Definition main.cpp:1730
bool generateHeaderCheckExceptions()
Definition main.cpp:1645
void resetCurrentFileInfoData(const std::filesystem::path &headerFile)
Definition main.cpp:814
bool isHeaderPrivate(const std::string &headerFile)
Definition main.cpp:1483
Definition main.cpp:80
bool parseVersion(const std::string &version, int &major, int &minor)
Definition main.cpp:95
std::string asciiToLower(std::string s)
Definition main.cpp:81
std::filesystem::path normilizedPath(const std::string &path)
Definition main.cpp:146
void printFilesystemError(const std::filesystem::filesystem_error &fserr, std::string_view errorMsg)
Definition main.cpp:140
void printInternalError()
Definition main.cpp:133
bool createDirectories(const std::string &path, std::string_view errorMsg, bool *exists=nullptr)
Definition main.cpp:157
std::string asciiToUpper(std::string s)
Definition main.cpp:88
static const std::regex GlobalHeaderRegex("^q(.*)global\\.h$")
HeaderChecks
Definition main.cpp:41
@ AllChecks
Definition main.cpp:50
@ NamespaceChecks
Definition main.cpp:43
@ PragmaOnceChecks
Definition main.cpp:47
@ NoChecks
Definition main.cpp:42
@ WeMeantItChecks
Definition main.cpp:46
@ CriticalChecks
Definition main.cpp:49
@ IncludeChecks
Definition main.cpp:45
@ PrivateHeaderChecks
Definition main.cpp:44
ErrorCodes
Definition main.cpp:34
@ SyncFailed
Definition main.cpp:37
@ InvalidArguments
Definition main.cpp:36
@ NoError
Definition main.cpp:35
constexpr std::string_view ErrorMessagePreamble
Definition main.cpp:57
constexpr int LinkerScriptCommentAlignment
Definition main.cpp:53
constexpr std::string_view WarningMessagePreamble
Definition main.cpp:58
bool MasterHeaderIncludeComparator(const std::string &a, const std::string &b)
Definition main.cpp:62
int main(int argc, char *argv[])
[ctor_close]