Documentation ¶
Overview ¶
Package debgen offers a simpler means of generating .deb artifacts.
debgen uses templates to generate control files and such.
**Warning: debgo [is being renamed to 'debber'](https://github.com/debber), Please note that the this version should still be used until debber-v0.3 becomes stable. It will not receive updates after that point. Ta**
Example (GenBinaryPackage) ¶
package main import ( "log" "os" "path/filepath" "github.com/mwpcheung/debgo/deb" "github.com/mwpcheung/debgo/debgen" ) func main() { pkg := deb.NewPackage("testpkg", "0.0.2", "me <a@me.org>", "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) } } } func prep() error { exesMap := map[string][]string{ "amd64": []string{"_out/a.amd64"}, "i386": []string{"_out/a.i386"}, "armhf": []string{"_out/a.armhf"}} err := createExes(exesMap) if err != nil { log.Fatalf("%v", err) } return err } func createExes(exesMap map[string][]string) error { for _, exes := range exesMap { for _, exe := range exes { err := os.MkdirAll(filepath.Dir(exe), 0777) if err != nil { return err } fi, err := os.Create(exe) if err != nil { return err } _, err = fi.Write([]byte("echo 1")) if err != nil { return err } err = fi.Close() if err != nil { return err } } } return nil }
Output:
Example (GenDevPackage) ¶
package main import ( "log" "github.com/mwpcheung/debgo/deb" "github.com/mwpcheung/debgo/debgen" ) func main() { 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:
Example (GenSourcePackage) ¶
package main import ( "log" "github.com/mwpcheung/debgo/deb" "github.com/mwpcheung/debgo/debgen" ) func main() { pkg := deb.NewPackage("testpkg", "0.0.2", "me <a@me.org>", "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:
Index ¶
- Constants
- Variables
- func ApplyGoDefaults(pkg *deb.Package)
- func GenDevArtifact(ddpkg *deb.Package, build *BuildParams, mappedFiles map[string]string) error
- func GetGoPathElement(workingDirectory string) string
- func GlobForGoSources(sourcesDir string, ignore []string) (map[string]string, error)
- func GlobForSources(sourcesRelativeDir, codeDir, glob, destinationPrefix string, ...) (map[string]string, error)
- func TarAddBytes(tw *tar.Writer, bytes []byte, destName string, mode int64) error
- func TarAddFile(tw *tar.Writer, sourceFile, destName string) error
- func TarAddFileOrDir(tw *tar.Writer, sourceFile, destName string) error
- func TarAddFiles(tw *tar.Writer, resources map[string]string) error
- func TarHeader(path string, datalen int64, mode int64) *tar.Header
- func TemplateFile(templateFile string, vars interface{}) ([]byte, error)
- func TemplateFileOrString(templateFile string, templateDefault string, vars interface{}) ([]byte, error)
- func TemplateString(tplText string, vars interface{}) ([]byte, error)
- type BuildParams
- type DebGenerator
- type SourcePackageGenerator
- func (spgen *SourcePackageGenerator) ApplyDefaultsPureGo()
- func (spgen *SourcePackageGenerator) GenDebianArchive() error
- func (spgen *SourcePackageGenerator) GenDscFile() error
- func (spgen *SourcePackageGenerator) GenOrigArchive() error
- func (spgen *SourcePackageGenerator) GenerateAllDefault() error
- type TemplateData
Examples ¶
Constants ¶
const ( GlobGoSources = "*.go" TemplateDebianSourceFormat = deb.FormatDefault // Debian source formaat TemplateDebianSourceOptions = `tar-ignore = .hg tar-ignore = .git tar-ignore = .bzr` //specifies files to ignore while building. // The debian rules file describes how to build a 'source deb' into a binary deb. The default template here invokes debhelper scripts to automate this process for simple cases. TemplateDebianRulesDefault = `#!/usr/bin/make -f # -*- makefile -*- # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@` // The debian rules file describes how to build a 'source deb' into a binary deb. This version contains a special script for building go packages. TemplateDebianRulesForGo = `` /* 839-byte string literal not displayed */ // The debian control file (binary debs) defines package metadata TemplateBinarydebControl = `` /* 406-byte string literal not displayed */ // The debian control file (source debs) defines build metadata AND package metadata TemplateSourcedebControl = `` /* 383-byte string literal not displayed */ // The dsc file defines package metadata AND checksums TemplateDebianDsc = `` /* 626-byte string literal not displayed */ TemplateChangelogHeader = `{{.Package.Name}} ({{.Package.Version}}) {{.Package.Status}}; urgency=low` TemplateChangelogInitialEntry = ` * Initial import` TemplateChangelogInitial = TemplateChangelogHeader + "\n\n" + TemplateChangelogInitialEntry + "\n\n" + TemplateChangelogFooter TemplateChangelogAdditionalEntry = "\n\n" + TemplateChangelogHeader + "\n\n{{.ChangelogEntry}}\n\n" + TemplateChangelogFooter TemplateDebianCopyright = `Copyright 2014 {{.Package.Name}}` TemplateDebianReadme = `{{.Package.Name}} ========== ` DevGoPathDefault = "/usr/share/gocode" // This is used by existing -dev.deb packages e.g. golang-doozer-dev and golang-protobuf-dev GoPathExtraDefault = ":" + DevGoPathDefault DebianDir = "debian" TplExtension = ".tpl" ChangelogDateLayout = "Mon, 02 Jan 2006 15:04:05 -0700" )
Variables ¶
var ( TemplateStringsSourceDefault = map[string]string{ "control": TemplateSourcedebControl, "compat": deb.DebianCompatDefault, "rules": TemplateDebianRulesDefault, "source/format": TemplateDebianSourceFormat, "source/options": TemplateDebianSourceOptions, "copyright": TemplateDebianCopyright, "changelog": TemplateChangelogInitial, "README.debian": TemplateDebianReadme} )
Functions ¶
func ApplyGoDefaults ¶
Applies go-specific information to packages. Includes dependencies, Go Path information.
func GenDevArtifact ¶
Default build function for Dev packages. Implement your own if you prefer
func GetGoPathElement ¶
Tries to find the most relevant GOPATH element. First, tries to find an element which is a parent of the current directory. If not, it uses the first element from the GOPATH
func GlobForGoSources ¶
Glob for Go-specific sources
func GlobForSources ¶
func GlobForSources(sourcesRelativeDir, codeDir, glob, destinationPrefix string, ignoreFiles []string) (map[string]string, error)
Glob for sources. This function looks for source files, and prepares their paths for
func TarAddBytes ¶
TarAddBytes adds a file by bytes with a given path
func TarAddFile ¶
TarAddFile adds a file from the file system This is just a helper function TODO: directories
func TarAddFiles ¶
TarAddFiles adds resources from file system. The key should be the destination filename. Value is the local filesystem path
func TemplateFile ¶
func TemplateFileOrString ¶
func TemplateString ¶
Types ¶
type BuildParams ¶
type BuildParams struct { IsVerbose bool // Whether to log debug information TmpDir string // Directory in-which to generate intermediate files & archives IsRmtemp bool // Delete tmp dir after execution? DestDir string // Where to generate .deb files and source debs (.dsc files etc) WorkingDir string // This is the root from which to find .go files, templates, resources, etc TemplateDir string // Optional. Only required if you're using templates ResourcesDir string // Optional. Only if debgo packages your resources automatically. }
BuildParams provides information about a particular build
func NewBuildParams ¶
func NewBuildParams() *BuildParams
Factory for BuildParams. Populates defaults.
func (*BuildParams) Init ¶
func (bp *BuildParams) Init() error
Initialise build directories (make Temp and Dest directories)
type DebGenerator ¶
type DebGenerator struct { DebWriter *deb.DebWriter BuildParams *BuildParams DefaultTemplateStrings map[string]string OrigFiles map[string]string }
DebGenerator generates source packages using templates and some overrideable behaviours
func NewDebGenerator ¶
func NewDebGenerator(debWriter *deb.DebWriter, buildParams *BuildParams) *DebGenerator
NewDebGenerator is a factory for SourcePackageGenerator.
func (*DebGenerator) GenControlArchive ¶
func (dgen *DebGenerator) GenControlArchive() error
GenControlArchive generates control archive, using a system of templates or files.
First it attempts to find the file inside BuildParams.Resources. If that doesn't exist, it attempts to find a template in templateDir Finally, it attempts to use a string-based template.
func (*DebGenerator) GenControlFile ¶
func (dgen *DebGenerator) GenControlFile(tgzw *targz.Writer, templateVars *TemplateData) error
Generates the control file based on a template
func (*DebGenerator) GenDataArchive ¶
func (dgen *DebGenerator) GenDataArchive() error
GenDataArchive generates the 'code' archive from files on the file system.
func (*DebGenerator) GenerateAllDefault ¶
func (dgen *DebGenerator) GenerateAllDefault() error
GenerateAllDefault applies the default build process. First it writes each file, then adds them to the .deb as a separate io operation.
type SourcePackageGenerator ¶
type SourcePackageGenerator struct { SourcePackage *deb.SourcePackage BuildParams *BuildParams TemplateStrings map[string]string //DebianFiles map[string]string OrigFiles map[string]string }
SourcePackageGenerator generates source packages using templates and some overrideable behaviours
func NewSourcePackageGenerator ¶
func NewSourcePackageGenerator(sourcePackage *deb.SourcePackage, buildParams *BuildParams) *SourcePackageGenerator
NewSourcePackageGenerator is a factory for SourcePackageGenerator.
func (*SourcePackageGenerator) ApplyDefaultsPureGo ¶
func (spgen *SourcePackageGenerator) ApplyDefaultsPureGo()
ApplyDefaultsPureGo overrides some template variables for pure-Go packages
func (*SourcePackageGenerator) GenDebianArchive ¶
func (spgen *SourcePackageGenerator) GenDebianArchive() error
GenDebianArchive builds <package>.debian.tar.gz This contains all the control data, changelog, rules, etc
func (*SourcePackageGenerator) GenDscFile ¶
func (spgen *SourcePackageGenerator) GenDscFile() error
func (*SourcePackageGenerator) GenOrigArchive ¶
func (spgen *SourcePackageGenerator) GenOrigArchive() error
GenOrigArchive builds <package>.orig.tar.gz This contains the original upstream source code and data.
func (*SourcePackageGenerator) GenerateAllDefault ¶
func (spgen *SourcePackageGenerator) GenerateAllDefault() error
GenerateAll builds all the artifacts using the default behaviour. Note that we could implement alternative methods in future (e.g. using a GenDiffArchive)
type TemplateData ¶
type TemplateData struct { Package *deb.Package Deb *deb.DebWriter EntryDate string ChangelogEntry string Checksums *deb.Checksums }
Data for templates
func NewTemplateData ¶
func NewTemplateData(pkg *deb.Package) *TemplateData
initialize "template data" object