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 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 PrepareSourceDebGenerator(ctrl *deb.Control, build *BuildParams) (*SourcePackageGenerator, error) { err := build.Init() if err != nil { return nil, fmt.Errorf("%v", err) } sourcePara := ctrl.SourceParas()[0] //sourcePara := deb.CopyPara(sp) sourcePara.Set(deb.VersionFName, build.Version) sourcePara.Set(deb.FormatFName, deb.FormatDefault) //Build ... spkg := deb.NewSourcePackage(ctrl) spgen := NewSourcePackageGenerator(spkg, build) /* sourcesDestinationDir := sourcePara.Get(deb.SourceFName) + "_" + sourcePara.Get(deb.VersionFName) for _, sourceFinder := range build.SourceFinders { sourcesRelativeTo := sourceFinder.BaseDir var sourceDir string if sourceFinder.IncludeDir != "" { sourceDir = sourceFinder.IncludeDir } else { sourceDir = sourceFinder.BaseDir } spgen.OrigFiles, err = GlobForSources(sourcesRelativeTo, sourceDir, sourceFinder.Glob, sourceFinder.Target + sourcesDestinationDir, []string{build.TmpDir, build.DestDir}) if err != nil { return nil, fmt.Errorf("Error resolving sources: %v", err) } } */ /* spgen.OrigFiles, err = GlobForSources(build.SourcesRelativeTo, build.SourceDir, build.SourcesGlob, sourcesDestinationDir, []string{build.TmpDir, build.DestDir}) if err != nil { return nil, fmt.Errorf("Error resolving sources: %v", err) } */ return spgen, nil }
func initDebber(input []string) error { //set to nothing ctrl := deb.NewControlEmpty() build := debgen.NewBuildParams() build.DestDir = "debian" fs := InitBuildFlags(cmdName+" init", build) var entry string var overwrite bool var flavour string var pkgName, maintainerName, maintainerEmail, shortDescription, longDescription, architecture string var license string fs.StringVar(&pkgName, "name", "", "Package name [required]") fs.StringVar(&maintainerName, "maintainer", "", "Maintainer name [required]") fs.StringVar(&maintainerEmail, "maintainer-email", "", "Maintainer's email address [required]") fs.StringVar(&shortDescription, "desc", "", "Package description [required]") fs.StringVar(&longDescription, "long-desc", "", "Package Long description") fs.StringVar(&entry, "entry", "Initial project import", "Changelog entry data") fs.BoolVar(&overwrite, "overwrite", false, "Overwrite existing files") fs.StringVar(&architecture, "architecture", "any", "Package Architecture (any)") fs.StringVar(&license, "license", "BSD-3-clause", "License") fs.StringVar(&flavour, "flav", "go:exe", "'flavour' implies a set of defaults - currently, one of 'go:exe', 'go:pkg', 'dev' or ''") //TODO flavour err := fs.Parse(os.Args[2:]) if err != nil { return fmt.Errorf("%v", err) } if pkgName == "" || maintainerName == "" || maintainerEmail == "" || shortDescription == "" || longDescription == "" { return fmt.Errorf("Required fields: --name, --maintainer, --maintainer-email, --desc, --long-desc") } //handle spaces in longDescription. TODO: utility function longDescriptions := strings.Split(longDescription, "\n") longDescription = "" for _, ldl := range longDescriptions { if longDescription != "" { longDescription += "\n" } longDescription += " " + strings.TrimSpace(ldl) } (*ctrl)[0].Set(deb.SourceFName, pkgName) (*ctrl)[0].Set(deb.MaintainerFName, fmt.Sprintf("%s <%s>", maintainerName, maintainerEmail)) (*ctrl)[0].Set(deb.DescriptionFName, fmt.Sprintf("%s\n%s", shortDescription, longDescription)) (*ctrl)[0].Set(deb.ArchitectureFName, architecture) if len(*ctrl) < 2 { *ctrl = append(*ctrl, deb.NewPackage()) } (*ctrl)[1].Set(deb.PackageFName, pkgName) (*ctrl)[1].Set(deb.DescriptionFName, fmt.Sprintf("%s\n%s", shortDescription, longDescription)) (*ctrl)[1].Set(deb.ArchitectureFName, architecture) //-dev package. Optional somehow? if len(*ctrl) < 3 { *ctrl = append(*ctrl, deb.NewPackage()) } (*ctrl)[2].Set(deb.PackageFName, pkgName+"-dev") (*ctrl)[2].Set(deb.ArchitectureFName, "all") (*ctrl)[2].Set(deb.DescriptionFName, fmt.Sprintf("%s - development package\n%s", shortDescription, longDescription)) deb.SetDefaults(ctrl) if strings.HasPrefix(flavour, "go:") { debgen.ApplyGoDefaults(ctrl) } else { debgen.ApplyBasicDefaults(ctrl) } if err == nil { //validation ... err = deb.ValidateControl(ctrl) if err != nil { println("") fmt.Fprintf(os.Stderr, "Usage:\n") fs.PrintDefaults() println("") } } if err != nil { return fmt.Errorf("%v", err) } err = build.Init() if err != nil { return fmt.Errorf("Error initialising build: %v", err) } spkg := deb.NewSourcePackage(ctrl) spgen := debgen.NewSourcePackageGenerator(spkg, build) if flavour == "go:exe" { spgen.ApplyDefaultsPureGo() } //create control file filename := filepath.Join(build.DebianDir, "control") _, err = os.Stat(filename) if os.IsNotExist(err) || overwrite { err = spgen.GenSourceControlFile() if err != nil { return fmt.Errorf("Error generating control file: %v", err) } } else if err != nil { return fmt.Errorf("Error generating control file: %v", err) } else { log.Printf("%s already exists", filename) } //changelog file filename = filepath.Join(build.DebianDir, "changelog") _, err = os.Stat(filename) if os.IsNotExist(err) || overwrite { changelogAddEntry(ctrl, build, entry) } else if err != nil { return fmt.Errorf("Error reading existing changelog: %v", err) } else { log.Printf("%s already exists", filename) } //copyright file filename = filepath.Join(build.DebianDir, "copyright") _, err = os.Stat(filename) if os.IsNotExist(err) || overwrite { err = copyrightInit(ctrl, build, license) if err != nil { return err } } else if err != nil { return fmt.Errorf("Error reading existing copyright file: %v", err) } else { log.Printf("%s already exists", filename) } //rules file ... filename = filepath.Join(build.DebianDir, "rules") _, err = os.Stat(filename) if os.IsNotExist(err) || overwrite { templateVars := debgen.NewTemplateData(ctrl) tpl, err := template.New("template").Parse(spgen.TemplateStrings["rules"]) if err != nil { return fmt.Errorf("Error parsing template: %v", err) } //create .. f, err := os.Create(filename) if err != nil { return fmt.Errorf("Error creating file: %v", err) } defer f.Close() err = tpl.Execute(f, templateVars) if err != nil { return fmt.Errorf("Error executing template: %v", err) } err = f.Close() if err != nil { return fmt.Errorf("Error closing written file: %v", err) } } else if err != nil { return fmt.Errorf("Error reading existing rules file: %v", err) } else { log.Printf("%s already exists", filename) } return nil }