blob: 367c137ae4f32a8998dbfe850d2fbb0b9e402d9a [file] [log] [blame]
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -07001genrule(
2 name = "patch_gi_init",
3 srcs = [
4 "usr/lib/python3/dist-packages/gi/__init__.py",
5 "@//debian:python_gi_patches",
6 ],
7 outs = ["gi/__init__.py"],
8 cmd = " && ".join([
9 "cp $(location usr/lib/python3/dist-packages/gi/__init__.py) $@",
10 "readonly PATCH=\"$$(readlink -f $(location @patch))\"",
11 "readonly FILE=\"$$(readlink -f $(location @//debian:python_gi_patches))\"",
12 "(cd $(@D) && \"$${PATCH}\" -p1 < \"$${FILE}\") > /dev/null",
13 ]),
14 tools = [
15 "@patch",
16 ],
17)
18
19genrule(
20 name = "patch_shapely_init",
21 srcs = [
22 "usr/lib/python3/dist-packages/shapely/__init__.py",
23 "@//debian:python_shapely_patches",
24 ],
25 outs = ["shapely/__init__.py"],
26 cmd = " && ".join([
27 "cp $(location usr/lib/python3/dist-packages/shapely/__init__.py) $@",
28 "readonly PATCH=\"$$(readlink -f $(location @patch))\"",
29 "readonly FILE=\"$$(readlink -f $(location @//debian:python_shapely_patches))\"",
30 "(cd $(@D) && \"$${PATCH}\" -p1 < \"$${FILE}\") > /dev/null",
31 ]),
32 tools = [
33 "@patch",
34 ],
35)
36
37genrule(
38 name = "patch_geos",
39 srcs = [
40 "usr/lib/python3/dist-packages/shapely/geos.py",
41 "@//debian:python_geos_patches",
42 ],
43 outs = ["shapely/geos.py"],
44 cmd = " && ".join([
45 "cp $(location usr/lib/python3/dist-packages/shapely/geos.py) $@",
46 "readonly PATCH=\"$$(readlink -f $(location @patch))\"",
47 "readonly FILE=\"$$(readlink -f $(location @//debian:python_geos_patches))\"",
48 "(cd $(@D) && \"$${PATCH}\" -p1 < \"$${FILE}\") > /dev/null",
49 ]),
50 tools = [
51 "@patch",
52 ],
53)
54
55_src_files = glob(
56 include = ["usr/lib/python3/dist-packages/**/*.py"],
57 exclude = [
58 "usr/lib/python3/dist-packages/gi/__init__.py",
59 "usr/lib/python3/dist-packages/shapely/__init__.py",
60 "usr/lib/python3/dist-packages/shapely/geos.py",
61 ],
62)
63
64_data_files = glob([
65 "usr/lib/x86_64-linux-gnu/girepository-1.0/**/*",
66])
67
68_src_copied = ["/".join(f.split("/")[4:]) for f in _src_files]
69
70_builtin_so_files = glob([
71 "usr/lib/python3/dist-packages/**/*.cpython-34m-x86_64-linux-gnu.so",
72])
73
74_system_so_files = glob(
75 include = [
76 "lib/x86_64-linux-gnu/**/*.so*",
77 "usr/lib/**/*.so*",
78 ],
79 exclude = [
80 "usr/lib/**/*.cpython-34m-x86_64-linux-gnu.so",
81 ],
82)
83
84_builtin_so_copied = ["/".join(f.split("/")[4:]) for f in _builtin_so_files]
85
86_system_so_copied = ["rpathed/" + f for f in _system_so_files]
87
88_builtin_rpaths = [":".join([
89 "\\$$ORIGIN/%s" % rel,
90 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
91 "\\$$ORIGIN/%s/rpathed/usr/lib" % rel,
92 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
93]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _builtin_so_copied]]
94
95_system_rpaths = [":".join([
96 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
97 "\\$$ORIGIN/%s/rpathed/usr/lib" % rel,
98 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
99]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _system_so_copied]]
100
101genrule(
102 name = "run_patchelf_builtin",
103 srcs = _builtin_so_files,
104 outs = _builtin_so_copied,
105 cmd = "\n".join(
106 [
107 "cp $(location %s) $(location %s)" % (src, dest)
108 for src, dest in zip(_builtin_so_files, _builtin_so_copied)
109 ] +
110 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_builtin_rpaths, _builtin_so_copied)],
111 ),
112 tools = [
113 "@patchelf",
114 ],
115)
116
117genrule(
118 name = "run_patchelf_system",
119 srcs = _system_so_files,
120 outs = _system_so_copied,
121 cmd = "\n".join(
122 [
123 "cp $(location %s) $(location %s)" % (src, dest)
124 for src, dest in zip(_system_so_files, _system_so_copied)
125 ] +
126 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_system_rpaths, _system_so_copied)],
127 ),
128 tools = [
129 "@patchelf",
130 ],
131)
132
133genrule(
134 name = "copy_libgeos_c",
135 srcs = ["rpathed/usr/lib/libgeos_c.so.1"],
136 outs = ["rpathed/usr/lib/libgeos_c.so"],
137 cmd = "cp $< $@",
138)
139
140genrule(
141 name = "copy_files",
142 srcs = _src_files,
143 outs = _src_copied,
144 cmd = " && ".join(["cp $(location %s) $(location %s)" % (src, dest) for src, dest in zip(
145 _src_files,
146 _src_copied,
147 )]),
148)
149
150py_library(
151 name = "python_gtk",
152 srcs = _src_copied + [
153 "gi/__init__.py",
154 "shapely/__init__.py",
155 "shapely/geos.py",
156 ],
157 data = _data_files + _builtin_so_copied + _system_so_copied + [
158 "rpathed/usr/lib/libgeos_c.so",
159 ],
160 imports = ["usr/lib/python3/dist-packages"],
161 restricted_to = ["@//tools:k8"],
162 visibility = ["//visibility:public"],
163)