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