예제 #1
0
파일: tasks.go 프로젝트: boldfield/goxc
// run all given tasks
func RunTasks(workingDirectory string, destPlatforms []platforms.Platform, settings *config.Settings, maxProcessors int) error {
	if settings.IsVerbose() {
		log.Printf("Using Go root: %s", settings.GoRoot)
		log.Printf("looping through each platform")
	}
	appName := core.GetAppName(settings.AppName, workingDirectory)

	outDestRoot, err := core.GetOutDestRoot(appName, workingDirectory, settings.ArtifactsDest)
	if err != nil {
		return err
	}
	defer log.SetPrefix("[goxc] ")
	exclusions := ResolveAliases(settings.TasksExclude)
	appends := ResolveAliases(settings.TasksAppend)
	mains := ResolveAliases(settings.Tasks)
	all := ResolveAliases(settings.TasksPrepend)
	//log.Printf("prepending %v", all)
	all = append(all, mains...)
	all = append(all, appends...)

	//exclude by resolved task names (not by aliases)
	tasksToRun := []string{}
	for _, taskName := range all {
		if !core.ContainsString(exclusions, taskName) {
			tasksToRun = append(tasksToRun, taskName)
		}
	}
	//0.6 check all tasks are valid before continuing
	for _, taskName := range tasksToRun {
		if _, keyExists := allTasks[taskName]; !keyExists {
			if strings.HasPrefix(taskName, ".") {
				log.Printf("'%s' looks like a directory, not a task - specify 'working directory' with -wd option", taskName)
			}
			if e, _ := core.FileExists(taskName); e {
				log.Printf("'%s' looks like a directory, not a task - specify 'working directory' with -wd option", taskName)
			}
			if settings.IsVerbose() {
				log.Printf("Task '%s' does NOT exist!", taskName)
			}
			return errors.New("Task '" + taskName + "' does not exist")
		}
	}
	mainDirs := []string{}
	allPackages := []string{}
	if len(tasksToRun) == 1 && tasksToRun[0] == "toolchain" {
		log.Printf("Toolchain task only - not searching for main dirs")
		//mainDirs = []string{workingDirectory}
	} else {
		var err error
		excludes := core.ParseCommaGlobs(settings.MainDirsExclude)
		excludesSource := core.ParseCommaGlobs(settings.SourceDirsExclude)
		excludesSource = append(excludesSource, excludes...)
		allPackages, err = source.FindSourceDirs(workingDirectory, "", excludesSource, settings.IsVerbose())
		if err != nil || len(allPackages) == 0 {
			log.Printf("Warning: could not establish list of source packages. Using working directory")
			allPackages = []string{workingDirectory}
		}
		mainDirs, err = source.FindMainDirs(workingDirectory, excludes, settings.IsVerbose())
		if err != nil || len(mainDirs) == 0 {
			log.Printf("Warning: could not find any main dirs: %v", err)
		} else {
			if settings.IsVerbose() {
				log.Printf("Found 'main package' dirs (len %d): %v", len(mainDirs), mainDirs)
			}
		}
	}
	if settings.IsVerbose() {
		log.Printf("Running tasks: %v", tasksToRun)
		log.Printf("All packages: %v", allPackages)
	}
	for _, taskName := range tasksToRun {
		log.SetPrefix("[goxc:" + taskName + "] ")
		if settings.IsVerbose() {
			log.Printf("Running task %s with settings: %v", taskName, settings.TaskSettings[taskName])
		}
		err := runTask(taskName, destPlatforms, allPackages, mainDirs, appName, workingDirectory, outDestRoot, settings, maxProcessors)
		if err != nil {
			// TODO: implement 'force' option.
			log.Printf("Stopping after '%s' failed with error '%v'", taskName, err)
			return err
		} else {
			if !settings.IsQuiet() {
				log.Printf("Task %s succeeded", taskName)
			}
		}
	}
	return nil
}
예제 #2
0
파일: goxc.go 프로젝트: boldfield/goxc
func printOptions(flagSet *flag.FlagSet) {
	fmt.Print("Help Options:\n")
	taskOptions := []string{"t", "tasks+", "tasks-", "+tasks"}
	packageVersioningOptions := []string{"pv", "pr", "br", "bu"}
	deprecatedOptions := []string{"av", "z", "tasks", "h-tasks", "help-tasks", "ht"} //still work but not mentioned
	platformOptions := []string{"os", "arch", "bc"}
	cfOptions := []string{"wc", "c"}
	boolOptions := []string{"h", "v", "version", "t", "wc"}

	//help
	fmt.Printf("  -h <topic>     Help - default topic is 'options'. Also 'tasks', or any task or alias name.\n")
	fmt.Printf("  -ht            Help - show tasks (and task aliases)\n")
	fmt.Printf("  -version       %s\n", flagSet.Lookup("version").Usage)
	fmt.Printf("  -v             %s\n", flagSet.Lookup("v").Usage)

	fmt.Print("Help Topics:\n")
	fmt.Printf("  options 	    default)\n")
	fmt.Printf("  tasks         lists all tasks and aliases\n")
	fmt.Printf("  <task-name>   task description, task options, and default values\n")
	fmt.Printf("  <alias-name>  lists an alias's task(s)\n")

	//tasks
	fmt.Printf("Tasks options:\n")
	flagSet.VisitAll(func(flag *flag.Flag) {
		if core.ContainsString(taskOptions, flag.Name) {
			printFlag(flag, core.ContainsString(boolOptions, flag.Name))
		}
	})

	fmt.Printf("Platform filtering:\n")
	flagSet.VisitAll(func(flag *flag.Flag) {
		if core.ContainsString(platformOptions, flag.Name) {
			printFlag(flag, core.ContainsString(boolOptions, flag.Name))
		}
	})

	fmt.Printf("Config files:\n")
	flagSet.VisitAll(func(flag *flag.Flag) {
		if core.ContainsString(cfOptions, flag.Name) {
			printFlag(flag, core.ContainsString(boolOptions, flag.Name))
		}
	})

	//versioning
	fmt.Printf("Package versioning:\n")
	flagSet.VisitAll(func(flag *flag.Flag) {
		if core.ContainsString(packageVersioningOptions, flag.Name) {
			printFlag(flag, core.ContainsString(boolOptions, flag.Name))
		}
	})

	//build
	fmt.Printf("Build:\n")
	flagSet.VisitAll(func(flag *flag.Flag) {
		if strings.HasPrefix(flag.Name, "build-") {
			printFlag(flag, core.ContainsString(boolOptions, flag.Name))
		}
	})

	//most
	fmt.Printf("Other options:\n")
	flagSet.VisitAll(func(flag *flag.Flag) {
		if core.ContainsString(taskOptions, flag.Name) ||
			core.ContainsString(packageVersioningOptions, flag.Name) ||
			core.ContainsString(platformOptions, flag.Name) ||
			core.ContainsString(cfOptions, flag.Name) ||
			core.ContainsString(deprecatedOptions, flag.Name) ||
			core.ContainsString([]string{"h", "help", "h-options", "help-options", "version", "v"}, flag.Name) ||
			strings.HasPrefix(flag.Name, "build-") {
			return
		}
		printFlag(flag, core.ContainsString(boolOptions, flag.Name))
	})
	for _, _ = range []string{"h", "version"} {
	}
}