this repo has no description

Driver: Better handling of global config

+65 -18
+15 -7
src/driver/global_config.ml
··· 4 4 5 5 type t = { deps : deps } 6 6 7 + let empty = { deps = { libraries = []; packages = [] } } 8 + 7 9 module Ast = struct 8 10 type item = Libraries of string list | Packages of string list 9 11 ··· 42 44 let ast = List.filter_map parse_entry entries in 43 45 of_ast ast 44 46 45 - let empty = { deps = { libraries = []; packages = [] } } 46 - 47 - let load pkg_name = 48 - let config_file = 49 - Fpath.(v (Opam.prefix ()) / "doc" / pkg_name / "odoc-config.sexp") 50 - in 51 - match Bos.OS.File.read config_file with Error _ -> empty | Ok s -> parse s 47 + let load config_file = 48 + match Bos.OS.File.read config_file with 49 + | Error _ -> 50 + Logs.err (fun m -> 51 + m "Failed to read odoc-config file: %a" Fpath.pp config_file); 52 + empty 53 + | Ok s -> ( 54 + try parse s 55 + with e -> 56 + Logs.err (fun m -> 57 + m "Failed to parse config file %a: %s" Fpath.pp config_file 58 + (Printexc.to_string e)); 59 + empty)
+1 -1
src/driver/global_config.mli
··· 6 6 7 7 val parse : string -> t 8 8 9 - val load : string -> t 9 + val load : Fpath.t -> t
+30 -6
src/driver/opam.ml
··· 128 128 | `Other -> "`Other")) 129 129 kind Fpath.pp file Fpath.pp rel_path 130 130 131 - type installed_files = { libs : Fpath.set; docs : doc_file list } 131 + type installed_files = { 132 + libs : Fpath.set; 133 + docs : doc_file list; 134 + odoc_config : Fpath.t option; 135 + } 132 136 133 137 type package_of_fpath = package Fpath.map 134 138 ··· 140 144 141 145 let pp_fpaths_of_package fmt l = 142 146 List.iter 143 - (fun (p, { libs; docs }) -> 144 - Format.fprintf fmt "%a:@,libs: %a@,docs: %a@," pp p pp_fpath_set libs 147 + (fun (p, { libs; docs; odoc_config }) -> 148 + Format.fprintf fmt "%a:@,libs: %a@,docs: %a@,odoc_config: %a@," pp p 149 + pp_fpath_set libs 145 150 Fmt.Dump.(list pp_doc_file) 146 - docs) 151 + docs (Fmt.option Fpath.pp) odoc_config) 147 152 l 148 153 149 154 let classify_docs prefix only_package contents = ··· 204 209 in 205 210 libs 206 211 212 + let find_odoc_config prefix only_package contents = 213 + let pkg_match pkg = 214 + match only_package with None -> true | Some p -> p = pkg 215 + in 216 + 217 + let opt = 218 + List.find_opt 219 + (fun fpath -> 220 + match Fpath.segs fpath with 221 + | [ "doc"; pkg; "odoc-config.sexp" ] -> pkg_match pkg 222 + | _ -> false) 223 + contents 224 + in 225 + 226 + Option.map (fun p -> Fpath.(prefix // p)) opt 227 + 207 228 let dune_overrides () = 208 229 let ocamlpath = Sys.getenv_opt "OCAMLPATH" in 209 230 match ocamlpath with ··· 248 269 (fun pkg acc -> 249 270 let libs = classify_libs base (Some pkg) contents in 250 271 let docs = classify_docs base (Some pkg) contents in 272 + let odoc_config = find_odoc_config base (Some pkg) contents in 251 273 Logs.debug (fun m -> 252 274 m "pkg %s Found %d docs" pkg (List.length docs)); 253 - ({ name = pkg; version = "dev" }, { libs; docs }) :: acc) 275 + ({ name = pkg; version = "dev" }, { libs; docs; odoc_config }) 276 + :: acc) 254 277 packages [] 255 278 | Error (`Msg msg) -> 256 279 Logs.err (fun m -> ··· 268 291 let contents = pkg_contents p in 269 292 let libs = classify_libs (Fpath.v prefix) None contents in 270 293 let docs = classify_docs (Fpath.v prefix) None contents in 271 - (p, { libs; docs })) 294 + let odoc_config = find_odoc_config (Fpath.v prefix) None contents in 295 + (p, { libs; docs; odoc_config })) 272 296 pkgs 273 297 in 274 298
+5 -1
src/driver/opam.mli
··· 6 6 rel_path : Fpath.t; 7 7 } 8 8 9 - type installed_files = { libs : Fpath.set; docs : doc_file list } 9 + type installed_files = { 10 + libs : Fpath.set; 11 + docs : doc_file list; 12 + odoc_config : Fpath.t option; 13 + } 10 14 11 15 type package_of_fpath = package Fpath.map 12 16
+14 -3
src/driver/packages.ml
··· 387 387 Some { pkg with libraries } 388 388 | None -> 389 389 let pkg_dir = pkg_dir packages_dir pkg.name in 390 - let config = Global_config.load pkg.name in 391 - let _, { Opam.docs; _ } = 390 + 391 + let _, { Opam.docs; odoc_config; _ } = 392 392 List.find 393 393 (fun (pkg', _) -> 394 394 (* Logs.debug (fun m -> ··· 396 396 pkg = pkg') 397 397 opam_map 398 398 in 399 + 400 + let config = 401 + match odoc_config with 402 + | None -> Global_config.empty 403 + | Some f -> Global_config.load f 404 + in 405 + 399 406 let mlds, assets, _ = mk_mlds docs in 400 407 Some 401 408 { ··· 474 481 (files.Opam.libs |> Fpath.Set.to_list) 475 482 in 476 483 let pkg_dir = pkg_dir packages_dir pkg.name in 477 - let config = Global_config.load pkg.name in 484 + let config = 485 + match files.odoc_config with 486 + | None -> Global_config.empty 487 + | Some f -> Global_config.load f 488 + in 478 489 let mlds, assets, _ = mk_mlds files.docs in 479 490 let selected = List.mem pkg.name packages in 480 491 let remaps =