Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmEnvironment.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 <map>
8
#include <string>
9
#include <vector>
10
11
#include <cm/optional>
12
13
/**
14
 * Helper class to represent an environment.
15
 */
16
class cmEnvironment
17
{
18
public:
19
  /** Initialize from `NAME=VALUE` strings. */
20
  cmEnvironment(std::vector<std::string> const& env = {});
21
22
  /**
23
   * Add a single variable (or remove if no = sign) to the current
24
   * environment.
25
   */
26
  void PutEnv(std::string const& env);
27
28
  /** Remove a single variable from the current environment. */
29
  void UnPutEnv(std::string const& env);
30
31
  /**
32
   * Move the environment entries from `other` into this one, overwriting
33
   * existing variables when a key is already present. */
34
  void Update(cmEnvironment&& other);
35
36
  /** Modify the value of a variable in-place using a transform function. */
37
  template <typename F>
38
  void Modify(std::string const& name, F&& transform)
39
0
  {
40
0
    cm::optional<std::string>& val = this->Map[name];
41
0
    if (!val.has_value()) {
42
0
      val = std::string{};
43
0
    }
44
0
    transform(*val);
45
0
  }
Unexecuted instantiation: cmEnvironment.cxx:void cmEnvironment::Modify<cmEnvironmentModification::ApplyTo(cmEnvironment&)::$_0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmEnvironmentModification::ApplyTo(cmEnvironment&)::$_0&&)
Unexecuted instantiation: cmEnvironment.cxx:void cmEnvironment::Modify<cmEnvironmentModification::ApplyTo(cmEnvironment&)::$_1>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmEnvironmentModification::ApplyTo(cmEnvironment&)::$_1&&)
Unexecuted instantiation: cmEnvironment.cxx:void cmEnvironment::Modify<(anonymous namespace)::ListAppend>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::ListAppend&&)
Unexecuted instantiation: cmEnvironment.cxx:void cmEnvironment::Modify<(anonymous namespace)::ListPrepend>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::ListPrepend&&)
46
47
  std::vector<std::string> GetVariables() const;
48
49
  std::string RecordDifference(cmEnvironment const& original) const;
50
51
protected:
52
  struct EnvNameLess
53
  {
54
    bool operator()(std::string const& lhs, std::string const& rhs) const;
55
  };
56
  std::map<std::string, cm::optional<std::string>, EnvNameLess> Map;
57
};
58
59
class cmEnvironmentModification
60
{
61
public:
62
  bool Add(std::string const& envmod);
63
  bool Add(std::vector<std::string> const& envmod);
64
65
  void ApplyTo(cmEnvironment& env);
66
67
private:
68
  struct Entry
69
  {
70
    std::string Name;
71
    std::string Value;
72
    std::string Op;
73
  };
74
75
  std::vector<Entry> Entries;
76
};