this repo has no description

Driver: Better handling of global config

+65 -18
+15 -7
src/driver/global_config.ml
··· 4 5 type t = { deps : deps } 6 7 module Ast = struct 8 type item = Libraries of string list | Packages of string list 9 ··· 42 let ast = List.filter_map parse_entry entries in 43 of_ast ast 44 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
··· 4 5 type t = { deps : deps } 6 7 + let empty = { deps = { libraries = []; packages = [] } } 8 + 9 module Ast = struct 10 type item = Libraries of string list | Packages of string list 11 ··· 44 let ast = List.filter_map parse_entry entries in 45 of_ast ast 46 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 7 val parse : string -> t 8 9 - val load : string -> t
··· 6 7 val parse : string -> t 8 9 + val load : Fpath.t -> t
+30 -6
src/driver/opam.ml
··· 128 | `Other -> "`Other")) 129 kind Fpath.pp file Fpath.pp rel_path 130 131 - type installed_files = { libs : Fpath.set; docs : doc_file list } 132 133 type package_of_fpath = package Fpath.map 134 ··· 140 141 let pp_fpaths_of_package fmt l = 142 List.iter 143 - (fun (p, { libs; docs }) -> 144 - Format.fprintf fmt "%a:@,libs: %a@,docs: %a@," pp p pp_fpath_set libs 145 Fmt.Dump.(list pp_doc_file) 146 - docs) 147 l 148 149 let classify_docs prefix only_package contents = ··· 204 in 205 libs 206 207 let dune_overrides () = 208 let ocamlpath = Sys.getenv_opt "OCAMLPATH" in 209 match ocamlpath with ··· 248 (fun pkg acc -> 249 let libs = classify_libs base (Some pkg) contents in 250 let docs = classify_docs base (Some pkg) contents in 251 Logs.debug (fun m -> 252 m "pkg %s Found %d docs" pkg (List.length docs)); 253 - ({ name = pkg; version = "dev" }, { libs; docs }) :: acc) 254 packages [] 255 | Error (`Msg msg) -> 256 Logs.err (fun m -> ··· 268 let contents = pkg_contents p in 269 let libs = classify_libs (Fpath.v prefix) None contents in 270 let docs = classify_docs (Fpath.v prefix) None contents in 271 - (p, { libs; docs })) 272 pkgs 273 in 274
··· 128 | `Other -> "`Other")) 129 kind Fpath.pp file Fpath.pp rel_path 130 131 + type installed_files = { 132 + libs : Fpath.set; 133 + docs : doc_file list; 134 + odoc_config : Fpath.t option; 135 + } 136 137 type package_of_fpath = package Fpath.map 138 ··· 144 145 let pp_fpaths_of_package fmt l = 146 List.iter 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 150 Fmt.Dump.(list pp_doc_file) 151 + docs (Fmt.option Fpath.pp) odoc_config) 152 l 153 154 let classify_docs prefix only_package contents = ··· 209 in 210 libs 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 + 228 let dune_overrides () = 229 let ocamlpath = Sys.getenv_opt "OCAMLPATH" in 230 match ocamlpath with ··· 269 (fun pkg acc -> 270 let libs = classify_libs base (Some pkg) contents in 271 let docs = classify_docs base (Some pkg) contents in 272 + let odoc_config = find_odoc_config base (Some pkg) contents in 273 Logs.debug (fun m -> 274 m "pkg %s Found %d docs" pkg (List.length docs)); 275 + ({ name = pkg; version = "dev" }, { libs; docs; odoc_config }) 276 + :: acc) 277 packages [] 278 | Error (`Msg msg) -> 279 Logs.err (fun m -> ··· 291 let contents = pkg_contents p in 292 let libs = classify_libs (Fpath.v prefix) None contents in 293 let docs = classify_docs (Fpath.v prefix) None contents in 294 + let odoc_config = find_odoc_config (Fpath.v prefix) None contents in 295 + (p, { libs; docs; odoc_config })) 296 pkgs 297 in 298
+5 -1
src/driver/opam.mli
··· 6 rel_path : Fpath.t; 7 } 8 9 - type installed_files = { libs : Fpath.set; docs : doc_file list } 10 11 type package_of_fpath = package Fpath.map 12
··· 6 rel_path : Fpath.t; 7 } 8 9 + type installed_files = { 10 + libs : Fpath.set; 11 + docs : doc_file list; 12 + odoc_config : Fpath.t option; 13 + } 14 15 type package_of_fpath = package Fpath.map 16
+14 -3
src/driver/packages.ml
··· 387 Some { pkg with libraries } 388 | None -> 389 let pkg_dir = pkg_dir packages_dir pkg.name in 390 - let config = Global_config.load pkg.name in 391 - let _, { Opam.docs; _ } = 392 List.find 393 (fun (pkg', _) -> 394 (* Logs.debug (fun m -> ··· 396 pkg = pkg') 397 opam_map 398 in 399 let mlds, assets, _ = mk_mlds docs in 400 Some 401 { ··· 474 (files.Opam.libs |> Fpath.Set.to_list) 475 in 476 let pkg_dir = pkg_dir packages_dir pkg.name in 477 - let config = Global_config.load pkg.name in 478 let mlds, assets, _ = mk_mlds files.docs in 479 let selected = List.mem pkg.name packages in 480 let remaps =
··· 387 Some { pkg with libraries } 388 | None -> 389 let pkg_dir = pkg_dir packages_dir pkg.name in 390 + 391 + let _, { Opam.docs; odoc_config; _ } = 392 List.find 393 (fun (pkg', _) -> 394 (* Logs.debug (fun m -> ··· 396 pkg = pkg') 397 opam_map 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 + 406 let mlds, assets, _ = mk_mlds docs in 407 Some 408 { ··· 481 (files.Opam.libs |> Fpath.Set.to_list) 482 in 483 let pkg_dir = pkg_dir packages_dir 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 489 let mlds, assets, _ = mk_mlds files.docs in 490 let selected = List.mem pkg.name packages in 491 let remaps =