1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4 
5 #include "cmConfigure.h" // IWYU pragma: keep
6 
7 #include <set>
8 #include <string>
9 #include <vector>
10 
11 #include "cmsys/RegularExpression.hxx"
12 
13 class cmXMLElement;
14 
15 /** \class cmCTestLaunchReporter
16  * \brief Generate CTest XML output for the 'ctest --launch' tool.
17  */
18 class cmCTestLaunchReporter
19 {
20 public:
21   // Initialize the launcher from its command line.
22   cmCTestLaunchReporter();
23   ~cmCTestLaunchReporter();
24 
25   cmCTestLaunchReporter(const cmCTestLaunchReporter&) = delete;
26   cmCTestLaunchReporter& operator=(const cmCTestLaunchReporter&) = delete;
27 
28   // Methods to check the result of the real command.
29   bool IsError() const;
30 
31   // Launcher options specified before the real command.
32   std::string OptionOutput;
33   std::string OptionSource;
34   std::string OptionLanguage;
35   std::string OptionTargetName;
36   std::string OptionTargetType;
37   std::string OptionBuildDir;
38   std::string OptionFilterPrefix;
39 
40   // The real command line appearing after launcher arguments.
41   std::string CWD;
42 
43   // The real command line after response file expansion.
44   std::vector<std::string> RealArgs;
45 
46   // A hash of the real command line is unique and unlikely to collide.
47   std::string LogHash;
48   void ComputeFileNames();
49 
50   bool Passthru;
51   struct cmsysProcess_s* Process;
52   int ExitCode;
53 
54   // Temporary log files for stdout and stderr of real command.
55   std::string LogDir;
56   std::string LogOut;
57   std::string LogErr;
58 
59   // Labels associated with the build rule.
60   std::set<std::string> Labels;
61   void LoadLabels();
62   bool SourceMatches(std::string const& lhs, std::string const& rhs);
63 
64   // Regular expressions to match warnings and their exceptions.
65   std::vector<cmsys::RegularExpression> RegexWarning;
66   std::vector<cmsys::RegularExpression> RegexWarningSuppress;
67   bool Match(std::string const& line,
68              std::vector<cmsys::RegularExpression>& regexps);
69   bool MatchesFilterPrefix(std::string const& line) const;
70 
71   // Methods to generate the xml fragment.
72   void WriteXML();
73   void WriteXMLAction(cmXMLElement&) const;
74   void WriteXMLCommand(cmXMLElement&);
75   void WriteXMLResult(cmXMLElement&);
76   void WriteXMLLabels(cmXMLElement&);
77   void DumpFileToXML(cmXMLElement&, const char* tag, std::string const& fname);
78 
79   // Configuration
80   std::string SourceDir;
81 };
82