Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
make_heptools.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 Small tool to generate the heptools toolchain from a given LCGCMT.
4 """
5 __author__ = "Marco Clemencic <marco.clemencic@cern.ch>"
6 
7 import os
8 import re
9 
10 class HepToolsGenerator(object):
11  """
12  Class wrapping the details needed to generate the toolchain file from LCGCMT.
13  """
14  __header__ = """cmake_minimum_required(VERSION 2.8.5)
15 
16 # Declare the version of HEP Tools we use
17 # (must be done before including heptools-common to allow evolution of the
18 # structure)
19 set(heptools_version %s)
20 
21 include(${CMAKE_CURRENT_LIST_DIR}/heptools-common.cmake)
22 
23 # please keep alphabetic order and the structure (tabbing).
24 # it makes it much easier to edit/read this file!
25 """
26  __trailer__ = """
27 # Prepare the search paths according to the versions above
28 LCG_prepare_paths()"""
29 
30  __AA_projects__ = ("COOL", "CORAL", "RELAX", "ROOT")
31 
32  __special_dirs__ = {"CLHEP": "clhep",
33  "fftw": "fftw3",
34  "Frontier_Client": "frontier_client",
35  "GCCXML": "gccxml",
36  "Qt": "qt",
37  "CASTOR": "castor",
38  "lfc": "Grid/LFC",
39  "TBB": "tbb",
40  }
41 
42  __special_names__ = {"qt": "Qt"}
43 
44  def __init__(self, lcgcmt_root):
45  """
46  Prepare the instance.
47 
48  @param lcgcmt_root: path to the root directory of a given LCGCMT version
49  """
50  self.lcgcmt_root = lcgcmt_root
51 
52  def __repr__(self):
53  """
54  Representation of the instance.
55  """
56  return "HepToolsGenerator(%r)" % self.lcgcmt_root
57 
58  @property
59  def versions(self):
60  """
61  Extract the external names and versions from an installed LCGCMT.
62 
63  @return: dictionary mapping external names to versions
64  """
65  from itertools import imap
66  def statements(lines):
67  """
68  Generator of CMT statements from a list of lines.
69  """
70  statement = "" # we start with an empty statement
71  for l in imap(lambda l: l.rstrip(), lines): # CMT ignores spaces at the end of line when checking for '\'
72  # append the current line to the statement so far
73  statement += l
74  if statement.endswith("\\"):
75  # in this case we need to strip the '\' and continue the concatenation
76  statement = statement[:-1]
77  else:
78  # we can stop concatenating, but we return only non-trivial statements
79  statement = statement.strip()
80  if statement:
81  yield statement
82  statement = "" # we start collecting a new statement
83 
84  def tokens(statement):
85  """
86  Split a statement in tokens.
87 
88  Trivial implementation assuming the tokens do not contain spaces.
89  """
90  return statement.split()
91 
92  def macro(args):
93  """
94  Analyze the arguments of a macro command.
95 
96  @return: tuple (name, value, exceptionsDict)
97  """
98  unquote = lambda s: s.strip('"')
99  name = args[0]
100  value = unquote(args[1])
101  # make a dictionary of the even to odd remaining args (unquoting the values)
102  exceptions = dict(zip(args[2::2],
103  map(unquote, args[3::2])))
104  return name, value, exceptions
105 
106  # prepare the dictionary for the results
107  versions = {}
108  # We extract the statements from the requirements file of the LCG_Configuration package
109  req = open(os.path.join(self.lcgcmt_root, "LCG_Configuration", "cmt", "requirements"))
110  for toks in imap(tokens, statements(req)):
111  if toks.pop(0) == "macro": # get only the macros ...
112  name, value, exceptions = macro(toks)
113  if name.endswith("_config_version"): # that end with _config_version
114  name = name[:-len("_config_version")]
115  name = self.__special_names__.get(name, name)
116  for tag in ["target-slc"]: # we use the alternative for 'target-slc' if present
117  value = exceptions.get(tag, value)
118  versions[name] = value.replace('(', '{').replace(')', '}')
119  return versions
120 
121  def _content(self):
122  """
123  Generator producing the content (in blocks) of the toolchain file.
124  """
125  versions = self.versions
126 
127  yield self.__header__ % versions.pop("LCG")
128 
129  yield "\n# Application Area Projects"
130  for name in self.__AA_projects__:
131  # the width of the first string is bound to the length of the names
132  # in self.__AA_projects__
133  yield "LCG_AA_project(%-5s %s)" % (name, versions.pop(name))
134 
135  yield "\n# Compilers"
136  # @FIXME: to be made cleaner and more flexible
137  for compiler in [("gcc43", "gcc", "4.3.5"),
138  ("gcc46", "gcc", "4.6.2"),
139  ("gcc47", "gcc", "4.7.2"),
140  ("clang30", "clang", "3.0"),
141  ("gccmax", "gcc", "4.7.2")]:
142  yield "LCG_compiler(%s %s %s)" % compiler
143 
144  yield "\n# Externals"
145  lengths = (max(map(len, versions.keys())),
146  max(map(len, versions.values())),
147  max(map(len, self.__special_dirs__.values()))
148  )
149  template = "LCG_external_package(%%-%ds %%-%ds %%-%ds)" % lengths
150 
151  def packageSorting(pkg):
152  "special package sorting keys"
153  key = pkg.lower()
154  if key == "javajni":
155  key = "javasdk_javajni"
156  return key
157  for name in sorted(versions.keys(), key=packageSorting):
158  # special case
159  if name == "uuid":
160  yield "if(NOT ${LCG_OS}${LCG_OS_VERS} STREQUAL slc6) # uuid is not distributed with SLC6"
161  # LCG_external_package(CLHEP 1.9.4.7 clhep)
162  yield template % (name, versions[name], self.__special_dirs__.get(name, ""))
163  if name == "uuid":
164  yield "endif()"
165 
166  yield self.__trailer__
167 
168  def __str__(self):
169  """
170  Return the content of the toolchain file.
171  """
172  return "\n".join(self._content())
173 
174 if __name__ == '__main__':
175  import sys
176  if len(sys.argv) != 2 or not os.path.exists(sys.argv[1]):
177  print "Usage : %s <path to LCGCMT version>" % os.path.basename(sys.argv[0])
178  sys.exit(1)
179  print HepToolsGenerator(sys.argv[1])

Generated at Wed Jan 30 2013 17:13:37 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004