diff options
author | Daniel Firth <dan.firth@codethink.co.uk> | 2016-09-16 13:32:49 +0100 |
---|---|---|
committer | Daniel Firth <dan.firth@codethink.co.uk> | 2016-09-16 13:33:37 +0100 |
commit | 33c5e79dd1af9bf18bf1eb0119a7f227a9216159 (patch) | |
tree | 3d2a8a85fd1ee3e51debd8bc00473da5c3071288 | |
parent | e0765f0ec26ed47dfaae3056333d61a3e8659b91 (diff) | |
download | ybd-lc/009.tar.gz |
Add schema validationlc/009
-rw-r--r-- | parse.py (renamed from ybd/parse.py) | 9 | ||||
-rw-r--r-- | schemas/chunk.json-schema | 116 | ||||
-rw-r--r-- | schemas/stratum.json-schema | 103 | ||||
-rw-r--r-- | schemas/system.json-schema | 63 |
4 files changed, 291 insertions, 0 deletions
@@ -1,6 +1,8 @@ import yaml import glob import sys +import jsonschema +import os def load_yaml(filename): with open(filename) as f: @@ -10,6 +12,7 @@ def load_yaml(filename): def parse_system(system): a = load_yaml(system) + jsonschema.validate(a, load_yaml(os.path.join(os.path.join(os.path.dirname(__file__), 'schemas/system.json-schema')))) for x in a['strata']: x['chunks'] = parse_stratum(x['morph'])['chunks'] del(x['morph']) @@ -17,6 +20,7 @@ def parse_system(system): def parse_stratum(stratum): a = load_yaml(stratum) + jsonschema.validate(a, load_yaml(os.path.join(os.path.join(os.path.dirname(__file__), 'schemas/stratum.json-schema')))) for x in a['chunks']: if 'morph' in x: c = load_yaml(x['morph']) @@ -24,4 +28,9 @@ def parse_stratum(stratum): x.update(c) return a +def parse_chunk(chunk): + a = load_yaml(chunk) + jsonschema.validate(a, load_yaml(os.path.join(os.path.join(os.path.dirname(__file__), 'schemas/chunk.json-schema')))) + return a + print(yaml.dump(parse_system(sys.argv[1]))) diff --git a/schemas/chunk.json-schema b/schemas/chunk.json-schema new file mode 100644 index 0000000..8de2fb5 --- /dev/null +++ b/schemas/chunk.json-schema @@ -0,0 +1,116 @@ +$schema: http://json-schema.org/draft-04/schema# +id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/chunk.json-schema + +description: | + This is a JSON-Schema description of a 'chunk' .morph file, which is part of + the Baserock definitions YAML representation format. + + This JSON-Schema file is valid for VERSION 7 of the Baserock definitions + YAML serialisation format. + + The Baserock definitions format is the recommended way of representing + Baserock definitions on disk. The actual data model is described separately. + See https://wiki.baserock.org/definitions for more information. + + This schema is represented as YAML, so that it can be edited more easily. + You may need to convert to JSON if using a JSON-Schema tool that expects + its input to be an actual string containing data serialised as JSON. + +definitions: + # Corresponds to CommandSequence in Baserock data model. + command-sequence: + type: array + items: { type: string } + + # Corresponds to DeviceNode in Baserock data model. + device-node: + type: object + required: [type, filename, gid, uid, major, minor, permissions] + properties: + type: { type: string } + filename: { type: string } + gid: { type: integer } + uid: { type: integer } + major: { type: integer } + minor: { type: integer } + permissions: { type: string } + + # Defines one or more instances of ChunkArtifact from the Baserock data model. + split-rules: + type: array + items: + type: object + + required: [artifact, include] + additionalProperties: false + + properties: + artifact: {type: string} + include: + type: array + items: + type: string + format: regex + + system-integration-commands: + type: object + patternProperties: + # The property name here should correspond to the name of the chunk's + # artifacts, probably the '-bins' artifact if you are using the normal + # splitting rules. + ^.*$: + type: object + patternProperties: + ^.*$: + $ref: "#/definitions/command-sequence" + +# Corresponds to Chunk in Baserock data model. +type: object + +additionalProperties: false +required: [ 'name', 'kind'] + +properties: + name: { type: string } + kind: { enum: [ "chunk" ] } + + description: { type: string } + + build-system: { type: string } + max-jobs: { type: integer } + + products: + $ref: "#/definitions/split-rules" + + pre-configure-commands: + $ref: "#/definitions/command-sequence" + configure-commands: + $ref: "#/definitions/command-sequence" + post-configure-commands: + $ref: "#/definitions/command-sequence" + pre-build-commands: + $ref: "#/definitions/command-sequence" + build-commands: + $ref: "#/definitions/command-sequence" + post-build-commands: + $ref: "#/definitions/command-sequence" + pre-install-commands: + $ref: "#/definitions/command-sequence" + install-commands: + $ref: "#/definitions/command-sequence" + post-install-commands: + $ref: "#/definitions/command-sequence" + pre-strip-commands: + $ref: "#/definitions/command-sequence" + strip-commands: + $ref: "#/definitions/command-sequence" + post-strip-commands: + $ref: "#/definitions/command-sequence" + + system-integration: + $ref: "#/definitions/system-integration-commands" + + devices: + type: array + items: + $ref: "#/definitions/device-node" diff --git a/schemas/stratum.json-schema b/schemas/stratum.json-schema new file mode 100644 index 0000000..209b92f --- /dev/null +++ b/schemas/stratum.json-schema @@ -0,0 +1,103 @@ +$schema: http://json-schema.org/draft-04/schema# +id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/chunk.json-schema + +description: | + This is a JSON-Schema description of a 'stratum' .morph file, which is part + of the Baserock definitions YAML representation format. + + This JSON-Schema file is valid for VERSION 7 of the Baserock definitions + YAML serialisation format. + + The Baserock definitions format is the recommended way of representing + Baserock definitions on disk. The actual data model is described separately. + See https://wiki.baserock.org/definitions for more information. + + This schema is represented as YAML, so that it can be edited more easily. + You may need to convert to JSON if using a JSON-Schema tool that expects + its input to be an actual string containing data serialised as JSON. + +definitions: + # Defines one or more instances of StratumArtifact from the Baserock data + # model. + split-rules: + type: array + items: + type: object + + required: [artifact, include] + additionalProperties: false + + properties: + artifact: {type: string} + include: + type: array + items: + type: string + format: regex + + # Corresponds to ChunkReference in Baserock data model. + chunk-reference: + type: object + + required: [ 'repo', 'ref' ] + additionalProperties: false + + properties: + name: { type: string } + morph: { type: string } + repo: { type: string } + ref: { type: string } + unpetrify-ref: { type: string } + build-mode: { type: string } + prefix: { type: string } + build-system: { type: string } + build-depends: + type: array + items: { type: string } + artifacts: + type: object + # This defines which chunk artifacts go in which stratum artifact. + # E.g. "glibc-nss: build-essential-runtime" specifies the glibc-nss + # chunk artifact should go in the build-essential-runtime stratum + # artifact. + patternProperties: + ^.*$: { type: string } + submodules: + $ref: "#/definitions/submodule-reference" + + submodule-reference: + type: object + properties: + url: { type: string } + submodules: + $ref: "#/definitions/submodule-reference" + + # This doesn't need any special treatment in the Baserock data model because + # it's a link to another stratum definition, without any extra info. + stratum-reference: + type: object + + required: [ 'morph' ] + additionalProperties: false + + properties: + morph: { type: string } + + +# Corresponds to Stratum in Baserock data model. +type: object + +required: [ 'name', 'kind', 'chunks' ] +additionalProperties: false + +properties: + name: { type: string } + kind: { enum: [ "stratum" ] } + description: { type: string } + + products: + $ref: "#/definitions/split-rules" + + chunks: + type: array + items: { $ref: "#/definitions/chunk-reference" } diff --git a/schemas/system.json-schema b/schemas/system.json-schema new file mode 100644 index 0000000..e4f2527 --- /dev/null +++ b/schemas/system.json-schema @@ -0,0 +1,63 @@ +$schema: http://json-schema.org/draft-04/schema# +id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/system.json-schema + +description: | + This is a JSON-Schema description of a 'system' .morph file, which is part of + the Baserock definitions YAML representation format. + + This JSON-Schema file is valid for VERSION 7 of the Baserock definitions + YAML serialisation format. + + The Baserock definitions format is the recommended way of representing + Baserock definitions on disk. The actual data model is described separately. + See https://wiki.baserock.org/definitions for more information. + + This schema is represented as YAML, so that it can be edited more easily. + You may need to convert to JSON if using a JSON-Schema tool that expects + its input to be an actual string containing data serialised as JSON. + +definitions: + # In the Baserock data model, this becomes a list of links to StratumArtifact + # entities. + stratum-reference: + type: object + + required: [ 'morph' ] + additionalProperties: false + + properties: + name: { type: string } + morph: { type: string } + include-mode: { type: string } + build-depends: + type: array + items: { type: string } + artifacts: + type: array + items: { type: string } + + +# Corresponds to System in Baserock data model. +system: +type: object + +required: [ 'name', 'kind', 'strata' ] +additionalProperties: false + +properties: + name: { type: string } + kind: { enum: [ "system" ] } + description: { type: string } + + # Morph and YBD will only accept certain values for 'arch' based on + # hardcoded conditions in those tools. + arch: { type: string } + + strata: + type: array + items: + $ref: "#/definitions/stratum-reference" + + configuration-extensions: + type: array + items: { type: string } |