From c894831614791888baaa698016ece77e30141f7d Mon Sep 17 00:00:00 2001 From: Sam Cowger Date: Tue, 7 Jan 2025 15:11:43 -0800 Subject: [PATCH 1/2] telemetry: build with OCaml 4.14.1 --- dune-project | 4 +- telemetry.opam | 4 +- telemetry.opam.locked-4.14.1 | 57 +++++++++++++++++++ ...opam.locked => telemetry.opam.locked-5.1.1 | 0 telemetry/lib/disk.ml | 17 +++--- telemetry/test/disk.ml | 22 ++++++- 6 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 telemetry.opam.locked-4.14.1 rename telemetry.opam.locked => telemetry.opam.locked-5.1.1 (100%) diff --git a/dune-project b/dune-project index f2227da..0fe45c2 100644 --- a/dune-project +++ b/dune-project @@ -72,11 +72,11 @@ (< 4.0.0))) (ppx_hash (and - (>= v0.16.3) + (>= v0.16.0) (< v0.18))) (ppx_sexp_conv (and - (>= v0.16.3) + (>= v0.16.0) (< v0.18))) (yojson (and diff --git a/telemetry.opam b/telemetry.opam index 1fd8881..754e6e6 100644 --- a/telemetry.opam +++ b/telemetry.opam @@ -9,8 +9,8 @@ depends: [ "alcotest" {>= "1.6.0" & < "2.0.0"} "base" {>= "v0.16.3" & < "v0.18"} "ppx_deriving_yojson" {>= "3.0.0" & < "4.0.0"} - "ppx_hash" {>= "v0.16.3" & < "v0.18"} - "ppx_sexp_conv" {>= "v0.16.3" & < "v0.18"} + "ppx_hash" {>= "v0.16.0" & < "v0.18"} + "ppx_sexp_conv" {>= "v0.16.0" & < "v0.18"} "yojson" {>= "2.0.0" & < "3.0.0"} "odoc" {with-doc} ] diff --git a/telemetry.opam.locked-4.14.1 b/telemetry.opam.locked-4.14.1 new file mode 100644 index 0000000..8b7b7cb --- /dev/null +++ b/telemetry.opam.locked-4.14.1 @@ -0,0 +1,57 @@ +opam-version: "2.0" +name: "telemetry" +version: "0.0.1" +synopsis: "Telemetry collection" +maintainer: "Sam Cowger" +authors: "Sam Cowger" +depends: [ + "alcotest" {= "1.8.0"} + "astring" {= "0.8.5"} + "base" {= "v0.16.3"} + "base-bigarray" {= "base"} + "base-threads" {= "base"} + "base-unix" {= "base"} + "cmdliner" {= "1.3.0"} + "conf-bash" {= "1"} + "cppo" {= "1.7.0"} + "csexp" {= "1.5.2"} + "dune" {= "3.16.1"} + "dune-configurator" {= "3.16.1"} + "fmt" {= "0.9.0"} + "ocaml" {= "4.14.1"} + "ocaml-base-compiler" {= "4.14.1"} + "ocaml-compiler-libs" {= "v0.12.4"} + "ocaml-config" {= "2"} + "ocaml-options-vanilla" {= "1"} + "ocaml-syntax-shims" {= "1.0.0"} + "ocamlbuild" {= "0.15.0"} + "ocamlfind" {= "1.9.6"} + "ppx_compare" {= "v0.16.0"} + "ppx_derivers" {= "1.2.1"} + "ppx_deriving" {= "6.0.3"} + "ppx_deriving_yojson" {= "3.9.0"} + "ppx_hash" {= "v0.16.0"} + "ppx_sexp_conv" {= "v0.16.0"} + "ppxlib" {= "0.33.0"} + "re" {= "1.12.0"} + "seq" {= "base"} + "sexplib0" {= "v0.16.0"} + "stdlib-shims" {= "0.3.0"} + "topkg" {= "1.0.7"} + "uutf" {= "1.0.3"} + "yojson" {= "2.2.2"} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] diff --git a/telemetry.opam.locked b/telemetry.opam.locked-5.1.1 similarity index 100% rename from telemetry.opam.locked rename to telemetry.opam.locked-5.1.1 diff --git a/telemetry/lib/disk.ml b/telemetry/lib/disk.ml index ed42fdf..bfac3ee 100644 --- a/telemetry/lib/disk.ml +++ b/telemetry/lib/disk.ml @@ -19,19 +19,18 @@ module Session = struct (** Attempt to decode a filename as a session. *) let of_filename (path : string) : t option = - match - Stdlib.Scanf.sscanf_opt + try + Stdlib.Scanf.sscanf (Stdlib.Filename.basename path) "session-%i-%i-%i" - (fun y m d -> y, m, d) + (fun year month day -> Some (Day { year; month; day })) with - | Some (year, month, day) -> Some (Day { year; month; day }) - | None -> - (match - Stdlib.Scanf.sscanf_opt (Stdlib.Filename.basename path) "session-%Li" Fn.id + | Stdlib.Scanf.Scan_failure _ -> + (try + Stdlib.Scanf.sscanf (Stdlib.Filename.basename path) "session-%Li" (fun id -> + Some (Custom { id })) with - | Some i -> Some (Custom { id = i }) - | None -> None) + | Stdlib.Scanf.Scan_failure _ -> None) ;; end diff --git a/telemetry/test/disk.ml b/telemetry/test/disk.ml index ce7d1a8..a58cf66 100644 --- a/telemetry/test/disk.ml +++ b/telemetry/test/disk.ml @@ -6,8 +6,28 @@ module Storage = Telemetry.Disk.M (SampleEvent) (SampleProfile) let ok (r : ('ok, _) Result.t) : 'ok = Option.value_exn (Result.ok r) +(* A rough copy of [Filename.temp_dir] to allow building with OCaml versions + prior to 5.1 *) +let make_temp_dir (prefix : string) (suffix : string) : string = + let temp_dir = Filename.get_temp_dir_name () in + let temp_file_name prefix suffix = + let rnd = Stdlib.Random.bits () land 0xFFFFFF in + Filename.concat temp_dir (Printf.sprintf "%s%06x%s" prefix rnd suffix) + in + let rec try_make tries = + let name = temp_file_name prefix suffix in + let perms = 0o700 in + try + Stdlib.Sys.mkdir name perms; + name + with + | Sys_error _ as e -> if tries >= 20 then raise e else try_make (tries + 1) + in + try_make 0 +;; + let storage = - let tmpdir = Filename.temp_dir "telemetry-test" "" in + let tmpdir = make_temp_dir "telemetry-test" "" in ok Storage.(create { root_dir = tmpdir }) ;; From cafd2a5b9e13637bc0c1ea4ec0f6e084600c7dc2 Mon Sep 17 00:00:00 2001 From: Sam Cowger Date: Tue, 7 Jan 2025 15:13:34 -0800 Subject: [PATCH 2/2] ci: build telemetry with OCaml 4.14.1 --- .github/workflows/telemetry-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/telemetry-ci.yml b/.github/workflows/telemetry-ci.yml index 67297c0..da14979 100644 --- a/.github/workflows/telemetry-ci.yml +++ b/.github/workflows/telemetry-ci.yml @@ -17,7 +17,7 @@ jobs: build: strategy: matrix: - ocaml-version: [5.1.1] + ocaml-version: [4.14.1, 5.1.1] os: [ubuntu-22.04] runs-on: ${{ matrix.os }} @@ -31,6 +31,9 @@ jobs: with: ocaml-compiler: ${{ matrix.ocaml-version }} + - name: Link lockfile + run: ln -s telemetry.opam.locked-${{ matrix.ocaml-version }} telemetry.opam.locked + - name: Install telemetry dependencies run: opam install ./telemetry.opam --deps-only --locked -y