[jhalfs] 01/01: Replace $(nproc || echo 1) and $(nproc)

"Git Owner" ([email protected] via alfs-discuss Mailing List) <[email protected]>
Newsgroups gmane.linux.lfs.automated
Message-ID <[email protected]>
This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch xry111/parallelism
in repository jhalfs.

commit 26014d1fbf60d5c2d32ff6098e7ea6b568296ddd
Author: Xi Ruoyao <[email protected]>
AuthorDate: Mon Sep 11 14:38:15 2023 +0800

    Replace $(nproc || echo 1) and $(nproc)
---
 LFS/lfs.xsl                  | 10 ++++++++++
 common/chroot.xsl            | 19 ++++++++++++++++---
 common/libs/func_book_parser | 13 +++++++++++--
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/LFS/lfs.xsl b/LFS/lfs.xsl
index c6075d6..c66c793 100644
--- a/LFS/lfs.xsl
+++ b/LFS/lfs.xsl
@@ -28,6 +28,10 @@
   -->
   <xsl:param name="testsuite" select="1"/>
 
+  <!-- Parallelism (LFS >= 12.1) -->
+  <xsl:param name="jobs_1" select="1"/>
+  <xsl:param name="jobs_2" select="1"/>
+
   <!-- Install non wide character ncurses 5? -->
   <xsl:param name="ncurses5" select="'n'"/>
 
@@ -615,6 +619,12 @@ unset OLD_PKGDIR
       <xsl:when test="contains(string(.),'&lt;lfs&gt;')">
         <xsl:value-of select="$hostname"/>
       </xsl:when>
+      <xsl:when test="contains(string(.),'$(nproc || echo 1)')">
+        <xsl:value-of select="$jobs_1"/>
+      </xsl:when>
+      <xsl:when test="contains(string(.),'$(nproc)')">
+        <xsl:value-of select="$jobs_2"/>
+      </xsl:when>
       <xsl:otherwise>
         <xsl:text>**EDITME</xsl:text>
         <xsl:apply-templates/>
diff --git a/common/chroot.xsl b/common/chroot.xsl
index 75371c0..dfd4236 100644
--- a/common/chroot.xsl
+++ b/common/chroot.xsl
@@ -6,6 +6,8 @@
       extension-element-prefixes="exsl"
       version="1.0">
 
+  <xsl:param name="jobs_2" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -41,7 +43,7 @@
       <xsl:apply-templates
            select=".//userinput[contains(string(),'&#xA;chroot') or
                                 starts-with(string(),'chroot')]"/>
-      <xsl:text>exit&#xA;</xsl:text>
+      <xsl:text>&#xA;exit&#xA;</xsl:text>
     </exsl:document>
     </xsl:if>
   </xsl:template>
@@ -55,6 +57,19 @@
   <xsl:template name="extract-chroot">
     <xsl:param name="instructions" select="''"/>
     <xsl:choose>
+      <xsl:when test="contains($instructions, '$(nproc || echo 1)')">
+        <xsl:call-template name="extract-chroot">
+          <xsl:with-param
+            name="instructions"
+            select="substring-before($instructions, '$(nproc || echo 1)')"/>
+        </xsl:call-template>
+        <xsl:value-of select="$jobs_2"/>
+        <xsl:call-template name="extract-chroot">
+          <xsl:with-param
+            name="instructions"
+            select="substring-after($instructions, '$(nproc || echo 1)')"/>
+        </xsl:call-template>
+      </xsl:when>
       <xsl:when test="not(starts-with($instructions,'&#xA;chroot')) and
                       contains($instructions, '&#xA;chroot')">
         <xsl:call-template name="extract-chroot">
@@ -80,8 +95,6 @@
       </xsl:when>
       <xsl:otherwise>
         <xsl:copy-of select="$instructions"/>
-        <xsl:text>
-</xsl:text>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
diff --git a/common/libs/func_book_parser b/common/libs/func_book_parser
index 10115b8..a25bb96 100644
--- a/common/libs/func_book_parser
+++ b/common/libs/func_book_parser
@@ -63,6 +63,13 @@ extract_commands() {         #
   fi
   popd > /dev/null
 
+  JOBS_1=1
+  JOBS_2=1
+  case "$OPTIMIZE" in
+    "1") JOBS_2="$N_PARALLEL";;
+    "2") JOBS_1="$N_PARALLEL"; N_PARALLEL_2="$N_PARALLEL";;
+  esac
+
   # First profile the book, for revision and arch. Note that
   # MULTIBLIB is set to "default" if pure 64 bit book. In this case,
   # profiling on arch is useless, but does not hurt either.
@@ -102,6 +109,8 @@ extract_commands() {         #
            --stringparam local          "$LOCAL"        \
            --stringparam log-level      "$LOG_LEVEL"    \
            --stringparam script-root    "$SCRIPT_ROOT"  \
+           --stringparam jobs_1         "$JOBS_1"       \
+           --stringparam jobs_2         "$JOBS_2"       \
            --output "./${COMMANDS}/"                    \
            $XSL                                         \
            prbook.xml >> $LOGDIR/$LOG 2>&1
@@ -139,9 +148,9 @@ create_chroot_scripts() {    #
   rm -rf chroot-scripts
   echo -n "Creating chroot commands scripts from $BOOK"
   if [ ! -z $ARCH ] ; then echo -n " $ARCH" ; fi
-  echo -n "... "
   xsltproc --nonet --xinclude \
-           -o chroot-scripts/ chroot.xsl \
+           --stringparam jobs_2 "$JOBS_2" \
+           -o chroot-scripts/ chroot.xsl  \
            $BOOK/chapter0?/*chroot*.xml >> $LOGDIR/$LOG 2>&1
   echo "done"
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

-- 
http://lists.linuxfromscratch.org/sympa/info/alfs-discuss
Unsubscribe: See the above information page
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.