Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 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 718 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 719 of file cmt2cmake.py.

720  def __init__(self, path):
721  """
722  Create a project instance from the root directory of the project.
723  """
724  self.path = os.path.realpath(path)
725  if not isProject(self.path):
726  raise ValueError("%s is not a project" % self.path)
727  self.requirements = os.path.join(self.path, "cmt", "project.cmt")
728  # Private variables for cached properties
729  self._packages = None
730  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 747 of file cmt2cmake.py.

748  def container(self):
749  """
750  Name of the container package of the project.
751 
752  The name of the container is deduced using the usual LHCb convention
753  (instead of the content of project.cmt).
754  """
755  if self._container is None:
756  for suffix in ["Release", "Sys"]:
757  try:
758  # gets the first package that ends with the suffix, and does
759  # not have a hat.. or raise StopIteration
760  c = (p for p in self.packages
761  if p.endswith(suffix) and "/" not in p).next()
762  self._container = self.packages[c]
763  break
764  except StopIteration:
765  pass
766  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 816 of file cmt2cmake.py.

817  def data_packages(self):
818  '''
819  Return the list of data packages used by this project (i.e. by all the
820  packages in this project) in the form of a dictionary
821  {name: version_pattern}.
822  '''
823  # for debugging we map
824  def appendDict(d, kv):
825  '''
826  helper function to extend a dictionary of lists
827  '''
828  k, v = kv
829  if k in d:
830  d[k].append(v)
831  else:
832  d[k] = [v]
833  return d
834  # dictionary {"data_package": ("user_package", "data_pkg_version")}
835  dp2pkg = {}
836  for pkgname, pkg in self.packages.items():
837  for dpname, dpversion in pkg.data_packages.items():
838  appendDict(dp2pkg, (dpname, (pkgname, dpversion)))
839 
840  # check and collect the data packages
841  result = {}
842  for dp in sorted(dp2pkg):
843  versions = set([v for _, v in dp2pkg[dp]])
844  if versions:
845  version = sorted(versions)[-1]
846  else:
847  version = '*'
848  if len(versions) != 1:
849  logging.warning('Different versions for data package %s, using %s from %s', dp, version, dp2pkg[dp])
850  result[dp] = version
851 
852  return result
def cmt2cmake.Project.generate (   self)

Definition at line 853 of file cmt2cmake.py.

854  def generate(self):
855  # list containing the lines to write to the file
856  data = ["CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)",
857  "",
858  "#---------------------------------------------------------------",
859  "# Load macros and functions for Gaudi-based projects",
860  "find_package(GaudiProject)",
861  "#---------------------------------------------------------------",
862  "",
863  "# Declare project name and version"]
864  l = "gaudi_project(%s %s" % (self.name, self.version)
865  use = "\n ".join(["%s %s" % u for u in self.uses()])
866  if use:
867  l += "\n USE " + use
868  # collect data packages
869  data_pkgs = []
870  for p, v in sorted(self.data_packages.items()):
871  if v in ('v*', '*'):
872  data_pkgs.append(p)
873  else:
874  data_pkgs.append("%s VERSION %s" % (p, v))
875  if data_pkgs:
876  l += ("\n DATA " +
877  "\n ".join(data_pkgs))
878  l += ")"
879  data.append(l)
880  return "\n".join(data) + "\n"
def cmt2cmake.Project.generateToolchain (   self)

Definition at line 881 of file cmt2cmake.py.

882  def generateToolchain(self):
883  heptools_version = self.heptools()
884  if heptools_version:
885  return toolchain_template.format(heptools_version)
886  return None
def cmt2cmake.Project.heptools (   self)
Return the version of heptools (LCGCMT) used by this project.

Definition at line 783 of file cmt2cmake.py.

784  def heptools(self):
785  '''
786  Return the version of heptools (LCGCMT) used by this project.
787  '''
788 
789  def updateCache(value):
790  '''
791  helper function to update the cache and return the value
792  '''
793  k = repr((self.name, self.version))
794  d = cache.get(k, {})
795  d['heptools'] = value
796  cache[k] = d
797  return value
798 
799  # check for a direct dependency
800  exp = re.compile(r'^\s*use\s+LCGCMT\s+LCGCMT[_-](\S+)')
801  for l in open(self.requirements):
802  m = exp.match(l)
803  if m:
804  return updateCache(m.group(1))
805 
806  # try with the projects we use (in the cache),
807  # including ourselves (we may already be there)
808  for u in list(self.uses()) + [(self.name, self.version)]:
809  u = repr(u)
810  if u in cache and 'heptools' in cache[u]:
811  return updateCache(cache[u]['heptools'])
812 
813  # we cannot guess the version of heptools
814  return None
def cmt2cmake.Project.name (   self)

Definition at line 768 of file cmt2cmake.py.

769  def name(self):
770  # The name of the project is the same of the container without
771  # the 'Release' or 'Sys' suffixes.
772  return self.container.name.replace("Release", "").replace("Sys", "")
def cmt2cmake.Project.packages (   self)
Dictionary of packages contained in the project.

Definition at line 732 of file cmt2cmake.py.

733  def packages(self):
734  """
735  Dictionary of packages contained in the project.
736  """
737  if self._packages is None:
738  self._packages = {}
739  for root, dirs, _files in os.walk(self.path):
740  if isPackage(root):
741  p = Package(root, self)
742  name = os.path.relpath(p.path, self.path)
743  self._packages[name] = p
744  dirs[:] = []
745  return self._packages
def cmt2cmake.Project.process (   self,
  overwrite = None 
)

Definition at line 887 of file cmt2cmake.py.

888  def process(self, overwrite=None):
889  # Prepare the project configuration
890  def produceFile(name, generator):
891  cml = os.path.join(self.path, name)
892  if ((overwrite == 'force')
893  or (not os.path.exists(cml))
894  or ((overwrite == 'update')
895  and (os.path.getmtime(cml) < os.path.getmtime(self.requirements)))):
896  # write the file
897  data = generator()
898  if data:
899  writeToFile(cml, data, logging)
900  else:
901  logging.info("file %s not generated (empty)", cml)
902  else:
903  logging.warning("file %s already exists", cml)
904 
905  produceFile("CMakeLists.txt", self.generate)
906  produceFile("toolchain.cmake", self.generateToolchain)
907 
908  # Recurse in the packages
909  for p in sorted(self.packages):
910  self.packages[p].process(overwrite)
911 
def cmt2cmake.Project.uses (   self)

Definition at line 777 of file cmt2cmake.py.

778  def uses(self):
779  for l in open(self.requirements):
780  l = l.split()
781  if l and l[0] == "use" and l[1] != "LCGCMT" and len(l) == 3:
782  yield (projectCase(l[1]), l[2].rsplit('_', 1)[-1])
def cmt2cmake.Project.version (   self)

Definition at line 774 of file cmt2cmake.py.

775  def version(self):
776  return self.container.version

Member Data Documentation

cmt2cmake.Project._container
private

Definition at line 729 of file cmt2cmake.py.

cmt2cmake.Project._packages
private

Definition at line 728 of file cmt2cmake.py.

cmt2cmake.Project.path

Definition at line 723 of file cmt2cmake.py.

cmt2cmake.Project.requirements

Definition at line 726 of file cmt2cmake.py.


The documentation for this class was generated from the following file:
Generated at Wed Nov 28 2012 12:17:35 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004