v0.0.344
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m11s

This commit is contained in:
Mike Schwörer 2023-12-07 19:36:21 +01:00
parent 5dad44ad09
commit 8247fc4524
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 19 additions and 15 deletions

View File

@ -61,11 +61,15 @@ func GenerateEnumSpecs(sourceDir string, destFile string) error {
} }
} }
gocode, _, err := _generateEnumSpecs(sourceDir, destFile, oldChecksum, true) gocode, _, changed, err := _generateEnumSpecs(sourceDir, destFile, oldChecksum, true)
if err != nil { if err != nil {
return err return err
} }
if changed {
return nil
}
err = os.WriteFile(destFile, []byte(gocode), 0o755) err = os.WriteFile(destFile, []byte(gocode), 0o755)
if err != nil { if err != nil {
return err return err
@ -74,11 +78,11 @@ func GenerateEnumSpecs(sourceDir string, destFile string) error {
return nil return nil
} }
func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, gofmt bool) (string, string, error) { func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, gofmt bool) (string, string, bool, error) {
files, err := os.ReadDir(sourceDir) files, err := os.ReadDir(sourceDir)
if err != nil { if err != nil {
return "", "", err return "", "", false, err
} }
files = langext.ArrFilter(files, func(v os.DirEntry) bool { return v.Name() != path.Base(destFile) }) files = langext.ArrFilter(files, func(v os.DirEntry) bool { return v.Name() != path.Base(destFile) })
@ -90,7 +94,7 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
for _, f := range files { for _, f := range files {
content, err := os.ReadFile(path.Join(sourceDir, f.Name())) content, err := os.ReadFile(path.Join(sourceDir, f.Name()))
if err != nil { if err != nil {
return "", "", err return "", "", false, err
} }
newChecksumStr += "\n" + f.Name() + "\t" + cryptext.BytesSha256(content) newChecksumStr += "\n" + f.Name() + "\t" + cryptext.BytesSha256(content)
} }
@ -101,7 +105,7 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
fmt.Printf("[EnumGenerate] Checksum has changed ( %s -> %s ), will generate new file\n\n", oldChecksum, newChecksum) fmt.Printf("[EnumGenerate] Checksum has changed ( %s -> %s ), will generate new file\n\n", oldChecksum, newChecksum)
} else { } else {
fmt.Printf("[EnumGenerate] Checksum unchanged ( %s ), nothing to do\n", oldChecksum) fmt.Printf("[EnumGenerate] Checksum unchanged ( %s ), nothing to do\n", oldChecksum)
return "", oldChecksum, nil return "", oldChecksum, false, nil
} }
allEnums := make([]EnumDef, 0) allEnums := make([]EnumDef, 0)
@ -112,7 +116,7 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
fmt.Printf("========= %s =========\n\n", f.Name()) fmt.Printf("========= %s =========\n\n", f.Name())
fileEnums, pn, err := processEnumFile(sourceDir, path.Join(sourceDir, f.Name())) fileEnums, pn, err := processEnumFile(sourceDir, path.Join(sourceDir, f.Name()))
if err != nil { if err != nil {
return "", "", err return "", "", false, err
} }
fmt.Printf("\n") fmt.Printf("\n")
@ -125,21 +129,21 @@ func _generateEnumSpecs(sourceDir string, destFile string, oldChecksum string, g
} }
if pkgname == "" { if pkgname == "" {
return "", "", errors.New("no package name found in any file") return "", "", false, errors.New("no package name found in any file")
} }
rdata := fmtEnumOutput(newChecksum, allEnums, pkgname) rdata := fmtEnumOutput(newChecksum, allEnums, pkgname)
if !gofmt { if !gofmt {
return rdata, newChecksum, nil return rdata, newChecksum, true, nil
} }
fdata, err := format.Source([]byte(rdata)) fdata, err := format.Source([]byte(rdata))
if err != nil { if err != nil {
return "", "", err return "", "", false, err
} }
return string(fdata), newChecksum, nil return string(fdata), newChecksum, true, nil
} }
func processEnumFile(basedir string, fn string) ([]EnumDef, string, error) { func processEnumFile(basedir string, fn string) ([]EnumDef, string, error) {

View File

@ -37,10 +37,10 @@ func TestGenerateEnumSpecs(t *testing.T) {
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run() _, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
tst.AssertNoErr(t, err) tst.AssertNoErr(t, err)
s1, cs1, err := _generateEnumSpecs(tmpDir, "", "N/A", true) s1, cs1, _, err := _generateEnumSpecs(tmpDir, "", "N/A", true)
tst.AssertNoErr(t, err) tst.AssertNoErr(t, err)
s2, cs2, err := _generateEnumSpecs(tmpDir, "", "N/A", true) s2, cs2, _, err := _generateEnumSpecs(tmpDir, "", "N/A", true)
tst.AssertNoErr(t, err) tst.AssertNoErr(t, err)
tst.AssertEqual(t, cs1, cs2) tst.AssertEqual(t, cs1, cs2)
@ -76,7 +76,7 @@ func TestGenerateEnumSpecsData(t *testing.T) {
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run() _, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
tst.AssertNoErr(t, err) tst.AssertNoErr(t, err)
s1, _, err := _generateEnumSpecs(tmpDir, "", "", true) s1, _, _, err := _generateEnumSpecs(tmpDir, "", "", true)
tst.AssertNoErr(t, err) tst.AssertNoErr(t, err)
fmt.Println() fmt.Println()

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.343" const GoextVersion = "0.0.344"
const GoextVersionTimestamp = "2023-12-07T18:29:17+0100" const GoextVersionTimestamp = "2023-12-07T19:36:21+0100"