Exemplo n.º 1
0
func main() {
	output := flag.String("o", "", "write generated code to file")
	release := flag.Bool("r", false, "write output for release (server config format)")
	test := flag.Bool("t", false, "just exit with status code 0 (test if binary exists)")
	flag.Parse()
	if flag.NArg() != 0 {
		usage()
	}
	if *test {
		return
	}
	if os.Getenv("GO15VENDOREXPERIMENT") != "1" {
		fatal(errors.New("environment variable GO15VENDOREXPERIMENT not set to 1"))
	}
	commit, date, err := git.GetHead("", os.Stderr)
	if err != nil {
		fatal(err)
	}
	outfp := os.Stdout
	if *output != "" {
		if !commitChanged(*output, commit) {
			// nothing to write
			return
		}
		outfp, err = os.Create(*output)
		if err != nil {
			fatal(err)
		}
	}
	printCode(outfp, *release, commit, date)
}
Exemplo n.º 2
0
func updateMuteFromSource(outfp, statfp io.Writer, commit string) error {
	fmt.Fprintf(statfp, "updating Mute from source...\n")
	binary, err := exec.LookPath(os.Args[0])
	if err != nil {
		return err
	}
	fmt.Fprintf(statfp, "...binary path: %s\n", binary)

	// change to source directory github.com/mutecomm/mute
	dir := filepath.Join(filepath.Dir(binary), "..", "src", "github.com", "mutecomm", "mute")

	// git status --porcelain
	fmt.Fprintf(statfp, "$ git status --porcelain (CWD=%s)\n", dir)
	if err := git.Status(dir, statfp); err != nil {
		return log.Error(err)
	}

	// git checkout master
	fmt.Fprintf(statfp, "$ git checkout master\n")
	if err := git.Checkout(dir, "master", outfp, statfp); err != nil {
		return log.Error(err)
	}

	// git pull
	fmt.Fprintf(statfp, "$ git pull\n")
	if err := git.Pull(dir, outfp, statfp); err != nil {
		return err
	}

	// get current HEAD
	head, _, err := git.GetHead(dir, statfp)
	if err != nil {
		return log.Error(err)
	}

	// git checkout, if necessary
	var detached bool
	if head != commit {
		fmt.Fprintf(statfp, "$ git checkout\n")
		if err := git.Checkout(dir, commit, outfp, statfp); err != nil {
			return log.Error(err)
		}
		detached = true
	}

	// go install -v mute/cmd/mutegenerate
	fmt.Fprintf(statfp, "$ go install -v ./cmd/mutegenerate\n")
	if err := gotool.Install(dir, "./cmd/mutegenerate", outfp, statfp); err != nil {
		return log.Error(err)
	}

	// go generate -v mute/util/release
	fmt.Fprintf(statfp, "$ go generate -v ./release\n")
	err = gotool.Generate(dir, "./release", outfp, statfp)
	if err != nil {
		return log.Error(err)
	}

	// go install -v mute/cmd/...
	fmt.Fprintf(statfp, "$ go install -v ./cmd/...\n")
	if err := gotool.Install(dir, "./cmd/...", outfp, statfp); err != nil {
		return log.Error(err)
	}

	// go back to master, if necessary
	if detached {
		fmt.Fprintf(statfp, "$ git checkout master\n")
		if err := git.Checkout(dir, "master", outfp, statfp); err != nil {
			return log.Error(err)
		}
	}

	fmt.Fprintf(statfp, "Mute updated (restart it, if necessary)\n")
	return nil
}