build: decodeLinkFile (support *.lla)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,6 +8,7 @@
|
|||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
|
||||||
|
llgo_autogen.ll
|
||||||
stories*.bin
|
stories*.bin
|
||||||
.DS_Store
|
.DS_Store
|
||||||
err.log
|
err.log
|
||||||
|
|||||||
@@ -17,9 +17,11 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -220,6 +222,7 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string,
|
|||||||
file := pkg.ExportFile + ".ll"
|
file := pkg.ExportFile + ".ll"
|
||||||
os.WriteFile(file, []byte(lpkg.String()), 0644)
|
os.WriteFile(file, []byte(lpkg.String()), 0644)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +394,11 @@ func llgoRoot() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func llgoPkgLinkFile(pkgPath string) string {
|
func llgoPkgLinkFile(pkgPath string) string {
|
||||||
return filepath.Join(llgoRoot()+pkgPath[len(llgoModPath):], "llgo_autogen.ll")
|
llFile := filepath.Join(llgoRoot()+pkgPath[len(llgoModPath):], "llgo_autogen.ll")
|
||||||
|
if _, err := os.Stat(llFile); os.IsNotExist(err) {
|
||||||
|
decodeLinkFile(llFile)
|
||||||
|
}
|
||||||
|
return llFile
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -410,6 +417,25 @@ func isPkgInMod(pkgPath, modPath string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *.ll => *.lla
|
||||||
|
func decodeLinkFile(llFile string) {
|
||||||
|
zipFile := llFile + "a"
|
||||||
|
zipf, err := zip.OpenReader(zipFile)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer zipf.Close()
|
||||||
|
f, err := zipf.Open("llgo_autogen.ll")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
data, err := io.ReadAll(f)
|
||||||
|
if err == nil {
|
||||||
|
os.WriteFile(llFile, data, 0644)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user