Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spack setup: Fix Bugs + Multi-setup (2) #5043

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions lib/spack/spack/build_systems/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,29 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from __future__ import print_function

import inspect
import os
import platform
import sys
import string
import os

import spack.build_environment
from llnl.util.filesystem import working_dir, join_path
from llnl.util.filesystem import set_executable
from spack.directives import depends_on, variant
from spack.package import PackageBase, run_after


def spack_transitive_include_path():
return ';'.join(
os.path.join(dep, 'include')
for dep in os.environ['SPACK_DEPENDENCIES'].split(os.pathsep)
)


class CMakePackage(PackageBase):
"""Specialized class for packages built using CMake

Expand Down Expand Up @@ -176,3 +188,77 @@ def check(self):

# Check that self.prefix is there after installation
run_after('install')(PackageBase.sanity_check_prefix)

def write_spconfig(self, spconfig_fname):
"""Writes the spconfig.py (CMake setup file) to a file."""
print('BEGIN write_spconfig')
spack.build_environment.setup_package(self)
with open(spconfig_fname, 'w') as fout:
self._write_spconfig(fout)
fout.write('\nproc = subprocess.Popen(cmd, env=env)\n'
'proc.wait()\n')

set_executable(spconfig_fname)
return spconfig_fname

def _write_spconfig(self, fout):
"""Writes the spconfig.py file to a stream."""

# Set-up the environment
_cmd = [str(spack.which('cmake'))] + \
self.std_cmake_args + self.cmake_args()

# No verbose makefile for interactive builds
cmd = [x for x in _cmd if not x.startswith('-DCMAKE_VERBOSE_MAKEFILE')]

env = dict()

paths = os.environ['PATH'].split(':')
paths = [item for item in paths if 'spack/env' not in item]
env['PATH'] = ':'.join(paths)
env['SPACK_TRANSITIVE_INCLUDE_PATH'] = spack_transitive_include_path()
env['CMAKE_PREFIX_PATH'] = os.environ['CMAKE_PREFIX_PATH']

if 'SPACK_CC' in os.environ:
env['CC'] = os.environ['SPACK_CC']
if 'SPACK_CXX' in os.environ:
env['CXX'] = os.environ['SPACK_CXX']
if 'SPACK_FC' in os.environ:
env['FC'] = os.environ['SPACK_FC']

fout.write(
r"""#!%s
#
# %s

import sys
import os
import subprocess

def cmdlist(str):
return list(x.strip().replace("'",'') for x in str.split('\n') if x)
env = dict(os.environ)
""" % (sys.executable, ' '.join(sys.argv)))

env_vars = sorted(list(env.keys()))
for name in env_vars:
val = env[name]
if string.find(name, 'PATH') < 0:
fout.write('env[%s] = %s\n' % (repr(name), repr(val)))
else:
if name == 'SPACK_TRANSITIVE_INCLUDE_PATH':
sep = ';'
else:
sep = ':'

fout.write(
'env[%s] = "%s".join(cmdlist("""\n' % (repr(name), sep))
for part in string.split(val, sep):
fout.write(' %s\n' % part)
fout.write('"""))\n')

fout.write('\ncmd = cmdlist("""\n')
fout.write('%s\n' % cmd[0])
for arg in cmd[1:]:
fout.write(' %s\n' % arg)
fout.write('""") + sys.argv[1:]\n')
20 changes: 11 additions & 9 deletions lib/spack/spack/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ def get_command(name):
return getattr(get_module(python_name), python_name)


def parse_specs(args, **kwargs):
def parse_specs(args, concretize=False, normalize=False, allow_multi=True):
"""Convenience function for parsing arguments from specs. Handles common
exceptions and dies if there are errors.
"""
concretize = kwargs.get('concretize', False)
normalize = kwargs.get('normalize', False)

try:
specs = spack.spec.parse(args)
Expand All @@ -119,15 +117,19 @@ def parse_specs(args, **kwargs):
elif normalize:
spec.normalize()

return specs

except spack.parse.ParseError as e:
tty.error(e.message, e.string, e.pos * " " + "^")
sys.exit(1)
tty.die(e.message, e.string, e.pos * " " + "^")

except spack.spec.SpecError as e:
tty.error(e.message)
sys.exit(1)
tty.die(e.message)

if allow_multi:
return specs

if len(specs) != 1:
tty.die('only one spec can be installed at a time.')
spec = specs.pop()
return spec


def elide_list(line_list, max_num=10):
Expand Down
4 changes: 4 additions & 0 deletions lib/spack/spack/cmd/common/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ def _specs(self, **kwargs):
_arguments['very_long'] = Args(
'-L', '--very-long', action='store_true',
help='show full dependency hashes as well as versions')

_arguments['jobs'] = Args(
'-j', '--jobs', action='store', type=int, dest="jobs",
help="explicitly set number of make jobs, default is #cpus.")
16 changes: 15 additions & 1 deletion lib/spack/spack/cmd/diy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@


def setup_parser(subparser):
arguments.add_common_arguments(subparser, ['jobs'])
subparser.add_argument(
'-d', '--source-path', dest='source_path', default=None,
help="Path to the source directory. Defaults to the current directory")
subparser.add_argument(
'-i', '--ignore-dependencies', action='store_true', dest='ignore_deps',
help="don't try to install dependencies of requested packages")
Expand All @@ -63,6 +67,10 @@ def diy(self, args):
if not args.spec:
tty.die("spack diy requires a package spec argument.")

if args.jobs is not None:
if args.jobs <= 0:
tty.die("The -j option must be a positive integer!")

specs = spack.cmd.parse_specs(args.spec)
if len(specs) > 1:
tty.die("spack diy only takes one spec.")
Expand All @@ -85,13 +93,19 @@ def diy(self, args):
tty.msg("Uninstall or try adding a version suffix for this DIY build.")
sys.exit(1)

source_path = args.source_path
if source_path is None:
source_path = os.getcwd()
source_path = os.path.abspath(source_path)

# Forces the build to run out of the current directory.
package.stage = DIYStage(os.getcwd())
package.stage = DIYStage(source_path)

# TODO: make this an argument, not a global.
spack.do_checksum = False

package.do_install(
make_jobs=args.jobs,
keep_prefix=args.keep_prefix,
install_deps=not args.ignore_deps,
verbose=not args.quiet,
Expand Down
Loading