Skip to content

Commit

Permalink
Merge pull request #744 from vkarak/feat/buildsys-allow-envvar-subst
Browse files Browse the repository at this point in the history
[feat] Enable environment variable substitution in shell code emitted by build systems
  • Loading branch information
vkarak committed Apr 9, 2019
2 parents d36ac09 + 54930e3 commit 715ac72
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
52 changes: 26 additions & 26 deletions reframe/core/buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Make(BuildSystem):
.. code::
make -j [N] [-f MAKEFILE] [-C SRCDIR] CC='X' CXX='X' FC='X' NVCC='X' CPPFLAGS='X' CFLAGS='X' CXXFLAGS='X' FCFLAGS='X' LDFLAGS='X' OPTIONS
make -j [N] [-f MAKEFILE] [-C SRCDIR] CC="X" CXX="X" FC="X" NVCC="X" CPPFLAGS="X" CFLAGS="X" CXXFLAGS="X" FCFLAGS="X" LDFLAGS="X" OPTIONS
The compiler and compiler flags variables will only be passed if they are
not :class:`None`.
Expand Down Expand Up @@ -246,31 +246,31 @@ def emit_build_commands(self, environ):
fflags = self._fflags(environ)
ldflags = self._ldflags(environ)
if cc is not None:
cmd_parts += ["CC='%s'" % cc]
cmd_parts += ['CC="%s"' % cc]

if cxx is not None:
cmd_parts += ["CXX='%s'" % cxx]
cmd_parts += ['CXX="%s"' % cxx]

if ftn is not None:
cmd_parts += ["FC='%s'" % ftn]
cmd_parts += ['FC="%s"' % ftn]

if nvcc is not None:
cmd_parts += ["NVCC='%s'" % nvcc]
cmd_parts += ['NVCC="%s"' % nvcc]

if cppflags is not None:
cmd_parts += ["CPPFLAGS='%s'" % ' '.join(cppflags)]
cmd_parts += ['CPPFLAGS="%s"' % ' '.join(cppflags)]

if cflags is not None:
cmd_parts += ["CFLAGS='%s'" % ' '.join(cflags)]
cmd_parts += ['CFLAGS="%s"' % ' '.join(cflags)]

if cxxflags is not None:
cmd_parts += ["CXXFLAGS='%s'" % ' '.join(cxxflags)]
cmd_parts += ['CXXFLAGS="%s"' % ' '.join(cxxflags)]

if fflags is not None:
cmd_parts += ["FCFLAGS='%s'" % ' '.join(fflags)]
cmd_parts += ['FCFLAGS="%s"' % ' '.join(fflags)]

if ldflags is not None:
cmd_parts += ["LDFLAGS='%s'" % ' '.join(ldflags)]
cmd_parts += ['LDFLAGS="%s"' % ' '.join(ldflags)]

if self.options:
cmd_parts += self.options
Expand Down Expand Up @@ -521,28 +521,28 @@ def emit_build_commands(self, environ):
fflags = self._combine_flags(cppflags, self._fflags(environ))
ldflags = self._ldflags(environ)
if cc is not None:
cmake_cmd += ["-DCMAKE_C_COMPILER='%s'" % cc]
cmake_cmd += ['-DCMAKE_C_COMPILER="%s"' % cc]

if cxx is not None:
cmake_cmd += ["-DCMAKE_CXX_COMPILER='%s'" % cxx]
cmake_cmd += ['-DCMAKE_CXX_COMPILER="%s"' % cxx]

if ftn is not None:
cmake_cmd += ["-DCMAKE_Fortran_COMPILER='%s'" % ftn]
cmake_cmd += ['-DCMAKE_Fortran_COMPILER="%s"' % ftn]

if nvcc is not None:
cmake_cmd += ["-DCMAKE_CUDA_COMPILER='%s'" % nvcc]
cmake_cmd += ['-DCMAKE_CUDA_COMPILER="%s"' % nvcc]

if cflags is not None:
cmake_cmd += ["-DCMAKE_C_FLAGS='%s'" % ' '.join(cflags)]
cmake_cmd += ['-DCMAKE_C_FLAGS="%s"' % ' '.join(cflags)]

if cxxflags is not None:
cmake_cmd += ["-DCMAKE_CXX_FLAGS='%s'" % ' '.join(cxxflags)]
cmake_cmd += ['-DCMAKE_CXX_FLAGS="%s"' % ' '.join(cxxflags)]

if fflags is not None:
cmake_cmd += ["-DCMAKE_Fortran_FLAGS='%s'" % ' '.join(fflags)]
cmake_cmd += ['-DCMAKE_Fortran_FLAGS="%s"' % ' '.join(fflags)]

if ldflags is not None:
cmake_cmd += ["-DCMAKE_EXE_LINKER_FLAGS='%s'" % ' '.join(ldflags)]
cmake_cmd += ['-DCMAKE_EXE_LINKER_FLAGS="%s"' % ' '.join(ldflags)]

if self.config_opts:
cmake_cmd += self.config_opts
Expand Down Expand Up @@ -599,28 +599,28 @@ def emit_build_commands(self, environ):
fflags = self._fflags(environ)
ldflags = self._ldflags(environ)
if cc is not None:
configure_cmd += ["CC='%s'" % cc]
configure_cmd += ['CC="%s"' % cc]

if cxx is not None:
configure_cmd += ["CXX='%s'" % cxx]
configure_cmd += ['CXX="%s"' % cxx]

if ftn is not None:
configure_cmd += ["FC='%s'" % ftn]
configure_cmd += ['FC="%s"' % ftn]

if cppflags is not None:
configure_cmd += ["CPPFLAGS='%s'" % ' '.join(cppflags)]
configure_cmd += ['CPPFLAGS="%s"' % ' '.join(cppflags)]

if cflags is not None:
configure_cmd += ["CFLAGS='%s'" % ' '.join(cflags)]
configure_cmd += ['CFLAGS="%s"' % ' '.join(cflags)]

if cxxflags is not None:
configure_cmd += ["CXXFLAGS='%s'" % ' '.join(cxxflags)]
configure_cmd += ['CXXFLAGS="%s"' % ' '.join(cxxflags)]

if fflags is not None:
configure_cmd += ["FCFLAGS='%s'" % ' '.join(fflags)]
configure_cmd += ['FCFLAGS="%s"' % ' '.join(fflags)]

if ldflags is not None:
configure_cmd += ["LDFLAGS='%s'" % ' '.join(ldflags)]
configure_cmd += ['LDFLAGS="%s"' % ' '.join(ldflags)]

if self.config_opts:
configure_cmd += self.config_opts
Expand Down
86 changes: 43 additions & 43 deletions unittests/test_buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def test_emit_from_env(self):
self.build_system.options = ['FOO=1']
self.build_system.max_concurrency = 32
expected = [
"make -f Makefile_foo -C foodir -j 32 CC='gcc' CXX='g++' "
"FC='gfortran' NVCC='nvcc' CPPFLAGS='-DNDEBUG' "
"CFLAGS='-Wall -std=c99' CXXFLAGS='-Wall -std=c++11' "
"FCFLAGS='-Wall' LDFLAGS='-dynamic' FOO=1"
'make -f Makefile_foo -C foodir -j 32 CC="gcc" CXX="g++" '
'FC="gfortran" NVCC="nvcc" CPPFLAGS="-DNDEBUG" '
'CFLAGS="-Wall -std=c99" CXXFLAGS="-Wall -std=c++11" '
'FCFLAGS="-Wall" LDFLAGS="-dynamic" FOO=1'
]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
Expand All @@ -60,10 +60,10 @@ def test_emit_from_buildsystem(self):
self.build_system.options = ['FOO=1']
self.build_system.max_concurrency = None
expected = [
"make -f Makefile_foo -C foodir -j CC='cc' CXX='CC' FC='ftn' "
"NVCC='clang' CPPFLAGS='-DFOO' CFLAGS='-Wall -std=c99 -O3' "
"CXXFLAGS='-Wall -std=c++11 -O3' FCFLAGS='-Wall -O3' "
"LDFLAGS='-static' FOO=1"
'make -f Makefile_foo -C foodir -j CC="cc" CXX="CC" FC="ftn" '
'NVCC="clang" CPPFLAGS="-DFOO" CFLAGS="-Wall -std=c99 -O3" '
'CXXFLAGS="-Wall -std=c++11 -O3" FCFLAGS="-Wall -O3" '
'LDFLAGS="-static" FOO=1'
]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
Expand All @@ -85,17 +85,17 @@ def test_emit_from_env(self):
self.build_system.make_opts = ['install']
self.build_system.max_concurrency = 32
expected = [
"cd src",
"mkdir -p build/foo",
"cd build/foo",
"cmake -DCMAKE_C_COMPILER='gcc' -DCMAKE_CXX_COMPILER='g++' "
"-DCMAKE_Fortran_COMPILER='gfortran' "
"-DCMAKE_CUDA_COMPILER='nvcc' "
"-DCMAKE_C_FLAGS='-DNDEBUG -Wall -std=c99' "
"-DCMAKE_CXX_FLAGS='-DNDEBUG -Wall -std=c++11' "
"-DCMAKE_Fortran_FLAGS='-DNDEBUG -Wall' "
"-DCMAKE_EXE_LINKER_FLAGS='-dynamic' -DFOO=1 ../..",
"make -j 32 install"
'cd src',
'mkdir -p build/foo',
'cd build/foo',
'cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" '
'-DCMAKE_Fortran_COMPILER="gfortran" '
'-DCMAKE_CUDA_COMPILER="nvcc" '
'-DCMAKE_C_FLAGS="-DNDEBUG -Wall -std=c99" '
'-DCMAKE_CXX_FLAGS="-DNDEBUG -Wall -std=c++11" '
'-DCMAKE_Fortran_FLAGS="-DNDEBUG -Wall" '
'-DCMAKE_EXE_LINKER_FLAGS="-dynamic" -DFOO=1 ../..',
'make -j 32 install'

]
self.assertEqual(expected,
Expand All @@ -107,15 +107,15 @@ def test_emit_from_buildsystem(self):
self.build_system.config_opts = ['-DFOO=1']
self.build_system.max_concurrency = None
expected = [
"mkdir -p build/foo",
"cd build/foo",
"cmake -DCMAKE_C_COMPILER='cc' -DCMAKE_CXX_COMPILER='CC' "
"-DCMAKE_Fortran_COMPILER='ftn' -DCMAKE_CUDA_COMPILER='clang' "
"-DCMAKE_C_FLAGS='-DFOO -Wall -std=c99 -O3' "
"-DCMAKE_CXX_FLAGS='-DFOO -Wall -std=c++11 -O3' "
"-DCMAKE_Fortran_FLAGS='-DFOO -Wall -O3' "
"-DCMAKE_EXE_LINKER_FLAGS='-static' -DFOO=1 ../..",
"make -j"
'mkdir -p build/foo',
'cd build/foo',
'cmake -DCMAKE_C_COMPILER="cc" -DCMAKE_CXX_COMPILER="CC" '
'-DCMAKE_Fortran_COMPILER="ftn" -DCMAKE_CUDA_COMPILER="clang" '
'-DCMAKE_C_FLAGS="-DFOO -Wall -std=c99 -O3" '
'-DCMAKE_CXX_FLAGS="-DFOO -Wall -std=c++11 -O3" '
'-DCMAKE_Fortran_FLAGS="-DFOO -Wall -O3" '
'-DCMAKE_EXE_LINKER_FLAGS="-static" -DFOO=1 ../..',
'make -j'

]
print(self.build_system.emit_build_commands(self.environ))
Expand All @@ -139,14 +139,14 @@ def test_emit_from_env(self):
self.build_system.make_opts = ['check']
self.build_system.max_concurrency = 32
expected = [
"cd src",
"mkdir -p build/foo",
"cd build/foo",
"../../configure CC='gcc' CXX='g++' FC='gfortran' "
"CPPFLAGS='-DNDEBUG' CFLAGS='-Wall -std=c99' "
"CXXFLAGS='-Wall -std=c++11' FCFLAGS='-Wall' "
"LDFLAGS='-dynamic' FOO=1",
"make -j 32 check"
'cd src',
'mkdir -p build/foo',
'cd build/foo',
'../../configure CC="gcc" CXX="g++" FC="gfortran" '
'CPPFLAGS="-DNDEBUG" CFLAGS="-Wall -std=c99" '
'CXXFLAGS="-Wall -std=c++11" FCFLAGS="-Wall" '
'LDFLAGS="-dynamic" FOO=1',
'make -j 32 check'

]
self.assertEqual(expected,
Expand All @@ -158,13 +158,13 @@ def test_emit_from_buildsystem(self):
self.build_system.config_opts = ['FOO=1']
self.build_system.max_concurrency = None
expected = [
"mkdir -p build/foo",
"cd build/foo",
"../../configure CC='cc' CXX='CC' FC='ftn' "
"CPPFLAGS='-DFOO' CFLAGS='-Wall -std=c99 -O3' "
"CXXFLAGS='-Wall -std=c++11 -O3' FCFLAGS='-Wall -O3' "
"LDFLAGS='-static' FOO=1",
"make -j"
'mkdir -p build/foo',
'cd build/foo',
'../../configure CC="cc" CXX="CC" FC="ftn" '
'CPPFLAGS="-DFOO" CFLAGS="-Wall -std=c99 -O3" '
'CXXFLAGS="-Wall -std=c++11 -O3" FCFLAGS="-Wall -O3" '
'LDFLAGS="-static" FOO=1',
'make -j'

]
print(self.build_system.emit_build_commands(self.environ))
Expand Down

0 comments on commit 715ac72

Please sign in to comment.