Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
greenc-FNAL committed Nov 1, 2018
1 parent a90a22d commit 107df3e
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions lib/spack/spack/build_systems/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
from spack.directives import depends_on, variant
from spack.package import PackageBase, InstallError, run_after

# Regex to extract the primary generator from the CMake generator
# string.
_primary_generator_extractor = re.compile(r'(?:.* - )?(.*)')


def _extract_primary_generator(generator):
"""Use the compiled regex _primary_generator_extractor to extract the
primary generator from the generator string which may contain an
optional secondary generator.
"""
primary_generator = _primary_generator_extractor.match(generator).group(1)
return primary_generator


class CMakePackage(PackageBase):
"""Specialized class for packages built using CMake
Expand Down Expand Up @@ -43,6 +56,17 @@ class CMakePackage(PackageBase):
+-----------------------------------------------+--------------------+
The generator used by CMake can be specified by providing the
generator attribute. Per
https://cmake.org/cmake/help/git-master/manual/cmake-generators.7.html,
the format is: [<secondary-generator> - ]<primary_generator>. The
full list of primary and secondary generators supported by CMake may
be found in the documentation for the version of CMake used;
however, at this time Spack supports only the primary generators
"Unix Makefiles" and "Ninja." Spack's CMake support is agnostic with
respect to primary generators. Spack will generate a runtime error
if the generator string does not follow the prescribed format, or if
the primary generator is not supported.
"""
#: Phases of a CMake package
phases = ['cmake', 'build', 'install']
Expand Down Expand Up @@ -109,14 +133,13 @@ def _std_args(pkg):
generator = 'Unix Makefiles'

# Make sure a valid generator was chosen
valid_generators = ['Unix Makefiles', 'Ninja']
generator_extractor = re.compile(r'(?:.*?-\s+)?(.*)')
primary_generator = generator_extractor.match(generator).group(1)
if primary_generator not in valid_generators:
valid_primary_generators = ['Unix Makefiles', 'Ninja']
primary_generator = _extract_primary_generator(generator)
if primary_generator not in valid_primary_generators:
msg = "Invalid CMake generator: '{0}'\n".format(generator)
msg += "CMakePackage currently supports the following "
msg += "primary generators: '{0}'".\
format("', '".join(valid_generators))
format("', '".join(valid_primary_generators))
raise InstallError(msg)

try:
Expand Down

0 comments on commit 107df3e

Please sign in to comment.