Exemple #1
0
// Applies non-go-specific information to packages.
// i.e. dependencies
func ApplyBasicDefaults(ctrl *deb.Control) {
	for _, pkg := range ctrl.SourceParas() {
		pkg.Set(deb.BuildDependsFName, deb.BuildDependsDefault)
	}
	for _, pkg := range ctrl.BinaryParas() {
		pkg.Set(deb.DependsFName, deb.DependsDefault)
	}
}
Exemple #2
0
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
}
Exemple #3
0
//Default flow for generating a deb
func PrepareBasicDebGen(ctrl *deb.Control, build *BuildParams) ([]*DebGenerator, error) {
	if build.Version == "" {
		return nil, fmt.Errorf("Error: 'version' is a required field")
	}
	// Initiate build
	err := build.Init()
	if err != nil {
		return nil, fmt.Errorf("%v", err)
	}

	dgens := []*DebGenerator{}
	//Build ... assume just one source package
	sourcePara := ctrl.SourceParas()[0]
	for _, binPara := range ctrl.BinaryParas() {
		//TODO check -dev package here ...
		debpara := deb.CopyPara(binPara)
		debpara.Set(deb.VersionFName, build.Version)
		debpara.Set(deb.SectionFName, sourcePara.Get(deb.SectionFName))
		debpara.Set(deb.MaintainerFName, sourcePara.Get(deb.MaintainerFName))
		debpara.Set(deb.PriorityFName, sourcePara.Get(deb.PriorityFName))
		//log.Printf("debPara: %+v", debpara)

		dataFiles := map[string]string{}
		//source package. TODO: find a better way to identify a sources-only .deb package.
		if strings.HasSuffix(binPara.Get(deb.PackageFName), "-dev") {
			/*
				if build.sourcesGlob != "" {
					sources, err = filepath.Glob(build.sourcesGlob)
					if err != nil {
						return fmt.Errorf("%v", err)
					}
					log.Printf("sources matching glob: %+v", sources)
				}*/
			/*
				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
					}
					sources, 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)
					}
					for k, v := range sources {
						dataFiles[k] = v
					}
				}
			*/
		} else {
			// no sources
		}
		//Add changelog
		cl := filepath.Join(build.DebianDir, "changelog")
		cf, err := os.Open(cl)
		if os.IsNotExist(err) {
		} else if err != nil {
			return nil, err
		} else {
			defer cf.Close()
			changelogGz := filepath.Join(build.TmpDir, "changelog.gz")
			gzf, err := os.OpenFile(changelogGz, os.O_CREATE|os.O_WRONLY, 0644)
			defer gzf.Close()
			if err != nil {
				return nil, fmt.Errorf("Error creating temp gzip file for changelog: %v", err)
			}
			gzw, err := gzip.NewWriterLevel(gzf, gzip.BestCompression)
			if err != nil {
				return nil, fmt.Errorf("Error gzipping changelog: %v", err)
			}
			_, err = io.Copy(gzw, cf)
			if err != nil {
				return nil, fmt.Errorf("Error gzipping changelog: %v", err)
			}
			err = gzw.Close()
			if err != nil {
				return nil, fmt.Errorf("Error gzipping changelog: %v", err)
			}
			err = cf.Close()
			if err != nil {
				return nil, fmt.Errorf("Error gzipping changelog: %v", err)
			}
			err = gzf.Close()
			if err != nil {
				return nil, fmt.Errorf("Error gzipping changelog: %v", err)
			}
			//exists. Add it.
			dataFiles["/usr/share/doc/"+binPara.Get(deb.PackageFName)+"/changelog.gz"] = changelogGz
		}
		//Add copyright
		cr := filepath.Join(build.DebianDir, "copyright")
		_, err = os.Stat(cr)
		if os.IsNotExist(err) {
		} else if err != nil {
			return nil, err
		} else {
			//exists. Add it.
			dataFiles["/usr/share/doc/"+binPara.Get(deb.PackageFName)+"/copyright"] = cr
		}
		//log.Printf("Resources: %v", build.Resources)
		// TODO determine this platform
		//err = bpkg.Build(build, debgen.GenBinaryArtifact)
		artifacts, err := deb.NewWriters(&deb.Control{debpara})
		if err != nil {
			return nil, fmt.Errorf("%v", err)
		}
		for arch, artifact := range artifacts {
			required := false
			for _, requiredArch := range build.Arches {
				if arch == requiredArch {
					//yes
					required = true
				}
			}
			if !required {
				continue
			}
			dgen := NewDebGenerator(artifact, build)
			dgens = append(dgens, dgen)
			dgen.DataFiles = map[string]string{}
			for k, v := range dataFiles {
				dgen.DataFiles[k] = v
			}
			/*
				for _, source := range sources {
					//NOTE: this should not use filepath.Join because it should always use forward-slash
					dgen.DataFiles[build.sourcesDest+"/"+source] = source
				}
			*/
			//add changelog

			// add resources ...
			f := func(path string, info os.FileInfo, err2 error) error {
				if info != nil && !info.IsDir() {
					rel, err := filepath.Rel(build.ResourcesDir, path)
					if err == nil {
						dgen.DataFiles[rel] = path
					}
					return err
				}
				return nil
			}
			err = filepath.Walk(build.ResourcesDir, f)

			if err != nil {
				return nil, fmt.Errorf("%v", err)
			}
			/*
				binFinders, ok := build.BinFinders[arch]
				if ok {
					for _, binFinder := range binFinders {
						if binFinder.Glob != "" {
							glob := filepath.Join(binFinder.BaseDir, binFinder.Glob)
							bins, err := filepath.Glob(glob)
							if err != nil {
								return nil, fmt.Errorf("%v", err)
							}
							log.Printf("glob: %s, bins: %v", glob, bins)
							//log.Printf("Binaries matching glob for '%s': %+v", arch, bins)
							for _, bin := range bins {
								target := binFinder.Target + "/" + bin
								dgen.DataFiles[target] = bin
							}
						}
					}
				}
			*/
			//			log.Printf("All data files: %v", dgen.DataFiles)
		}
	}
	return dgens, nil
}