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