예제 #1
0
파일: wafcontext.go 프로젝트: hwaf/hwaf
func waf_gen_wscript_from_yml(fname string) error {
	var err error
	hscript := filepath.Join(filepath.Dir(fname), "hscript.yml")
	f, err := os.Open(hscript)
	if err != nil {
		return err
	}
	// FIXME: don't gobble up the whole file. read piecewise
	buf, err := ioutil.ReadAll(f)
	if err != nil {
		return err
	}

	f, err = os.Create(fname)
	if err != nil {
		return err
	}
	defer f.Close()

	err = waf_gen_wscript_hdr(f)
	if err != nil {
		return err
	}

	data := make(map[string]interface{})
	err = yaml.Unmarshal(buf, data)
	if err != nil {
		return fmt.Errorf("error decoding file [%s]: %v", hscript, err)
	}

	wscript, err := waf_get_wscript(data)
	if err != nil {
		return fmt.Errorf("error parsing file [%s]:\n%v", hscript, err)
	}

	enc := hlib.NewHscriptPyEncoder(f)
	if enc == nil {
		return fmt.Errorf("error creating HscriptPyEncoder for file [%s]", fname)
	}

	err = enc.Encode(wscript)
	if err != nil {
		return err
	}

	return err
}
예제 #2
0
func newRelease(r io.Reader) (*Release, error) {
	var err error
	release := &Release{
		PackageDb: make(PackageDb),
		lcgApps:   make(map[string]struct{}),
		lcgExts:   make(map[string]struct{}),
	}

	scan := bufio.NewScanner(r)
	for scan.Scan() {
		line := scan.Text()
		line = strings.Trim(line, " \r\n\t")
		if line == "" {
			continue
		}
		if line[0] == '#' {
			continue
		}
		if strings.HasPrefix(line, "COMPILER: ") {
			fields := strings.Split(line, " ")
			name := fields[1]
			vers := fields[2]
			release.Toolchain = Toolchain{Name: name, Version: vers}
			continue
		}

		fields := strings.Split(line, ";")
		pkg, err := newPackage(fields)
		if err != nil {
			return nil, err
		}
		msg.Debugf("%v (%v) %v\n", pkg.Name, pkg.Version, pkg.Deps)

		if _, exists := release.PackageDb[pkg.Id]; exists {
			handle_err(
				fmt.Errorf("package %v already in package-db:\nold: %#v\nnew: %#v\n",
					pkg.Id,
					release.PackageDb[pkg.Id],
					pkg,
				),
			)
		}
		release.PackageDb[pkg.Id] = pkg

		if pkg.Name == "LCGCMT" {
			release.lcg = pkg
		}
		switch pkg.Name {
		case "ROOT", "RELAX", "COOL", "CORAL":
			release.lcgApps[pkg.Name] = struct{}{}
		}
	}

	err = scan.Err()
	if err != nil && err != io.EOF {
		return nil, err
	}

	{
		f, err := locateLcgExtAsset(release.lcg.Version)
		if err != nil {
			return nil, err
		}
		defer f.Close()
		exts := []string{}
		buf, err := ioutil.ReadAll(f)
		if err != nil {
			return nil, err
		}
		err = goyaml.Unmarshal(buf, &exts)
		if err != nil {
			return nil, err
		}

		for _, ext := range exts {
			release.lcgExts[ext] = struct{}{}
		}
	}

	return release, nil
}
예제 #3
0
파일: cmd_build.go 프로젝트: pzduniak/meta
func cmd_run_build(cmd *commander.Command, args []string) {
	// shall we stfu
	//verbose := g_cmd.Flag.Lookup("v").Value.Get().(bool)
	// get Metafile's path
	name := cmd.Flag.Lookup("p").Value.Get().(string)
	// print what file are we building
	log.Printf("Building %s", name)

	// load the file
	buffer, err := ioutil.ReadFile(name)
	if err != nil {
		// handle yo errors
		log.Printf("ERROR: %v", err)
		os.Exit(1)
	}

	// create an instance of a metafile
	meta := Metafile{}
	// and create a new XML file
	output := axml.NewDocument("meta")

	// put yaml data into the instance
	err = yaml.Unmarshal(buffer, &meta)
	if err != nil {
		// probably YAML syntax error
		log.Printf("ERROR: %v", err)
		os.Exit(1)
	}

	// Ensure that meta exists
	if meta.Meta == nil {
		log.Print("ERROR: meta key has to exist")
		os.Exit(1)
	}

	// Add <info>
	info := axml.NewNode("info")
	info.Attributes = meta.Meta
	output.Root.AddNode(info)

	var scriptlist []*Script
	scriptlist = make([]*Script)

	for _, mf := range meta.Scripts {
		matches, err := filepath.Glob(filepath.Join(meta.Source, mf.Path))

		if err != nil {
			panic(err)
		}

		for _, match := range matches {
			script := axml.NewNode("script")
			script.Attributes = map[string]string{
				"src":  match,
				"type": mf.Type,
			}
			output.Root.AddNode(script)
		}
	}

	log.Print(output.Render(false))
}
예제 #4
0
파일: main.go 프로젝트: sbinet/go-bldbot
func main() {
	fmt.Printf(">>>\n>>> buildbot <<<\n>>>\n")
	flag.Parse()

	config := Config{
		Slaves: make([]Slave, 0, 2),
	}
	f, err := os.Open(*g_config)
	if err != nil {
		log.Panicf("buildbot: could not open file [%s] (%v)\n", *g_config, err)
	}
	defer f.Close()
	in, err := ioutil.ReadAll(f)
	err = yml.Unmarshal(in, &config)
	if err != nil {
		log.Panicf("buildbot: could not decode file [%s] (%v)\n", *g_config, err)
	}

	if len(config.Slaves) <= 0 {
		log.Printf("buildbot: found no slave to send work to.\n")
		os.Exit(2)
	}

	slaves := config.Slaves
	//fmt.Printf(">>> %v\n", slaves)
	builders := make([]*Builder, 0, len(slaves))

	for _, slave := range slaves {
		err = slave.Ping()
		if err != nil {
			log.Printf("%s\n", err.Error())
			continue
		}
		//fmt.Printf("--- slave [%s] ---\n%v\n", slave.Name, string(out))
		err = os.MkdirAll("logs", 0755)
		if err != nil {
			log.Panicf("could create logs directory ! (err=%v)\n", err)
		}

		err = os.MkdirAll("output", 0755)
		if err != nil {
			log.Panicf("could create output directory ! (err=%v)\n", err)
		}

		fname := filepath.Join("logs", fmt.Sprintf("%s.txt", slave.Name))
		logfile, err := os.Create(fname)
		if err != nil {
			log.Printf(
				"could not create logfile [%s] for slave [%s] (err=%v)\n",
				fname, slave.Name, err,
			)
		}
		tmpdir, err := ioutil.TempDir("", "go-bldbot-"+time.Now().Format("20060102")+"-")
		if err != nil {
			log.Panicf("could not create tempdir for slave [%s] (err=%v)\n",
				slave.Name, err,
			)
		}
		slave.Path = tmpdir
		os.RemoveAll(tmpdir)

		builders = append(builders, &Builder{
			slave: slave,
			w:     logfile,
		})
	}

	fmt.Printf(">>> found the following builders:\n")
	for _, builder := range builders {
		fmt.Printf(
			" %s \t(%s:%s)\n",
			builder.slave.Name,
			builder.slave.Addr,
			builder.slave.Path,
		)
	}

	fmt.Printf(">>> launching builders... (parallel=%v)\n", *g_parallel)
	done := make(chan BuildReport)
	allgood := true
	for _, builder := range builders {
		fmt.Printf(" %s...\n", builder.slave.Name)
		if *g_parallel {
			go func(builder *Builder) {
				done <- builder.run()
			}(builder)
		} else {
			resp := builder.run()
			if resp.err != nil {
				log.Printf(
					"build failed for slave [%s]:\n%v\nmsg=%s\n",
					resp.slave.Name, resp.err, resp.msg,
				)
				allgood = false
				continue
			}
		}
	}
	fmt.Printf(">>> launching builders... (parallel=%v) [done]\n", *g_parallel)

	if *g_parallel {
		for _ = range builders {
			report := <-done
			if report.err != nil {
				log.Printf(
					"build failed for slave [%s]:\n%v\n",
					report.slave.Name, report.err,
				)
				allgood = false
				continue
			}
		}
	}

	fmt.Printf(">>> all good: %v\n", allgood)
	if !allgood {
		os.Exit(1)
	}
}