示例#1
0
文件: main.go 项目: hanwen/termite
func Inspect(files []string) {
	wd, _ := os.Getwd()
	for _, p := range files {
		if p[0] != '/' {
			p = filepath.Join(wd, p)
		}
		p = p[1:]
		req := attr.AttrRequest{Name: p}
		rep := attr.AttrResponse{}
		rpc, err := Rpc()
		err = rpc.Call("LocalMaster.InspectFile", &req, &rep)
		if err != nil {
			log.Fatal("LocalMaster.InspectFile: ", err)
		}

		for _, a := range rep.Attrs {
			entries := []string{}
			log.Printf("%v", a.LongString())
			for n, m := range a.NameModeMap {
				entries = append(entries, fmt.Sprintf("%s %s", n, m))
			}
			sort.Strings(entries)
			for _, e := range entries {
				log.Println(e)
			}
		}
	}
}
示例#2
0
文件: main.go 项目: hanwen/termite
func Refresh() {
	req := 1
	rep := 1
	rpc, err := Rpc()
	err = rpc.Call("LocalMaster.RefreshAttributeCache", &req, &rep)
	if err != nil {
		log.Fatal("LocalMaster.RefreshAttributeCache: ", err)
	}
}
示例#3
0
func (s *DBusSuite) TestCall(c *C) {
	socket := fmt.Sprintf("/tmp/test.%s.sock", uuid.New()[0:8])

	go Serve(socket)
	rpc := NewRPC(socket)
	rpc.SetTimeout(1 * time.Second)
	rpc.Connect()

	var result int
	rpc.Call("Arith.Add", 1, &result)

	c.Assert(result, Equals, 16)
}
示例#4
0
文件: main.go 项目: hanwen/termite
func main() {
	command := flag.String("c", "", "command to run.")
	refresh := flag.Bool("refresh", false, "refresh master file cache.")
	shutdown := flag.Bool("shutdown", false, "shutdown master.")
	inspect := flag.Bool("inspect", false, "inspect files on master.")
	exec := flag.Bool("exec", false, "run command args without shell.")
	directory := flag.String("dir", "", "directory from where to run (default: cwd).")
	worker := flag.String("worker", "", "request to run on a worker explicitly")
	debug := flag.Bool("dbg", false, "set on debugging in request.")

	flag.Parse()
	log.SetPrefix("S")

	if *shutdown {
		req := 1
		rep := 1
		rpc, err := Rpc()
		err = rpc.Call("LocalMaster.Shutdown", &req, &rep)
		if err != nil {
			log.Fatal(err)
		}
		return
	}
	if *refresh {
		Refresh()
	}

	if *inspect {
		Inspect(flag.Args())
	}

	if *directory == "" {
		wd, err := os.Getwd()
		if err != nil {
			log.Fatal("Getwd", err)
		}

		directory = &wd
	}

	var req *termite.WorkRequest
	var rule *termite.LocalRule
	if *exec {
		req = &termite.WorkRequest{
			Binary: flag.Args()[0],
			Argv:   flag.Args(),
			Dir:    *directory,
			Env:    os.Environ(),
		}
	} else {
		req, rule = PrepareRun(*command, *directory, topDir)
	}
	var waitMsg syscall.WaitStatus
	rep := termite.WorkResponse{}
	if rule != nil && rule.Local {
		waitMsg = RunLocally(req, rule)
		if !rule.SkipRefresh {
			Refresh()
		}
		rep.WorkerId = "(local)"
	} else {
		req.Debug = req.Debug || os.Getenv("TERMITE_DEBUG") != "" || *debug
		req.Worker = *worker

		req.TrackReads = true
		req.DeclaredDeps = strings.Split(os.Getenv("MAKE_DEPS"), " ")
		req.DeclaredTarget = os.Getenv("MAKE_TARGET")

		rpc, err := Rpc()
		if err != nil {
			log.Fatalf("rpc connection problem (%s): %v", *command, err)
		}

		err = rpc.Call("LocalMaster.Run", req, &rep)
		if err != nil {
			log.Fatal("LocalMaster.Run: ", err)
		}

		os.Stdout.Write([]byte(rep.Stdout))
		os.Stderr.Write([]byte(rep.Stderr))

		waitMsg = rep.Exit
	}

	if waitMsg != 0 {
		log.Printf("Failed %s: '%q'", rep.WorkerId, *command)
	}

	// TODO - is this necessary?
	rpc, _ := Rpc()
	rpc.Close()
	os.Exit(int(waitMsg))
}