Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 6339049ee -> 85da72b12


newt - Default -j val equal to num logical CPUs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/85da72b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/85da72b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/85da72b1

Branch: refs/heads/develop
Commit: 85da72b12e717033beed4e43bd321cb22094075a
Parents: 6339049
Author: Christopher Collins <[email protected]>
Authored: Fri Jan 20 11:26:56 2017 -0800
Committer: Christopher Collins <[email protected]>
Committed: Fri Jan 20 11:26:56 2017 -0800

----------------------------------------------------------------------
 newt/newt.go | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/85da72b1/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 8395db6..7ecc608 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -22,6 +22,7 @@ package main
 import (
        "fmt"
        "os"
+       "runtime"
 
        log "github.com/Sirupsen/logrus"
        "github.com/spf13/cobra"
@@ -38,6 +39,20 @@ var newtVerbose bool
 var newtLogFile string
 var newtNumJobs int
 
+func newtDfltNumJobs() int {
+       maxProcs := runtime.GOMAXPROCS(0)
+       numCpu := runtime.NumCPU()
+
+       var numJobs int
+       if maxProcs < numCpu {
+               numJobs = maxProcs
+       } else {
+               numJobs = numCpu
+       }
+
+       return numJobs
+}
+
 func newtCmd() *cobra.Command {
        newtHelpText := cli.FormatHelp(`Newt allows you to create your own 
embedded 
                application based on the Mynewt operating system.  Newt 
provides both 
@@ -99,7 +114,7 @@ func newtCmd() *cobra.Command {
        newtCmd.PersistentFlags().StringVarP(&newtLogFile, "outfile", "o",
                "", "Filename to tee output to")
        newtCmd.PersistentFlags().IntVarP(&newtNumJobs, "jobs", "j",
-               1, "Number of concurrent build jobs")
+               newtDfltNumJobs(), "Number of concurrent build jobs")
 
        versHelpText := cli.FormatHelp(`Display the Newt version number.`)
        versHelpEx := "  newt version"

Reply via email to