Skip to content

Commit

Permalink
Merge pull request #171 from yfyf/fix-ocamlc-warnings
Browse files Browse the repository at this point in the history
Fix or suppress ocamlc unused variable/binding warnings
  • Loading branch information
knuton authored Aug 1, 2024
2 parents 95cd09b + 0dbdea9 commit cc9b31e
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 23 deletions.
1 change: 0 additions & 1 deletion controller/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ PlayOS controller is an OCaml application that manages various system tasks for

- `bindings/`: bindings to various things
- `gui/`: static gui assets
- `nix/`: nix stuff
- `server/`: main application code
- `bin/`: binaries to start a dev server

Expand Down
2 changes: 2 additions & 0 deletions controller/bindings/connman/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(include ../disable-unused-warnings.dune)

(library
(name connman)
(modules connman connman_interfaces)
Expand Down
4 changes: 2 additions & 2 deletions controller/bindings/curl/curl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ let request ?proxy ?(headers = []) ?data ?(options = []) url =
| Ok (Unix.WEXITED n, _, stderr) ->
Lwt.return (RequestFailure (ProcessExit (n, stderr)))

| Ok (Unix.WSIGNALED signal, _, stderr) ->
| Ok (Unix.WSIGNALED signal, _, _stderr) ->
Lwt.return (RequestFailure (ProcessKill signal))

| Ok (Unix.WSTOPPED signal, _, stderr) ->
| Ok (Unix.WSTOPPED signal, _, _stderr) ->
Lwt.return (RequestFailure (ProcessStop signal))

| Error (Unix.Unix_error (err, _, _)) ->
Expand Down
6 changes: 6 additions & 0 deletions controller/bindings/disable-unused-warnings.dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; OBus generates bindings that contains a lot of unused variables/bindings
; and dune treats these as errors, so we disable them here.
; Refer to ocamlc man pages or `ocamlc -warn-help` for descriptions of
; the warning numbers.
(env (dev (flags :standard -w -27-32-33)))

2 changes: 2 additions & 0 deletions controller/bindings/rauc/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(include ../disable-unused-warnings.dune)

(library
(name rauc)
(modules rauc rauc_interfaces)
Expand Down
2 changes: 2 additions & 0 deletions controller/bindings/systemd/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(include ../disable-unused-warnings.dune)

(library
(name systemd)
(modules systemd systemd_interfaces)
Expand Down
2 changes: 2 additions & 0 deletions controller/bindings/timedate/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(include ../disable-unused-warnings.dune)

(library
(name timedate)
(modules timedate timedate_interfaces)
Expand Down
6 changes: 3 additions & 3 deletions controller/bindings/util/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let read_from_file log_src path =
let%lwt () = Lwt_io.close in_chan in
return contents
with
| (Unix.Unix_error (err, fn, _)) as exn ->
| (Unix.Unix_error (err, _fn, _)) as exn ->
let%lwt () = Logs_lwt.err ~src:log_src
(fun m -> m "failed to read from %s: %s" path (Unix.error_message err))
in
Expand All @@ -27,12 +27,12 @@ let write_to_file log_src path str =
let%lwt fd =
Lwt_unix.openfile path [ O_WRONLY; O_CREAT; O_TRUNC ] 0o755
in
let%lwt bytes_written =
let%lwt _bytes_written =
Lwt_unix.write_string fd str 0 (String.length str)
in
Lwt_unix.close fd
with
| (Unix.Unix_error (err, fn, _)) as exn ->
| (Unix.Unix_error (err, _fn, _)) as exn ->
let%lwt () = Logs_lwt.err ~src:log_src
(fun m -> m "failed to write to %s: %s" path (Unix.error_message err))
in
Expand Down
5 changes: 5 additions & 0 deletions controller/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
(gui/reset.css as static/reset.css)
(gui/style.css as static/style.css)
(gui/client.js as static/client.js)))

; Disable missing-record-field-pattern warnings (partial matching),
; because they are kind of useless.
; See https://ocaml.org/manual/4.14/comp.html#ss:warn9 for details.
(env (dev (flags :standard -w -9)))
22 changes: 9 additions & 13 deletions controller/server/gui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ open Lwt
open Sexplib.Std
open Opium_kernel.Rock
open Opium.App
open Sys

let log_src = Logs.Src.create "gui"

Expand Down Expand Up @@ -70,7 +69,7 @@ end

(** Localization GUI *)
module LocalizationGui = struct
let overview req =
let overview _req =
let%lwt td_daemon = Timedate.daemon () in
let%lwt current_timezone = Timedate.get_configured_timezone () in
let%lwt all_timezones = Timedate.get_available_timezones td_daemon in
Expand Down Expand Up @@ -140,7 +139,7 @@ module LocalizationGui = struct
}))

let set_timezone req =
let%lwt td_daemon = Timedate.daemon () in
let%lwt _td_daemon = Timedate.daemon () in
let%lwt form_data =
urlencoded_pairs_of_body req
in
Expand Down Expand Up @@ -207,9 +206,8 @@ end
module NetworkGui = struct

open Connman
open Network

let overview ~(connman:Manager.t) req =
let overview ~(connman:Manager.t) _req =

let%lwt all_services = Manager.get_services connman in

Expand Down Expand Up @@ -240,11 +238,11 @@ module NetworkGui = struct
match%lwt Curl.request ?proxy:(Option.map (Service.Proxy.to_uri ~include_userinfo:true) proxy) (Uri.of_string "http://captive.dividat.com/") with
| RequestSuccess (code, response) ->
`String response
|> respond ?code:(Some (Cohttp.Code.(`Code code)))
|> respond ?code:(Some (`Code code))
|> Lwt.return
| RequestFailure err ->
`String (Format.sprintf "Error reaching captive portal: %s" (Curl.pretty_print_error err))
|> respond ?code:(Some Cohttp.Code.(`Service_unavailable))
|> respond ?code:(Some `Service_unavailable)
|> Lwt.return

(** Helper to find a service by id *)
Expand Down Expand Up @@ -315,16 +313,14 @@ module NetworkGui = struct
fail_with "A host and port are required to configure a proxy server"

(** Set static IP configuration on a service *)
let update_static_ip ~(connman: Connman.Manager.t) service form_data =
let update_static_ip service form_data =
let get_prop s =
form_data
|> List.assoc s
|> List.hd
in
match form_data |> List.assoc_opt "static_ip_enabled" with
| None ->
let open Cohttp in
let open Cohttp_lwt_unix in
let%lwt () = Logs_lwt.err ~src:log_src
(fun m -> m "disabling static ip %s" (get_prop "static_ip_address"))
in
Expand Down Expand Up @@ -362,7 +358,7 @@ module NetworkGui = struct
let%lwt service = with_service ~connman (param req "id") in

(* Static IP *)
let%lwt () = update_static_ip ~connman service form_data in
let%lwt () = update_static_ip service form_data in

(* Proxy *)
let%lwt current_proxy = Manager.get_default_proxy connman in
Expand Down Expand Up @@ -426,7 +422,7 @@ module LabelGui = struct
)
} : Label_printer.label)

let overview req =
let overview _req =
let%lwt label = make_label () in
Lwt.return (page (Label_page.html label))

Expand Down Expand Up @@ -458,7 +454,7 @@ end
module StatusGui = struct
let build ~health_s ~update_s ~rauc app =
app
|> get "/status" (fun req ->
|> get "/status" (fun _req ->
let%lwt rauc =
match update_s |> Lwt_react.S.value with
(* RAUC status is not meaningful while installing
Expand Down
5 changes: 3 additions & 2 deletions controller/server/network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ let enable_and_scan_wifi_devices ~connman =


let init ~connman =
let%lwt () = Logs_lwt.info (fun m -> m "initializing network connections") in
let%lwt () = Logs_lwt.info ~src:log_src
(fun m -> m "initializing network connections") in

match%lwt enable_and_scan_wifi_devices ~connman with

| Ok () ->
Lwt_result.return ()

| Error exn ->
let%lwt () = Logs_lwt.warn
let%lwt () = Logs_lwt.warn ~src:log_src
(fun m -> m "enabling and scanning wifi failed: %s, %s"
(OBus_error.name exn)
(Printexc.to_string exn))
Expand Down
1 change: 0 additions & 1 deletion controller/server/server.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Lwt
open Sexplib.Std

let shutdown () =
match%lwt
Expand Down
1 change: 0 additions & 1 deletion controller/server/update.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Lwt
open Sexplib.Std
open Sexplib.Conv

let log_src = Logs.Src.create "update"
Expand Down

0 comments on commit cc9b31e

Please sign in to comment.