Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): replace copy.sh with Go generator for softfloat files and reorganize imports in runtime_softfloat64_test.go for make fmt compatibility #3584

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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
Loading