Maytham Alsudany pushed to branch master at lintian / lintian


Commits:
be30cc13 by Maytham Alsudany at 2025-03-20T00:26:34+00:00
Emit warning when nproc is used in debian/rules

As per Debian Policy 4.9.1, packages should respect `parallel` in
`DEB_BUILD_OPTIONS`. Using `nproc` without checking `DEB_BUILD_OPTIONS`
is not good.

This commit adds the debian-rules-calls-nproc tag, which is emitted when
`nproc` is executed in debian/rules.

Closes: #1088671

Apply fixes

- - - - -


6 changed files:

- lib/Lintian/Check/Debian/Rules.pm
- + 
t/recipes/checks/debian/rules/debian-rules-calls-nproc/build-spec/debian/rules
- + 
t/recipes/checks/debian/rules/debian-rules-calls-nproc/build-spec/fill-values
- + t/recipes/checks/debian/rules/debian-rules-calls-nproc/eval/desc
- + t/recipes/checks/debian/rules/debian-rules-calls-nproc/eval/hints
- + tags/d/debian-rules-calls-nproc.tag


Changes:

=====================================
lib/Lintian/Check/Debian/Rules.pm
=====================================
@@ -456,6 +456,12 @@ sub source {
                 $pointer);
         }
 
+        if ($line =~ /\$\$\(\s*((\/usr)?\/bin\/)?nproc\s*\)/s
+            || $line =~ /\$\(shell \s*((\/usr)?\/bin\/)?nproc\s*\)/s
+            || $line =~ /`\s*((\/usr)?\/bin\/)?nproc\s*\`/s) {
+            $self->pointed_hint('debian-rules-calls-nproc',$pointer);
+        }
+
         if ($line !~ /^ifn?(?:eq|def)\s/ && $line =~ /^([^\s:][^:]*):+(.*)/s) {
             my ($target_names, $target_dependencies) = ($1, $2);
             @current_targets = split $SPACE, $target_names;


=====================================
t/recipes/checks/debian/rules/debian-rules-calls-nproc/build-spec/debian/rules
=====================================
@@ -0,0 +1,12 @@
+#!/usr/bin/make -f
+
+NUM_CPUS=`/usr/bin/nproc`
+
+%:
+       dh $@
+
+override_dh_auto_build:
+       # This use of `nproc` will not cause a hint. 
+       @echo "Building with $$(nproc) jobs."
+       dh_auto_build -- -j $(shell nproc)
+       echo Just saying the word nproc also will not cause a hint.


=====================================
t/recipes/checks/debian/rules/debian-rules-calls-nproc/build-spec/fill-values
=====================================
@@ -0,0 +1,3 @@
+Skeleton: source-native
+Testname: debian-rules-calls-nproc
+Description: debian/rules calls nproc


=====================================
t/recipes/checks/debian/rules/debian-rules-calls-nproc/eval/desc
=====================================
@@ -0,0 +1,2 @@
+Testname: debian-rules-calls-nproc
+Check: debian/rules


=====================================
t/recipes/checks/debian/rules/debian-rules-calls-nproc/eval/hints
=====================================
@@ -0,0 +1,3 @@
+debian-rules-calls-nproc (source): debian-rules-calls-nproc [debian/rules:3]
+debian-rules-calls-nproc (source): debian-rules-calls-nproc [debian/rules:11]
+debian-rules-calls-nproc (source): debian-rules-calls-nproc [debian/rules:10]


=====================================
tags/d/debian-rules-calls-nproc.tag
=====================================
@@ -0,0 +1,20 @@
+Tag: debian-rules-calls-nproc
+Severity: warning
+Check: debian/rules
+Explanation: The <code>debian/rules</code> file for this package appears to
+ use nproc to determine the number of jobs to run in parallel during the
+ package build. This violates the Debian Policy, as the build must respect
+ "parallel=N" when passed in DEB_BUILD_OPTIONS.
+ .
+ To determine the number of jobs to run in parallel during the package build,
+ you can use the DEB_BUILD_OPTION_PARALLEL variable from
+ <code>/usr/share/dpkg/buildopts.mk</code>, which is set to the value of "N"
+ when "parallel=N" is passed.
+ .
+     include /usr/share/dpkg/buildopts.mk
+     NUM_CPUS=$(DEB_BUILD_OPTION_PARALLEL)
+ .
+ You can also use Make's <code>addprefix</code> to add a prefix like "-j" if
+ the DEB_BUILD_OPTION_PARALLEL variable is present, which can then be passed as
+ an argument.
+See-Also: debian-policy 4.9.1



View it on GitLab: 
https://salsa.debian.org/lintian/lintian/-/commit/be30cc13400c1313f56c52b5aa6b1f22523f1191

-- 
View it on GitLab: 
https://salsa.debian.org/lintian/lintian/-/commit/be30cc13400c1313f56c52b5aa6b1f22523f1191
You're receiving this email because of your account on salsa.debian.org.


Reply via email to