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: // }
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) } } }
// Default build function for Dev packages. // Implement your own if you prefer func GenDevArtifact(ddpkg *deb.Package, build *BuildParams, mappedFiles map[string]string) error { artifacts, err := deb.NewDebWriters(ddpkg) if err != nil { return err } for arch, artifact := range artifacts { dgen := NewDebGenerator(artifact, build) dgen.OrigFiles = mappedFiles err = dgen.GenerateAllDefault() if err != nil { return fmt.Errorf("Error building for '%s': %v", arch, err) } } return err }
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) } } }
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) } } }