class test_lafilefixer(TestCase):
def get_test_cases_clean(self):
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' -lm'\n" + \
- "current=6\n" + \
- "age=0\n" + \
- "revision=2\n" + \
- "installed=yes\n" + \
- "dlopen=''\n" + \
- "dlpreopen=''\n" + \
- "libdir='/usr/lib64'\n"
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' -lm'\n" + \
- "current=6\n" + \
- "age=0\n" + \
- "revision=2\n" + \
- "installed=yes\n" + \
- "dlopen=''\n" + \
- "dlpreopen=''\n" + \
- "libdir='/usr/lib64'\n"
- yield "dependency_libs=' liba.la /usr/lib64/bar.la -lc'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' -lm'\n" + \
+ b"current=6\n" + \
+ b"age=0\n" + \
+ b"revision=2\n" + \
+ b"installed=yes\n" + \
+ b"dlopen=''\n" + \
+ b"dlpreopen=''\n" + \
+ b"libdir='/usr/lib64'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' -lm'\n" + \
+ b"current=6\n" + \
+ b"age=0\n" + \
+ b"revision=2\n" + \
+ b"installed=yes\n" + \
+ b"dlopen=''\n" + \
+ b"dlpreopen=''\n" + \
+ b"libdir='/usr/lib64'\n"
+ yield b"dependency_libs=' liba.la /usr/lib64/bar.la -lc'\n"
def get_test_cases_update(self):
#.la -> -l*
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc'\n", \
- "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' -L/usr/lib64 -la -lb -lc'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc'\n", \
+ b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' -L/usr/lib64 -la -lb -lc'\n"
#move stuff into inherited_linker_flags
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la -pthread /usr/lib64/libb.la -lc'\n" + \
- "inherited_linker_flags=''\n", \
- "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' -L/usr/lib64 -la -lb -lc'\n" + \
- "inherited_linker_flags=' -pthread'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la -pthread /usr/lib64/libb.la -lc'\n" + \
+ b"inherited_linker_flags=''\n", \
+ b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' -L/usr/lib64 -la -lb -lc'\n" + \
+ b"inherited_linker_flags=' -pthread'\n"
#reorder
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la -R/usr/lib64 /usr/lib64/libb.la -lc'\n", \
- "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' -R/usr/lib64 -L/usr/lib64 -la -lb -lc'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la -R/usr/lib64 /usr/lib64/libb.la -lc'\n", \
+ b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' -R/usr/lib64 -L/usr/lib64 -la -lb -lc'\n"
#remove duplicates from dependency_libs (the original version didn't do it for inherited_linker_flags)
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libc.la -pthread -mt" + \
- " -L/usr/lib -R/usr/lib64 -lc /usr/lib64/libb.la -lc'\n" +\
- "inherited_linker_flags=' -pthread -pthread'\n", \
- "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' -R/usr/lib64 -L/usr/lib64 -L/usr/lib -la -lc -lb'\n" +\
- "inherited_linker_flags=' -pthread -pthread -mt'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libc.la -pthread -mt" + \
+ b" -L/usr/lib -R/usr/lib64 -lc /usr/lib64/libb.la -lc'\n" +\
+ b"inherited_linker_flags=' -pthread -pthread'\n", \
+ b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' -R/usr/lib64 -L/usr/lib64 -L/usr/lib -la -lc -lb'\n" +\
+ b"inherited_linker_flags=' -pthread -pthread -mt'\n"
#-L rewriting
- yield "dependency_libs=' -L/usr/X11R6/lib'\n", \
- "dependency_libs=' -L/usr/lib'\n"
- yield "dependency_libs=' -L/usr/local/lib'\n", \
- "dependency_libs=' -L/usr/lib'\n"
- yield "dependency_libs=' -L/usr/lib64/pkgconfig/../..'\n", \
- "dependency_libs=' -L/usr'\n"
- yield "dependency_libs=' -L/usr/lib/pkgconfig/..'\n", \
- "dependency_libs=' -L/usr/lib'\n"
- yield "dependency_libs=' -L/usr/lib/pkgconfig/../.. -L/usr/lib/pkgconfig/..'\n", \
- "dependency_libs=' -L/usr -L/usr/lib'\n"
+ yield b"dependency_libs=' -L/usr/X11R6/lib'\n", \
+ b"dependency_libs=' -L/usr/lib'\n"
+ yield b"dependency_libs=' -L/usr/local/lib'\n", \
+ b"dependency_libs=' -L/usr/lib'\n"
+ yield b"dependency_libs=' -L/usr/lib64/pkgconfig/../..'\n", \
+ b"dependency_libs=' -L/usr'\n"
+ yield b"dependency_libs=' -L/usr/lib/pkgconfig/..'\n", \
+ b"dependency_libs=' -L/usr/lib'\n"
+ yield b"dependency_libs=' -L/usr/lib/pkgconfig/../.. -L/usr/lib/pkgconfig/..'\n", \
+ b"dependency_libs=' -L/usr -L/usr/lib'\n"
def get_test_cases_broken(self):
- yield ""
+ yield b""
#no dependency_libs
- yield "dlname='libfoo.so.1'\n" + \
- "current=6\n" + \
- "age=0\n" + \
- "revision=2\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"current=6\n" + \
+ b"age=0\n" + \
+ b"revision=2\n"
#borken dependency_libs
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc' \n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc' \n"
#borken dependency_libs
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc\n"
#crap in dependency_libs
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc /-lstdc++'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc /-lstdc++'\n"
#dependency_libs twice
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc /-lstdc++'\n" +\
- "dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc /-lstdc++'\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc /-lstdc++'\n" +\
+ b"dependency_libs=' /usr/lib64/liba.la /usr/lib64/libb.la -lc /-lstdc++'\n"
#inherited_linker_flags twice
- yield "dlname='libfoo.so.1'\n" + \
- "library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
- "old_library='libpdf.a'\n" + \
- "inherited_linker_flags=''\n" +\
- "inherited_linker_flags=''\n"
+ yield b"dlname='libfoo.so.1'\n" + \
+ b"library_names='libfoo.so.1.0.2 libfoo.so.1 libfoo.so'\n" + \
+ b"old_library='libpdf.a'\n" + \
+ b"inherited_linker_flags=''\n" +\
+ b"inherited_linker_flags=''\n"
def testlafilefixer(self):
from portage.util.lafilefixer import _parse_lafile_contents, rewrite_lafile
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import os as _os
import re
-from portage import os
+from portage import _unicode_decode
from portage.exception import InvalidData
#########################################################
#########################################################
#These regexes are used to parse the interesting entries in the la file
-dep_libs_re = re.compile("dependency_libs='(?P<value>[^']*)'$")
-inh_link_flags_re = re.compile("inherited_linker_flags='(?P<value>[^']*)'$")
+dep_libs_re = re.compile(b"dependency_libs='(?P<value>[^']*)'$")
+inh_link_flags_re = re.compile(b"inherited_linker_flags='(?P<value>[^']*)'$")
#regexes for replacing stuff in -L entries.
#replace 'X11R6/lib' and 'local/lib' with 'lib', no idea what's this about.
-X11_local_sub = re.compile("X11R6/lib|local/lib")
+X11_local_sub = re.compile(b"X11R6/lib|local/lib")
#get rid of the '..'
-pkgconfig_sub1 = re.compile("usr/lib[^/]*/pkgconfig/\.\./\.\.")
-pkgconfig_sub2 = re.compile("(?P<usrlib>usr/lib[^/]*)/pkgconfig/\.\.")
+pkgconfig_sub1 = re.compile(b"usr/lib[^/]*/pkgconfig/\.\./\.\.")
+pkgconfig_sub2 = re.compile(b"(?P<usrlib>usr/lib[^/]*)/pkgconfig/\.\.")
#detect flags that should go into inherited_linker_flags instead of dependency_libs
-flag_re = re.compile("-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads")
+flag_re = re.compile(b"-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads")
def _parse_lafile_contents(contents):
"""
dep_libs = None
inh_link_flags = None
- for line in contents.split("\n"):
+ for line in contents.split(b"\n"):
m = dep_libs_re.match(line)
if m:
if dep_libs is not None:
#Check entries in 'dependency_libs'.
for dep_libs_entry in dep_libs.split():
- if dep_libs_entry.startswith("-l"):
+ if dep_libs_entry.startswith(b"-l"):
#-lfoo, keep it
if dep_libs_entry not in new_dep_libs:
new_dep_libs.append(dep_libs_entry)
- elif dep_libs_entry.endswith(".la"):
+ elif dep_libs_entry.endswith(b".la"):
#Two cases:
#1) /usr/lib64/libfoo.la, turn it into -lfoo and append -L/usr/lib64 to libladir
#2) libfoo.la, keep it
- dir, file = os.path.split(dep_libs_entry)
+ dir, file = _os.path.split(dep_libs_entry)
- if not dir or not file.startswith("lib"):
+ if not dir or not file.startswith(b"lib"):
if dep_libs_entry not in new_dep_libs:
new_dep_libs.append(dep_libs_entry)
else:
#/usr/lib64/libfoo.la -> -lfoo
- lib = "-l" + file[3:-3]
+ lib = b"-l" + file[3:-3]
if lib not in new_dep_libs:
new_dep_libs.append(lib)
#/usr/lib64/libfoo.la -> -L/usr/lib64
- ladir = "-L" + dir
+ ladir = b"-L" + dir
if ladir not in libladir:
libladir.append(ladir)
- elif dep_libs_entry.startswith("-L"):
+ elif dep_libs_entry.startswith(b"-L"):
#Do some replacement magic and store them in 'libladir'.
#This allows us to place all -L entries at the beginning
#of 'dependency_libs'.
ladir = dep_libs_entry
- ladir = X11_local_sub.sub("lib", ladir)
- ladir = pkgconfig_sub1.sub("usr", ladir)
- ladir = pkgconfig_sub2.sub("\g<usrlib>", ladir)
+ ladir = X11_local_sub.sub(b"lib", ladir)
+ ladir = pkgconfig_sub1.sub(b"usr", ladir)
+ ladir = pkgconfig_sub2.sub(b"\g<usrlib>", ladir)
if ladir not in libladir:
libladir.append(ladir)
- elif dep_libs_entry.startswith("-R"):
+ elif dep_libs_entry.startswith(b"-R"):
if dep_libs_entry not in librpath:
librpath.append(dep_libs_entry)
else:
raise InvalidData("Error: Unexpected entry '%s' in 'dependency_libs'" \
- % dep_libs_entry)
+ % _unicode_decode(dep_libs_entry))
#What should 'dependency_libs' and 'inherited_linker_flags' look like?
- expected_dep_libs = ""
+ expected_dep_libs = b""
for x in (librpath, libladir, new_dep_libs):
if x:
- expected_dep_libs += " " + " ".join(x)
+ expected_dep_libs += b" " + b" ".join(x)
- expected_inh_link_flags = ""
+ expected_inh_link_flags = b""
if new_inh_link_flags:
- expected_inh_link_flags += " " + " ".join(new_inh_link_flags)
+ expected_inh_link_flags += b" " + b" ".join(new_inh_link_flags)
#Don't touch the file if we don't need to, otherwise put the expected values into
#'contents' and write it into the la file.
(inh_link_flags is None or expected_inh_link_flags == inh_link_flags):
return False, None
- contents = re.sub("dependency_libs='" + dep_libs + "'", \
- "dependency_libs='" + expected_dep_libs + "'" , contents)
+ contents = re.sub(b"dependency_libs='" + dep_libs + b"'", \
+ b"dependency_libs='" + expected_dep_libs + b"'" , contents)
if inh_link_flags is not None:
- contents = re.sub("inherited_linker_flags='" + inh_link_flags + "'", \
- "inherited_linker_flags='" + expected_inh_link_flags + "'" , contents)
+ contents = re.sub(b"inherited_linker_flags='" + inh_link_flags + b"'", \
+ b"inherited_linker_flags='" + expected_inh_link_flags + b"'" , contents)
return True, contents