Exemple #1
0
func (s *Settings) GetTaskSettingString(taskName, settingName string) string {
	retUntyped := s.GetTaskSetting(taskName, settingName)
	if retUntyped == nil {
		return ""
	}
	str, err := typeutils.ToString(retUntyped, taskName+"."+settingName)
	if err != nil {
		//already logged
	}
	return str
}
Exemple #2
0
func loadJsonFileAsMap(jsonFile string, verbose bool) (map[string]interface{}, error) {
	var f map[string]interface{}
	rawJson, err := loadFile(jsonFile, verbose)
	if err != nil {
		return f, err
	}
	errs := validateRawJson(rawJson, jsonFile)
	if errs != nil && len(errs) > 0 {
		return f, errs[0]
	}
	//TODO: super-verbose option for logging file content? log.Printf("%s\n", string(file))
	err = json.Unmarshal(rawJson, &f)
	if err != nil {
		log.Printf("ERROR (%s): invalid json!", jsonFile)
		printErrorDetails(rawJson, err)
	} else {
		//it was known as FormatVersion until v0.9
		if fv, keyExists := f["FormatVersion"]; keyExists {
			f["ConfigVersion"] = fv
		}
		//fill all the way down.
		if fv, keyExists := f["ConfigVersion"]; keyExists {
			if s, keyExists := f["Settings"]; keyExists {
				//Support for old versions, up until version 0.5.
				settingsSection, err := typeutils.ToMap(s, "Settings")
				if err != nil {
					return f, err
				} else {
					if _, keyExists = settingsSection["ConfigVersion"]; !keyExists {
						//set from jsonSettings
						//it was previously known as FormatVersion ...
						formatVersion, err := typeutils.ToString(fv, "FormatVersion")
						if err != nil {
							return f, err
						}
						settingsSection["ConfigVersion"] = formatVersion
					}
					return settingsSection, err
				}
				//settings, err := loadSettingsSection(settingsSection)
				//return settings, err
			}
		} else {
			return f, errors.New("File format version not specified!")
		}
	}

	return f, err
}
Exemple #3
0
func buildSettingsFromMap(m map[string]interface{}) (*BuildSettings, error) {
	var err error
	bs := BuildSettings{}
	FillBuildSettingsDefaults(&bs)
	for k, v := range m {
		switch k {
		//case "GoRoot":
		//	bs.GoRoot, err = typeutils.ToString(v, k)
		case "Processors":
			var fp float64
			fp, err = typeutils.ToFloat64(v, k)
			if err == nil {
				processors := int(fp)
				bs.Processors = &processors
			}
		case "Race":
			var race bool
			race, err = typeutils.ToBool(v, k)
			if err == nil {
				bs.Race = &race
			}
		case "Verbose":
			var verbose bool
			verbose, err = typeutils.ToBool(v, k)
			if err == nil {
				bs.Verbose = &verbose
			}
		case "PrintCommands":
			var printCommands bool
			printCommands, err = typeutils.ToBool(v, k)
			if err == nil {
				bs.PrintCommands = &printCommands
			}
		case "CcFlags":
			var ccFlags string
			ccFlags, err = typeutils.ToString(v, k)
			if err == nil {
				bs.CcFlags = &ccFlags
			}
		case "Compiler":
			var s string
			s, err = typeutils.ToString(v, k)
			if err == nil {
				bs.Compiler = &s
			}
		case "GccGoFlags":
			var s string
			s, err = typeutils.ToString(v, k)
			if err == nil {
				bs.GccGoFlags = &s
			}
		case "GcFlags":
			var s string
			s, err = typeutils.ToString(v, k)
			if err == nil {
				bs.GcFlags = &s
			}
		case "InstallSuffix":
			var s string
			s, err = typeutils.ToString(v, k)
			if err == nil {
				bs.InstallSuffix = &s
			}
		case "LdFlags":
			var s string
			s, err = typeutils.ToString(v, k)
			if err == nil {
				bs.LdFlags = &s
			}
		case "Tags":
			var s string
			s, err = typeutils.ToString(v, k)
			if err == nil {
				bs.Tags = &s
			}
		case "LdFlagsXVars":
			var xVars map[string]interface{}
			xVars, err = typeutils.ToMap(v, k)
			if err == nil {
				bs.LdFlagsXVars = &xVars
			}
		case "ExtraArgs":
			bs.ExtraArgs, err = typeutils.ToStringSlice(v, k)
		default:
			log.Printf("Warning!! Unrecognised Setting '%s' (value %v)", k, v)
		}
		if err != nil {
			return &bs, err
		}

	}
	return &bs, err
}
Exemple #4
0
func debBuild(dest platforms.Platform, tp TaskParams) (err error) {
	metadata := tp.Settings.GetTaskSettingMap(TASK_PKG_BUILD, "metadata")
	armArchName := getArmArchName(tp.Settings)
	metadataDeb := tp.Settings.GetTaskSettingMap(TASK_PKG_BUILD, "metadata-deb")
	rmtemp := tp.Settings.GetTaskSettingBool(TASK_PKG_BUILD, "rmtemp")
	debDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName()) //v0.8.1 dont use platform dir
	tmpDir := filepath.Join(debDir, ".goxc-temp")
	if rmtemp {
		defer os.RemoveAll(tmpDir)
	}
	os.MkdirAll(tmpDir, 0755)
	err = ioutil.WriteFile(filepath.Join(tmpDir, "debian-binary"), []byte("2.0\n"), 0644)
	if err != nil {
		return err
	}
	description := "?"
	if desc, keyExists := metadata["description"]; keyExists {
		description, err = typeutils.ToString(desc, "description")
		if err != nil {
			return err
		}
	}
	maintainer := "?"
	if maint, keyExists := metadata["maintainer"]; keyExists {
		maintainer, err = typeutils.ToString(maint, "maintainer")
		if err != nil {
			return err
		}
	}
	controlContent := getDebControlFileContent(tp.AppName, maintainer, tp.Settings.GetFullVersionName(), dest.Arch, armArchName, description, metadataDeb)
	if tp.Settings.IsVerbose() {
		log.Printf("Control file:\n%s", string(controlContent))
	}
	err = ioutil.WriteFile(filepath.Join(tmpDir, "control"), controlContent, 0644)
	if err != nil {
		return err
	}
	err = archive.TarGz(filepath.Join(tmpDir, "control.tar.gz"), []archive.ArchiveItem{archive.ArchiveItem{FileSystemPath: filepath.Join(tmpDir, "control"), ArchivePath: "control"}})
	if err != nil {
		return err
	}
	//build
	items := []archive.ArchiveItem{}

	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
		}
		items = append(items, archive.ArchiveItem{FileSystemPath: binPath, ArchivePath: "/usr/bin/" + exeName})
	}
	//TODO add resources to /usr/share/appName/
	err = archive.TarGz(filepath.Join(tmpDir, "data.tar.gz"), items)
	if err != nil {
		return err
	}

	targetFile := filepath.Join(debDir, fmt.Sprintf("%s_%s_%s.deb", tp.AppName, tp.Settings.GetFullVersionName(), getDebArch(dest.Arch, armArchName))) //goxc_0.5.2_i386.deb")
	inputs := [][]string{
		[]string{filepath.Join(tmpDir, "debian-binary"), "debian-binary"},
		[]string{filepath.Join(tmpDir, "control.tar.gz"), "control.tar.gz"},
		[]string{filepath.Join(tmpDir, "data.tar.gz"), "data.tar.gz"}}
	err = ar.ArForDeb(targetFile, inputs)
	return
}
Exemple #5
0
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

}
Exemple #6
0
func loadSettingsSection(settingsSection map[string]interface{}) (settings Settings, err error) {
	settings = Settings{}
	for k, v := range settingsSection {
		//try to match key
		switch k {
		case "Tasks":
			settings.Tasks, err = typeutils.ToStringSlice(v, k)
		case "TasksExclude":
			settings.TasksExclude, err = typeutils.ToStringSlice(v, k)
		case "TasksAppend":
			settings.TasksAppend, err = typeutils.ToStringSlice(v, k)
		case "TasksPrepend":
			settings.TasksPrepend, err = typeutils.ToStringSlice(v, k)
		case "AppName":
			settings.AppName, err = typeutils.ToString(v, k)
		case "ArtifactsDest":
			settings.ArtifactsDest, err = typeutils.ToString(v, k)
		case "OutPath":
			settings.OutPath, err = typeutils.ToString(v, k)
		case "Arch":
			settings.Arch, err = typeutils.ToString(v, k)
		case "Os":
			settings.Os, err = typeutils.ToString(v, k)
		case "BuildConstraints":
			settings.BuildConstraints, err = typeutils.ToString(v, k)
		case "ResourcesInclude":
			settings.ResourcesInclude, err = typeutils.ToString(v, k)
		case "ResourcesExclude":
			settings.ResourcesExclude, err = typeutils.ToString(v, k)
		case "MainDirsExclude":
			settings.MainDirsExclude, err = typeutils.ToString(v, k)
		//deprecated
		case "Resources":
			for k2, v2 := range v.(map[string]interface{}) {
				switch k2 {
				case "Include":
					settings.ResourcesInclude, err = typeutils.ToString(v2, k+":"+k2)
				case "Exclude":
					settings.ResourcesExclude, err = typeutils.ToString(v2, k+":"+k2)
				}
			}
		case "PackageVersion":
			settings.PackageVersion, err = typeutils.ToString(v, k)
		case "BranchName":
			settings.BranchName, err = typeutils.ToString(v, k)
		case "PrereleaseInfo":
			settings.PrereleaseInfo, err = typeutils.ToString(v, k)
		case "BuildName":
			settings.BuildName, err = typeutils.ToString(v, k)
		case "Verbosity":
			settings.Verbosity, err = typeutils.ToString(v, k)
		case "TaskSettings":
			settings.TaskSettings, err = typeutils.ToMapStringMapStringInterface(v, k)
		case "FormatVersion":
			settings.GoxcConfigVersion, err = typeutils.ToString(v, k)
		case "ConfigVersion":
			settings.GoxcConfigVersion, err = typeutils.ToString(v, k)
		case "BuildSettings":
			m, err := typeutils.ToMap(v, k)
			if err == nil {
				settings.BuildSettings, err = buildSettingsFromMap(m)
				if err == nil {
					//log.Printf("Parsed build settings OK (%+v)", settings.BuildSettings)
				}
			}
		case "Env":
			settings.Env, err = typeutils.ToStringSlice(v, k)
		default:
			log.Printf("Warning!! Unrecognised Setting '%s' (value %v)", k, v)
		}
		if err != nil {
			return settings, err
		}
	}
	return settings, err
}
Exemple #7
0
func debSourceBuild(tp TaskParams) (err error) {
	metadata := tp.Settings.GetTaskSettingMap(TASK_PKG_SOURCE, "metadata")
	metadataDeb := tp.Settings.GetTaskSettingMap(TASK_PKG_SOURCE, "metadata-deb")
	//default to just package <packagename>
	description := "package " + tp.AppName
	if desc, keyExists := metadata["description"]; keyExists {
		description, err = typeutils.ToString(desc, "description")
		if err != nil {
			return err
		}
	}
	maintainer := "?"
	if maint, keyExists := metadata["maintainer"]; keyExists {
		maintainer, err = typeutils.ToString(maint, "maintainer")
		if err != nil {
			return err
		}
	}
	maintainerEmail := "?"
	if maint, keyExists := metadata["maintainerEmail"]; keyExists {
		maintainerEmail, err = typeutils.ToString(maint, "maintainerEmail")
		if err != nil {
			return err
		}
	}
	version := tp.Settings.GetFullVersionName()
	arches := "all"
	items, err := sdeb.SdebGetSourcesAsArchiveItems(tp.WorkingDirectory, tp.AppName+"-"+tp.Settings.GetFullVersionName())
	if err != nil {
		return err
	}
	if err != nil {
		return err
	}

	//build
	//1. generate orig.tar.gz
	destDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName(), "source-deb")
	err = os.MkdirAll(destDir, 0777)
	if err != nil {
		return err
	}

	//set up template
	templateDir := tp.Settings.GetTaskSettingString(TASK_PKG_SOURCE, "templateDir")
	templateVars := getTemplateVars(tp.AppName, tp.Settings.GetFullVersionName(), maintainer, maintainerEmail, tp.Settings.GetFullVersionName(), arches, description, metadataDeb)

	//TODO add/exclude resources to /usr/share
	origTgzName := tp.AppName + "_" + version + ".orig.tar.gz"
	origTgzPath := filepath.Join(destDir, origTgzName)
	err = archive.TarGz(origTgzPath, items)
	if err != nil {
		return err
	}
	log.Printf("Created %s", origTgzPath)

	checksumMd5, checksumSha1, checksumSha256, err := checksums(origTgzPath, origTgzName)
	if err != nil {
		return err
	}
	templateVars.Files = append(templateVars.Files, *checksumMd5)
	templateVars.ChecksumsSha1 = append(templateVars.ChecksumsSha1, *checksumSha1)
	templateVars.ChecksumsSha256 = append(templateVars.ChecksumsSha256, *checksumSha256)

	//2. generate .debian.tar.gz (just containing debian/ directory)

	//debian/control
	controlData, err := getDebMetadataFileContent(filepath.Join(templateDir, "control.tpl"), sdeb.TEMPLATE_SOURCEDEB_CONTROL, templateVars)
	if err != nil {
		return err
	}

	//compat
	compatData, err := getDebMetadataFileContent(filepath.Join(templateDir, "compat.tpl"), sdeb.TEMPLATE_DEBIAN_COMPAT, templateVars)
	if err != nil {
		return err
	}

	//debian/rules
	rulesData, err := getDebMetadataFileContent(filepath.Join(templateDir, "rules.tpl"), sdeb.TEMPLATE_DEBIAN_RULES, templateVars)
	if err != nil {
		return err
	}

	//debian/source/format
	sourceFormatData, err := getDebMetadataFileContent(filepath.Join(templateDir, "source_format.tpl"), sdeb.TEMPLATE_DEBIAN_SOURCE_FORMAT, templateVars)
	if err != nil {
		return err
	}

	//debian/source/options
	sourceOptionsData, err := getDebMetadataFileContent(filepath.Join(templateDir, "source_options.tpl"), sdeb.TEMPLATE_DEBIAN_SOURCE_OPTIONS, templateVars)
	if err != nil {
		return err
	}

	//debian/rules
	copyrightData, err := getDebMetadataFileContent(filepath.Join(templateDir, "copyright.tpl"), sdeb.TEMPLATE_DEBIAN_COPYRIGHT, templateVars)
	if err != nil {
		return err
	}

	//debian/changelog (slightly different)
	changelogFilename := tp.Settings.GetTaskSettingString(TASK_PKG_SOURCE, "changelogFile")
	var changelogData []byte
	_, err = os.Stat(changelogFilename)
	if os.IsNotExist(err) {
		initialChangelogTemplate := sdeb.TEMPLATE_CHANGELOG_HEADER + "\n\n" + sdeb.TEMPLATE_CHANGELOG_INITIAL_ENTRY + "\n\n" + sdeb.TEMPLATE_CHANGELOG_FOOTER
		changelogData, err = getDebMetadataFileContent(filepath.Join(templateDir, "initial-changelog.tpl"), initialChangelogTemplate, templateVars)
		if err != nil {
			return err
		}
	} else if err != nil {
		return err
	} else {
		changelogData, err = ioutil.ReadFile(changelogFilename)
		if err != nil {
			return err
		}
	}

	//generate debian/README.Debian
	//TODO: try pulling in README.md etc
	//debian/README.Debian
	readmeData, err := getDebMetadataFileContent(filepath.Join(templateDir, "readme.tpl"), sdeb.TEMPLATE_DEBIAN_README, templateVars)
	if err != nil {
		return err
	}
	debTgzName := tp.AppName + "_" + version + ".debian.tar.gz"
	debTgzPath := filepath.Join(destDir, debTgzName)
	err = archive.TarGz(debTgzPath,
		[]archive.ArchiveItem{
			archive.ArchiveItemFromBytes(changelogData, "debian/changelog"),
			archive.ArchiveItemFromBytes(copyrightData, "debian/copyright"),
			archive.ArchiveItemFromBytes(compatData, "debian/compat"),
			archive.ArchiveItemFromBytes(controlData, "debian/control"),
			archive.ArchiveItemFromBytes(readmeData, "debian/README.Debian"),
			archive.ArchiveItemFromBytes(rulesData, "debian/rules"),
			archive.ArchiveItemFromBytes(sourceFormatData, "debian/source/format"),
			archive.ArchiveItemFromBytes(sourceOptionsData, "debian/source/options")})
	if err != nil {
		return err
	}
	log.Printf("Created %s", debTgzPath)

	checksumMd5, checksumSha1, checksumSha256, err = checksums(debTgzPath, debTgzName)
	if err != nil {
		return err
	}
	templateVars.Files = append(templateVars.Files, *checksumMd5)
	templateVars.ChecksumsSha1 = append(templateVars.ChecksumsSha1, *checksumSha1)
	templateVars.ChecksumsSha256 = append(templateVars.ChecksumsSha256, *checksumSha256)

	dscData, err := getDebMetadataFileContent(filepath.Join(templateDir, "dsc.tpl"), sdeb.TEMPLATE_DEBIAN_DSC, templateVars)
	if err != nil {
		return err
	}
	//3. generate .dsc file
	dscPath := filepath.Join(destDir, tp.AppName+"_"+version+".dsc")
	err = ioutil.WriteFile(dscPath, dscData, 0644)
	if err == nil {
		log.Printf("Wrote %s", dscPath)
	}
	return err
}
Exemple #8
0
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

}
Exemple #9
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
}