-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
95 changed files
with
567 additions
and
6,707 deletions.
There are no files selected for viewing
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
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
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,111 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var ( | ||
fileExts = map[string]void{} | ||
) | ||
|
||
func init() { | ||
exts := []string{ | ||
".c", | ||
".h", | ||
".go", | ||
".goc", | ||
".md", | ||
".txt", | ||
".git", | ||
".bzr", | ||
".tmp", | ||
".swig", | ||
".swigcxx", | ||
".a", | ||
".s", | ||
".S", | ||
".syso", | ||
".so", | ||
".dll", | ||
".o", | ||
".5", | ||
".6", | ||
".8", | ||
".out", | ||
".cc", | ||
".hh", | ||
".dat", | ||
".py", | ||
".pyc", | ||
".zip", | ||
".z", | ||
".7z", | ||
".gz", | ||
".tar", | ||
".bz2", | ||
".tgz", | ||
".rar", | ||
".pro", | ||
".occ", | ||
".asc", | ||
".conf", | ||
".html", | ||
".jpg", | ||
".png", | ||
".js", | ||
".json", | ||
".src", | ||
".log", | ||
".patch", | ||
".diff", | ||
".php", | ||
".rit", | ||
".css", | ||
".lua", | ||
".less", | ||
".ttf", | ||
".expected", | ||
".ps", | ||
".bak", | ||
".cix", | ||
".d", | ||
".hac", | ||
".hrb", | ||
".java", | ||
".lexres", | ||
".lst", | ||
".pan", | ||
".phpt", | ||
".prof", | ||
".set", | ||
".sol", | ||
".vrs", | ||
".exe", | ||
".bat", | ||
".sh", | ||
".rc", | ||
".bash", | ||
} | ||
|
||
for _, ext := range exts { | ||
fileExts[ext] = void{} | ||
} | ||
} | ||
|
||
func fx(nm string) (isFileExt, isGoFileExt bool) { | ||
nm = strings.ToLower(nm) | ||
ext := filepath.Ext(nm) | ||
|
||
if ext == ".go" { | ||
return true, true | ||
} | ||
|
||
if !strings.HasPrefix(nm, "go.") { | ||
if _, ok := fileExts[ext]; ok { | ||
return true, false | ||
} | ||
} | ||
|
||
return false, false | ||
} |
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,114 @@ | ||
package main | ||
|
||
import ( | ||
"go/parser" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
var ( | ||
autoInstCh = make(chan AutoInstOptions, 10) | ||
) | ||
|
||
func autoInstall(ao AutoInstOptions) { | ||
select { | ||
case autoInstCh <- ao: | ||
default: | ||
} | ||
} | ||
|
||
type AutoInstOptions struct { | ||
// if ImportPaths is empty, Src is parsed in order to populate it | ||
ImportPaths []string | ||
Src string | ||
|
||
// the environment variables as passed by the client - they should not be merged with os.Environ(...) | ||
// GOPATH is be valid | ||
Env map[string]string | ||
} | ||
|
||
func (a *AutoInstOptions) imports() map[string]string { | ||
m := map[string]string{} | ||
|
||
if len(a.ImportPaths) == 0 { | ||
_, af, _ := parseAstFile("a.go", a.Src, parser.ImportsOnly) | ||
a.ImportPaths = fileImportPaths(af) | ||
} | ||
|
||
for _, p := range a.ImportPaths { | ||
m[p] = filepath.FromSlash(p) + ".a" | ||
} | ||
|
||
return m | ||
} | ||
|
||
func (a *AutoInstOptions) install() { | ||
if a.Env == nil { | ||
a.Env = map[string]string{} | ||
} | ||
|
||
osArch := runtime.GOOS + "_" + runtime.GOARCH | ||
roots := []string{} | ||
|
||
if p := a.Env["GOROOT"]; p != "" { | ||
roots = append(roots, filepath.Join(p, "pkg", osArch)) | ||
} | ||
|
||
psep := string(filepath.ListSeparator) | ||
if s := a.Env["_pathsep"]; s != "" { | ||
psep = s | ||
} | ||
|
||
for _, p := range strings.Split(a.Env["GOPATH"], psep) { | ||
if p != "" { | ||
roots = append(roots, filepath.Join(p, "pkg", osArch)) | ||
} | ||
} | ||
|
||
if len(roots) == 0 { | ||
return | ||
} | ||
|
||
archiveOk := func(fn string) bool { | ||
for _, root := range roots { | ||
_, err := os.Stat(filepath.Join(root, fn)) | ||
if err == nil { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
el := envSlice(a.Env) | ||
installed := []string{} | ||
|
||
for path, fn := range a.imports() { | ||
if !archiveOk(fn) { | ||
cmd := exec.Command("go", "install", path) | ||
cmd.Env = el | ||
cmd.Stderr = ioutil.Discard | ||
cmd.Stdout = ioutil.Discard | ||
cmd.Run() | ||
|
||
if archiveOk(fn) { | ||
installed = append(installed, path) | ||
} | ||
} | ||
} | ||
|
||
if len(installed) > 0 { | ||
postMessage("auto-installed: %v", strings.Join(installed, ", ")) | ||
} | ||
} | ||
|
||
func init() { | ||
go func() { | ||
for ao := range autoInstCh { | ||
ao.install() | ||
} | ||
}() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.