File: cmPackageInfoReader.h

package info (click to toggle)
cmake 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,412 kB
  • sloc: ansic: 403,924; cpp: 290,826; sh: 4,091; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 98; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (111 lines) | stat: -rw-r--r-- 4,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */
#pragma once

#include "cmConfigure.h" // IWYU pragma: keep

#include <map>
#include <memory>
#include <string>
#include <vector>

#include <cm/optional>
#include <cm/string_view>

#include <cm3p/json/value.h>

#include "cmStateTypes.h"

class cmExecutionStatus;
class cmMakefile;
class cmTarget;

struct cmPackageRequirement
{
  std::string Name;
  std::string Version;
  std::vector<std::string> Components;
  std::vector<std::string> Hints;
};

/** \class cmPackageInfoReader
 * \brief Read and parse CPS files.
 *
 * This class encapsulates the functionality to read package configuration
 * files which use the Common Package Specification, and provides utilities to
 * translate the declarations therein into imported targets.
 */
class cmPackageInfoReader
{
public:
  static std::unique_ptr<cmPackageInfoReader> Read(
    std::string const& path, cmPackageInfoReader const* parent = nullptr);

  std::string GetName() const;
  cm::optional<std::string> GetVersion() const;
  cm::optional<std::string> GetCompatVersion() const;

  // NOTE: The eventual intent is for CPS to support multiple version schemas,
  // and in particular, we expect to want to support "simple", "custom", "rpm",
  // "dpkg" and "pep440". Additionally, we desire to be able to parse each of
  // these to the maximum extent possible; in particular, we want to be able
  // to decompose "simple" and "pep440" versions into components represented
  // as numeric types rather than strings, which is not possible with the "rpm"
  // and "dpkg" schemas. Therefore, we require different data structures to
  // represent different version schemas.

  struct Pep440Version
  {
    // NOTE: This structure is currently incomplete as we only support the
    // "simple" schema at this time.
    bool Simple; // "simple" can be represented as a subset of "pep440"
    std::vector<unsigned> ReleaseComponents;
    cm::optional<std::string> LocalLabel;
  };

  // FIXME: Return a sum type (e.g. {cm,std}::variant) of possible versions
  // when we support more than just the "simple" (and possibly "pep440")
  // schema(s).
  /// If the package uses the 'simple' version scheme, parse the provided
  /// version string as a numeric tuple and optional trailing string.  Returns
  /// a disengaged optional for other schemes or if no version is specified.
  cm::optional<Pep440Version> ParseVersion(
    cm::optional<std::string> const& version) const;

  std::vector<cmPackageRequirement> GetRequirements() const;
  std::vector<std::string> GetComponentNames() const;

  /// Create targets for components specified in the CPS file.
  bool ImportTargets(cmMakefile* makefile, cmExecutionStatus& status);

  /// Add configuration-specific properties for targets.
  bool ImportTargetConfigurations(cmMakefile* makefile,
                                  cmExecutionStatus& status) const;

private:
  cmPackageInfoReader() = default;

  cmTarget* AddLibraryComponent(cmMakefile* makefile,
                                cmStateEnums::TargetType type,
                                std::string const& name,
                                Json::Value const& data,
                                std::string const& package) const;

  void SetTargetProperties(cmMakefile* makefile, cmTarget* target,
                           Json::Value const& data, std::string const& package,
                           cm::string_view configuration) const;
  void SetImportProperty(cmTarget* target, cm::string_view property,
                         cm::string_view configuration,
                         Json::Value const& value) const;
  void SetMetaProperty(cmTarget* target, cm::string_view property,
                       Json::Value const& value) const;

  std::string ResolvePath(std::string path) const;

  std::string Path;
  Json::Value Data;
  std::string Prefix;

  std::map<std::string, cmTarget*> ComponentTargets;
  std::vector<std::string> DefaultConfigurations;
};