From 0634379bb7b1af96fb16686afc301ae7ae9ee8b9 Mon Sep 17 00:00:00 2001 From: Geert-Johan Riemer Date: Wed, 16 Dec 2020 12:59:50 +0100 Subject: [PATCH] Remove embed-syso feature --- .gitignore | 1 - README.md | 13 --- embedded/embedded.go | 3 +- rice/embed-go_test.go | 2 +- rice/embed-syso.go | 206 ------------------------------------------ rice/flags.go | 2 +- rice/main.go | 3 - rice/util.go | 3 +- 8 files changed, 4 insertions(+), 229 deletions(-) delete mode 100644 rice/embed-syso.go diff --git a/.gitignore b/.gitignore index a3c9819..4482a4c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ /rice/rice.exe *.rice-box.go -*.rice-box.syso .wercker diff --git a/README.md b/README.md index feef3a1..cc26323 100644 --- a/README.md +++ b/README.md @@ -90,19 +90,6 @@ go build *A Note on Symbolic Links*: `embed-go` uses the `os.Walk` function from the standard library. The `os.Walk` function does **not** follow symbolic links. When creating a box, be aware that any symbolic links inside your box's directory are not followed. When the box itself is a symbolic link, the rice tool resolves its actual location before adding the contents. -### `rice embed-syso`: Embed resources by generating a coff .syso file and some .go source code - -** This method is experimental. Do not use for production systems. ** - -Execute this method before building. It generates a COFF .syso file and Go source file. The Go compiler then compiles these files into the binary. - -Execute the following commands: - -```bash -rice embed-syso -go build -``` - ### `rice append`: Append resources to executable as zip file This method changes an already built executable. It appends the resources as zip file to the binary. It makes compilation a lot faster. Using the append method works great for adding large assets to an executable binary. diff --git a/embedded/embedded.go b/embedded/embedded.go index a83dd2d..7d6d78a 100644 --- a/embedded/embedded.go +++ b/embedded/embedded.go @@ -9,8 +9,7 @@ import ( ) const ( - EmbedTypeGo = 0 - EmbedTypeSyso = 1 + EmbedTypeGo = 0 ) // EmbeddedBox defines an embedded box diff --git a/rice/embed-go_test.go b/rice/embed-go_test.go index b29c73a..0bd91da 100644 --- a/rice/embed-go_test.go +++ b/rice/embed-go_test.go @@ -86,7 +86,7 @@ func main() { []byte("Fasttemplate double escaping"), }, } - withIgnoredFiles := append(sourceFiles, sourceFile{"foo/rice-box.go", []byte("package main\nfunc init() {\n}")}, sourceFile{"foo/_amd64.rice-box.syso", []byte{}}) + withIgnoredFiles := append(sourceFiles, sourceFile{"foo/rice-box.go", []byte("package main\nfunc init() {\n}")}) pkg, cleanup, err := setUpTestPkg("foobar", withIgnoredFiles) defer cleanup() if err != nil { diff --git a/rice/embed-syso.go b/rice/embed-syso.go deleted file mode 100644 index b478c54..0000000 --- a/rice/embed-syso.go +++ /dev/null @@ -1,206 +0,0 @@ -package main - -// import ( -// "bytes" -// "encoding/gob" -// "fmt" -// "go/build" -// "io" -// "io/ioutil" -// "os" -// "path/filepath" -// "regexp" -// "strings" -// "text/template" - -// "github.com/GeertJohan/go.rice/embedded" -// "github.com/akavel/rsrc/coff" -// ) - -const sysoBoxSuffix = ".rice-box.syso" - -// type sizedReader struct { -// *bytes.Reader -// } - -// func (s sizedReader) Size() int64 { -// return int64(s.Len()) -// } - -// var tmplEmbeddedSysoHelper *template.Template - -// func init() { -// var err error -// tmplEmbeddedSysoHelper, err = template.New("embeddedSysoHelper").Parse(`package {{.Package}} -// // ############# GENERATED CODE ##################### -// // ## This file was generated by the rice tool. -// // ## Do not edit unless you know what you're doing. -// // ################################################## - -// // extern char _bricebox_{{.Symname}}[], _ericebox_{{.Symname}}; -// // int get_{{.Symname}}_length() { -// // return &_ericebox_{{.Symname}} - _bricebox_{{.Symname}}; -// // } -// import "C" -// import ( -// "bytes" -// "encoding/gob" -// "github.com/GeertJohan/go.rice/embedded" -// "unsafe" -// ) - -// func init() { -// ptr := unsafe.Pointer(&C._bricebox_{{.Symname}}) -// bts := C.GoBytes(ptr, C.get_{{.Symname}}_length()) -// embeddedBox := &embedded.EmbeddedBox{} -// err := gob.NewDecoder(bytes.NewReader(bts)).Decode(embeddedBox) -// if err != nil { -// panic("error decoding embedded box: "+err.Error()) -// } -// embeddedBox.Link() -// embedded.RegisterEmbeddedBox(embeddedBox.Name, embeddedBox) -// }`) -// if err != nil { -// panic("could not parse template embeddedSysoHelper: " + err.Error()) -// } -// } - -// type embeddedSysoHelperData struct { -// Package string -// Symname string -// } - -// func operationEmbedSyso(pkg *build.Package) { - -// regexpSynameReplacer := regexp.MustCompile(`[^a-z0-9_]`) - -// boxMap := findBoxes(pkg) - -// // notify user when no calls to rice.FindBox are made (is this an error and therefore os.Exit(1) ? -// if len(boxMap) == 0 { -// fmt.Println("no calls to rice.FindBox() found") -// return -// } - -// verbosef("\n") - -// for boxname := range boxMap { -// // find path and filename for this box -// boxPath := filepath.Join(pkg.Dir, boxname) -// boxFilename := strings.Replace(boxname, "/", "-", -1) -// boxFilename = strings.Replace(boxFilename, "..", "back", -1) -// boxFilename = strings.Replace(boxFilename, ".", "-", -1) - -// // verbose info -// verbosef("embedding box '%s'\n", boxname) -// verbosef("\tto file %s\n", boxFilename) - -// // read box metadata -// boxInfo, ierr := os.Stat(boxPath) -// if ierr != nil { -// fmt.Printf("Error: unable to access box at %s\n", boxPath) -// os.Exit(1) -// } - -// // create box datastructure (used by template) -// box := &embedded.EmbeddedBox{ -// Name: boxname, -// Time: boxInfo.ModTime(), -// EmbedType: embedded.EmbedTypeSyso, -// Files: make(map[string]*embedded.EmbeddedFile), -// Dirs: make(map[string]*embedded.EmbeddedDir), -// } - -// // fill box datastructure with file data -// filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error { -// if err != nil { -// fmt.Printf("error walking box: %s\n", err) -// os.Exit(1) -// } - -// filename := strings.TrimPrefix(path, boxPath) -// filename = strings.Replace(filename, "\\", "/", -1) -// filename = strings.TrimPrefix(filename, "/") -// if info.IsDir() { -// embeddedDir := &embedded.EmbeddedDir{ -// Filename: filename, -// DirModTime: info.ModTime(), -// } -// verbosef("\tincludes dir: '%s'\n", embeddedDir.Filename) -// box.Dirs[embeddedDir.Filename] = embeddedDir - -// // add tree entry (skip for root, it'll create a recursion) -// if embeddedDir.Filename != "" { -// pathParts := strings.Split(embeddedDir.Filename, "/") -// parentDir := box.Dirs[strings.Join(pathParts[:len(pathParts)-1], "/")] -// parentDir.ChildDirs = append(parentDir.ChildDirs, embeddedDir) -// } -// } else if !generated(filename) { -// embeddedFile := &embedded.EmbeddedFile{ -// Filename: filename, -// FileModTime: info.ModTime(), -// Content: "", -// } -// verbosef("\tincludes file: '%s'\n", embeddedFile.Filename) -// contentBytes, err := ioutil.ReadFile(path) -// if err != nil { -// fmt.Printf("error reading file content while walking box: %s\n", err) -// os.Exit(1) -// } -// embeddedFile.Content = string(contentBytes) -// box.Files[embeddedFile.Filename] = embeddedFile -// } -// return nil -// }) - -// // encode embedded box to gob file -// boxGobBuf := &bytes.Buffer{} -// err := gob.NewEncoder(boxGobBuf).Encode(box) -// if err != nil { -// fmt.Printf("error encoding box to gob: %v\n", err) -// os.Exit(1) -// } - -// verbosef("gob-encoded embeddedBox is %d bytes large\n", boxGobBuf.Len()) - -// // write coff -// symname := regexpSynameReplacer.ReplaceAllString(boxname, "_") -// createCoffSyso(boxname, symname, "386", boxGobBuf.Bytes()) -// createCoffSyso(boxname, symname, "amd64", boxGobBuf.Bytes()) - -// // write go -// sysoHelperData := embeddedSysoHelperData{ -// Package: pkg.Name, -// Symname: symname, -// } -// fileSysoHelper, err := os.Create(boxFilename + ".rice-box.go") -// if err != nil { -// fmt.Printf("error creating syso helper: %v\n", err) -// os.Exit(1) -// } -// err = tmplEmbeddedSysoHelper.Execute(fileSysoHelper, sysoHelperData) -// if err != nil { -// fmt.Printf("error executing tmplEmbeddedSysoHelper: %v\n", err) -// os.Exit(1) -// } -// } -// } - -// func createCoffSyso(boxFilename string, symname string, arch string, data []byte) { -// boxCoff := coff.NewRDATA() -// switch arch { -// case "386": -// case "amd64": -// boxCoff.FileHeader.Machine = 0x8664 -// default: -// panic("invalid arch") -// } -// boxCoff.AddData("_bricebox_"+symname, sizedReader{bytes.NewReader(data)}) -// boxCoff.AddData("_ericebox_"+symname, io.NewSectionReader(strings.NewReader("\000\000"), 0, 2)) // TODO: why? copied from rsrc, which copied it from as-generated -// boxCoff.Freeze() -// err := writeCoff(boxCoff, boxFilename+"_"+arch+sysoBoxSuffix) -// if err != nil { -// fmt.Printf("error writing %s coff/.syso: %v\n", arch, err) -// os.Exit(1) -// } -// } diff --git a/rice/flags.go b/rice/flags.go index 96620b9..d35004b 100644 --- a/rice/flags.go +++ b/rice/flags.go @@ -20,7 +20,7 @@ var flags struct { } `command:"append"` EmbedGo struct{} `command:"embed-go" alias:"embed"` - EmbedSyso struct{} `command:"embed-syso"` + EmbedSyso struct{} `command:"embed-syso" hidden:"true"` Clean struct{} `command:"clean"` Tags []string `long:"tags" description:"Tags to use with the implicit go build"` diff --git a/rice/main.go b/rice/main.go index 162b2d6..7e7df03 100644 --- a/rice/main.go +++ b/rice/main.go @@ -38,9 +38,6 @@ func main() { case "embed-syso": log.Println("WARNING: embedding .syso is experimental..") log.Fatalln("FATAL: embed-syso is broken and will remain unusable until further notice. Please see https://github.com/GeertJohan/go.rice/issues/162") - // for _, pkg := range pkgs { - // operationEmbedSyso(pkg) - // } case "append": operationAppend(pkgs) case "clean": diff --git a/rice/util.go b/rice/util.go index 863dca8..b67f35f 100644 --- a/rice/util.go +++ b/rice/util.go @@ -10,8 +10,7 @@ import ( // generated tests if a filename was generated by rice func generated(filename string) bool { return filepath.Base(filename) == boxFilename || - strings.HasSuffix(filename, "."+boxFilename) || - strings.HasSuffix(filename, sysoBoxSuffix) + strings.HasSuffix(filename, "."+boxFilename) } // randomString generates a pseudo-random alpha-numeric string with given length.