예제 #1
0
func sourceGen(input []string) error {
	build := debgen.NewBuildParams()
	fs := InitBuildFlags(cmdName+" "+TaskGenSource, build)
	var sourceDir string
	fs.StringVar(&sourceDir, "sources", ".", "source dir")
	var isDiscoverGoPath bool
	fs.BoolVar(&isDiscoverGoPath, "discover-gopath", true, "Use Go-style path (try to discover base relative to GOPATH element)")
	var sourcesGlob string
	fs.StringVar(&sourcesGlob, "sources-glob", debgen.GlobGoSources, "Glob for inclusion of sources")
	var destinationDir string
	fs.StringVar(&destinationDir, "destination-dir", debgen.DevGoPathDefault, "Directory name to store sources in archive")
	var sourcesRelativeTo string
	fs.StringVar(&sourcesRelativeTo, "sources-relative-to", ".", "Sources relative to (this is ignored when -discover-gopath is selected)")
	fs.StringVar(&build.Version, "version", "", "Package version")

	// parse and validate flags
	err := fs.Parse(os.Args[2:])
	if err != nil {
		return fmt.Errorf("%v", err)
	}
	if build.Version == "" {
		return fmt.Errorf("Error: --version is a required flag")
	}
	if isDiscoverGoPath {
		sourcesRelativeTo = debgen.GetGoPathElement(sourceDir)
	}
	mappedSources, err := debgen.GlobForSources(sourcesRelativeTo, sourceDir, sourcesGlob, destinationDir, []string{build.TmpDir, build.DebianDir})
	if err != nil {
		return fmt.Errorf("%v", err)
	}
	fi, err := os.Open(filepath.Join(build.DebianDir, "control"))
	if err != nil {
		return fmt.Errorf("%v", err)
	}

	cfr := deb.NewControlFileReader(fi)
	ctrl, err := cfr.Parse()
	if err != nil {
		return fmt.Errorf("%v", err)
	}

	spgen, err := debgen.PrepareSourceDebGenerator(ctrl, build)
	for k, v := range mappedSources {
		spgen.OrigFiles[k] = v
	}
	if err != nil {
		return fmt.Errorf("%v", err)
	}
	err = spgen.GenerateAllDefault()
	if err != nil {
		return fmt.Errorf("%v", err)
	}

	return err
}
예제 #2
0
/*
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
}