Brian Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 1 | genrule( |
| 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 Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 28 | "usr/share/tcltk/**", |
Brian Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 29 | ]) |
| 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 Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 35 | "usr/lib/python2.7/lib-dynload/*.so", |
Brian Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 36 | ]) |
| 37 | |
| 38 | _system_so_files = glob([ |
Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 39 | "usr/lib/**/*.so*", |
Brian Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 40 | "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 Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 50 | "\\$$ORIGIN/%s/rpathed/usr/lib" % rel, |
Brian Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 51 | "\\$$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 | |
| 59 | genrule( |
| 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 | |
| 75 | genrule( |
| 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 | |
| 91 | genrule( |
| 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 | |
| 101 | genrule( |
Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 102 | name = "create_rc", |
Brian Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 103 | outs = ["usr/share/matplotlib/mpl-data/matplotlibrc"], |
Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 104 | 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 Silverman | 6470f44 | 2018-08-05 12:08:16 -0700 | [diff] [blame] | 111 | ) |
| 112 | |
| 113 | py_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 | ) |