summaryrefslogtreecommitdiff
path: root/lib/spack/spack/schema/spec.py
blob: 8d2390b2f3e958452a6ae3ae1afc76ed8774cf1d (plain) (blame)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

"""Schema for a spec found in spec descriptor or database index.json files

TODO: This needs to be updated? Especially the hashes under properties.

.. literalinclude:: _spack_root/lib/spack/spack/schema/spec.py
   :lines: 13-
"""


target = {
    "oneOf": [
        {"type": "string"},
        {
            "type": "object",
            "additionalProperties": False,
            "required": ["name", "vendor", "features", "generation", "parents"],
            "properties": {
                "name": {"type": "string"},
                "vendor": {"type": "string"},
                "features": {"type": "array", "items": {"type": "string"}},
                "generation": {"type": "integer"},
                "parents": {"type": "array", "items": {"type": "string"}},
            },
        },
    ]
}

arch = {
    "type": "object",
    "additionalProperties": False,
    "properties": {"platform": {}, "platform_os": {}, "target": target},
}

dependencies = {
    "type": "object",
    "patternProperties": {
        r"\w[\w-]*": {  # package name
            "type": "object",
            "properties": {
                "hash": {"type": "string"},
                "type": {"type": "array", "items": {"type": "string"}},
            },
        }
    },
}

build_spec = {
    "type": "object",
    "additionalProperties": False,
    "required": ["name", "hash"],
    "properties": {"name": {"type": "string"}, "hash": {"type": "string"}},
}

#: Properties for inclusion in other schemas
properties = {
    "spec": {
        "type": "object",
        "additionalProperties": False,
        "required": ["_meta", "nodes"],
        "properties": {
            "_meta": {"type": "object", "properties": {"version": {"type": "number"}}},
            "nodes": {
                "type": "array",
                "items": {
                    "type": "object",
                    "additionalProperties": False,
                    "required": ["version", "arch", "compiler", "namespace", "parameters"],
                    "properties": {
                        "name": {"type": "string"},
                        "hash": {"type": "string"},
                        "package_hash": {"type": "string"},
                        # these hashes were used on some specs prior to 0.18
                        "full_hash": {"type": "string"},
                        "build_hash": {"type": "string"},
                        "version": {"oneOf": [{"type": "string"}, {"type": "number"}]},
                        "arch": arch,
                        "compiler": {
                            "type": "object",
                            "additionalProperties": False,
                            "properties": {
                                "name": {"type": "string"},
                                "version": {"type": "string"},
                            },
                        },
                        "develop": {"anyOf": [{"type": "boolean"}, {"type": "string"}]},
                        "namespace": {"type": "string"},
                        "parameters": {
                            "type": "object",
                            "required": [
                                "cflags",
                                "cppflags",
                                "cxxflags",
                                "fflags",
                                "ldflags",
                                "ldlibs",
                            ],
                            "additionalProperties": True,
                            "properties": {
                                "patches": {"type": "array", "items": {"type": "string"}},
                                "cflags": {"type": "array", "items": {"type": "string"}},
                                "cppflags": {"type": "array", "items": {"type": "string"}},
                                "cxxflags": {"type": "array", "items": {"type": "string"}},
                                "fflags": {"type": "array", "items": {"type": "string"}},
                                "ldflags": {"type": "array", "items": {"type": "string"}},
                                "ldlib": {"type": "array", "items": {"type": "string"}},
                            },
                        },
                        "patches": {"type": "array", "items": {}},
                        "dependencies": dependencies,
                        "build_spec": build_spec,
                    },
                },
            },
        },
    }
}

#: Full schema with metadata
schema = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Spack spec schema",
    "type": "object",
    "additionalProperties": False,
    "patternProperties": properties,
}