gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / gobject-introspection-absolute-shlib-path.patch
1 # Names of libraries included in typelib files are opened by dlopen. Here we
2 # add the full path.
3 #
4 # This patch was provided by Luca Bruno <lucabru@src.gnome.org> for
5 # 'gobject-introspection' 1.40.0 in Nix.
6 #
7 # It has since been updated to work with newer versions of
8 # gobject-introspection.
9 --- a/giscanner/scannermain.py
10 +++ b/giscanner/scannermain.py
11 @@ -95,6 +95,39 @@ def get_windows_option_group(parser):
12 return group
13
14
15 +def _get_default_fallback_libpath():
16 + # Newer multiple-output-optimized stdenv has an environment variable
17 + # $outputLib which in turn specifies another variable which then is used as
18 + # the destination for the library contents (${!outputLib}/lib).
19 + store_path = os.environ.get(os.environ.get("outputLib")) if "outputLib" in os.environ else None
20 + if store_path is None:
21 + outputs = os.environ.get("outputs", "out").split()
22 + if "lib" in outputs:
23 + # For multiple output derivations let's try whether there is a $lib
24 + # environment variable and use that as the base store path.
25 + store_path = os.environ.get("lib")
26 + elif "out" in outputs:
27 + # Otherwise we have a single output derivation, so the libraries
28 + # most certainly will end up in "$out/lib".
29 + store_path = os.environ.get("out")
30 +
31 + if store_path is not None:
32 + # Even if we have a $lib as output, there still should be a $lib/lib
33 + # directory.
34 + return os.path.join(store_path, 'lib')
35 + else:
36 + # If we haven't found a possible scenario, let's return an empty string
37 + # so that the shared library won't be prepended with a path.
38 + #
39 + # Note that this doesn't mean that all hope is lost, because after all
40 + # we can still use --fallback-library-path to set one.
41 + #
42 + # Also, we're not returning None, because that would make it very
43 + # difficult to disable adding fallback paths altogether using something
44 + # like: --fallback-library-path=""
45 + return ""
46 +
47 +
48 def _get_option_parser():
49 parser = optparse.OptionParser('%prog [options] sources',
50 version='%prog ' + giscanner.__version__)
51 @@ -205,6 +238,10 @@ match the namespace prefix.""")
52 parser.add_option("", "--filelist",
53 action="store", dest="filelist", default=[],
54 help="file containing headers and sources to be scanned")
55 + parser.add_option("", "--fallback-library-path",
56 + action="store", dest="fallback_libpath",
57 + default=_get_default_fallback_libpath(),
58 + help="Path to prepend to unknown shared libraries")
59
60 group = get_preprocessor_option_group(parser)
61 parser.add_option_group(group)
62 --- a/giscanner/shlibs.py
63 +++ b/giscanner/shlibs.py
64 @@ -57,6 +57,14 @@ def _ldd_library_pattern(library_name):
65 $""" % re.escape(library_name), re.VERBOSE)
66
67
68 +def _ldd_library_guix_pattern(library_name):
69 + store_dir = re.escape(
70 + os.environ.get("NIX_STORE", default="/gnu/store")
71 + )
72 + pattern = r'(%s(?:/[^/]*)+lib%s[^A-Za-z0-9_-][^\s\(\)]*)'
73 + return re.compile(pattern % (store_dir, re.escape(library_name)))
74 +
75 +
76 # This is a what we do for non-la files. We assume that we are on an
77 # ELF-like system where ldd exists and the soname extracted with ldd is
78 # a filename that can be opened with dlopen().
79 @@ -106,7 +112,8 @@ def _resolve_non_libtool(options, binary, libraries):
80 output = output.decode("utf-8", "replace")
81
82 shlibs = resolve_from_ldd_output(libraries, output)
83 - return list(map(sanitize_shlib_path, shlibs))
84 + fallback_libpath = options.fallback_libpath or "";
85 + return list(map(lambda p: os.path.join(fallback_libpath, p), map(sanitize_shlib_path, shlibs)))
86
87
88 def sanitize_shlib_path(lib):
89 @@ -115,19 +122,18 @@ def sanitize_shlib_path(lib):
90 # In case we get relative paths on macOS (like @rpath) then we fall
91 # back to the basename as well:
92 # https://gitlab.gnome.org/GNOME/gobject-introspection/issues/222
93 - if sys.platform == "darwin":
94 - if not os.path.isabs(lib):
95 - return os.path.basename(lib)
96 - return lib
97 - else:
98 +
99 + # Always use absolute paths if available
100 + if not os.path.isabs(lib):
101 return os.path.basename(lib)
102 + return lib
103
104
105 def resolve_from_ldd_output(libraries, output):
106 patterns = {}
107 for library in libraries:
108 if not os.path.isfile(library):
109 - patterns[library] = _ldd_library_pattern(library)
110 + patterns[library] = (_ldd_library_pattern(library), _ldd_library_guix_pattern(library))
111 if len(patterns) == 0:
112 return []
113
114 @@ -139,8 +145,12 @@ def resolve_from_ldd_output(libraries, output):
115 if line.endswith(':'):
116 continue
117 for word in line.split():
118 - for library, pattern in patterns.items():
119 - m = pattern.match(word)
120 + for library, (pattern, guix_pattern) in patterns.items():
121 + store_dir = os.environ.get("NIX_STORE", default="/gnu/store")
122 + if line.find(store_dir) != -1:
123 + m = guix_pattern.match(word)
124 + else:
125 + m = pattern.match(word)
126 if m:
127 del patterns[library]
128 shlibs.append(m.group())
129
130 --- a/giscanner/utils.py
131 +++ b/giscanner/utils.py
132 @@ -111,17 +111,11 @@ def extract_libtool_shlib(la_file):
133 if dlname is None:
134 return None
135
136 - # Darwin uses absolute paths where possible; since the libtool files never
137 - # contain absolute paths, use the libdir field
138 - if platform.system() == 'Darwin':
139 - dlbasename = os.path.basename(dlname)
140 - libdir = _extract_libdir_field(la_file)
141 - if libdir is None:
142 - return dlbasename
143 - return libdir + '/' + dlbasename
144 - # From the comments in extract_libtool(), older libtools had
145 - # a path rather than the raw dlname
146 - return os.path.basename(dlname)
147 + dlbasename = os.path.basename(dlname)
148 + libdir = _extract_libdir_field(la_file)
149 + if libdir is None:
150 + return dlbasename
151 + return libdir + '/' + dlbasename
152
153
154 def extract_libtool(la_file):
155 --- a/tests/scanner/test_shlibs.py
156 +++ b/tests/scanner/test_shlibs.py
157 @@ -40,6 +64,7 @@ class TestLddParser(unittest.TestCase):
158
159 self.assertEqual(
160 sanitize_shlib_path('/foo/bar'),
161 - '/foo/bar' if sys.platform == 'darwin' else 'bar')
162 + # Always use an absolute filename for Guix
163 + '/foo/bar')
164
165 def test_unresolved_library(self):
166 output = ''