浏览代码

Merge pull request #48 from vmarkovtsev/master

Windows
Vadim Markovtsev 7 年之前
父节点
当前提交
fe00c0d507
共有 4 个文件被更改,包括 58 次插入52 次删除
  1. 7 3
      .travis.yml
  2. 25 17
      Makefile
  3. 10 2
      README.md
  4. 16 30
      cmd/hercules/root.go

+ 7 - 3
.travis.yml

@@ -10,9 +10,12 @@ services:
 
 addons:
   apt:
+    sources:
+    - ubuntu-toolchain-r-test
     packages:
     - libxml2-dev
-    - libcunit1-dev
+    - gcc-6
+    - g++-6
 
 go:
   - 1.8
@@ -21,6 +24,8 @@ go:
 go_import_path: gopkg.in/src-d/hercules.v3
 
 before_install:
+  - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
+  - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90
   - wget -O protoc.zip https://github.com/google/protobuf/releases/download/v3.5.0/protoc-3.5.0-linux-x86_64.zip
   - unzip -d ~/.local protoc.zip && rm protoc.zip
   - go get -v github.com/gogo/protobuf/protoc-gen-gogo
@@ -32,9 +37,8 @@ before_install:
   - pip3 --version
 
 install:
-  - make dependencies
   - git clone --depth 1 https://github.com/src-d/go-git $GOPATH/src/gopkg.in/src-d/go-git.v4
-  - go get -t -v -ldflags "-X gopkg.in/src-d/hercules.v3.GIT_HASH=$(git rev-parse HEAD)" ./...
+  - make
   - pip3 install --user -r requirements.txt tensorflow
   - docker run -d --privileged -p 9432:9432 --name bblfshd bblfsh/bblfshd
   - docker exec -it bblfshd bblfshctl driver install --all

+ 25 - 17
Makefile

@@ -1,33 +1,41 @@
+GOPATH ?= $(shell go env GOPATH)
+ifneq ($(OS),Windows_NT)
+EXE =
+else
+EXE = .exe
 ifneq (oneshell, $(findstring oneshell, $(.FEATURES)))
   $(error GNU make 3.82 or later is required)
 endif
+endif
 
-all: ${GOPATH}/bin/hercules
+all: ${GOPATH}/bin/hercules${EXE}
 
 test: all
 	go test gopkg.in/src-d/hercules.v3
 
-dependencies: ${GOPATH}/src/gopkg.in/bblfsh/client-go.v2 ${GOPATH}/src/gopkg.in/src-d/hercules.v3 ${GOPATH}/src/gopkg.in/src-d/hercules.v3/pb/pb.pb.go ${GOPATH}/src/gopkg.in/src-d/hercules.v3/pb/pb_pb2.py ${GOPATH}/src/gopkg.in/src-d/hercules.v3/cmd/hercules/plugin_template_source.go
+${GOPATH}/bin/protoc-gen-gogo${EXE}:
+	go get -v github.com/gogo/protobuf/protoc-gen-gogo
 
-${GOPATH}/src/gopkg.in/src-d/hercules.v3/pb/pb.pb.go: pb/pb.proto
-	PATH=$$PATH:$$GOPATH/bin protoc --gogo_out=pb --proto_path=pb pb/pb.proto
+ifneq ($(OS),Windows_NT)
+pb/pb.pb.go: pb/pb.proto ${GOPATH}/bin/protoc-gen-gogo
+	PATH=${PATH}:${GOPATH}/bin protoc --gogo_out=pb --proto_path=pb pb/pb.proto
+else
+.ONESHELL:
+pb/pb.pb.go: pb/pb.proto ${GOPATH}/bin/protoc-gen-gogo.exe
+	SET PATH=${PATH}${GOPATH}\bin
+	protoc --gogo_out=pb --proto_path=pb pb/pb.proto
+endif
 
-${GOPATH}/src/gopkg.in/src-d/hercules.v3/pb/pb_pb2.py: pb/pb.proto
+pb/pb_pb2.py: pb/pb.proto
 	protoc --python_out pb --proto_path=pb pb/pb.proto
 
-${GOPATH}/src/gopkg.in/src-d/hercules.v3/cmd/hercules/plugin_template_source.go: ${GOPATH}/src/gopkg.in/src-d/hercules.v3/cmd/hercules/plugin.template
-	cd ${GOPATH}/src/gopkg.in/src-d/hercules.v3/cmd/hercules && go generate
+cmd/hercules/plugin_template_source.go: cmd/hercules/plugin.template
+	cd cmd/hercules && go generate
 
-${GOPATH}/src/gopkg.in/src-d/hercules.v3:
-	go get -d gopkg.in/src-d/hercules.v3/...
-
-.ONESHELL:
 ${GOPATH}/src/gopkg.in/bblfsh/client-go.v2:
-	go get -v gopkg.in/bblfsh/client-go.v2/... || true
-	cd $$GOPATH/src/gopkg.in/bblfsh/client-go.v2
+	go get -d -v gopkg.in/bblfsh/client-go.v2/... && \
+	cd ${GOPATH}/src/gopkg.in/bblfsh/client-go.v2 && \
 	make dependencies
 
-.ONESHELL:
-${GOPATH}/bin/hercules: dependencies *.go cmd/hercules/*.go rbtree/*.go yaml/*.go toposort/*.go pb/*.go
-	cd ${GOPATH}/src/gopkg.in/src-d/hercules.v3
-	go get -ldflags "-X gopkg.in/src-d/hercules.v3.BinaryGitHash=$$(git rev-parse HEAD)" gopkg.in/src-d/hercules.v3/cmd/hercules
+${GOPATH}/bin/hercules${EXE}: *.go cmd/hercules/*.go rbtree/*.go yaml/*.go toposort/*.go pb/*.go ${GOPATH}/src/gopkg.in/bblfsh/client-go.v2 pb/pb.pb.go pb/pb_pb2.py cmd/hercules/plugin_template_source.go
+	go get -ldflags "-X gopkg.in/src-d/hercules.v3.BinaryGitHash=$(shell git rev-parse HEAD)" gopkg.in/src-d/hercules.v3/cmd/hercules

+ 10 - 2
README.md

@@ -27,12 +27,20 @@ There is a [presentation](http://vmarkovtsev.github.io/techtalks-2017-moscow-lig
 You are going to need Go (>= v1.8) and Python 2 or 3.
 ```
 go get -d gopkg.in/src-d/hercules.v3/cmd/hercules
-cd $GOPATH/src/gopkg.in/hercules.v3/cmd/hercules
+cd $GOPATH/src/gopkg.in/src-d/hercules.v3/cmd/hercules
 make
 ```
 
 #### Windows
-Numpy and SciPy are requirements. Install the correct version by downloading the wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy.
+`hercules`: [bblfsh/client-go](https://github.com/bblfsh/client-go/blob/master/WINDOWS.md) is needed.
+
+```
+go get -d gopkg.in/src-d/hercules.v3/cmd/hercules
+cd %GOPATH%/src/gopkg.in/src-d/hercules.v3/cmd/hercules
+make
+```
+
+`labours.py`: Numpy and SciPy are requirements. Install the correct version by downloading the wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy.
 Couples analysis also needs Tensorflow.
 
 ### Contributions

+ 16 - 30
cmd/hercules/root.go

@@ -10,16 +10,14 @@ import (
 	"os"
 	"plugin"
 	"runtime/pprof"
-	"strconv"
 	"strings"
 	_ "unsafe" // for go:linkname
 
 	"github.com/gogo/protobuf/proto"
 	"github.com/spf13/cobra"
 	"github.com/spf13/pflag"
-	"github.com/vbauerster/mpb"
-	"github.com/vbauerster/mpb/decor"
 	"golang.org/x/crypto/ssh/terminal"
+	progress "gopkg.in/cheggaaa/pb.v1"
 	"gopkg.in/src-d/go-billy.v4/osfs"
 	"gopkg.in/src-d/go-git.v4"
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
@@ -157,29 +155,21 @@ targets can be added using the --plugin system.`,
 		// core logic
 		pipeline := hercules.NewPipeline(repository)
 		pipeline.SetFeaturesFromFlags()
-		var progress *mpb.Progress
-		var progressRendered bool
+		var bar *progress.ProgressBar
 		if !disableStatus {
-			beforeRender := func([]*mpb.Bar) {
-				progressRendered = true
-			}
-			progress = mpb.New(mpb.Output(os.Stderr), mpb.WithBeforeRenderFunc(beforeRender))
-			var bar *mpb.Bar
 			pipeline.OnProgress = func(commit, length int) {
 				if bar == nil {
-					width := len(strconv.Itoa(length))*2 + 3
-					bar = progress.AddBar(int64(length+1),
-						mpb.PrependDecorators(decor.DynamicName(
-							func(stats *decor.Statistics) string {
-								if stats.Current < stats.Total {
-									return fmt.Sprintf("%d / %d", stats.Current, length)
-								}
-								return "finalizing"
-							}, width, 0)),
-						mpb.AppendDecorators(decor.ETA(4, 0)),
-					)
+					bar = progress.New(length + 1)
+					bar.Callback = func(msg string) {
+						os.Stderr.WriteString("\r" + msg)
+					}
+					bar.NotPrint = true
+					bar.ShowPercent = false
+					bar.ShowSpeed = false
+					bar.SetMaxWidth(80)
+					bar.Start()
 				}
-				bar.Incr(commit - int(bar.Current()))
+				bar.Set(commit)
 			}
 		}
 
@@ -212,21 +202,17 @@ targets can be added using the --plugin system.`,
 			panic(err)
 		}
 		if !disableStatus {
-			progress.Stop()
-			if progressRendered {
-				// this is the only way to reliably clear the progress bar
-				fmt.Fprint(os.Stderr, "\033[F\033[K")
+			bar.Finish()
+			fmt.Fprint(os.Stderr, "\r" + strings.Repeat(" ", 80) + "\r")
+			if !terminal.IsTerminal(int(os.Stdout.Fd())) {
+				fmt.Fprint(os.Stderr, "writing...\r")
 			}
-			fmt.Fprint(os.Stderr, "writing...\r")
 		}
 		if !protobuf {
 			printResults(uri, deployed, results)
 		} else {
 			protobufResults(uri, deployed, results)
 		}
-		if !disableStatus {
-			fmt.Fprint(os.Stderr, "\033[K")
-		}
 	},
 }