Skip to content

Instantly share code, notes, and snippets.

@mpl
Created May 12, 2016 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpl/ac9033bb28207401b7cedc3d74e6c096 to your computer and use it in GitHub Desktop.
Save mpl/ac9033bb28207401b7cedc3d74e6c096 to your computer and use it in GitHub Desktop.
diff --git a/build/build.go b/build/build.go
index 3386d47..e97246b 100644
--- a/build/build.go
+++ b/build/build.go
@@ -10,13 +10,11 @@ import (
"go/types"
"io/ioutil"
"os"
- "os/exec"
"path/filepath"
"strconv"
"strings"
"time"
- "github.com/fsnotify/fsnotify"
"github.com/gopherjs/gopherjs/compiler"
"github.com/kardianos/osext"
"github.com/neelance/sourcemap"
@@ -301,7 +299,6 @@ type Session struct {
options *Options
Archives map[string]*compiler.Archive
Types map[string]*types.Package
- Watcher *fsnotify.Watcher
}
func NewSession(options *Options) *Session {
@@ -318,19 +315,6 @@ func NewSession(options *Options) *Session {
Archives: make(map[string]*compiler.Archive),
}
s.Types = make(map[string]*types.Package)
- if options.Watch {
- if out, err := exec.Command("ulimit", "-n").Output(); err == nil {
- if n, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil && n < 1024 {
- fmt.Printf("Warning: The maximum number of open file descriptors is very low (%d). Change it with 'ulimit -n 8192'.\n", n)
- }
- }
-
- var err error
- s.Watcher, err = fsnotify.NewWatcher()
- if err != nil {
- panic(err)
- }
- }
return s
}
@@ -342,9 +326,6 @@ func (s *Session) InstallSuffix() string {
}
func (s *Session) BuildDir(packagePath string, importPath string, pkgObj string) error {
- if s.Watcher != nil {
- s.Watcher.Add(packagePath)
- }
buildPkg, err := NewBuildContext(s.InstallSuffix(), s.options.BuildTags).ImportDir(packagePath, 0)
if err != nil {
return err
@@ -404,9 +385,6 @@ func (s *Session) BuildImportPath(path string) (*compiler.Archive, error) {
func (s *Session) buildImportPathWithSrcDir(path string, srcDir string) (*PackageData, *compiler.Archive, error) {
pkg, err := importWithSrcDir(path, srcDir, 0, s.InstallSuffix(), s.options.BuildTags)
- if s.Watcher != nil && pkg != nil { // add watch even on error
- s.Watcher.Add(pkg.Dir)
- }
if err != nil {
return nil, nil, err
}
@@ -659,29 +637,3 @@ func hasGopathPrefix(file, gopath string) (hasGopathPrefix bool, prefixLen int)
}
return false, 0
}
-
-func (s *Session) WaitForChange() {
- s.options.PrintSuccess("watching for changes...\n")
- for {
- select {
- case ev := <-s.Watcher.Events:
- if ev.Op&(fsnotify.Create|fsnotify.Write|fsnotify.Remove|fsnotify.Rename) == 0 || filepath.Base(ev.Name)[0] == '.' {
- continue
- }
- if !strings.HasSuffix(ev.Name, ".go") && !strings.HasSuffix(ev.Name, ".inc.js") {
- continue
- }
- s.options.PrintSuccess("change detected: %s\n", ev.Name)
- case err := <-s.Watcher.Errors:
- s.options.PrintError("watcher error: %s\n", err.Error())
- }
- break
- }
-
- go func() {
- for range s.Watcher.Events {
- // consume, else Close() may deadlock
- }
- }()
- s.Watcher.Close()
-}
diff --git a/tool.go b/tool.go
index 92c9ac4..e6c41f3 100644
--- a/tool.go
+++ b/tool.go
@@ -105,9 +105,6 @@ func main() {
for i, name := range args {
name = filepath.ToSlash(name)
names[i] = name
- if s.Watcher != nil {
- s.Watcher.Add(name)
- }
}
if err := s.BuildFiles(args, pkgObj, currentDirectory); err != nil {
return err
@@ -117,9 +114,6 @@ func main() {
for _, pkgPath := range args {
pkgPath = filepath.ToSlash(pkgPath)
- if s.Watcher != nil {
- s.Watcher.Add(pkgPath)
- }
pkg, err := gbuild.Import(pkgPath, 0, s.InstallSuffix(), options.BuildTags)
if err != nil {
return err
@@ -140,10 +134,7 @@ func main() {
return nil
}, options, nil)
- if s.Watcher == nil {
- os.Exit(exitCode)
- }
- s.WaitForChange()
+ os.Exit(exitCode)
}
}
@@ -191,9 +182,6 @@ func main() {
pkgPath = filepath.ToSlash(pkgPath)
pkg, err := gbuild.Import(pkgPath, 0, s.InstallSuffix(), options.BuildTags)
- if s.Watcher != nil && pkg != nil { // add watch even on error
- s.Watcher.Add(pkg.Dir)
- }
if err != nil {
return err
}
@@ -211,11 +199,7 @@ func main() {
}
return nil
}, options, nil)
-
- if s.Watcher == nil {
- os.Exit(exitCode)
- }
- s.WaitForChange()
+ os.Exit(exitCode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment