Example #1
0
func runTaskCopyResources(tp TaskParams) error {
	resources := core.ParseIncludeResources(tp.WorkingDirectory, tp.Settings.ResourcesInclude, tp.Settings.ResourcesExclude, tp.Settings.IsVerbose())
	destFolder := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName())
	log.Printf("resources: %v", resources)
	for _, resource := range resources {
		if strings.HasPrefix(resource, tp.WorkingDirectory) {
			resource = resource[len(tp.WorkingDirectory)+1:]
		}
		//_, resourcebase := filepath.Split(resource)
		sourcePath := filepath.Join(tp.WorkingDirectory, resource)
		destPath := filepath.Join(destFolder, resource)
		finfo, err := os.Lstat(sourcePath)
		if err != nil {
			return err
		}
		if finfo.IsDir() {
			err = os.MkdirAll(destPath, 0777)
			if err != nil && !os.IsExist(err) {
				return err
			}
		} else {
			err = os.MkdirAll(filepath.Dir(destPath), 0777)
			if err != nil && !os.IsExist(err) {
				return err
			}
			_, err = copyFile(sourcePath, destPath)
		}
		if err != nil {
			return err
		}
	}
	return nil
}
Example #2
0
File: archive.go Project: yl10/goxc
func archivePlat(goos, arch string, mainDirs []string, workingDirectory, outDestRoot string, settings *config.Settings, ending string, archiver archive.Archiver, includeTopLevelDir bool) error {
	resources := core.ParseIncludeResources(workingDirectory, settings.ResourcesInclude, settings.ResourcesExclude, !settings.IsQuiet())
	//log.Printf("Resources: %v", resources)
	exes := []string{}
	for _, mainDir := range mainDirs {
		var exeName string
		if len(mainDirs) == 1 {
			exeName = settings.AppName
		} else {
			exeName = filepath.Base(mainDir)
		}
		binPath, err := core.GetAbsoluteBin(goos, arch, settings.AppName, exeName, workingDirectory, settings.GetFullVersionName(), settings.OutPath, settings.ArtifactsDest)

		if err != nil {
			return err
		}
		exes = append(exes, binPath)
	}
	outDir := filepath.Join(outDestRoot, settings.GetFullVersionName())
	err := os.MkdirAll(outDir, 0777)
	if err != nil {
		return err
	}
	archivePath, err := archive.ArchiveBinariesAndResources(outDir, goos+"_"+arch,
		exes, settings.AppName, resources, *settings, archiver, ending, includeTopLevelDir)
	if err != nil {
		log.Printf("ZIP error: %s", err)
		return err
	} else {
		if !settings.IsQuiet() {
			log.Printf("Artifact(s) archived to %s", archivePath)
		}
	}
	return nil
}