Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Public Attributes | Private Attributes | List of all members
cmt2cmake.Project Class Reference
Inheritance diagram for cmt2cmake.Project:
Inheritance graph
[legend]
Collaboration diagram for cmt2cmake.Project:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def packages
 
def container
 
def name
 
def version
 
def uses
 
def heptools
 
def data_packages
 
def generate
 
def generateToolchain
 
def process
 

Public Attributes

 path
 
 requirements
 

Private Attributes

 _packages
 
 _container
 

Detailed Description

Definition at line 733 of file cmt2cmake.py.

Constructor & Destructor Documentation

def cmt2cmake.Project.__init__ (   self,
  path 
)
Create a project instance from the root directory of the project.

Definition at line 734 of file cmt2cmake.py.

735  def __init__(self, path):
736  """
737  Create a project instance from the root directory of the project.
738  """
739  self.path = os.path.realpath(path)
740  if not isProject(self.path):
741  raise ValueError("%s is not a project" % self.path)
742  self.requirements = os.path.join(self.path, "cmt", "project.cmt")
743  # Private variables for cached properties
744  self._packages = None
745  self._container = None

Member Function Documentation

def cmt2cmake.Project.container (   self)
Name of the container package of the project.

The name of the container is deduced using the usual LHCb convention
(instead of the content of project.cmt).

Definition at line 762 of file cmt2cmake.py.

763  def container(self):
764  """
765  Name of the container package of the project.
766 
767  The name of the container is deduced using the usual LHCb convention
768  (instead of the content of project.cmt).
769  """
770  if self._container is None:
771  for suffix in ["Release", "Sys"]:
772  try:
773  # gets the first package that ends with the suffix, and does
774  # not have a hat.. or raise StopIteration
775  c = (p for p in self.packages
776  if p.endswith(suffix) and "/" not in p).next()
777  self._container = self.packages[c]
778  break
779  except StopIteration:
780  pass
781  return self._container
def cmt2cmake.Project.data_packages (   self)
Return the list of data packages used by this project (i.e. by all the
packages in this project) in the form of a dictionary
{name: version_pattern}.

Definition at line 831 of file cmt2cmake.py.

832  def data_packages(self):
833  '''
834  Return the list of data packages used by this project (i.e. by all the
835  packages in this project) in the form of a dictionary
836  {name: version_pattern}.
837  '''
838  # for debugging we map
839  def appendDict(d, kv):
840  '''
841  helper function to extend a dictionary of lists
842  '''
843  k, v = kv
844  if k in d:
845  d[k].append(v)
846  else:
847  d[k] = [v]
848  return d
849  # dictionary {"data_package": ("user_package", "data_pkg_version")}
850  dp2pkg = {}
851  for pkgname, pkg in self.packages.items():
852  for dpname, dpversion in pkg.data_packages.items():
853  appendDict(dp2pkg, (dpname, (pkgname, dpversion)))
854 
855  # check and collect the data packages
856  result = {}
857  for dp in sorted(dp2pkg):
858  versions = set([v for _, v in dp2pkg[dp]])
859  if versions:
860  version = sorted(versions)[-1]
861  else:
862  version = '*'
863  if len(versions) != 1:
864  logging.warning('Different versions for data package %s, using %s from %s', dp, version, dp2pkg[dp])
865  result[dp] = version
866 
867  return result
def cmt2cmake.Project.generate (   self)

Definition at line 868 of file cmt2cmake.py.

869  def generate(self):
870  # list containing the lines to write to the file
871  data = ["CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)",
872  "",
873  "#---------------------------------------------------------------",
874  "# Load macros and functions for Gaudi-based projects",
875  "find_package(GaudiProject)",
876  "#---------------------------------------------------------------",
877  "",
878  "# Declare project name and version"]
879  l = "gaudi_project(%s %s" % (self.name, self.version)
880  use = "\n ".join(["%s %s" % u for u in self.uses()])
881  if use:
882  l += "\n USE " + use
883  # collect data packages
884  data_pkgs = []
885  for p, v in sorted(self.data_packages.items()):
886  if v in ('v*', '*'):
887  data_pkgs.append(p)
888  else:
889  data_pkgs.append("%s VERSION %s" % (p, v))
890  if data_pkgs:
891  l += ("\n DATA " +
892  "\n ".join(data_pkgs))
893  l += ")"
894  data.append(l)
895  return "\n".join(data) + "\n"
def cmt2cmake.Project.generateToolchain (   self)

Definition at line 896 of file cmt2cmake.py.

897  def generateToolchain(self):
898  heptools_version = self.heptools()
899  if heptools_version:
900  return toolchain_template.format(heptools_version)
901  return None
def cmt2cmake.Project.heptools (   self)
Return the version of heptools (LCGCMT) used by this project.

Definition at line 798 of file cmt2cmake.py.

799  def heptools(self):
800  '''
801  Return the version of heptools (LCGCMT) used by this project.
802  '''
803 
804  def updateCache(value):
805  '''
806  helper function to update the cache and return the value
807  '''
808  k = repr((self.name, self.version))
809  d = cache.get(k, {})
810  d['heptools'] = value
811  cache[k] = d
812  return value
813 
814  # check for a direct dependency
815  exp = re.compile(r'^\s*use\s+LCGCMT\s+LCGCMT[_-](\S+)')
816  for l in open(self.requirements):
817  m = exp.match(l)
818  if m:
819  return updateCache(m.group(1))
820 
821  # try with the projects we use (in the cache),
822  # including ourselves (we may already be there)
823  for u in list(self.uses()) + [(self.name, self.version)]:
824  u = repr(u)
825  if u in cache and 'heptools' in cache[u]:
826  return updateCache(cache[u]['heptools'])
827 
828  # we cannot guess the version of heptools
829  return None
def cmt2cmake.Project.name (   self)

Definition at line 783 of file cmt2cmake.py.

784  def name(self):
785  # The name of the project is the same of the container without
786  # the 'Release' or 'Sys' suffixes.
787  return self.container.name.replace("Release", "").replace("Sys", "")
def cmt2cmake.Project.packages (   self)
Dictionary of packages contained in the project.

Definition at line 747 of file cmt2cmake.py.

748  def packages(self):
749  """
750  Dictionary of packages contained in the project.
751  """
752  if self._packages is None:
753  self._packages = {}
754  for root, dirs, _files in os.walk(self.path):
755  if isPackage(root):
756  p = Package(root, self)
757  name = os.path.relpath(p.path, self.path)
758  self._packages[name] = p
759  dirs[:] = []
760  return self._packages
def cmt2cmake.Project.process (   self,
  overwrite = None 
)

Definition at line 902 of file cmt2cmake.py.

903  def process(self, overwrite=None):
904  # Prepare the project configuration
905  def produceFile(name, generator):
906  cml = os.path.join(self.path, name)
907  if ((overwrite == 'force')
908  or (not os.path.exists(cml))
909  or ((overwrite == 'update')
910  and (os.path.getmtime(cml) < os.path.getmtime(self.requirements)))):
911  # write the file
912  data = generator()
913  if data:
914  writeToFile(cml, data, logging)
915  else:
916  logging.info("file %s not generated (empty)", cml)
917  else:
918  logging.warning("file %s already exists", cml)
919 
920  produceFile("CMakeLists.txt", self.generate)
921  produceFile("toolchain.cmake", self.generateToolchain)
922 
923  # Recurse in the packages
924  for p in sorted(self.packages):
925  self.packages[p].process(overwrite)
926 
def cmt2cmake.Project.uses (   self)

Definition at line 792 of file cmt2cmake.py.

793  def uses(self):
794  for l in open(self.requirements):
795  l = l.split()
796  if l and l[0] == "use" and l[1] != "LCGCMT" and len(l) == 3:
797  yield (projectCase(l[1]), l[2].rsplit('_', 1)[-1])
def cmt2cmake.Project.version (   self)

Definition at line 789 of file cmt2cmake.py.

790  def version(self):
791  return self.container.version

Member Data Documentation

cmt2cmake.Project._container
private

Definition at line 744 of file cmt2cmake.py.

cmt2cmake.Project._packages
private

Definition at line 743 of file cmt2cmake.py.

cmt2cmake.Project.path

Definition at line 738 of file cmt2cmake.py.

cmt2cmake.Project.requirements

Definition at line 741 of file cmt2cmake.py.


The documentation for this class was generated from the following file:
Generated at Wed Jan 30 2013 17:13:49 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004