Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmScriptGenerator.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <ostream>
8
#include <string>
9
#include <vector>
10
11
#include <cm/string_view>
12
13
class cmScriptGeneratorIndent
14
{
15
public:
16
0
  cmScriptGeneratorIndent() = default;
17
  cmScriptGeneratorIndent(int level)
18
0
    : Level(level)
19
0
  {
20
0
  }
21
  void Write(std::ostream& os) const
22
0
  {
23
0
    for (int i = 0; i < this->Level; ++i) {
24
0
      os << " ";
25
0
    }
26
0
  }
27
  cmScriptGeneratorIndent Next(int step = 2) const
28
0
  {
29
0
    return { this->Level + step };
30
0
  }
31
32
private:
33
  int Level = 0;
34
};
35
inline std::ostream& operator<<(std::ostream& os,
36
                                cmScriptGeneratorIndent indent)
37
0
{
38
0
  indent.Write(os);
39
0
  return os;
40
0
}
41
42
class cmScriptGeneratorQuoted
43
{
44
public:
45
  cmScriptGeneratorQuoted(cm::string_view value, int bracket_length)
46
0
    : Value(value)
47
0
    , BracketLength(bracket_length)
48
0
  {
49
0
  }
50
51
  std::string str() const;
52
0
  operator std::string() const { return str(); }
53
54
private:
55
  friend std::ostream& operator<<(std::ostream& os,
56
                                  cmScriptGeneratorQuoted const& self);
57
58
  cm::string_view Value;
59
  int BracketLength;
60
};
61
62
/** \class cmScriptGenerator
63
 * \brief Support class for generating install and test scripts.
64
 *
65
 */
66
class cmScriptGenerator
67
{
68
public:
69
  cmScriptGenerator(std::string config_var,
70
                    std::vector<std::string> configurations);
71
  virtual ~cmScriptGenerator();
72
73
  cmScriptGenerator(cmScriptGenerator const&) = delete;
74
  cmScriptGenerator& operator=(cmScriptGenerator const&) = delete;
75
76
  void Generate(std::ostream& os, std::string const& config,
77
                std::vector<std::string> const& configurationTypes);
78
79
  static cmScriptGeneratorQuoted Quote(cm::string_view value);
80
81
protected:
82
  using Indent = cmScriptGeneratorIndent;
83
  virtual void GenerateScript(std::ostream& os);
84
  virtual void GenerateScriptConfigs(std::ostream& os, Indent indent);
85
  virtual void GenerateScriptActions(std::ostream& os, Indent indent);
86
  virtual void GenerateScriptForConfig(std::ostream& os,
87
                                       std::string const& config,
88
                                       Indent indent);
89
0
  virtual void GenerateScriptNoConfig(std::ostream&, Indent) {}
90
0
  virtual bool NeedsScriptNoConfig() const { return false; }
91
92
  // Test if this generator does something for a given configuration.
93
  bool GeneratesForConfig(std::string const&);
94
95
  std::string CreateConfigTest(std::string const& config);
96
  std::string CreateConfigTest(std::vector<std::string> const& configs);
97
  std::string CreateComponentTest(std::string const& component);
98
99
  // Information shared by most generator types.
100
  std::string RuntimeConfigVariable;
101
  std::vector<std::string> const Configurations;
102
103
  // Information used during generation.
104
  std::string ConfigurationName;
105
  std::vector<std::string> const* ConfigurationTypes = nullptr;
106
107
  // True if the subclass needs to generate an explicit rule for each
108
  // configuration.  False if the subclass only generates one rule for
109
  // all enabled configurations.
110
  bool ActionsPerConfig = false;
111
112
private:
113
  void GenerateScriptActionsOnce(std::ostream& os, Indent indent);
114
  void GenerateScriptActionsPerConfig(std::ostream& os, Indent indent);
115
};