func Example_buildBinaryDeb() { pkg := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) 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.NewWriters(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.Writer) 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) } } }
func Example_genDevPackage() { ctrl := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) spara := ctrl.GetParasByField(deb.SourceFName, "testpkg") bpara := ctrl.GetParasByField(deb.PackageFName, "testpkg-dev") nctrl := &deb.Control{spara[0], bpara[0]} 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) } artifacts, err := deb.NewWriters(nctrl) if err != nil { log.Fatalf("Error building -dev: %v", err) } for _, artifact := range artifacts { dgen := debgen.NewDebGenerator(artifact, build) dgen.DataFiles = mappedFiles err = dgen.GenerateAllDefault() if err != nil { log.Fatalf("Error building -dev: %v", err) } } // Output: // }
func Example_genBinaryPackage() { ctrl := deb.NewControlDefault("testpkg", "me", "<*****@*****.**>", "Dummy package for doing nothing", "testpkg is a dummy package", true) for _, pkg := range ctrl.BinaryParas() { pkg.Set(deb.VersionFName, "0.0.2") } build := debgen.NewBuildParams() build.Init() build.IsRmtemp = false artifacts, err := deb.NewWriters(ctrl) 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_genSourcePackage() { ctrl := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) build := debgen.NewBuildParams() build.IsRmtemp = false debgen.ApplyGoDefaults(ctrl) spkg := deb.NewSourcePackage(ctrl) err := build.Init() if err != nil { log.Fatalf("Error initializing dirs: %v", err) } spgen := debgen.NewSourcePackageGenerator(spkg, build) spgen.ApplyDefaultsPureGo() sourcesDestinationDir := ctrl.Get(deb.SourceFName) + "_" + ctrl.Get(deb.VersionFName) 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: // }
func TestCopy(t *testing.T) { ctrl := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) nctrl := deb.Copy(ctrl) if ctrl == nctrl { t.Errorf("Copy returned the same reference - not a copy") } if ctrl.Get(deb.PackageFName) != nctrl.Get(deb.PackageFName) { t.Errorf("Copy didn't copy the same Name value") } t.Logf("Original: %+v", ctrl) t.Logf("Copy: %+v", nctrl) }
func Example_buildDevPackage() { ctrl := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) buildFunc := func(dpkg *deb.Control) error { // Generate files here. return nil } spara := ctrl.GetParasByField(deb.SourceFName, "testpkg") bpara := ctrl.GetParasByField(deb.PackageFName, "testpkg-dev") nctrl := deb.Control{spara[0], bpara[0]} err := buildFunc(&nctrl) if err != nil { log.Fatalf("%v", err) } }
func Test_buildSourceDeb(t *testing.T) { pkg := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) 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) } }
func Test_buildBinaryDeb(t *testing.T) { pkg := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true) 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.NewWriters(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.Writer) 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 } err = os.MkdirAll(deb.DistDirDefault, 0777) 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 checksums(path, name string) (*Checksum, *Checksum, *Checksum, error) { //checksums f, err := os.Open(path) if err != nil { return nil, nil, nil, err } hashMd5 := md5.New() size, err := io.Copy(hashMd5, f) if err != nil { return nil, nil, nil, err } checksumMd5 := Checksum{hex.EncodeToString(hashMd5.Sum(nil)), size, name} f.Seek(int64(0), 0) hash256 := sha256.New() size, err = io.Copy(hash256, f) if err != nil { return nil, nil, nil, err } checksumSha256 := Checksum{hex.EncodeToString(hash256.Sum(nil)), size, name} f.Seek(int64(0), 0) hash1 := sha1.New() size, err = io.Copy(hash1, f) if err != nil { return nil, nil, nil, err } checksumSha1 := Checksum{hex.EncodeToString(hash1.Sum(nil)), size, name} err = f.Close() if err != nil { return nil, nil, nil, err } return &checksumMd5, &checksumSha1, &checksumSha256, nil } */ func debSourceBuild(tp TaskParams) (err error) { metadata := tp.Settings.GetTaskSettingMap(TASK_DEB_SOURCE, "metadata") //armArchName := getArmArchName(tp.Settings) metadataDebX := tp.Settings.GetTaskSettingMap(TASK_DEB_SOURCE, "metadata-deb") otherMappedFilesFromSetting := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "other-mapped-files") otherMappedFiles, err := calcOtherMappedFiles(otherMappedFilesFromSetting) if err != nil { return err } metadataDeb := map[string]string{} for k, v := range metadataDebX { val, ok := v.(string) if ok { metadataDeb[k] = val } } rmtemp := tp.Settings.GetTaskSettingBool(TASK_DEB_SOURCE, "rmtemp") debDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName()) //v0.8.1 dont use platform dir tmpDir := filepath.Join(debDir, ".goxc-temp") shortDescription := "?" if desc, keyExists := metadata["description"]; keyExists { var err error shortDescription, err = typeutils.ToString(desc, "description") if err != nil { return err } } longDescription := " " if ldesc, keyExists := metadata["long-description"]; keyExists { var err error longDescription, err = typeutils.ToString(ldesc, "long-description") if err != nil { return err } } maintainerName := "?" if maint, keyExists := metadata["maintainer"]; keyExists { var err error maintainerName, err = typeutils.ToString(maint, "maintainer") if err != nil { return err } } maintainerEmail := "*****@*****.**" if maintEmail, keyExists := metadata["maintainer-email"]; keyExists { var err error maintainerEmail, err = typeutils.ToString(maintEmail, "maintainer-email") if err != nil { return err } } build := debgen.NewBuildParams() build.DestDir = debDir build.TmpDir = tmpDir build.Init() build.IsRmtemp = rmtemp var ctrl *deb.Control //Read control data. If control file doesnt exist, use parameters ... fi, err := os.Open(filepath.Join(build.DebianDir, "control")) if os.IsNotExist(err) { log.Printf("WARNING - no debian 'control' file found. Use `debber` to generate proper debian metadata") ctrl = deb.NewControlDefault(tp.AppName, maintainerName, maintainerEmail, shortDescription, longDescription, false) } else if err != nil { return fmt.Errorf("%v", err) } else { cfr := deb.NewControlFileReader(fi) ctrl, err = cfr.Parse() if err != nil { return fmt.Errorf("%v", err) } } goSourcesDir := tp.Settings.GetTaskSettingString(TASK_DEB_SOURCE, "go-sources-dir") mappedSources, err := debgen.GlobForGoSources(goSourcesDir, []string{build.DestDir, build.TmpDir}) if err != nil { return fmt.Errorf("%v", err) } for k, v := range mappedSources { otherMappedFiles[k] = v } build.Version = tp.Settings.GetFullVersionName() spgen, err := debgen.PrepareSourceDebGenerator(ctrl, build) if spgen.OrigFiles == nil { spgen.OrigFiles = map[string]string{} } for k, v := range otherMappedFiles { spgen.OrigFiles[k] = v } if err != nil { return fmt.Errorf("%v", err) } err = spgen.GenerateAllDefault() if err != nil { return fmt.Errorf("%v", err) } if tp.Settings.IsVerbose() { log.Printf("Wrote dsc file to %s", filepath.Join(build.DestDir, spgen.SourcePackage.DscFileName)) log.Printf("Wrote orig file to %s", filepath.Join(build.DestDir, spgen.SourcePackage.OrigFileName)) log.Printf("Wrote debian file to %s", filepath.Join(build.DestDir, spgen.SourcePackage.DebianFileName)) } return nil }
func debBuild(dest platforms.Platform, tp TaskParams) error { metadata := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "metadata") armArchName := getArmArchName(tp.Settings) //maintain support for old configs ... metadataDebX := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "metadata-deb") otherMappedFilesFromSetting := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "other-mapped-files") otherMappedFiles, err := calcOtherMappedFiles(otherMappedFilesFromSetting) if err != nil { return err } if tp.Settings.IsVerbose() { log.Printf("other mapped files: %+v", otherMappedFiles) } metadataDeb := map[string]string{} for k, v := range metadataDebX { val, ok := v.(string) if ok { metadataDeb[k] = val } } rmtemp := tp.Settings.GetTaskSettingBool(TASK_DEB_GEN, "rmtemp") debDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName()) //v0.8.1 dont use platform dir tmpDir := filepath.Join(debDir, ".goxc-temp") shortDescription := "?" if desc, keyExists := metadata["description"]; keyExists { var err error shortDescription, err = typeutils.ToString(desc, "description") if err != nil { return err } } longDescription := " " if ldesc, keyExists := metadata["long-description"]; keyExists { var err error longDescription, err = typeutils.ToString(ldesc, "long-description") if err != nil { return err } } maintainerName := "?" if maint, keyExists := metadata["maintainer"]; keyExists { var err error maintainerName, err = typeutils.ToString(maint, "maintainer") if err != nil { return err } } maintainerEmail := "*****@*****.**" if maintEmail, keyExists := metadata["maintainer-email"]; keyExists { var err error maintainerEmail, err = typeutils.ToString(maintEmail, "maintainer-email") if err != nil { return err } } //'dev' Package should be a separate task addDevPackage := false /* pkg := deb.NewPackage(tp.AppName, tp.Settings.GetFullVersionName(), maintainer, description) pkg.AdditionalControlData = metadataDeb*/ build := debgen.NewBuildParams() build.DestDir = debDir build.TmpDir = tmpDir build.Init() build.IsRmtemp = rmtemp var ctrl *deb.Control //Read control data. If control file doesnt exist, use parameters ... fi, err := os.Open(filepath.Join(build.DebianDir, "control")) if os.IsNotExist(err) { log.Printf("WARNING - no debian 'control' file found. Use `debber` to generate proper debian metadata") ctrl = deb.NewControlDefault(tp.AppName, maintainerName, maintainerEmail, shortDescription, longDescription, addDevPackage) } else if err != nil { return fmt.Errorf("%v", err) } else { cfr := deb.NewControlFileReader(fi) ctrl, err = cfr.Parse() if err != nil { return fmt.Errorf("%v", err) } } debArch := getDebArch(dest.Arch, armArchName) build.Arches = []deb.Architecture{debArch} build.Version = tp.Settings.GetFullVersionName() dgens, err := debgen.PrepareBasicDebGen(ctrl, build) if err != nil { return fmt.Errorf("Error preparing deb generator: %v", err) } //there should only be one for this platform. // Anyway this part maps all binaries. for _, dgen := range dgens { // -dev paragraphs handled by 'deb-dev' task. if !strings.HasSuffix(dgen.DebWriter.Control.Get(deb.PackageFName), "-dev") { for _, mainDir := range tp.MainDirs { var exeName string if len(tp.MainDirs) == 1 { exeName = tp.Settings.AppName } else { exeName = filepath.Base(mainDir) } binPath, err := core.GetAbsoluteBin(dest.Os, dest.Arch, tp.Settings.AppName, exeName, tp.WorkingDirectory, tp.Settings.GetFullVersionName(), tp.Settings.OutPath, tp.Settings.ArtifactsDest) if err != nil { return err } if dgen.DataFiles == nil { dgen.DataFiles = map[string]string{} } dgen.DataFiles["./usr/bin/"+exeName] = binPath } for k, v := range otherMappedFiles { dgen.DataFiles[k] = v } err = dgen.GenerateAllDefault() if err != nil { return fmt.Errorf("Error generating deb: %v", err) } if !tp.Settings.IsQuiet() { log.Printf("Wrote deb to %s", filepath.Join(build.DestDir, dgen.DebWriter.Filename)) } } } return err }
func debDevBuild(tp TaskParams) error { metadata := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "metadata") //maintain support for old configs ... metadataDebX := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "metadata-deb") otherMappedFilesFromSetting := tp.Settings.GetTaskSettingMap(TASK_DEB_GEN, "other-mapped-files") otherMappedFiles, err := calcOtherMappedFiles(otherMappedFilesFromSetting) if err != nil { return err } metadataDeb := map[string]string{} for k, v := range metadataDebX { val, ok := v.(string) if ok { metadataDeb[k] = val } } rmtemp := tp.Settings.GetTaskSettingBool(TASK_DEB_GEN, "rmtemp") debDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName()) //v0.8.1 dont use platform dir tmpDir := filepath.Join(debDir, ".goxc-temp") shortDescription := "?" if desc, keyExists := metadata["description"]; keyExists { var err error shortDescription, err = typeutils.ToString(desc, "description") if err != nil { return err } } longDescription := " " if ldesc, keyExists := metadata["long-description"]; keyExists { var err error longDescription, err = typeutils.ToString(ldesc, "long-description") if err != nil { return err } } maintainerName := "?" if maint, keyExists := metadata["maintainer"]; keyExists { var err error maintainerName, err = typeutils.ToString(maint, "maintainer") if err != nil { return err } } maintainerEmail := "*****@*****.**" if maintEmail, keyExists := metadata["maintainer-email"]; keyExists { var err error maintainerEmail, err = typeutils.ToString(maintEmail, "maintainer-email") if err != nil { return err } } //'dev' Package should be a separate task addDevPackage := false /* pkg := deb.NewPackage(tp.AppName, tp.Settings.GetFullVersionName(), maintainer, description) pkg.AdditionalControlData = metadataDeb*/ build := debgen.NewBuildParams() build.DestDir = debDir build.TmpDir = tmpDir build.Init() build.IsRmtemp = rmtemp var ctrl *deb.Control //Read control data. If control file doesnt exist, use parameters ... fi, err := os.Open(filepath.Join(build.DebianDir, "control")) if os.IsNotExist(err) { log.Printf("WARNING - no debian 'control' file found. Use `debber` to generate proper debian metadata") ctrl = deb.NewControlDefault(tp.AppName, maintainerName, maintainerEmail, shortDescription, longDescription, addDevPackage) } else if err != nil { return fmt.Errorf("%v", err) } else { cfr := deb.NewControlFileReader(fi) ctrl, err = cfr.Parse() if err != nil { return fmt.Errorf("%v", err) } } goSourcesDir := tp.Settings.GetTaskSettingString(TASK_DEB_GEN, "go-sources-dir") mappedSources, err := debgen.GlobForGoSources(goSourcesDir, []string{build.DestDir, build.TmpDir}) if err != nil { return fmt.Errorf("%v", err) } for k, v := range mappedSources { otherMappedFiles[k] = v } debArch := deb.ArchAll build.Arches = []deb.Architecture{debArch} build.Version = tp.Settings.GetFullVersionName() dgens, err := debgen.PrepareBasicDebGen(ctrl, build) if err != nil { return fmt.Errorf("Error preparing deb generator: %v", err) } //there should only be one for this platform. // Anyway this part maps all binaries. for _, dgen := range dgens { if strings.HasSuffix(dgen.DebWriter.Control.Get(deb.PackageFName), "-dev") { for k, v := range otherMappedFiles { dgen.DataFiles[k] = v } err = dgen.GenerateAllDefault() if err != nil { return fmt.Errorf("Error generating deb: %v", err) } if !tp.Settings.IsQuiet() { log.Printf("Wrote -dev deb to %s", filepath.Join(build.DestDir, dgen.DebWriter.Filename)) } } } return err }