Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/verify-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ jobs:
yamllint_file_or_dir: "*.yaml"
yamllint_strict: false
yamllint_comment: false

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: "Install dependencies"
run: |
python3 -m pip install --upgrade pip
python3 -m pip install PyYAML jsonschema

- name: "Verify features"
run: |
for file in features_c*.yaml; do
python3 verify_features.py "$file"
done
83 changes: 83 additions & 0 deletions features.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
$schema: "http://json-schema.org/draft-07/schema#"
title: Feature List Schema
type: object
required:
- features
properties:
features:
type: array
items:
$ref: "#/definitions/feature"
definitions:
feature:
type: object
required:
- desc
additionalProperties: false
properties:
desc:
type: string
description: "The title and / or description of the feature. Supports Markdown."
paper:
description: "One or multiple paper numbers that belong to the feature."
oneOf:
- type: string
- type: array
items:
type: string
lib:
type: boolean
default: false
description: "If true, the feature counts as a standard library feature."
support:
type: array
description: "A list of toolchains that support the feature."
items:
type: string
pattern: "^(GCC|Clang|MSVC|Xcode)( [0-9]+(\\.[0-9]+)*)?( \\((partial|hint)\\))?$"
hints:
type: array
description: "A list of hints targeting toolchains in the support list."
items:
type: object
required:
- target
- msg
additionalProperties: false
properties:
target:
type: string
description: "The toolchain that this hint targets."
msg:
type: string
description: "The reason for partial support, or the hint. Supports Markdown."
ftm:
type: array
description: "A list of feature-testing macros (FTM) for the feature."
items:
type: object
required:
- name
- value
additionalProperties: false
properties:
name:
type: string
description: "The name of the FTM."
value:
oneOf:
- type: string
- type: integer
description: "The value of the FTM."
desc:
type: string
description: "Optional description of what this FTM specifically refers to."
content:
type: string
description: "Information about the feature (e.g. a filename)."
keywords:
type: array
description: "A list of keywords to categorize the feature."
items:
type: string
1 change: 1 addition & 0 deletions features_c23.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
features:
- desc: "`static_assert` with no message"
paper: N3020
Expand Down
1 change: 1 addition & 0 deletions features_c99.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
features:
- desc: "Universal-character-names in [identifiers](https://en.cppreference.com/w/c/language/identifiers.html)"
support:
Expand Down
35 changes: 35 additions & 0 deletions verify_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import yaml
import jsonschema
import sys

def validate_yaml(schema_file, data_file):
try:
with open(schema_file, 'r') as f:
schema = yaml.safe_load(f)

with open(data_file, 'r') as f:
data = yaml.safe_load(f)

jsonschema.validate(instance=data, schema=schema)
print(f"Verification successful: {data_file}")
return True
except jsonschema.exceptions.ValidationError as e:
print(f"Verification failed: {data_file}")
print(f"Error: {e.message}")
print(f"Path: {' -> '.join(map(str, e.path))}")
return False
except Exception as e:
print(f"An error occurred: {e}")
return False

if __name__ == "__main__":
schema_path = "features.schema.yaml"

if len(sys.argv) < 2:
print("Usage: python3 verify_features.py <data_file.yaml>")
sys.exit(1)

data_path = sys.argv[1]
success = validate_yaml(schema_path, data_path)
if not success:
sys.exit(1)