Exemplo n.º 1
0
func BuildGo(cfg *config.Config, destbin, goos, goarch, targettype string) error {
	srcdir := cfg.Srcdir
	os.Chdir(cfg.Basedir())

	os.Setenv("GOPATH", filepath.Join(srcdir, "go"))
	if goarch != "" {
		os.Setenv("GOARCH", goarch)
	}

	if goos != "" {
		os.Setenv("GOOS", goos)
	}

	publisher_version := cfg.Publisherversion.String()
	binaryname := "sp"
	if goos == "windows" {
		binaryname += ".exe"
	}
	// separator should be " " or "=".
	// Old versions of Go use " ", newer versions use "=" for setting the linker flags
	separator := " "
	if tmp := os.Getenv("BUILDSEPERATOR"); tmp != "" {
		separator = tmp
	}

	// Now compile the go executable
	arguments := []string{"build", "-ldflags", fmt.Sprintf("-X main.dest%s%s -X main.version%s%s", separator, targettype, separator, publisher_version), "-o", filepath.Join(destbin, binaryname), "sp/main"}
	cmd := exec.Command("go", arguments...)
	outbuf, err := cmd.CombinedOutput()
	if err != nil {
		fmt.Println(string(outbuf))
		return err
	}
	return nil
}
Exemplo n.º 2
0
func DoThings(cfg *config.Config) error {

	r, err := os.Open(filepath.Join(cfg.Basedir(), "doc", "commands-xml", "commands.xml"))
	if err != nil {
		return err
	}
	c, err := commandsxml.ReadCommandsFile(r)
	if err != nil {
		return err
	}
	manualpath = filepath.Join(cfg.Builddir, "manual")

	for _, lang := range []string{"de", "en"} {
		docbase := filepath.Join(cfg.Builddir, "speedatapublisher-"+lang+".docset")
		destpath = filepath.Join(docbase, "Contents", "Resources", "Documents")
		plistpath := filepath.Join(docbase, "Contents", "info.plist")

		err = os.RemoveAll(docbase)
		if err != nil {
			return err
		}

		err = os.MkdirAll(destpath, 0755)
		if err != nil {
			return err
		}

		filepath.Walk(manualpath, cp)

		err = ioutil.WriteFile(plistpath, []byte(plist(lang)), 0644)
		if err != nil {
			return err
		}

		db, err := sql.Open("sqlite3", filepath.Join(docbase, "Contents", "Resources", "docSet.dsidx"))
		if err != nil {
			return err
		}
		defer db.Close()

		_, err = db.Exec(`CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);`)
		if err != nil {
			return err
		}

		for _, v := range c.CommandsEn {
			_, err = db.Exec(`INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?, ?, ?);`, v.NameEn, "Command", filepath.Join("commands-"+lang, v.Htmllink()))
			if err != nil {
				return err
			}
			for _, attr := range v.Attributes() {
				_, err = db.Exec(`INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?, ?, ?);`, attr.NameEn, "Function", filepath.Join("commands-"+lang, v.Htmllink()+"#"+attr.HTMLFragment()))
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
Exemplo n.º 3
0
func DoThings(cfg *config.Config) error {
	r, err := os.Open(filepath.Join(cfg.Basedir(), "doc", "commands-xml", "commands.xml"))
	if err != nil {
		return err
	}
	c, err := commandsxml.ReadCommandsFile(r)
	if err != nil {
		return err
	}
	for _, cmd := range c.CommandsEn {
		cmd.Childelements("en")
	}
	outdir := filepath.Join(cfg.Builddir, "manual")
	err = os.MkdirAll(outdir, 0755)
	if err != nil {
		return err
	}

	funcMap := template.FuncMap{
		"translate":      translate,
		"attributes":     attributes,
		"childelements":  childelements,
		"parentelements": parentelements,
		"sortedcommands": sortedcommands,
		"footer":         footer,
		"atttypeinfo":    atttypeinfo,
	}
	templates, err = template.New("").Funcs(funcMap).ParseFiles(filepath.Join(cfg.Basedir(), "doc", "manual", "templates", "command.html"))
	if err != nil {
		return err
	}
	os.MkdirAll(filepath.Join(outdir, "commands-en"), 0755)
	os.MkdirAll(filepath.Join(outdir, "commands-de"), 0755)

	version := cfg.Publisherversion.String()
	for _, lang := range []string{"de", "en"} {
		for _, v := range c.CommandsEn {
			fullpath := filepath.Join(outdir, "commands-"+lang, v.Htmllink())
			wg.Add(1)
			go builddoc(c, v, version, lang, fullpath)
		}
	}
	wg.Wait()
	return nil
}
Exemplo n.º 4
0
// Generate the html documentation and copy all necessary assets to the build directory
func DoThings(cfg *config.Config) error {
	var err error

	curwd, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}
	err = os.Chdir(filepath.Join(cfg.Basedir(), "doc", "manual"))
	if err != nil {
		log.Fatal(err)
	}

	defer os.Chdir(curwd)

	md := MDDoc{}
	md.root = "doc"
	md.dest = filepath.Join(cfg.Builddir, "manual")
	md.basedir = "."
	md.changelog = parseChangelog(filepath.Join(cfg.Basedir(), "doc", "changelog.xml"))
	md.assets = filepath.Join(cfg.Basedir(), "assets")
	md.renderer = blackfriday.HtmlRenderer(0, "", "")
	md.Version = cfg.Publisherversion.String()

	funcMap := template.FuncMap{
		"rootDoc": md.rootDoc,
		"footer":  md.footerHTML,
		"assets":  md.getAssetsDir,
		"root":    md.getRootDir,
	}

	err = os.MkdirAll(md.dest, 0755)
	if err != nil {
		return err
	}

	// text.template because we trust the input...
	templates, err = template.New("").Funcs(funcMap).ParseFiles(filepath.Join(md.basedir, "templates", "main.html"))
	if err != nil {
		return err
	}

	err = filepath.Walk(md.root, md.generateHTMLDocs)
	if err != nil {
		return err
	}

	md.writeFeed("en")
	md.writeFeed("de")
	return nil
}
Exemplo n.º 5
0
func MkBuilddir(cfg *config.Config, srcbindir string) error {
	// build dir contains the documentation
	if false {
		fmt.Println("xx")
	}

	var err error

	destdir := filepath.Join(cfg.Builddir, "speedata-publisher")
	os.RemoveAll(destdir)
	os.MkdirAll(destdir, 0755)

	srcdir := filepath.Join(cfg.Basedir(), "src")

	mapping := []struct {
		src    string
		dest   string
		reject []string
	}{
		{src: srcbindir, dest: filepath.Join(destdir, "sdluatex")},
		{src: filepath.Join(cfg.Builddir, "manual"), dest: filepath.Join(destdir, "share", "doc")},
		{src: filepath.Join(cfg.Basedir(), "lib"), dest: filepath.Join(destdir, "share", "lib")},
		{src: filepath.Join(cfg.Basedir(), "schema"), dest: filepath.Join(destdir, "share", "schema"), reject: []string{"changelog.rng", "readme.txt"}},
		{src: filepath.Join(cfg.Basedir(), "fonts"), dest: filepath.Join(destdir, "sw", "fonts")},
		{src: filepath.Join(cfg.Basedir(), "img"), dest: filepath.Join(destdir, "sw", "img")},
		{src: filepath.Join(srcdir, "tex"), dest: filepath.Join(destdir, "sw", "tex")},
		{src: filepath.Join(srcdir, "lua"), dest: filepath.Join(destdir, "sw", "lua"), reject: []string{"viznodelist.lua", "fileutils.lua"}},
		{src: filepath.Join(srcdir, "hyphenation"), dest: filepath.Join(destdir, "sw", "hyphenation")},
	}

	for _, v := range mapping {
		reject := append(v.reject, ".DS_Store")
		err = fileutils.CpR(v.src, v.dest, reject...)
		if err != nil {
			return err
		}
	}
	exefiles, err := filepath.Glob(filepath.Join(destdir, "bin", "*"))
	if err != nil {
		fmt.Println(err)
		os.Exit(-1)
	}
	for _, v := range exefiles {
		os.Chmod(v, 0755)
	}
	return nil
}