1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# test_lafilefixer.py -- Portage Unit Testing Functionality
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
from portage.exception import InvalidData
class test_lafilefixer(TestCase):
def get_test_cases_clean(self):
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 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 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 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 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 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 b""
#no dependency_libs
yield b"dlname='libfoo.so.1'\n" + \
b"current=6\n" + \
b"age=0\n" + \
b"revision=2\n"
#borken dependency_libs
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 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 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 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 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
for clean_contents in self.get_test_cases_clean():
self.assertEqual(rewrite_lafile(clean_contents), (False, None))
for original_contents, fixed_contents in self.get_test_cases_update():
self.assertEqual(rewrite_lafile(original_contents), (True, fixed_contents))
for broken_contents in self.get_test_cases_broken():
self.assertRaises(InvalidData, rewrite_lafile, broken_contents)
|