The unpac monorepo manager self-hosting as a monorepo using unpac

Merge pull request #46 from emillon/select-dune-rules

Select `unsafe.ml` with just dune rules

authored by dinosaure.tngl.sh and committed by

GitHub fa375d80 d04477d2

+12 -59
-1
base64.opam
··· 17 17 depends: [ 18 18 "ocaml" {>="4.03.0"} 19 19 "base-bytes" 20 - "dune-configurator" 21 20 "dune" {>= "2.0"} 22 21 "bos" {with-test} 23 22 "rresult" {with-test}
+5 -52
config/config.ml
··· 1 - module Config = Configurator.V1 2 - 3 - let pre407 = 4 - {ocaml|external unsafe_set_uint16 : bytes -> int -> int -> unit = "%caml_string_set16u" [@@noalloc]|ocaml} 5 - 6 - let standard = 7 - {ocaml|external unsafe_set_uint16 : bytes -> int -> int -> unit = "%caml_bytes_set16u" [@@noalloc]|ocaml} 8 - 9 - type t = { major : int; minor : int; patch : int option; extra : string option } 10 - 11 - let v ?patch ?extra major minor = { major; minor; patch; extra } 12 - 13 - let parse s = 14 - try 15 - Scanf.sscanf s "%d.%d.%d+%s" (fun major minor patch extra -> 16 - v ~patch ~extra major minor) 17 - with End_of_file | Scanf.Scan_failure _ -> ( 18 - try 19 - Scanf.sscanf s "%d.%d+%s" (fun major minor extra -> v ~extra major minor) 20 - with End_of_file | Scanf.Scan_failure _ -> ( 21 - try 22 - Scanf.sscanf s "%d.%d.%d" (fun major minor patch -> 23 - v ~patch major minor) 24 - with End_of_file | Scanf.Scan_failure _ -> 25 - Scanf.sscanf s "%d.%d" (fun major minor -> v major minor))) 26 - 27 - let ( >|= ) x f = match x with Some x -> Some (f x) | None -> None 28 - 29 - let ocaml_cp ~src ~dst = 30 - let ic = open_in src in 31 - let oc = open_out dst in 32 - let bf = Bytes.create 0x1000 in 33 - let rec go () = 34 - match input ic bf 0 (Bytes.length bf) with 35 - | 0 -> () 36 - | len -> 37 - output oc bf 0 len ; 38 - go () 39 - | exception End_of_file -> () in 40 - go () ; 41 - close_in ic ; 42 - close_out oc 1 + let parse s = Scanf.sscanf s "%d.%d" (fun major minor -> (major, minor)) 43 2 44 3 let () = 45 - Config.main ~name:"config-base64" @@ fun t -> 46 - match Config.ocaml_config_var t "version" >|= parse with 47 - | Some version -> 48 - let dst = "unsafe.ml" in 49 - 50 - if (version.major, version.minor) >= (4, 7) 51 - then ocaml_cp ~src:"unsafe_stable.ml" ~dst 52 - else ocaml_cp ~src:"unsafe_pre407.ml" ~dst 53 - | None -> Config.die "OCaml version is not available" 54 - | exception exn -> Config.die "Got an exception: %s" (Printexc.to_string exn) 4 + let version = parse Sys.ocaml_version in 5 + if version >= (4, 7) 6 + then print_string "unsafe_stable.ml" 7 + else print_string "unsafe_pre407.ml"
+6 -2
config/dune
··· 1 1 (executable 2 - (name config) 3 - (libraries dune-configurator)) 2 + (name config)) 3 + 4 + (rule 5 + (with-stdout-to 6 + which-unsafe-file 7 + (run ./config.exe)))
+1 -4
src/dune
··· 5 5 (libraries bytes)) 6 6 7 7 (rule 8 - (targets unsafe.ml) 9 - (deps unsafe_pre407.ml unsafe_stable.ml) 10 - (action 11 - (run ../config/config.exe))) 8 + (copy %{read:../config/which-unsafe-file} unsafe.ml)) 12 9 13 10 (library 14 11 (name base64_rfc2045)