mirror of
https://github.com/zyedidia/micro
synced 2024-09-30 05:06:02 +00:00
Build : using go:generate and go:embed (#2195)
* using go:generate and go:embed * fix import
This commit is contained in:
parent
fe3186ba9d
commit
ec3292e8c4
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
||||||
[submodule "tools/go-bindata"]
|
|
||||||
path = tools/go-bindata
|
|
||||||
url = https://github.com/zyedidia/go-bindata
|
|
35
Makefile
35
Makefile
|
@ -13,7 +13,12 @@ GOVARS = -X github.com/zyedidia/micro/v2/internal/util.Version=$(VERSION) -X git
|
||||||
DEBUGVAR = -X github.com/zyedidia/micro/v2/internal/util.Debug=ON
|
DEBUGVAR = -X github.com/zyedidia/micro/v2/internal/util.Debug=ON
|
||||||
VSCODE_TESTS_BASE_URL = 'https://raw.githubusercontent.com/microsoft/vscode/e6a45f4242ebddb7aa9a229f85555e8a3bd987e2/src/vs/editor/test/common/model/'
|
VSCODE_TESTS_BASE_URL = 'https://raw.githubusercontent.com/microsoft/vscode/e6a45f4242ebddb7aa9a229f85555e8a3bd987e2/src/vs/editor/test/common/model/'
|
||||||
|
|
||||||
# Builds micro after checking dependencies but without updating the runtime
|
fetch-tags:
|
||||||
|
git fetch --tags
|
||||||
|
|
||||||
|
generate:
|
||||||
|
go generate ./runtime
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||||
|
|
||||||
|
@ -23,36 +28,12 @@ build-dbg:
|
||||||
build-tags: fetch-tags
|
build-tags: fetch-tags
|
||||||
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||||
|
|
||||||
# Builds micro after building the runtime and checking dependencies
|
build-all: generate build
|
||||||
build-all: runtime build
|
|
||||||
|
|
||||||
# Builds micro without checking for dependencies
|
|
||||||
build-quick:
|
|
||||||
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
|
||||||
|
|
||||||
# Same as 'build' but installs to $GOBIN afterward
|
|
||||||
install:
|
install:
|
||||||
go install -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
go install -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||||
|
|
||||||
# Same as 'build-all' but installs to $GOBIN afterward
|
install-all: generate install
|
||||||
install-all: runtime install
|
|
||||||
|
|
||||||
# Same as 'build-quick' but installs to $GOBIN afterward
|
|
||||||
install-quick:
|
|
||||||
go install -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
|
||||||
|
|
||||||
fetch-tags:
|
|
||||||
git fetch --tags
|
|
||||||
|
|
||||||
# Builds the runtime
|
|
||||||
runtime:
|
|
||||||
git submodule update --init
|
|
||||||
rm -f runtime/syntax/*.hdr
|
|
||||||
go run runtime/syntax/make_headers.go runtime/syntax
|
|
||||||
go build -o tools/bindata ./tools/go-bindata
|
|
||||||
tools/bindata -pkg config -nomemcopy -nometadata -o runtime.go runtime/...
|
|
||||||
mv runtime.go internal/config
|
|
||||||
gofmt -w internal/config/runtime.go
|
|
||||||
|
|
||||||
testgen:
|
testgen:
|
||||||
mkdir -p tools/vscode-tests
|
mkdir -p tools/vscode-tests
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -8,19 +8,16 @@ require (
|
||||||
github.com/mattn/go-isatty v0.0.11
|
github.com/mattn/go-isatty v0.0.11
|
||||||
github.com/mattn/go-runewidth v0.0.7
|
github.com/mattn/go-runewidth v0.0.7
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff
|
|
||||||
github.com/sergi/go-diff v1.1.0
|
github.com/sergi/go-diff v1.1.0
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
|
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
|
||||||
github.com/zyedidia/clipboard v1.0.3
|
github.com/zyedidia/clipboard v1.0.3
|
||||||
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
|
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
|
||||||
github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5
|
|
||||||
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d
|
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d
|
||||||
github.com/zyedidia/pty v1.1.15 // indirect
|
github.com/zyedidia/pty v1.1.15 // indirect
|
||||||
github.com/zyedidia/tcell/v2 v2.0.8
|
github.com/zyedidia/tcell/v2 v2.0.8
|
||||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415
|
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415
|
||||||
golang.org/x/text v0.3.2
|
golang.org/x/text v0.3.2
|
||||||
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.2.7
|
gopkg.in/yaml.v2 v2.2.7
|
||||||
layeh.com/gopher-luar v1.0.7
|
layeh.com/gopher-luar v1.0.7
|
||||||
)
|
)
|
||||||
|
@ -29,4 +26,4 @@ replace github.com/kballard/go-shellquote => github.com/zyedidia/go-shellquote v
|
||||||
|
|
||||||
replace github.com/mattn/go-runewidth => github.com/zyedidia/go-runewidth v0.0.12
|
replace github.com/mattn/go-runewidth => github.com/zyedidia/go-runewidth v0.0.12
|
||||||
|
|
||||||
go 1.11
|
go 1.16
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -27,8 +27,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff h1:+6NUiITWwE5q1KO6SAfUX918c+Tab0+tGAM/mtdlUyA=
|
|
||||||
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
|
|
||||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
@ -47,8 +45,6 @@ github.com/zyedidia/go-runewidth v0.0.12 h1:aHWj8qL3aH7caRzoPBJXe1pEaZBXHpKtfTui
|
||||||
github.com/zyedidia/go-runewidth v0.0.12/go.mod h1:vF8djYdLmG8BJaUZ4CznFYCJ3pFR8m4B4VinTvTTarU=
|
github.com/zyedidia/go-runewidth v0.0.12/go.mod h1:vF8djYdLmG8BJaUZ4CznFYCJ3pFR8m4B4VinTvTTarU=
|
||||||
github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655 h1:Z3RhH6hvcSx7eX6Q/pP6YVsgea/1eMDG99vtWwi3nK4=
|
github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655 h1:Z3RhH6hvcSx7eX6Q/pP6YVsgea/1eMDG99vtWwi3nK4=
|
||||||
github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655/go.mod h1:1sTqqO+kcYzZp43M5VsJe1tns9IzlSeC9jB6c2+o/5Y=
|
github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655/go.mod h1:1sTqqO+kcYzZp43M5VsJe1tns9IzlSeC9jB6c2+o/5Y=
|
||||||
github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5 h1:Zs6mpwXvlqpF9zHl5XaN0p5V4J9XvP+WBuiuXyIgqvc=
|
|
||||||
github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5/go.mod h1:c1r+Ob9tUTPB0FKWO1+x+Hsc/zNa45WdGq7Y38Ybip0=
|
|
||||||
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d h1:zmDMkh22zXOB7gz8jFaI4GpI7llsPgzm38/jG0UgxjE=
|
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d h1:zmDMkh22zXOB7gz8jFaI4GpI7llsPgzm38/jG0UgxjE=
|
||||||
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d/go.mod h1:NDJSTTYWivnza6zkRapeX2/LwhKPEMQ7bJxqgDVT78I=
|
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d/go.mod h1:NDJSTTYWivnza6zkRapeX2/LwhKPEMQ7bJxqgDVT78I=
|
||||||
github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s=
|
github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s=
|
||||||
|
@ -70,8 +66,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
|
|
||||||
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
rt "github.com/zyedidia/micro/v2/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -90,7 +92,7 @@ func (af assetFile) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (af assetFile) Data() ([]byte, error) {
|
func (af assetFile) Data() ([]byte, error) {
|
||||||
return Asset(string(af))
|
return rt.Asset(string(af))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nf namedFile) Name() string {
|
func (nf namedFile) Name() string {
|
||||||
|
@ -123,7 +125,7 @@ func AddRuntimeFilesFromDirectory(fileType RTFiletype, directory, pattern string
|
||||||
// AddRuntimeFilesFromAssets registers each file from the given asset-directory for
|
// AddRuntimeFilesFromAssets registers each file from the given asset-directory for
|
||||||
// the filetype which matches the file-pattern
|
// the filetype which matches the file-pattern
|
||||||
func AddRuntimeFilesFromAssets(fileType RTFiletype, directory, pattern string) {
|
func AddRuntimeFilesFromAssets(fileType RTFiletype, directory, pattern string) {
|
||||||
files, err := AssetDir(directory)
|
files, err := rt.AssetDir(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -214,9 +216,9 @@ func InitRuntimeFiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
plugdir = filepath.Join("runtime", "plugins")
|
plugdir = filepath.Join("runtime", "plugins")
|
||||||
if files, err := AssetDir(plugdir); err == nil {
|
if files, err := rt.AssetDir(plugdir); err == nil {
|
||||||
for _, d := range files {
|
for _, d := range files {
|
||||||
if srcs, err := AssetDir(filepath.Join(plugdir, d)); err == nil {
|
if srcs, err := rt.AssetDir(filepath.Join(plugdir, d)); err == nil {
|
||||||
p := new(Plugin)
|
p := new(Plugin)
|
||||||
p.Name = d
|
p.Name = d
|
||||||
p.DirName = d
|
p.DirName = d
|
||||||
|
@ -225,7 +227,7 @@ func InitRuntimeFiles() {
|
||||||
if strings.HasSuffix(f, ".lua") {
|
if strings.HasSuffix(f, ".lua") {
|
||||||
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))
|
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))
|
||||||
} else if strings.HasSuffix(f, ".json") {
|
} else if strings.HasSuffix(f, ".json") {
|
||||||
data, err := Asset(filepath.Join(plugdir, d, f))
|
data, err := rt.Asset(filepath.Join(plugdir, d, f))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
31
runtime/runtime.go
Normal file
31
runtime/runtime.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate go run syntax/make_headers.go syntax
|
||||||
|
|
||||||
|
//go:embed colorschemes help plugins syntax
|
||||||
|
var runtime embed.FS
|
||||||
|
|
||||||
|
// AssetDir lists file names in folder
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
name = strings.TrimLeft(name, "runtime/")
|
||||||
|
entries, err := runtime.ReadDir(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
names := make([]string, len(entries), len(entries))
|
||||||
|
for i, entry := range entries {
|
||||||
|
names[i] = entry.Name()
|
||||||
|
}
|
||||||
|
return names, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asset returns a file content
|
||||||
|
func Asset(name string) ([]byte, error) {
|
||||||
|
name = strings.TrimLeft(name, "runtime/")
|
||||||
|
return runtime.ReadFile(name)
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 9453701aa0dbd20f88145dbd77c6f50937f17a19
|
|
Loading…
Reference in a new issue