Skip to content

Commit

Permalink
Remove elvish-stub.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaq committed Oct 26, 2016
1 parent 05069da commit 3627187
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 434 deletions.
19 changes: 5 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ PKG_COVERS := $(shell go list ./... | grep -v /vendor/ | grep "^github.com/elves
COVER_MODE := count

FIRST_GOPATH=$(shell go env GOPATH | cut -d: -f1)
STUB := $(FIRST_GOPATH)/bin/elvish-stub

default: get stub test
default: get test

get:
go get .

generate:
go generate ./...

stub: $(STUB)

$(STUB): ./stubimpl/main.c
test -n $(FIRST_GOPATH)
mkdir -p $(FIRST_GOPATH)/bin
$(CC) ./stubimpl/main.c -o $@

test: stub
test:
go test $(PKGS)
: ./stubimpl/test.sh

cover/%: %
mkdir -p cover
Expand All @@ -36,8 +27,8 @@ goveralls: cover/all
go get -u github.com/mattn/goveralls
$(FIRST_GOPATH)/bin/goveralls -coverprofile=cover/all -service=travis-ci \

upload: get stub
tar cfz elvish.tar.gz -C $(FIRST_GOPATH)/bin elvish elvish-stub
upload: get
tar cfz elvish.tar.gz -C $(FIRST_GOPATH)/bin elvish
test "$(TRAVIS_GO_VERSION)" = 1.7 -a "$(TRAVIS_PULL_REQUEST)" = false \
&& test -n "$(TRAVIS_TAG)" -o "$(TRAVIS_BRANCH)" = master \
&& curl http://ul.elvish.io:6060/ -F name=elvish-$(TRAVIS_OS_NAME).tar.gz \
Expand All @@ -46,4 +37,4 @@ upload: get stub

travis: goveralls upload

.PHONY: default get generate stub test goveralls upload travis
.PHONY: default get generate test goveralls upload travis
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Elvish mimics bash and zsh in a lot of places. The following shows some key diff
Go >= 1.6 is required. Linux is fully supported. It is likely to work on BSDs and Mac OS X. Windows is **not** supported yet.
The main binary can be installed using `go get github.com/elves/elvish`. There is also an auxiliary program called elvish-stub; install it with `make stub`. Elvish is functional without the stub, but job control features depend on it.
Elvish is a go-gettable package, and can be installed using `go get github.com/elves/elvish`.
If you are lazy and use `bash` or `zsh` now, here is something you can copy-paste into your terminal:
Expand All @@ -160,7 +160,6 @@ export PATH=$PATH:$GOPATH/bin
mkdir -p $GOPATH
go get github.com/elves/elvish
make -C $GOPATH/src/github.com/elves/elvish stub
for f in ~/.bashrc ~/.zshrc; do
printf 'export %s=%s\n' GOPATH '$HOME/go' PATH '$PATH:$GOPATH/bin' >> $f
Expand Down
3 changes: 0 additions & 3 deletions eval/builtin-fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,4 @@ func preExit(ec *EvalCtx) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
if ec.Stub != nil {
ec.Stub.Terminate()
}
}
11 changes: 1 addition & 10 deletions eval/compile_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync"

"github.com/elves/elvish/parse"
"github.com/elves/elvish/stub"
)

// Op is an operation on an EvalCtx.
Expand Down Expand Up @@ -41,14 +40,7 @@ func (cp *compiler) pipeline(n *parse.Pipeline) OpFunc {
bg := n.Background
if bg {
ec = ec.fork("background job " + n.SourceText())

// Set up a new stub.
st, err := stub.NewStub(os.Stderr)
if err != nil {
throwf("failed to spawn stub: %v", err)
}
st.SetTitle(n.SourceText())
ec.Stub = st
ec.intCh = nil

if ec.Editor != nil {
// TODO: Redirect output in interactive mode so that the line
Expand Down Expand Up @@ -104,7 +96,6 @@ func (cp *compiler) pipeline(n *parse.Pipeline) OpFunc {
// Background job, wait for form termination asynchronously.
go func() {
wg.Wait()
ec.Stub.Terminate()
msg := "job " + n.SourceText() + " finished"
if !allok(errors) {
msg += ", errors = " + makeCompositeError(errors).Error()
Expand Down
64 changes: 24 additions & 40 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/elves/elvish/parse"
"github.com/elves/elvish/store"
"github.com/elves/elvish/stub"
"github.com/elves/elvish/sys"
"github.com/elves/elvish/util"
)
Expand All @@ -40,7 +39,6 @@ type Evaler struct {
Modules map[string]Namespace
Store *store.Store
Editor Editor
Stub *stub.Stub
intCh chan struct{}
}

Expand All @@ -65,7 +63,7 @@ func (ec *EvalCtx) falsify() {

// NewEvaler creates a new Evaler.
func NewEvaler(st *store.Store) *Evaler {
return &Evaler{Namespace{}, map[string]Namespace{}, st, nil, nil, nil}
return &Evaler{Namespace{}, map[string]Namespace{}, st, nil, nil}
}

func (e *Evaler) searchPaths() []string {
Expand Down Expand Up @@ -166,47 +164,32 @@ func (ev *Evaler) Eval(op Op, name, text string) error {
{File: os.Stderr, Chan: BlackholeChan},
}

signal.Ignore(syscall.SIGTTIN)
signal.Ignore(syscall.SIGTTOU)
// signal.Ignore(syscall.SIGTTIN)
// signal.Ignore(syscall.SIGTTOU)
stopSigGoroutine := make(chan struct{})
sigGoRoutineDone := make(chan struct{})
// XXX Should use fd of /dev/terminal instead of 0.
if ev.Stub != nil && ev.Stub.Alive() && sys.IsATTY(0) {
ev.Stub.SetTitle(summarize(text))
dir, err := os.Getwd()
if err != nil {
dir = "/"
}
ev.Stub.Chdir(dir)
err = sys.Tcsetpgrp(0, ev.Stub.Process().Pid)
if err != nil {
fmt.Println("failed to put stub in foreground:", err)
}

ev.intCh = make(chan struct{})
go func() {
closedIntCh := false
loop:
for {
select {
case sig := <-ev.Stub.Signals():
switch sig {
case syscall.SIGINT, syscall.SIGQUIT:
if !closedIntCh {
close(ev.intCh)
closedIntCh = true
}
}
case <-stopSigGoroutine:
break loop
// Set up intCh.
ev.intCh = make(chan struct{})
sigCh := make(chan os.Signal)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGQUIT)
go func() {
closedIntCh := false
loop:
for {
select {
case <-sigCh:
if !closedIntCh {
close(ev.intCh)
closedIntCh = true
}
case <-stopSigGoroutine:
break loop
}
ev.intCh = nil
close(sigGoRoutineDone)
}()
} else {
}
ev.intCh = nil
signal.Stop(sigCh)
close(sigGoRoutineDone)
}
}()

ret, err := ev.eval(op, ports, name, text)
close(outCh)
Expand All @@ -218,7 +201,8 @@ func (ev *Evaler) Eval(op Op, name, text string) error {
fmt.Println(falseIndicator)
}

// XXX Should use fd of /dev/tty instead of 0.
// Put myself in foreground, in case some command has put me in background.
// XXX Should probably use fd of /dev/tty instead of 0.
if sys.IsATTY(0) {
err := sys.Tcsetpgrp(0, syscall.Getpgrp())
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions eval/external_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func (e ExternalCmd) Call(ec *EvalCtx, argVals []Value, opts map[string]Value) {
}

sys := syscall.SysProcAttr{}
if ec.Stub != nil && ec.Stub.Alive() {
sys.Setpgid = true
sys.Pgid = ec.Stub.Process().Pid
}
attr := syscall.ProcAttr{Env: os.Environ(), Files: files[:], Sys: &sys}

path, err := ec.Search(e.Name)
Expand Down
12 changes: 0 additions & 12 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/elves/elvish/eval"
"github.com/elves/elvish/parse"
"github.com/elves/elvish/store"
"github.com/elves/elvish/stub"
"github.com/elves/elvish/sys"
"github.com/elves/elvish/util"
)
Expand Down Expand Up @@ -83,17 +82,6 @@ func Main() {
}
}()

stub, err := stub.NewStub(os.Stderr)
if err != nil {
fmt.Println("failed to spawn stub:", err)
} else {
ev.Stub = stub
go func() {
<-stub.State()
fmt.Println("stub has died")
}()
}

if len(args) == 1 {
if *cmd {
evalText(ev, "code from -c", args[0])
Expand Down
11 changes: 0 additions & 11 deletions stub/bad_signal.go

This file was deleted.

Loading

0 comments on commit 3627187

Please sign in to comment.