Skip to content

Commit

Permalink
fix(ci): replace copy script with Go generator for softfloat files + …
Browse files Browse the repository at this point in the history
…make imports work with `make fmt`
  • Loading branch information
omarsy committed Jan 22, 2025
1 parent 92c41eb commit f993d9c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 37 deletions.
32 changes: 0 additions & 32 deletions gnovm/pkg/gnolang/internal/softfloat/copy.sh

This file was deleted.

80 changes: 80 additions & 0 deletions gnovm/pkg/gnolang/internal/softfloat/gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import (
"fmt"
"os"
"strings"
)

func main() {
// File paths
goroot := os.Getenv("GOROOT")
softfloatSrc := fmt.Sprintf("%s/src/runtime/softfloat64.go", goroot)
softfloatTestSrc := fmt.Sprintf("%s/src/runtime/softfloat64_test.go", goroot)
softfloatDest := "runtime_softfloat64.go"
softfloatTestDest := "runtime_softfloat64_test.go"

// Process softfloat64.go file
processFile(softfloatSrc, softfloatDest, "runtime", "softfloat")

// Process softfloat64_test.go file
processTestFile(softfloatTestSrc, softfloatTestDest)

fmt.Println("Files processed successfully.")
}

func processFile(src, dest, oldPkg, newPkg string) {
// Read source file
content, err := os.ReadFile(src)
if err != nil {
fmt.Println("Error reading source file:", err)
return
}

// Prepare header
header := "// Code generated by github.com/gnolang/gno/gnovm/pkg/gnolang/internal/softfloat/gen. DO NOT EDIT.\n// This file is copied from $GOROOT/src/runtime/softfloat64.go.\n// It is the software floating point implementation used by the Go runtime.\n\n"

// Combine header with content
newContent := header + string(content)

// Replace package name
newContent = strings.Replace(newContent, "package "+oldPkg, "package "+newPkg, 1)

// Write to destination file
err = os.WriteFile(dest, []byte(newContent), 0o644)
if err != nil {
fmt.Println("Error writing to destination file:", err)
}
}

func processTestFile(src, dest string) {
// Read source test file
content, err := os.ReadFile(src)
if err != nil {
fmt.Println("Error reading source test file:", err)
return
}

// Prepare header
header := "// Code generated by github.com/gnolang/gno/gnovm/pkg/gnolang/internal/softfloat/gen. DO NOT EDIT.\n// This file is copied from $GOROOT/src/runtime/softfloat64_test.go.\n// It is the tests for the software floating point implementation\n// used by the Go runtime.\n\n"

// Combine header with content
newContent := header + string(content)

// Replace package name and imports
newContent = strings.Replace(newContent, "package runtime_test", "package softfloat_test", 1)
newContent = strings.Replace(newContent, "\t. \"runtime\"", "\t\"runtime\"", 1)
newContent = strings.Replace(newContent, "GOARCH", "runtime.GOARCH", 1)

lines := strings.Split(newContent, "\n")

lines = append(lines[:12], append([]string{"\t. \"github.com/gnolang/gno/gnovm/pkg/gnolang/internal/softfloat\""}, lines[12:]...)...)

newContent = strings.Join(lines, "\n")

// Write to destination file
err = os.WriteFile(dest, []byte(newContent), 0o644)
if err != nil {
fmt.Println("Error writing to destination test file:", err)
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/internal/softfloat/softfloat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package softfloat

// This file mostly exports the functions from runtime_softfloat64.go

//go:generate sh copy.sh
//go:generate go run github.com/gnolang/gno/gnovm/pkg/gnolang/internal/softfloat/gen

const (
mask = 0x7FF
Expand Down

0 comments on commit f993d9c

Please sign in to comment.