From 04ba4437f0f01bff5f16501a5795dde65859c365 Mon Sep 17 00:00:00 2001 From: Matthieu Dubuget Date: Sun, 22 Nov 2026 18:46:51 +0100 Subject: [PATCH] licenses fix tentative --- dune-project | 1 + tools/gen_licenses.ml | 27 ++++++++++++++++++--------- totpin.opam | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dune-project b/dune-project index 4c98ed2..98daec0 100644 --- a/dune-project +++ b/dune-project @@ -35,6 +35,7 @@ countdown. Press any key (or Ctrl-C) to quit.") console-eio digestif (bos :build) + (ocamlfind :build) (ocaml-lsp-server :with-dev-setup) (merlin :with-dev-setup) (ocamlformat :with-dev-setup) diff --git a/tools/gen_licenses.ml b/tools/gen_licenses.ml index 00c9608..52c90d9 100644 --- a/tools/gen_licenses.ml +++ b/tools/gen_licenses.ml @@ -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 -> diff --git a/totpin.opam b/totpin.opam index 84133c7..867b8fb 100644 --- a/totpin.opam +++ b/totpin.opam @@ -24,6 +24,7 @@ depends: [ "console-eio" "digestif" "bos" {build} + "ocamlfind" {build} "ocaml-lsp-server" {with-dev-setup} "merlin" {with-dev-setup} "ocamlformat" {with-dev-setup}