summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-06-20 23:53:48 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2016-06-20 23:53:48 -0700
commitf18e1a93716135c07c94b40b2cf7f550bd2217e5 (patch)
tree8fd50269beb630fe4830faa2677643f61b0f7a49 /lib
parent3f90fee614cf44f31344de3443f2a2e63c6d9fb4 (diff)
parentaa86488fd9809ced16704e4bd4d607c89d6dda75 (diff)
downloadspack-f18e1a93716135c07c94b40b2cf7f550bd2217e5.tar.gz
spack-f18e1a93716135c07c94b40b2cf7f550bd2217e5.tar.bz2
spack-f18e1a93716135c07c94b40b2cf7f550bd2217e5.tar.xz
spack-f18e1a93716135c07c94b40b2cf7f550bd2217e5.zip
Merge branch 'features/cantera' of https://github.com/adamjstewart/spack into adamjstewart-features/cantera
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/build_environment.py28
-rw-r--r--lib/spack/spack/cmd/create.py187
2 files changed, 153 insertions, 62 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 3fcfb151b8..83468be8e6 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -63,7 +63,7 @@ from llnl.util.filesystem import *
import spack
from spack.environment import EnvironmentModifications, validate
from spack.util.environment import *
-from spack.util.executable import Executable, which
+from spack.util.executable import Executable
#
# This can be set by the user to globally disable parallel builds.
@@ -130,8 +130,13 @@ def load_module(mod):
text = modulecmd('show', mod, output=str, error=str).split()
for i, word in enumerate(text):
if word == 'conflict':
+<<<<<<< HEAD
exec(compile(modulecmd('unload', text[
i + 1], output=str, error=str), '<string>', 'exec'))
+=======
+ exec(compile(modulecmd('unload', text[i + 1], output=str,
+ error=str), '<string>', 'exec'))
+>>>>>>> aa86488fd9809ced16704e4bd4d607c89d6dda75
# Load the module now that there are no conflicts
load = modulecmd('load', mod, output=str, error=str)
exec(compile(load, '<string>', 'exec'))
@@ -239,8 +244,13 @@ def set_build_environment_variables(pkg, env):
# handled by putting one in the <build_env_path>/case-insensitive
# directory. Add that to the path too.
env_paths = []
+<<<<<<< HEAD
compiler_specific = join_path(spack.build_env_path, pkg.compiler.name)
for item in [spack.build_env_path, compiler_specific]:
+=======
+ for item in [spack.build_env_path, join_path(spack.build_env_path,
+ pkg.compiler.name)]:
+>>>>>>> aa86488fd9809ced16704e4bd4d607c89d6dda75
env_paths.append(item)
ci = join_path(item, 'case-insensitive')
if os.path.isdir(ci):
@@ -270,8 +280,13 @@ def set_build_environment_variables(pkg, env):
env.unset('DYLD_LIBRARY_PATH')
# Add bin directories from dependencies to the PATH for the build.
+<<<<<<< HEAD
bin_dirs = reversed(
filter(os.path.isdir, ['%s/bin' % prefix for prefix in dep_prefixes]))
+=======
+ bin_dirs = reversed(filter(os.path.isdir,
+ ['%s/bin' % prefix for prefix in dep_prefixes]))
+>>>>>>> aa86488fd9809ced16704e4bd4d607c89d6dda75
for item in bin_dirs:
env.prepend_path('PATH', item)
@@ -286,7 +301,10 @@ def set_build_environment_variables(pkg, env):
for directory in ('lib', 'lib64', 'share'):
pcdir = join_path(pre, directory, 'pkgconfig')
if os.path.isdir(pcdir):
+<<<<<<< HEAD
# pkg_config_dirs.append(pcdir)
+=======
+>>>>>>> aa86488fd9809ced16704e4bd4d607c89d6dda75
env.prepend_path('PKG_CONFIG_PATH', pcdir)
if pkg.spec.architecture.target.module_name:
@@ -299,7 +317,7 @@ def set_module_variables_for_package(pkg, module):
"""Populate the module scope of install() with some useful functions.
This makes things easier for package writers.
"""
- # number of jobs spack will to build with.
+ # number of jobs spack will build with.
jobs = multiprocessing.cpu_count()
if not pkg.parallel:
jobs = 1
@@ -312,6 +330,7 @@ def set_module_variables_for_package(pkg, module):
# TODO: make these build deps that can be installed if not found.
m.make = MakeExecutable('make', jobs)
m.gmake = MakeExecutable('gmake', jobs)
+ m.scons = MakeExecutable('scons', jobs)
# easy shortcut to os.environ
m.env = os.environ
@@ -325,6 +344,7 @@ def set_module_variables_for_package(pkg, module):
# TODO: Currently, everything is a link dependency, but tools like
# TODO: this shouldn't be.
m.cmake = Executable('cmake')
+ m.ctest = Executable('ctest')
# standard CMake arguments
m.std_cmake_args = ['-DCMAKE_INSTALL_PREFIX=%s' % pkg.prefix,
@@ -382,9 +402,13 @@ def get_rpaths(pkg):
def parent_class_modules(cls):
+<<<<<<< HEAD
"""
Get list of super class modules that are all descend from spack.Package
"""
+=======
+ """Get list of super class modules that all descend from spack.Package"""
+>>>>>>> aa86488fd9809ced16704e4bd4d607c89d6dda75
if not issubclass(cls, spack.Package) or issubclass(spack.Package, cls):
return []
result = []
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py
index 41bfa741f6..8cbb367f86 100644
--- a/lib/spack/spack/cmd/create.py
+++ b/lib/spack/spack/cmd/create.py
@@ -1,4 +1,3 @@
-_copyright = """\
##############################################################################
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
@@ -23,10 +22,8 @@ _copyright = """\
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
-"""
import string
import os
-import hashlib
import re
from ordereddict_backport import OrderedDict
@@ -41,16 +38,37 @@ import spack.util.web
from spack.spec import Spec
from spack.util.naming import *
from spack.repository import Repo, RepoError
-import spack.util.crypto as crypto
from spack.util.executable import which
-from spack.stage import Stage
description = "Create a new package file from an archive URL"
-package_template = string.Template(
- _copyright + """
+package_template = string.Template("""\
+##############################################################################
+# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/llnl/spack
+# Please also see the LICENSE file for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
#
# This is a template package file for Spack. We've put "FIXME"
# next to all the things you'll want to change. Once you've handled
@@ -68,24 +86,21 @@ package_template = string.Template(
#
from spack import *
+
class ${class_name}(Package):
- ""\"FIXME: put a proper description of your package here.""\"
- # FIXME: add a proper url for your package's homepage here.
+ ""\"FIXME: Put a proper description of your package here.""\"
+
+ # FIXME: Add a proper url for your package's homepage here.
homepage = "http://www.example.com"
url = "${url}"
${versions}
-
+${extends}
# FIXME: Add dependencies if this package requires them.
# depends_on("foo")
def install(self, spec, prefix):
- # FIXME: Modify the configure line to suit your build system here.
- ${configure}
-
- # FIXME: Add logic to build and install here
- make()
- make("install")
+${install}
""")
@@ -120,41 +135,95 @@ def setup_parser(subparser):
class ConfigureGuesser(object):
def __call__(self, stage):
- """Try to guess the type of build system used by the project, and return
- an appropriate configure line.
- """
- autotools = "configure('--prefix=%s' % prefix)"
- cmake = "cmake('.', *std_cmake_args)"
- python = "python('setup.py', 'install', '--prefix=%s' % prefix)"
- r = "R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)"
-
- config_lines = ((r'/configure$', 'autotools', autotools),
- (r'/CMakeLists.txt$', 'cmake', cmake),
- (r'/setup.py$', 'python', python),
- (r'/NAMESPACE$', 'r', r))
-
- # Peek inside the tarball.
- tar = which('tar')
- output = tar(
- "--exclude=*/*/*", "-tf", stage.archive_file, output=str)
- lines = output.split("\n")
-
- # Set the configure line to the one that matched.
- for pattern, bs, cl in config_lines:
+ """Try to guess the type of build system used by the project.
+ Set the appropriate default installation instructions and any
+ necessary extensions for Python and R."""
+
+ # Default installation instructions
+ installDict = {
+ 'autotools': """\
+ # FIXME: Modify the configure line to suit your build system here.
+ configure('--prefix={0}'.format(prefix))
+
+ # FIXME: Add logic to build and install here.
+ make()
+ make('install')""",
+
+ 'cmake': """\
+ with working_dir('spack-build', create=True):
+ # FIXME: Modify the cmake line to suit your build system here.
+ cmake('..', *std_cmake_args)
+
+ # FIXME: Add logic to build and install here.
+ make()
+ make('install')""",
+
+ 'scons': """\
+ # FIXME: Add logic to build and install here.
+ scons('prefix={0}'.format(prefix))
+ scons('install')""",
+
+ 'python': """\
+ # FIXME: Add logic to build and install here.
+ python('setup.py', 'install', '--prefix={0}'.format(prefix))""",
+
+ 'R': """\
+ # FIXME: Add logic to build and install here.
+ R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir),
+ self.stage.source_path)""",
+
+ 'unknown': """\
+ # FIXME: Unknown build system
+ make()
+ make('install')"""
+ }
+
+ # A list of clues that give us an idea of the build system a package
+ # uses. If the regular expression matches a file contained in the
+ # archive, the corresponding build system is assumed.
+ clues = [
+ (r'/configure$', 'autotools'),
+ (r'/CMakeLists.txt$', 'cmake'),
+ (r'/SConstruct$', 'scons'),
+ (r'/setup.py$', 'python'),
+ (r'/NAMESPACE$', 'R')
+ ]
+
+ # Peek inside the compressed file.
+ if stage.archive_file.endswith('.zip'):
+ try:
+ unzip = which('unzip')
+ output = unzip('-l', stage.archive_file, output=str)
+ except:
+ output = ''
+ else:
+ try:
+ tar = which('tar')
+ output = tar('--exclude=*/*/*', '-tf',
+ stage.archive_file, output=str)
+ except:
+ output = ''
+ lines = output.split('\n')
+
+ # Determine the build system based on the files contained
+ # in the archive.
+ build_system = 'unknown'
+ for pattern, bs in clues:
if any(re.search(pattern, l) for l in lines):
- config_line = cl
build_system = bs
- break
- else:
- # None matched -- just put both, with cmake commented out
- config_line = "# FIXME: Spack couldn't guess one, so here are some options:\n"
- config_line += " # " + autotools + "\n"
- config_line += " # " + cmake
- build_system = 'unknown'
- self.configure = config_line
self.build_system = build_system
+ # Set the appropriate default installation instructions
+ self.install = installDict[build_system]
+
+ # Set any necessary extensions for Python and R
+ extensions = ''
+ if build_system in ['python', 'R']:
+ extensions = "\n extends('{0}')\n".format(build_system)
+
+ self.extends = extensions
+
def guess_name_and_version(url, args):
# Try to deduce name and version of the new package from the URL
@@ -168,7 +237,7 @@ def guess_name_and_version(url, args):
else:
try:
name = spack.url.parse_name(url, version)
- except spack.url.UndetectableNameError, e:
+ except spack.url.UndetectableNameError:
# Use a user-supplied name if one is present
tty.die("Couldn't guess a name for this package. Try running:", "",
"spack create --name <name> <url>")
@@ -182,7 +251,8 @@ def guess_name_and_version(url, args):
def find_repository(spec, args):
# figure out namespace for spec
if spec.namespace and args.namespace and spec.namespace != args.namespace:
- tty.die("Namespaces '%s' and '%s' do not match." % (spec.namespace, args.namespace))
+ tty.die("Namespaces '%s' and '%s' do not match." % (spec.namespace,
+ args.namespace))
if not spec.namespace and args.namespace:
spec.namespace = args.namespace
@@ -193,8 +263,8 @@ def find_repository(spec, args):
try:
repo = Repo(repo_path)
if spec.namespace and spec.namespace != repo.namespace:
- tty.die("Can't create package with namespace %s in repo with namespace %s"
- % (spec.namespace, repo.namespace))
+ tty.die("Can't create package with namespace %s in repo with "
+ "namespace %s" % (spec.namespace, repo.namespace))
except RepoError as e:
tty.die(str(e))
else:
@@ -214,11 +284,7 @@ def find_repository(spec, args):
def fetch_tarballs(url, name, version):
"""Try to find versions of the supplied archive by scraping the web.
-
- Prompts the user to select how many to download if many are found.
-
-
- """
+ Prompts the user to select how many to download if many are found."""
versions = spack.util.web.find_versions_of_archive(url)
rkeys = sorted(versions.keys(), reverse=True)
versions = OrderedDict(zip(rkeys, (versions[v] for v in rkeys)))
@@ -226,11 +292,11 @@ def fetch_tarballs(url, name, version):
archives_to_fetch = 1
if not versions:
# If the fetch failed for some reason, revert to what the user provided
- versions = { version : url }
+ versions = {version: url}
elif len(versions) > 1:
tty.msg("Found %s versions of %s:" % (len(versions), name),
*spack.cmd.elide_list(
- ["%-10s%s" % (v,u) for v, u in versions.iteritems()]))
+ ["%-10s%s" % (v, u) for v, u in versions.iteritems()]))
print
archives_to_fetch = tty.get_number(
"Include how many checksums in the package file?",
@@ -277,7 +343,7 @@ def create(parser, args):
name = 'py-%s' % name
# Prepend 'r-' to R package names, by convention.
- if guesser.build_system == 'r':
+ if guesser.build_system == 'R':
name = 'r-%s' % name
# Create a directory for the new package.
@@ -292,10 +358,11 @@ def create(parser, args):
pkg_file.write(
package_template.substitute(
name=name,
- configure=guesser.configure,
class_name=mod_to_class(name),
url=url,
- versions=make_version_calls(ver_hash_tuples)))
+ versions=make_version_calls(ver_hash_tuples),
+ extends=guesser.extends,
+ install=guesser.install))
# If everything checks out, go ahead and edit.
spack.editor(pkg_path)