Exemple #1
0
func katiMain(args []string) error {
	defer glog.Flush()
	if cpuprofile != "" {
		f, err := os.Create(cpuprofile)
		if err != nil {
			return err
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	if heapprofile != "" {
		defer writeHeapProfile()
	}
	defer kati.DumpStats()
	if memstats != "" {
		ms := memStatsDumper{
			Template: template.Must(template.New("memstats").Parse(memstats)),
		}
		ms.dump()
		defer ms.dump()
	}
	if traceEventFile != "" {
		f, err := os.Create(traceEventFile)
		if err != nil {
			panic(err)
		}
		kati.TraceEventStart(f)
		defer kati.TraceEventStop()
	}

	if shellDate != "" {
		if shellDate == "ref" {
			shellDate = shellDateTimeformat[:20] // until Z, drop 07:00
		}
		t, err := time.Parse(shellDateTimeformat, shellDate)
		if err != nil {
			panic(err)
		}
		kati.ShellDateTimestamp = t
	}

	req := kati.FromCommandLine(args)
	if makefileFlag != "" {
		req.Makefile = makefileFlag
	}
	req.EnvironmentVars = os.Environ()
	req.UseCache = useCache
	req.EagerEvalCommand = eagerCmdEvalFlag

	g, err := load(req)
	if err != nil {
		return err
	}

	err = save(g, req.Targets)
	if err != nil {
		return err
	}

	if generateNinja {
		var args []string
		if regenNinja {
			args = os.Args
		}
		n := kati.NinjaGenerator{
			Args:              args,
			Suffix:            ninjaSuffix,
			GomaDir:           gomaDir,
			DetectAndroidEcho: detectAndroidEcho,
		}
		return n.Save(g, "", req.Targets)
	}

	if syntaxCheckOnlyFlag {
		return nil
	}

	if queryFlag != "" {
		kati.Query(os.Stdout, queryFlag, g)
		return nil
	}

	execOpt := &kati.ExecutorOpt{
		NumJobs: jobsFlag,
	}
	ex, err := kati.NewExecutor(execOpt)
	if err != nil {
		return err
	}
	err = ex.Exec(g, req.Targets)
	if err != nil {
		return err
	}
	return nil
}
Exemple #2
0
func katiMain(args []string) error {
	if cpuprofile != "" {
		f, err := os.Create(cpuprofile)
		if err != nil {
			return err
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	if heapprofile != "" {
		defer writeHeapProfile()
	}
	defer kati.DumpStats()
	if memstats != "" {
		ms := memStatsDumper{
			Template: template.Must(template.New("memstats").Parse(memstats)),
		}
		ms.dump()
		defer ms.dump()
	}
	if traceEventFile != "" {
		f, err := os.Create(traceEventFile)
		if err != nil {
			panic(err)
		}
		kati.TraceEventStart(f)
		defer kati.TraceEventStop()
	}

	if shellDate != "" {
		if shellDate == "ref" {
			shellDate = shellDateTimeformat[:20] // until Z, drop 07:00
		}
		t, err := time.Parse(shellDateTimeformat, shellDate)
		if err != nil {
			panic(err)
		}
		kati.ShellDateTimestamp = t
	}

	var leafNames []string
	if findCacheLeafNames != "" {
		leafNames = strings.Fields(findCacheLeafNames)
	}
	if findCachePrunes != "" {
		kati.UseFindCache = true
		kati.AndroidFindCacheInit(strings.Fields(findCachePrunes), leafNames)
	}

	req := kati.FromCommandLine(args)
	if makefileFlag != "" {
		req.Makefile = makefileFlag
	}
	req.EnvironmentVars = os.Environ()
	req.UseCache = useCache
	req.EagerEvalCommand = eagerCmdEvalFlag

	g, cached, err := load(req)
	if err != nil {
		return err
	}

	if !cached {
		err = save(g, req.Targets)
		if err != nil {
			return err
		}
	}

	if generateNinja {
		return kati.GenerateNinja(g, gomaDir)
	}

	if syntaxCheckOnlyFlag {
		return nil
	}

	if queryFlag != "" {
		kati.Query(os.Stdout, queryFlag, g)
		return nil
	}

	execOpt := &kati.ExecutorOpt{
		NumJobs: jobsFlag,
	}
	ex, err := kati.NewExecutor(execOpt)
	if err != nil {
		return err
	}
	err = ex.Exec(g)
	if err != nil {
		return err
	}
	return nil
}