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