示例#1
0
文件: main.go 项目: hwaf/hwaf
func main() {

	var err error
	pwd, err := os.Getwd()
	handle_err(err)

	wdir := pwd
	if len(os.Args) > 1 {
		switch os.Args[1] {
		case "init", "setup", "asetup":
			// these are supposed to *create* the .hwaf directory...

		default:
			wdir = func() string {
				// try to find a workarea in a parent dir:
				for dir := wdir; dir != "/"; dir = filepath.Dir(dir) {
					if path_exists(filepath.Join(dir, ".hwaf")) {
						return dir
					}
				}
				return ""
			}()
		}
	}

	switch wdir {
	case "":
		g_ctx, err = hwaflib.NewContext()
		handle_err(err)
	default:
		g_ctx, err = hwaflib.NewContextFrom(wdir)
		handle_err(err)
	}

	if len(os.Args) == 1 {
		if path_exists("wscript") {
			os.Args = append(os.Args, "waf", "build+install")
		} else {
			g_ctx.Errorf("'hwaf' needs a command to run (or be executed from a directory containing a wscript file.)\n")
			g_ctx.Errorf("run 'hwaf help' for informations\n")
			os.Exit(1)
		}
	}

	err = g_cmd.Flag.Parse(os.Args[1:])
	handle_err(err)

	args := g_cmd.Flag.Args()
	err = g_cmd.Dispatch(args)
	handle_err(err)

	g_ctx.Exit(0)
	return
}
示例#2
0
func main() {
	var err error

	flag.Parse()
	if *g_out == "" || *g_out == "." {
		*g_out, err = os.Getwd()
		handle_err(err)
	}
	if !path_exists(*g_out) {
		err = os.MkdirAll(*g_out, 0755)
		if err != nil {
			fmt.Fprintf(os.Stderr, "**error**: could not create directory [%s]: %v\n", *g_out, err)
		}
		handle_err(err)
	}

	g_pkglist = flag.Args()

	g_ctx, err = hwaflib.NewContext()
	handle_err(err)

	pwd, err := os.Getwd()
	handle_err(err)

	g_ctx, err = hwaflib.NewContextFrom(pwd)
	handle_err(err)

	pinfo, err := g_ctx.ProjectInfos()
	handle_err(err)

	pkgs, err := collect_pkgs()
	handle_err(err)

	if *g_list {
		for _, pkg := range pkgs {
			fmt.Printf("=> %-20s (version=%s)\n", pkg.Name, pkg.Version)
		}
	} else {

		err = pack_pkgs(pkgs)
		if err != nil {
			fmt.Fprintf(os.Stderr, "*** error packing tarball: %v\n", err)
			os.Exit(1)
		}

		proj_name := *g_packname
		proj_vers := *g_packvers

		if *g_packall {
			if *g_packname == "" {
				proj_name, err = pinfo.Get("HWAF_BDIST_APPNAME")
				if err != nil {
					fmt.Fprintf(os.Stderr, "*** error retrieving HWAF_BDIST_APPNAME: %v\n", err)
					os.Exit(1)
				}
			}
			if *g_packvers == "" {
				proj_vers, err = pinfo.Get("HWAF_BDIST_VERSION")
				if err != nil {
					fmt.Fprintf(os.Stderr, "*** error retrieving HWAF_BDIST_VERSION: %v\n", err)
					os.Exit(1)
				}
			}

			fmt.Printf(">>> %s-%s.tar.gz\n", proj_name, proj_vers)
			err = pack_project(pkgs, proj_name, proj_vers)
			if err != nil {
				fmt.Fprintf(os.Stderr, "*** error packing project-level tarball: %v\n", err)
				os.Exit(1)
			}
		}
	}

	os.Exit(0)
}