diff --git a/src/build.ml b/src/build.ml index 6d41d3b7..b77c48b1 100644 --- a/src/build.ml +++ b/src/build.ml @@ -131,6 +131,18 @@ let dyn_paths t = Dyn_paths t let contents p = Contents p let lines_of p = Lines_of p +let read_sexp p = + contents p + >>^ fun s -> + let lb = Lexing.from_string s in + lb.lex_curr_p <- + { pos_fname = Path.to_string p + ; pos_lnum = 1 + ; pos_bol = 0 + ; pos_cnum = 0 + }; + Sexp_lexer.single lb + let if_file_exists p ~then_ ~else_ = If_file_exists (p, ref (Undecided (then_, else_))) diff --git a/src/build.mli b/src/build.mli index 197f9e4e..36e88a8f 100644 --- a/src/build.mli +++ b/src/build.mli @@ -45,6 +45,9 @@ val dyn_paths : ('a, Path.t list) t -> ('a, 'a) t val contents : Path.t -> ('a, string) t val lines_of : Path.t -> ('a, string list) t +(** Load an S-expression from a file *) +val read_sexp : Path.t -> (unit, Sexp.Ast.t) t + (** Evaluates to [true] if the file is present on the file system or is the target of a rule. *) val file_exists : Path.t -> ('a, bool) t diff --git a/src/super_context.ml b/src/super_context.ml index e502dbde..0b068c28 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -720,13 +720,8 @@ let expand_and_eval_set ~dir set ~standard = Build.return (Ordered_set_lang.eval_with_standard set ~standard) | files -> let paths = List.map files ~f:(Path.relative dir) in - Build.paths paths - >>> - Build.arr (fun () -> - let files_contents = - List.map2 files paths ~f:(fun fn path -> - (fn, Sexp_load.single (Path.to_string path))) - |> String_map.of_alist_exn - in - let set = Ordered_set_lang.Unexpanded.expand set ~files_contents in - Ordered_set_lang.eval_with_standard set ~standard) + Build.all (List.map paths ~f:Build.read_sexp) + >>^ fun sexps -> + let files_contents = List.combine files sexps |> String_map.of_alist_exn in + let set = Ordered_set_lang.Unexpanded.expand set ~files_contents in + Ordered_set_lang.eval_with_standard set ~standard