From 1fe626ec7cd8b8a2bceb9e73dd9597d9f99813cf Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 26 Nov 2015 17:53:33 +0100 Subject: resource directive : sketch of implementation + clang / llvm use case --- var/spack/packages/clang/package.py | 7 +++++++ var/spack/packages/llvm/package.py | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'var') diff --git a/var/spack/packages/clang/package.py b/var/spack/packages/clang/package.py index 4f977bf9a4..d0869362f5 100644 --- a/var/spack/packages/clang/package.py +++ b/var/spack/packages/clang/package.py @@ -39,6 +39,13 @@ class Clang(Package): version('3.6.2', 'ff862793682f714bb7862325b9c06e20', url='http://llvm.org/releases/3.6.2/cfe-3.6.2.src.tar.xz') version('3.5.1', '93f9532f8f7e6f1d8e5c1116907051cb', url='http://llvm.org/releases/3.5.1/cfe-3.5.1.src.tar.xz') + ########## + # @3.7.0 + resource(name='clang-tools-extra', + url='http://llvm.org/releases/3.7.0/clang-tools-extra-3.7.0.src.tar.xz', + md5='d5a87dacb65d981a427a536f6964642e', destination='tools', when='@3.7.0') + ########## + def install(self, spec, prefix): env['CXXFLAGS'] = self.compiler.cxx11_flag diff --git a/var/spack/packages/llvm/package.py b/var/spack/packages/llvm/package.py index a6759c3033..b68aa82aff 100644 --- a/var/spack/packages/llvm/package.py +++ b/var/spack/packages/llvm/package.py @@ -41,13 +41,24 @@ class Llvm(Package): depends_on('python@2.7:') + ########## + # @3.7.0 + # TODO : Add support for libc++ <- libc++ABI <- libunwind with variant? + resource(name='compiler-rt', + url='http://llvm.org/releases/3.7.0/compiler-rt-3.7.0.src.tar.xz', md5='383c10affd513026f08936b5525523f5', + destination='projects', when='@3.7.0') + resource(name='openmp', + url='http://llvm.org/releases/3.7.0/openmp-3.7.0.src.tar.xz', md5='f482c86fdead50ba246a1a2b0bbf206f', + destination='projects', when='@3.7.0') + ########## + def install(self, spec, prefix): env['CXXFLAGS'] = self.compiler.cxx11_flag with working_dir('spack-build', create=True): cmake('..', - '-DLLVM_REQUIRES_RTTI=1', - '-DPYTHON_EXECUTABLE=%s/bin/python' % spec['python'].prefix, + '-DLLVM_REQUIRES_RTTI:BOOL=ON', + '-DPYTHON_EXECUTABLE:PATH=%s/bin/python' % spec['python'].prefix, *std_cmake_args) make() make("install") -- cgit v1.2.3-60-g2f50 From a173ab1e3185e322406d0b7379ea77872fbe34c2 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 1 Dec 2015 12:16:08 +0100 Subject: clang : default OpenMP is libomp --- var/spack/packages/clang/package.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'var') diff --git a/var/spack/packages/clang/package.py b/var/spack/packages/clang/package.py index d0869362f5..eac1863b97 100644 --- a/var/spack/packages/clang/package.py +++ b/var/spack/packages/clang/package.py @@ -50,9 +50,15 @@ class Clang(Package): env['CXXFLAGS'] = self.compiler.cxx11_flag with working_dir('spack-build', create=True): + + options = [] + if '@3.7.0:' in spec: + options.append('-DCLANG_DEFAULT_OPENMP_RUNTIME:STRING=libomp') + options.extend(std_cmake_args) + cmake('..', - '-DCLANG_PATH_TO_LLVM_BUILD=%s' % spec['llvm'].prefix, - '-DLLVM_MAIN_SRC_DIR=%s' % spec['llvm'].prefix, - *std_cmake_args) + '-DCLANG_PATH_TO_LLVM_BUILD:PATH=%s' % spec['llvm'].prefix, + '-DLLVM_MAIN_SRC_DIR:PATH=%s' % spec['llvm'].prefix, + *options) make() make("install") -- cgit v1.2.3-60-g2f50 From 39a3cfd4d9fc8d0981ba118de9a1e049fba4b144 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 2 Dec 2015 12:24:37 +0100 Subject: reource directive accepts 'basename' keyword llvm : libc++ variant --- lib/spack/spack/directives.py | 5 ++++- lib/spack/spack/package.py | 3 ++- lib/spack/spack/resource.py | 4 +++- var/spack/packages/llvm/package.py | 9 ++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) (limited to 'var') diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 48a7df7462..07ef32294b 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -276,10 +276,12 @@ def resource(pkg, **kwargs): * 'when' : represents the condition upon which the resource is needed (optional) * 'destination' : path where to extract / checkout the resource (optional). This path must be a relative path, and it must fall inside the stage area of the main package. + * 'basename' : basename of the resource source folder within destination (optional). """ when = kwargs.get('when', pkg.name) destination = kwargs.get('destination', "") + basename = kwargs.get('basename', None) # Check if the path is relative if os.path.isabs(destination): message = "The destination keyword of a resource directive can't be an absolute path.\n" @@ -296,7 +298,8 @@ def resource(pkg, **kwargs): resources = pkg.resources.setdefault(when_spec, []) fetcher = from_kwargs(**kwargs) name = kwargs.get('name') - resources.append(Resource(name, fetcher, destination)) + resources.append(Resource(name, fetcher, destination, basename)) + class DirectiveError(spack.error.SpackError): """This is raised when something is wrong with a package directive.""" diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index c10283a6ee..3f48231c75 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -681,7 +681,8 @@ class Package(object): for resource in resources: stage = resource.fetcher.stage _expand_archive(stage, resource.name) - link_path = join_path(self.stage.source_path, resource.destination, os.path.basename(stage.source_path)) + basename = os.path.basename(stage.source_path) if resource.basename is None else resource.basename + link_path = join_path(self.stage.source_path, resource.destination, basename) if not os.path.exists(link_path): # Create a symlink os.symlink(stage.source_path, link_path) diff --git a/lib/spack/spack/resource.py b/lib/spack/spack/resource.py index 00ee2d49e4..b20612686d 100644 --- a/lib/spack/spack/resource.py +++ b/lib/spack/spack/resource.py @@ -27,11 +27,13 @@ Describes an optional resource needed for a build. Typically a bunch of sources package to enable optional features. """ + class Resource(object): """ Represents an optional resource. Aggregates a name, a fetcher and a destination. """ - def __init__(self, name, fetcher, destination): + def __init__(self, name, fetcher, destination, basename): self.name = name self.fetcher = fetcher self.destination = destination + self.basename = basename diff --git a/var/spack/packages/llvm/package.py b/var/spack/packages/llvm/package.py index b68aa82aff..872a6c082b 100644 --- a/var/spack/packages/llvm/package.py +++ b/var/spack/packages/llvm/package.py @@ -41,15 +41,22 @@ class Llvm(Package): depends_on('python@2.7:') + variant('libcxx', default=False, description="Builds the LLVM Standard C++ library targeting C++11") + ########## # @3.7.0 - # TODO : Add support for libc++ <- libc++ABI <- libunwind with variant? resource(name='compiler-rt', url='http://llvm.org/releases/3.7.0/compiler-rt-3.7.0.src.tar.xz', md5='383c10affd513026f08936b5525523f5', destination='projects', when='@3.7.0') resource(name='openmp', url='http://llvm.org/releases/3.7.0/openmp-3.7.0.src.tar.xz', md5='f482c86fdead50ba246a1a2b0bbf206f', destination='projects', when='@3.7.0') + resource(name='libcxx', + url='http://llvm.org/releases/3.7.0/libcxx-3.7.0.src.tar.xz', md5='46aa5175cbe1ad42d6e9c995968e56dd', + destination='projects', basename='libcxx', when='+libcxx@3.7.0') + resource(name='libcxxabi', + url='http://llvm.org/releases/3.7.0/libcxxabi-3.7.0.src.tar.xz', md5='5aa769e2fca79fa5335cfae8f6258772', + destination='projects', basename='libcxxabi', when='+libcxx@3.7.0') ########## def install(self, spec, prefix): -- cgit v1.2.3-60-g2f50 From 20e67bc5e6c4a4ac759bb068ff78c13bfc17fb0f Mon Sep 17 00:00:00 2001 From: alalazo Date: Wed, 9 Dec 2015 13:06:39 +0100 Subject: clang : solve the issue with missing default include paths for OpenMP and libc++ resource : support for finer grained linking of resources --- lib/spack/spack/directives.py | 17 +++++++++-------- lib/spack/spack/package.py | 16 +++++++++++----- lib/spack/spack/resource.py | 6 +++--- var/spack/packages/clang/package.py | 31 +++++++++++++++++++++++++++++++ var/spack/packages/llvm/package.py | 4 ++-- 5 files changed, 56 insertions(+), 18 deletions(-) (limited to 'var') diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 07ef32294b..22b262b57c 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -269,19 +269,20 @@ def variant(pkg, name, default=False, description=""): def resource(pkg, **kwargs): """ Define an external resource to be fetched and staged when building the package. Based on the keywords present in the - dictionary the appropriate FetchStrategy will be used for the resource. + dictionary the appropriate FetchStrategy will be used for the resource. Resources are fetched and staged in their + own folder inside spack stage area, and then linked into the stage area of the package that needs them. List of recognized keywords: - * 'when' : represents the condition upon which the resource is needed (optional) - * 'destination' : path where to extract / checkout the resource (optional). This path must be a relative path, - and it must fall inside the stage area of the main package. - * 'basename' : basename of the resource source folder within destination (optional). - + * 'when' : (optional) represents the condition upon which the resource is needed + * 'destination' : (optional) path where to link the resource. This path must be relative to the main package stage + area. + * 'placement' : (optional) gives the possibility to fine tune how the resource is linked into the main package stage + area. """ when = kwargs.get('when', pkg.name) destination = kwargs.get('destination', "") - basename = kwargs.get('basename', None) + placement = kwargs.get('placement', None) # Check if the path is relative if os.path.isabs(destination): message = "The destination keyword of a resource directive can't be an absolute path.\n" @@ -298,7 +299,7 @@ def resource(pkg, **kwargs): resources = pkg.resources.setdefault(when_spec, []) fetcher = from_kwargs(**kwargs) name = kwargs.get('name') - resources.append(Resource(name, fetcher, destination, basename)) + resources.append(Resource(name, fetcher, destination, placement)) class DirectiveError(spack.error.SpackError): diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index dcb514af00..b386f8f6a8 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -683,11 +683,17 @@ class Package(object): for resource in resources: stage = resource.fetcher.stage _expand_archive(stage, resource.name) - basename = os.path.basename(stage.source_path) if resource.basename is None else resource.basename - link_path = join_path(self.stage.source_path, resource.destination, basename) - if not os.path.exists(link_path): - # Create a symlink - os.symlink(stage.source_path, link_path) + # Turn placement into a dict with relative paths + placement = os.path.basename(stage.source_path) if resource.placement is None else resource.placement + if not isinstance(placement, dict): + placement = {'': placement} + # Make the paths in the dictionary absolute and link + for key, value in placement.iteritems(): + link_path = join_path(self.stage.source_path, resource.destination, value) + source_path = join_path(stage.source_path, key) + if not os.path.exists(link_path): + # Create a symlink + os.symlink(source_path, link_path) ########## self.stage.chdir_to_source() diff --git a/lib/spack/spack/resource.py b/lib/spack/spack/resource.py index b20612686d..8d081b45c9 100644 --- a/lib/spack/spack/resource.py +++ b/lib/spack/spack/resource.py @@ -30,10 +30,10 @@ package to enable optional features. class Resource(object): """ - Represents an optional resource. Aggregates a name, a fetcher and a destination. + Represents an optional resource. Aggregates a name, a fetcher, a destination and a placement """ - def __init__(self, name, fetcher, destination, basename): + def __init__(self, name, fetcher, destination, placement): self.name = name self.fetcher = fetcher self.destination = destination - self.basename = basename + self.placement = placement diff --git a/var/spack/packages/clang/package.py b/var/spack/packages/clang/package.py index eac1863b97..ca368b3074 100644 --- a/var/spack/packages/clang/package.py +++ b/var/spack/packages/clang/package.py @@ -22,8 +22,13 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## + + from spack import * +import os +import os.path + class Clang(Package): """The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler. @@ -62,3 +67,29 @@ class Clang(Package): *options) make() make("install") + # CLang doesn't look in llvm folders for system headers... + self.link_llvm_directories(spec) + + def link_llvm_directories(self, spec): + + def clang_include_dir_at(root): + return join_path(root, 'include') + + def clang_lib_dir_at(root): + return join_path(root, 'lib/clang/', str(self.version), 'include') + + def do_link(source_dir, destination_dir): + if os.path.exists(source_dir): + for name in os.listdir(source_dir): + source = join_path(source_dir, name) + link = join_path(destination_dir, name) + os.symlink(source, link) + + # Link folder and files in include + llvm_dir = clang_include_dir_at(spec['llvm'].prefix) + clang_dir = clang_include_dir_at(self.prefix) + do_link(llvm_dir, clang_dir) + # Link folder and files in lib + llvm_dir = clang_lib_dir_at(spec['llvm'].prefix) + clang_dir = clang_lib_dir_at(self.prefix) + do_link(llvm_dir, clang_dir) \ No newline at end of file diff --git a/var/spack/packages/llvm/package.py b/var/spack/packages/llvm/package.py index 872a6c082b..d7ae3390be 100644 --- a/var/spack/packages/llvm/package.py +++ b/var/spack/packages/llvm/package.py @@ -53,10 +53,10 @@ class Llvm(Package): destination='projects', when='@3.7.0') resource(name='libcxx', url='http://llvm.org/releases/3.7.0/libcxx-3.7.0.src.tar.xz', md5='46aa5175cbe1ad42d6e9c995968e56dd', - destination='projects', basename='libcxx', when='+libcxx@3.7.0') + destination='projects', placement='libcxx', when='+libcxx@3.7.0') resource(name='libcxxabi', url='http://llvm.org/releases/3.7.0/libcxxabi-3.7.0.src.tar.xz', md5='5aa769e2fca79fa5335cfae8f6258772', - destination='projects', basename='libcxxabi', when='+libcxx@3.7.0') + destination='projects', placement='libcxxabi', when='+libcxx@3.7.0') ########## def install(self, spec, prefix): -- cgit v1.2.3-60-g2f50