licenses fix tentative

This commit is contained in:
Matthieu Dubuget committed 2026-11-22 18:48:51 +01:00
1 parent 42e5e3321a
commit 04ba4437f0
3 files changed
+20 -9

No files matched your search

+18 -9
View File
@@ -29,6 +29,10 @@ let line cmd =
| x :: _ -> Ok x
| [] -> msg "no output from: %s" (Cmd.to_string cmd)
(* Windows writes paths with backslashes, and drive letters in either case. *)
let normalize s =
String.lowercase_ascii (String.map (function '\\' -> '/' | c -> c) s)
let starts_with ~prefix s =
String.length s >= String.length prefix
&& String.sub s 0 (String.length prefix) = prefix
@@ -64,19 +68,23 @@ let load_changes switch =
|> List.filter (Fpath.has_ext ".changes")
|> map_result (fun f ->
let* content = OS.File.read f in
Ok (Fpath.(basename (rem_ext f)), content))
Ok (Fpath.(basename (rem_ext f)), normalize content))
let owner ~stdlib ~changes lib =
let* dir = line (ocamlfind [ "query"; "-format"; "%d"; lib ]) in
if starts_with ~prefix:stdlib dir then Ok (Some "ocaml")
if starts_with ~prefix:(normalize stdlib) (normalize dir) then Ok "ocaml"
else
let top = List.hd (String.split_on_char '.' lib) in
let meta = Re.compile (Re.str (Printf.sprintf "lib/%s/META" top)) in
Ok
(List.find_map
(fun (pkg, content) ->
if Re.execp meta content then Some pkg else None)
changes)
let meta =
Re.compile (Re.str (normalize (Printf.sprintf "lib/%s/META" top)))
in
match
List.find_map
(fun (pkg, content) -> if Re.execp meta content then Some pkg else None)
changes
with
| Some pkg -> Ok pkg
| None -> msg "no opam package found for the library %s" lib
let license_re = Re.Perl.compile_pat ~opts:[ `Multiline ] "^license:[ \t]*(.*)$"
@@ -125,7 +133,8 @@ let run file =
let* owners =
map_result (owner ~stdlib ~changes) (List.sort_uniq compare libs)
in
let packages = List.sort_uniq compare (List.filter_map Fun.id owners) in
let packages = List.sort_uniq compare owners in
if packages = [] then msg "no library found in %s" file else
let* infos =
map_result
(fun p ->