示例#1
0
文件: asetup.go 项目: hwaf/hwaf
func (a *asetup_t) handle_toolchain_section(lcfg *gocfg.Config, lcfg_fname string) error {
	var err error
	n := "hwaf-" + a.cmd.Name()

	section := "hwaf-toolchain"
	if !lcfg.HasSection(section) {
		if !lcfg.AddSection(section) {
			err = fmt.Errorf("%s: could not create section [%s] in file [%s]",
				n, section, lcfg_fname)
			if err != nil {
				return err
			}
		}
	}
	for k, v := range a.opts.toolchain {
		if lcfg.HasOption(section, k) {
			lcfg.RemoveOption(section, k)
		}
		ok := lcfg.AddOption(section, k, v)
		if !ok {
			err = fmt.Errorf(
				"%s: could not add option [%s=%q] to file [%s]",
				n, k, v, lcfg_fname,
			)
			if err != nil {
				return err
			}
		}
	}
	return err
}
示例#2
0
文件: asetup.go 项目: hwaf/hwaf
func (a *asetup_t) handle_env_section(lcfg *gocfg.Config, lcfg_fname, dirname string) error {
	var err error
	n := "hwaf-" + a.cmd.Name()

	section := "hwaf-env"
	if !lcfg.HasSection(section) {
		if !lcfg.AddSection(section) {
			err = fmt.Errorf("%s: could not create section [%s] in file [%s]",
				n, section, lcfg_fname)
			if err != nil {
				return err
			}
		}
	}
	// add a few asetup defaults...
	for k, v := range map[string]string{
		"SVNGROUPS": "svn+ssh://svn.cern.ch/reps/atlasgroups",
		"SVNGRP":    "svn+ssh://svn.cern.ch/reps/atlasgrp",
		"SVNINST":   "svn+ssh://svn.cern.ch/reps/atlasinst",
		"SVNOFF":    "svn+ssh://svn.cern.ch/reps/atlasoff",
		"SVNPERF":   "svn+ssh://svn.cern.ch/reps/atlasperf",
		"SVNPHYS":   "svn+ssh://svn.cern.ch/reps/atlasphys",
		"SVNROOT":   "svn+ssh://svn.cern.ch/reps/atlasoff",
		"SVNUSR":    "******",
		"TestArea":  dirname,
	} {
		a.opts.env[k] = v
	}

	for k, v := range a.opts.env {
		if lcfg.HasOption(section, k) {
			lcfg.RemoveOption(section, k)
		}
		ok := lcfg.AddOption(section, k, v)
		if !ok {
			err = fmt.Errorf(
				"%s: could not add option [%s=%q] to file [%s]",
				n, k, v, lcfg_fname,
			)
			if err != nil {
				return err
			}
		}
	}

	return err
}
示例#3
0
func hwaf_run_cmd_setup(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-" + cmd.Name()
	dirname := "."
	switch len(args) {
	case 0:
		dirname = "."
	case 1:
		dirname = args[0]
	default:
		err = fmt.Errorf("%s: you need to give a directory name", n)
		handle_err(err)
	}

	dirname = os.ExpandEnv(dirname)
	dirname = filepath.Clean(dirname)

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)
	cfg_fname := cmd.Flag.Lookup("cfg").Value.Get().(string)
	pkgdir := cmd.Flag.Lookup("pkgdir").Value.Get().(string)
	variant := cmd.Flag.Lookup("variant").Value.Get().(string)
	tags := cmd.Flag.Lookup("tags").Value.Get().(string)

	projdirs := []string{}
	const pathsep = string(os.PathListSeparator)
	for _, v := range strings.Split(cmd.Flag.Lookup("p").Value.Get().(string), pathsep) {
		if v != "" {
			v = os.ExpandEnv(v)
			v = filepath.Clean(v)
			projdirs = append(projdirs, v)
		}
	}

	if verbose {
		fmt.Printf("%s: setup workarea [%s]...\n", n, dirname)
		fmt.Printf("%s: projects=%v\n", n, projdirs)
		if cfg_fname != "" {
			fmt.Printf("%s: cfg-file=%s\n", n, cfg_fname)
		}
	}

	if cfg_fname != "" && !path_exists(cfg_fname) {
		err = fmt.Errorf("configuration file [%s] does not exist (or is not readable)", cfg_fname)
		handle_err(err)
	}

	for _, projdir := range projdirs {
		if !path_exists(projdir) {
			err = fmt.Errorf("no such directory: [%s]", projdir)
			handle_err(err)
		}

		pinfo := filepath.Join(projdir, "project.info")
		if !path_exists(pinfo) {
			err = fmt.Errorf("no such file: [%s]", pinfo)
			handle_err(err)
		}
	}

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

	err = os.Chdir(dirname)
	handle_err(err)

	if verbose {
		fmt.Printf("%s: create local config...\n", n)
	}

	var lcfg *gocfg.Config
	lcfg_fname := "local.conf"

	// if the user provided a configuration file use that as a default
	if cfg_fname != "" && path_exists(cfg_fname) {
		lcfg, err = gocfg.ReadDefault(cfg_fname)
		handle_err(err)
	} else {
		if path_exists(lcfg_fname) {
			lcfg, err = gocfg.ReadDefault(lcfg_fname)
			handle_err(err)
		} else {
			lcfg = gocfg.NewDefault()
		}
	}

	section := "hwaf-cfg"
	if !lcfg.HasSection(section) && !lcfg.AddSection(section) {
		err = fmt.Errorf("%s: could not create section [%s] in file [%s]",
			n, section, lcfg_fname)
		handle_err(err)
	}

	// fetch a few informations from the first project.info
	cmtcfg := g_ctx.Cmtcfg()
	//projvers := time.Now().Format("20060102")
	if len(projdirs) > 0 {
		pinfo, err := hwaflib.NewProjectInfo(filepath.Join(projdirs[0], "project.info"))
		handle_err(err)
		cmtcfg, err = pinfo.Get("CMTCFG")
		handle_err(err)
	}

	if variant != "" {
		cmtcfg = variant
	}

	if tags != "" {
		tags_slice := strings.Split(tags, ",")
		tags = strings.Join(tags_slice, " ")
	}

	for k, v := range map[string]string{
		"projects": strings.Join(projdirs, pathsep),
		"pkgdir":   pkgdir,
		"cmtcfg":   cmtcfg,
		"tags":     tags,
	} {
		if lcfg.HasOption(section, k) {
			lcfg.RemoveOption(section, k)
		}
		if !lcfg.AddOption(section, k, v) {
			err := fmt.Errorf("%s: could not add option [%s] to section [%s]",
				n, k, section,
			)
			handle_err(err)
		}
	}

	err = lcfg.WriteFile(lcfg_fname, 0600, "")
	handle_err(err)

	if verbose {
		fmt.Printf("%s: setup workarea [%s]... [ok]\n", n, dirname)
	}
}