blob: 208761ad773bcdbdca9a9736dda4b470c62b4087 [file] [log] [blame]
Brian Silverman6470f442018-08-05 12:08:16 -07001genrule(
2 name = "patch_init",
3 srcs = [
4 "usr/lib/python2.7/dist-packages/matplotlib/__init__.py",
5 "@//debian:matplotlib_patches",
6 ],
7 outs = ["matplotlib/__init__.py"],
8 cmd = " && ".join([
9 "cp $(location usr/lib/python2.7/dist-packages/matplotlib/__init__.py) $@",
10 "readonly PATCH=\"$$(readlink -f $(location @patch))\"",
11 "readonly FILE=\"$$(readlink -f $(location @//debian:matplotlib_patches))\"",
12 "(cd $(@D) && \"$${PATCH}\" -p1 < \"$${FILE}\") > /dev/null",
13 ]),
14 tools = [
15 "@patch",
16 ],
17)
18
19_src_files = glob(
20 include = ["usr/lib/python2.7/dist-packages/**/*.py"],
21 exclude = [
22 "usr/lib/python2.7/dist-packages/matplotlib/__init__.py",
23 ],
24)
25
26_data_files = glob([
27 "usr/share/matplotlib/mpl-data/**",
28])
29
30_src_copied = ["/".join(f.split("/")[4:]) for f in _src_files]
31
32_builtin_so_files = glob([
33 "usr/lib/python2.7/dist-packages/**/*.x86_64-linux-gnu.so",
34])
35
36_system_so_files = glob([
37 "usr/lib/x86_64-linux-gnu/**/*.so*",
38 "lib/x86_64-linux-gnu/**/*.so*",
39])
40
41_builtin_so_copied = ["/".join(f.split("/")[4:]) for f in _builtin_so_files]
42
43_system_so_copied = ["rpathed/" + f for f in _system_so_files]
44
45_builtin_rpaths = [":".join([
46 "\\$$ORIGIN/%s" % rel,
47 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
48 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
49]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _builtin_so_copied]]
50
51_system_rpaths = [":".join([
52 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
53 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
54]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _system_so_copied]]
55
56genrule(
57 name = "run_patchelf_builtin",
58 srcs = _builtin_so_files,
59 outs = _builtin_so_copied,
60 cmd = "\n".join(
61 [
62 "cp $(location %s) $(location %s)" % (src, dest)
63 for src, dest in zip(_builtin_so_files, _builtin_so_copied)
64 ] +
65 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_builtin_rpaths, _builtin_so_copied)],
66 ),
67 tools = [
68 "@patchelf",
69 ],
70)
71
72genrule(
73 name = "run_patchelf_system",
74 srcs = _system_so_files,
75 outs = _system_so_copied,
76 cmd = "\n".join(
77 [
78 "cp $(location %s) $(location %s)" % (src, dest)
79 for src, dest in zip(_system_so_files, _system_so_copied)
80 ] +
81 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_system_rpaths, _system_so_copied)],
82 ),
83 tools = [
84 "@patchelf",
85 ],
86)
87
88genrule(
89 name = "copy_files",
90 srcs = _src_files,
91 outs = _src_copied,
92 cmd = " && ".join(["cp $(location %s) $(location %s)" % (src, dest) for src, dest in zip(
93 _src_files,
94 _src_copied,
95 )]),
96)
97
98genrule(
99 name = "create_empty_rc",
100 outs = ["usr/share/matplotlib/mpl-data/matplotlibrc"],
101 cmd = "touch $@",
102)
103
104py_library(
105 name = "matplotlib",
106 srcs = _src_copied + [
107 "matplotlib/__init__.py",
108 ],
109 data = _data_files + _builtin_so_copied + _system_so_copied + [
110 ":usr/share/matplotlib/mpl-data/matplotlibrc",
111 ],
112 imports = ["usr/lib/python2.7/dist-packages"],
113 restricted_to = ["@//tools:k8"],
114 visibility = ["//visibility:public"],
115)