[PATCH v3 2/6] gitlab-ci: Adapt JOBS variable for FreeBSD runners

Philippe Mathieu-Daudé posted 6 patches 4 years, 7 months ago
[PATCH v3 2/6] gitlab-ci: Adapt JOBS variable for FreeBSD runners
Posted by Philippe Mathieu-Daudé 4 years, 7 months ago
'nproc' is not available on FreeBSD:

  $ JOBS=$(expr $(nproc) + 1)
  bash: line 119: nproc: command not found
  expr: syntax error

Instead, use 'sysctl -n hw.ncpu'.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 .gitlab-ci.d/buildtest-template.yml | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
index 58b01744751..fe4f18595ac 100644
--- a/.gitlab-ci.d/buildtest-template.yml
+++ b/.gitlab-ci.d/buildtest-template.yml
@@ -1,6 +1,16 @@
 .environment_variables_template:
   before_script:
-    - JOBS=$(expr $(nproc) + 1)
+    - if
+        test $(uname) = "FreeBSD"
+        ;
+      then
+        JOBS=$(sysctl -n hw.ncpu)
+        ;
+      else
+        JOBS=$(expr $(nproc) + 1)
+        ;
+      fi
+    - echo "=== Using $JOBS simultaneous jobs ==="
 
 .native_build_job_template:
   stage: build
-- 
2.26.3

Re: [PATCH v3 2/6] gitlab-ci: Adapt JOBS variable for FreeBSD runners
Posted by Willian Rampazzo 4 years, 7 months ago
On Wed, May 19, 2021 at 3:46 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> 'nproc' is not available on FreeBSD:
>
>   $ JOBS=$(expr $(nproc) + 1)
>   bash: line 119: nproc: command not found
>   expr: syntax error
>
> Instead, use 'sysctl -n hw.ncpu'.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  .gitlab-ci.d/buildtest-template.yml | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>


Re: [PATCH v3 2/6] gitlab-ci: Adapt JOBS variable for FreeBSD runners
Posted by Thomas Huth 4 years, 7 months ago
On 19/05/2021 20.45, Philippe Mathieu-Daudé wrote:
> 'nproc' is not available on FreeBSD:
> 
>    $ JOBS=$(expr $(nproc) + 1)
>    bash: line 119: nproc: command not found
>    expr: syntax error
> 
> Instead, use 'sysctl -n hw.ncpu'.

Could we maybe use "getconf _NPROCESSORS_ONLN" instead? ... that might work 
on both, Linux and FreeBSD...?

  Thomas


Re: [PATCH v3 2/6] gitlab-ci: Adapt JOBS variable for FreeBSD runners
Posted by Wainer dos Santos Moschetta 4 years, 7 months ago
Hi,

On 5/19/21 3:45 PM, Philippe Mathieu-Daudé wrote:
> 'nproc' is not available on FreeBSD:
>
>    $ JOBS=$(expr $(nproc) + 1)
>    bash: line 119: nproc: command not found
>    expr: syntax error
>
> Instead, use 'sysctl -n hw.ncpu'.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   .gitlab-ci.d/buildtest-template.yml | 12 +++++++++++-
>   1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
> index 58b01744751..fe4f18595ac 100644
> --- a/.gitlab-ci.d/buildtest-template.yml
> +++ b/.gitlab-ci.d/buildtest-template.yml
> @@ -1,6 +1,16 @@
>   .environment_variables_template:
>     before_script:
> -    - JOBS=$(expr $(nproc) + 1)
> +    - if
> +        test $(uname) = "FreeBSD"
> +        ;
> +      then
> +        JOBS=$(sysctl -n hw.ncpu)
> +        ;
> +      else
> +        JOBS=$(expr $(nproc) + 1)
> +        ;
> +      fi
> +    - echo "=== Using $JOBS simultaneous jobs ==="

It has grown to beyond variables definitions. I suggest to rename it to 
something like `.before_script_template` (pure creativity, see?).

- Wainer

>   
>   .native_build_job_template:
>     stage: build


Re: [PATCH v3 2/6] gitlab-ci: Adapt JOBS variable for FreeBSD runners
Posted by Warner Losh 4 years, 7 months ago
On Thu, May 20, 2021 at 12:18 PM Wainer dos Santos Moschetta <
wainersm@redhat.com> wrote:

> Hi,
>
> On 5/19/21 3:45 PM, Philippe Mathieu-Daudé wrote:
> > 'nproc' is not available on FreeBSD:
> >
> >    $ JOBS=$(expr $(nproc) + 1)
> >    bash: line 119: nproc: command not found
> >    expr: syntax error
> >
> > Instead, use 'sysctl -n hw.ncpu'.
> >
> > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > ---
> >   .gitlab-ci.d/buildtest-template.yml | 12 +++++++++++-
> >   1 file changed, 11 insertions(+), 1 deletion(-)
> >
> > diff --git a/.gitlab-ci.d/buildtest-template.yml
> b/.gitlab-ci.d/buildtest-template.yml
> > index 58b01744751..fe4f18595ac 100644
> > --- a/.gitlab-ci.d/buildtest-template.yml
> > +++ b/.gitlab-ci.d/buildtest-template.yml
> > @@ -1,6 +1,16 @@
> >   .environment_variables_template:
> >     before_script:
> > -    - JOBS=$(expr $(nproc) + 1)
> > +    - if
> > +        test $(uname) = "FreeBSD"
> > +        ;
> > +      then
> > +        JOBS=$(sysctl -n hw.ncpu)
> > +        ;
> > +      else
> > +        JOBS=$(expr $(nproc) + 1)
> > +        ;
> > +      fi
> > +    - echo "=== Using $JOBS simultaneous jobs ==="
>
> It has grown to beyond variables definitions. I suggest to rename it to
> something like `.before_script_template` (pure creativity, see?).
>

Also, would it help if FreeBSD were to add nproc in the future?

Warner