From c55327daed509bd8ce3b81d0b154c2bb3ce65f3c Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 1 Sep 2007 15:08:16 +0000 Subject: package.bbclass: Improve strip function and convert to python (from poky) --- classes/package.bbclass | 112 ++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 61 deletions(-) (limited to 'classes/package.bbclass') diff --git a/classes/package.bbclass b/classes/package.bbclass index 95e4acd4d6..bc69dc9f8f 100644 --- a/classes/package.bbclass +++ b/classes/package.bbclass @@ -136,59 +136,57 @@ python () { bb.data.setVarFlag('do_package', 'deptask', 'do_package', d) } -# file(1) output to match to consider a file an unstripped executable -FILE_UNSTRIPPED_MATCH ?= "not stripped" -#FIXME: this should be "" when any errors are gone! -IGNORE_STRIP_ERRORS ?= "1" - -runstrip() { - # Function to strip a single file, called from RUNSTRIP in populate_packages below - # A working 'file' (one which works on the target architecture) - # is necessary for this stuff to work, hence the addition to do_package[depends] - - local ro st - - st=0 - if { file "$1" || { - oewarn "file $1: failed (forced strip)" >&2 - echo '${FILE_UNSTRIPPED_MATCH}' - } - } | grep -q '${FILE_UNSTRIPPED_MATCH}' - then - oenote "${STRIP} $1" - ro= - test -w "$1" || { - ro=1 - chmod +w "$1" - } - mkdir -p $(dirname "$1")/.debug - debugfile="$(dirname "$1")/.debug/$(basename "$1")" - '${OBJCOPY}' --only-keep-debug "$1" "$debugfile" - '${STRIP}' "$1" - st=$? - '${OBJCOPY}' --add-gnu-debuglink="$debugfile" "$1" - test -n "$ro" && chmod -w "$1" - if test $st -ne 0 - then - oewarn "runstrip: ${STRIP} $1: strip failed" >&2 - if [ x${IGNORE_STRIP_ERRORS} = x1 ] - then - #FIXME: remove this, it's for error detection - if file "$1" 2>/dev/null >&2 - then - (oefatal "${STRIP} $1: command failed" >/dev/tty) - else - (oefatal "file $1: command failed" >/dev/tty) - fi - st=0 - fi - fi - else - oenote "runstrip: skip $1" - fi - return $st -} +def runstrip(file, d): + # Function to strip a single file, called from populate_packages below + # A working 'file' (one which works on the target architecture) + # is necessary for this stuff to work, hence the addition to do_package[depends] + + import bb, os, commands, stat + + pathprefix = "export PATH=%s; " % bb.data.getVar('PATH', d, 1) + + ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, file)) + + if ret: + bb.error("runstrip: 'file %s' failed (forced strip)" % file) + + if "not stripped" not in result: + bb.debug(1, "runstrip: skip %s" % file) + return 0 + + strip = bb.data.getVar("STRIP", d, 1) + objcopy = bb.data.getVar("OBJCOPY", d, 1) + + newmode = None + if not os.access(file, os.W_OK): + origmode = os.stat(file)[stat.ST_MODE] + newmode = origmode | stat.S_IWRITE + os.chmod(file, newmode) + + extraflags = "" + if ".so" in file and "shared" in result: + extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded" + elif "shared" in result or "executable" in result: + extraflags = "--remove-section=.comment --remove-section=.note" + + bb.mkdirhier(os.path.join(os.path.dirname(file), ".debug")) + debugfile=os.path.join(os.path.dirname(file), ".debug", os.path.basename(file)) + + stripcmd = "'%s' %s '%s'" % (strip, extraflags, file) + bb.debug(1, "runstrip: %s" % stripcmd) + + os.system("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile)) + ret = os.system("%s%s" % (pathprefix, stripcmd)) + os.system("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file)) + + if newmode: + os.chmod(file, origmode) + + if ret: + bb.error("runstrip: '%s' strip command failed" % stripcmd) + + return 1 # # Package data handling routines @@ -376,19 +374,11 @@ python populate_packages () { package_list.append(pkg) if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1'): - stripfunc = "" for root, dirs, files in os.walk(dvar): for f in files: file = os.path.join(root, f) if not os.path.islink(file) and not os.path.isdir(file) and isexec(file): - stripfunc += "\trunstrip %s || st=1\n" % (file) - if not stripfunc == "": - from bb import build - localdata = bb.data.createCopy(d) - # strip - bb.data.setVar('RUNSTRIP', '\tlocal st\n\tst=0\n%s\treturn $st' % stripfunc, localdata) - bb.data.setVarFlag('RUNSTRIP', 'func', 1, localdata) - bb.build.exec_func('RUNSTRIP', localdata) + runstrip(file, d) for pkg in package_list: localdata = bb.data.createCopy(d) -- cgit v1.2.3 From eb4534607c691fa07f62c054dea9cc18baf3d9a2 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 1 Sep 2007 15:16:50 +0000 Subject: classes: Convert to PKGDATA_DIR variable (from poky) --- classes/package.bbclass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'classes/package.bbclass') diff --git a/classes/package.bbclass b/classes/package.bbclass index bc69dc9f8f..fe48ec6afd 100644 --- a/classes/package.bbclass +++ b/classes/package.bbclass @@ -503,13 +503,13 @@ python emit_pkgdata() { if not packages: return - data_file = bb.data.expand("${STAGING_DIR}/pkgdata/${PN}", d) + data_file = bb.data.expand("${PKGDATA_DIR}/${PN}", d) f = open(data_file, 'w') f.write("PACKAGES: %s\n" % packages) f.close() for pkg in packages.split(): - subdata_file = bb.data.expand("${STAGING_DIR}/pkgdata/runtime/%s" % pkg, d) + subdata_file = bb.data.expand("${PKGDATA_DIR}/runtime/%s" % pkg, d) sf = open(subdata_file, 'w') write_if_exists(sf, pkg, 'DESCRIPTION') write_if_exists(sf, pkg, 'RDEPENDS') @@ -528,7 +528,7 @@ python emit_pkgdata() { write_if_exists(sf, pkg, 'pkg_prerm') sf.close() } -emit_pkgdata[dirs] = "${STAGING_DIR}/pkgdata/runtime" +emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime" ldconfig_postinst_fragment() { if [ x"$D" = "x" ]; then @@ -830,7 +830,7 @@ python package_depchains() { def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d): def packaged(pkg, d): - return os.access(bb.data.expand('${STAGING_DIR}/pkgdata/runtime/%s.packaged' % pkg, d), os.R_OK) + return os.access(bb.data.expand('${PKGDATA_DIR}/runtime/%s.packaged' % pkg, d), os.R_OK) #bb.note('rdepends for %s is %s' % (base, rdepends)) -- cgit v1.2.3 From 52b47c22bb23cfd473600fd484d8879001e772a6 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 4 Sep 2007 08:38:17 +0000 Subject: package*.bbclass: Switch to separate tasks for each packing type (from poky) --- classes/package.bbclass | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'classes/package.bbclass') diff --git a/classes/package.bbclass b/classes/package.bbclass index fe48ec6afd..5bff49584e 100644 --- a/classes/package.bbclass +++ b/classes/package.bbclass @@ -120,18 +120,12 @@ PACKAGE_DEPENDS += "file-native" python () { import bb - if bb.data.getVar('PACKAGES', d, True) != '': deps = bb.data.getVarFlag('do_package', 'depends', d) or "" for dep in (bb.data.getVar('PACKAGE_DEPENDS', d, True) or "").split(): deps += " %s:do_populate_staging" % dep bb.data.setVarFlag('do_package', 'depends', deps, d) - deps = bb.data.getVarFlag('do_package_write', 'depends', d) or "" - for dep in (bb.data.getVar('PACKAGE_EXTRA_DEPENDS', d, True) or "").split(): - deps += " %s:do_populate_staging" % dep - bb.data.setVarFlag('do_package_write', 'depends', deps, d) - # shlibs requires any DEPENDS to have already packaged for the *.list files bb.data.setVarFlag('do_package', 'deptask', 'do_package', d) } @@ -906,21 +900,14 @@ python package_do_package () { do_package[dirs] = "${D}" addtask package before do_build after do_install - - -PACKAGE_WRITE_FUNCS ?= "read_subpackage_metadata" - -python package_do_package_write () { - for f in (bb.data.getVar('PACKAGE_WRITE_FUNCS', d, 1) or '').split(): - bb.build.exec_func(f, d) +# Dummy task to mark when all packaging is complete +do_package_write () { + : } -do_package_write[dirs] = "${D}" addtask package_write before do_build after do_package - EXPORT_FUNCTIONS do_package do_package_write - # # Helper functions for the package writing classes # -- cgit v1.2.3 From d9d8e78b952be13336c8dfa96ed445fa1c7f1dff Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 4 Sep 2007 08:39:28 +0000 Subject: package.bbclass: Turn install path into a variable (PKGDATA) and cleanup some unneeded complexity (from poky) --- classes/package.bbclass | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'classes/package.bbclass') diff --git a/classes/package.bbclass b/classes/package.bbclass index 5bff49584e..5233fa363c 100644 --- a/classes/package.bbclass +++ b/classes/package.bbclass @@ -2,6 +2,8 @@ # General packaging help functions # +PKGDEST = "${WORKDIR}/install" + def legitimize_package_name(s): """ Make sure package names are legitimate strings @@ -374,25 +376,21 @@ python populate_packages () { if not os.path.islink(file) and not os.path.isdir(file) and isexec(file): runstrip(file, d) + pkgdest = bb.data.getVar('PKGDEST', d, 1) + os.system('rm -rf %s' % pkgdest) + for pkg in package_list: localdata = bb.data.createCopy(d) - root = os.path.join(workdir, "install", pkg) - - os.system('rm -rf %s' % root) + root = os.path.join(pkgdest, pkg) + bb.mkdirhier(root) - bb.data.setVar('ROOT', '', localdata) - bb.data.setVar('ROOT_%s' % pkg, root, localdata) bb.data.setVar('PKG', pkg, localdata) - overrides = bb.data.getVar('OVERRIDES', localdata, 1) if not overrides: raise bb.build.FuncFailed('OVERRIDES not defined') - bb.data.setVar('OVERRIDES', overrides+':'+pkg, localdata) - + bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata) bb.data.update_data(localdata) - root = bb.data.getVar('ROOT', localdata, 1) - bb.mkdirhier(root) filesvar = bb.data.getVar('FILES', localdata, 1) or "" files = filesvar.split() for file in files: @@ -445,7 +443,7 @@ python populate_packages () { for pkg in package_list: dangling_links[pkg] = [] pkg_files[pkg] = [] - inst_root = os.path.join(workdir, "install", pkg) + inst_root = os.path.join(pkgdest, pkg) for root, dirs, files in os.walk(inst_root): for f in files: path = os.path.join(root, f) @@ -566,6 +564,8 @@ python package_do_shlibs() { bb.error("TARGET_SYS not defined") return + pkgdest = bb.data.getVar('PKGDEST', d, 1) + shlibs_dir = os.path.join(staging, target_sys, "shlibs") old_shlibs_dir = os.path.join(staging, "shlibs") bb.mkdirhier(shlibs_dir) @@ -578,7 +578,7 @@ python package_do_shlibs() { needed[pkg] = [] sonames = list() - top = os.path.join(workdir, "install", pkg) + top = os.path.join(pkgdest, pkg) for root, dirs, files in os.walk(top): for file in files: soname = None @@ -664,7 +664,7 @@ python package_do_shlibs() { else: bb.note("Couldn't find shared library provider for %s" % n) - deps_file = os.path.join(workdir, "install", pkg + ".shlibdeps") + deps_file = os.path.join(pkgdest, pkg + ".shlibdeps") if os.path.exists(deps_file): os.remove(deps_file) if len(deps): @@ -697,6 +697,8 @@ python package_do_pkgconfig () { bb.error("TARGET_SYS not defined") return + pkgdest = bb.data.getVar('PKGDEST', d, 1) + shlibs_dir = os.path.join(staging, target_sys, "shlibs") old_shlibs_dir = os.path.join(staging, "shlibs") bb.mkdirhier(shlibs_dir) @@ -710,7 +712,7 @@ python package_do_pkgconfig () { for pkg in packages.split(): pkgconfig_provided[pkg] = [] pkgconfig_needed[pkg] = [] - top = os.path.join(workdir, "install", pkg) + top = os.path.join(pkgdest, pkg) for root, dirs, files in os.walk(top): for file in files: m = pc_re.match(file) @@ -773,7 +775,7 @@ python package_do_pkgconfig () { found = True if found == False: bb.note("couldn't find pkgconfig module '%s' in any package" % n) - deps_file = os.path.join(workdir, "install", pkg + ".pcdeps") + deps_file = os.path.join(pkgdest, pkg + ".pcdeps") if os.path.exists(deps_file): os.remove(deps_file) if len(deps): @@ -787,14 +789,14 @@ python read_shlibdeps () { packages = (bb.data.getVar('PACKAGES', d, 1) or "").split() for pkg in packages: rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "") - shlibsfile = bb.data.expand("${WORKDIR}/install/" + pkg + ".shlibdeps", d) + shlibsfile = bb.data.expand("${PKGDEST}/" + pkg + ".shlibdeps", d) if os.access(shlibsfile, os.R_OK): fd = file(shlibsfile) lines = fd.readlines() fd.close() for l in lines: rdepends.append(l.rstrip()) - pcfile = bb.data.expand("${WORKDIR}/install/" + pkg + ".pcdeps", d) + pcfile = bb.data.expand("${PKGDEST}/" + pkg + ".pcdeps", d) if os.access(pcfile, os.R_OK): fd = file(pcfile) lines = fd.readlines() -- cgit v1.2.3 From 4db71c3a65096e3186abeb14a8eec3b5d6e1909c Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 29 Sep 2007 10:34:46 +0000 Subject: package.bbclass: Fix .packaged pkgmaps data creation to fix depchains. Clean up/optimise PACKAGES checks a bit --- classes/package.bbclass | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'classes/package.bbclass') diff --git a/classes/package.bbclass b/classes/package.bbclass index 5233fa363c..516cae823d 100644 --- a/classes/package.bbclass +++ b/classes/package.bbclass @@ -128,11 +128,12 @@ python () { deps += " %s:do_populate_staging" % dep bb.data.setVarFlag('do_package', 'depends', deps, d) + deps = (bb.data.getVarFlag('do_package', 'deptask', d) or "").split() # shlibs requires any DEPENDS to have already packaged for the *.list files - bb.data.setVarFlag('do_package', 'deptask', 'do_package', d) + deps.append("do_package") + bb.data.setVarFlag('do_package', 'deptask', " ".join(deps), d) } - def runstrip(file, d): # Function to strip a single file, called from populate_packages below # A working 'file' (one which works on the target architecture) @@ -481,6 +482,8 @@ python populate_packages () { populate_packages[dirs] = "${D}" python emit_pkgdata() { + from glob import glob + def write_if_exists(f, pkg, var): def encode(str): import codecs @@ -492,14 +495,14 @@ python emit_pkgdata() { f.write('%s_%s: %s\n' % (var, pkg, encode(val))) packages = bb.data.getVar('PACKAGES', d, 1) - if not packages: - return data_file = bb.data.expand("${PKGDATA_DIR}/${PN}", d) f = open(data_file, 'w') f.write("PACKAGES: %s\n" % packages) f.close() + workdir = bb.data.getVar('WORKDIR', d, 1) + for pkg in packages.split(): subdata_file = bb.data.expand("${PKGDATA_DIR}/runtime/%s" % pkg, d) sf = open(subdata_file, 'w') @@ -519,6 +522,13 @@ python emit_pkgdata() { write_if_exists(sf, pkg, 'pkg_preinst') write_if_exists(sf, pkg, 'pkg_prerm') sf.close() + + allow_empty = bb.data.getVar('ALLOW_EMPTY_%s' % pkg, d, 1) + root = "%s/install/%s" % (workdir, pkg) + os.chdir(root) + g = glob('*') + if g or allow_empty == "1": + file(bb.data.expand('${PKGDATA_DIR}/runtime/%s.packaged' % pkg, d), 'w').close() } emit_pkgdata[dirs] = "${PKGDATA_DIR}/runtime" @@ -540,9 +550,6 @@ python package_do_shlibs() { libdir_re = re.compile(".*/lib$") packages = bb.data.getVar('PACKAGES', d, 1) - if not packages: - bb.debug(1, "no packages to build; not calculating shlibs") - return workdir = bb.data.getVar('WORKDIR', d, 1) if not workdir: @@ -678,9 +685,6 @@ python package_do_pkgconfig () { import re, os packages = bb.data.getVar('PACKAGES', d, 1) - if not packages: - bb.debug(1, "no packages to build; not calculating pkgconfig dependencies") - return workdir = bb.data.getVar('WORKDIR', d, 1) if not workdir: @@ -786,7 +790,7 @@ python package_do_pkgconfig () { } python read_shlibdeps () { - packages = (bb.data.getVar('PACKAGES', d, 1) or "").split() + packages = bb.data.getVar('PACKAGES', d, 1).split() for pkg in packages: rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "") shlibsfile = bb.data.expand("${PKGDEST}/" + pkg + ".shlibdeps", d) @@ -896,6 +900,11 @@ PACKAGEFUNCS ?= "package_do_split_locales \ emit_pkgdata" python package_do_package () { + packages = (bb.data.getVar('PACKAGES', d, 1) or "").split() + if len(packages) < 1: + bb.debug(1, "No packages to build, skipping do_package") + return + for f in (bb.data.getVar('PACKAGEFUNCS', d, 1) or '').split(): bb.build.exec_func(f, d) } -- cgit v1.2.3 From bcaec55e4e64f6bca21cf0e50eaec787bd29b735 Mon Sep 17 00:00:00 2001 From: Henryk Ploetz Date: Tue, 2 Oct 2007 18:51:53 +0000 Subject: mono 1.2.5.1: added mono.bbclass, many changes required for packaging New file: packages/mono/mono-mcs-intermediate_1.2.5.1.bb Compiles mono in native mode with standard prefix, then tars up the resulting tree and puts the tarfile into staging New file: packages/mono/mono_files.py Automatically generated using collect-path.py (attached to this mail) and contains a list that maps file patterns to package names (and contained assemblies, see below). New file: classes/mono.bbclass Has a helper function for the list that maps file patterns to package names and assemblies (see below). Also has a function mono_do_clilibs and inserts that function into PACKAGEFUNCS. This function calls mono_find_provides_and_requires which finds out (through calls to monodis --assembly and monodis --assemblyref) which assemblies are provided and required by a particular package. mono_do_clilibs then puts the information about provided assemblies into ${STAGING_DIR}/clilibs/${packagename}.list and information about the required packages into ${PKGDEST}/{packagename}.clilibdeps where it will later be picked up by the modified read_shlibdeps. Originally I had dependency resolution through the partial list in mono_files.py but obviously this doens't scale, so I implemented the new method with mono_do_clilibs. The benefit is now that I don't really need the extra information in mono_files.py anymore and can in principle get rid of mono_get_file_table and related code. Instead it should be possible to modify collect-paths.py to output bitbake .inc code (e.g. PACKAGES = "..." and a whole lot of FILES_... = "...") instead of python code. There's still the minor problem of how to handle the .mdb files, that's why I didn't implement it yet but instead opted for an approach that I knew would work. (Debian just puts the .mdb files into the individual packages, while I would argue that they do belong into corresponding -dbg packages.) Modified file: classes/package.bbclass In read_shlibdeps I folded the two identical code blocks dealing with *.shlibdeps and *.pcdeps into one and added *.clilibdeps (generated by mono_do_clilibs above). Modified file: packages/mono/mono_1.2.5.1.bb Add the mono-mcs-intermediate workaround. Add a whole lot of python code in populate_packages_prepend in order to split up the packages based on information from mono_files.py (via mono.bbclass' mono_get_file_table). As I said above a lot of this code can hopefully be replaced in the future. --- classes/package.bbclass | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'classes/package.bbclass') diff --git a/classes/package.bbclass b/classes/package.bbclass index 516cae823d..b114049b8e 100644 --- a/classes/package.bbclass +++ b/classes/package.bbclass @@ -793,20 +793,14 @@ python read_shlibdeps () { packages = bb.data.getVar('PACKAGES', d, 1).split() for pkg in packages: rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "") - shlibsfile = bb.data.expand("${PKGDEST}/" + pkg + ".shlibdeps", d) - if os.access(shlibsfile, os.R_OK): - fd = file(shlibsfile) - lines = fd.readlines() - fd.close() - for l in lines: - rdepends.append(l.rstrip()) - pcfile = bb.data.expand("${PKGDEST}/" + pkg + ".pcdeps", d) - if os.access(pcfile, os.R_OK): - fd = file(pcfile) - lines = fd.readlines() - fd.close() - for l in lines: - rdepends.append(l.rstrip()) + for extension in ".shlibdeps", ".pcdeps", ".clilibdeps": + depsfile = bb.data.expand("${PKGDEST}/" + pkg + extension, d) + if os.access(depsfile, os.R_OK): + fd = file(depsfile) + lines = fd.readlines() + fd.close() + for l in lines: + rdepends.append(l.rstrip()) bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d) } -- cgit v1.2.3