[pacman-dev,1/1] makepkg: add support for parallel jobs during compilation

Message ID 5903731b385642b429a8ca900642a94283f9cce9.1630956442.git.dacohen@pm.me
State Rejected, archived
Headers show
Series makepkg: add support for parallel jobs during compilation | expand

Commit Message

David Cohen Sept. 6, 2021, 7:33 p.m. UTC
Currently PKGBUILD has no way to receive from makepkg if it wants to use
parallel jobs during compilation. This patch adds the '-jN' option to
makepkg, which will propagate to PKGBUILD 2 variables:
JOBS is 0 if options is not used, or N otherwise.
JOBS_ARG is an empty string is option is not used, or '-jN' otherwise.

If the PKGBUILD script does not support parallel jobs, this option will
have no impact during the compilation.

Signed-off-by: David Cohen <dacohen@pm.me>
---
 doc/makepkg.8.asciidoc | 7 +++++++
 scripts/makepkg.sh.in  | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

--
2.33.0

Comments

Santiago Torres Arias Sept. 6, 2021, 7:37 p.m. UTC | #1
On Mon, Sep 06, 2021 at 07:33:17PM +0000, David Cohen via pacman-dev wrote:
> Currently PKGBUILD has no way to receive from makepkg if it wants to use
> parallel jobs during compilation. This patch adds the '-jN' option to
> makepkg, which will propagate to PKGBUILD 2 variables:
> JOBS is 0 if options is not used, or N otherwise.
> JOBS_ARG is an empty string is option is not used, or '-jN' otherwise.
> 
> If the PKGBUILD script does not support parallel jobs, this option will
> have no impact during the compilation.

Hi David.

Thank you for your contribution!

It appears to me that you can achieve this by doing proper changes here.

    https://gitlab.archlinux.org/pacman/pacman/-/blob/master/etc/makepkg.conf.in#L46

I wonder if this is rather another way to do it through the CLI, and I
wonder if we can evaluate its usefulness on those grounds :)

Cheers!
-Santiago

Patch

diff --git a/doc/makepkg.8.asciidoc b/doc/makepkg.8.asciidoc
index 38032e7b..6b6a481e 100644
--- a/doc/makepkg.8.asciidoc
+++ b/doc/makepkg.8.asciidoc
@@ -99,6 +99,13 @@  Options
 	Install or upgrade the package after a successful build using
 	linkman:pacman[8].

+*-j* <jobs>::
+	Suggest simultaneous jobs in parallel during compilation. If `PKGBUILD`
+	supports parallel compilation, it can use JOBS and JOBS_ARG variables.
+	JOBS is 0 if option is not used, or <jobs> otherwise.
+	JOBS_ARG is empty string if option is not used, or -j<jobs> otherwise.
+	If `PKGBUILD` does not support it, the option will make no difference.
+
 *-L, \--log*::
 	Enable logging. This will use the *tee* program to send the output of each
 	of the PKGBUILD functions to both the console and to a text file in the
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index e58edfa1..1a590d03 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -61,6 +61,8 @@  HOLDVER=0
 IGNOREARCH=0
 INFAKEROOT=0
 INSTALL=0
+JOBS=0
+JOBS_ARG=''
 LOGGING=0
 NEEDED=0
 NOARCHIVE=0
@@ -975,6 +977,7 @@  usage() {
 	printf -- "$(gettext "  -g, --geninteg   Generate integrity checks for source files")\n"
 	printf -- "$(gettext "  -h, --help       Show this help message and exit")\n"
 	printf -- "$(gettext "  -i, --install    Install package after successful build")\n"
+	printf -- "$(gettext "  -j <jobs>        Suggest simultaneous jobs in parallel during compilation")\n"
 	printf -- "$(gettext "  -L, --log        Log package build process")\n"
 	printf -- "$(gettext "  -m, --nocolor    Disable colorized output messages")\n"
 	printf -- "$(gettext "  -o, --nobuild    Download and extract files only")\n"
@@ -1037,7 +1040,7 @@  fi
 ARGLIST=("$@")

 # Parse Command Line Options.
-OPT_SHORT="AcCdefFghiLmop:rRsSV"
+OPT_SHORT="AcCdefFghij:Lmop:rRsSV"
 OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 'config:' 'force' 'geninteg'
           'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild'
           'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'packagelist'
@@ -1076,6 +1079,7 @@  while true; do
 		-g|--geninteg)    BUILDPKG=0 GENINTEG=1 IGNOREARCH=1;;
 		--holdver)        HOLDVER=1 ;;
 		-i|--install)     INSTALL=1 ;;
+		-j)               shift; JOBS=$1 JOBS_ARG="-j$1" ;;
 		--key)            shift; GPGKEY=$1 ;;
 		-L|--log)         LOGGING=1 ;;
 		-m|--nocolor)     USE_COLOR='n'; PACMAN_OPTS+=("--color" "never") ;;