-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ci): replace copy script with Go generator for softfloat files + …
…make imports work with `make fmt`
- Loading branch information
Showing
5 changed files
with
85 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
gnovm/pkg/gnolang/internal/softfloat/runtime_softfloat64_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters