Compare commits

..
14 Commits
Author SHA1 Message Date
skruecken 59584f3928 Dont remove build dir anymore
Build / Build (push) Successful in 1m20s
2025-05-19 21:51:32 +02:00
skruecken 77bcf116fb Removed creation of build dir 2025-05-19 21:51:07 +02:00
skruecken 41437f0f2f Embedded the Templates in the go binary
Build / Build (push) Successful in 1m26s
2025-05-19 21:46:38 +02:00
skruecken 1f05960ffc Reworked Gitea Actions
Build / Build (push) Successful in 1m52s
2025-05-19 21:24:23 +02:00
skruecken ae2879de41 Fixed Branchname
ProtoGen Action Runner / build (push) Failing after 56s
2025-05-19 21:21:36 +02:00
skruecken efd3916fb4 Reworked Actions Build 2025-05-19 21:20:37 +02:00
skruecken 52238f9aaf Added Workflow
ProtoGen Action Runner / build (push) Failing after 0s
2025-05-19 21:17:05 +02:00
skruecken a887d76dd9 Added build cli 2025-05-19 21:13:11 +02:00
skruecken 014186b65a Removed Default write to build dir 2025-05-19 21:11:36 +02:00
skruecken e6763a6d4b Modified Makefile with PHONY targets 2025-05-19 21:05:11 +02:00
skruecken e80cba9110 Added -i for Input File 2025-05-19 21:04:54 +02:00
skruecken ac5c660583 Added Build Script for Windows and linux 2025-05-19 21:01:26 +02:00
skruecken 853fda9814 Build Output File Select 2025-05-19 20:59:15 +02:00
skruecken aff454c277 Maintaince Utilty files 2025-05-19 20:59:01 +02:00
8 changed files with 97 additions and 18 deletions
+28
View File
@@ -0,0 +1,28 @@
name: Build
on: [push]
jobs:
Build:
runs-on: ubuntu-latest
container:
image: golang:latest
options: --network host
steps:
- run: |
apt-get update
apt-get install -y nodejs npm
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: go mod tidy
- run: make build
- run: ls -lah ${{ gitea.workspace }}
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: alox.protogen
path: ./alox.protogen
- run: echo "This job's status is ${{ job.status }}."
+2
View File
@@ -1 +1,3 @@
alox.protogen
alox.protogen.exe
build/
+10
View File
@@ -0,0 +1,10 @@
.PHONY: build build_win clean
build:
GOOS=linux go build .
build_win:
GOOS=windows go build .
clean:
rm -rf build/*
+47 -5
View File
@@ -1,7 +1,10 @@
package main
import (
"embed"
"encoding/json"
"flag"
"fmt"
"log"
"os"
@@ -11,30 +14,69 @@ import (
"github.com/knadh/koanf/providers/file"
)
//go:embed templates/*
var embeddedTemplates embed.FS
var appConfig = koanf.New(".")
func main() {
if err := appConfig.Load(file.Provider("testdata/conf.yaml"), yaml.Parser()); err != nil {
confPath := flag.String("c", "testdata/conf.yaml", "Config File")
outFileName := flag.String("o", "", "Name of the Output File")
inputFile := flag.String("i", "testdata/prot1.json", "Name of the Input File")
flag.Parse()
if err := appConfig.Load(file.Provider(*confPath), yaml.Parser()); err != nil {
log.Printf("error loading config: %v", err)
} else {
log.Printf("CONF: %v", appConfig)
}
file, _ := os.ReadFile("testdata/prot1.json")
file, err := os.ReadFile(*inputFile)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
var cfg proto.Proto
json.Unmarshal(file, &cfg)
proto.InitTemplates()
// if outFileName is set use it, if is not set set it to default value
if *outFileName != "" {
cfg.FileName = *outFileName
} else {
*outFileName = "build/proto"
}
// If filename not set in json take it from cli or default
if cfg.FileName != "" {
cfg.FileName = *outFileName
}
proto.InitTemplates(embeddedTemplates, "templates/*.tmpl")
header, err := proto.CreateCStyleHeader(&cfg)
if err != nil {
log.Printf("ERROR: %v", err)
}
log.Printf("TEMPLATE HEADER: \n%v", header)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
err = os.WriteFile(fmt.Sprintf("%s.h", *outFileName), []byte(header), 0666)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
source, err := proto.CreateCStyleSource(&cfg)
if err != nil {
log.Printf("ERROR: %v", err)
}
log.Printf("TEMPLATE SOURCE: \n%v", source)
err = os.WriteFile(fmt.Sprintf("%s.c", *outFileName), []byte(source), 0666)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
}
+7 -2
View File
@@ -3,6 +3,7 @@ package proto
import (
"bytes"
"encoding/json"
"io/fs"
"log"
"strconv"
"text/template"
@@ -34,6 +35,7 @@ type Proto struct {
ProtocolHeader ProtocolHeader `json:"protocol"`
ESP_TO_PC []ProtoMessage `json:"messages_esp_to_pc"`
PC_TO_ESP []ProtoMessage `json:"messages_pc_to_esp"`
FileName string `json:"filename,omitempty"`
}
func (h *HexByte) UnmarshalJSON(data []byte) error {
@@ -62,6 +64,7 @@ type PayloadStruct struct {
}
type CStyleData struct {
FileName string
CenumPCTOESP Cenum
CenumESPTOPC Cenum
PayloadStructs []PayloadStruct
@@ -71,13 +74,13 @@ type CStyleData struct {
var tmpl *template.Template
func InitTemplates() {
func InitTemplates(fsys fs.FS, pattern string) {
funcs := template.FuncMap{
"snake": toSnakeCase,
"isLast": isLast,
}
Ntmpl, err := template.New("all").Funcs(funcs).ParseGlob("templates/*.tmpl")
Ntmpl, err := template.New("all").Funcs(funcs).ParseFS(fsys, pattern)
if err != nil {
log.Fatalf("failed to parse templates: %v", err)
}
@@ -105,6 +108,7 @@ func CreateCStyleHeader(proto *Proto) (string, error) {
}
var data = CStyleData{
FileName: proto.FileName,
CenumPCTOESP: Cenum{
EnumName: "PC_TO_ESP_MESSAGE_IDS",
Entries: proto.PC_TO_ESP,
@@ -148,6 +152,7 @@ func CreateCStyleSource(proto *Proto) (string, error) {
}
var data = CStyleData{
FileName: proto.FileName,
CenumPCTOESP: Cenum{
EnumName: "PC_TO_ESP_MESSAGE_IDS",
Entries: proto.PC_TO_ESP,
+2 -2
View File
@@ -86,7 +86,7 @@ Each message is described as:
- [x] Hook-Funktionen
- [x] Message-Dispatcher (Switch-Case)
- [x] Send-Funktionen
- [ ] Generate Header and Source File
- [x] Generate Header and Source File
---
## To-Do
@@ -119,7 +119,7 @@ Each message is described as:
### Tooling
- [ ] CLI interface (`--input`, `--output`, `--language`, ...)
- [ ] Logging / verbose mode
- [ ] Build script / Makefile
- [x] Build script / Makefile
### Testing
- [ ] Unit tests for generator
+1 -1
View File
@@ -1,7 +1,7 @@
{{- define "cpartSource" -}}
// AUTO GENERATED DO NOT EDIT!!!
#include "uart_prot.h"
#include "{{.FileName}}.h"
#include <string.h>
// Message Dispatcher
-8
View File
@@ -1,8 +0,0 @@
# Current Work
Added ArrayLenght need to implement it everywhere in the template
in Payload struct it happend already
Need it in:
- Send Parameter
- [x] Also remove trailing "," in send parameter