Package conary :: Package build :: Module buildpackage
[hide private]
[frames] | no frames]

Source Code for Module conary.build.buildpackage

  1  # 
  2  # Copyright (c) 2004-2008 rPath, Inc. 
  3  # 
  4  # This program is distributed under the terms of the Common Public License, 
  5  # version 1.0. A copy of this license should have been distributed with this 
  6  # source file in a file called LICENSE. If it is not present, the license 
  7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, but 
 10  # without any warranty; without even the implied warranty of merchantability 
 11  # or fitness for a particular purpose. See the Common Public License for 
 12  # full details. 
 13  # 
 14   
 15  """ 
 16  Contains classes used during the build process to collect files 
 17  into BuildComponents.  These BuildComponents are used to create Packages 
 18  and create changesets from the files created during the build process 
 19  """ 
 20   
 21  import os 
 22  import time 
 23   
 24  from conary import files 
 25  from conary.lib import sha1helper 
 26  from conary.build import use 
 27  from conary.deps import deps 
 28   
29 -def BuildDeviceFile(devtype, major, minor, owner, group, perms):
30 if devtype == "b": 31 f = files.BlockDevice(None) 32 elif devtype == "c": 33 f = files.CharacterDevice(None) 34 else: 35 raise AssertionError 36 37 f.devt.major.set(major) 38 f.devt.minor.set(minor) 39 f.inode.owner.set(owner) 40 f.inode.group.set(group) 41 f.inode.perms.set(perms) 42 f.inode.mtime.set(int(time.time())) 43 f.flags.set(0) 44 45 return f
46
47 -def _getUseFlavor(recipe):
48 """ 49 Returns a deps.Flavor instance that represents the Use flags 50 that have been used. 51 """ 52 if 'abstractBaseClass' in recipe.__class__.__dict__ \ 53 and recipe.abstractBaseClass: 54 # abstract base classes shouldn't be flavored 55 return deps.Flavor() 56 f = use.createFlavor(recipe.name, use.Use._iterUsed(), 57 recipe.Flags._iterUsed(), 58 use.Arch._iterUsed(), 59 targetDep=recipe.isCrossCompileTool()) 60 if recipe.isCrossCompileTool(): 61 # there's no guarantee that a cross compiler tool will mention 62 # anything in its flavor to automatically add the target flavor. 63 # We have to do it manually. 64 f.union(recipe.targetFlavor) 65 return f
66
67 -class BuildComponent(dict):
68
69 - def addFile(self, path, realPath):
70 """ 71 Add a file to the build component 72 73 @param path: the destination of the file in the component 74 @param realPath: the location of the actual file on the filesystem, 75 used to obtain the contents of the file when creating a changeset 76 to commit to the repository 77 """ 78 # skip uid/gid lookups because packagepolicy will change the 79 # ownerships according to Ownership settings anyway 80 (f, linkCount, inode) = files.FileFromFilesystem(realPath, None, 81 inodeInfo = True, assumeRoot = True) 82 f.inode.perms.set(f.inode.perms() & 01777) 83 self[path] = (realPath, f) 84 if (f.inode.perms() & 0400) != 0400: 85 # we can safely change the permissions now, the original 86 # permissions have been recorded 87 os.chmod(realPath, f.inode.perms() | 0400) 88 89 if linkCount > 1: 90 if f.hasContents: 91 l = self.linkGroups.get(inode, []) 92 l.append(path) 93 self.linkGroups[inode] = l 94 # add to list to check for config files later 95 self.hardlinks.append(path) 96 else: 97 if not isinstance(f, files.Directory): 98 # no hardlinks allowed for special files other than dirs 99 self.badhardlinks.append(path) 100 return f
101
102 - def addDevice(self, path, devtype, major, minor, 103 owner='root', group='root', perms=0660):
104 """ 105 Add a device node to the build component 106 107 @param path: the destination of the device node in the component 108 """ 109 f = BuildDeviceFile(devtype, major, minor, owner, group, perms) 110 self[path] = (None, f) 111 return f
112
113 - def getFile(self, path):
114 return self[path][1]
115
116 - def getRealPath(self, path):
117 return self[path][0]
118
119 - def getName(self):
120 """ 121 Return the name of the BuildComponent 122 123 @returns: name of the BuildComponent 124 @rtype: str 125 """ 126 return self.name
127
128 - def getUserMap(self):
129 """ 130 Dict mapping user names to tuples of C{(preferred_uid, groupname, 131 preferred_groupid, homedir, comment, shell)} 132 """ 133 return self.recipe.usermap
134
135 - def getUserGroupMap(self):
136 """ 137 Reverse map from group name to user name for groups created as part 138 of a user definition. 139 """ 140 return self.recipe.usergrpmap
141
142 - def getGroupMap(self):
143 """ 144 Dict mapping group names to preferred_groupid 145 """ 146 return self.recipe.groupmap
147
148 - def getSuppGroupMap(self):
149 """ 150 Dict mapping user names to C{(group, preferred_groupid)} tuples 151 """ 152 return self.recipe.suppmap
153
154 - def __init__(self, name, recipe):
155 self.name = name 156 self.requires = deps.DependencySet() 157 self.provides = deps.DependencySet() 158 self.provides.addDep(deps.TroveDependencies, deps.Dependency(name)) 159 self.flavor = _getUseFlavor(recipe) 160 self.linkGroups = {} 161 self.requiresMap = {} 162 self.providesMap = {} 163 self.hardlinks = [] 164 self.badhardlinks = [] 165 self.recipe = recipe 166 dict.