Gaudi Framework, version v23r3

Home   Generated: Thu Jun 28 2012

make_heptools.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 Small tool to generate the heptools toolchain from a given LCGCMT.
00004 """
00005 __author__ = "Marco Clemencic <marco.clemencic@cern.ch>"
00006 
00007 import os
00008 import re
00009 
00010 class HepToolsGenerator(object):
00011     """
00012     Class wrapping the details needed to generate the toolchain file from LCGCMT.
00013     """
00014     __header__ = """cmake_minimum_required(VERSION 2.8.5)
00015 
00016 # Declare the version of HEP Tools we use
00017 # (must be done before including heptools-common to allow evolution of the
00018 # structure)
00019 set(heptools_version  %s)
00020 
00021 include(${CMAKE_CURRENT_LIST_DIR}/heptools-common.cmake)
00022 
00023 # please keep alphabetic order and the structure (tabbing).
00024 # it makes it much easier to edit/read this file!
00025 """
00026     __trailer__ = """
00027 # Prepare the search paths according to the versions above
00028 LCG_prepare_paths()"""
00029 
00030     __AA_projects__ = ("COOL", "CORAL", "RELAX", "ROOT")
00031 
00032     __special_dirs__ = {"CLHEP": "clhep",
00033                         "fftw": "fftw3",
00034                         "Frontier_Client": "frontier_client",
00035                         "GCCXML":  "gccxml",
00036                         }
00037 
00038     __special_names__ = {"qt": "Qt"}
00039 
00040     def __init__(self, lcgcmt_root):
00041         """
00042         Prepare the instance.
00043 
00044         @param lcgcmt_root: path to the root directory of a given LCGCMT version
00045         """
00046         self.lcgcmt_root = lcgcmt_root
00047 
00048     def __repr__(self):
00049         """
00050         Representation of the instance.
00051         """
00052         return "HepToolsGenerator(%r)" % self.lcgcmt_root
00053 
00054     @property
00055     def versions(self):
00056         """
00057         Extract the external names and versions from an installed LCGCMT.
00058 
00059         @return: dictionary mapping external names to versions
00060         """
00061         from itertools import imap
00062         def statements(lines):
00063             """
00064             Generator of CMT statements from a list of lines.
00065             """
00066             statement = "" # we start with an empty statement
00067             for l in imap(lambda l: l.rstrip(), lines): # CMT ignores spaces at the end of line when checking for '\'
00068                 # append the current line to the statement so far
00069                 statement += l
00070                 if statement.endswith("\\"):
00071                     # in this case we need  to strip the '\' and continue the concatenation
00072                     statement = statement[:-1]
00073                 else:
00074                     # we can stop concatenating, but we return only non-trivial statements
00075                     statement = statement.strip()
00076                     if statement:
00077                         yield statement
00078                         statement = "" # we start collecting a new statement
00079 
00080         def tokens(statement):
00081             """
00082             Split a statement in tokens.
00083 
00084             Trivial implementation assuming the tokens do not contain spaces.
00085             """
00086             return statement.split()
00087 
00088         def macro(args):
00089             """
00090             Analyze the arguments of a macro command.
00091 
00092             @return: tuple (name, value, exceptionsDict)
00093             """
00094             unquote = lambda s: s.strip('"')
00095             name = args[0]
00096             value = unquote(args[1])
00097             # make a dictionary of the even to odd remaining args (unquoting the values)
00098             exceptions = dict(zip(args[2::2],
00099                                   map(unquote, args[3::2])))
00100             return name, value, exceptions
00101 
00102         # prepare the dictionary for the results
00103         versions = {}
00104         # We extract the statements from the requirements file of the LCG_Configuration package
00105         req = open(os.path.join(self.lcgcmt_root, "LCG_Configuration", "cmt", "requirements"))
00106         for toks in imap(tokens, statements(req)):
00107             if toks.pop(0) == "macro": # get only the macros ...
00108                 name, value, exceptions = macro(toks)
00109                 if name.endswith("_config_version"): # that end with _config_version
00110                     name = name[:-len("_config_version")]
00111                     name = self.__special_names__.get(name, name)
00112                     for tag in ["target-slc"]: # we use the alternative for 'target-slc' if present
00113                         value = exceptions.get(tag, value)
00114                     versions[name] = value.replace('(', '{').replace(')', '}')
00115         return versions
00116 
00117     def _content(self):
00118         """
00119         Generator producing the content (in blocks) of the toolchain file.
00120         """
00121         versions = self.versions
00122 
00123         yield self.__header__ % versions.pop("LCG")
00124 
00125         yield "\n# Application Area Projects"
00126         for name in self.__AA_projects__:
00127             # the width of the first string is bound to the length of the names
00128             # in self.__AA_projects__
00129             yield "LCG_AA_project(%-5s %s)" % (name, versions.pop(name))
00130 
00131         yield "\n# Compilers"
00132         # @FIXME: to be made cleaner and more flexible
00133         for compiler in [("gcc43", "gcc", "4.3.5"),
00134                          ("gcc46", "gcc", "4.6.2"),
00135                          ("gcc47", "gcc", "4.7.0"),
00136                          ("clang30", "clang", "3.0"),
00137                          ("gccmax", "gcc", "4.7.0")]:
00138             yield "LCG_compiler(%s %s %s)" % compiler
00139 
00140         yield "\n# Externals"
00141         lengths = (max(map(len, versions.keys())),
00142                    max(map(len, versions.values())),
00143                    max(map(len, self.__special_dirs__.values()))
00144                    )
00145         template = "LCG_external_package(%%-%ds %%-%ds %%-%ds)" % lengths
00146 
00147         def packageSorting(pkg):
00148             "special package sorting keys"
00149             key = pkg.lower()
00150             if key == "javajni":
00151                 key = "javasdk_javajni"
00152             return key
00153         for name in sorted(versions.keys(), key=packageSorting):
00154             # special case
00155             if name == "uuid":
00156                 yield "if(NOT ${os} STREQUAL slc6) # uuid is not distributed with SLC6"
00157             # LCG_external_package(CLHEP            1.9.4.7             clhep)
00158             yield template % (name, versions[name], self.__special_dirs__.get(name, ""))
00159             if name == "uuid":
00160                 yield "endif()"
00161 
00162         yield self.__trailer__
00163 
00164     def __str__(self):
00165         """
00166         Return the content of the toolchain file.
00167         """
00168         return "\n".join(self._content())
00169 
00170 if __name__ == '__main__':
00171     import sys
00172     if len(sys.argv) != 2 or not os.path.exists(sys.argv[1]):
00173         print "Usage : %s <path to LCGCMT version>" % os.path.basename(sys.argv[0])
00174         sys.exit(1)
00175     print HepToolsGenerator(sys.argv[1])
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 12:29:50 for Gaudi Framework, version v23r3 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004