Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Packaging process |
| 3 | # |
| 4 | # Executive summary: This class iterates over the functions listed in PACKAGEFUNCS |
| 5 | # Taking D and splitting it up into the packages listed in PACKAGES, placing the |
| 6 | # resulting output in PKGDEST. |
| 7 | # |
| 8 | # There are the following default steps but PACKAGEFUNCS can be extended: |
| 9 | # |
| 10 | # a) package_get_auto_pr - get PRAUTO from remote PR service |
| 11 | # |
| 12 | # b) perform_packagecopy - Copy D into PKGD |
| 13 | # |
| 14 | # c) package_do_split_locales - Split out the locale files, updates FILES and PACKAGES |
| 15 | # |
| 16 | # d) split_and_strip_files - split the files into runtime and debug and strip them. |
| 17 | # Debug files include debug info split, and associated sources that end up in -dbg packages |
| 18 | # |
| 19 | # e) fixup_perms - Fix up permissions in the package before we split it. |
| 20 | # |
| 21 | # f) populate_packages - Split the files in PKGD into separate packages in PKGDEST/<pkgname> |
| 22 | # Also triggers the binary stripping code to put files in -dbg packages. |
| 23 | # |
| 24 | # g) package_do_filedeps - Collect perfile run-time dependency metadata |
| 25 | # The data is stores in FILER{PROVIDES,DEPENDS}_file_pkg variables with |
| 26 | # a list of affected files in FILER{PROVIDES,DEPENDS}FLIST_pkg |
| 27 | # |
| 28 | # h) package_do_shlibs - Look at the shared libraries generated and autotmatically add any |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 29 | # dependencies found. Also stores the package name so anyone else using this library |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | # knows which package to depend on. |
| 31 | # |
| 32 | # i) package_do_pkgconfig - Keep track of which packages need and provide which .pc files |
| 33 | # |
| 34 | # j) read_shlibdeps - Reads the stored shlibs information into the metadata |
| 35 | # |
| 36 | # k) package_depchains - Adds automatic dependencies to -dbg and -dev packages |
| 37 | # |
| 38 | # l) emit_pkgdata - saves the packaging data into PKGDATA_DIR for use in later |
| 39 | # packaging steps |
| 40 | |
| 41 | inherit packagedata |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | inherit chrpath |
| 43 | |
| 44 | # Need the package_qa_handle_error() in insane.bbclass |
| 45 | inherit insane |
| 46 | |
| 47 | PKGD = "${WORKDIR}/package" |
| 48 | PKGDEST = "${WORKDIR}/packages-split" |
| 49 | |
| 50 | LOCALE_SECTION ?= '' |
| 51 | |
| 52 | ALL_MULTILIB_PACKAGE_ARCHS = "${@all_multilib_tune_values(d, 'PACKAGE_ARCHS')}" |
| 53 | |
| 54 | # rpm is used for the per-file dependency identification |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 55 | # dwarfsrcfiles is used to determine the list of debug source files |
| 56 | PACKAGE_DEPENDS += "rpm-native dwarfsrcfiles-native" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 58 | |
| 59 | # If your postinstall can execute at rootfs creation time rather than on |
| 60 | # target but depends on a native/cross tool in order to execute, you need to |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 61 | # list that tool in PACKAGE_WRITE_DEPS. Target package dependencies belong |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | # in the package dependencies as normal, this is just for native/cross support |
| 63 | # tools at rootfs build time. |
| 64 | PACKAGE_WRITE_DEPS ??= "" |
| 65 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | def legitimize_package_name(s): |
| 67 | """ |
| 68 | Make sure package names are legitimate strings |
| 69 | """ |
| 70 | import re |
| 71 | |
| 72 | def fixutf(m): |
| 73 | cp = m.group(1) |
| 74 | if cp: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | return ('\\u%s' % cp).encode('latin-1').decode('unicode_escape') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | |
| 77 | # Handle unicode codepoints encoded as <U0123>, as in glibc locale files. |
| 78 | s = re.sub('<U([0-9A-Fa-f]{1,4})>', fixutf, s) |
| 79 | |
| 80 | # Remaining package name validity fixes |
| 81 | return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-') |
| 82 | |
| 83 | def do_split_packages(d, root, file_regex, output_pattern, description, postinst=None, recursive=False, hook=None, extra_depends=None, aux_files_pattern=None, postrm=None, allow_dirs=False, prepend=False, match_path=False, aux_files_pattern_verbatim=None, allow_links=False, summary=None): |
| 84 | """ |
| 85 | Used in .bb files to split up dynamically generated subpackages of a |
| 86 | given package, usually plugins or modules. |
| 87 | |
| 88 | Arguments: |
| 89 | root -- the path in which to search |
| 90 | file_regex -- regular expression to match searched files. Use |
| 91 | parentheses () to mark the part of this expression |
| 92 | that should be used to derive the module name (to be |
| 93 | substituted where %s is used in other function |
| 94 | arguments as noted below) |
| 95 | output_pattern -- pattern to use for the package names. Must include %s. |
| 96 | description -- description to set for each package. Must include %s. |
| 97 | postinst -- postinstall script to use for all packages (as a |
| 98 | string) |
| 99 | recursive -- True to perform a recursive search - default False |
| 100 | hook -- a hook function to be called for every match. The |
| 101 | function will be called with the following arguments |
| 102 | (in the order listed): |
| 103 | f: full path to the file/directory match |
| 104 | pkg: the package name |
| 105 | file_regex: as above |
| 106 | output_pattern: as above |
| 107 | modulename: the module name derived using file_regex |
| 108 | extra_depends -- extra runtime dependencies (RDEPENDS) to be set for |
| 109 | all packages. The default value of None causes a |
| 110 | dependency on the main package (${PN}) - if you do |
| 111 | not want this, pass '' for this parameter. |
| 112 | aux_files_pattern -- extra item(s) to be added to FILES for each |
| 113 | package. Can be a single string item or a list of |
| 114 | strings for multiple items. Must include %s. |
| 115 | postrm -- postrm script to use for all packages (as a string) |
| 116 | allow_dirs -- True allow directories to be matched - default False |
| 117 | prepend -- if True, prepend created packages to PACKAGES instead |
| 118 | of the default False which appends them |
| 119 | match_path -- match file_regex on the whole relative path to the |
| 120 | root rather than just the file name |
| 121 | aux_files_pattern_verbatim -- extra item(s) to be added to FILES for |
| 122 | each package, using the actual derived module name |
| 123 | rather than converting it to something legal for a |
| 124 | package name. Can be a single string item or a list |
| 125 | of strings for multiple items. Must include %s. |
| 126 | allow_links -- True to allow symlinks to be matched - default False |
| 127 | summary -- Summary to set for each package. Must include %s; |
| 128 | defaults to description if not set. |
| 129 | |
| 130 | """ |
| 131 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | dvar = d.getVar('PKGD') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 133 | root = d.expand(root) |
| 134 | output_pattern = d.expand(output_pattern) |
| 135 | extra_depends = d.expand(extra_depends) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | |
| 137 | # If the root directory doesn't exist, don't error out later but silently do |
| 138 | # no splitting. |
| 139 | if not os.path.exists(dvar + root): |
| 140 | return [] |
| 141 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | ml = d.getVar("MLPREFIX") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | if ml: |
| 144 | if not output_pattern.startswith(ml): |
| 145 | output_pattern = ml + output_pattern |
| 146 | |
| 147 | newdeps = [] |
| 148 | for dep in (extra_depends or "").split(): |
| 149 | if dep.startswith(ml): |
| 150 | newdeps.append(dep) |
| 151 | else: |
| 152 | newdeps.append(ml + dep) |
| 153 | if newdeps: |
| 154 | extra_depends = " ".join(newdeps) |
| 155 | |
| 156 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 157 | packages = d.getVar('PACKAGES').split() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 158 | split_packages = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | |
| 160 | if postinst: |
| 161 | postinst = '#!/bin/sh\n' + postinst + '\n' |
| 162 | if postrm: |
| 163 | postrm = '#!/bin/sh\n' + postrm + '\n' |
| 164 | if not recursive: |
| 165 | objs = os.listdir(dvar + root) |
| 166 | else: |
| 167 | objs = [] |
| 168 | for walkroot, dirs, files in os.walk(dvar + root): |
| 169 | for file in files: |
| 170 | relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1) |
| 171 | if relpath: |
| 172 | objs.append(relpath) |
| 173 | |
| 174 | if extra_depends == None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 | extra_depends = d.getVar("PN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 176 | |
| 177 | if not summary: |
| 178 | summary = description |
| 179 | |
| 180 | for o in sorted(objs): |
| 181 | import re, stat |
| 182 | if match_path: |
| 183 | m = re.match(file_regex, o) |
| 184 | else: |
| 185 | m = re.match(file_regex, os.path.basename(o)) |
| 186 | |
| 187 | if not m: |
| 188 | continue |
| 189 | f = os.path.join(dvar + root, o) |
| 190 | mode = os.lstat(f).st_mode |
| 191 | if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))): |
| 192 | continue |
| 193 | on = legitimize_package_name(m.group(1)) |
| 194 | pkg = output_pattern % on |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 195 | split_packages.add(pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | if not pkg in packages: |
| 197 | if prepend: |
| 198 | packages = [pkg] + packages |
| 199 | else: |
| 200 | packages.append(pkg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 201 | oldfiles = d.getVar('FILES_' + pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | newfile = os.path.join(root, o) |
| 203 | # These names will be passed through glob() so if the filename actually |
| 204 | # contains * or ? (rare, but possible) we need to handle that specially |
| 205 | newfile = newfile.replace('*', '[*]') |
| 206 | newfile = newfile.replace('?', '[?]') |
| 207 | if not oldfiles: |
| 208 | the_files = [newfile] |
| 209 | if aux_files_pattern: |
| 210 | if type(aux_files_pattern) is list: |
| 211 | for fp in aux_files_pattern: |
| 212 | the_files.append(fp % on) |
| 213 | else: |
| 214 | the_files.append(aux_files_pattern % on) |
| 215 | if aux_files_pattern_verbatim: |
| 216 | if type(aux_files_pattern_verbatim) is list: |
| 217 | for fp in aux_files_pattern_verbatim: |
| 218 | the_files.append(fp % m.group(1)) |
| 219 | else: |
| 220 | the_files.append(aux_files_pattern_verbatim % m.group(1)) |
| 221 | d.setVar('FILES_' + pkg, " ".join(the_files)) |
| 222 | else: |
| 223 | d.setVar('FILES_' + pkg, oldfiles + " " + newfile) |
| 224 | if extra_depends != '': |
| 225 | d.appendVar('RDEPENDS_' + pkg, ' ' + extra_depends) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 226 | if not d.getVar('DESCRIPTION_' + pkg): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 227 | d.setVar('DESCRIPTION_' + pkg, description % on) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 228 | if not d.getVar('SUMMARY_' + pkg): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | d.setVar('SUMMARY_' + pkg, summary % on) |
| 230 | if postinst: |
| 231 | d.setVar('pkg_postinst_' + pkg, postinst) |
| 232 | if postrm: |
| 233 | d.setVar('pkg_postrm_' + pkg, postrm) |
| 234 | if callable(hook): |
| 235 | hook(f, pkg, file_regex, output_pattern, m.group(1)) |
| 236 | |
| 237 | d.setVar('PACKAGES', ' '.join(packages)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 238 | return list(split_packages) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | |
| 240 | PACKAGE_DEPENDS += "file-native" |
| 241 | |
| 242 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 243 | if d.getVar('PACKAGES') != '': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | deps = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | for dep in (d.getVar('PACKAGE_DEPENDS') or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | deps += " %s:do_populate_sysroot" % dep |
| 247 | d.appendVarFlag('do_package', 'depends', deps) |
| 248 | |
| 249 | # shlibs requires any DEPENDS to have already packaged for the *.list files |
| 250 | d.appendVarFlag('do_package', 'deptask', " do_packagedata") |
| 251 | } |
| 252 | |
| 253 | # Get a list of files from file vars by searching files under current working directory |
| 254 | # The list contains symlinks, directories and normal files. |
| 255 | def files_from_filevars(filevars): |
| 256 | import os,glob |
| 257 | cpath = oe.cachedpath.CachedPath() |
| 258 | files = [] |
| 259 | for f in filevars: |
| 260 | if os.path.isabs(f): |
| 261 | f = '.' + f |
| 262 | if not f.startswith("./"): |
| 263 | f = './' + f |
| 264 | globbed = glob.glob(f) |
| 265 | if globbed: |
| 266 | if [ f ] != globbed: |
| 267 | files += globbed |
| 268 | continue |
| 269 | files.append(f) |
| 270 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 271 | symlink_paths = [] |
| 272 | for ind, f in enumerate(files): |
| 273 | # Handle directory symlinks. Truncate path to the lowest level symlink |
| 274 | parent = '' |
| 275 | for dirname in f.split('/')[:-1]: |
| 276 | parent = os.path.join(parent, dirname) |
| 277 | if dirname == '.': |
| 278 | continue |
| 279 | if cpath.islink(parent): |
| 280 | bb.warn("FILES contains file '%s' which resides under a " |
| 281 | "directory symlink. Please fix the recipe and use the " |
| 282 | "real path for the file." % f[1:]) |
| 283 | symlink_paths.append(f) |
| 284 | files[ind] = parent |
| 285 | f = parent |
| 286 | break |
| 287 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 288 | if not cpath.islink(f): |
| 289 | if cpath.isdir(f): |
| 290 | newfiles = [ os.path.join(f,x) for x in os.listdir(f) ] |
| 291 | if newfiles: |
| 292 | files += newfiles |
| 293 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 294 | return files, symlink_paths |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | |
| 296 | # Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files |
| 297 | def get_conffiles(pkg, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 298 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 299 | root = os.path.join(pkgdest, pkg) |
| 300 | cwd = os.getcwd() |
| 301 | os.chdir(root) |
| 302 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 303 | conffiles = d.getVar('CONFFILES_%s' % pkg); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 304 | if conffiles == None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 305 | conffiles = d.getVar('CONFFILES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 306 | if conffiles == None: |
| 307 | conffiles = "" |
| 308 | conffiles = conffiles.split() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 309 | conf_orig_list = files_from_filevars(conffiles)[0] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | |
| 311 | # Remove links and directories from conf_orig_list to get conf_list which only contains normal files |
| 312 | conf_list = [] |
| 313 | for f in conf_orig_list: |
| 314 | if os.path.isdir(f): |
| 315 | continue |
| 316 | if os.path.islink(f): |
| 317 | continue |
| 318 | if not os.path.exists(f): |
| 319 | continue |
| 320 | conf_list.append(f) |
| 321 | |
| 322 | # Remove the leading './' |
| 323 | for i in range(0, len(conf_list)): |
| 324 | conf_list[i] = conf_list[i][1:] |
| 325 | |
| 326 | os.chdir(cwd) |
| 327 | return conf_list |
| 328 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 329 | def checkbuildpath(file, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 330 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 331 | with open(file) as f: |
| 332 | file_content = f.read() |
| 333 | if tmpdir in file_content: |
| 334 | return True |
| 335 | |
| 336 | return False |
| 337 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 338 | def parse_debugsources_from_dwarfsrcfiles_output(dwarfsrcfiles_output): |
| 339 | debugfiles = {} |
| 340 | |
| 341 | for line in dwarfsrcfiles_output.splitlines(): |
| 342 | if line.startswith("\t"): |
| 343 | debugfiles[os.path.normpath(line.split()[0])] = "" |
| 344 | |
| 345 | return debugfiles.keys() |
| 346 | |
| 347 | def append_source_info(file, sourcefile, d, fatal=True): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 348 | import subprocess |
| 349 | |
| 350 | cmd = ["dwarfsrcfiles", file] |
| 351 | try: |
| 352 | output = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT) |
| 353 | retval = 0 |
| 354 | except subprocess.CalledProcessError as exc: |
| 355 | output = exc.output |
| 356 | retval = exc.returncode |
| 357 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 358 | # 255 means a specific file wasn't fully parsed to get the debug file list, which is not a fatal failure |
| 359 | if retval != 0 and retval != 255: |
| 360 | msg = "dwarfsrcfiles failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "") |
| 361 | if fatal: |
| 362 | bb.fatal(msg) |
| 363 | bb.note(msg) |
| 364 | |
| 365 | debugsources = parse_debugsources_from_dwarfsrcfiles_output(output) |
| 366 | # filenames are null-separated - this is an artefact of the previous use |
| 367 | # of rpm's debugedit, which was writing them out that way, and the code elsewhere |
| 368 | # is still assuming that. |
| 369 | debuglistoutput = '\0'.join(debugsources) + '\0' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 370 | lf = bb.utils.lockfile(sourcefile + ".lock") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 371 | open(sourcefile, 'a').write(debuglistoutput) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 372 | bb.utils.unlockfile(lf) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 373 | |
| 374 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 375 | def splitdebuginfo(file, dvar, debugdir, debuglibdir, debugappend, debugsrcdir, sourcefile, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | # Function to split a single file into two components, one is the stripped |
| 377 | # target system binary, the other contains any debugging information. The |
| 378 | # two files are linked to reference each other. |
| 379 | # |
| 380 | # sourcefile is also generated containing a list of debugsources |
| 381 | |
| 382 | import stat |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 383 | import subprocess |
| 384 | |
| 385 | src = file[len(dvar):] |
| 386 | dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend |
| 387 | debugfile = dvar + dest |
| 388 | |
| 389 | # Split the file... |
| 390 | bb.utils.mkdirhier(os.path.dirname(debugfile)) |
| 391 | #bb.note("Split %s -> %s" % (file, debugfile)) |
| 392 | # Only store off the hard link reference if we successfully split! |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 393 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 394 | dvar = d.getVar('PKGD') |
| 395 | objcopy = d.getVar("OBJCOPY") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 396 | |
| 397 | # We ignore kernel modules, we don't generate debug info files. |
| 398 | if file.find("/lib/modules/") != -1 and file.endswith(".ko"): |
| 399 | return 1 |
| 400 | |
| 401 | newmode = None |
| 402 | if not os.access(file, os.W_OK) or os.access(file, os.R_OK): |
| 403 | origmode = os.stat(file)[stat.ST_MODE] |
| 404 | newmode = origmode | stat.S_IWRITE | stat.S_IREAD |
| 405 | os.chmod(file, newmode) |
| 406 | |
| 407 | # We need to extract the debug src information here... |
| 408 | if debugsrcdir: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 409 | append_source_info(file, sourcefile, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 410 | |
| 411 | bb.utils.mkdirhier(os.path.dirname(debugfile)) |
| 412 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 413 | subprocess.check_output([objcopy, '--only-keep-debug', file, debugfile], stderr=subprocess.STDOUT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 414 | |
| 415 | # Set the debuglink to have the view of the file path on the target |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 416 | subprocess.check_output([objcopy, '--add-gnu-debuglink', debugfile, file], stderr=subprocess.STDOUT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | |
| 418 | if newmode: |
| 419 | os.chmod(file, origmode) |
| 420 | |
| 421 | return 0 |
| 422 | |
| 423 | def copydebugsources(debugsrcdir, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 424 | # The debug src information written out to sourcefile is further processed |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 425 | # and copied to the destination here. |
| 426 | |
| 427 | import stat |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 428 | import subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 429 | |
| 430 | sourcefile = d.expand("${WORKDIR}/debugsources.list") |
| 431 | if debugsrcdir and os.path.isfile(sourcefile): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 432 | dvar = d.getVar('PKGD') |
| 433 | strip = d.getVar("STRIP") |
| 434 | objcopy = d.getVar("OBJCOPY") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 435 | workdir = d.getVar("WORKDIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | workparentdir = os.path.dirname(os.path.dirname(workdir)) |
| 437 | workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir) |
| 438 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 439 | # If build path exists in sourcefile, it means toolchain did not use |
| 440 | # -fdebug-prefix-map to compile |
| 441 | if checkbuildpath(sourcefile, d): |
| 442 | localsrc_prefix = workparentdir + "/" |
| 443 | else: |
| 444 | localsrc_prefix = "/usr/src/debug/" |
| 445 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 446 | nosuchdir = [] |
| 447 | basepath = dvar |
| 448 | for p in debugsrcdir.split("/"): |
| 449 | basepath = basepath + "/" + p |
| 450 | if not cpath.exists(basepath): |
| 451 | nosuchdir.append(basepath) |
| 452 | bb.utils.mkdirhier(basepath) |
| 453 | cpath.updatecache(basepath) |
| 454 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 455 | # Ignore files from the recipe sysroots (target and native) |
| 456 | processdebugsrc = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 457 | # We need to ignore files that are not actually ours |
| 458 | # we do this by only paying attention to items from this package |
| 459 | processdebugsrc += "fgrep -zw '%s' | " |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 460 | # Remove prefix in the source paths |
| 461 | processdebugsrc += "sed 's#%s##g' | " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 462 | processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)" |
| 463 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 464 | cmd = processdebugsrc % (sourcefile, workbasedir, localsrc_prefix, workparentdir, dvar, debugsrcdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 465 | try: |
| 466 | subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
| 467 | except subprocess.CalledProcessError: |
| 468 | # Can "fail" if internal headers/transient sources are attempted |
| 469 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 470 | |
| 471 | # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced. |
| 472 | # Work around this by manually finding and copying any symbolic links that made it through. |
| 473 | cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s' 2>/dev/null)" % (dvar, debugsrcdir, dvar, debugsrcdir, workparentdir, dvar, debugsrcdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 474 | subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 475 | |
| 476 | # The copy by cpio may have resulted in some empty directories! Remove these |
| 477 | cmd = "find %s%s -empty -type d -delete" % (dvar, debugsrcdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 478 | subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 479 | |
| 480 | # Also remove debugsrcdir if its empty |
| 481 | for p in nosuchdir[::-1]: |
| 482 | if os.path.exists(p) and not os.listdir(p): |
| 483 | os.rmdir(p) |
| 484 | |
| 485 | # |
| 486 | # Package data handling routines |
| 487 | # |
| 488 | |
| 489 | def get_package_mapping (pkg, basepkg, d): |
| 490 | import oe.packagedata |
| 491 | |
| 492 | data = oe.packagedata.read_subpkgdata(pkg, d) |
| 493 | key = "PKG_%s" % pkg |
| 494 | |
| 495 | if key in data: |
| 496 | # Have to avoid undoing the write_extra_pkgs(global_variants...) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 497 | if bb.data.inherits_class('allarch', d) and not d.getVar('MULTILIB_VARIANTS') \ |
| 498 | and data[key] == basepkg: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 499 | return pkg |
| 500 | return data[key] |
| 501 | |
| 502 | return pkg |
| 503 | |
| 504 | def get_package_additional_metadata (pkg_type, d): |
| 505 | base_key = "PACKAGE_ADD_METADATA" |
| 506 | for key in ("%s_%s" % (base_key, pkg_type.upper()), base_key): |
| 507 | if d.getVar(key, False) is None: |
| 508 | continue |
| 509 | d.setVarFlag(key, "type", "list") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 510 | if d.getVarFlag(key, "separator") is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 511 | d.setVarFlag(key, "separator", "\\n") |
| 512 | metadata_fields = [field.strip() for field in oe.data.typed_value(key, d)] |
| 513 | return "\n".join(metadata_fields).strip() |
| 514 | |
| 515 | def runtime_mapping_rename (varname, pkg, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 516 | #bb.note("%s before: %s" % (varname, d.getVar(varname))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 517 | |
| 518 | new_depends = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 519 | deps = bb.utils.explode_dep_versions2(d.getVar(varname) or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 520 | for depend in deps: |
| 521 | new_depend = get_package_mapping(depend, pkg, d) |
| 522 | new_depends[new_depend] = deps[depend] |
| 523 | |
| 524 | d.setVar(varname, bb.utils.join_deps(new_depends, commasep=False)) |
| 525 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 526 | #bb.note("%s after: %s" % (varname, d.getVar(varname))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 527 | |
| 528 | # |
| 529 | # Package functions suitable for inclusion in PACKAGEFUNCS |
| 530 | # |
| 531 | |
| 532 | python package_get_auto_pr() { |
| 533 | import oe.prservice |
| 534 | import re |
| 535 | |
| 536 | # Support per recipe PRSERV_HOST |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 537 | pn = d.getVar('PN') |
| 538 | host = d.getVar("PRSERV_HOST_" + pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 539 | if not (host is None): |
| 540 | d.setVar("PRSERV_HOST", host) |
| 541 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 542 | pkgv = d.getVar("PKGV") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 543 | |
| 544 | # PR Server not active, handle AUTOINC |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 545 | if not d.getVar('PRSERV_HOST'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 546 | if 'AUTOINC' in pkgv: |
| 547 | d.setVar("PKGV", pkgv.replace("AUTOINC", "0")) |
| 548 | return |
| 549 | |
| 550 | auto_pr = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 551 | pv = d.getVar("PV") |
| 552 | version = d.getVar("PRAUTOINX") |
| 553 | pkgarch = d.getVar("PACKAGE_ARCH") |
| 554 | checksum = d.getVar("BB_TASKHASH") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 555 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 556 | if d.getVar('PRSERV_LOCKDOWN'): |
| 557 | auto_pr = d.getVar('PRAUTO_' + version + '_' + pkgarch) or d.getVar('PRAUTO_' + version) or None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 558 | if auto_pr is None: |
| 559 | bb.fatal("Can NOT get PRAUTO from lockdown exported file") |
| 560 | d.setVar('PRAUTO',str(auto_pr)) |
| 561 | return |
| 562 | |
| 563 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 564 | conn = d.getVar("__PRSERV_CONN") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 565 | if conn is None: |
| 566 | conn = oe.prservice.prserv_make_conn(d) |
| 567 | if conn is not None: |
| 568 | if "AUTOINC" in pkgv: |
| 569 | srcpv = bb.fetch2.get_srcrev(d) |
| 570 | base_ver = "AUTOINC-%s" % version[:version.find(srcpv)] |
| 571 | value = conn.getPR(base_ver, pkgarch, srcpv) |
| 572 | d.setVar("PKGV", pkgv.replace("AUTOINC", str(value))) |
| 573 | |
| 574 | auto_pr = conn.getPR(version, pkgarch, checksum) |
| 575 | except Exception as e: |
| 576 | bb.fatal("Can NOT get PRAUTO, exception %s" % str(e)) |
| 577 | if auto_pr is None: |
| 578 | bb.fatal("Can NOT get PRAUTO from remote PR service") |
| 579 | d.setVar('PRAUTO',str(auto_pr)) |
| 580 | } |
| 581 | |
| 582 | LOCALEBASEPN ??= "${PN}" |
| 583 | |
| 584 | python package_do_split_locales() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 585 | if (d.getVar('PACKAGE_NO_LOCALE') == '1'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 586 | bb.debug(1, "package requested not splitting locales") |
| 587 | return |
| 588 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 589 | packages = (d.getVar('PACKAGES') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 590 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 591 | datadir = d.getVar('datadir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 592 | if not datadir: |
| 593 | bb.note("datadir not defined") |
| 594 | return |
| 595 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 596 | dvar = d.getVar('PKGD') |
| 597 | pn = d.getVar('LOCALEBASEPN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 598 | |
| 599 | if pn + '-locale' in packages: |
| 600 | packages.remove(pn + '-locale') |
| 601 | |
| 602 | localedir = os.path.join(dvar + datadir, 'locale') |
| 603 | |
| 604 | if not cpath.isdir(localedir): |
| 605 | bb.debug(1, "No locale files in this package") |
| 606 | return |
| 607 | |
| 608 | locales = os.listdir(localedir) |
| 609 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 610 | summary = d.getVar('SUMMARY') or pn |
| 611 | description = d.getVar('DESCRIPTION') or "" |
| 612 | locale_section = d.getVar('LOCALE_SECTION') |
| 613 | mlprefix = d.getVar('MLPREFIX') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 614 | for l in sorted(locales): |
| 615 | ln = legitimize_package_name(l) |
| 616 | pkg = pn + '-locale-' + ln |
| 617 | packages.append(pkg) |
| 618 | d.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l)) |
| 619 | d.setVar('RRECOMMENDS_' + pkg, '%svirtual-locale-%s' % (mlprefix, ln)) |
| 620 | d.setVar('RPROVIDES_' + pkg, '%s-locale %s%s-translation' % (pn, mlprefix, ln)) |
| 621 | d.setVar('SUMMARY_' + pkg, '%s - %s translations' % (summary, l)) |
| 622 | d.setVar('DESCRIPTION_' + pkg, '%s This package contains language translation files for the %s locale.' % (description, l)) |
| 623 | if locale_section: |
| 624 | d.setVar('SECTION_' + pkg, locale_section) |
| 625 | |
| 626 | d.setVar('PACKAGES', ' '.join(packages)) |
| 627 | |
| 628 | # Disabled by RP 18/06/07 |
| 629 | # Wildcards aren't supported in debian |
| 630 | # They break with ipkg since glibc-locale* will mean that |
| 631 | # glibc-localedata-translit* won't install as a dependency |
| 632 | # for some other package which breaks meta-toolchain |
| 633 | # Probably breaks since virtual-locale- isn't provided anywhere |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 634 | #rdep = (d.getVar('RDEPENDS_%s' % pn) or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 635 | #rdep.append('%s-locale*' % pn) |
| 636 | #d.setVar('RDEPENDS_%s' % pn, ' '.join(rdep)) |
| 637 | } |
| 638 | |
| 639 | python perform_packagecopy () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 640 | import subprocess |
| 641 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 642 | dest = d.getVar('D') |
| 643 | dvar = d.getVar('PKGD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 644 | |
| 645 | # Start by package population by taking a copy of the installed |
| 646 | # files to operate on |
| 647 | # Preserve sparse files and hard links |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 648 | cmd = 'tar -cf - -C %s -p -S . | tar -xf - -C %s' % (dest, dvar) |
| 649 | subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 650 | |
| 651 | # replace RPATHs for the nativesdk binaries, to make them relocatable |
| 652 | if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d): |
| 653 | rpath_replace (dvar, d) |
| 654 | } |
| 655 | perform_packagecopy[cleandirs] = "${PKGD}" |
| 656 | perform_packagecopy[dirs] = "${PKGD}" |
| 657 | |
| 658 | # We generate a master list of directories to process, we start by |
| 659 | # seeding this list with reasonable defaults, then load from |
| 660 | # the fs-perms.txt files |
| 661 | python fixup_perms () { |
| 662 | import pwd, grp |
| 663 | |
| 664 | # init using a string with the same format as a line as documented in |
| 665 | # the fs-perms.txt file |
| 666 | # <path> <mode> <uid> <gid> <walk> <fmode> <fuid> <fgid> |
| 667 | # <path> link <link target> |
| 668 | # |
| 669 | # __str__ can be used to print out an entry in the input format |
| 670 | # |
| 671 | # if fs_perms_entry.path is None: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 672 | # an error occurred |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 673 | # if fs_perms_entry.link, you can retrieve: |
| 674 | # fs_perms_entry.path = path |
| 675 | # fs_perms_entry.link = target of link |
| 676 | # if not fs_perms_entry.link, you can retrieve: |
| 677 | # fs_perms_entry.path = path |
| 678 | # fs_perms_entry.mode = expected dir mode or None |
| 679 | # fs_perms_entry.uid = expected uid or -1 |
| 680 | # fs_perms_entry.gid = expected gid or -1 |
| 681 | # fs_perms_entry.walk = 'true' or something else |
| 682 | # fs_perms_entry.fmode = expected file mode or None |
| 683 | # fs_perms_entry.fuid = expected file uid or -1 |
| 684 | # fs_perms_entry_fgid = expected file gid or -1 |
| 685 | class fs_perms_entry(): |
| 686 | def __init__(self, line): |
| 687 | lsplit = line.split() |
| 688 | if len(lsplit) == 3 and lsplit[1].lower() == "link": |
| 689 | self._setlink(lsplit[0], lsplit[2]) |
| 690 | elif len(lsplit) == 8: |
| 691 | self._setdir(lsplit[0], lsplit[1], lsplit[2], lsplit[3], lsplit[4], lsplit[5], lsplit[6], lsplit[7]) |
| 692 | else: |
| 693 | msg = "Fixup Perms: invalid config line %s" % line |
| 694 | package_qa_handle_error("perm-config", msg, d) |
| 695 | self.path = None |
| 696 | self.link = None |
| 697 | |
| 698 | def _setdir(self, path, mode, uid, gid, walk, fmode, fuid, fgid): |
| 699 | self.path = os.path.normpath(path) |
| 700 | self.link = None |
| 701 | self.mode = self._procmode(mode) |
| 702 | self.uid = self._procuid(uid) |
| 703 | self.gid = self._procgid(gid) |
| 704 | self.walk = walk.lower() |
| 705 | self.fmode = self._procmode(fmode) |
| 706 | self.fuid = self._procuid(fuid) |
| 707 | self.fgid = self._procgid(fgid) |
| 708 | |
| 709 | def _setlink(self, path, link): |
| 710 | self.path = os.path.normpath(path) |
| 711 | self.link = link |
| 712 | |
| 713 | def _procmode(self, mode): |
| 714 | if not mode or (mode and mode == "-"): |
| 715 | return None |
| 716 | else: |
| 717 | return int(mode,8) |
| 718 | |
| 719 | # Note uid/gid -1 has special significance in os.lchown |
| 720 | def _procuid(self, uid): |
| 721 | if uid is None or uid == "-": |
| 722 | return -1 |
| 723 | elif uid.isdigit(): |
| 724 | return int(uid) |
| 725 | else: |
| 726 | return pwd.getpwnam(uid).pw_uid |
| 727 | |
| 728 | def _procgid(self, gid): |
| 729 | if gid is None or gid == "-": |
| 730 | return -1 |
| 731 | elif gid.isdigit(): |
| 732 | return int(gid) |
| 733 | else: |
| 734 | return grp.getgrnam(gid).gr_gid |
| 735 | |
| 736 | # Use for debugging the entries |
| 737 | def __str__(self): |
| 738 | if self.link: |
| 739 | return "%s link %s" % (self.path, self.link) |
| 740 | else: |
| 741 | mode = "-" |
| 742 | if self.mode: |
| 743 | mode = "0%o" % self.mode |
| 744 | fmode = "-" |
| 745 | if self.fmode: |
| 746 | fmode = "0%o" % self.fmode |
| 747 | uid = self._mapugid(self.uid) |
| 748 | gid = self._mapugid(self.gid) |
| 749 | fuid = self._mapugid(self.fuid) |
| 750 | fgid = self._mapugid(self.fgid) |
| 751 | return "%s %s %s %s %s %s %s %s" % (self.path, mode, uid, gid, self.walk, fmode, fuid, fgid) |
| 752 | |
| 753 | def _mapugid(self, id): |
| 754 | if id is None or id == -1: |
| 755 | return "-" |
| 756 | else: |
| 757 | return "%d" % id |
| 758 | |
| 759 | # Fix the permission, owner and group of path |
| 760 | def fix_perms(path, mode, uid, gid, dir): |
| 761 | if mode and not os.path.islink(path): |
| 762 | #bb.note("Fixup Perms: chmod 0%o %s" % (mode, dir)) |
| 763 | os.chmod(path, mode) |
| 764 | # -1 is a special value that means don't change the uid/gid |
| 765 | # if they are BOTH -1, don't bother to lchown |
| 766 | if not (uid == -1 and gid == -1): |
| 767 | #bb.note("Fixup Perms: lchown %d:%d %s" % (uid, gid, dir)) |
| 768 | os.lchown(path, uid, gid) |
| 769 | |
| 770 | # Return a list of configuration files based on either the default |
| 771 | # files/fs-perms.txt or the contents of FILESYSTEM_PERMS_TABLES |
| 772 | # paths are resolved via BBPATH |
| 773 | def get_fs_perms_list(d): |
| 774 | str = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 775 | bbpath = d.getVar('BBPATH') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 776 | fs_perms_tables = d.getVar('FILESYSTEM_PERMS_TABLES') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 777 | for conf_file in fs_perms_tables.split(): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 778 | confpath = bb.utils.which(bbpath, conf_file) |
| 779 | if confpath: |
| 780 | str += " %s" % bb.utils.which(bbpath, conf_file) |
| 781 | else: |
| 782 | bb.warn("cannot find %s specified in FILESYSTEM_PERMS_TABLES" % conf_file) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 783 | return str |
| 784 | |
| 785 | |
| 786 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 787 | dvar = d.getVar('PKGD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 788 | |
| 789 | fs_perms_table = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 790 | fs_link_table = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | |
| 792 | # By default all of the standard directories specified in |
| 793 | # bitbake.conf will get 0755 root:root. |
| 794 | target_path_vars = [ 'base_prefix', |
| 795 | 'prefix', |
| 796 | 'exec_prefix', |
| 797 | 'base_bindir', |
| 798 | 'base_sbindir', |
| 799 | 'base_libdir', |
| 800 | 'datadir', |
| 801 | 'sysconfdir', |
| 802 | 'servicedir', |
| 803 | 'sharedstatedir', |
| 804 | 'localstatedir', |
| 805 | 'infodir', |
| 806 | 'mandir', |
| 807 | 'docdir', |
| 808 | 'bindir', |
| 809 | 'sbindir', |
| 810 | 'libexecdir', |
| 811 | 'libdir', |
| 812 | 'includedir', |
| 813 | 'oldincludedir' ] |
| 814 | |
| 815 | for path in target_path_vars: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 816 | dir = d.getVar(path) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 817 | if dir == "": |
| 818 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 819 | fs_perms_table[dir] = fs_perms_entry(d.expand("%s 0755 root root false - - -" % (dir))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 820 | |
| 821 | # Now we actually load from the configuration files |
| 822 | for conf in get_fs_perms_list(d).split(): |
| 823 | if os.path.exists(conf): |
| 824 | f = open(conf) |
| 825 | for line in f: |
| 826 | if line.startswith('#'): |
| 827 | continue |
| 828 | lsplit = line.split() |
| 829 | if len(lsplit) == 0: |
| 830 | continue |
| 831 | if len(lsplit) != 8 and not (len(lsplit) == 3 and lsplit[1].lower() == "link"): |
| 832 | msg = "Fixup perms: %s invalid line: %s" % (conf, line) |
| 833 | package_qa_handle_error("perm-line", msg, d) |
| 834 | continue |
| 835 | entry = fs_perms_entry(d.expand(line)) |
| 836 | if entry and entry.path: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 837 | if entry.link: |
| 838 | fs_link_table[entry.path] = entry |
| 839 | if entry.path in fs_perms_table: |
| 840 | fs_perms_table.pop(entry.path) |
| 841 | else: |
| 842 | fs_perms_table[entry.path] = entry |
| 843 | if entry.path in fs_link_table: |
| 844 | fs_link_table.pop(entry.path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 845 | f.close() |
| 846 | |
| 847 | # Debug -- list out in-memory table |
| 848 | #for dir in fs_perms_table: |
| 849 | # bb.note("Fixup Perms: %s: %s" % (dir, str(fs_perms_table[dir]))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 850 | #for link in fs_link_table: |
| 851 | # bb.note("Fixup Perms: %s: %s" % (link, str(fs_link_table[link]))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 852 | |
| 853 | # We process links first, so we can go back and fixup directory ownership |
| 854 | # for any newly created directories |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 855 | # Process in sorted order so /run gets created before /run/lock, etc. |
| 856 | for entry in sorted(fs_link_table.values(), key=lambda x: x.link): |
| 857 | link = entry.link |
| 858 | dir = entry.path |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 859 | origin = dvar + dir |
| 860 | if not (cpath.exists(origin) and cpath.isdir(origin) and not cpath.islink(origin)): |
| 861 | continue |
| 862 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 863 | if link[0] == "/": |
| 864 | target = dvar + link |
| 865 | ptarget = link |
| 866 | else: |
| 867 | target = os.path.join(os.path.dirname(origin), link) |
| 868 | ptarget = os.path.join(os.path.dirname(dir), link) |
| 869 | if os.path.exists(target): |
| 870 | msg = "Fixup Perms: Unable to correct directory link, target already exists: %s -> %s" % (dir, ptarget) |
| 871 | package_qa_handle_error("perm-link", msg, d) |
| 872 | continue |
| 873 | |
| 874 | # Create path to move directory to, move it, and then setup the symlink |
| 875 | bb.utils.mkdirhier(os.path.dirname(target)) |
| 876 | #bb.note("Fixup Perms: Rename %s -> %s" % (dir, ptarget)) |
| 877 | os.rename(origin, target) |
| 878 | #bb.note("Fixup Perms: Link %s -> %s" % (dir, link)) |
| 879 | os.symlink(link, origin) |
| 880 | |
| 881 | for dir in fs_perms_table: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 882 | origin = dvar + dir |
| 883 | if not (cpath.exists(origin) and cpath.isdir(origin)): |
| 884 | continue |
| 885 | |
| 886 | fix_perms(origin, fs_perms_table[dir].mode, fs_perms_table[dir].uid, fs_perms_table[dir].gid, dir) |
| 887 | |
| 888 | if fs_perms_table[dir].walk == 'true': |
| 889 | for root, dirs, files in os.walk(origin): |
| 890 | for dr in dirs: |
| 891 | each_dir = os.path.join(root, dr) |
| 892 | fix_perms(each_dir, fs_perms_table[dir].mode, fs_perms_table[dir].uid, fs_perms_table[dir].gid, dir) |
| 893 | for f in files: |
| 894 | each_file = os.path.join(root, f) |
| 895 | fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir) |
| 896 | } |
| 897 | |
| 898 | python split_and_strip_files () { |
| 899 | import stat, errno |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 900 | import subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 901 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 902 | dvar = d.getVar('PKGD') |
| 903 | pn = d.getVar('PN') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 904 | targetos = d.getVar('TARGET_OS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 905 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 906 | oldcwd = os.getcwd() |
| 907 | os.chdir(dvar) |
| 908 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 909 | # We default to '.debug' style |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 910 | if d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-file-directory': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 911 | # Single debug-file-directory style debug info |
| 912 | debugappend = ".debug" |
| 913 | debugdir = "" |
| 914 | debuglibdir = "/usr/lib/debug" |
| 915 | debugsrcdir = "/usr/src/debug" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 916 | elif d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-without-src': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 917 | # Original OE-core, a.k.a. ".debug", style debug info, but without sources in /usr/src/debug |
| 918 | debugappend = "" |
| 919 | debugdir = "/.debug" |
| 920 | debuglibdir = "" |
| 921 | debugsrcdir = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 922 | elif d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-with-srcpkg': |
| 923 | debugappend = "" |
| 924 | debugdir = "/.debug" |
| 925 | debuglibdir = "" |
| 926 | debugsrcdir = "/usr/src/debug" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 927 | else: |
| 928 | # Original OE-core, a.k.a. ".debug", style debug info |
| 929 | debugappend = "" |
| 930 | debugdir = "/.debug" |
| 931 | debuglibdir = "" |
| 932 | debugsrcdir = "/usr/src/debug" |
| 933 | |
| 934 | sourcefile = d.expand("${WORKDIR}/debugsources.list") |
| 935 | bb.utils.remove(sourcefile) |
| 936 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 937 | # |
| 938 | # First lets figure out all of the files we may have to process ... do this only once! |
| 939 | # |
| 940 | elffiles = {} |
| 941 | symlinks = {} |
| 942 | kernmods = [] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 943 | staticlibs = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 944 | inodes = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 945 | libdir = os.path.abspath(dvar + os.sep + d.getVar("libdir")) |
| 946 | baselibdir = os.path.abspath(dvar + os.sep + d.getVar("base_libdir")) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 947 | skipfiles = (d.getVar("INHIBIT_PACKAGE_STRIP_FILES") or "").split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 948 | if (d.getVar('INHIBIT_PACKAGE_STRIP') != '1' or \ |
| 949 | d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 950 | checkelf = {} |
| 951 | checkelflinks = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 952 | for root, dirs, files in cpath.walk(dvar): |
| 953 | for f in files: |
| 954 | file = os.path.join(root, f) |
| 955 | if file.endswith(".ko") and file.find("/lib/modules/") != -1: |
| 956 | kernmods.append(file) |
| 957 | continue |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 958 | if oe.package.is_static_lib(file): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 959 | staticlibs.append(file) |
| 960 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 961 | |
| 962 | # Skip debug files |
| 963 | if debugappend and file.endswith(debugappend): |
| 964 | continue |
| 965 | if debugdir and debugdir in os.path.dirname(file[len(dvar):]): |
| 966 | continue |
| 967 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 968 | if file in skipfiles: |
| 969 | continue |
| 970 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 971 | try: |
| 972 | ltarget = cpath.realpath(file, dvar, False) |
| 973 | s = cpath.lstat(ltarget) |
| 974 | except OSError as e: |
| 975 | (err, strerror) = e.args |
| 976 | if err != errno.ENOENT: |
| 977 | raise |
| 978 | # Skip broken symlinks |
| 979 | continue |
| 980 | if not s: |
| 981 | continue |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 982 | # Check its an executable |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 983 | if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 984 | or ((file.startswith(libdir) or file.startswith(baselibdir)) and (".so" in f or ".node" in f)): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 985 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 986 | if cpath.islink(file): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 987 | checkelflinks[file] = ltarget |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 988 | continue |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 989 | # Use a reference of device ID and inode number to identify files |
| 990 | file_reference = "%d_%d" % (s.st_dev, s.st_ino) |
| 991 | checkelf[file] = (file, file_reference) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 992 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 993 | results = oe.utils.multiprocess_launch(oe.package.is_elf, checkelflinks.values(), d) |
| 994 | results_map = {} |
| 995 | for (ltarget, elf_file) in results: |
| 996 | results_map[ltarget] = elf_file |
| 997 | for file in checkelflinks: |
| 998 | ltarget = checkelflinks[file] |
| 999 | # If it's a symlink, and points to an ELF file, we capture the readlink target |
| 1000 | if results_map[ltarget]: |
| 1001 | target = os.readlink(file) |
| 1002 | #bb.note("Sym: %s (%d)" % (ltarget, results_map[ltarget])) |
| 1003 | symlinks[file] = target |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1004 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1005 | results = oe.utils.multiprocess_launch(oe.package.is_elf, checkelf.keys(), d) |
| 1006 | for (file, elf_file) in results: |
| 1007 | # It's a file (or hardlink), not a link |
| 1008 | # ...but is it ELF, and is it already stripped? |
| 1009 | if elf_file & 1: |
| 1010 | if elf_file & 2: |
| 1011 | if 'already-stripped' in (d.getVar('INSANE_SKIP_' + pn) or "").split(): |
| 1012 | bb.note("Skipping file %s from %s for already-stripped QA test" % (file[len(dvar):], pn)) |
| 1013 | else: |
| 1014 | msg = "File '%s' from %s was already stripped, this will prevent future debugging!" % (file[len(dvar):], pn) |
| 1015 | package_qa_handle_error("already-stripped", msg, d) |
| 1016 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1017 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1018 | # At this point we have an unstripped elf file. We need to: |
| 1019 | # a) Make sure any file we strip is not hardlinked to anything else outside this tree |
| 1020 | # b) Only strip any hardlinked file once (no races) |
| 1021 | # c) Track any hardlinks between files so that we can reconstruct matching debug file hardlinks |
| 1022 | |
| 1023 | # Use a reference of device ID and inode number to identify files |
| 1024 | file_reference = checkelf[file][1] |
| 1025 | if file_reference in inodes: |
| 1026 | os.unlink(file) |
| 1027 | os.link(inodes[file_reference][0], file) |
| 1028 | inodes[file_reference].append(file) |
| 1029 | else: |
| 1030 | inodes[file_reference] = [file] |
| 1031 | # break hardlink |
| 1032 | bb.utils.break_hardlinks(file) |
| 1033 | elffiles[file] = elf_file |
| 1034 | # Modified the file so clear the cache |
| 1035 | cpath.updatecache(file) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1036 | |
| 1037 | # |
| 1038 | # First lets process debug splitting |
| 1039 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1040 | if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1041 | oe.utils.multiprocess_launch(splitdebuginfo, list(elffiles), d, extraargs=(dvar, debugdir, debuglibdir, debugappend, debugsrcdir, sourcefile, d)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1042 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1043 | if debugsrcdir and not targetos.startswith("mingw"): |
| 1044 | for file in staticlibs: |
| 1045 | append_source_info(file, sourcefile, d, fatal=False) |
| 1046 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1047 | # Hardlink our debug symbols to the other hardlink copies |
| 1048 | for ref in inodes: |
| 1049 | if len(inodes[ref]) == 1: |
| 1050 | continue |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1051 | |
| 1052 | target = inodes[ref][0][len(dvar):] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1053 | for file in inodes[ref][1:]: |
| 1054 | src = file[len(dvar):] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1055 | dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(target) + debugappend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1056 | fpath = dvar + dest |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1057 | ftarget = dvar + debuglibdir + os.path.dirname(target) + debugdir + "/" + os.path.basename(target) + debugappend |
| 1058 | bb.utils.mkdirhier(os.path.dirname(fpath)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1059 | # Only one hardlink of separated debug info file in each directory |
| 1060 | if not os.access(fpath, os.R_OK): |
| 1061 | #bb.note("Link %s -> %s" % (fpath, ftarget)) |
| 1062 | os.link(ftarget, fpath) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1063 | |
| 1064 | # Create symlinks for all cases we were able to split symbols |
| 1065 | for file in symlinks: |
| 1066 | src = file[len(dvar):] |
| 1067 | dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend |
| 1068 | fpath = dvar + dest |
| 1069 | # Skip it if the target doesn't exist |
| 1070 | try: |
| 1071 | s = os.stat(fpath) |
| 1072 | except OSError as e: |
| 1073 | (err, strerror) = e.args |
| 1074 | if err != errno.ENOENT: |
| 1075 | raise |
| 1076 | continue |
| 1077 | |
| 1078 | ltarget = symlinks[file] |
| 1079 | lpath = os.path.dirname(ltarget) |
| 1080 | lbase = os.path.basename(ltarget) |
| 1081 | ftarget = "" |
| 1082 | if lpath and lpath != ".": |
| 1083 | ftarget += lpath + debugdir + "/" |
| 1084 | ftarget += lbase + debugappend |
| 1085 | if lpath.startswith(".."): |
| 1086 | ftarget = os.path.join("..", ftarget) |
| 1087 | bb.utils.mkdirhier(os.path.dirname(fpath)) |
| 1088 | #bb.note("Symlink %s -> %s" % (fpath, ftarget)) |
| 1089 | os.symlink(ftarget, fpath) |
| 1090 | |
| 1091 | # Process the debugsrcdir if requested... |
| 1092 | # This copies and places the referenced sources for later debugging... |
| 1093 | copydebugsources(debugsrcdir, d) |
| 1094 | # |
| 1095 | # End of debug splitting |
| 1096 | # |
| 1097 | |
| 1098 | # |
| 1099 | # Now lets go back over things and strip them |
| 1100 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1101 | if (d.getVar('INHIBIT_PACKAGE_STRIP') != '1'): |
| 1102 | strip = d.getVar("STRIP") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1103 | sfiles = [] |
| 1104 | for file in elffiles: |
| 1105 | elf_file = int(elffiles[file]) |
| 1106 | #bb.note("Strip %s" % file) |
| 1107 | sfiles.append((file, elf_file, strip)) |
| 1108 | for f in kernmods: |
| 1109 | sfiles.append((f, 16, strip)) |
| 1110 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1111 | oe.utils.multiprocess_launch(oe.package.runstrip, sfiles, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1112 | |
| 1113 | # |
| 1114 | # End of strip |
| 1115 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1116 | os.chdir(oldcwd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | python populate_packages () { |
| 1120 | import glob, re |
| 1121 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1122 | workdir = d.getVar('WORKDIR') |
| 1123 | outdir = d.getVar('DEPLOY_DIR') |
| 1124 | dvar = d.getVar('PKGD') |
| 1125 | packages = d.getVar('PACKAGES') |
| 1126 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1127 | |
| 1128 | bb.utils.mkdirhier(outdir) |
| 1129 | os.chdir(dvar) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1130 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1131 | autodebug = not (d.getVar("NOAUTOPACKAGEDEBUG") or False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1132 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1133 | split_source_package = (d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-with-srcpkg') |
| 1134 | |
| 1135 | # If debug-with-srcpkg mode is enabled then the src package is added |
| 1136 | # into the package list and the source directory as its main content |
| 1137 | if split_source_package: |
| 1138 | src_package_name = ('%s-src' % d.getVar('PN')) |
| 1139 | packages += (' ' + src_package_name) |
| 1140 | d.setVar('FILES_%s' % src_package_name, '/usr/src/debug') |
| 1141 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1142 | # Sanity check PACKAGES for duplicates |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1143 | # Sanity should be moved to sanity.bbclass once we have the infrastructure |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1144 | package_dict = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1145 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1146 | for i, pkg in enumerate(packages.split()): |
| 1147 | if pkg in package_dict: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1148 | msg = "%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg |
| 1149 | package_qa_handle_error("packages-list", msg, d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1150 | # If debug-with-srcpkg mode is enabled then the src package will have |
| 1151 | # priority over dbg package when assigning the files. |
| 1152 | # This allows src package to include source files and remove them from dbg. |
| 1153 | elif split_source_package and pkg.endswith("-src"): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1154 | package_dict[pkg] = (10, i) |
| 1155 | elif autodebug and pkg.endswith("-dbg"): |
| 1156 | package_dict[pkg] = (30, i) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1157 | else: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1158 | package_dict[pkg] = (50, i) |
| 1159 | package_list = sorted(package_dict.keys(), key=package_dict.get) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1160 | d.setVar('PACKAGES', ' '.join(package_list)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1161 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1162 | |
| 1163 | seen = [] |
| 1164 | |
| 1165 | # os.mkdir masks the permissions with umask so we have to unset it first |
| 1166 | oldumask = os.umask(0) |
| 1167 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1168 | debug = [] |
| 1169 | for root, dirs, files in cpath.walk(dvar): |
| 1170 | dir = root[len(dvar):] |
| 1171 | if not dir: |
| 1172 | dir = os.sep |
| 1173 | for f in (files + dirs): |
| 1174 | path = "." + os.path.join(dir, f) |
| 1175 | if "/.debug/" in path or path.endswith("/.debug"): |
| 1176 | debug.append(path) |
| 1177 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1178 | for pkg in package_list: |
| 1179 | root = os.path.join(pkgdest, pkg) |
| 1180 | bb.utils.mkdirhier(root) |
| 1181 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1182 | filesvar = d.getVar('FILES_%s' % pkg) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1183 | if "//" in filesvar: |
| 1184 | msg = "FILES variable for package %s contains '//' which is invalid. Attempting to fix this but you should correct the metadata.\n" % pkg |
| 1185 | package_qa_handle_error("files-invalid", msg, d) |
| 1186 | filesvar.replace("//", "/") |
| 1187 | |
| 1188 | origfiles = filesvar.split() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1189 | files, symlink_paths = files_from_filevars(origfiles) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1190 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1191 | if autodebug and pkg.endswith("-dbg"): |
| 1192 | files.extend(debug) |
| 1193 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1194 | for file in files: |
| 1195 | if (not cpath.islink(file)) and (not cpath.exists(file)): |
| 1196 | continue |
| 1197 | if file in seen: |
| 1198 | continue |
| 1199 | seen.append(file) |
| 1200 | |
| 1201 | def mkdir(src, dest, p): |
| 1202 | src = os.path.join(src, p) |
| 1203 | dest = os.path.join(dest, p) |
| 1204 | fstat = cpath.stat(src) |
| 1205 | os.mkdir(dest, fstat.st_mode) |
| 1206 | os.chown(dest, fstat.st_uid, fstat.st_gid) |
| 1207 | if p not in seen: |
| 1208 | seen.append(p) |
| 1209 | cpath.updatecache(dest) |
| 1210 | |
| 1211 | def mkdir_recurse(src, dest, paths): |
| 1212 | if cpath.exists(dest + '/' + paths): |
| 1213 | return |
| 1214 | while paths.startswith("./"): |
| 1215 | paths = paths[2:] |
| 1216 | p = "." |
| 1217 | for c in paths.split("/"): |
| 1218 | p = os.path.join(p, c) |
| 1219 | if not cpath.exists(os.path.join(dest, p)): |
| 1220 | mkdir(src, dest, p) |
| 1221 | |
| 1222 | if cpath.isdir(file) and not cpath.islink(file): |
| 1223 | mkdir_recurse(dvar, root, file) |
| 1224 | continue |
| 1225 | |
| 1226 | mkdir_recurse(dvar, root, os.path.dirname(file)) |
| 1227 | fpath = os.path.join(root,file) |
| 1228 | if not cpath.islink(file): |
| 1229 | os.link(file, fpath) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1230 | continue |
| 1231 | ret = bb.utils.copyfile(file, fpath) |
| 1232 | if ret is False or ret == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1233 | bb.fatal("File population failed") |
| 1234 | |
| 1235 | # Check if symlink paths exist |
| 1236 | for file in symlink_paths: |
| 1237 | if not os.path.exists(os.path.join(root,file)): |
| 1238 | bb.fatal("File '%s' cannot be packaged into '%s' because its " |
| 1239 | "parent directory structure does not exist. One of " |
| 1240 | "its parent directories is a symlink whose target " |
| 1241 | "directory is not included in the package." % |
| 1242 | (file, pkg)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1243 | |
| 1244 | os.umask(oldumask) |
| 1245 | os.chdir(workdir) |
| 1246 | |
| 1247 | # Handle LICENSE_EXCLUSION |
| 1248 | package_list = [] |
| 1249 | for pkg in packages.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1250 | if d.getVar('LICENSE_EXCLUSION-' + pkg): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1251 | msg = "%s has an incompatible license. Excluding from packaging." % pkg |
| 1252 | package_qa_handle_error("incompatible-license", msg, d) |
| 1253 | else: |
| 1254 | package_list.append(pkg) |
| 1255 | d.setVar('PACKAGES', ' '.join(package_list)) |
| 1256 | |
| 1257 | unshipped = [] |
| 1258 | for root, dirs, files in cpath.walk(dvar): |
| 1259 | dir = root[len(dvar):] |
| 1260 | if not dir: |
| 1261 | dir = os.sep |
| 1262 | for f in (files + dirs): |
| 1263 | path = os.path.join(dir, f) |
| 1264 | if ('.' + path) not in seen: |
| 1265 | unshipped.append(path) |
| 1266 | |
| 1267 | if unshipped != []: |
| 1268 | msg = pn + ": Files/directories were installed but not shipped in any package:" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1269 | if "installed-vs-shipped" in (d.getVar('INSANE_SKIP_' + pn) or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1270 | bb.note("Package %s skipping QA tests: installed-vs-shipped" % pn) |
| 1271 | else: |
| 1272 | for f in unshipped: |
| 1273 | msg = msg + "\n " + f |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1274 | msg = msg + "\nPlease set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.\n" |
| 1275 | msg = msg + "%s: %d installed and not shipped files." % (pn, len(unshipped)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1276 | package_qa_handle_error("installed-vs-shipped", msg, d) |
| 1277 | } |
| 1278 | populate_packages[dirs] = "${D}" |
| 1279 | |
| 1280 | python package_fixsymlinks () { |
| 1281 | import errno |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1282 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1283 | packages = d.getVar("PACKAGES", False).split() |
| 1284 | |
| 1285 | dangling_links = {} |
| 1286 | pkg_files = {} |
| 1287 | for pkg in packages: |
| 1288 | dangling_links[pkg] = [] |
| 1289 | pkg_files[pkg] = [] |
| 1290 | inst_root = os.path.join(pkgdest, pkg) |
| 1291 | for path in pkgfiles[pkg]: |
| 1292 | rpath = path[len(inst_root):] |
| 1293 | pkg_files[pkg].append(rpath) |
| 1294 | rtarget = cpath.realpath(path, inst_root, True, assume_dir = True) |
| 1295 | if not cpath.lexists(rtarget): |
| 1296 | dangling_links[pkg].append(os.path.normpath(rtarget[len(inst_root):])) |
| 1297 | |
| 1298 | newrdepends = {} |
| 1299 | for pkg in dangling_links: |
| 1300 | for l in dangling_links[pkg]: |
| 1301 | found = False |
| 1302 | bb.debug(1, "%s contains dangling link %s" % (pkg, l)) |
| 1303 | for p in packages: |
| 1304 | if l in pkg_files[p]: |
| 1305 | found = True |
| 1306 | bb.debug(1, "target found in %s" % p) |
| 1307 | if p == pkg: |
| 1308 | break |
| 1309 | if pkg not in newrdepends: |
| 1310 | newrdepends[pkg] = [] |
| 1311 | newrdepends[pkg].append(p) |
| 1312 | break |
| 1313 | if found == False: |
| 1314 | bb.note("%s contains dangling symlink to %s" % (pkg, l)) |
| 1315 | |
| 1316 | for pkg in newrdepends: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1317 | rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1318 | for p in newrdepends[pkg]: |
| 1319 | if p not in rdepends: |
| 1320 | rdepends[p] = [] |
| 1321 | d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False)) |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | python package_package_name_hook() { |
| 1326 | """ |
| 1327 | A package_name_hook function can be used to rewrite the package names by |
| 1328 | changing PKG. For an example, see debian.bbclass. |
| 1329 | """ |
| 1330 | pass |
| 1331 | } |
| 1332 | |
| 1333 | EXPORT_FUNCTIONS package_name_hook |
| 1334 | |
| 1335 | |
| 1336 | PKGDESTWORK = "${WORKDIR}/pkgdata" |
| 1337 | |
| 1338 | python emit_pkgdata() { |
| 1339 | from glob import glob |
| 1340 | import json |
| 1341 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1342 | def process_postinst_on_target(pkg, mlprefix): |
| 1343 | defer_fragment = """ |
| 1344 | if [ -n "$D" ]; then |
| 1345 | $INTERCEPT_DIR/postinst_intercept delay_to_first_boot %s mlprefix=%s |
| 1346 | exit 0 |
| 1347 | fi |
| 1348 | """ % (pkg, mlprefix) |
| 1349 | |
| 1350 | postinst = d.getVar('pkg_postinst_%s' % pkg) |
| 1351 | postinst_ontarget = d.getVar('pkg_postinst_ontarget_%s' % pkg) |
| 1352 | |
| 1353 | if postinst_ontarget: |
| 1354 | bb.debug(1, 'adding deferred pkg_postinst_ontarget() to pkg_postinst() for %s' % pkg) |
| 1355 | if not postinst: |
| 1356 | postinst = '#!/bin/sh\n' |
| 1357 | postinst += defer_fragment |
| 1358 | postinst += postinst_ontarget |
| 1359 | d.setVar('pkg_postinst_%s' % pkg, postinst) |
| 1360 | |
| 1361 | def add_set_e_to_scriptlets(pkg): |
| 1362 | for scriptlet_name in ('pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'): |
| 1363 | scriptlet = d.getVar('%s_%s' % (scriptlet_name, pkg)) |
| 1364 | if scriptlet: |
| 1365 | scriptlet_split = scriptlet.split('\n') |
| 1366 | if scriptlet_split[0].startswith("#!"): |
| 1367 | scriptlet = scriptlet_split[0] + "\nset -e\n" + "\n".join(scriptlet_split[1:]) |
| 1368 | else: |
| 1369 | scriptlet = "set -e\n" + "\n".join(scriptlet_split[0:]) |
| 1370 | d.setVar('%s_%s' % (scriptlet_name, pkg), scriptlet) |
| 1371 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1372 | def write_if_exists(f, pkg, var): |
| 1373 | def encode(str): |
| 1374 | import codecs |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1375 | c = codecs.getencoder("unicode_escape") |
| 1376 | return c(str)[0].decode("latin1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1377 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1378 | val = d.getVar('%s_%s' % (var, pkg)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1379 | if val: |
| 1380 | f.write('%s_%s: %s\n' % (var, pkg, encode(val))) |
| 1381 | return val |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1382 | val = d.getVar('%s' % (var)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1383 | if val: |
| 1384 | f.write('%s: %s\n' % (var, encode(val))) |
| 1385 | return val |
| 1386 | |
| 1387 | def write_extra_pkgs(variants, pn, packages, pkgdatadir): |
| 1388 | for variant in variants: |
| 1389 | with open("%s/%s-%s" % (pkgdatadir, variant, pn), 'w') as fd: |
| 1390 | fd.write("PACKAGES: %s\n" % ' '.join( |
| 1391 | map(lambda pkg: '%s-%s' % (variant, pkg), packages.split()))) |
| 1392 | |
| 1393 | def write_extra_runtime_pkgs(variants, packages, pkgdatadir): |
| 1394 | for variant in variants: |
| 1395 | for pkg in packages.split(): |
| 1396 | ml_pkg = "%s-%s" % (variant, pkg) |
| 1397 | subdata_file = "%s/runtime/%s" % (pkgdatadir, ml_pkg) |
| 1398 | with open(subdata_file, 'w') as fd: |
| 1399 | fd.write("PKG_%s: %s" % (ml_pkg, pkg)) |
| 1400 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1401 | packages = d.getVar('PACKAGES') |
| 1402 | pkgdest = d.getVar('PKGDEST') |
| 1403 | pkgdatadir = d.getVar('PKGDESTWORK') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1404 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1405 | data_file = pkgdatadir + d.expand("/${PN}" ) |
| 1406 | f = open(data_file, 'w') |
| 1407 | f.write("PACKAGES: %s\n" % packages) |
| 1408 | f.close() |
| 1409 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1410 | pn = d.getVar('PN') |
| 1411 | global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split() |
| 1412 | variants = (d.getVar('MULTILIB_VARIANTS') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1413 | |
| 1414 | if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): |
| 1415 | write_extra_pkgs(variants, pn, packages, pkgdatadir) |
| 1416 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1417 | if bb.data.inherits_class('allarch', d) and not variants \ |
| 1418 | and not bb.data.inherits_class('packagegroup', d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1419 | write_extra_pkgs(global_variants, pn, packages, pkgdatadir) |
| 1420 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1421 | workdir = d.getVar('WORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1422 | |
| 1423 | for pkg in packages.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1424 | pkgval = d.getVar('PKG_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1425 | if pkgval is None: |
| 1426 | pkgval = pkg |
| 1427 | d.setVar('PKG_%s' % pkg, pkg) |
| 1428 | |
| 1429 | pkgdestpkg = os.path.join(pkgdest, pkg) |
| 1430 | files = {} |
| 1431 | total_size = 0 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1432 | seen = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1433 | for f in pkgfiles[pkg]: |
| 1434 | relpth = os.path.relpath(f, pkgdestpkg) |
| 1435 | fstat = os.lstat(f) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1436 | files[os.sep + relpth] = fstat.st_size |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1437 | if fstat.st_ino not in seen: |
| 1438 | seen.add(fstat.st_ino) |
| 1439 | total_size += fstat.st_size |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1440 | d.setVar('FILES_INFO', json.dumps(files)) |
| 1441 | |
| 1442 | subdata_file = pkgdatadir + "/runtime/%s" % pkg |
| 1443 | sf = open(subdata_file, 'w') |
| 1444 | write_if_exists(sf, pkg, 'PN') |
| 1445 | write_if_exists(sf, pkg, 'PE') |
| 1446 | write_if_exists(sf, pkg, 'PV') |
| 1447 | write_if_exists(sf, pkg, 'PR') |
| 1448 | write_if_exists(sf, pkg, 'PKGE') |
| 1449 | write_if_exists(sf, pkg, 'PKGV') |
| 1450 | write_if_exists(sf, pkg, 'PKGR') |
| 1451 | write_if_exists(sf, pkg, 'LICENSE') |
| 1452 | write_if_exists(sf, pkg, 'DESCRIPTION') |
| 1453 | write_if_exists(sf, pkg, 'SUMMARY') |
| 1454 | write_if_exists(sf, pkg, 'RDEPENDS') |
| 1455 | rprov = write_if_exists(sf, pkg, 'RPROVIDES') |
| 1456 | write_if_exists(sf, pkg, 'RRECOMMENDS') |
| 1457 | write_if_exists(sf, pkg, 'RSUGGESTS') |
| 1458 | write_if_exists(sf, pkg, 'RREPLACES') |
| 1459 | write_if_exists(sf, pkg, 'RCONFLICTS') |
| 1460 | write_if_exists(sf, pkg, 'SECTION') |
| 1461 | write_if_exists(sf, pkg, 'PKG') |
| 1462 | write_if_exists(sf, pkg, 'ALLOW_EMPTY') |
| 1463 | write_if_exists(sf, pkg, 'FILES') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1464 | write_if_exists(sf, pkg, 'CONFFILES') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1465 | process_postinst_on_target(pkg, d.getVar("MLPREFIX")) |
| 1466 | add_set_e_to_scriptlets(pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1467 | write_if_exists(sf, pkg, 'pkg_postinst') |
| 1468 | write_if_exists(sf, pkg, 'pkg_postrm') |
| 1469 | write_if_exists(sf, pkg, 'pkg_preinst') |
| 1470 | write_if_exists(sf, pkg, 'pkg_prerm') |
| 1471 | write_if_exists(sf, pkg, 'FILERPROVIDESFLIST') |
| 1472 | write_if_exists(sf, pkg, 'FILES_INFO') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1473 | for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1474 | write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile) |
| 1475 | |
| 1476 | write_if_exists(sf, pkg, 'FILERDEPENDSFLIST') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1477 | for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1478 | write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile) |
| 1479 | |
| 1480 | sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size)) |
| 1481 | sf.close() |
| 1482 | |
| 1483 | # Symlinks needed for rprovides lookup |
| 1484 | if rprov: |
| 1485 | for p in rprov.strip().split(): |
| 1486 | subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg) |
| 1487 | bb.utils.mkdirhier(os.path.dirname(subdata_sym)) |
| 1488 | oe.path.symlink("../../runtime/%s" % pkg, subdata_sym, True) |
| 1489 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1490 | allow_empty = d.getVar('ALLOW_EMPTY_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1491 | if not allow_empty: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1492 | allow_empty = d.getVar('ALLOW_EMPTY') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1493 | root = "%s/%s" % (pkgdest, pkg) |
| 1494 | os.chdir(root) |
| 1495 | g = glob('*') |
| 1496 | if g or allow_empty == "1": |
| 1497 | # Symlinks needed for reverse lookups (from the final package name) |
| 1498 | subdata_sym = pkgdatadir + "/runtime-reverse/%s" % pkgval |
| 1499 | oe.path.symlink("../runtime/%s" % pkg, subdata_sym, True) |
| 1500 | |
| 1501 | packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg |
| 1502 | open(packagedfile, 'w').close() |
| 1503 | |
| 1504 | if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): |
| 1505 | write_extra_runtime_pkgs(variants, packages, pkgdatadir) |
| 1506 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1507 | if bb.data.inherits_class('allarch', d) and not variants \ |
| 1508 | and not bb.data.inherits_class('packagegroup', d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1509 | write_extra_runtime_pkgs(global_variants, packages, pkgdatadir) |
| 1510 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1511 | } |
| 1512 | emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse ${PKGDESTWORK}/runtime-rprovides" |
| 1513 | |
| 1514 | ldconfig_postinst_fragment() { |
| 1515 | if [ x"$D" = "x" ]; then |
| 1516 | if [ -x /sbin/ldconfig ]; then /sbin/ldconfig ; fi |
| 1517 | fi |
| 1518 | } |
| 1519 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1520 | RPMDEPS = "${STAGING_LIBDIR_NATIVE}/rpm/rpmdeps --alldeps" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1521 | |
| 1522 | # Collect perfile run-time dependency metadata |
| 1523 | # Output: |
| 1524 | # FILERPROVIDESFLIST_pkg - list of all files w/ deps |
| 1525 | # FILERPROVIDES_filepath_pkg - per file dep |
| 1526 | # |
| 1527 | # FILERDEPENDSFLIST_pkg - list of all files w/ deps |
| 1528 | # FILERDEPENDS_filepath_pkg - per file dep |
| 1529 | |
| 1530 | python package_do_filedeps() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1531 | if d.getVar('SKIP_FILEDEPS') == '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1532 | return |
| 1533 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1534 | pkgdest = d.getVar('PKGDEST') |
| 1535 | packages = d.getVar('PACKAGES') |
| 1536 | rpmdeps = d.getVar('RPMDEPS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1537 | |
| 1538 | def chunks(files, n): |
| 1539 | return [files[i:i+n] for i in range(0, len(files), n)] |
| 1540 | |
| 1541 | pkglist = [] |
| 1542 | for pkg in packages.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1543 | if d.getVar('SKIP_FILEDEPS_' + pkg) == '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1544 | continue |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1545 | if pkg.endswith('-dbg') or pkg.endswith('-doc') or pkg.find('-locale-') != -1 or pkg.find('-localedata-') != -1 or pkg.find('-gconv-') != -1 or pkg.find('-charmap-') != -1 or pkg.startswith('kernel-module-') or pkg.endswith('-src'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1546 | continue |
| 1547 | for files in chunks(pkgfiles[pkg], 100): |
| 1548 | pkglist.append((pkg, files, rpmdeps, pkgdest)) |
| 1549 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1550 | processed = oe.utils.multiprocess_launch(oe.package.filedeprunner, pkglist, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1551 | |
| 1552 | provides_files = {} |
| 1553 | requires_files = {} |
| 1554 | |
| 1555 | for result in processed: |
| 1556 | (pkg, provides, requires) = result |
| 1557 | |
| 1558 | if pkg not in provides_files: |
| 1559 | provides_files[pkg] = [] |
| 1560 | if pkg not in requires_files: |
| 1561 | requires_files[pkg] = [] |
| 1562 | |
| 1563 | for file in provides: |
| 1564 | provides_files[pkg].append(file) |
| 1565 | key = "FILERPROVIDES_" + file + "_" + pkg |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1566 | d.appendVar(key, " " + " ".join(provides[file])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1567 | |
| 1568 | for file in requires: |
| 1569 | requires_files[pkg].append(file) |
| 1570 | key = "FILERDEPENDS_" + file + "_" + pkg |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1571 | d.appendVar(key, " " + " ".join(requires[file])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1572 | |
| 1573 | for pkg in requires_files: |
| 1574 | d.setVar("FILERDEPENDSFLIST_" + pkg, " ".join(requires_files[pkg])) |
| 1575 | for pkg in provides_files: |
| 1576 | d.setVar("FILERPROVIDESFLIST_" + pkg, " ".join(provides_files[pkg])) |
| 1577 | } |
| 1578 | |
| 1579 | SHLIBSDIRS = "${PKGDATA_DIR}/${MLPREFIX}shlibs2" |
| 1580 | SHLIBSWORKDIR = "${PKGDESTWORK}/${MLPREFIX}shlibs2" |
| 1581 | |
| 1582 | python package_do_shlibs() { |
| 1583 | import re, pipes |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1584 | import subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1585 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1586 | exclude_shlibs = d.getVar('EXCLUDE_FROM_SHLIBS', False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1587 | if exclude_shlibs: |
| 1588 | bb.note("not generating shlibs") |
| 1589 | return |
| 1590 | |
| 1591 | lib_re = re.compile("^.*\.so") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1592 | libdir_re = re.compile(".*/%s$" % d.getVar('baselib')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1593 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1594 | packages = d.getVar('PACKAGES') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1595 | |
| 1596 | shlib_pkgs = [] |
| 1597 | exclusion_list = d.getVar("EXCLUDE_PACKAGES_FROM_SHLIBS") |
| 1598 | if exclusion_list: |
| 1599 | for pkg in packages.split(): |
| 1600 | if pkg not in exclusion_list.split(): |
| 1601 | shlib_pkgs.append(pkg) |
| 1602 | else: |
| 1603 | bb.note("not generating shlibs for %s" % pkg) |
| 1604 | else: |
| 1605 | shlib_pkgs = packages.split() |
| 1606 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1607 | targetos = d.getVar('TARGET_OS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1608 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1609 | workdir = d.getVar('WORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1610 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1611 | ver = d.getVar('PKGV') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1612 | if not ver: |
| 1613 | msg = "PKGV not defined" |
| 1614 | package_qa_handle_error("pkgv-undefined", msg, d) |
| 1615 | return |
| 1616 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1617 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1618 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1619 | shlibswork_dir = d.getVar('SHLIBSWORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1620 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1621 | def linux_so(file, pkg, pkgver, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1622 | needs_ldconfig = False |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1623 | needed = set() |
| 1624 | sonames = set() |
| 1625 | renames = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1626 | ldir = os.path.dirname(file).replace(pkgdest + "/" + pkg, '') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1627 | cmd = d.getVar('OBJDUMP') + " -p " + pipes.quote(file) + " 2>/dev/null" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1628 | fd = os.popen(cmd) |
| 1629 | lines = fd.readlines() |
| 1630 | fd.close() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1631 | rpath = tuple() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1632 | for l in lines: |
| 1633 | m = re.match("\s+RPATH\s+([^\s]*)", l) |
| 1634 | if m: |
| 1635 | rpaths = m.group(1).replace("$ORIGIN", ldir).split(":") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1636 | rpath = tuple(map(os.path.normpath, rpaths)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1637 | for l in lines: |
| 1638 | m = re.match("\s+NEEDED\s+([^\s]*)", l) |
| 1639 | if m: |
| 1640 | dep = m.group(1) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1641 | if dep not in needed: |
| 1642 | needed.add((dep, file, rpath)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1643 | m = re.match("\s+SONAME\s+([^\s]*)", l) |
| 1644 | if m: |
| 1645 | this_soname = m.group(1) |
| 1646 | prov = (this_soname, ldir, pkgver) |
| 1647 | if not prov in sonames: |
| 1648 | # if library is private (only used by package) then do not build shlib for it |
| 1649 | if not private_libs or this_soname not in private_libs: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1650 | sonames.add(prov) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1651 | if libdir_re.match(os.path.dirname(file)): |
| 1652 | needs_ldconfig = True |
| 1653 | if snap_symlinks and (os.path.basename(file) != this_soname): |
| 1654 | renames.append((file, os.path.join(os.path.dirname(file), this_soname))) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1655 | return (needs_ldconfig, needed, sonames, renames) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1656 | |
| 1657 | def darwin_so(file, needed, sonames, renames, pkgver): |
| 1658 | if not os.path.exists(file): |
| 1659 | return |
| 1660 | ldir = os.path.dirname(file).replace(pkgdest + "/" + pkg, '') |
| 1661 | |
| 1662 | def get_combinations(base): |
| 1663 | # |
| 1664 | # Given a base library name, find all combinations of this split by "." and "-" |
| 1665 | # |
| 1666 | combos = [] |
| 1667 | options = base.split(".") |
| 1668 | for i in range(1, len(options) + 1): |
| 1669 | combos.append(".".join(options[0:i])) |
| 1670 | options = base.split("-") |
| 1671 | for i in range(1, len(options) + 1): |
| 1672 | combos.append("-".join(options[0:i])) |
| 1673 | return combos |
| 1674 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1675 | if (file.endswith('.dylib') or file.endswith('.so')) and not pkg.endswith('-dev') and not pkg.endswith('-dbg') and not pkg.endswith('-src'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1676 | # Drop suffix |
| 1677 | name = os.path.basename(file).rsplit(".",1)[0] |
| 1678 | # Find all combinations |
| 1679 | combos = get_combinations(name) |
| 1680 | for combo in combos: |
| 1681 | if not combo in sonames: |
| 1682 | prov = (combo, ldir, pkgver) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1683 | sonames.add(prov) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1684 | if file.endswith('.dylib') or file.endswith('.so'): |
| 1685 | rpath = [] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1686 | p = subprocess.Popen([d.expand("${HOST_PREFIX}otool"), '-l', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1687 | out, err = p.communicate() |
| 1688 | # If returned successfully, process stdout for results |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1689 | if p.returncode == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1690 | for l in out.split("\n"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1691 | l = l.strip() |
| 1692 | if l.startswith('path '): |
| 1693 | rpath.append(l.split()[1]) |
| 1694 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1695 | p = subprocess.Popen([d.expand("${HOST_PREFIX}otool"), '-L', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1696 | out, err = p.communicate() |
| 1697 | # If returned successfully, process stdout for results |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1698 | if p.returncode == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1699 | for l in out.split("\n"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1700 | l = l.strip() |
| 1701 | if not l or l.endswith(":"): |
| 1702 | continue |
| 1703 | if "is not an object file" in l: |
| 1704 | continue |
| 1705 | name = os.path.basename(l.split()[0]).rsplit(".", 1)[0] |
| 1706 | if name and name not in needed[pkg]: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1707 | needed[pkg].add((name, file, tuple())) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1708 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1709 | def mingw_dll(file, needed, sonames, renames, pkgver): |
| 1710 | if not os.path.exists(file): |
| 1711 | return |
| 1712 | |
| 1713 | if file.endswith(".dll"): |
| 1714 | # assume all dlls are shared objects provided by the package |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1715 | sonames.add((os.path.basename(file), os.path.dirname(file).replace(pkgdest + "/" + pkg, ''), pkgver)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1716 | |
| 1717 | if (file.endswith(".dll") or file.endswith(".exe")): |
| 1718 | # use objdump to search for "DLL Name: .*\.dll" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1719 | p = subprocess.Popen([d.expand("${HOST_PREFIX}objdump"), "-p", file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1720 | out, err = p.communicate() |
| 1721 | # process the output, grabbing all .dll names |
| 1722 | if p.returncode == 0: |
| 1723 | for m in re.finditer("DLL Name: (.*?\.dll)$", out.decode(), re.MULTILINE | re.IGNORECASE): |
| 1724 | dllname = m.group(1) |
| 1725 | if dllname: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1726 | needed[pkg].add((dllname, file, tuple())) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1727 | |
| 1728 | if d.getVar('PACKAGE_SNAP_LIB_SYMLINKS') == "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1729 | snap_symlinks = True |
| 1730 | else: |
| 1731 | snap_symlinks = False |
| 1732 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1733 | use_ldconfig = bb.utils.contains('DISTRO_FEATURES', 'ldconfig', True, False, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1734 | |
| 1735 | needed = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1736 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1737 | # Take shared lock since we're only reading, not writing |
| 1738 | lf = bb.utils.lockfile(d.expand("${PACKAGELOCK}"), True) |
| 1739 | shlib_provider = oe.package.read_shlib_providers(d) |
| 1740 | bb.utils.unlockfile(lf) |
| 1741 | |
| 1742 | for pkg in shlib_pkgs: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1743 | private_libs = d.getVar('PRIVATE_LIBS_' + pkg) or d.getVar('PRIVATE_LIBS') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1744 | private_libs = private_libs.split() |
| 1745 | needs_ldconfig = False |
| 1746 | bb.debug(2, "calculating shlib provides for %s" % pkg) |
| 1747 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1748 | pkgver = d.getVar('PKGV_' + pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1749 | if not pkgver: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1750 | pkgver = d.getVar('PV_' + pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1751 | if not pkgver: |
| 1752 | pkgver = ver |
| 1753 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1754 | needed[pkg] = set() |
| 1755 | sonames = set() |
| 1756 | renames = [] |
| 1757 | linuxlist = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1758 | for file in pkgfiles[pkg]: |
| 1759 | soname = None |
| 1760 | if cpath.islink(file): |
| 1761 | continue |
| 1762 | if targetos == "darwin" or targetos == "darwin8": |
| 1763 | darwin_so(file, needed, sonames, renames, pkgver) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1764 | elif targetos.startswith("mingw"): |
| 1765 | mingw_dll(file, needed, sonames, renames, pkgver) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1766 | elif os.access(file, os.X_OK) or lib_re.match(file): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1767 | linuxlist.append(file) |
| 1768 | |
| 1769 | if linuxlist: |
| 1770 | results = oe.utils.multiprocess_launch(linux_so, linuxlist, d, extraargs=(pkg, pkgver, d)) |
| 1771 | for r in results: |
| 1772 | ldconfig = r[0] |
| 1773 | needed[pkg] |= r[1] |
| 1774 | sonames |= r[2] |
| 1775 | renames.extend(r[3]) |
| 1776 | needs_ldconfig = needs_ldconfig or ldconfig |
| 1777 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1778 | for (old, new) in renames: |
| 1779 | bb.note("Renaming %s to %s" % (old, new)) |
| 1780 | os.rename(old, new) |
| 1781 | pkgfiles[pkg].remove(old) |
| 1782 | |
| 1783 | shlibs_file = os.path.join(shlibswork_dir, pkg + ".list") |
| 1784 | if len(sonames): |
| 1785 | fd = open(shlibs_file, 'w') |
| 1786 | for s in sonames: |
| 1787 | if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]: |
| 1788 | (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]] |
| 1789 | if old_pkg != pkg: |
| 1790 | bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver)) |
| 1791 | bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0])) |
| 1792 | fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n') |
| 1793 | if s[0] not in shlib_provider: |
| 1794 | shlib_provider[s[0]] = {} |
| 1795 | shlib_provider[s[0]][s[1]] = (pkg, pkgver) |
| 1796 | fd.close() |
| 1797 | if needs_ldconfig and use_ldconfig: |
| 1798 | bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1799 | postinst = d.getVar('pkg_postinst_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1800 | if not postinst: |
| 1801 | postinst = '#!/bin/sh\n' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1802 | postinst += d.getVar('ldconfig_postinst_fragment') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1803 | d.setVar('pkg_postinst_%s' % pkg, postinst) |
| 1804 | bb.debug(1, 'LIBNAMES: pkg %s sonames %s' % (pkg, sonames)) |
| 1805 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1806 | assumed_libs = d.getVar('ASSUME_SHLIBS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1807 | if assumed_libs: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1808 | libdir = d.getVar("libdir") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1809 | for e in assumed_libs.split(): |
| 1810 | l, dep_pkg = e.split(":") |
| 1811 | lib_ver = None |
| 1812 | dep_pkg = dep_pkg.rsplit("_", 1) |
| 1813 | if len(dep_pkg) == 2: |
| 1814 | lib_ver = dep_pkg[1] |
| 1815 | dep_pkg = dep_pkg[0] |
| 1816 | if l not in shlib_provider: |
| 1817 | shlib_provider[l] = {} |
| 1818 | shlib_provider[l][libdir] = (dep_pkg, lib_ver) |
| 1819 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1820 | libsearchpath = [d.getVar('libdir'), d.getVar('base_libdir')] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1821 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1822 | for pkg in shlib_pkgs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1823 | bb.debug(2, "calculating shlib requirements for %s" % pkg) |
| 1824 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1825 | private_libs = d.getVar('PRIVATE_LIBS_' + pkg) or d.getVar('PRIVATE_LIBS') or "" |
| 1826 | private_libs = private_libs.split() |
| 1827 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1828 | deps = list() |
| 1829 | for n in needed[pkg]: |
| 1830 | # if n is in private libraries, don't try to search provider for it |
| 1831 | # this could cause problem in case some abc.bb provides private |
| 1832 | # /opt/abc/lib/libfoo.so.1 and contains /usr/bin/abc depending on system library libfoo.so.1 |
| 1833 | # but skipping it is still better alternative than providing own |
| 1834 | # version and then adding runtime dependency for the same system library |
| 1835 | if private_libs and n[0] in private_libs: |
| 1836 | bb.debug(2, '%s: Dependency %s covered by PRIVATE_LIBS' % (pkg, n[0])) |
| 1837 | continue |
| 1838 | if n[0] in shlib_provider.keys(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1839 | shlib_provider_path = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1840 | for k in shlib_provider[n[0]].keys(): |
| 1841 | shlib_provider_path.append(k) |
| 1842 | match = None |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1843 | for p in list(n[2]) + shlib_provider_path + libsearchpath: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1844 | if p in shlib_provider[n[0]]: |
| 1845 | match = p |
| 1846 | break |
| 1847 | if match: |
| 1848 | (dep_pkg, ver_needed) = shlib_provider[n[0]][match] |
| 1849 | |
| 1850 | bb.debug(2, '%s: Dependency %s requires package %s (used by files: %s)' % (pkg, n[0], dep_pkg, n[1])) |
| 1851 | |
| 1852 | if dep_pkg == pkg: |
| 1853 | continue |
| 1854 | |
| 1855 | if ver_needed: |
| 1856 | dep = "%s (>= %s)" % (dep_pkg, ver_needed) |
| 1857 | else: |
| 1858 | dep = dep_pkg |
| 1859 | if not dep in deps: |
| 1860 | deps.append(dep) |
| 1861 | continue |
| 1862 | bb.note("Couldn't find shared library provider for %s, used by files: %s" % (n[0], n[1])) |
| 1863 | |
| 1864 | deps_file = os.path.join(pkgdest, pkg + ".shlibdeps") |
| 1865 | if os.path.exists(deps_file): |
| 1866 | os.remove(deps_file) |
| 1867 | if len(deps): |
| 1868 | fd = open(deps_file, 'w') |
| 1869 | for dep in deps: |
| 1870 | fd.write(dep + '\n') |
| 1871 | fd.close() |
| 1872 | } |
| 1873 | |
| 1874 | python package_do_pkgconfig () { |
| 1875 | import re |
| 1876 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1877 | packages = d.getVar('PACKAGES') |
| 1878 | workdir = d.getVar('WORKDIR') |
| 1879 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1880 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1881 | shlibs_dirs = d.getVar('SHLIBSDIRS').split() |
| 1882 | shlibswork_dir = d.getVar('SHLIBSWORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1883 | |
| 1884 | pc_re = re.compile('(.*)\.pc$') |
| 1885 | var_re = re.compile('(.*)=(.*)') |
| 1886 | field_re = re.compile('(.*): (.*)') |
| 1887 | |
| 1888 | pkgconfig_provided = {} |
| 1889 | pkgconfig_needed = {} |
| 1890 | for pkg in packages.split(): |
| 1891 | pkgconfig_provided[pkg] = [] |
| 1892 | pkgconfig_needed[pkg] = [] |
| 1893 | for file in pkgfiles[pkg]: |
| 1894 | m = pc_re.match(file) |
| 1895 | if m: |
| 1896 | pd = bb.data.init() |
| 1897 | name = m.group(1) |
| 1898 | pkgconfig_provided[pkg].append(name) |
| 1899 | if not os.access(file, os.R_OK): |
| 1900 | continue |
| 1901 | f = open(file, 'r') |
| 1902 | lines = f.readlines() |
| 1903 | f.close() |
| 1904 | for l in lines: |
| 1905 | m = var_re.match(l) |
| 1906 | if m: |
| 1907 | name = m.group(1) |
| 1908 | val = m.group(2) |
| 1909 | pd.setVar(name, pd.expand(val)) |
| 1910 | continue |
| 1911 | m = field_re.match(l) |
| 1912 | if m: |
| 1913 | hdr = m.group(1) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1914 | exp = pd.expand(m.group(2)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1915 | if hdr == 'Requires': |
| 1916 | pkgconfig_needed[pkg] += exp.replace(',', ' ').split() |
| 1917 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1918 | for pkg in packages.split(): |
| 1919 | pkgs_file = os.path.join(shlibswork_dir, pkg + ".pclist") |
| 1920 | if pkgconfig_provided[pkg] != []: |
| 1921 | f = open(pkgs_file, 'w') |
| 1922 | for p in pkgconfig_provided[pkg]: |
| 1923 | f.write('%s\n' % p) |
| 1924 | f.close() |
| 1925 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1926 | # Take shared lock since we're only reading, not writing |
| 1927 | lf = bb.utils.lockfile(d.expand("${PACKAGELOCK}"), True) |
| 1928 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1929 | # Go from least to most specific since the last one found wins |
| 1930 | for dir in reversed(shlibs_dirs): |
| 1931 | if not os.path.exists(dir): |
| 1932 | continue |
| 1933 | for file in os.listdir(dir): |
| 1934 | m = re.match('^(.*)\.pclist$', file) |
| 1935 | if m: |
| 1936 | pkg = m.group(1) |
| 1937 | fd = open(os.path.join(dir, file)) |
| 1938 | lines = fd.readlines() |
| 1939 | fd.close() |
| 1940 | pkgconfig_provided[pkg] = [] |
| 1941 | for l in lines: |
| 1942 | pkgconfig_provided[pkg].append(l.rstrip()) |
| 1943 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1944 | bb.utils.unlockfile(lf) |
| 1945 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1946 | for pkg in packages.split(): |
| 1947 | deps = [] |
| 1948 | for n in pkgconfig_needed[pkg]: |
| 1949 | found = False |
| 1950 | for k in pkgconfig_provided.keys(): |
| 1951 | if n in pkgconfig_provided[k]: |
| 1952 | if k != pkg and not (k in deps): |
| 1953 | deps.append(k) |
| 1954 | found = True |
| 1955 | if found == False: |
| 1956 | bb.note("couldn't find pkgconfig module '%s' in any package" % n) |
| 1957 | deps_file = os.path.join(pkgdest, pkg + ".pcdeps") |
| 1958 | if len(deps): |
| 1959 | fd = open(deps_file, 'w') |
| 1960 | for dep in deps: |
| 1961 | fd.write(dep + '\n') |
| 1962 | fd.close() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | def read_libdep_files(d): |
| 1966 | pkglibdeps = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1967 | packages = d.getVar('PACKAGES').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1968 | for pkg in packages: |
| 1969 | pkglibdeps[pkg] = {} |
| 1970 | for extension in ".shlibdeps", ".pcdeps", ".clilibdeps": |
| 1971 | depsfile = d.expand("${PKGDEST}/" + pkg + extension) |
| 1972 | if os.access(depsfile, os.R_OK): |
| 1973 | fd = open(depsfile) |
| 1974 | lines = fd.readlines() |
| 1975 | fd.close() |
| 1976 | for l in lines: |
| 1977 | l.rstrip() |
| 1978 | deps = bb.utils.explode_dep_versions2(l) |
| 1979 | for dep in deps: |
| 1980 | if not dep in pkglibdeps[pkg]: |
| 1981 | pkglibdeps[pkg][dep] = deps[dep] |
| 1982 | return pkglibdeps |
| 1983 | |
| 1984 | python read_shlibdeps () { |
| 1985 | pkglibdeps = read_libdep_files(d) |
| 1986 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1987 | packages = d.getVar('PACKAGES').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1988 | for pkg in packages: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1989 | rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1990 | for dep in pkglibdeps[pkg]: |
| 1991 | # Add the dep if it's not already there, or if no comparison is set |
| 1992 | if dep not in rdepends: |
| 1993 | rdepends[dep] = [] |
| 1994 | for v in pkglibdeps[pkg][dep]: |
| 1995 | if v not in rdepends[dep]: |
| 1996 | rdepends[dep].append(v) |
| 1997 | d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False)) |
| 1998 | } |
| 1999 | |
| 2000 | python package_depchains() { |
| 2001 | """ |
| 2002 | For a given set of prefix and postfix modifiers, make those packages |
| 2003 | RRECOMMENDS on the corresponding packages for its RDEPENDS. |
| 2004 | |
| 2005 | Example: If package A depends upon package B, and A's .bb emits an |
| 2006 | A-dev package, this would make A-dev Recommends: B-dev. |
| 2007 | |
| 2008 | If only one of a given suffix is specified, it will take the RRECOMMENDS |
| 2009 | based on the RDEPENDS of *all* other packages. If more than one of a given |
| 2010 | suffix is specified, its will only use the RDEPENDS of the single parent |
| 2011 | package. |
| 2012 | """ |
| 2013 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2014 | packages = d.getVar('PACKAGES') |
| 2015 | postfixes = (d.getVar('DEPCHAIN_POST') or '').split() |
| 2016 | prefixes = (d.getVar('DEPCHAIN_PRE') or '').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2017 | |
| 2018 | def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d): |
| 2019 | |
| 2020 | #bb.note('depends for %s is %s' % (base, depends)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2021 | rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg) or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2022 | |
| 2023 | for depend in depends: |
| 2024 | if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'): |
| 2025 | #bb.note("Skipping %s" % depend) |
| 2026 | continue |
| 2027 | if depend.endswith('-dev'): |
| 2028 | depend = depend[:-4] |
| 2029 | if depend.endswith('-dbg'): |
| 2030 | depend = depend[:-4] |
| 2031 | pkgname = getname(depend, suffix) |
| 2032 | #bb.note("Adding %s for %s" % (pkgname, depend)) |
| 2033 | if pkgname not in rreclist and pkgname != pkg: |
| 2034 | rreclist[pkgname] = [] |
| 2035 | |
| 2036 | #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist))) |
| 2037 | d.setVar('RRECOMMENDS_%s' % pkg, bb.utils.join_deps(rreclist, commasep=False)) |
| 2038 | |
| 2039 | def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d): |
| 2040 | |
| 2041 | #bb.note('rdepends for %s is %s' % (base, rdepends)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2042 | rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg) or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2043 | |
| 2044 | for depend in rdepends: |
| 2045 | if depend.find('virtual-locale-') != -1: |
| 2046 | #bb.note("Skipping %s" % depend) |
| 2047 | continue |
| 2048 | if depend.endswith('-dev'): |
| 2049 | depend = depend[:-4] |
| 2050 | if depend.endswith('-dbg'): |
| 2051 | depend = depend[:-4] |
| 2052 | pkgname = getname(depend, suffix) |
| 2053 | #bb.note("Adding %s for %s" % (pkgname, depend)) |
| 2054 | if pkgname not in rreclist and pkgname != pkg: |
| 2055 | rreclist[pkgname] = [] |
| 2056 | |
| 2057 | #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist))) |
| 2058 | d.setVar('RRECOMMENDS_%s' % pkg, bb.utils.join_deps(rreclist, commasep=False)) |
| 2059 | |
| 2060 | def add_dep(list, dep): |
| 2061 | if dep not in list: |
| 2062 | list.append(dep) |
| 2063 | |
| 2064 | depends = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2065 | for dep in bb.utils.explode_deps(d.getVar('DEPENDS') or ""): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2066 | add_dep(depends, dep) |
| 2067 | |
| 2068 | rdepends = [] |
| 2069 | for pkg in packages.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2070 | for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + pkg) or ""): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2071 | add_dep(rdepends, dep) |
| 2072 | |
| 2073 | #bb.note('rdepends is %s' % rdepends) |
| 2074 | |
| 2075 | def post_getname(name, suffix): |
| 2076 | return '%s%s' % (name, suffix) |
| 2077 | def pre_getname(name, suffix): |
| 2078 | return '%s%s' % (suffix, name) |
| 2079 | |
| 2080 | pkgs = {} |
| 2081 | for pkg in packages.split(): |
| 2082 | for postfix in postfixes: |
| 2083 | if pkg.endswith(postfix): |
| 2084 | if not postfix in pkgs: |
| 2085 | pkgs[postfix] = {} |
| 2086 | pkgs[postfix][pkg] = (pkg[:-len(postfix)], post_getname) |
| 2087 | |
| 2088 | for prefix in prefixes: |
| 2089 | if pkg.startswith(prefix): |
| 2090 | if not prefix in pkgs: |
| 2091 | pkgs[prefix] = {} |
| 2092 | pkgs[prefix][pkg] = (pkg[:-len(prefix)], pre_getname) |
| 2093 | |
| 2094 | if "-dbg" in pkgs: |
| 2095 | pkglibdeps = read_libdep_files(d) |
| 2096 | pkglibdeplist = [] |
| 2097 | for pkg in pkglibdeps: |
| 2098 | for k in pkglibdeps[pkg]: |
| 2099 | add_dep(pkglibdeplist, k) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2100 | dbgdefaultdeps = ((d.getVar('DEPCHAIN_DBGDEFAULTDEPS') == '1') or (bb.data.inherits_class('packagegroup', d))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2101 | |
| 2102 | for suffix in pkgs: |
| 2103 | for pkg in pkgs[suffix]: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2104 | if d.getVarFlag('RRECOMMENDS_' + pkg, 'nodeprrecs'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2105 | continue |
| 2106 | (base, func) = pkgs[suffix][pkg] |
| 2107 | if suffix == "-dev": |
| 2108 | pkg_adddeprrecs(pkg, base, suffix, func, depends, d) |
| 2109 | elif suffix == "-dbg": |
| 2110 | if not dbgdefaultdeps: |
| 2111 | pkg_addrrecs(pkg, base, suffix, func, pkglibdeplist, d) |
| 2112 | continue |
| 2113 | if len(pkgs[suffix]) == 1: |
| 2114 | pkg_addrrecs(pkg, base, suffix, func, rdepends, d) |
| 2115 | else: |
| 2116 | rdeps = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2117 | for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + base) or ""): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2118 | add_dep(rdeps, dep) |
| 2119 | pkg_addrrecs(pkg, base, suffix, func, rdeps, d) |
| 2120 | } |
| 2121 | |
| 2122 | # Since bitbake can't determine which variables are accessed during package |
| 2123 | # iteration, we need to list them here: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2124 | PACKAGEVARS = "FILES RDEPENDS RRECOMMENDS SUMMARY DESCRIPTION RSUGGESTS RPROVIDES RCONFLICTS PKG ALLOW_EMPTY pkg_postinst pkg_postrm INITSCRIPT_NAME INITSCRIPT_PARAMS DEBIAN_NOAUTONAME ALTERNATIVE PKGE PKGV PKGR USERADD_PARAM GROUPADD_PARAM CONFFILES SYSTEMD_SERVICE LICENSE SECTION pkg_preinst pkg_prerm RREPLACES GROUPMEMS_PARAM SYSTEMD_AUTO_ENABLE SKIP_FILEDEPS PRIVATE_LIBS" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2125 | |
| 2126 | def gen_packagevar(d): |
| 2127 | ret = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2128 | pkgs = (d.getVar("PACKAGES") or "").split() |
| 2129 | vars = (d.getVar("PACKAGEVARS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2130 | for p in pkgs: |
| 2131 | for v in vars: |
| 2132 | ret.append(v + "_" + p) |
| 2133 | |
| 2134 | # Ensure that changes to INCOMPATIBLE_LICENSE re-run do_package for |
| 2135 | # affected recipes. |
| 2136 | ret.append('LICENSE_EXCLUSION-%s' % p) |
| 2137 | return " ".join(ret) |
| 2138 | |
| 2139 | PACKAGE_PREPROCESS_FUNCS ?= "" |
| 2140 | # Functions for setting up PKGD |
| 2141 | PACKAGEBUILDPKGD ?= " \ |
| 2142 | perform_packagecopy \ |
| 2143 | ${PACKAGE_PREPROCESS_FUNCS} \ |
| 2144 | split_and_strip_files \ |
| 2145 | fixup_perms \ |
| 2146 | " |
| 2147 | # Functions which split PKGD up into separate packages |
| 2148 | PACKAGESPLITFUNCS ?= " \ |
| 2149 | package_do_split_locales \ |
| 2150 | populate_packages" |
| 2151 | # Functions which process metadata based on split packages |
| 2152 | PACKAGEFUNCS += " \ |
| 2153 | package_fixsymlinks \ |
| 2154 | package_name_hook \ |
| 2155 | package_do_filedeps \ |
| 2156 | package_do_shlibs \ |
| 2157 | package_do_pkgconfig \ |
| 2158 | read_shlibdeps \ |
| 2159 | package_depchains \ |
| 2160 | emit_pkgdata" |
| 2161 | |
| 2162 | python do_package () { |
| 2163 | # Change the following version to cause sstate to invalidate the package |
| 2164 | # cache. This is useful if an item this class depends on changes in a |
| 2165 | # way that the output of this class changes. rpmdeps is a good example |
| 2166 | # as any change to rpmdeps requires this to be rerun. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2167 | # PACKAGE_BBCLASS_VERSION = "2" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2168 | |
| 2169 | # Init cachedpath |
| 2170 | global cpath |
| 2171 | cpath = oe.cachedpath.CachedPath() |
| 2172 | |
| 2173 | ########################################################################### |
| 2174 | # Sanity test the setup |
| 2175 | ########################################################################### |
| 2176 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2177 | packages = (d.getVar('PACKAGES') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2178 | if len(packages) < 1: |
| 2179 | bb.debug(1, "No packages to build, skipping do_package") |
| 2180 | return |
| 2181 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2182 | workdir = d.getVar('WORKDIR') |
| 2183 | outdir = d.getVar('DEPLOY_DIR') |
| 2184 | dest = d.getVar('D') |
| 2185 | dvar = d.getVar('PKGD') |
| 2186 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2187 | |
| 2188 | if not workdir or not outdir or not dest or not dvar or not pn: |
| 2189 | msg = "WORKDIR, DEPLOY_DIR, D, PN and PKGD all must be defined, unable to package" |
| 2190 | package_qa_handle_error("var-undefined", msg, d) |
| 2191 | return |
| 2192 | |
| 2193 | bb.build.exec_func("package_get_auto_pr", d) |
| 2194 | |
| 2195 | ########################################################################### |
| 2196 | # Optimisations |
| 2197 | ########################################################################### |
| 2198 | |
| 2199 | # Continually expanding complex expressions is inefficient, particularly |
| 2200 | # when we write to the datastore and invalidate the expansion cache. This |
| 2201 | # code pre-expands some frequently used variables |
| 2202 | |
| 2203 | def expandVar(x, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2204 | d.setVar(x, d.getVar(x)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2205 | |
| 2206 | for x in 'PN', 'PV', 'BPN', 'TARGET_SYS', 'EXTENDPRAUTO': |
| 2207 | expandVar(x, d) |
| 2208 | |
| 2209 | ########################################################################### |
| 2210 | # Setup PKGD (from D) |
| 2211 | ########################################################################### |
| 2212 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2213 | for f in (d.getVar('PACKAGEBUILDPKGD') or '').split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2214 | bb.build.exec_func(f, d) |
| 2215 | |
| 2216 | ########################################################################### |
| 2217 | # Split up PKGD into PKGDEST |
| 2218 | ########################################################################### |
| 2219 | |
| 2220 | cpath = oe.cachedpath.CachedPath() |
| 2221 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2222 | for f in (d.getVar('PACKAGESPLITFUNCS') or '').split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2223 | bb.build.exec_func(f, d) |
| 2224 | |
| 2225 | ########################################################################### |
| 2226 | # Process PKGDEST |
| 2227 | ########################################################################### |
| 2228 | |
| 2229 | # Build global list of files in each split package |
| 2230 | global pkgfiles |
| 2231 | pkgfiles = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2232 | packages = d.getVar('PACKAGES').split() |
| 2233 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2234 | for pkg in packages: |
| 2235 | pkgfiles[pkg] = [] |
| 2236 | for walkroot, dirs, files in cpath.walk(pkgdest + "/" + pkg): |
| 2237 | for file in files: |
| 2238 | pkgfiles[pkg].append(walkroot + os.sep + file) |
| 2239 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2240 | for f in (d.getVar('PACKAGEFUNCS') or '').split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2241 | bb.build.exec_func(f, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2242 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2243 | qa_sane = d.getVar("QA_SANE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2244 | if not qa_sane: |
| 2245 | bb.fatal("Fatal QA errors found, failing task.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | do_package[dirs] = "${SHLIBSWORKDIR} ${PKGDESTWORK} ${D}" |
| 2249 | do_package[vardeps] += "${PACKAGEBUILDPKGD} ${PACKAGESPLITFUNCS} ${PACKAGEFUNCS} ${@gen_packagevar(d)}" |
| 2250 | addtask package after do_install |
| 2251 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2252 | SSTATETASKS += "do_package" |
| 2253 | do_package[cleandirs] = "${PKGDEST} ${PKGDESTWORK}" |
| 2254 | do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST} ${PKGDESTWORK}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2255 | do_package_setscene[dirs] = "${STAGING_DIR}" |
| 2256 | |
| 2257 | python do_package_setscene () { |
| 2258 | sstate_setscene(d) |
| 2259 | } |
| 2260 | addtask do_package_setscene |
| 2261 | |
| 2262 | do_packagedata () { |
| 2263 | : |
| 2264 | } |
| 2265 | |
| 2266 | addtask packagedata before do_build after do_package |
| 2267 | |
| 2268 | SSTATETASKS += "do_packagedata" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2269 | # PACKAGELOCK protects readers of PKGDATA_DIR against writes |
| 2270 | # whilst code is reading in do_package |
| 2271 | PACKAGELOCK = "${STAGING_DIR}/package-output.lock" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2272 | do_packagedata[sstate-inputdirs] = "${PKGDESTWORK}" |
| 2273 | do_packagedata[sstate-outputdirs] = "${PKGDATA_DIR}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2274 | do_packagedata[sstate-lockfile] = "${PACKAGELOCK}" |
| 2275 | do_packagedata[stamp-extra-info] = "${MACHINE_ARCH}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2276 | |
| 2277 | python do_packagedata_setscene () { |
| 2278 | sstate_setscene(d) |
| 2279 | } |
| 2280 | addtask do_packagedata_setscene |
| 2281 | |
| 2282 | # |
| 2283 | # Helper functions for the package writing classes |
| 2284 | # |
| 2285 | |
| 2286 | def mapping_rename_hook(d): |
| 2287 | """ |
| 2288 | Rewrite variables to account for package renaming in things |
| 2289 | like debian.bbclass or manual PKG variable name changes |
| 2290 | """ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2291 | pkg = d.getVar("PKG") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2292 | runtime_mapping_rename("RDEPENDS", pkg, d) |
| 2293 | runtime_mapping_rename("RRECOMMENDS", pkg, d) |
| 2294 | runtime_mapping_rename("RSUGGESTS", pkg, d) |