Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 1 | genrule( |
| 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 | |
| 19 | genrule( |
| 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 | |
| 37 | genrule( |
| 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 Kuszmaul | 58683ed | 2020-01-25 20:33:11 -0800 | [diff] [blame] | 66 | "usr/share/font*/**", |
| 67 | "etc/**", |
Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 68 | ]) |
| 69 | |
| 70 | _src_copied = ["/".join(f.split("/")[4:]) for f in _src_files] |
| 71 | |
| 72 | _builtin_so_files = glob([ |
James Kuszmaul | f89cfab | 2020-01-17 19:48:25 -0800 | [diff] [blame] | 73 | "usr/lib/python3/dist-packages/**/*.cpython-35m-x86_64-linux-gnu.so", |
Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 74 | ]) |
| 75 | |
| 76 | _system_so_files = glob( |
| 77 | include = [ |
| 78 | "lib/x86_64-linux-gnu/**/*.so*", |
| 79 | "usr/lib/**/*.so*", |
| 80 | ], |
| 81 | exclude = [ |
James Kuszmaul | f89cfab | 2020-01-17 19:48:25 -0800 | [diff] [blame] | 82 | "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 Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 85 | ], |
| 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 | |
| 105 | genrule( |
| 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 | |
| 121 | genrule( |
| 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 | |
| 137 | genrule( |
| 138 | name = "copy_libgeos_c", |
James Kuszmaul | f89cfab | 2020-01-17 19:48:25 -0800 | [diff] [blame] | 139 | 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 Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 141 | cmd = "cp $< $@", |
| 142 | ) |
| 143 | |
| 144 | genrule( |
| 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 | |
| 154 | py_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 Kuszmaul | f89cfab | 2020-01-17 19:48:25 -0800 | [diff] [blame] | 162 | "rpathed/usr/lib/x86_64-linux-gnu/libgeos_c.so", |
Brian Silverman | b0ebf1d | 2018-10-17 23:36:40 -0700 | [diff] [blame] | 163 | ], |
| 164 | imports = ["usr/lib/python3/dist-packages"], |
| 165 | restricted_to = ["@//tools:k8"], |
| 166 | visibility = ["//visibility:public"], |
| 167 | ) |