Repository: NVIDIA/hpc-container-maker

Issue:
Building block Boost: add possibility to pass args to ./b2
I want to build my boost with C++ 14, so I need to pass the flag `cxxflags="-std=c++14"` to the `./b2` build process: `./b2 cxxflags="-std=c++14" -j$(nproc) -q install`. There is currently no way to pass arguments to `./b2`: https://github.com/NVIDIA/hpc-container-maker/blob/5d7c29c4a16c59dbce7a21a51fed5d5e18e73763/hpccm/building_blocks/boost.py#L185

Discussion:
samcmill: @SimeonEhrig does this address the issues to your satisifcation?
SimeonEhrig: @samcmill I tested the code successful and it does what I expected. Thanks for the fix.

Patch:
diff --git a/docs/building_blocks.md b/docs/building_blocks.md
index 8178a5a..c13ed81 100644
--- a/docs/building_blocks.md
+++ b/docs/building_blocks.md
@@ -209,6 +209,9 @@ The `boost` building block downloads and installs the
 __Parameters__
 
 
+- __b2_opts__: List of options to pass to `b2`.  The default is an empty
+list.
+
 - __bootstrap_opts__: List of options to pass to `bootstrap.sh`.  The
 default is an empty list.
 
@@ -233,7 +236,8 @@ is `/usr/local/boost`.
 - __python__: Boolean flag to specify whether Boost should be built with
 Python support.  If enabled, the Python C headers need to be
 installed (typically this can be done by adding `python-dev` or
-`python-devel` to the list of OS packages).  The default is False.
+`python-devel` to the list of OS packages).  This flag is ignored
+if `bootstrap_opts` is set.  The default is False.
 
 - __sourceforge__: Boolean flag to specify whether Boost should be
 downloaded from SourceForge rather than the current Boost
diff --git a/hpccm/building_blocks/boost.py b/hpccm/building_blocks/boost.py
index c1fc959..8bd1df2 100644
--- a/hpccm/building_blocks/boost.py
+++ b/hpccm/building_blocks/boost.py
@@ -46,6 +46,9 @@ class boost(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig,
 
     # Parameters
 
+    b2_opts: List of options to pass to `b2`.  The default is an empty
+    list.
+
     bootstrap_opts: List of options to pass to `bootstrap.sh`.  The
     default is an empty list.
 
@@ -70,7 +73,8 @@ class boost(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig,
     python: Boolean flag to specify whether Boost should be built with
     Python support.  If enabled, the Python C headers need to be
     installed (typically this can be done by adding `python-dev` or
-    `python-devel` to the list of OS packages).  The default is False.
+    `python-devel` to the list of OS packages).  This flag is ignored
+    if `bootstrap_opts` is set.  The default is False.
 
     sourceforge: Boolean flag to specify whether Boost should be
     downloaded from SourceForge rather than the current Boost
@@ -97,6 +101,7 @@ class boost(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig,
 
         super(boost, self).__init__(**kwargs)
 
+        self.__b2_opts = kwargs.get('b2_opts', [])
         self.__baseurl = kwargs.get('baseurl',
                                     'https://dl.bintray.com/boostorg/release/__version__/source')
         self.__bootstrap_opts = kwargs.get('bootstrap_opts', [])
@@ -166,7 +171,7 @@ class boost(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig,
         # standard Python install.  It requires the development
         # package, python-dev or python-devel.  So skip Python unless
         # it's specifically enabled.
-        if not self.__python:
+        if not self.__bootstrap_opts and not self.__python:
             self.__bootstrap_opts.append('--without-libraries=python')
 
         # Download source from web
@@ -182,7 +187,9 @@ class boost(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig,
                 ' '.join(self.__bootstrap_opts)))
 
         # Build and install
-        self.__commands.append('./b2 -j{} -q install'.format(self.__parallel))
+        self.__b2_opts.append('-j{}'.format(self.__parallel))
+        self.__b2_opts.append('-q install')
+        self.__commands.append('./b2 {0}'.format(' '.join(self.__b2_opts)))
 
         # Set library path
         libpath = posixpath.join(self.__prefix, 'lib')


Test patch:
diff --git a/test/test_boost.py b/test/test_boost.py
index f417497..fa40659 100644
--- a/test/test_boost.py
+++ b/test/test_boost.py
@@ -141,6 +141,49 @@ RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://
     echo "/usr/local/boost/lib" >> /etc/ld.so.conf.d/hpccm.conf && ldconfig && \
     rm -rf /var/tmp/boost_1_68_0.tar.bz2 /var/tmp/boost_1_68_0''')
 
+    @ubuntu
+    @docker
+    def test_bootstrap_opts(self):
+        b = boost(bootstrap_opts=['--with-libraries=atomic,chrono'],
+                  version='1.72.0')
+        self.assertEqual(str(b),
+r'''# Boost version 1.72.0
+RUN apt-get update -y && \
+    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+        bzip2 \
+        libbz2-dev \
+        tar \
+        wget \
+        zlib1g-dev && \
+    rm -rf /var/lib/apt/lists/*
+RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.bz2 && \
+    mkdir -p /var/tmp && tar -x -f /var/tmp/boost_1_72_0.tar.bz2 -C /var/tmp -j && \
+    cd /var/tmp/boost_1_72_0 && ./bootstrap.sh --prefix=/usr/local/boost --with-libraries=atomic,chrono && \
+    ./b2 -j$(nproc) -q install && \
+    rm -rf /var/tmp/boost_1_72_0.tar.bz2 /var/tmp/boost_1_72_0
+ENV LD_LIBRARY_PATH=/usr/local/boost/lib:$LD_LIBRARY_PATH''')
+
+    @ubuntu
+    @docker
+    def test_b2_opts(self):
+        b = boost(b2_opts=['cxxflags="-std=c++14"'], version='1.72.0')
+        self.assertEqual(str(b),
+r'''# Boost version 1.72.0
+RUN apt-get update -y && \
+    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+        bzip2 \
+        libbz2-dev \
+        tar \
+        wget \
+        zlib1g-dev && \
+    rm -rf /var/lib/apt/lists/*
+RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.bz2 && \
+    mkdir -p /var/tmp && tar -x -f /var/tmp/boost_1_72_0.tar.bz2 -C /var/tmp -j && \
+    cd /var/tmp/boost_1_72_0 && ./bootstrap.sh --prefix=/usr/local/boost --without-libraries=python && \
+    ./b2 cxxflags="-std=c++14" -j$(nproc) -q install && \
+    rm -rf /var/tmp/boost_1_72_0.tar.bz2 /var/tmp/boost_1_72_0
+ENV LD_LIBRARY_PATH=/usr/local/boost/lib:$LD_LIBRARY_PATH''')
+
     @ubuntu
     @docker
     def test_runtime(self):