blob: d65101a4b18d24e42a4a918bb695f78f14a3d018 [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([
James Kuszmaulf89cfab2020-01-17 19:48:25 -080071 "usr/lib/python3/dist-packages/**/*.cpython-35m-x86_64-linux-gnu.so",
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -070072])
73
74_system_so_files = glob(
75 include = [
76 "lib/x86_64-linux-gnu/**/*.so*",
77 "usr/lib/**/*.so*",
78 ],
79 exclude = [
James Kuszmaulf89cfab2020-01-17 19:48:25 -080080 "usr/lib/**/*.cpython-35m-x86_64-linux-gnu.so",
81 "usr/lib/gcc/x86_64-linux-gnu/6/libgcc_s.so.1",
82 "usr/lib/gcc/x86_64-linux-gnu/6/libgcc_s.so",
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -070083 ],
84)
85
86_builtin_so_copied = ["/".join(f.split("/")[4:]) for f in _builtin_so_files]
87
88_system_so_copied = ["rpathed/" + f for f in _system_so_files]
89
90_builtin_rpaths = [":".join([
91 "\\$$ORIGIN/%s" % rel,
92 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
93 "\\$$ORIGIN/%s/rpathed/usr/lib" % rel,
94 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
95]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _builtin_so_copied]]
96
97_system_rpaths = [":".join([
98 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
99 "\\$$ORIGIN/%s/rpathed/usr/lib" % rel,
100 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
101]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _system_so_copied]]
102
103genrule(
104 name = "run_patchelf_builtin",
105 srcs = _builtin_so_files,
106 outs = _builtin_so_copied,
107 cmd = "\n".join(
108 [
109 "cp $(location %s) $(location %s)" % (src, dest)
110 for src, dest in zip(_builtin_so_files, _builtin_so_copied)
111 ] +
112 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_builtin_rpaths, _builtin_so_copied)],
113 ),
114 tools = [
115 "@patchelf",
116 ],
117)
118
119genrule(
120 name = "run_patchelf_system",
121 srcs = _system_so_files,
122 outs = _system_so_copied,
123 cmd = "\n".join(
124 [
125 "cp $(location %s) $(location %s)" % (src, dest)
126 for src, dest in zip(_system_so_files, _system_so_copied)
127 ] +
128 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_system_rpaths, _system_so_copied)],
129 ),
130 tools = [
131 "@patchelf",
132 ],
133)
134
135genrule(
136 name = "copy_libgeos_c",
James Kuszmaulf89cfab2020-01-17 19:48:25 -0800137 srcs = ["rpathed/usr/lib/x86_64-linux-gnu/libgeos_c.so.1"],
138 outs = ["rpathed/usr/lib/x86_64-linux-gnu/libgeos_c.so"],
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -0700139 cmd = "cp $< $@",
140)
141
142genrule(
143 name = "copy_files",
144 srcs = _src_files,
145 outs = _src_copied,
146 cmd = " && ".join(["cp $(location %s) $(location %s)" % (src, dest) for src, dest in zip(
147 _src_files,
148 _src_copied,
149 )]),
150)
151
152py_library(
153 name = "python_gtk",
154 srcs = _src_copied + [
155 "gi/__init__.py",
156 "shapely/__init__.py",
157 "shapely/geos.py",
158 ],
159 data = _data_files + _builtin_so_copied + _system_so_copied + [
James Kuszmaulf89cfab2020-01-17 19:48:25 -0800160 "rpathed/usr/lib/x86_64-linux-gnu/libgeos_c.so",
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -0700161 ],
162 imports = ["usr/lib/python3/dist-packages"],
163 restricted_to = ["@//tools:k8"],
164 visibility = ["//visibility:public"],
165)