Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | |
| 2 | sysroot_stage_dir() { |
| 3 | src="$1" |
| 4 | dest="$2" |
| 5 | # if the src doesn't exist don't do anything |
| 6 | if [ ! -d "$src" ]; then |
| 7 | return |
| 8 | fi |
| 9 | |
| 10 | mkdir -p "$dest" |
| 11 | ( |
| 12 | cd $src |
| 13 | find . -print0 | cpio --null -pdlu $dest |
| 14 | ) |
| 15 | } |
| 16 | |
| 17 | sysroot_stage_libdir() { |
| 18 | src="$1" |
| 19 | dest="$2" |
| 20 | |
| 21 | sysroot_stage_dir $src $dest |
| 22 | } |
| 23 | |
| 24 | sysroot_stage_dirs() { |
| 25 | from="$1" |
| 26 | to="$2" |
| 27 | |
| 28 | sysroot_stage_dir $from${includedir} $to${includedir} |
| 29 | if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then |
| 30 | sysroot_stage_dir $from${bindir} $to${bindir} |
| 31 | sysroot_stage_dir $from${sbindir} $to${sbindir} |
| 32 | sysroot_stage_dir $from${base_bindir} $to${base_bindir} |
| 33 | sysroot_stage_dir $from${base_sbindir} $to${base_sbindir} |
| 34 | sysroot_stage_dir $from${libexecdir} $to${libexecdir} |
| 35 | sysroot_stage_dir $from${sysconfdir} $to${sysconfdir} |
| 36 | sysroot_stage_dir $from${localstatedir} $to${localstatedir} |
| 37 | fi |
| 38 | if [ -d $from${libdir} ] |
| 39 | then |
| 40 | sysroot_stage_libdir $from${libdir} $to${libdir} |
| 41 | fi |
| 42 | if [ -d $from${base_libdir} ] |
| 43 | then |
| 44 | sysroot_stage_libdir $from${base_libdir} $to${base_libdir} |
| 45 | fi |
| 46 | if [ -d $from${nonarch_base_libdir} ] |
| 47 | then |
| 48 | sysroot_stage_libdir $from${nonarch_base_libdir} $to${nonarch_base_libdir} |
| 49 | fi |
| 50 | sysroot_stage_dir $from${datadir} $to${datadir} |
| 51 | # We don't care about docs/info/manpages/locales |
| 52 | rm -rf $to${mandir}/ $to${docdir}/ $to${infodir}/ ${to}${datadir}/locale/ |
| 53 | rm -rf $to${datadir}/applications/ $to${datadir}/fonts/ $to${datadir}/pixmaps/ |
| 54 | } |
| 55 | |
| 56 | sysroot_stage_all() { |
| 57 | sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR} |
| 58 | } |
| 59 | |
| 60 | python sysroot_strip () { |
| 61 | import stat, errno |
| 62 | |
| 63 | dvar = d.getVar('SYSROOT_DESTDIR', True) |
| 64 | pn = d.getVar('PN', True) |
| 65 | |
| 66 | os.chdir(dvar) |
| 67 | |
| 68 | # Return type (bits): |
| 69 | # 0 - not elf |
| 70 | # 1 - ELF |
| 71 | # 2 - stripped |
| 72 | # 4 - executable |
| 73 | # 8 - shared library |
| 74 | # 16 - kernel module |
| 75 | def isELF(path): |
| 76 | type = 0 |
| 77 | ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\"")) |
| 78 | |
| 79 | if ret: |
| 80 | bb.error("split_and_strip_files: 'file %s' failed" % path) |
| 81 | return type |
| 82 | |
| 83 | # Not stripped |
| 84 | if "ELF" in result: |
| 85 | type |= 1 |
| 86 | if "not stripped" not in result: |
| 87 | type |= 2 |
| 88 | if "executable" in result: |
| 89 | type |= 4 |
| 90 | if "shared" in result: |
| 91 | type |= 8 |
| 92 | return type |
| 93 | |
| 94 | |
| 95 | elffiles = {} |
| 96 | inodes = {} |
| 97 | libdir = os.path.abspath(dvar + os.sep + d.getVar("libdir", True)) |
| 98 | baselibdir = os.path.abspath(dvar + os.sep + d.getVar("base_libdir", True)) |
| 99 | if (d.getVar('INHIBIT_SYSROOT_STRIP', True) != '1'): |
| 100 | # |
| 101 | # First lets figure out all of the files we may have to process |
| 102 | # |
| 103 | for root, dirs, files in os.walk(dvar): |
| 104 | for f in files: |
| 105 | file = os.path.join(root, f) |
| 106 | |
| 107 | try: |
| 108 | ltarget = oe.path.realpath(file, dvar, False) |
| 109 | s = os.lstat(ltarget) |
| 110 | except OSError as e: |
| 111 | (err, strerror) = e.args |
| 112 | if err != errno.ENOENT: |
| 113 | raise |
| 114 | # Skip broken symlinks |
| 115 | continue |
| 116 | if not s: |
| 117 | continue |
| 118 | # Check its an excutable |
| 119 | if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \ |
| 120 | or ((file.startswith(libdir) or file.startswith(baselibdir)) and ".so" in f): |
| 121 | # If it's a symlink, and points to an ELF file, we capture the readlink target |
| 122 | if os.path.islink(file): |
| 123 | continue |
| 124 | |
| 125 | # It's a file (or hardlink), not a link |
| 126 | # ...but is it ELF, and is it already stripped? |
| 127 | elf_file = isELF(file) |
| 128 | if elf_file & 1: |
| 129 | if elf_file & 2: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 130 | if 'already-stripped' in (d.getVar('INSANE_SKIP_' + pn, True) or "").split(): |
| 131 | bb.note("Skipping file %s from %s for already-stripped QA test" % (file[len(dvar):], pn)) |
| 132 | else: |
| 133 | bb.warn("File '%s' from %s was already stripped, this will prevent future debugging!" % (file[len(dvar):], pn)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 134 | continue |
| 135 | |
| 136 | if s.st_ino in inodes: |
| 137 | os.unlink(file) |
| 138 | os.link(inodes[s.st_ino], file) |
| 139 | else: |
| 140 | inodes[s.st_ino] = file |
| 141 | # break hardlink |
| 142 | bb.utils.copyfile(file, file) |
| 143 | elffiles[file] = elf_file |
| 144 | |
| 145 | # |
| 146 | # Now strip them (in parallel) |
| 147 | # |
| 148 | strip = d.getVar("STRIP", True) |
| 149 | sfiles = [] |
| 150 | for file in elffiles: |
| 151 | elf_file = int(elffiles[file]) |
| 152 | #bb.note("Strip %s" % file) |
| 153 | sfiles.append((file, elf_file, strip)) |
| 154 | |
| 155 | oe.utils.multiprocess_exec(sfiles, oe.package.runstrip) |
| 156 | } |
| 157 | |
| 158 | do_populate_sysroot[dirs] = "${SYSROOT_DESTDIR}" |
| 159 | do_populate_sysroot[umask] = "022" |
| 160 | |
| 161 | addtask populate_sysroot after do_install |
| 162 | |
| 163 | SYSROOT_PREPROCESS_FUNCS ?= "" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 164 | SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | SYSROOT_LOCK = "${STAGING_DIR}/staging.lock" |
| 166 | |
| 167 | # We clean out any existing sstate from the sysroot if we rerun configure |
| 168 | python sysroot_cleansstate () { |
| 169 | ss = sstate_state_fromvars(d, "populate_sysroot") |
| 170 | sstate_clean(ss, d) |
| 171 | } |
| 172 | do_configure[prefuncs] += "sysroot_cleansstate" |
| 173 | |
| 174 | |
| 175 | BB_SETSCENE_VERIFY_FUNCTION = "sysroot_checkhashes" |
| 176 | |
| 177 | def sysroot_checkhashes(covered, tasknames, fnids, fns, d, invalidtasks = None): |
| 178 | problems = set() |
| 179 | configurefnids = set() |
| 180 | if not invalidtasks: |
| 181 | invalidtasks = xrange(len(tasknames)) |
| 182 | for task in invalidtasks: |
| 183 | if tasknames[task] == "do_configure" and task not in covered: |
| 184 | configurefnids.add(fnids[task]) |
| 185 | for task in covered: |
| 186 | if tasknames[task] == "do_populate_sysroot" and fnids[task] in configurefnids: |
| 187 | problems.add(task) |
| 188 | return problems |
| 189 | |
| 190 | python do_populate_sysroot () { |
| 191 | bb.build.exec_func("sysroot_stage_all", d) |
| 192 | bb.build.exec_func("sysroot_strip", d) |
| 193 | for f in (d.getVar('SYSROOT_PREPROCESS_FUNCS', True) or '').split(): |
| 194 | bb.build.exec_func(f, d) |
| 195 | pn = d.getVar("PN", True) |
| 196 | multiprov = d.getVar("MULTI_PROVIDER_WHITELIST", True).split() |
| 197 | provdir = d.expand("${SYSROOT_DESTDIR}${base_prefix}/sysroot-providers/") |
| 198 | bb.utils.mkdirhier(provdir) |
| 199 | for p in d.getVar("PROVIDES", True).split(): |
| 200 | if p in multiprov: |
| 201 | continue |
| 202 | p = p.replace("/", "_") |
| 203 | with open(provdir + p, "w") as f: |
| 204 | f.write(pn) |
| 205 | } |
| 206 | |
| 207 | do_populate_sysroot[vardeps] += "${SYSROOT_PREPROCESS_FUNCS}" |
| 208 | do_populate_sysroot[vardepsexclude] += "MULTI_PROVIDER_WHITELIST" |
| 209 | |
| 210 | SSTATETASKS += "do_populate_sysroot" |
| 211 | do_populate_sysroot[cleandirs] = "${SYSROOT_DESTDIR}" |
| 212 | do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}" |
| 213 | do_populate_sysroot[sstate-outputdirs] = "${STAGING_DIR_HOST}/" |
| 214 | do_populate_sysroot[stamp-extra-info] = "${MACHINE}" |
| 215 | |
| 216 | python do_populate_sysroot_setscene () { |
| 217 | sstate_setscene(d) |
| 218 | } |
| 219 | addtask do_populate_sysroot_setscene |
| 220 | |
| 221 | |