Exemple #1
0
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
}
Exemple #2
0
// goxc function to archive a binary along with supporting files (e.g. README or LICENCE).
func ArchiveBinariesAndResources(outDir, platName string, binPaths []string, appName string, resources []string, settings config.Settings, archiver Archiver, ending string, includeTopLevelDir bool) (zipFilename string, err error) {
	var zipName string
	if settings.PackageVersion != "" && settings.PackageVersion != core.PACKAGE_VERSION_DEFAULT {
		//0.1.6 using appname_version_platform. See issue 3
		zipName = appName + "_" + settings.GetFullVersionName() + "_" + platName
	} else {
		zipName = appName + "_" + platName
	}
	zipFilename = filepath.Join(outDir, zipName+"."+ending)
	var zipDir string
	if includeTopLevelDir {
		zipDir = zipName
	} else {
		zipDir = ""
	}
	toArchive := []ArchiveItem{}
	for _, binPath := range binPaths {
		destFile := filepath.Base(binPath)
		if zipDir != "" {
			destFile = filepath.Join(zipDir, destFile)
		}
		toArchive = append(toArchive, ArchiveItemFromFileSystem(binPath, destFile))
	}
	for _, resource := range resources {
		destFile := resource
		if zipDir != "" {
			destFile = filepath.Join(zipDir, destFile)
		}
		toArchive = append(toArchive, ArchiveItemFromFileSystem(resource, destFile))
	}
	err = archiver(zipFilename, toArchive)
	return
}
Exemple #3
0
// invoke the go command via the os/exec package
// 0.3.1
// v0.9 changed signature
func InvokeGo(workingDirectory string, subCmd string, subCmdArgs []string, env []string, settings *config.Settings) error {
	fullVersionName := settings.GetFullVersionName()
	//var buildSettings config.BuildSettings
	buildSettings := settings.BuildSettings
	goRoot := settings.GoRoot
	if settings.IsVerbose() {
		log.Printf("build settings: %s", goRoot)
	}
	cmdPath := filepath.Join(goRoot, "bin", "go")
	args := []string{subCmd}

	//these features only apply to `go build` & `go install`
	if isBuildCommand(subCmd) {
		if buildSettings.Processors != nil {
			args = append(args, "-p", strconv.Itoa(*buildSettings.Processors))
		}
		if buildSettings.Race != nil && *buildSettings.Race {
			args = append(args, "-race")
		}
		if buildSettings.Verbose != nil && *buildSettings.Verbose {
			args = append(args, "-v")
		}
		if buildSettings.PrintCommands != nil && *buildSettings.PrintCommands {
			args = append(args, "-x")
		}
		if buildSettings.CcFlags != nil && *buildSettings.CcFlags != "" {
			args = append(args, "-ccflags", *buildSettings.CcFlags)
		}
		if buildSettings.Compiler != nil && *buildSettings.Compiler != "" {
			args = append(args, "-compiler", *buildSettings.Compiler)
		}
		if buildSettings.GccGoFlags != nil && *buildSettings.GccGoFlags != "" {
			args = append(args, "-gccgoflags", *buildSettings.GccGoFlags)
		}
		if buildSettings.GcFlags != nil && *buildSettings.GcFlags != "" {
			args = append(args, "-gcflags", *buildSettings.GcFlags)
		}
		if buildSettings.InstallSuffix != nil && *buildSettings.InstallSuffix != "" {
			args = append(args, "-installsuffix", *buildSettings.InstallSuffix)
		}
		ldflags := ""
		if buildSettings.LdFlags != nil {
			ldflags = *buildSettings.LdFlags
		}
		if buildSettings.LdFlagsXVars != nil {
			//TODO!
			ldflags = ldflags + " " + buildFlags(buildInterpolationVars(*buildSettings.LdFlagsXVars, fullVersionName), "-X")
		} else {
			log.Printf("WARNING: LdFlagsXVars is nil. Not passing package version into compiler")
		}
		if ldflags != "" {
			args = append(args, "-ldflags", ldflags)
		}
		if buildSettings.Tags != nil && *buildSettings.Tags != "" {
			args = append(args, "-tags", *buildSettings.Tags)
		}
		if len(buildSettings.ExtraArgs) > 0 {
			args = append(args, buildSettings.ExtraArgs...)
		}
	}
	if settings.IsVerbose() {
		log.Printf("Env: %v", settings.Env)
	}
	if len(settings.Env) > 0 {
		vars := struct {
			PS  string
			PLS string
			Env map[string]string
		}{
			string(os.PathSeparator),
			string(os.PathListSeparator),
			map[string]string{},
		}
		for _, val := range os.Environ() {
			k, v, err := splitEnvVar(val)
			if err != nil {
				//ignore invalid env vars from environment
			} else {
				vars.Env[k] = v
			}
		}
		for _, envTpl := range settings.Env {
			if settings.IsVerbose() {
				log.Printf("Processing env var %s", envTpl)
			}
			tpl, err := template.New("envItem").Parse(envTpl)
			if err != nil {
				return err
			}
			var dest bytes.Buffer
			err = tpl.Execute(&dest, vars)
			if err != nil {
				return err
			}
			executed := dest.String()
			if settings.IsVerbose() {
				if envTpl != executed {
					log.Printf("Setting env var (converted from %s to %s)", envTpl, executed)
				} else {
					log.Printf("Setting env var from config: %s", executed)
				}
			}
			env = append(env, dest.String())
			//new address if necessary
			k, v, err := splitEnvVar(dest.String())
			if err != nil {
				//fail on badly specified ENV vars
				return errors.New("Invalid env var defined by settings")
			} else {
				vars.Env[k] = v
			}
		}
	}
	args = append(args, subCmdArgs...)
	cmd, err := NewCmd(cmdPath, workingDirectory, args, env, settings.IsVerbose(), !settings.IsQuiet())
	if err != nil {
		return err
	}
	if settings.IsVerbose() {
		log.Printf("invoking '%s %v' from '%s'", cmdPath, PrintableArgs(args), workingDirectory)
	}

	err = StartAndWait(cmd)
	if err != nil {
		log.Printf("'go' returned error: %s", err)
		return err
	}
	if settings.IsVerbose() {
		log.Printf("'go' completed successfully")
	}
	return nil

}