blob: 5f89ba9722218d495249f737cfea14d5de8a8262 [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/**",
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -070028 "usr/share/tcltk/**",
Brian Silverman6470f442018-08-05 12:08:16 -070029])
30
31_src_copied = ["/".join(f.split("/")[4:]) for f in _src_files]
32
33_builtin_so_files = glob([
34 "usr/lib/python2.7/dist-packages/**/*.x86_64-linux-gnu.so",
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -070035 "usr/lib/python2.7/lib-dynload/*.so",
Brian Silverman6470f442018-08-05 12:08:16 -070036])
37
38_system_so_files = glob([
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -070039 "usr/lib/**/*.so*",
Brian Silverman6470f442018-08-05 12:08:16 -070040 "lib/x86_64-linux-gnu/**/*.so*",
41])
42
43_builtin_so_copied = ["/".join(f.split("/")[4:]) for f in _builtin_so_files]
44
45_system_so_copied = ["rpathed/" + f for f in _system_so_files]
46
47_builtin_rpaths = [":".join([
48 "\\$$ORIGIN/%s" % rel,
49 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -070050 "\\$$ORIGIN/%s/rpathed/usr/lib" % rel,
Brian Silverman6470f442018-08-05 12:08:16 -070051 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
52]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _builtin_so_copied]]
53
54_system_rpaths = [":".join([
55 "\\$$ORIGIN/%s/rpathed/usr/lib/x86_64-linux-gnu" % rel,
56 "\\$$ORIGIN/%s/rpathed/lib/x86_64-linux-gnu" % rel,
57]) for rel in ["/".join([".." for _ in so.split("/")[1:]]) for so in _system_so_copied]]
58
59genrule(
60 name = "run_patchelf_builtin",
61 srcs = _builtin_so_files,
62 outs = _builtin_so_copied,
63 cmd = "\n".join(
64 [
65 "cp $(location %s) $(location %s)" % (src, dest)
66 for src, dest in zip(_builtin_so_files, _builtin_so_copied)
67 ] +
68 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_builtin_rpaths, _builtin_so_copied)],
69 ),
70 tools = [
71 "@patchelf",
72 ],
73)
74
75genrule(
76 name = "run_patchelf_system",
77 srcs = _system_so_files,
78 outs = _system_so_copied,
79 cmd = "\n".join(
80 [
81 "cp $(location %s) $(location %s)" % (src, dest)
82 for src, dest in zip(_system_so_files, _system_so_copied)
83 ] +
84 ["$(location @patchelf) --set-rpath %s $(location %s)" % (rpath, so) for rpath, so in zip(_system_rpaths, _system_so_copied)],
85 ),
86 tools = [
87 "@patchelf",
88 ],
89)
90
91genrule(
92 name = "copy_files",
93 srcs = _src_files,
94 outs = _src_copied,
95 cmd = " && ".join(["cp $(location %s) $(location %s)" % (src, dest) for src, dest in zip(
96 _src_files,
97 _src_copied,
98 )]),
99)
100
101genrule(
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -0700102 name = "create_rc",
Brian Silverman6470f442018-08-05 12:08:16 -0700103 outs = ["usr/share/matplotlib/mpl-data/matplotlibrc"],
Brian Silvermanb0ebf1d2018-10-17 23:36:40 -0700104 cmd = "\n".join([
105 "cat > $@ << END",
106 # This is necessary to make matplotlib actually plot things to the
107 # screen by default.
108 "backend : TkAgg",
109 "END",
110 ]),
Brian Silverman6470f442018-08-05 12:08:16 -0700111)
112
113py_library(
114 name = "matplotlib",
115 srcs = _src_copied + [
116 "matplotlib/__init__.py",
117 ],
118 data = _data_files + _builtin_so_copied + _system_so_copied + [
119 ":usr/share/matplotlib/mpl-data/matplotlibrc",
120 ],
121 imports = ["usr/lib/python2.7/dist-packages"],
122 restricted_to = ["@//tools:k8"],
123 visibility = ["//visibility:public"],
124)