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