This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new d08b59e7 newt: Auto-detect number of build jobs with -j 0
d08b59e7 is described below

commit d08b59e7f9b84a85d9b5336fb9d7fcb26fd5d4c1
Author: Szymon Janc <[email protected]>
AuthorDate: Mon Oct 12 19:46:09 2026 +0200

    newt: Auto-detect number of build jobs with -j 0
    
    Passing "-j 0" resulted in no build workers being started, so nothing
    was compiled and linking failed. Make 0 mean one job per CPU available
    to newt and reject negative values.
    
    CPU count is taken from runtime.GOMAXPROCS(0), which is also used as the
    default. It honors CPU affinity on all platforms and cgroup CPU limits
    on Linux (Go 1.25+), and does not rely on /proc/cpuinfo layout, which
    made gopsutil report 0 cores on ARM (e.g. Raspberry Pi). This drops the
    gopsutil dependency.
    
    Note that on SMT-capable hosts the default now counts logical CPUs
    instead of physical cores.
    
    Assisted-by: Claude:claude-opus-5-5
---
 docs/command_list/newt_build.rst        |  2 +-
 docs/command_list/newt_clean.rst        |  2 +-
 docs/command_list/newt_create_image.rst |  2 +-
 docs/command_list/newt_debug.rst        |  2 +-
 docs/command_list/newt_help.rst         |  2 +-
 docs/command_list/newt_info.rst         |  2 +-
 docs/command_list/newt_load.rst         |  2 +-
 docs/command_list/newt_mfg.rst          |  2 +-
 docs/command_list/newt_new.rst          |  2 +-
 docs/command_list/newt_pkg.rst          |  2 +-
 docs/command_list/newt_resign_image.rst |  2 +-
 docs/command_list/newt_run.rst          |  2 +-
 docs/command_list/newt_size.rst         |  2 +-
 docs/command_list/newt_target.rst       |  2 +-
 docs/command_list/newt_test.rst         |  2 +-
 docs/command_list/newt_upgrade.rst      |  2 +-
 docs/command_list/newt_vals.rst         |  2 +-
 docs/command_list/newt_version.rst      |  2 +-
 docs/install/newt_linux.rst             |  2 +-
 docs/install/newt_mac.rst               |  2 +-
 docs/install/newt_windows.rst           |  2 +-
 docs/newt_ops.rst                       |  2 +-
 go.mod                                  |  5 -----
 go.sum                                  | 12 ------------
 newt/newt.go                            | 34 +++++++++++++++++++--------------
 25 files changed, 42 insertions(+), 53 deletions(-)

diff --git a/docs/command_list/newt_build.rst b/docs/command_list/newt_build.rst
index ba2a3c6b..cf584bfa 100644
--- a/docs/command_list/newt_build.rst
+++ b/docs/command_list/newt_build.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_clean.rst b/docs/command_list/newt_clean.rst
index 0fd0e6ef..bf2dc907 100644
--- a/docs/command_list/newt_clean.rst
+++ b/docs/command_list/newt_clean.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_create_image.rst 
b/docs/command_list/newt_create_image.rst
index bd5e9423..f0a8d389 100644
--- a/docs/command_list/newt_create_image.rst
+++ b/docs/command_list/newt_create_image.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_debug.rst b/docs/command_list/newt_debug.rst
index 6978c7e1..d73ef175 100644
--- a/docs/command_list/newt_debug.rst
+++ b/docs/command_list/newt_debug.rst
@@ -24,7 +24,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_help.rst b/docs/command_list/newt_help.rst
index 6a722eb7..251beb50 100644
--- a/docs/command_list/newt_help.rst
+++ b/docs/command_list/newt_help.rst
@@ -25,7 +25,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_info.rst b/docs/command_list/newt_info.rst
index 5bc5ab83..84adf26f 100644
--- a/docs/command_list/newt_info.rst
+++ b/docs/command_list/newt_info.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_load.rst b/docs/command_list/newt_load.rst
index f2fd4125..c27601e2 100644
--- a/docs/command_list/newt_load.rst
+++ b/docs/command_list/newt_load.rst
@@ -23,7 +23,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_mfg.rst b/docs/command_list/newt_mfg.rst
index fd03b467..89fbbbd2 100644
--- a/docs/command_list/newt_mfg.rst
+++ b/docs/command_list/newt_mfg.rst
@@ -26,7 +26,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_new.rst b/docs/command_list/newt_new.rst
index 5c49ecd4..0a02a61a 100644
--- a/docs/command_list/newt_new.rst
+++ b/docs/command_list/newt_new.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_pkg.rst b/docs/command_list/newt_pkg.rst
index 999947ed..c0ad2486 100644
--- a/docs/command_list/newt_pkg.rst
+++ b/docs/command_list/newt_pkg.rst
@@ -23,7 +23,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_resign_image.rst 
b/docs/command_list/newt_resign_image.rst
index 7a942399..0fffb735 100644
--- a/docs/command_list/newt_resign_image.rst
+++ b/docs/command_list/newt_resign_image.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_run.rst b/docs/command_list/newt_run.rst
index 099451e0..fc3eb0b4 100644
--- a/docs/command_list/newt_run.rst
+++ b/docs/command_list/newt_run.rst
@@ -29,7 +29,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_size.rst b/docs/command_list/newt_size.rst
index b4e2eab4..a79142d8 100644
--- a/docs/command_list/newt_size.rst
+++ b/docs/command_list/newt_size.rst
@@ -24,7 +24,7 @@ Global Flags:
 .. code-block:: console
 
       -h, --help              Help for newt commands
-      -j, --jobs int          Number of concurrent build jobs (default 8)
+      -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
       -l, --loglevel string   Log level (default "WARN")
       -o, --outfile string    Filename to tee output to
       -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_target.rst 
b/docs/command_list/newt_target.rst
index 818e041b..06635ff7 100644
--- a/docs/command_list/newt_target.rst
+++ b/docs/command_list/newt_target.rst
@@ -31,7 +31,7 @@ Global Flags:
 .. code-block:: console
 
       -h, --help              Help for newt commands
-      -j, --jobs int          Number of concurrent build jobs (default 8)
+      -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
       -l, --loglevel string   Log level (default "WARN")
       -o, --outfile string    Filename to tee output to
       -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_test.rst b/docs/command_list/newt_test.rst
index a971cdaf..86cf384e 100644
--- a/docs/command_list/newt_test.rst
+++ b/docs/command_list/newt_test.rst
@@ -23,7 +23,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_upgrade.rst 
b/docs/command_list/newt_upgrade.rst
index 05fda7e5..36d473b5 100644
--- a/docs/command_list/newt_upgrade.rst
+++ b/docs/command_list/newt_upgrade.rst
@@ -23,7 +23,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_vals.rst b/docs/command_list/newt_vals.rst
index 9a641286..3fa73a4a 100644
--- a/docs/command_list/newt_vals.rst
+++ b/docs/command_list/newt_vals.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/command_list/newt_version.rst 
b/docs/command_list/newt_version.rst
index b6ef0e4c..03fc273c 100644
--- a/docs/command_list/newt_version.rst
+++ b/docs/command_list/newt_version.rst
@@ -16,7 +16,7 @@ Global Flags:
 .. code-block:: console
 
         -h, --help              Help for newt commands
-        -j, --jobs int          Number of concurrent build jobs (default 8)
+        -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 8)
         -l, --loglevel string   Log level (default "WARN")
         -o, --outfile string    Filename to tee output to
         -q, --quiet             Be quiet; only display error output
diff --git a/docs/install/newt_linux.rst b/docs/install/newt_linux.rst
index 13bc169e..06410c60 100644
--- a/docs/install/newt_linux.rst
+++ b/docs/install/newt_linux.rst
@@ -100,7 +100,7 @@ Checking the Installed Version of Newt
     Flags:
           --escape            Apply Windows escapes to shell commands
       -h, --help              Help for newt commands
-      -j, --jobs int          Number of concurrent build jobs (default 4)
+      -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 4)
       -l, --loglevel string   Log level (default "WARN")
       -o, --outfile string    Filename to tee output to
       -q, --quiet             Be quiet; only display error output
diff --git a/docs/install/newt_mac.rst b/docs/install/newt_mac.rst
index 1593f70f..3cc3666b 100644
--- a/docs/install/newt_mac.rst
+++ b/docs/install/newt_mac.rst
@@ -165,7 +165,7 @@ Get information about newt:
 
     Flags:
       -h, --help              Help for newt commands
-      -j, --jobs int          Number of concurrent build jobs (default 4)
+      -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 4)
       -l, --loglevel string   Log level (default "WARN")
       -o, --outfile string    Filename to tee output to
       -q, --quiet             Be quiet; only display error output
diff --git a/docs/install/newt_windows.rst b/docs/install/newt_windows.rst
index 25852807..baf4cb8d 100644
--- a/docs/install/newt_windows.rst
+++ b/docs/install/newt_windows.rst
@@ -229,7 +229,7 @@ Checking the Installed Version
     Flags:
           --escape            Apply Windows escapes to shell commands
       -h, --help              Help for newt commands
-      -j, --jobs int          Number of concurrent build jobs (default 4)
+      -j, --jobs int          Number of concurrent build jobs (0 = number of 
CPUs) (default 4)
       -l, --loglevel string   Log level (default "WARN")
       -o, --outfile string    Filename to tee output to
       -q, --quiet             Be quiet; only display error output
diff --git a/docs/newt_ops.rst b/docs/newt_ops.rst
index 5d723204..48199fc1 100644
--- a/docs/newt_ops.rst
+++ b/docs/newt_ops.rst
@@ -59,7 +59,7 @@ through the ``-h`` or ``--help`` options.
 
         Global Flags:
           -h, --help              Help for newt commands
-          -j, --jobs int          Number of concurrent build jobs (default 8)
+          -j, --jobs int          Number of concurrent build jobs (0 = number 
of CPUs) (default 8)
           -l, --loglevel string   Log level (default "WARN")
           -o, --outfile string    Filename to tee output to
           -q, --quiet             Be quiet; only display error output
diff --git a/go.mod b/go.mod
index 9034db2c..36110cb4 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,6 @@ require (
        github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
        github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
        github.com/otiai10/copy v1.9.0
-       github.com/shirou/gopsutil v2.21.11+incompatible
        github.com/sirupsen/logrus v1.9.1
        github.com/spf13/cast v1.5.0
        github.com/spf13/cobra v1.6.1
@@ -16,13 +15,9 @@ require (
 
 require (
        github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5 
// indirect
-       github.com/go-ole/go-ole v1.2.6 // indirect
        github.com/google/go-cmp v0.6.0 // indirect
        github.com/inconshreveable/mousetrap v1.1.0 // indirect
        github.com/pkg/errors v0.9.1 // indirect
-       github.com/tklauser/go-sysconf v0.3.11 // indirect
-       github.com/tklauser/numcpus v0.6.0 // indirect
-       github.com/yusufpapurcu/wmi v1.2.2 // indirect
        golang.org/x/crypto v0.52.0 // indirect
        golang.org/x/sys v0.45.0 // indirect
        golang.org/x/term v0.43.0 // indirect
diff --git a/go.sum b/go.sum
index cf59bd4a..e4548edf 100644
--- a/go.sum
+++ b/go.sum
@@ -8,8 +8,6 @@ github.com/davecgh/go-spew v1.1.1 
h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod 
h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/frankban/quicktest v1.14.3 
h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
 github.com/frankban/quicktest v1.14.3/go.mod 
h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
-github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
-github.com/go-ole/go-ole v1.2.6/go.mod 
h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
 github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 github.com/google/go-cmp v0.6.0/go.mod 
h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 github.com/inconshreveable/mousetrap v1.0.1/go.mod 
h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
@@ -37,8 +35,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod 
h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
 github.com/rogpeppe/go-internal v1.6.1 
h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
 github.com/rogpeppe/go-internal v1.6.1/go.mod 
h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod 
h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
-github.com/shirou/gopsutil v2.21.11+incompatible 
h1:lOGOyCG67a5dv2hq5Z1BLDUqqKp3HkbjPcz5j6XMS0U=
-github.com/shirou/gopsutil v2.21.11+incompatible/go.mod 
h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/sirupsen/logrus v1.9.1 
h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ=
 github.com/sirupsen/logrus v1.9.1/go.mod 
h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
 github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
@@ -50,17 +46,9 @@ github.com/spf13/pflag v1.0.5/go.mod 
h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
 github.com/stretchr/objx v0.1.0/go.mod 
h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.7.0 
h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
 github.com/stretchr/testify v1.7.0/go.mod 
h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/tklauser/go-sysconf v0.3.11 
h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
-github.com/tklauser/go-sysconf v0.3.11/go.mod 
h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
-github.com/tklauser/numcpus v0.6.0 
h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
-github.com/tklauser/numcpus v0.6.0/go.mod 
h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
-github.com/yusufpapurcu/wmi v1.2.2 
h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
-github.com/yusufpapurcu/wmi v1.2.2/go.mod 
h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
 golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
 golang.org/x/crypto v0.52.0/go.mod 
h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
-golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
 golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
 golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
diff --git a/newt/newt.go b/newt/newt.go
index 021c34a5..5a443624 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -24,7 +24,6 @@ import (
        "os"
        "runtime"
 
-       "github.com/shirou/gopsutil/cpu"
        log "github.com/sirupsen/logrus"
        "github.com/spf13/cobra"
        "mynewt.apache.org/newt/newt/cli"
@@ -40,21 +39,25 @@ var newtLogFile string
 var newtNumJobs int
 var newtHelp bool
 
+// Returns the number of CPUs available to this process.  GOMAXPROCS honors
+// CPU affinity on all platforms and cgroup CPU limits on Linux.
 func newtDfltNumJobs() int {
-       maxProcs := runtime.GOMAXPROCS(0)
-       numCpu := runtime.NumCPU()
-       cpu, err := cpu.Counts(false)
-       if err == nil && cpu > 0 {
-               numCpu = cpu
+       return max(runtime.GOMAXPROCS(0), 1)
+}
+
+// Returns the number of concurrent build jobs to use for the specified -j
+// value.  0 means one job per CPU available to this process.
+func newtResolveNumJobs(numJobs int) (int, error) {
+       if numJobs < 0 {
+               return 0, util.FmtNewtError(
+                       "Invalid number of jobs: %d; must be 0 or greater", 
numJobs)
        }
-       var numJobs int
-       if maxProcs < numCpu {
-               numJobs = maxProcs
-       } else {
-               numJobs = numCpu
+
+       if numJobs == 0 {
+               numJobs = newtDfltNumJobs()
        }
 
-       return numJobs
+       return numJobs, nil
 }
 
 func newtCmd() *cobra.Command {
@@ -100,7 +103,10 @@ func newtCmd() *cobra.Command {
                                cli.NewtUsage(nil, err)
                        }
 
-                       newtutil.NewtNumJobs = newtNumJobs
+                       newtutil.NewtNumJobs, err = 
newtResolveNumJobs(newtNumJobs)
+                       if err != nil {
+                               cli.NewtUsage(nil, err)
+                       }
                },
                Run: func(cmd *cobra.Command, args []string) {
                        cmd.Help()
@@ -118,7 +124,7 @@ func newtCmd() *cobra.Command {
        newtCmd.PersistentFlags().StringVarP(&newtLogFile, "outfile", "o",
                "", "Filename to tee output to")
        newtCmd.PersistentFlags().IntVarP(&newtNumJobs, "jobs", "j",
-               newtDfltNumJobs(), "Number of concurrent build jobs")
+               newtDfltNumJobs(), "Number of concurrent build jobs (0 = number 
of CPUs)")
        newtCmd.PersistentFlags().BoolVarP(&newtHelp, "help", "h",
                false, "Help for newt commands")
        newtCmd.PersistentFlags().BoolVarP(&util.EscapeShellCmds, "escape", "",

Reply via email to