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/**", |
| 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 | |
| 56 | genrule( |
| 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 | |
| 72 | genrule( |
| 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 | |
| 88 | genrule( |
| 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 | |
| 98 | genrule( |
| 99 | name = "create_empty_rc", |
| 100 | outs = ["usr/share/matplotlib/mpl-data/matplotlibrc"], |
| 101 | cmd = "touch $@", |
| 102 | ) |
| 103 | |
| 104 | py_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 | ) |