mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
Per the standing fork rule, a hanzoai fork declares its OWN module path and
is required directly -- never resolved via a `replace` against the upstream
path. Keeping the upstream path meant every import line in every consumer
carried the upstream brand.
module github.com/traefik/yaegi -> module github.com/hanzoai/yaegi
Mechanical and behaviour-neutral: every occurrence is an import path
(package self-imports, cmd/, _test/ fixtures interpreted at test time, and
the guthib.com/<org>/{fromage,cheese,vin} fake vendor trees under
example/pkg, whose directory components were renamed in lockstep with the
import strings that reference them).
GOPATH-mode source-import tests (interp TestFile) resolve the module by its
path under $GOPATH/src, so the required checkout location moves with the
module path -- as README already documents. Verified green at
$GOPATH/src/github.com/hanzoai/yaegi.
LICENSE is untouched: "Copyright 2020 Traefik Labs SAS" is the Apache-2.0
attribution and is a legal obligation, not a brand leak.
Also drops the inherited CONTRIBUTING.md CLA clause, which named an
upstream agreement this fork does not administer.
109 lines
2.3 KiB
Go
109 lines
2.3 KiB
Go
//go:generate go build
|
|
|
|
/*
|
|
extract generates wrappers of stdlib package exported symbols. This command
|
|
is reserved for internal use in yaegi project.
|
|
|
|
For a similar purpose with third party packages, see the yaegi extract subcommand,
|
|
based on the same code.
|
|
|
|
Output files are written in the current directory, and prefixed with the go version.
|
|
|
|
Usage:
|
|
|
|
extract package...
|
|
|
|
The same program is used for all target operating systems and architectures.
|
|
The GOOS and GOARCH environment variables set the desired target.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/yaegi/extract"
|
|
)
|
|
|
|
var (
|
|
exclude = flag.String("exclude", "", "comma separated list of regexp matching symbols to exclude")
|
|
include = flag.String("include", "", "comma separated list of regexp matching symbols to include")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if flag.NArg() == 0 {
|
|
flag.Usage()
|
|
log.Fatalf("missing package path")
|
|
}
|
|
|
|
wd, err := os.Getwd()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
ext := extract.Extractor{
|
|
Dest: path.Base(wd),
|
|
}
|
|
|
|
goos, goarch := os.Getenv("GOOS"), os.Getenv("GOARCH")
|
|
|
|
if *exclude != "" {
|
|
ext.Exclude = strings.Split(*exclude, ",")
|
|
}
|
|
|
|
if *include != "" {
|
|
ext.Include = strings.Split(*include, ",")
|
|
}
|
|
|
|
for _, pkgIdent := range flag.Args() {
|
|
var buf bytes.Buffer
|
|
|
|
if pkgIdent == "syscall" && goos == "solaris" {
|
|
// Syscall6 is broken on solaris (https://github.com/golang/go/issues/24357),
|
|
// it breaks build, skip related symbols.
|
|
ext.Exclude = append(ext.Exclude, "Syscall6")
|
|
}
|
|
|
|
importPath, err := ext.Extract(pkgIdent, "", &buf)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
var oFile string
|
|
if pkgIdent == "syscall" {
|
|
oFile = strings.ReplaceAll(importPath, "/", "_") + "_" + goos + "_" + goarch + ".go"
|
|
} else {
|
|
oFile = strings.ReplaceAll(importPath, "/", "_") + ".go"
|
|
}
|
|
|
|
version := runtime.Version()
|
|
if strings.HasPrefix(version, "devel") {
|
|
log.Fatalf("extracting only supported with stable releases of Go, not %v", version)
|
|
}
|
|
parts := strings.Split(version, ".")
|
|
prefix := parts[0] + "_" + extract.GetMinor(parts[1])
|
|
|
|
f, err := os.Create(prefix + "_" + oFile)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if _, err := io.Copy(f, &buf); err != nil {
|
|
_ = f.Close()
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if err := f.Close(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|