From 8645471410dfe54ba0b837d508c7e6843436f573 Mon Sep 17 00:00:00 2001 From: Matthieu Dubuget Date: Sun, 22 Nov 2026 18:56:55 +0100 Subject: [PATCH] --- dune-project | 2 +- tools/gen_licenses.ml | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dune-project b/dune-project index 98daec0..a348b30 100644 --- a/dune-project +++ b/dune-project @@ -2,7 +2,7 @@ (name totpin) -(version 1.0) +(version 1.1) (generate_opam_files true) diff --git a/tools/gen_licenses.ml b/tools/gen_licenses.ml index 52c90d9..976ae5e 100644 --- a/tools/gen_licenses.ml +++ b/tools/gen_licenses.ml @@ -21,7 +21,13 @@ let rec map_result f = function Ok (y :: ys) let ocamlfind args = Cmd.(v "ocamlfind" %% of_list args) -let lines cmd = OS.Cmd.(run_out cmd |> to_lines) +let chop_cr s = + let n = String.length s in + if n > 0 && s.[n - 1] = '\r' then String.sub s 0 (n - 1) else s + +let lines cmd = + let* l = OS.Cmd.(run_out cmd |> to_lines) in + Ok (List.map chop_cr l) let line cmd = let* l = lines cmd in @@ -29,9 +35,18 @@ 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. *) +(* Windows writes paths with backslashes (doubled in the .changes files, where + they are escaped), and drive letters in either case. *) let normalize s = - String.lowercase_ascii (String.map (function '\\' -> '/' | c -> c) s) + let b = Buffer.create (String.length s) in + String.iter + (fun c -> + let c = if c = '\\' then '/' else Char.lowercase_ascii c in + let n = Buffer.length b in + if not (c = '/' && n > 0 && Buffer.nth b (n - 1) = '/') then + Buffer.add_char b c) + s; + Buffer.contents b let starts_with ~prefix s = String.length s >= String.length prefix