diff --git a/bin/print_rules.ml b/bin/print_rules.ml index 2c0df0318d8..40389c204c9 100644 --- a/bin/print_rules.ml +++ b/bin/print_rules.ml @@ -68,7 +68,7 @@ let rec encode : Action.For_shell.t -> Dune_lang.t = | With_accepted_exit_codes (pred, t) -> List [ atom "with-accepted-exit-codes" - ; Predicate_lang.encode Dune_lang.Encoder.int pred + ; Predicate_lang.encode Dune_sexp.Encoder.int pred ; encode t ] | Dynamic_run (a, xs) -> List (atom "run_dynamic" :: program a :: List.map xs ~f:string) @@ -103,10 +103,58 @@ let rec encode : Action.For_shell.t -> Dune_lang.t = | Extension ext -> List [ atom "ext"; Dune_sexp.Quoted_string (Sexp.to_string ext) ] ;; +let encode_path p = + let make constr arg = + Dune_sexp.List [ Dune_sexp.atom constr; Dune_sexp.atom_or_quoted_string arg ] + in + let open Path in + match p with + | In_build_dir p -> make "In_build_dir" (Path.Build.to_string p) + | In_source_tree p -> make "In_source_tree" (Path.Source.to_string p) + | External p -> make "External" (Path.External.to_string p) +;; + +let encode_file_selector file_selector = + let open Dune_sexp.Encoder in + let module File_selector = Dune_engine.File_selector in + let dir = File_selector.dir file_selector in + let predicate = File_selector.predicate file_selector in + let only_generated_files = File_selector.only_generated_files file_selector in + record + [ "dir", encode_path dir + ; "predicate", Predicate_lang.Glob.encode predicate + ; "only_generated_files", bool only_generated_files + ] +;; + +let encode_alias alias = + let open Dune_sexp.Encoder in + let dir = Dune_engine.Alias.dir alias in + let name = Dune_engine.Alias.name alias in + record + [ "dir", encode_path (Path.build dir) + ; "name", Dune_sexp.atom_or_quoted_string (Dune_util.Alias_name.to_string name) + ] +;; + +let encode_dep_set deps = + Dune_sexp.List + (Dep.Set.to_list_map + deps + ~f: + (let open Dune_sexp.Encoder in + function + | File_selector g -> pair string encode_file_selector ("glob", g) + | Env e -> pair string string ("Env", e) + | File f -> pair string encode_path ("File", f) + | Alias a -> pair string encode_alias ("Alias", a) + | Universe -> string "Universe")) +;; + let print_rule_sexp ppf (rule : Dune_engine.Reflection.Rule.t) = let sexp_of_action action = Action.for_shell action |> encode in let paths ps = - Dune_lang.Encoder.list + Dune_sexp.Encoder.list (fun p -> Path.Build.relative rule.targets.root p |> Path.Build.to_string @@ -114,11 +162,11 @@ let print_rule_sexp ppf (rule : Dune_engine.Reflection.Rule.t) = (Filename.Set.to_list ps) in let sexp = - Dune_lang.Encoder.record + Dune_sexp.Encoder.record (List.concat - [ [ "deps", Dep.Set.encode rule.deps + [ [ "deps", encode_dep_set rule.deps ; ( "targets" - , Dune_lang.Encoder.record + , Dune_sexp.Encoder.record [ "files", paths rule.targets.files ; "directories", paths rule.targets.dirs ] ) diff --git a/src/dune_config_file/dune_config_file.ml b/src/dune_config_file/dune_config_file.ml index 0b31881b547..1bf91c61025 100644 --- a/src/dune_config_file/dune_config_file.ml +++ b/src/dune_config_file/dune_config_file.ml @@ -75,7 +75,17 @@ module Dune_config = struct module Sandboxing_preference = struct type t = Sandbox_mode.t list - let decode = repeat Sandbox_mode.decode + let decode : Sandbox_mode.t Dune_sexp.Decoder.t = + let open Dune_sexp.Decoder in + enum + [ "none", None + ; "symlink", Some Sandbox_mode.Symlink + ; "copy", Some Copy + ; "hardlink", Some Hardlink + ] + ;; + + let decode = repeat decode end module Cache = struct diff --git a/src/dune_engine/alias.ml b/src/dune_engine/alias.ml index 15f655755a7..0f1a5d13e6f 100644 --- a/src/dune_engine/alias.ml +++ b/src/dune_engine/alias.ml @@ -3,8 +3,6 @@ open Import module Name = struct include Dune_util.Alias_name - let encode s = Dune_sexp.Encoder.string (to_string s) - let of_string s = match of_string_opt s with | Some s -> s @@ -96,11 +94,6 @@ let register_as_standard name = let default = make_standard Name.default -let encode { dir; name } = - let open Dune_sexp.Encoder in - record [ "dir", Dpath.encode (Path.build dir); "name", Name.encode name ] -;; - let get_ctx (path : Path.Build.t) = match Path.Build.extract_first_component path with | None -> None diff --git a/src/dune_engine/alias.mli b/src/dune_engine/alias.mli index 9366772ac04..c35cd44b815 100644 --- a/src/dune_engine/alias.mli +++ b/src/dune_engine/alias.mli @@ -22,7 +22,6 @@ val name : t -> Name.t val dir : t -> Path.Build.t val to_dyn : t -> Dyn.t -val encode : t Dune_sexp.Encoder.t val of_user_written_path : loc:Loc.t -> Path.t -> t val fully_qualified_name : t -> Path.Build.t val default : dir:Path.Build.t -> t diff --git a/src/dune_engine/dep.ml b/src/dune_engine/dep.ml index a8d9a1f5762..225455931b6 100644 --- a/src/dune_engine/dep.ml +++ b/src/dune_engine/dep.ml @@ -45,17 +45,15 @@ module T = struct | Universe, Universe -> Ordering.Eq ;; - let encode t = - let open Dune_sexp.Encoder in + let to_dyn t = + let open Dyn in match t with - | File_selector g -> pair string File_selector.encode ("glob", g) - | Env e -> pair string string ("Env", e) - | File f -> pair string Dpath.encode ("File", f) - | Alias a -> pair string Alias.encode ("Alias", a) - | Universe -> string "Universe" + | File_selector g -> variant "File_selector" [ File_selector.to_dyn g ] + | Env e -> variant "Env" [ string e ] + | File f -> variant "File" [ Path.to_dyn f ] + | Alias a -> variant "Alias" [ Alias.to_dyn a ] + | Universe -> variant "Universe" [] ;; - - let to_dyn t = Dyn.String (Dune_sexp.to_string (encode t)) end include T @@ -254,7 +252,6 @@ module Set = struct let of_files l = of_list_map l ~f:file let of_files_set = Path.Set.fold ~init:empty ~f:(fun f acc -> add acc (file f)) let add_paths t paths = Path.Set.fold paths ~init:t ~f:(fun p set -> add set (File p)) - let encode t = Dune_sexp.Encoder.list encode (to_list t) (* This is to force the rules to be loaded for directories without files when depending on [(source_tree x)]. Otherwise, we wouldn't clean up stale diff --git a/src/dune_engine/dep.mli b/src/dune_engine/dep.mli index a4d9f63c290..a848fcc020d 100644 --- a/src/dune_engine/dep.mli +++ b/src/dune_engine/dep.mli @@ -73,7 +73,6 @@ module Set : sig val of_files : Path.t list -> t val of_files_set : Path.Set.t -> t - val encode : t -> Dune_sexp.t val add_paths : t -> Path.Set.t -> t val digest : t -> Digest.t end diff --git a/src/dune_engine/dpath.ml b/src/dune_engine/dpath.ml index d49c4eb78c4..9da183f561a 100644 --- a/src/dune_engine/dpath.ml +++ b/src/dune_engine/dpath.ml @@ -108,17 +108,3 @@ let analyse_dir (fn : Path.t) = ;; type t = Path.t - -let encode p = - (* CR rgrinberg: only reason this lives here is to implement - [$ dune rules]. Seems like it should just live there along with all the - other encoders in the engine. *) - let make constr arg = - Dune_sexp.List [ Dune_sexp.atom constr; Dune_sexp.atom_or_quoted_string arg ] - in - let open Path in - match p with - | In_build_dir p -> make "In_build_dir" (Path.Build.to_string p) - | In_source_tree p -> make "In_source_tree" (Path.Source.to_string p) - | External p -> make "External" (Path.External.to_string p) -;; diff --git a/src/dune_engine/dpath.mli b/src/dune_engine/dpath.mli index 1fdddac8ea8..f7ed78f6dc9 100644 --- a/src/dune_engine/dpath.mli +++ b/src/dune_engine/dpath.mli @@ -39,8 +39,6 @@ val describe_path : Path.t -> string type t = Path.t -val encode : Path.t Dune_sexp.Encoder.t - module Build : sig type t = Path.Build.t diff --git a/src/dune_engine/dune b/src/dune_engine/dune index c0b4548f085..82ef2ed07d8 100644 --- a/src/dune_engine/dune +++ b/src/dune_engine/dune @@ -14,7 +14,6 @@ dune_async_io threads.posix predicate_lang - dune_sexp dune_cache dune_cache_storage dune_glob diff --git a/src/dune_engine/file_selector.ml b/src/dune_engine/file_selector.ml index cedee74500e..1e90c8f18a9 100644 --- a/src/dune_engine/file_selector.ml +++ b/src/dune_engine/file_selector.ml @@ -11,6 +11,7 @@ type t = let dir t = t.dir let only_generated_files t = t.only_generated_files +let predicate t = t.predicate let digest_exn { dir; predicate; only_generated_files } = Digest.generic (dir, Predicate_lang.Glob.digest_exn predicate, only_generated_files) @@ -37,15 +38,6 @@ let to_dyn { dir; predicate; only_generated_files } = ] ;; -let encode { dir; predicate; only_generated_files } = - let open Dune_sexp.Encoder in - record - [ "dir", Dpath.encode dir - ; "predicate", Predicate_lang.Glob.encode predicate - ; "only_generated_files", bool only_generated_files - ] -;; - let equal x y = compare x y = Eq let hash { dir; predicate; only_generated_files } = diff --git a/src/dune_engine/file_selector.mli b/src/dune_engine/file_selector.mli index b4674943de0..941aa0319ab 100644 --- a/src/dune_engine/file_selector.mli +++ b/src/dune_engine/file_selector.mli @@ -8,6 +8,7 @@ type t val dir : t -> Path.t val only_generated_files : t -> bool val of_glob : dir:Path.t -> Glob.t -> t +val predicate : t -> Predicate_lang.Glob.t val of_predicate_lang : dir:Path.t @@ -18,7 +19,6 @@ val of_predicate_lang val equal : t -> t -> bool val hash : t -> int val compare : t -> t -> Ordering.t -val encode : t Dune_sexp.Encoder.t (** [to_dyn] is used as a marshallable representation of [t] (to compute digests), so it must be injective *) diff --git a/src/dune_engine/sandbox_mode.ml b/src/dune_engine/sandbox_mode.ml index 5507fbc88c5..10c59543ec8 100644 --- a/src/dune_engine/sandbox_mode.ml +++ b/src/dune_engine/sandbox_mode.ml @@ -120,16 +120,6 @@ let symlink = Some Symlink let copy = Some Copy let hardlink = Some Hardlink -let decode = - let open Dune_sexp.Decoder in - enum - [ "none", None - ; "symlink", Some Symlink - ; "copy", Some Copy - ; "hardlink", Some Hardlink - ] -;; - let to_string = function | None -> "none" | Some Symlink -> "symlink" diff --git a/src/dune_engine/sandbox_mode.mli b/src/dune_engine/sandbox_mode.mli index 47a313c0574..d538d6a1f0d 100644 --- a/src/dune_engine/sandbox_mode.mli +++ b/src/dune_engine/sandbox_mode.mli @@ -80,6 +80,5 @@ val none : t val symlink : t val copy : t val hardlink : t -val decode : t Dune_sexp.Decoder.t val to_string : t -> string val to_dyn : t -> Dyn.t