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