Skip to content

Commit

Permalink
New Simulation AST schema.
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Rule (VM/EMT3) <Timothy.Rule@de.bosch.com>
  • Loading branch information
timrulebosch committed Jan 8, 2025
1 parent 472b43a commit f4180a2
Show file tree
Hide file tree
Showing 9 changed files with 748 additions and 18 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ dist:
@ls -1sh $(DIST_DIR)/*.*
@ls -1sh $(PYTHON_DIST_DIR)/dist/*.*

_generate_clean:
generate_clean:
-@rm -rf $(DOC_SCHEMA_YAML_DIR)
$(MAKE) -C code/go/dse clean

generate: _generate_clean $(DOC_YAML_SCHEMAS)
generate_doc:
for d in $(DOC_YAML_SCHEMAS) ;\
do \
swagger-cli validate $$d ;\
Expand All @@ -159,8 +159,11 @@ generate: _generate_clean $(DOC_YAML_SCHEMAS)
done;
cp doc/templates/yaml/_index.md $(DOC_SCHEMA_YAML_DIR)/_index.md

generate_code:
$(MAKE) -C code/go/dse generate

generate: generate_clean generate_code $(DOC_YAML_SCHEMAS) generate_doc

test:

install:
Expand All @@ -173,4 +176,3 @@ clean:
-@rm -rf $(DIST_DIR)

.PHONY: default build fbs msgpack python dist dist_package clean $(FBS_SCHEMA_SOURCES) $(MPK_SCHEMA_SOURCES)

12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,20 @@ $ sudo apt install npm
# widdershins
$ git clone https://github.com/Mermade/widdershins.git
$ cd widdershins/
$ sudo -E npm install -g widdershins```
$ sudo -E npm install -g widdershins --before=2020-04-01

# swagger-cli
$ sudo -E npm install -g @apidevtools/swagger-cli

# oapi-codegen
$ go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest

# Audit
$ npm list -g
/usr/local/lib
├── @apidevtools/swagger-cli@4.0.4
├── nexe@3.0.0
└── widdershins@4.0.1
```


Expand Down
45 changes: 31 additions & 14 deletions code/go/dse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,44 @@
# SPDX-License-Identifier: Apache-2.0


KIND_YAML_DIR = ../../../schemas/yaml
KIND_YAML_FILES = $(shell ls $(KIND_YAML_DIR)/*.yaml)
YAML_DIR = ../../../schemas/yaml
KIND_YAML_FILES = $(shell cd $(YAML_DIR); ls *.yaml)
KIND_YAML_FILES := $(filter-out Simulation.yaml, $(KIND_YAML_FILES))
KIND_GO_FILES = $(subst .yaml,.go, $(KIND_YAML_FILES))
KIND_FILES = $(addprefix kind/, $(KIND_GO_FILES))
AST_FILES = ast/Simulation.go ast/metadata.go


.PHONY: generate
generate: clean kind
generate: clean kind ast

kind: $(KIND_YAML_FILES)

kind: $(KIND_FILES)
@echo "package kind" > kind/kind.go
kind/%.go: $(YAML_DIR)/%.yaml
@echo "$$(basename $<) --> $@"
@~/go/bin/oapi-codegen -config $(@D)/config.yaml $< > $@
@sed -i '/delete_this_line/d' $@
@sed -i '/\/\//d' $@
@sed -i '/./!d' $@
@sed -i -e 's/externalRef[[:digit:]]*\.//g' $@
@sed -i -e 's/`json:"/`yaml:"/g' $@
@go fmt $@

ast: $(AST_FILES)
@echo "package ast" > ast/ast.go
ast/%.go: $(YAML_DIR)/%.yaml
@echo "$$(basename $<) --> $@"
@~/go/bin/oapi-codegen -config $(@D)/config.yaml $< > $@
@sed -i '/delete_this_line/d' $@
@sed -i '/\/\//d' $@
@sed -i '/./!d' $@
@sed -i -e 's/externalRef[[:digit:]]*\.//g' $@
@sed -i -e 's/`json:"/`yaml:"/g' $@
@go fmt $@

.PHONY: $(KIND_YAML_FILES)
$(KIND_YAML_FILES):
@echo $$(basename $@)
@~/go/bin/oapi-codegen -config kind/config.yaml $@ > kind/$$(basename $@ .yaml).go
@sed -i '/delete_this_line/d' kind/$$(basename $@ .yaml).go
@sed -i '/\/\//d' kind/$$(basename $@ .yaml).go
@sed -i '/./!d' kind/$$(basename $@ .yaml).go
@sed -i -e 's/externalRef[[:digit:]]*\.//g' kind/$$(basename $@ .yaml).go
@sed -i -e 's/`json:"/`yaml:"/g' kind/$$(basename $@ .yaml).go
@go fmt kind/$$(basename $@ .yaml).go

.PHONY: clean
clean:
@rm -f kind/*.go
@rm -f ast/*.go
63 changes: 63 additions & 0 deletions code/go/dse/ast/Simulation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ast

import ()

const (
SimulationKindSimulation SimulationKind = "Simulation"
)

type Model struct {
Arch *string `yaml:"arch,omitempty"`
Channels []ModelChannel `yaml:"channels"`
Env *[]Var `yaml:"env,omitempty"`
Model string `yaml:"model"`
Name string `yaml:"name"`
Workflows *[]Workflow `yaml:"workflows,omitempty"`
}
type ModelChannel struct {
Alias *string `yaml:"alias,omitempty"`
Name string `yaml:"name"`
}
type Simulation struct {
Kind SimulationKind `yaml:"kind"`
Metadata *ObjectMetadata `yaml:"metadata,omitempty"`
Spec SimulationSpec `yaml:"spec"`
}
type SimulationKind string
type SimulationChannel struct {
Name string `yaml:"name"`
Networks *[]SimulationNetwork `yaml:"networks,omitempty"`
}
type SimulationNetwork struct {
MimeType string `yaml:"mime_type"`
Name string `yaml:"name"`
}
type SimulationSpec struct {
Arch string `yaml:"arch"`
Channels []SimulationChannel `yaml:"channels"`
Stacks []Stack `yaml:"stacks"`
Uses *[]Uses `yaml:"uses,omitempty"`
Vars *[]Var `yaml:"vars,omitempty"`
}
type Stack struct {
Arch *string `yaml:"arch,omitempty"`
Env *[]Var `yaml:"env,omitempty"`
Models []Model `yaml:"models"`
Name string `yaml:"name"`
Stacked *bool `yaml:"stacked,omitempty"`
}
type Uses struct {
Name string `yaml:"name"`
Path *string `yaml:"path,omitempty"`
Url string `yaml:"url"`
Version *string `yaml:"version,omitempty"`
}
type Var struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
}
type Workflow struct {
Name string `yaml:"name"`
Uses *string `yaml:"uses,omitempty"`
Vars *[]Var `yaml:"vars,omitempty"`
}
1 change: 1 addition & 0 deletions code/go/dse/ast/ast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package ast
5 changes: 5 additions & 0 deletions code/go/dse/ast/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package: ast
generate:
models: true
import-mapping:
metadata.yaml: delete_this_line
9 changes: 9 additions & 0 deletions code/go/dse/ast/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ast

type Annotations map[string]interface{}
type Labels map[string]string
type ObjectMetadata struct {
Annotations *Annotations `yaml:"annotations,omitempty"`
Labels *Labels `yaml:"labels,omitempty"`
Name *string `yaml:"name,omitempty"`
}
Loading

0 comments on commit f4180a2

Please sign in to comment.