Exemplo n.º 1
0
func Example_genBinaryPackage() {

	pkg := deb.NewPackage("testpkg", "0.0.2", "me <*****@*****.**>", "Dummy package for doing nothing\n")

	build := debgen.NewBuildParams()
	build.Init()
	build.IsRmtemp = false

	artifacts, err := deb.NewDebWriters(pkg)
	if err != nil {
		log.Fatalf("Error building binary: %v", err)
	}
	artifacts[deb.ArchAmd64].MappedFiles = map[string]string{"/usr/bin/a": "_out/a.amd64"}
	artifacts[deb.ArchI386].MappedFiles = map[string]string{"/usr/bin/a": "_out/a.i386"}
	artifacts[deb.ArchArmhf].MappedFiles = map[string]string{"/usr/bin/a": "_out/a.armhf"}

	prep() //prepare files for packaging using some other means.

	for arch, artifact := range artifacts {
		log.Printf("generating artifact '%s'/%v", arch, artifact)
		dgen := debgen.NewDebGenerator(artifact, build)
		err = dgen.GenerateAllDefault()
		if err != nil {
			log.Fatalf("Error building for '%s': %v", arch, err)
		}
	}

	// Output:
	//
}
Exemplo n.º 2
0
func Example_buildBinaryDeb() {

	pkg := deb.NewPackage("testpkg", "0.0.2", "me", "lovely package\n")
	pkg.Description = "hiya"
	exesMap := map[string][]string{
		"amd64": []string{filepath.Join(deb.TempDirDefault, "/a.amd64")},
		"i386":  []string{filepath.Join(deb.TempDirDefault, "/a.i386")},
		"armhf": []string{filepath.Join(deb.TempDirDefault, "/a.armhf")}}
	err := createExes(exesMap)
	if err != nil {
		log.Fatalf("%v", err)
	}
	artifacts, err := deb.NewDebWriters(pkg)
	if err != nil {
		log.Fatalf("Error building binary: %v", err)
	}
	artifacts[deb.ArchAmd64].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.amd64")}
	artifacts[deb.ArchI386].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.i386")}
	artifacts[deb.ArchArmhf].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.armhf")}
	buildDeb := func(art *deb.DebWriter) error {
		//generate artifact here ...
		return nil
	}
	for arch, artifact := range artifacts {
		//build binary deb here ...
		err = buildDeb(artifact)
		if err != nil {
			log.Fatalf("Error building for '%s': %v", arch, err)
		}
	}
}
Exemplo n.º 3
0
func Example_genSourcePackage() {

	pkg := deb.NewPackage("testpkg", "0.0.2", "me <*****@*****.**>", "Dummy package for doing nothing\n")
	build := debgen.NewBuildParams()
	build.IsRmtemp = false
	debgen.ApplyGoDefaults(pkg)
	spkg := deb.NewSourcePackage(pkg)
	err := build.Init()
	if err != nil {
		log.Fatalf("Error initializing dirs: %v", err)
	}
	spgen := debgen.NewSourcePackageGenerator(spkg, build)
	spgen.ApplyDefaultsPureGo()
	sourcesDestinationDir := pkg.Name + "_" + pkg.Version
	sourceDir := ".."
	sourcesRelativeTo := debgen.GetGoPathElement(sourceDir)
	spgen.OrigFiles, err = debgen.GlobForSources(sourcesRelativeTo, sourceDir, debgen.GlobGoSources, sourcesDestinationDir, []string{build.TmpDir, build.DestDir})
	if err != nil {
		log.Fatalf("Error resolving sources: %v", err)
	}
	err = spgen.GenerateAllDefault()

	if err != nil {
		log.Fatalf("Error building source: %v", err)
	}

	// Output:
	//
}
Exemplo n.º 4
0
func TestCopy(t *testing.T) {
	pkg := deb.NewPackage("a", "1", "me", "desc")
	npkg := deb.Copy(pkg)
	if pkg == npkg {
		t.Errorf("Copy returned the same reference - not a copy")
	}
	if pkg.Name != npkg.Name {
		t.Errorf("Copy didn't copy the same Name value")
	}
	t.Logf("Original: %+v", pkg)
	t.Logf("Copy:     %+v", npkg)
}
Exemplo n.º 5
0
func Example_buildDevPackage() {

	pkg := deb.NewPackage("testpkg", "0.0.2", "me", "A package\ntestpkg is a lovel package with many wow")
	buildFunc := func(dpkg *deb.Package) error {
		// Generate files here.
		return nil
	}
	dpkg := deb.NewDevPackage(pkg)
	err := buildFunc(dpkg)
	if err != nil {
		log.Fatalf("%v", err)
	}
}
Exemplo n.º 6
0
func Test_buildSourceDeb(t *testing.T) {
	pkg := deb.NewPackage("testpkg", "0.0.2", "me <[email protected]>", "Nice of all the package\n")
	pkg.Description = "hiya"
	spkg := deb.NewSourcePackage(pkg)
	err := buildOrigArchive(spkg) // it's up to you how to build this
	if err != nil {
		t.Fatalf("Error building source package: %v", err)
	}
	err = buildDebianArchive(spkg) // again - do it yourself
	if err != nil {
		t.Fatalf("Error building source package: %v", err)
	}
	err = buildDscFile(spkg) // yep, same again
	if err != nil {
		t.Fatalf("Error building source package: %v", err)
	}
}
Exemplo n.º 7
0
func main() {
	name := "debgen-dev"
	log.SetPrefix("[" + name + "] ")
	//set to empty strings because they're being overridden
	pkg := deb.NewPackage("", "", "", "")
	build := debgen.NewBuildParams()
	debgen.ApplyGoDefaults(pkg)
	fs := cmdutils.InitFlags(name, pkg, build)
	fs.StringVar(&pkg.Architecture, "arch", "all", "Architectures [any,386,armhf,amd64,all]")
	ddpkg := deb.NewDevPackage(pkg)

	var sourceDir string
	var glob string
	var sourcesRelativeTo string
	var sourcesDestinationDir string
	fs.StringVar(&sourceDir, "sources", build.WorkingDir, "source dir")
	fs.StringVar(&glob, "sources-glob", debgen.GlobGoSources, "Glob for inclusion of sources")
	fs.StringVar(&sourcesRelativeTo, "sources-relative-to", "", "Sources relative to (it will assume relevant gopath element, unless you specify this)")
	fs.StringVar(&sourcesDestinationDir, "sources-destination", debgen.DevGoPathDefault, "Destination dir for sources to be installed")
	err := cmdutils.ParseFlags(name, pkg, fs)
	if err != nil {
		log.Fatalf("%v", err)
	}

	if sourcesRelativeTo == "" {
		sourcesRelativeTo = debgen.GetGoPathElement(sourceDir)
	}
	mappedFiles, err := debgen.GlobForSources(sourcesRelativeTo, sourceDir, glob, sourcesDestinationDir, []string{build.TmpDir, build.DestDir})
	if err != nil {
		log.Fatalf("Error resolving sources: %v", err)
	}
	err = build.Init()
	if err != nil {
		log.Fatalf("Error creating build directories: %v", err)
	}
	err = debgen.GenDevArtifact(ddpkg, build, mappedFiles)
	if err != nil {
		log.Fatalf("Error building -dev: %v", err)
	}

}
Exemplo n.º 8
0
func Example_genDevPackage() {
	pkg := deb.NewPackage("testpkg", "0.0.2", "me", "Dummy package for doing nothing\n")

	ddpkg := deb.NewDevPackage(pkg)
	build := debgen.NewBuildParams()
	build.IsRmtemp = false
	build.Init()
	var err error
	mappedFiles, err := debgen.GlobForGoSources(".", []string{build.TmpDir, build.DestDir})
	if err != nil {
		log.Fatalf("Error building -dev: %v", err)
	}

	err = debgen.GenDevArtifact(ddpkg, build, mappedFiles)
	if err != nil {
		log.Fatalf("Error building -dev: %v", err)
	}

	// Output:
	//
}
Exemplo n.º 9
0
func main() {
	name := "debgen-source"
	log.SetPrefix("[" + name + "] ")
	//set to empty strings because they're being overridden
	pkg := deb.NewPackage("", "", "", "")
	build := debgen.NewBuildParams()
	debgen.ApplyGoDefaults(pkg)
	fs := cmdutils.InitFlags(name, pkg, build)
	fs.StringVar(&pkg.Architecture, "arch", "all", "Architectures [any,386,armhf,amd64,all]")

	var sourceDir string
	var glob string
	var sourcesRelativeTo string
	fs.StringVar(&sourceDir, "sources", ".", "source dir")
	fs.StringVar(&glob, "sources-glob", debgen.GlobGoSources, "Glob for inclusion of sources")
	fs.StringVar(&sourcesRelativeTo, "sources-relative-to", "", "Sources relative to (it will assume relevant gopath element, unless you specify this)")
	err := cmdutils.ParseFlags(name, pkg, fs)
	if err != nil {
		log.Fatalf("%v", err)
	}
	err = build.Init()
	if err != nil {
		log.Fatalf("Error creating build directories: %v", err)
	}
	if sourcesRelativeTo == "" {
		sourcesRelativeTo = debgen.GetGoPathElement(sourceDir)
	}
	spkg := deb.NewSourcePackage(pkg)
	sourcesDestinationDir := pkg.Name + "_" + pkg.Version
	spgen := debgen.NewSourcePackageGenerator(spkg, build)
	spgen.OrigFiles, err = debgen.GlobForSources(sourcesRelativeTo, sourceDir, glob, sourcesDestinationDir, []string{build.TmpDir, build.DestDir})
	if err != nil {
		log.Fatalf("Error resolving sources: %v", err)
	}
	err = spgen.GenerateAllDefault()
	if err != nil {
		log.Fatalf("%v", err)
	}

}
Exemplo n.º 10
0
func main() {
	name := "debgen-changelog"
	log.SetPrefix("[" + name + "] ")
	//set to empty strings because they're being overridden
	pkg := deb.NewPackage("", "", "", "")
	build := debgen.NewBuildParams()
	debgen.ApplyGoDefaults(pkg)
	fs := cmdutils.InitFlags(name, pkg, build)
	fs.StringVar(&pkg.Architecture, "arch", "all", "Architectures [any,386,armhf,amd64,all]")
	var entry string
	fs.StringVar(&entry, "entry", "", "Changelog entry data")

	err := cmdutils.ParseFlags(name, pkg, fs)
	if err != nil {
		log.Fatalf("%v", err)
	}
	if entry == "" {
		log.Fatalf("Error: --entry is a required flag")

	}
	filename := filepath.Join(build.ResourcesDir, "debian", "changelog")
	templateVars := debgen.NewTemplateData(pkg)
	templateVars.ChangelogEntry = entry
	err = os.MkdirAll(filepath.Join(build.ResourcesDir, "debian"), 0777)
	if err != nil {
		log.Fatalf("Error making dirs: %v", err)
	}

	_, err = os.Stat(filename)
	if os.IsNotExist(err) {
		tpl, err := template.New("template").Parse(debgen.TemplateChangelogInitial)
		if err != nil {
			log.Fatalf("Error parsing template: %v", err)
		}
		//create ..
		f, err := os.Create(filename)
		if err != nil {
			log.Fatalf("Error creating file: %v", err)
		}
		defer f.Close()
		err = tpl.Execute(f, templateVars)
		if err != nil {
			log.Fatalf("Error executing template: %v", err)
		}
		err = f.Close()
		if err != nil {
			log.Fatalf("Error closing written file: %v", err)
		}
	} else if err != nil {
		log.Fatalf("Error reading existing changelog: %v", err)
	} else {
		tpl, err := template.New("template").Parse(debgen.TemplateChangelogAdditionalEntry)
		if err != nil {
			log.Fatalf("Error parsing template: %v", err)
		}
		//append..
		f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0666)
		if err != nil {
			log.Fatalf("Error opening file: %v", err)
		}
		defer f.Close()
		err = tpl.Execute(f, templateVars)
		if err != nil {
			log.Fatalf("Error executing template: %v", err)
		}
		err = f.Close()
		if err != nil {
			log.Fatalf("Error closing written file: %v", err)
		}
	}

}
Exemplo n.º 11
0
func Test_buildBinaryDeb(t *testing.T) {

	pkg := deb.NewPackage("testpkg", "0.0.2", "me", "lovely package\n")
	exesMap := map[string][]string{
		"amd64": []string{filepath.Join(deb.TempDirDefault, "a.amd64")},
		"i386":  []string{filepath.Join(deb.TempDirDefault, "a.i386")},
		"armhf": []string{filepath.Join(deb.TempDirDefault, "a.armhf")}}
	err := createExes(exesMap)
	if err != nil {
		t.Fatalf("%v", err)
	}
	artifacts, err := deb.NewDebWriters(pkg)
	if err != nil {
		t.Fatalf("Error building binary: %v", err)
	}
	artifacts[deb.ArchAmd64].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.amd64")}
	artifacts[deb.ArchI386].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.i386")}
	artifacts[deb.ArchArmhf].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.armhf")}
	buildDeb := func(art *deb.DebWriter) error {
		archiveFilename := filepath.Join(deb.TempDirDefault, art.ControlArchive)
		controlTgzw, err := targz.NewWriterFromFile(archiveFilename)
		if err != nil {
			return err
		}
		controlData := []byte("Package: testpkg\n")
		//TODO add more files here ...
		header := &tar.Header{Name: "control", Size: int64(len(controlData)), Mode: int64(644), ModTime: time.Now()}
		err = controlTgzw.WriteHeader(header)
		if err != nil {
			return err
		}
		_, err = controlTgzw.Write(controlData)
		if err != nil {
			return err
		}
		err = controlTgzw.Close()
		if err != nil {
			return err
		}

		archiveFilename = filepath.Join(deb.TempDirDefault, art.DataArchive)
		dataTgzw, err := targz.NewWriterFromFile(archiveFilename)
		if err != nil {
			return err
		}
		//TODO add files here ...
		err = dataTgzw.Close()
		if err != nil {
			return err
		}
		//generate artifact here ...
		err = art.Build(deb.TempDirDefault, deb.DistDirDefault)
		if err != nil {
			return err
		}
		return nil
	}
	for arch, artifact := range artifacts {
		//build binary deb here ...
		err = buildDeb(artifact)
		if err != nil {
			t.Fatalf("Error building for '%s': %v", arch, err)
		}
	}
}
Exemplo n.º 12
0
func main() {
	name := "debgen-deb"
	log.SetPrefix("[" + name + "] ")
	//set to empty strings because they're being overridden
	pkg := deb.NewPackage("", "", "", "")
	build := debgen.NewBuildParams()
	debgen.ApplyGoDefaults(pkg)
	fs := cmdutils.InitFlags(name, pkg, build)

	var binDir string
	var resourcesDir string
	fs.StringVar(&binDir, "binaries", "", "directory containing binaries for each architecture. Directory names should end with the architecture")
	fs.StringVar(&pkg.Architecture, "arch", "any", "Architectures [any,386,armhf,amd64,all]")
	fs.StringVar(&resourcesDir, "resources", "", "directory containing resources for this platform")
	err := cmdutils.ParseFlags(name, pkg, fs)
	if err != nil {
		log.Fatalf("%v", err)
	}
	err = build.Init()
	if err != nil {
		log.Fatalf("%v", err)
	}

	//log.Printf("Resources: %v", build.Resources)
	// TODO determine this platform
	//err = bpkg.Build(build, debgen.GenBinaryArtifact)
	artifacts, err := deb.NewDebWriters(pkg)
	if err != nil {
		log.Fatalf("%v", err)
	}
	for arch, artifact := range artifacts {
		dgen := debgen.NewDebGenerator(artifact, build)
		err = filepath.Walk(resourcesDir, func(path string, info os.FileInfo, err2 error) error {
			if info != nil && !info.IsDir() {
				rel, err := filepath.Rel(resourcesDir, path)
				if err == nil {
					dgen.OrigFiles[rel] = path
				}
				return err
			}
			return nil
		})
		if err != nil {
			log.Fatalf("%v", err)
		}

		archBinDir := filepath.Join(binDir, string(arch))

		err = filepath.Walk(archBinDir, func(path string, info os.FileInfo, err2 error) error {
			if info != nil && !info.IsDir() {
				rel, err := filepath.Rel(binDir, path)
				if err == nil {
					dgen.OrigFiles[rel] = path
				}
				return err
			}
			return nil
		})
		err = dgen.GenerateAllDefault()
		if err != nil {
			log.Fatalf("Error building for '%s': %v", arch, err)
		}
	}
}