edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! Content-addressed cache of external-tool results, for test builds only. |
| 2 | //! |
| 3 | //! The gates shell out to ffmpeg (lavfi source generation, y4m and raw |
| 4 | //! loaders), aomenc (encodes) and aomdec / ffmpeg (oracle decodes). Those |
| 5 | //! results are deterministic functions of the program, its arguments, its |
| 6 | //! explicit environment, its working directory, its stdin and the contents of |
| 7 | //! every input file, so a second run can reuse them. The decoder under test is |
| 8 | //! never routed through here: only the external tool's `Output` is cached. |
| 9 | //! |
| 10 | //! Shell scripts are never cached: they can read hidden inputs (the control |
| 11 | //! tests' ffmpeg/aomdec shims read a sibling file), which no key can cover. |
| 12 | //! |
| 13 | //! A call is cached only when every path-like argument already names an |
| 14 | //! existing file (its content is hashed into the key) or a `/dev/` node. Any |
| 15 | //! other path-like argument is an output the tool would write, which cannot be |
| 16 | //! snapshotted, so that call simply runs. Only successful runs are stored. |
| 17 | //! |
| 18 | //! Environment: `EC_TOOL_CACHE=0|off` disables the cache; `EC_TOOL_CACHE_DIR` |
| 19 | //! overrides the directory (default `$HOME/.cache/ec-tool-cache`). |
| 20 | |
| 21 | use OsStr; |
| 22 | use fs; |
| 23 | use ; |
| 24 | use OsStrExt; |
| 25 | use ExitStatusExt; |
| 26 | use ; |
| 27 | use ; |
| 28 | use ; |
| 29 | |
| 30 | /// Outputs larger than this are run every time instead of stored. |
| 31 | const CAP_BYTES: u64 = 256 << 20; |
| 32 | const FNV_PRIME: u64 = 0x0000_0100_0000_01b3; |
| 33 | const BASIS_A: u64 = 0xcbf2_9ce4_8422_2325; |
| 34 | const BASIS_B: u64 = 0x8422_2325_cbf2_9ce4; |
| 35 | |
| 36 | /// Two independent 64-bit FNV-1a passes, giving a 128-bit key without deps. |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// The cache directory, or `None` when the cache is disabled. |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | /// Runs `cmd` through the cache (or straight through when disabled). `run` |
| 83 | /// performs the real spawn; it is called at most once. |
| 84 | /// |
| 85 | /// # Panics |
| 86 | /// Never from the cache itself; `run` is infallible here, so the internal |
| 87 | /// `io::Result` is always `Ok`. |
| 88 | pub |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | /// [`cached_output`] for callers that handle the `io::Result` of `.output()`. |
| 100 | pub |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | /// Resolves `prog` to a canonical path, searching PATH for bare names. |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | /// A path-like argument: contains '/' and is not a `key:value` filter or a |
| 148 | /// string with spaces. Those are the arguments that could name an output. |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | /// The argument itself and, for `--opt=path` / `key=path`, the part after the |
| 154 | /// first '='. |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | /// The key for this call, or `None` when the call must not be cached. |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 |