| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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:
[legend]
Collaboration diagram for cmt2cmake.Project:
[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 734 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 735 of file cmt2cmake.py.

735
736 def __init__(self, path):
737 """
738 Create a project instance from the root directory of the project.
739 """
740 self.path = os.path.realpath(path)
741 if not isProject(self.path):
742 raise ValueError("%s is not a project" % self.path)
743 self.requirements = os.path.join(self.path, "cmt", "project.cmt")
744 # Private variables for cached properties
745 self._packages = None
746 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 763 of file cmt2cmake.py.

763
764 def container(self):
765 """
766 Name of the container package of the project.
767
768 The name of the container is deduced using the usual LHCb convention
769 (instead of the content of project.cmt).
770 """
771 if self._container is None:
772 for suffix in ["Release", "Sys"]:
773 try:
774 # gets the first package that ends with the suffix, and does
775 # not have a hat.. or raise StopIteration
776 c = (p for p in self.packages
777 if p.endswith(suffix) and "/" not in p).next()
778 self._container = self.packages[c]
779 break
780 except StopIteration:
781 pass
782 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 832 of file cmt2cmake.py.

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

def cmt2cmake.Project.generate | ( |  | self | ) |

Definition at line 869 of file cmt2cmake.py.

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

def cmt2cmake.Project.generateToolchain | ( |  | self | ) |

Definition at line 897 of file cmt2cmake.py.

897
898 def generateToolchain(self):
899 heptools_version = self.heptools()
900 if heptools_version:
901 return toolchain_template.format(heptools_version)
902 return None

def cmt2cmake.Project.heptools | ( |  | self | ) |

    Return the version of heptools (LCGCMT) used by this project.

Definition at line 799 of file cmt2cmake.py.

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

def cmt2cmake.Project.name | ( |  | self | ) |

Definition at line 784 of file cmt2cmake.py.

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

def cmt2cmake.Project.packages | ( |  | self | ) |

    Dictionary of packages contained in the project.

Definition at line 748 of file cmt2cmake.py.

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

def cmt2cmake.Project.process | ( |  | self,
|  |  | overwrite = `None`
| ) |  |

Definition at line 903 of file cmt2cmake.py.

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

def cmt2cmake.Project.uses | ( |  | self | ) |

Definition at line 793 of file cmt2cmake.py.

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

def cmt2cmake.Project.version | ( |  | self | ) |

Definition at line 790 of file cmt2cmake.py.

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

## Member Data Documentation

cmt2cmake.Project._container
| private

Definition at line 745 of file cmt2cmake.py.

cmt2cmake.Project._packages
| private

Definition at line 744 of file cmt2cmake.py.

cmt2cmake.Project.path

Definition at line 739 of file cmt2cmake.py.

cmt2cmake.Project.requirements

Definition at line 742 of file cmt2cmake.py.

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/cmake/cmt2cmake/cmt2cmake.py